NetworkPkg: remove unnecessary timeout event when setting IPv6 address.
authorFu Siyuan <siyuan.fu@intel.com>
Thu, 15 Oct 2015 06:42:50 +0000 (06:42 +0000)
committersfu5 <sfu5@Edk2>
Thu, 15 Oct 2015 06:42:50 +0000 (06:42 +0000)
Use Ip6Cfg->SetData() to set IP6 manual address is asynchronous process and the
registered data notify event will be singled when process is done. So it's not
necessary to create another timeout event for the address setting.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18610 6f19259b-4bc3-4df7-8a09-765794883524

NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c

index 35bdc57479caf54e17ca591861a28d41a6cd082c..6ad5f5f1ac9fd5eb318a3fcd55e597d13e92dbd7 100644 (file)
@@ -1376,16 +1376,15 @@ PxeBcRegisterIp6Address (
   EFI_IP6_CONFIG_MANUAL_ADDRESS    CfgAddr;\r
   EFI_IPv6_ADDRESS                 GatewayAddr;\r
   UINTN                            DataSize;\r
-  EFI_EVENT                        TimeOutEvt;\r
   EFI_EVENT                        MappedEvt;\r
   EFI_STATUS                       Status;\r
-  UINT64                           DadTriggerTime;\r
-  EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS    DadXmits;\r
   BOOLEAN                          NoGateway;\r
+  EFI_IPv6_ADDRESS                 *Ip6Addr;\r
+  UINTN                            Index;\r
 \r
   Status     = EFI_SUCCESS;\r
-  TimeOutEvt = NULL;\r
   MappedEvt  = NULL;\r
+  Ip6Addr    = NULL;\r
   DataSize   = sizeof (EFI_IP6_CONFIG_POLICY);\r
   Ip6Cfg     = Private->Ip6Cfg;\r
   Ip6        = Private->Ip6;\r
@@ -1426,34 +1425,6 @@ PxeBcRegisterIp6Address (
     goto ON_EXIT;\r
   }\r
 \r
-  //\r
-  // Get Duplicate Address Detection Transmits count.\r
-  //\r
-  DataSize = sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS);\r
-  Status = Ip6Cfg->GetData (\r
-                     Ip6Cfg,\r
-                     Ip6ConfigDataTypeDupAddrDetectTransmits,\r
-                     &DataSize,\r
-                     &DadXmits\r
-                     );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  //\r
-  // Create a timer as setting address timeout event since DAD in IP6 driver.\r
-  //\r
-  Status = gBS->CreateEvent (\r
-                  EVT_TIMER,\r
-                  TPL_CALLBACK,\r
-                  NULL,\r
-                  NULL,\r
-                  &TimeOutEvt\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_EXIT;\r
-  }\r
-\r
   //\r
   // Create a notify event to set address flag when DAD if IP6 driver succeeded.\r
   //\r
@@ -1468,6 +1439,7 @@ PxeBcRegisterIp6Address (
     goto ON_EXIT;\r
   }\r
 \r
+  Private->IsAddressOk = FALSE;\r
   Status = Ip6Cfg->RegisterDataNotify (\r
                      Ip6Cfg,\r
                      Ip6ConfigDataTypeManualAddress,\r
@@ -1485,23 +1457,54 @@ PxeBcRegisterIp6Address (
                      );\r
   if (EFI_ERROR(Status) && Status != EFI_NOT_READY) {\r
     goto ON_EXIT;\r
-  }\r
+  } else if (Status == EFI_NOT_READY) {\r
+    //\r
+    // Poll the network until the asynchronous process is finished.\r
+    //\r
+    while (!Private->IsAddressOk) {\r
+      Ip6->Poll (Ip6);\r
+    }\r
+    //\r
+    // Check whether the IP6 address setting is successed.\r
+    //\r
+    DataSize = 0;\r
+    Status = Ip6Cfg->GetData (\r
+                       Ip6Cfg,\r
+                       Ip6ConfigDataTypeManualAddress,\r
+                       &DataSize,\r
+                       NULL\r
+                       );\r
+    if (Status != EFI_BUFFER_TOO_SMALL || DataSize == 0) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto ON_EXIT;\r
+    }\r
 \r
-  //\r
-  // Start the 5 secondes timer to wait for setting address.\r
-  //\r
-  Status = EFI_NO_MAPPING;\r
-  DadTriggerTime = TICKS_PER_SECOND * DadXmits.DupAddrDetectTransmits + PXEBC_DAD_ADDITIONAL_DELAY;\r
-  gBS->SetTimer (TimeOutEvt, TimerRelative, DadTriggerTime);\r
+    Ip6Addr = AllocatePool (DataSize);\r
+    if (Ip6Addr == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Status = Ip6Cfg->GetData (\r
+                       Ip6Cfg,\r
+                       Ip6ConfigDataTypeManualAddress,\r
+                       &DataSize,\r
+                       (VOID*) Ip6Addr\r
+                       );\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto ON_EXIT;\r
+    }\r
 \r
-  while (EFI_ERROR (gBS->CheckEvent (TimeOutEvt))) {\r
-    Ip6->Poll (Ip6);\r
-    if (Private->IsAddressOk) {\r
-      Status = EFI_SUCCESS;\r
-      break;\r
+    for (Index = 0; Index < DataSize / sizeof (EFI_IPv6_ADDRESS); Index++) {\r
+      if (CompareMem (Ip6Addr + Index, Address, sizeof (EFI_IPv6_ADDRESS)) == 0) {\r
+        break;\r
+      }\r
+    }\r
+    if (Index == DataSize / sizeof (EFI_IPv6_ADDRESS)) {\r
+      Status = EFI_ABORTED;\r
+      goto ON_EXIT;\r
     }\r
   }\r
-\r
+  \r
   //\r
   // Set the default gateway address back if needed.\r
   //\r
@@ -1526,8 +1529,8 @@ ON_EXIT:
               );\r
     gBS->CloseEvent (MappedEvt);\r
   }\r
-  if (TimeOutEvt != NULL) {\r
-    gBS->CloseEvent (TimeOutEvt);\r
+  if (Ip6Addr != NULL) {\r
+    FreePool (Ip6Addr);\r
   }\r
   return Status;\r
 }\r