]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Nv.c
MdeModulePkg/Ip4Dxe: Refine the IPv4 configuration help info
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Config2Nv.c
index ee771e3d6df5cc60db21a8b6e2781c216ae44310..c8dc6976d751941486435f470b31a1a77f48de43 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 - 2017, 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,23 @@ 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) || \r
+        (SubnetMask.Addr[0] != 0 && !NetIp4IsUnicast (NTOHL (StationAddress.Addr[0]), NTOHL (SubnetMask.Addr[0]))) || \r
+        !Ip4StationAddressValid (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) || \r
+        (Gateway.Addr[0] != 0 && SubnetMask.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 +633,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 +1149,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 +1165,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 +1176,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