Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4 installed after RestEx

2023-11-10 Thread Leif Lindholm
On Fri, Nov 10, 2023 at 00:39:53 +, Chang, Abner wrote:
> [AMD Official Use Only - General]
> 
> Thanks Leif, some responses are given in line.
> As we would like to have this be part of edk2-stable202312,  we
> prefer letting this change gets in stable release first and address
> the comment in another patch afterward.
>
> Hi Igor,
> Could you please check my comment and help to send another patch after 
> edk2-stable202312?
> 
> Thanks
> Abner
> 
> 
> > -Original Message-
> > From: Leif Lindholm 
> > Sent: Thursday, November 9, 2023 11:12 PM
> > To: devel@edk2.groups.io; ig...@ami.com
> > Cc: Chang, Abner ; Nickle Wang
> > ; gaolim...@byosoft.com.cn
> > Subject: Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix
> > issue if IPv4 installed after RestEx
> >
> > Caution: This message originated from an External Source. Use proper caution
> > when opening attachments, clicking links, or responding.
> >
> >
> > On 2023-11-07 12:06, Igor Kulchytskyy via groups.io wrote:
> > > Supported function of the driver changed to wait for all newtwork
> >
> > Typo:
> > newtwork ->
> > network
> >
> > > interface to be installed.
> > > Filer out the network interfaces which are not supported by
> >
> > Filer ->
> > Filter
> >
> > > Redfish Host Interface.
> >
> > These sound like two separate changes?
> This is for the same issue.

That means it should be in the same set, not in the same patch.

