]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
MdeModulePkg/Network: Fix potential ASSERT if NetIp4IsUnicast is called
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Impl.c
index e733816556bf888dacb71af921da42a554860a41..3cdf8ecaad06f033a2e5381d0f73ef90e6ba2d35 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 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
@@ -550,6 +550,7 @@ Ip4InitProtocol (
   IpInstance->Signature = IP4_PROTOCOL_SIGNATURE;\r
   CopyMem (&IpInstance->Ip4Proto, &mEfiIp4ProtocolTemplete, sizeof (IpInstance->Ip4Proto));\r
   IpInstance->State     = IP4_STATE_UNCONFIGED;\r
+  IpInstance->InDestroy   = FALSE;\r
   IpInstance->Service   = IpSb;\r
 \r
   InitializeListHead (&IpInstance->Link);\r
@@ -676,8 +677,11 @@ Ip4ConfigProtocol (
     // Use the default address. Check the state.\r
     //\r
     if (IpSb->State == IP4_SERVICE_UNSTARTED) {\r
-      Status = EFI_NO_MAPPING;\r
-      goto ON_ERROR;\r
+      Status = Ip4StartAutoConfig (&IpSb->Ip4Config2Instance);\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        goto ON_ERROR;\r
+      }\r
     }\r
 \r
     IpIf = IpSb->DefaultInterface;\r
@@ -806,66 +810,6 @@ Ip4CleanProtocol (
 }\r
 \r
 \r
-/**\r
-  Validate that Ip/Netmask pair is OK to be used as station\r
-  address. Only continuous netmasks are supported. and check\r
-  that StationAddress is a unicast address on the newtwork.\r
-\r
-  @param[in]  Ip                 The IP address to validate.\r
-  @param[in]  Netmask            The netmaks of the IP.\r
-\r
-  @retval TRUE                   The Ip/Netmask pair is valid.\r
-  @retval FALSE                  The Ip/Netmask pair is invalid.\r
-\r
-**/\r
-BOOLEAN\r
-Ip4StationAddressValid (\r
-  IN IP4_ADDR               Ip,\r
-  IN IP4_ADDR               Netmask\r
-  )\r
-{\r
-  IP4_ADDR                  NetBrdcastMask;\r
-  INTN                      Len;\r
-  INTN                      Type;\r
-\r
-  //\r
-  // Only support the station address with 0.0.0.0/0 to enable DHCP client.\r
-  //\r
-  if (Netmask == IP4_ALLZERO_ADDRESS) {\r
-    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);\r
-  }\r
-\r
-  //\r
-  // Only support the continuous net masks\r
-  //\r
-  if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {\r
-    return FALSE;\r
-  }\r
-\r
-  //\r
-  // Station address can't be class D or class E address\r
-  //\r
-  if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {\r
-    return FALSE;\r
-  }\r
-\r
-  //\r
-  // Station address can't be subnet broadcast/net broadcast address\r
-  //\r
-  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {\r
-    return FALSE;\r
-  }\r
-\r
-  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];\r
-\r
-  if (Ip == (Ip | ~NetBrdcastMask)) {\r
-    return FALSE;\r
-  }\r
-\r
-  return TRUE;\r
-}\r
-\r
-\r
 /**\r
   Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.\r
 \r
@@ -993,8 +937,7 @@ EfiIp4Configure (
     Status = Ip4CleanProtocol (IpInstance);\r
 \r
     //\r
-    // Don't change the state if it is DESTROY, consider the following\r
-    // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,\r
+    // Consider the following valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,\r
     // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,\r
     // the unload fails miserably.\r
     //\r