]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Update 'ifconfig -r' implementation
authorJiaxin Wu <jiaxin.wu@intel.com>
Wed, 2 Mar 2016 07:58:25 +0000 (15:58 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Thu, 3 Mar 2016 07:27:24 +0000 (15:27 +0800)
This patch is used to update ifconfig -r implementation
to sync with UEFI Shell 2.2.

option -r means to reconfigure all or specified interface,
and set DHCP policy. If specified interface is already set
to DHCP, then refresh the IPv4 configuration.

If the interface name is specified
with '-r', DHCP DORA process will be triggered by the policy
transition (static -> dhcp).

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Carsey Jaben <jaben.carsey@intel.com>
Cc: El-Haj-Mahmoud Samer <samer.el-haj-mahmoud@hpe.com>
Cc: Subramanian Sriram <sriram-s@hpe.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Sriram Subramanian <sriram-s@hpe.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c

index 0c4a3b09c323832cc58856b847da773c486f9f8c..92108a14ade22c4895055ca84fda1314c98ddc70 100644 (file)
@@ -2,7 +2,7 @@
   The implementation for Shell command ifconfig based on IP4Config2 protocol.\r
 \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
   The implementation for Shell command ifconfig based on IP4Config2 protocol.\r
 \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, 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
@@ -710,6 +710,7 @@ IfConfigShowInterfaceInfo (
   The clean process of the ifconfig command to clear interface info.\r
 \r
   @param[in]   IfList    The pointer of IfList(interface list).\r
   The clean process of the ifconfig command to clear interface info.\r
 \r
   @param[in]   IfList    The pointer of IfList(interface list).\r
+  @param[in]   IfName    The pointer of interface name.\r
 \r
   @retval SHELL_SUCCESS  The ifconfig command clean processed successfully.\r
   @retval others         The ifconfig command clean process failed.\r
 \r
   @retval SHELL_SUCCESS  The ifconfig command clean processed successfully.\r
   @retval others         The ifconfig command clean process failed.\r
@@ -717,7 +718,8 @@ IfConfigShowInterfaceInfo (
 **/\r
 SHELL_STATUS\r
 IfConfigClearInterfaceInfo (\r
 **/\r
 SHELL_STATUS\r
 IfConfigClearInterfaceInfo (\r
-  IN LIST_ENTRY    *IfList\r
+  IN LIST_ENTRY    *IfList,\r
+  IN CHAR16        *IfName\r
   )\r
 {\r
   EFI_STATUS                Status;  \r
   )\r
 {\r
   EFI_STATUS                Status;  \r
@@ -726,8 +728,7 @@ IfConfigClearInterfaceInfo (
   LIST_ENTRY                *Next;\r
   IFCONFIG_INTERFACE_CB     *IfCb;\r
   EFI_IP4_CONFIG2_POLICY    Policy;\r
   LIST_ENTRY                *Next;\r
   IFCONFIG_INTERFACE_CB     *IfCb;\r
   EFI_IP4_CONFIG2_POLICY    Policy;\r
-\r
-  Policy = Ip4Config2PolicyDhcp;\r
+  \r
   Status = EFI_SUCCESS;\r
   ShellStatus = SHELL_SUCCESS;\r
 \r
   Status = EFI_SUCCESS;\r
   ShellStatus = SHELL_SUCCESS;\r
 \r
@@ -737,9 +738,29 @@ IfConfigClearInterfaceInfo (
 \r
   //\r
   // Go through the interface list.\r
 \r
   //\r
   // Go through the interface list.\r
+  // If the interface name is specified, DHCP DORA process will be \r
+  // triggered by the policy transition (static -> dhcp).\r
   //\r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, IfList) {\r
     IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);\r
   //\r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, IfList) {\r
     IfCb = NET_LIST_USER_STRUCT (Entry, IFCONFIG_INTERFACE_CB, Link);\r
+\r
+    if ((IfName != NULL) && (StrCmp (IfName, IfCb->IfInfo->Name) == 0)) {\r
+      Policy = Ip4Config2PolicyStatic;\r
+      \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
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork1HiiHandle, L"ifconfig");\r
+        ShellStatus = SHELL_ACCESS_DENIED;\r
+        break;\r
+      }  \r
+    }\r
+\r
+    Policy = Ip4Config2PolicyDhcp;\r
     \r
     Status = IfCb->IfCfg->SetData (\r
                             IfCb->IfCfg,\r
     \r
     Status = IfCb->IfCfg->SetData (\r
                             IfCb->IfCfg,\r
@@ -1143,7 +1164,7 @@ IfConfig (
     break;\r
 \r
   case IfConfigOpClear:\r
     break;\r
 \r
   case IfConfigOpClear:\r
-    ShellStatus = IfConfigClearInterfaceInfo (&Private->IfList);\r
+    ShellStatus = IfConfigClearInterfaceInfo (&Private->IfList, Private->IfName);\r
     break;\r
 \r
   case IfConfigOpSet:\r
     break;\r
 \r
   case IfConfigOpSet:\r