@@ -322,9 +322,16 @@ GetTargetNetworkInterfaceInternal (
322322{
323323 EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * ThisNetworkInterface ;
324324
325+ if (IsListEmpty (& mEfiRedfishDiscoverNetworkInterface )) {
326+ return NULL ;
327+ }
328+
325329 ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * )GetFirstNode (& mEfiRedfishDiscoverNetworkInterface );
326330 while (TRUE) {
327- if (CompareMem ((VOID * )& ThisNetworkInterface -> MacAddress , & TargetNetworkInterface -> MacAddress , ThisNetworkInterface -> HwAddressSize ) == 0 ) {
331+ if ((MAC_COMPARE (ThisNetworkInterface , TargetNetworkInterface ) == 0 ) &&
332+ (VALID_TCP6 (TargetNetworkInterface , ThisNetworkInterface ) ||
333+ VALID_TCP4 (TargetNetworkInterface , ThisNetworkInterface )))
334+ {
328335 return ThisNetworkInterface ;
329336 }
330337
@@ -354,6 +361,10 @@ GetTargetNetworkInterfaceInternalByController (
354361{
355362 EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * ThisNetworkInterface ;
356363
364+ if (IsListEmpty (& mEfiRedfishDiscoverNetworkInterface )) {
365+ return NULL ;
366+ }
367+
357368 ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * )GetFirstNode (& mEfiRedfishDiscoverNetworkInterface );
358369 while (TRUE) {
359370 if (ThisNetworkInterface -> OpenDriverControllerHandle == ControllerHandle ) {
@@ -476,6 +487,42 @@ CheckIsIpVersion6 (
476487 return FALSE;
477488}
478489
490+ /**
491+ This function returns the IP type supported by the Host Interface.
492+
493+ @retval 00h is Unknown
494+ 01h is Ipv4
495+ 02h is Ipv6
496+
497+ **/
498+ UINT8
499+ GetHiIpProtocolType (
500+ VOID
501+ )
502+ {
503+ EFI_STATUS Status ;
504+ REDFISH_OVER_IP_PROTOCOL_DATA * Data ;
505+ REDFISH_INTERFACE_DATA * DeviceDescriptor ;
506+
507+ Data = NULL ;
508+ DeviceDescriptor = NULL ;
509+ if (mSmbios == NULL ) {
510+ Status = gBS -> LocateProtocol (& gEfiSmbiosProtocolGuid , NULL , (VOID * * )& mSmbios );
511+ if (EFI_ERROR (Status )) {
512+ return REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN ;
513+ }
514+ }
515+
516+ Status = RedfishGetHostInterfaceProtocolData (mSmbios , & DeviceDescriptor , & Data ); // Search for SMBIOS type 42h
517+ if (!EFI_ERROR (Status ) && (Data != NULL ) &&
518+ (Data -> HostIpAssignmentType == RedfishHostIpAssignmentStatic ))
519+ {
520+ return Data -> HostIpAddressFormat ;
521+ }
522+
523+ return REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN ;
524+ }
525+
479526/**
480527 This function discover Redfish service through SMBIOS host interface.
481528
@@ -512,6 +559,18 @@ DiscoverRedfishHostInterface (
512559
513560 Status = RedfishGetHostInterfaceProtocolData (mSmbios , & DeviceDescriptor , & Data ); // Search for SMBIOS type 42h
514561 if (!EFI_ERROR (Status ) && (Data != NULL ) && (DeviceDescriptor != NULL )) {
562+ if ((Instance -> NetworkInterface -> NetworkProtocolType == ProtocolTypeTcp4 ) &&
563+ (Data -> HostIpAddressFormat != REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4 )) // IPv4 case
564+ {
565+ DEBUG ((DEBUG_ERROR , "%a: Network Interface is IPv4, but Host Interface requires Ipv6\n" , __func__ ));
566+ return EFI_UNSUPPORTED ;
567+ } else if ((Instance -> NetworkInterface -> NetworkProtocolType == ProtocolTypeTcp6 ) &&
568+ (Data -> HostIpAddressFormat != REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6 )) // IPv6 case
569+ {
570+ DEBUG ((DEBUG_ERROR , "%a: Network Interface is IPv6, but Host Interface requires IPv4\n" , __func__ ));
571+ return EFI_UNSUPPORTED ;
572+ }
573+
515574 //
516575 // Check if we can reach out Redfish service using this network interface.
517576 // Check with MAC address using Device Descriptor Data Device Type 04 and Type 05.
@@ -1102,6 +1161,7 @@ RedfishServiceGetNetworkInterface (
11021161 OUT EFI_REDFISH_DISCOVER_NETWORK_INTERFACE * * NetworkIntfInstances
11031162 )
11041163{
1164+ EFI_STATUS Status ;
11051165 EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * ThisNetworkInterfaceIntn ;
11061166 EFI_REDFISH_DISCOVER_NETWORK_INTERFACE * ThisNetworkInterface ;
11071167 EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL * RestExInstance ;
@@ -1141,13 +1201,23 @@ RedfishServiceGetNetworkInterface (
11411201
11421202 ThisNetworkInterfaceIntn = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * )GetFirstNode (& mEfiRedfishDiscoverNetworkInterface );
11431203 while (TRUE) {
1204+ // If Get Subnet Info failed then skip this interface
1205+ Status = NetworkInterfaceGetSubnetInfo (ThisNetworkInterfaceIntn , ImageHandle ); // Get subnet info
1206+ if (EFI_ERROR (Status )) {
1207+ if (IsNodeAtEnd (& mEfiRedfishDiscoverNetworkInterface , & ThisNetworkInterfaceIntn -> Entry )) {
1208+ break ;
1209+ }
1210+
1211+ ThisNetworkInterfaceIntn = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * )GetNextNode (& mEfiRedfishDiscoverNetworkInterface , & ThisNetworkInterfaceIntn -> Entry );
1212+ continue ;
1213+ }
1214+
11441215 ThisNetworkInterface -> IsIpv6 = FALSE;
11451216 if (CheckIsIpVersion6 (ThisNetworkInterfaceIntn )) {
11461217 ThisNetworkInterface -> IsIpv6 = TRUE;
11471218 }
11481219
11491220 CopyMem ((VOID * )& ThisNetworkInterface -> MacAddress , & ThisNetworkInterfaceIntn -> MacAddress , ThisNetworkInterfaceIntn -> HwAddressSize );
1150- NetworkInterfaceGetSubnetInfo (ThisNetworkInterfaceIntn , ImageHandle ); // Get subnet info.
11511221 if (!ThisNetworkInterface -> IsIpv6 ) {
11521222 IP4_COPY_ADDRESS (& ThisNetworkInterface -> SubnetId .v4 , & ThisNetworkInterfaceIntn -> SubnetAddr .v4 ); // IPv4 subnet information.
11531223 } else {
@@ -1230,7 +1300,12 @@ RedfishServiceAcquireService (
12301300
12311301 if (TargetNetworkInterface != NULL ) {
12321302 TargetNetworkInterfaceInternal = GetTargetNetworkInterfaceInternal (TargetNetworkInterface );
1233- NumNetworkInterfaces = 1 ;
1303+ if (TargetNetworkInterfaceInternal == NULL ) {
1304+ DEBUG ((DEBUG_ERROR , "%a:No network interface on platform.\n" , __func__ ));
1305+ return EFI_UNSUPPORTED ;
1306+ }
1307+
1308+ NumNetworkInterfaces = 1 ;
12341309 } else {
12351310 TargetNetworkInterfaceInternal = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * )GetFirstNode (& mEfiRedfishDiscoverNetworkInterface );
12361311 NumNetworkInterfaces = NumberOfNetworkInterface ();
@@ -1260,7 +1335,13 @@ RedfishServiceAcquireService (
12601335 // Get subnet information in case subnet information is not set because
12611336 // RedfishServiceGetNetworkInterfaces hasn't been called yet.
12621337 //
1263- NetworkInterfaceGetSubnetInfo (TargetNetworkInterfaceInternal , ImageHandle );
1338+ Status1 = NetworkInterfaceGetSubnetInfo (TargetNetworkInterfaceInternal , ImageHandle );
1339+ if (EFI_ERROR (Status1 )) {
1340+ DEBUG ((DEBUG_ERROR , "%a: Get subnet information fail.\n" , __func__ ));
1341+ FreePool (Instance );
1342+ continue ;
1343+ }
1344+
12641345 NewInstance = TRUE;
12651346 }
12661347
@@ -1601,10 +1682,22 @@ BuildupNetworkInterface (
16011682 EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL * RestExInstance ;
16021683 EFI_TPL OldTpl ;
16031684 BOOLEAN NewNetworkInterfaceInstalled ;
1685+ UINT8 IpType ;
1686+ UINTN ListCount ;
16041687
1688+ ListCount = (sizeof (gRequiredProtocol ) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL ));
16051689 NewNetworkInterfaceInstalled = FALSE;
16061690 Index = 0 ;
1607- do {
1691+
1692+ // Get IP Type to filter out unnecessary network protocol if possible
1693+ IpType = GetHiIpProtocolType ();
1694+
1695+ for (Index = 0 ; Index < ListCount ; Index ++ ) {
1696+ // Check IP Type and skip an unnecessary network protocol if does not match
1697+ if (IS_TCP4_MATCH (IpType ) || IS_TCP6_MATCH (IpType )) {
1698+ continue ;
1699+ }
1700+
16081701 Status = gBS -> OpenProtocol (
16091702 // Already in list?
16101703 ControllerHandle ,
@@ -1615,11 +1708,6 @@ BuildupNetworkInterface (
16151708 EFI_OPEN_PROTOCOL_GET_PROTOCOL
16161709 );
16171710 if (!EFI_ERROR (Status )) {
1618- Index ++ ;
1619- if (Index == (sizeof (gRequiredProtocol ) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL ))) {
1620- break ;
1621- }
1622-
16231711 continue ;
16241712 }
16251713
@@ -1632,11 +1720,6 @@ BuildupNetworkInterface (
16321720 EFI_OPEN_PROTOCOL_GET_PROTOCOL
16331721 );
16341722 if (EFI_ERROR (Status )) {
1635- Index ++ ;
1636- if (Index == (sizeof (gRequiredProtocol ) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL ))) {
1637- break ;
1638- }
1639-
16401723 continue ;
16411724 }
16421725
@@ -1695,11 +1778,6 @@ BuildupNetworkInterface (
16951778 ProtocolDiscoverIdPtr
16961779 );
16971780 if (EFI_ERROR (Status )) {
1698- Index ++ ;
1699- if (Index == (sizeof (gRequiredProtocol ) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL ))) {
1700- break ;
1701- }
1702-
17031781 continue ;
17041782 }
17051783
@@ -1756,25 +1834,13 @@ BuildupNetworkInterface (
17561834 }
17571835 } else {
17581836 DEBUG ((DEBUG_MANAGEABILITY , "%a: Not REST EX, continue with next\n" , __func__ ));
1759- Index ++ ;
1760- if (Index == (sizeof (gRequiredProtocol ) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL ))) {
1761- break ;
1762- }
1763-
17641837 continue ;
17651838 }
17661839 }
17671840
17681841 return Status ;
1769- } else {
1770- Index ++ ;
1771- if (Index == (sizeof (gRequiredProtocol ) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL ))) {
1772- break ;
1773- }
1774-
1775- continue ;
17761842 }
1777- } while ( Index < ( sizeof ( gRequiredProtocol ) / sizeof ( REDFISH_DISCOVER_REQUIRED_PROTOCOL )));
1843+ }
17781844
17791845 return EFI_DEVICE_ERROR ;
17801846}
0 commit comments