]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Fix 'ifconfig' can't get the address from dhcp in some case
authorJiaxin Wu <jiaxin.wu@intel.com>
Thu, 20 Aug 2015 06:45:19 +0000 (06:45 +0000)
committerjiaxinwu <jiaxinwu@Edk2>
Thu, 20 Aug 2015 06:45:19 +0000 (06:45 +0000)
R18201 fix caused ifconfig in shell failed to get the address from dhcp with the
command "ifconfig -s eth0 dhcp" since the default policy is dhcp already.
We can fix it by following the rule to starting the Ip4 auto configuration.

Cc: Ye Ting <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviwed-by: Ye Ting <ting.ye@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18244 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c

index df19a9f90240a20d6f39ef0238d1aa2b327640bb..273f1a85dd72b87ea5fdd882b81bae1fa1957078 100644 (file)
@@ -274,6 +274,85 @@ IfConfigManualAddressNotify (
 }\r
 \r
 \r
+/**\r
+  Create an IP child, use it to start the auto configuration, then destroy it.\r
+\r
+  @param[in] Controller       The controller which has the service installed.\r
+  @param[in] Image            The image handle used to open service.\r
+\r
+  @retval EFI_SUCCESS         The configuration is done.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IfConfigStartIp4(\r
+  IN  EFI_HANDLE            Controller,\r
+  IN  EFI_HANDLE            Image\r
+  )\r
+{\r
+  EFI_IP4_PROTOCOL              *Ip4;\r
+  EFI_HANDLE                    Ip4Handle;\r
+  EFI_IP4_CONFIG_DATA           Ip4ConfigData;\r
+  EFI_STATUS                    Status;\r
+\r
+  //\r
+  // Get the Ip4ServiceBinding Protocol\r
+  //\r
+  Ip4Handle     = NULL;\r
+  Ip4           = NULL;\r
+\r
+  Status = NetLibCreateServiceChild (\r
+             Controller,\r
+             Image,\r
+             &gEfiIp4ServiceBindingProtocolGuid,\r
+             &Ip4Handle\r
+             );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                 Ip4Handle,\r
+                 &gEfiIp4ProtocolGuid,\r
+                 (VOID **) &Ip4,\r
+                 Controller,\r
+                 Image,\r
+                 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                 );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  Ip4ConfigData.DefaultProtocol          = EFI_IP_PROTO_ICMP;\r
+  Ip4ConfigData.AcceptAnyProtocol        = FALSE;\r
+  Ip4ConfigData.AcceptIcmpErrors         = FALSE;\r
+  Ip4ConfigData.AcceptBroadcast          = FALSE;\r
+  Ip4ConfigData.AcceptPromiscuous        = FALSE;\r
+  Ip4ConfigData.UseDefaultAddress        = TRUE;\r
+  ZeroMem (&Ip4ConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS));\r
+  ZeroMem (&Ip4ConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
+  Ip4ConfigData.TypeOfService            = 0;\r
+  Ip4ConfigData.TimeToLive               = 1;\r
+  Ip4ConfigData.DoNotFragment            = FALSE;\r
+  Ip4ConfigData.RawData                  = FALSE;\r
+  Ip4ConfigData.ReceiveTimeout           = 0;\r
+  Ip4ConfigData.TransmitTimeout          = 0;\r
+\r
+  Ip4->Configure (Ip4, &Ip4ConfigData);\r
+  \r
+ON_EXIT: \r
+  NetLibDestroyServiceChild (\r
+    Controller,\r
+    Image,\r
+    &gEfiIp4ServiceBindingProtocolGuid,\r
+    Ip4Handle\r
+    );\r
+  \r
+  return Status;\r
+}\r
+\r
+\r
 /**\r
   Print MAC address.\r
 \r
@@ -874,21 +953,27 @@ IfConfigSetInterfaceInfo (
     // Process valid variables.\r
     //\r
     if (StrCmp(VarArg->Arg, L"dhcp") == 0) {\r
-      //\r
-      // Set dhcp config policy\r
-      //\r
-      Policy = Ip4Config2PolicyDhcp;\r
-      Status = IfCb->IfCfg->SetData (\r
-                              IfCb->IfCfg,\r
-                              Ip4Config2DataTypePolicy,\r
-                              sizeof (EFI_IP4_CONFIG2_POLICY),\r
-                              &Policy\r
-                              );\r
-\r
-      if (EFI_ERROR(Status)) {\r
-        goto ON_EXIT;\r
+      if (IfCb->Policy == Ip4Config2PolicyDhcp) {\r
+        Status = IfConfigStartIp4 (IfCb->NicHandle, gImageHandle);\r
+        if (EFI_ERROR(Status)) {\r
+          goto ON_EXIT;\r
+        }\r
+      } else {\r
+        //\r
+        // Set dhcp config policy\r
+        //\r
+        Policy = Ip4Config2PolicyDhcp;\r
+        Status = IfCb->IfCfg->SetData (\r
+                                IfCb->IfCfg,\r
+                                Ip4Config2DataTypePolicy,\r
+                                sizeof (EFI_IP4_CONFIG2_POLICY),\r
+                                &Policy\r
+                                );\r
+        if (EFI_ERROR(Status)) {\r
+          goto ON_EXIT;\r
+        }\r
       }\r
-\r
+      \r
       VarArg= VarArg->Next;    \r
 \r
     } else if (StrCmp (VarArg->Arg, L"static") == 0) {\r
@@ -1038,7 +1123,7 @@ ON_EXIT:
     FreePool (Dns);\r
   }\r
   \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 \r
 }\r
 \r