]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
ShellPkg: Refine casting expression result to bigger size
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6ConfigImpl.c
index 8b389772d9715a388b90e689f9fab44d35935be3..bde5982b69b6883fed9859bd0bf083c1b2ba17c2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of EFI IPv6 Configuration Protocol.\r
 \r
 /** @file\r
   The implementation of EFI IPv6 Configuration Protocol.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -52,7 +52,8 @@ Ip6ConfigOnPolicyChanged (
   LIST_ENTRY      *Next;\r
   IP6_INTERFACE   *IpIf;\r
   IP6_DAD_ENTRY   *DadEntry;\r
   LIST_ENTRY      *Next;\r
   IP6_INTERFACE   *IpIf;\r
   IP6_DAD_ENTRY   *DadEntry;\r
-\r
+  IP6_DELAY_JOIN_LIST       *DelayNode;\r
+  \r
   //\r
   // Currently there are only two policies: Manual and Automatic. Regardless of\r
   // what transition is going on, i.e., Manual -> Automatic and Automatic ->\r
   //\r
   // Currently there are only two policies: Manual and Automatic. Regardless of\r
   // what transition is going on, i.e., Manual -> Automatic and Automatic ->\r
@@ -94,10 +95,18 @@ Ip6ConfigOnPolicyChanged (
 \r
   NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {\r
     //\r
 \r
   NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {\r
     //\r
-    // remove all pending DAD entries for the global addresses.\r
+    // remove all pending delay node and DAD entries for the global addresses.\r
     //\r
     IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);\r
 \r
     //\r
     IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);\r
 \r
+    NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DelayJoinList) {\r
+      DelayNode = NET_LIST_USER_STRUCT (Entry2, IP6_DELAY_JOIN_LIST, Link);\r
+      if (!NetIp6IsLinkLocalAddr (&DelayNode->AddressInfo->Address)) {\r
+        RemoveEntryList (&DelayNode->Link);\r
+        FreePool (DelayNode);\r
+      }\r
+    }\r
+\r
     NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DupAddrDetectList) {\r
       DadEntry = NET_LIST_USER_STRUCT_S (Entry2, IP6_DAD_ENTRY, Link, IP6_DAD_ENTRY_SIGNATURE);\r
 \r
     NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DupAddrDetectList) {\r
       DadEntry = NET_LIST_USER_STRUCT_S (Entry2, IP6_DAD_ENTRY, Link, IP6_DAD_ENTRY_SIGNATURE);\r
 \r
@@ -112,7 +121,7 @@ Ip6ConfigOnPolicyChanged (
 \r
   if (NewPolicy == Ip6ConfigPolicyAutomatic) {\r
     //\r
 \r
   if (NewPolicy == Ip6ConfigPolicyAutomatic) {\r
     //\r
-    // Set paramters to trigger router solicitation sending in timer handler.\r
+    // Set parameters to trigger router solicitation sending in timer handler.\r
     //\r
     IpSb->RouterAdvertiseReceived = FALSE;\r
     IpSb->SolicitTimer            = IP6_MAX_RTR_SOLICITATIONS;\r
     //\r
     IpSb->RouterAdvertiseReceived = FALSE;\r
     IpSb->SolicitTimer            = IP6_MAX_RTR_SOLICITATIONS;\r
@@ -210,9 +219,9 @@ Ip6ConfigStartStatefulAutoConfig (
   // with DNS SERVERS.\r
   //\r
   Oro                         = (EFI_DHCP6_PACKET_OPTION *) OptBuf;\r
   // with DNS SERVERS.\r
   //\r
   Oro                         = (EFI_DHCP6_PACKET_OPTION *) OptBuf;\r
-  Oro->OpCode                 = HTONS (IP6_CONFIG_DHCP6_OPTION_ORO);\r
+  Oro->OpCode                 = HTONS (DHCP6_OPT_ORO);\r
   Oro->OpLen                  = HTONS (2);\r
   Oro->OpLen                  = HTONS (2);\r
-  *((UINT16 *) &Oro->Data[0]) = HTONS (IP6_CONFIG_DHCP6_OPTION_DNS_SERVERS);\r
+  *((UINT16 *) &Oro->Data[0]) = HTONS (DHCP6_OPT_DNS_SERVERS);\r
   OptList[0]                  = Oro;\r
 \r
   Status                      = EFI_SUCCESS;\r
   OptList[0]                  = Oro;\r
 \r
   Status                      = EFI_SUCCESS;\r
@@ -473,7 +482,7 @@ Ip6ConfigWriteConfigData (
 \r
       DataRecord           = &Variable->DataRecord[Variable->DataRecordCount];\r
       DataRecord->DataType = (EFI_IP6_CONFIG_DATA_TYPE) Index;\r
 \r
       DataRecord           = &Variable->DataRecord[Variable->DataRecordCount];\r
       DataRecord->DataType = (EFI_IP6_CONFIG_DATA_TYPE) Index;\r
-      DataRecord->DataSize = DataItem->DataSize;\r
+      DataRecord->DataSize = (UINT32) DataItem->DataSize;\r
       DataRecord->Offset   = (UINT16) (Heap - (CHAR8 *) Variable);\r
 \r
       Variable->DataRecordCount++;\r
       DataRecord->Offset   = (UINT16) (Heap - (CHAR8 *) Variable);\r
 \r
       Variable->DataRecordCount++;\r
@@ -656,36 +665,35 @@ Ip6ConfigSetPolicy (
 \r
     return EFI_ABORTED;\r
   } else {\r
 \r
     return EFI_ABORTED;\r
   } else {\r
-\r
-    if (NewPolicy == Ip6ConfigPolicyAutomatic) {\r
-      //\r
-      // Clean the ManualAddress, Gateway and DnsServers, shrink the variable\r
-      // data size, and fire up all the related events.\r
-      //\r
-      DataItem           = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];\r
-      if (DataItem->Data.Ptr != NULL) {\r
-        FreePool (DataItem->Data.Ptr);\r
-      }\r
-      DataItem->Data.Ptr = NULL;\r
-      DataItem->DataSize = 0;\r
-      DataItem->Status   = EFI_NOT_FOUND;\r
-      NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);\r
-\r
-      DataItem           = &Instance->DataItem[Ip6ConfigDataTypeGateway];\r
-      if (DataItem->Data.Ptr != NULL) {\r
-        FreePool (DataItem->Data.Ptr);\r
-      }\r
-      DataItem->Data.Ptr = NULL;\r
-      DataItem->DataSize = 0;\r
-      DataItem->Status   = EFI_NOT_FOUND;\r
-      NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);\r
-\r
-      DataItem           = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];\r
-      DataItem->Data.Ptr = NULL;\r
-      DataItem->DataSize = 0;\r
-      DataItem->Status   = EFI_NOT_FOUND;\r
-      NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);\r
-    } else {\r
+    //\r
+    // Clean the ManualAddress, Gateway and DnsServers, shrink the variable\r
+    // data size, and fire up all the related events.\r
+    //\r
+    DataItem           = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];\r
+    if (DataItem->Data.Ptr != NULL) {\r
+      FreePool (DataItem->Data.Ptr);\r
+    }\r
+    DataItem->Data.Ptr = NULL;\r
+    DataItem->DataSize = 0;\r
+    DataItem->Status   = EFI_NOT_FOUND;\r
+    NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);\r
+\r
+    DataItem           = &Instance->DataItem[Ip6ConfigDataTypeGateway];\r
+    if (DataItem->Data.Ptr != NULL) {\r
+      FreePool (DataItem->Data.Ptr);\r
+    }\r
+    DataItem->Data.Ptr = NULL;\r
+    DataItem->DataSize = 0;\r
+    DataItem->Status   = EFI_NOT_FOUND;\r
+    NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);\r
+\r
+    DataItem           = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];\r
+    DataItem->Data.Ptr = NULL;\r
+    DataItem->DataSize = 0;\r
+    DataItem->Status   = EFI_NOT_FOUND;\r
+    NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);\r
+    \r
+    if (NewPolicy == Ip6ConfigPolicyManual) {\r
       //\r
       // The policy is changed from automatic to manual. Stop the DHCPv6 process\r
       // and destroy the DHCPv6 child.\r
       //\r
       // The policy is changed from automatic to manual. Stop the DHCPv6 process\r
       // and destroy the DHCPv6 child.\r
@@ -1012,6 +1020,14 @@ Ip6ConfigSetMaunualAddress (
         128\r
         );\r
 \r
         128\r
         );\r
 \r
+      //\r
+      // If the new address's prefix length is not specified, just use the previous configured\r
+      // prefix length for this address.\r
+      //\r
+      if (NewAddress->PrefixLength == 0) {\r
+        NewAddress->PrefixLength = CurrentAddrInfo->PrefixLength;\r
+      }\r
+\r
       //\r
       // This manual address is already in use, see whether prefix length is changed.\r
       //\r
       //\r
       // This manual address is already in use, see whether prefix length is changed.\r
       //\r
@@ -1311,7 +1327,6 @@ Ip6ConfigSetDnsServer (
 {\r
   UINTN                 OldIndex;\r
   UINTN                 NewIndex;\r
 {\r
   UINTN                 OldIndex;\r
   UINTN                 NewIndex;\r
-  UINTN                 Index1;\r
   EFI_IPv6_ADDRESS      *OldDns;\r
   EFI_IPv6_ADDRESS      *NewDns;\r
   UINTN                 OldDnsCount;\r
   EFI_IPv6_ADDRESS      *OldDns;\r
   EFI_IPv6_ADDRESS      *NewDns;\r
   UINTN                 OldDnsCount;\r
@@ -1350,15 +1365,10 @@ Ip6ConfigSetDnsServer (
       //\r
       // The dns server address must be unicast.\r
       //\r
       //\r
       // The dns server address must be unicast.\r
       //\r
-      FreePool (Tmp);\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-\r
-    for (Index1 = NewIndex + 1; Index1 < NewDnsCount; Index1++) {\r
-      if (EFI_IP6_EQUAL (NewDns + NewIndex, NewDns + Index1)) {\r
+      if (Tmp != NULL) {\r
         FreePool (Tmp);\r
         FreePool (Tmp);\r
-        return EFI_INVALID_PARAMETER;\r
       }\r
       }\r
+      return EFI_INVALID_PARAMETER;\r
     }\r
 \r
     if (OneAdded) {\r
     }\r
 \r
     if (OneAdded) {\r
@@ -1418,11 +1428,12 @@ Ip6ConfigInitIfInfo (
   OUT EFI_IP6_CONFIG_INTERFACE_INFO  *IfInfo\r
   )\r
 {\r
   OUT EFI_IP6_CONFIG_INTERFACE_INFO  *IfInfo\r
   )\r
 {\r
-  IfInfo->Name[0] = L'e';\r
-  IfInfo->Name[1] = L't';\r
-  IfInfo->Name[2] = L'h';\r
-  IfInfo->Name[3] = (CHAR16) (L'0' + IpSb->Ip6ConfigInstance.IfIndex);\r
-  IfInfo->Name[4] = 0;\r
+  UnicodeSPrint (\r
+    IfInfo->Name,\r
+    sizeof (IfInfo->Name),\r
+    L"eth%d",\r
+    IpSb->Ip6ConfigInstance.IfIndex\r
+  );\r
 \r
   IfInfo->IfType        = IpSb->SnpMode.IfType;\r
   IfInfo->HwAddressSize = IpSb->SnpMode.HwAddressSize;\r
 \r
   IfInfo->IfType        = IpSb->SnpMode.IfType;\r
   IfInfo->HwAddressSize = IpSb->SnpMode.HwAddressSize;\r
@@ -1491,7 +1502,7 @@ Ip6ConfigParseDhcpReply (
     CopyMem (&OpCode, &OptList[Index]->OpCode, sizeof (OpCode));\r
     OpCode = NTOHS (OpCode);\r
 \r
     CopyMem (&OpCode, &OptList[Index]->OpCode, sizeof (OpCode));\r
     OpCode = NTOHS (OpCode);\r
 \r
-    if (OpCode == IP6_CONFIG_DHCP6_OPTION_DNS_SERVERS) {\r
+    if (OpCode == DHCP6_OPT_DNS_SERVERS) {\r
       CopyMem (&Length, &OptList[Index]->OpLen, sizeof (Length));\r
       Length = NTOHS (Length);\r
 \r
       CopyMem (&Length, &OptList[Index]->OpLen, sizeof (Length));\r
       Length = NTOHS (Length);\r
 \r
@@ -1594,11 +1605,13 @@ Ip6ConfigSetStatefulAddrCallback (
       //\r
       // Decline those duplicates.\r
       //\r
       //\r
       // Decline those duplicates.\r
       //\r
-      Instance->Dhcp6->Decline (\r
-                         Instance->Dhcp6,\r
-                         Instance->DeclineAddressCount,\r
-                         Instance->DeclineAddress\r
-                         );\r
+      if (Instance->Dhcp6 != NULL) {\r
+        Instance->Dhcp6->Decline (\r
+                           Instance->Dhcp6,\r
+                           Instance->DeclineAddressCount,\r
+                           Instance->DeclineAddress\r
+                           );\r
+      }\r
     }\r
 \r
     if (Instance->DeclineAddress != NULL) {\r
     }\r
 \r
     if (Instance->DeclineAddress != NULL) {\r
@@ -2190,7 +2203,7 @@ Ip6ConfigInitInstance (
   DataItem->SetData  = Ip6ConfigSetPolicy;\r
   DataItem->Data.Ptr = &Instance->Policy;\r
   DataItem->DataSize = sizeof (Instance->Policy);\r
   DataItem->SetData  = Ip6ConfigSetPolicy;\r
   DataItem->Data.Ptr = &Instance->Policy;\r
   DataItem->DataSize = sizeof (Instance->Policy);\r
-  Instance->Policy   = Ip6ConfigPolicyAutomatic;\r
+  Instance->Policy   = Ip6ConfigPolicyManual;\r
   SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);\r
 \r
   DataItem           = &Instance->DataItem[Ip6ConfigDataTypeDupAddrDetectTransmits];\r
   SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);\r
 \r
   DataItem           = &Instance->DataItem[Ip6ConfigDataTypeDupAddrDetectTransmits];\r
@@ -2316,12 +2329,12 @@ Ip6ConfigCleanInstance (
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
-  Destory the Dhcp6 child in IP6_CONFIG_INSTANCE and release the resources.\r
+  Destroy the Dhcp6 child in IP6_CONFIG_INSTANCE and release the resources.\r
 \r
   @param[in, out] Instance    The buffer of IP6_CONFIG_INSTANCE to be freed.\r
 \r
   @retval EFI_SUCCESS         The child was successfully destroyed.\r
 \r
   @param[in, out] Instance    The buffer of IP6_CONFIG_INSTANCE to be freed.\r
 \r
   @retval EFI_SUCCESS         The child was successfully destroyed.\r
-  @retval Others              Failed to destory the child.\r
+  @retval Others              Failed to destroy the child.\r
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r