> > > Cc: Abner Chang 
> > > Cc: Nickle Wang 
> > > Signed-off-by: Igor Kulchytskyy 
> > > ---
> > >   RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c | 165
> > ++--
> > >   1 file changed, 117 insertions(+), 48 deletions(-)
> > >
> > > diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> > b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> > > index 23da3b968f..85e47843e4 100644
> > > --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> > > +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> > > @@ -322,9 +322,16 @@ GetTargetNetworkInterfaceInternal (
> > >   {
> > > EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
> > *ThisNetworkInterface;
> > >
> > > +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> > > +return NULL;
> > > +  }
> > > +
> > > ThisNetworkInterface =
> > (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode
> > (&mEfiRedfishDiscoverNetworkInterface);
> > > while (TRUE) {
> > > -if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,
> > &TargetNetworkInterface->MacAddress, ThisNetworkInterface-
> > >HwAddressSize) == 0) {
> > > +if ((CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,
> > &TargetNetworkInterface->MacAddress, ThisNetworkInterface-
> > >HwAddressSize) == 0) &&
> > > +((TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-
> > >NetworkProtocolType == ProtocolTypeTcp6)) ||
> > > + (!TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-
> > >NetworkProtocolType == ProtocolTypeTcp4
> > > +{
> >
> > This could really benefit from some helper macros.
> > e.g. if the test could look like
> 
> Hi Igor,
> Could we consider this suggestion after stable release?
> 
> >
> > if ((MAC_COMPARE (ThisNetworkInterface, TargetNetworkInterface) == 0) &&
> >  (VALID_TCP6 (TargetNetworkInterface, ThisNetworkInterface) ||
> >   VALID_TCP4 (TargetNetworkInterface, ThisNetworkInterface))) {
> >
> > > return ThisNetworkInterface;
> > >   }
> > >
> > > @@ -354,6 +361,10 @@ GetTargetNetworkInterfaceInternalByController (
> > >   {
> > > EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
> > *ThisNetworkInterface;
> > >
> > > +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> > > +return NULL;
> > > +  }
> > > +
> > > ThisNetworkInterface =
> > (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode
> > (&mEfiRedfishDiscoverNetworkInterface);
> > > while (TRUE) {
> > >   if (ThisNetworkInterface->OpenDriverControllerHandle ==
> > ControllerHandle) {
> > > @@ -476,6 +487,42 @@ CheckIsIpVersion6 (
> > > return FALSE;
> > >   }
> > >
> >

Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4 installed after RestEx

2023-11-09 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Thanks Leif, some responses are given in line.
As we would like to have this be part of edk2-stable202312,  we prefer letting 
this change gets in stable release first and address the comment in another 
patch afterward.

Hi Igor,
Could you please check my comment and help to send another patch after 
edk2-stable202312?

Thanks
Abner


> -Original Message-
> From: Leif Lindholm 
> Sent: Thursday, November 9, 2023 11:12 PM
> To: devel@edk2.groups.io; ig...@ami.com
> Cc: Chang, Abner ; Nickle Wang
> ; gaolim...@byosoft.com.cn
> Subject: Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix
> issue if IPv4 installed after RestEx
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> On 2023-11-07 12:06, Igor Kulchytskyy via groups.io wrote:
> > Supported function of the driver changed to wait for all newtwork
>
> Typo:
> newtwork ->
> network
>
> > interface to be installed.
> > Filer out the network interfaces which are not supported by
>
> Filer ->
> Filter
>
> > Redfish Host Interface.
>
> These sound like two separate changes?
This is for the same issue.

>
> > Cc: Abner Chang 
> > Cc: Nickle Wang 
> > Signed-off-by: Igor Kulchytskyy 
> > ---
> >   RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c | 165
> ++--
> >   1 file changed, 117 insertions(+), 48 deletions(-)
> >
> > diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> > index 23da3b968f..85e47843e4 100644
> > --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> > +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> > @@ -322,9 +322,16 @@ GetTargetNetworkInterfaceInternal (
> >   {
> > EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
> *ThisNetworkInterface;
> >
> > +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> > +return NULL;
> > +  }
> > +
> > ThisNetworkInterface =
> (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode
> (&mEfiRedfishDiscoverNetworkInterface);
> > while (TRUE) {
> > -if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,
> &TargetNetworkInterface->MacAddress, ThisNetworkInterface-
> >HwAddressSize) == 0) {
> > +if ((CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,
> &TargetNetworkInterface->MacAddress, ThisNetworkInterface-
> >HwAddressSize) == 0) &&
> > +((TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-
> >NetworkProtocolType == ProtocolTypeTcp6)) ||
> > + (!TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-
> >NetworkProtocolType == ProtocolTypeTcp4
> > +{
>
> This could really benefit from some helper macros.
> e.g. if the test could look like

Hi Igor,
Could we consider this suggestion after stable release?

>
> if ((MAC_COMPARE (ThisNetworkInterface, TargetNetworkInterface) == 0) &&
>  (VALID_TCP6 (TargetNetworkInterface, ThisNetworkInterface) ||
>   VALID_TCP4 (TargetNetworkInterface, ThisNetworkInterface))) {
>
> > return ThisNetworkInterface;
> >   }
> >
> > @@ -354,6 +361,10 @@ GetTargetNetworkInterfaceInternalByController (
> >   {
> > EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
> *ThisNetworkInterface;
> >
> > +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> > +return NULL;
> > +  }
> > +
> > ThisNetworkInterface =
> (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode
> (&mEfiRedfishDiscoverNetworkInterface);
> > while (TRUE) {
> >   if (ThisNetworkInterface->OpenDriverControllerHandle ==
> ControllerHandle) {
> > @@ -476,6 +487,42 @@ CheckIsIpVersion6 (
> > return FALSE;
> >   }
> >
> > +/**
> > +  This function returns the  IP type supported by the Host Interface.
> > +
> > +  @retval 00h is Unknown
> > +  01h is Ipv4
> > +  02h is Ipv6
> > +
> > +**/
> > +UINT8
>
> If this is just a local helper function, we probably want it STATIC.
However, it is recommended that not using STATIC for local function for the 
source level debug purpose in 5.4.2.2.2 in edk2 C coding standard spec.

>
> > +GetHiIpProtocolType (
> > +  VOID
> > +  )
> > +{
> > +  EFI_STATUS Status;
> > +  REDFISH_OVER_IP_PROTOCOL_DATA  *Data;
> > +  REDFISH_INT

Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4 installed after RestEx

2023-11-09 Thread Leif Lindholm

On 2023-11-07 12:06, Igor Kulchytskyy via groups.io wrote:

Supported function of the driver changed to wait for all newtwork


Typo:
newtwork ->
network


interface to be installed.
Filer out the network interfaces which are not supported by


Filer ->
Filter


Redfish Host Interface.


These sound like two separate changes?


Cc: Abner Chang 
Cc: Nickle Wang 
Signed-off-by: Igor Kulchytskyy 
---
  RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c | 165 ++--
  1 file changed, 117 insertions(+), 48 deletions(-)

diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c 
b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
index 23da3b968f..85e47843e4 100644
--- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
+++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
@@ -322,9 +322,16 @@ GetTargetNetworkInterfaceInternal (
  {
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL  *ThisNetworkInterface;

+  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
+return NULL;
+  }
+
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL 
*)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
-if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, 
&TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
+if ((CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, 
&TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) &&
+((TargetNetworkInterface->IsIpv6 && 
(ThisNetworkInterface->NetworkProtocolType == ProtocolTypeTcp6)) ||
+ (!TargetNetworkInterface->IsIpv6 && 
(ThisNetworkInterface->NetworkProtocolType == ProtocolTypeTcp4
+{


This could really benefit from some helper macros.
e.g. if the test could look like

if ((MAC_COMPARE (ThisNetworkInterface, TargetNetworkInterface) == 0) &&
(VALID_TCP6 (TargetNetworkInterface, ThisNetworkInterface) ||
 VALID_TCP4 (TargetNetworkInterface, ThisNetworkInterface))) {


return ThisNetworkInterface;
  }

@@ -354,6 +361,10 @@ GetTargetNetworkInterfaceInternalByController (
  {
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL  *ThisNetworkInterface;

+  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
+return NULL;
+  }
+
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL 
*)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
  if (ThisNetworkInterface->OpenDriverControllerHandle == ControllerHandle) 
{
@@ -476,6 +487,42 @@ CheckIsIpVersion6 (
return FALSE;
  }

+/**
+  This function returns the  IP type supported by the Host Interface.
+
+  @retval 00h is Unknown
+  01h is Ipv4
+  02h is Ipv6
+
+**/
+UINT8


If this is just a local helper function, we probably want it STATIC.


+GetHiIpProtocolType (
+  VOID
+  )
+{
+  EFI_STATUS Status;
+  REDFISH_OVER_IP_PROTOCOL_DATA  *Data;
+  REDFISH_INTERFACE_DATA *DeviceDescriptor;
+
+  Data = NULL;
+  DeviceDescriptor = NULL;
+  if (mSmbios == NULL) {
+Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID 
**)&mSmbios);
+if (EFI_ERROR (Status)) {
+  return REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
+}
+  }
+
+  Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor, 
&Data); // Search for SMBIOS type 42h
+  if (!EFI_ERROR (Status) && (Data != NULL) &&
+  (Data->HostIpAssignmentType == RedfishHostIpAssignmentStatic))
+  {
+return Data->HostIpAddressFormat;
+  }
+
+  return REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
+}
+
  /**
This function discover Redfish service through SMBIOS host interface.

@@ -512,6 +559,18 @@ DiscoverRedfishHostInterface (

Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor, 
&Data); // Search for SMBIOS type 42h
if (!EFI_ERROR (Status) && (Data != NULL) && (DeviceDescriptor != NULL)) {
+if ((Instance->NetworkInterface->NetworkProtocolType == ProtocolTypeTcp4) 
&&
+(Data->HostIpAddressFormat != 
REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4)) // IPv4 case
+{
+  DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv4, but Host Interface 
requires Ipv6\n", __func__));
+  return EFI_UNSUPPORTED;
+} else if ((Instance->NetworkInterface->NetworkProtocolType == ProtocolTypeTcp6) 
&&
+   (Data->HostIpAddressFormat != 
REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6)) // IPv6 case
+{
+  DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv6, but Host Interface 
requires IPv4\n", __func__));
+  return EFI_UNSUPPORTED;
+}
+
  //
  // Check if we can reach out Redfish service using this network interface.
  // Check with MAC address using Device Descriptor Data Device Type 04 and 
Type 05.
@@ -1102,6 +1161,7 @@ RedfishServiceGetNetworkInterface (
OUT EFI_REDFISH_DISCOVER_NETWORK_INTERFACE  **NetworkIntfInstances
)
  {
+  EFI_STATUS 

Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4 installed after RestEx

2023-11-07 Thread Nickle Wang via groups.io
Hi @Liming Gao<mailto:gaolim...@byosoft.com.cn>, @Kinney, Michael 
D<mailto:michael.d.kin...@intel.com>



> If the patch is sent before Soft Feature Freeze, and plans to catch this 
> stable tag, the patch contributor need reply to his patch and notify edk2 
> community



We would like to include this fix to edk2-stable202311 release. Could you 
please help us to merge this patch? This patch review was started on November 
1: https://edk2.groups.io/g/devel/message/110440. Anber and I gave reviewed-by 
to this patch today. We have a pull request ready for merging here: 
https://github.com/tianocore/edk2/pull/4994



Thanks,

Nickle



> -Original Message-

> From: devel@edk2.groups.io  On Behalf Of Chang, Abner

> via groups.io

> Sent: Wednesday, November 8, 2023 8:14 AM

> To: Igor Kulchytskyy ; devel@edk2.groups.io

> Cc: Nickle Wang 

> Subject: Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix 
> issue if

> IPv4 installed after RestEx

>

> External email: Use caution opening links or attachments

>

>

> [AMD Official Use Only - General]

>

> Reviewed-by: Abner Chang mailto:abner.ch...@amd.com>>

>

> > -Original Message-

> > From: Igor Kulchytskyy mailto:ig...@ami.com>>

> > Sent: Tuesday, November 7, 2023 8:06 PM

> > To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>

> > Cc: Chang, Abner mailto:abner.ch...@amd.com>>; Nickle 
> > Wang

> > mailto:nick...@nvidia.com>>

> > Subject: [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4

> > installed after RestEx

> >

> > Caution: This message originated from an External Source. Use proper

> > caution when opening attachments, clicking links, or responding.

> >

> >

> > Supported function of the driver changed to wait for all newtwork

> > interface to be installed.

> > Filer out the network interfaces which are not supported by Redfish

> > Host Interface.

> >

> > Cc: Abner Chang mailto:abner.ch...@amd.com>>

> > Cc: Nickle Wang mailto:nick...@nvidia.com>>

> > Signed-off-by: Igor Kulchytskyy mailto:ig...@ami.com>>

> > ---

> >  RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c | 165

> > ++--

> >  1 file changed, 117 insertions(+), 48 deletions(-)

> >

> > diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c

> > b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c

> > index 23da3b968f..85e47843e4 100644

> > --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c

> > +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c

> > @@ -322,9 +322,16 @@ GetTargetNetworkInterfaceInternal (  {

> >EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL

> > *ThisNetworkInterface;

> >

> > +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {

> > +return NULL;

> > +  }

> > +

> >ThisNetworkInterface =

> > (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode

> > (&mEfiRedfishDiscoverNetworkInterface);

> >while (TRUE) {

> > -if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,

> > &TargetNetworkInterface->MacAddress, ThisNetworkInterface-

> > >HwAddressSize) == 0) {

> > +if ((CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,

> > &TargetNetworkInterface->MacAddress, ThisNetworkInterface-

> > >HwAddressSize) == 0) &&

> > +((TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-

> > >NetworkProtocolType == ProtocolTypeTcp6)) ||

> > + (!TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-

> > >NetworkProtocolType == ProtocolTypeTcp4

> > +{

> >return ThisNetworkInterface;

> >  }

> >

> > @@ -354,6 +361,10 @@ GetTargetNetworkInterfaceInternalByController (

> > {

> >EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL

> > *ThisNetworkInterface;

> >

> > +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {

> > +return NULL;

> > +  }

> > +

> >ThisNetworkInterface =

> > (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode

> > (&mEfiRedfishDiscoverNetworkInterface);

> >while (TRUE) {

> >  if (ThisNetworkInterface->OpenDriverControllerHandle ==

> > ControllerHandle) {

> > @@ -476,6 +487,42 @@ CheckIsIpVersion6 (

> >return FALSE;

> >  }

> >

> > +/**

> > +  This function returns the  IP type supported by the Host Interface.

> > +

&

Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4 installed after RestEx

2023-11-07 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Reviewed-by: Abner Chang 

> -Original Message-
> From: Igor Kulchytskyy 
> Sent: Tuesday, November 7, 2023 8:06 PM
> To: devel@edk2.groups.io
> Cc: Chang, Abner ; Nickle Wang
> 
> Subject: [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4 
> installed
> after RestEx
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Supported function of the driver changed to wait for all newtwork
> interface to be installed.
> Filer out the network interfaces which are not supported by
> Redfish Host Interface.
>
> Cc: Abner Chang 
> Cc: Nickle Wang 
> Signed-off-by: Igor Kulchytskyy 
> ---
>  RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c | 165
> ++--
>  1 file changed, 117 insertions(+), 48 deletions(-)
>
> diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> index 23da3b968f..85e47843e4 100644
> --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> @@ -322,9 +322,16 @@ GetTargetNetworkInterfaceInternal (
>  {
>EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
> *ThisNetworkInterface;
>
> +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> +return NULL;
> +  }
> +
>ThisNetworkInterface =
> (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode
> (&mEfiRedfishDiscoverNetworkInterface);
>while (TRUE) {
> -if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,
> &TargetNetworkInterface->MacAddress, ThisNetworkInterface-
> >HwAddressSize) == 0) {
> +if ((CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,
> &TargetNetworkInterface->MacAddress, ThisNetworkInterface-
> >HwAddressSize) == 0) &&
> +((TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-
> >NetworkProtocolType == ProtocolTypeTcp6)) ||
> + (!TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-
> >NetworkProtocolType == ProtocolTypeTcp4
> +{
>return ThisNetworkInterface;
>  }
>
> @@ -354,6 +361,10 @@ GetTargetNetworkInterfaceInternalByController (
>  {
>EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
> *ThisNetworkInterface;
>
> +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> +return NULL;
> +  }
> +
>ThisNetworkInterface =
> (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode
> (&mEfiRedfishDiscoverNetworkInterface);
>while (TRUE) {
>  if (ThisNetworkInterface->OpenDriverControllerHandle ==
> ControllerHandle) {
> @@ -476,6 +487,42 @@ CheckIsIpVersion6 (
>return FALSE;
>  }
>
> +/**
> +  This function returns the  IP type supported by the Host Interface.
> +
> +  @retval 00h is Unknown
> +  01h is Ipv4
> +  02h is Ipv6
> +
> +**/
> +UINT8
> +GetHiIpProtocolType (
> +  VOID
> +  )
> +{
> +  EFI_STATUS Status;
> +  REDFISH_OVER_IP_PROTOCOL_DATA  *Data;
> +  REDFISH_INTERFACE_DATA *DeviceDescriptor;
> +
> +  Data = NULL;
> +  DeviceDescriptor = NULL;
> +  if (mSmbios == NULL) {
> +Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID
> **)&mSmbios);
> +if (EFI_ERROR (Status)) {
> +  return
> REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
> +}
> +  }
> +
> +  Status = RedfishGetHostInterfaceProtocolData (mSmbios,
> &DeviceDescriptor, &Data); // Search for SMBIOS type 42h
> +  if (!EFI_ERROR (Status) && (Data != NULL) &&
> +  (Data->HostIpAssignmentType == RedfishHostIpAssignmentStatic))
> +  {
> +return Data->HostIpAddressFormat;
> +  }
> +
> +  return
> REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
> +}
> +
>  /**
>This function discover Redfish service through SMBIOS host interface.
>
> @@ -512,6 +559,18 @@ DiscoverRedfishHostInterface (
>
>Status = RedfishGetHostInterfaceProtocolData (mSmbios,
> &DeviceDescriptor, &Data); // Search for SMBIOS type 42h
>if (!EFI_ERROR (Status) && (Data != NULL) && (DeviceDescriptor != NULL)) {
> +if ((Instance->NetworkInterface->NetworkProtocolType ==
> ProtocolTypeTcp4) &&
> +(Data->HostIpAddressFormat !=
> REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4)) // IPv4 case
> +{
> +  DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv4, but Host
> Interface requires Ipv6\n", __func__));
> +  return EFI_UNSUPPORTED;
> +} else if ((Instance->NetworkInterface->NetworkProtocolType ==
> ProtocolTypeTcp6) &&
> +   (Data->HostIpAddressFormat !=
> REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6)) // IPv6 case
> +{
> +  DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv6, but Host
> Interface requires IPv4\n", __func__));
> +  return EFI_UNSUPPORTED;
> +}
> +
>  //
>  // Check if we can reach out Redfish service using this network 
> interface.
>  // Check with MAC address using Device Descriptor Data Device Type 04
> 

Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4 installed after RestEx

2023-11-07 Thread Mike Maslenkin



> On 7. 11. 2023., at 15:06, Igor Kulchytskyy via groups.io 
>  wrote:
> 
> Supported function of the driver changed to wait for all newtwork
> interface to be installed.
> Filer out the network interfaces which are not supported by
> Redfish Host Interface.
> 
> Cc: Abner Chang 
> Cc: Nickle Wang 
> Signed-off-by: Igor Kulchytskyy 
> ---
> RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c | 165 ++--
> 1 file changed, 117 insertions(+), 48 deletions(-)
> 
> diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c 
> b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> index 23da3b968f..85e47843e4 100644
> --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> @@ -322,9 +322,16 @@ GetTargetNetworkInterfaceInternal (
> {
>   EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL  *ThisNetworkInterface;
> 
> +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> +return NULL;
> +  }
> +
>   ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL 
> *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
>   while (TRUE) {
> -if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, 
> &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 
> 0) {
> +if ((CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, 
> &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 
> 0) &&
> +((TargetNetworkInterface->IsIpv6 && 
> (ThisNetworkInterface->NetworkProtocolType == ProtocolTypeTcp6)) ||
> + (!TargetNetworkInterface->IsIpv6 && 
> (ThisNetworkInterface->NetworkProtocolType == ProtocolTypeTcp4
> +{
>   return ThisNetworkInterface;
> }
> 
> @@ -354,6 +361,10 @@ GetTargetNetworkInterfaceInternalByController (
> {
>   EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL  *ThisNetworkInterface;
> 
> +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> +return NULL;
> +  }
> +
>   ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL 
> *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
>   while (TRUE) {
> if (ThisNetworkInterface->OpenDriverControllerHandle == ControllerHandle) 
> {
> @@ -476,6 +487,42 @@ CheckIsIpVersion6 (
>   return FALSE;
> }
> 
> +/**
> +  This function returns the  IP type supported by the Host Interface.
> +
> +  @retval 00h is Unknown
> +  01h is Ipv4
> +  02h is Ipv6
> +
> +**/
> +UINT8
> +GetHiIpProtocolType (
> +  VOID
> +  )
> +{
> +  EFI_STATUS Status;
> +  REDFISH_OVER_IP_PROTOCOL_DATA  *Data;
> +  REDFISH_INTERFACE_DATA *DeviceDescriptor;
> +
> +  Data = NULL;
> +  DeviceDescriptor = NULL;
> +  if (mSmbios == NULL) {
> +Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID 
> **)&mSmbios);
> +if (EFI_ERROR (Status)) {
> +  return REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
> +}
> +  }
> +
> +  Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor, 
> &Data); // Search for SMBIOS type 42h
> +  if (!EFI_ERROR (Status) && (Data != NULL) &&
> +  (Data->HostIpAssignmentType == RedfishHostIpAssignmentStatic))
> +  {
> +return Data->HostIpAddressFormat;
> +  }
> +
> +  return REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
> +}
> +
> /**
>   This function discover Redfish service through SMBIOS host interface.
> 
> @@ -512,6 +559,18 @@ DiscoverRedfishHostInterface (
> 
>   Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor, 
> &Data); // Search for SMBIOS type 42h
>   if (!EFI_ERROR (Status) && (Data != NULL) && (DeviceDescriptor != NULL)) {
> +if ((Instance->NetworkInterface->NetworkProtocolType == 
> ProtocolTypeTcp4) &&
> +(Data->HostIpAddressFormat != 
> REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4)) // IPv4 case
> +{
> +  DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv4, but Host 
> Interface requires Ipv6\n", __func__));
> +  return EFI_UNSUPPORTED;
> +} else if ((Instance->NetworkInterface->NetworkProtocolType == 
> ProtocolTypeTcp6) &&
> +   (Data->HostIpAddressFormat != 
> REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6)) // IPv6 case
> +{
> +  DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv6, but Host 
> Interface requires IPv4\n", __func__));
> +  return EFI_UNSUPPORTED;
> +}
> +
> //
> // Check if we can reach out Redfish service using this network interface.
> // Check with MAC address using Device Descriptor Data Device Type 04 and 
> Type 05.
> @@ -1102,6 +1161,7 @@ RedfishServiceGetNetworkInterface (
>   OUT EFI_REDFISH_DISCOVER_NETWORK_INTERFACE  **NetworkIntfInstances
>   )
> {
> +  EFI_STATUS   Status;
>   EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL  *ThisNetworkInterfaceIntn;
>   EFI_REDFISH_DISCOVER_NETWORK_INTERFACE   *ThisNetworkInterface;
>   EFI_REDFISH_DISCOVER_REST_

Re: [edk2-devel] [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4 installed after RestEx

2023-11-07 Thread Nickle Wang via groups.io
Thanks for fixing this issue. This version looks good to me. I test it on my 
system and it works well.

Reviewed-by: Nickle Wang 

Regards,
Nickle

> -Original Message-
> From: Igor Kulchytskyy 
> Sent: Tuesday, November 7, 2023 8:06 PM
> To: devel@edk2.groups.io
> Cc: Abner Chang ; Nickle Wang 
> Subject: [PATCH v3] RedfishPkg: RedfishDiscoverDxe: Fix issue if IPv4 
> installed
> after RestEx
> 
> External email: Use caution opening links or attachments
> 
> 
> Supported function of the driver changed to wait for all newtwork interface 
> to be
> installed.
> Filer out the network interfaces which are not supported by Redfish Host
> Interface.
> 
> Cc: Abner Chang 
> Cc: Nickle Wang 
> Signed-off-by: Igor Kulchytskyy 
> ---
>  RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c | 165 ++---
> ---
>  1 file changed, 117 insertions(+), 48 deletions(-)
> 
> diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> index 23da3b968f..85e47843e4 100644
> --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
> @@ -322,9 +322,16 @@ GetTargetNetworkInterfaceInternal (  {
>EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
> *ThisNetworkInterface;
> 
> +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> +return NULL;
> +  }
> +
>ThisNetworkInterface =
> (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode
> (&mEfiRedfishDiscoverNetworkInterface);
>while (TRUE) {
> -if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,
> &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize)
> == 0) {
> +if ((CompareMem ((VOID *)&ThisNetworkInterface->MacAddress,
> &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize)
> == 0) &&
> +((TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-
> >NetworkProtocolType == ProtocolTypeTcp6)) ||
> + (!TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface-
> >NetworkProtocolType == ProtocolTypeTcp4
> +{
>return ThisNetworkInterface;
>  }
> 
> @@ -354,6 +361,10 @@ GetTargetNetworkInterfaceInternalByController (  {
>EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
> *ThisNetworkInterface;
> 
> +  if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
> +return NULL;
> +  }
> +
>ThisNetworkInterface =
> (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode
> (&mEfiRedfishDiscoverNetworkInterface);
>while (TRUE) {
>  if (ThisNetworkInterface->OpenDriverControllerHandle == ControllerHandle)
> { @@ -476,6 +487,42 @@ CheckIsIpVersion6 (
>return FALSE;
>  }
> 
> +/**
> +  This function returns the  IP type supported by the Host Interface.
> +
> +  @retval 00h is Unknown
> +  01h is Ipv4
> +  02h is Ipv6
> +
> +**/
> +UINT8
> +GetHiIpProtocolType (
> +  VOID
> +  )
> +{
> +  EFI_STATUS Status;
> +  REDFISH_OVER_IP_PROTOCOL_DATA  *Data;
> +  REDFISH_INTERFACE_DATA *DeviceDescriptor;
> +
> +  Data = NULL;
> +  DeviceDescriptor = NULL;
> +  if (mSmbios == NULL) {
> +Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID
> **)&mSmbios);
> +if (EFI_ERROR (Status)) {
> +  return
> REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
> +}
> +  }
> +
> +  Status = RedfishGetHostInterfaceProtocolData (mSmbios,
> + &DeviceDescriptor, &Data); // Search for SMBIOS type 42h  if (!EFI_ERROR
> (Status) && (Data != NULL) &&
> +  (Data->HostIpAssignmentType == RedfishHostIpAssignmentStatic))  {
> +return Data->HostIpAddressFormat;
> +  }
> +
> +  return REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
> +}
> +
>  /**
>This function discover Redfish service through SMBIOS host interface.
> 
> @@ -512,6 +559,18 @@ DiscoverRedfishHostInterface (
> 
>Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor,
> &Data); // Search for SMBIOS type 42h
>if (!EFI_ERROR (Status) && (Data != NULL) && (DeviceDescriptor != NULL)) {
> +if ((Instance->NetworkInterface->NetworkProtocolType == ProtocolTypeTcp4)
> &&
> +(Data->HostIpAddressFormat !=
> REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4)) // IPv4 case
> +{
> +  DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv4, but Host Interface
> requires Ipv6\n", __func__));
> +  return EFI_UNSUPPORTED;
> +} else if ((Instance->NetworkInterface->NetworkProtocolType ==
> ProtocolTypeTcp6) &&
> +   (Data->HostIpAddressFormat !=
> REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6)) // IPv6 case
> +{
> +  DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv6, but Host Interface
> requires IPv4\n", __func__));
> +  return EFI_UNSUPPORTED;
> +}
> +
>  //
>  // Check if we can reach out Redfish service using this network 
> interface.
>  // Check with MAC address using Device Descriptor Data Device Type