]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
MdeModulePkg: Update IP4 stack drivers for classless address unicast check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Config2Nv.c
index ee771e3d6df5cc60db21a8b6e2781c216ae44310..8eea8877bfb4b7f62f6f9589c7030ec6e293a97e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper functions for configuring or getting the parameters relating to Ip4.\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -608,20 +608,20 @@ Ip4Config2ConvertIfrNvDataToConfigNvData (
     //\r
     Ip4NvData->Policy = Ip4Config2PolicyStatic;\r
 \r
-    Status = Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationAddress.v4);\r
-    if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (StationAddress.Addr[0]), 0)) {\r
-      CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-    \r
     Status = Ip4Config2StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v4);\r
     if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);\r
       return EFI_INVALID_PARAMETER;\r
     }\r
+\r
+    Status = Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationAddress.v4);\r
+    if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (StationAddress.Addr[0]), NTOHL (SubnetMask.Addr[0]))) {\r
+      CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
     \r
     Status = Ip4Config2StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);\r
-    if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
+    if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL (SubnetMask.Addr[0])))) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
       return EFI_INVALID_PARAMETER;\r
     }\r
@@ -630,7 +630,7 @@ Ip4Config2ConvertIfrNvDataToConfigNvData (
     if (!EFI_ERROR (Status) && DnsCount > 0) {\r
       for (Index = 0; Index < DnsCount; Index ++) {\r
         CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR));\r
-        if (!NetIp4IsUnicast (NTOHL (Ip), 0)) {\r
+        if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {\r
           CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);\r
           FreePool(DnsAddress);\r
           return EFI_INVALID_PARAMETER;\r
@@ -1146,7 +1146,7 @@ Ip4FormCallback (
     switch (QuestionId) {\r
     case KEY_LOCAL_IP:\r
       Status = Ip4Config2StrToIp (IfrFormNvData->StationAddress, &StationAddress.v4);\r
-      if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (StationAddress.Addr[0]), 0)) {\r
+      if (EFI_ERROR (Status) || IP4_IS_UNSPECIFIED (NTOHL (StationAddress.Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (StationAddress.Addr[0]))) {\r
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
         Status = EFI_INVALID_PARAMETER;\r
       }\r
@@ -1162,7 +1162,7 @@ Ip4FormCallback (
 \r
     case KEY_GATE_WAY:\r
       Status = Ip4Config2StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);\r
-      if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
+      if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST(NTOHL(Gateway.Addr[0]))) {\r
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
         Status = EFI_INVALID_PARAMETER;\r
       }\r
@@ -1173,7 +1173,7 @@ Ip4FormCallback (
       if (!EFI_ERROR (Status) && DnsCount > 0) {\r
         for (Index = 0; Index < DnsCount; Index ++) {\r
           CopyMem (&Ip, &DnsAddress[Index], sizeof (IP4_ADDR));\r
-          if (!NetIp4IsUnicast (NTOHL (Ip), 0)) {\r
+          if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {\r
             CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Dns Server!", NULL);\r
             Status = EFI_INVALID_PARAMETER;\r
             break;\r