]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
MdeModulePkg: Update IP4 stack to support point-to-point link with 31-bit mask.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Common.c
index bd66f63527f987158074d1d34f2a1e343bc6b487..b582ccf13f66836768ed6e7e57865ef6af269e3e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\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
 http://opensource.org/licenses/bsd-license.php\r
@@ -270,148 +270,43 @@ Ip4NtohHead (
 \r
 \r
 /**\r
-  Set the Ip4 variable data.\r
-  \r
-  Save the list of all of the IPv4 addresses and subnet masks that are currently\r
-  being used to volatile variable storage.\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]  IpSb                  Ip4 service binding instance\r
+  @param[in]  Ip                 The IP address to validate.\r
+  @param[in]  Netmask            The netmaks of the IP.\r
 \r
-  @retval EFI_SUCCESS           Successfully set variable.\r
-  @retval EFI_OUT_OF_RESOURCES  There are not enough resources to set the variable.\r
-  @retval other                 Set variable failed.\r
+  @retval TRUE                   The Ip/Netmask pair is valid.\r
+  @retval FALSE                  The Ip/Netmask pair is invalid.\r
 \r
 **/\r
-EFI_STATUS\r
-Ip4SetVariableData (\r
-  IN IP4_SERVICE  *IpSb\r
+BOOLEAN\r
+Ip4StationAddressValid (\r
+  IN IP4_ADDR               Ip,\r
+  IN IP4_ADDR               Netmask\r
   )\r
 {\r
-  UINT32                 NumConfiguredInstance;\r
-  LIST_ENTRY             *Entry;\r
-  UINTN                  VariableDataSize;\r
-  EFI_IP4_VARIABLE_DATA  *Ip4VariableData;\r
-  EFI_IP4_ADDRESS_PAIR   *Ip4AddressPair;\r
-  IP4_PROTOCOL           *IpInstance;\r
-  CHAR16                 *NewMacString;\r
-  EFI_STATUS             Status;\r
-\r
-  NumConfiguredInstance = 0;\r
-\r
   //\r
-  // Go through the children list to count the configured children.\r
+  // Only support the station address with 0.0.0.0/0 to enable DHCP client.\r
   //\r
-  NET_LIST_FOR_EACH (Entry, &IpSb->Children) {\r
-    IpInstance = NET_LIST_USER_STRUCT_S (Entry, IP4_PROTOCOL, Link, IP4_PROTOCOL_SIGNATURE);\r
-\r
-    if (IpInstance->State == IP4_STATE_CONFIGED) {\r
-      NumConfiguredInstance++;\r
-    }\r
+  if (Netmask == IP4_ALLZERO_ADDRESS) {\r
+    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);\r
   }\r
 \r
   //\r
-  // Calculate the size of the Ip4VariableData. As there may be no IP child,\r
-  // we should add extra buffer for the address paris only if the number of configured\r
-  // children is more than 1.\r
+  // Only support the continuous net masks\r
   //\r
-  VariableDataSize = sizeof (EFI_IP4_VARIABLE_DATA);\r
-\r
-  if (NumConfiguredInstance > 1) {\r
-    VariableDataSize += sizeof (EFI_IP4_ADDRESS_PAIR) * (NumConfiguredInstance - 1);\r
+  if (NetGetMaskLength (Netmask) == (IP4_MASK_MAX + 1)) {\r
+    return FALSE;\r
   }\r
 \r
-  Ip4VariableData = AllocatePool (VariableDataSize);\r
-  if (Ip4VariableData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Ip4VariableData->DriverHandle = IpSb->Image;\r
-  Ip4VariableData->AddressCount = NumConfiguredInstance;\r
-\r
-  Ip4AddressPair = &Ip4VariableData->AddressPairs[0];\r
-\r
   //\r
-  // Go through the children list to fill the configured children's address pairs.\r
+  // Station address can't be class D or class E address\r
   //\r
-  NET_LIST_FOR_EACH (Entry, &IpSb->Children) {\r
-    IpInstance = NET_LIST_USER_STRUCT_S (Entry, IP4_PROTOCOL, Link, IP4_PROTOCOL_SIGNATURE);\r
-\r
-    if (IpInstance->State == IP4_STATE_CONFIGED) {\r
-      Ip4AddressPair->InstanceHandle       = IpInstance->Handle;\r
-      EFI_IP4 (Ip4AddressPair->Ip4Address) = NTOHL (IpInstance->Interface->Ip);\r
-      EFI_IP4 (Ip4AddressPair->SubnetMask) = NTOHL (IpInstance->Interface->SubnetMask);\r
-\r
-      Ip4AddressPair++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get the mac string.\r
-  //\r
-  Status = NetLibGetMacString (IpSb->Controller, IpSb->Image, &NewMacString);\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  if (IpSb->MacString != NULL) {\r
-    //\r
-    // The variable is set already, we're going to update it.\r
-    //\r
-    if (StrCmp (IpSb->MacString, NewMacString) != 0) {\r
-      //\r
-      // The mac address is changed, delete the previous variable first.\r
-      //\r
-      gRT->SetVariable (\r
-             IpSb->MacString,\r
-             &gEfiIp4ServiceBindingProtocolGuid,\r
-             EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-             0,\r
-             NULL\r
-             );\r
-    }\r
-\r
-    FreePool (IpSb->MacString);\r
+  if (NetGetIpClass (Ip) > IP4_ADDR_CLASSC) {\r
+    return FALSE;\r
   }\r
 \r
-  IpSb->MacString = NewMacString;\r
-\r
-  Status = gRT->SetVariable (\r
-                  IpSb->MacString,\r
-                  &gEfiIp4ServiceBindingProtocolGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                  VariableDataSize,\r
-                  (VOID *) Ip4VariableData\r
-                  );\r
-\r
-ON_ERROR:\r
-\r
-  FreePool (Ip4VariableData);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Clear the variable and free the resource.\r
-\r
-  @param[in]  IpSb                  Ip4 service binding instance\r
-\r
-**/\r
-VOID\r
-Ip4ClearVariableData (\r
-  IN IP4_SERVICE  *IpSb\r
-  )\r
-{\r
-  ASSERT (IpSb->MacString != NULL);\r
-\r
-  gRT->SetVariable (\r
-         IpSb->MacString,\r
-         &gEfiIp4ServiceBindingProtocolGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-         0,\r
-         NULL\r
-         );\r
-\r
-  FreePool (IpSb->MacString);\r
-  IpSb->MacString = NULL;\r
+  return NetIp4IsUnicast (Ip, Netmask);\r
 }\r