ShellPkg: Fix ifconfig hang issue with incomplete parameters
authorJiaxin Wu <jiaxin.wu@intel.com>
Thu, 10 Dec 2015 10:59:29 +0000 (10:59 +0000)
committerjiaxinwu <jiaxinwu@Edk2>
Thu, 10 Dec 2015 10:59:29 +0000 (10:59 +0000)
This patch is used to fix ifconfig hang issue with incomplete
parameters. In addition, some error related output information
is added to increase the interactivity.

Cc: Leekha Shaveta <shaveta@freescale.com>
Cc: Carsey Jaben <jaben.carsey@intel.com>
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>
Tested-by: Leekha Shaveta <shaveta@freescale.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19212 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni

index fb6f575..f8dbc88 100644 (file)
@@ -828,6 +828,7 @@ IfConfigClearInterfaceInfo (
                             &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
@@ -904,6 +905,7 @@ IfConfigSetInterfaceInfo (
                   &TimeOutEvt\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
     goto ON_EXIT;\r
   }\r
@@ -916,6 +918,7 @@ IfConfigSetInterfaceInfo (
                   &MappedEvt\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
     goto ON_EXIT;\r
   }\r
@@ -974,6 +977,7 @@ IfConfigSetInterfaceInfo (
       if (IfCb->Policy == Ip4Config2PolicyDhcp) {\r
         Status = IfConfigStartIp4 (IfCb->NicHandle, gImageHandle);\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
           goto ON_EXIT;\r
         }\r
@@ -989,6 +993,7 @@ IfConfigSetInterfaceInfo (
                                 &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
           goto ON_EXIT;\r
         }\r
@@ -997,23 +1002,13 @@ IfConfigSetInterfaceInfo (
       VarArg= VarArg->Next;    \r
 \r
     } else if (StrCmp (VarArg->Arg, L"static") == 0) {\r
-      //\r
-      // Set manual config policy.\r
-      //\r
-      Policy = Ip4Config2PolicyStatic;\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
-        ShellStatus = SHELL_ACCESS_DENIED;\r
+      VarArg= VarArg->Next;\r
+      if (VarArg == NULL) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);\r
+        ShellStatus = SHELL_INVALID_PARAMETER;\r
         goto ON_EXIT;\r
       }\r
 \r
-      VarArg= VarArg->Next;   \r
-\r
       ZeroMem (&ManualAddress, sizeof (ManualAddress));\r
     \r
       //\r
@@ -1021,6 +1016,7 @@ IfConfigSetInterfaceInfo (
       //\r
       Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.Address);\r
       if (EFI_ERROR(Status)) {\r
+        ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IPADDRESS), gShellNetwork1HiiHandle, VarArg->Arg);\r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
         goto ON_EXIT;\r
       }\r
@@ -1029,8 +1025,15 @@ IfConfigSetInterfaceInfo (
       // Get subnetmask.\r
       //    \r
       VarArg = VarArg->Next;\r
+      if (VarArg == NULL) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);\r
+        ShellStatus = SHELL_INVALID_PARAMETER;\r
+        goto ON_EXIT;\r
+      }\r
+      \r
       Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.SubnetMask);\r
       if (EFI_ERROR(Status)) {\r
+        ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IPADDRESS), gShellNetwork1HiiHandle, VarArg->Arg);\r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
         goto ON_EXIT;\r
       }\r
@@ -1039,12 +1042,38 @@ IfConfigSetInterfaceInfo (
       // Get gateway.\r
       //\r
       VarArg = VarArg->Next;\r
+      if (VarArg == NULL) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);\r
+        ShellStatus = SHELL_INVALID_PARAMETER;\r
+        goto ON_EXIT;\r
+      }\r
+      \r
       Status = NetLibStrToIp4 (VarArg->Arg, &Gateway);\r
       if (EFI_ERROR(Status)) {\r
+        ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IPADDRESS), gShellNetwork1HiiHandle, VarArg->Arg);\r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
         goto ON_EXIT;\r
       }\r
+\r
+      //\r
+      // Set manual config policy.\r
+      //\r
+      Policy = Ip4Config2PolicyStatic;\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
+        goto ON_EXIT;\r
+      }\r
       \r
+      //\r
+      // Set Manual Address.\r
+      //\r
       IsAddressOk = FALSE;\r
 \r
       Status = IfCb->IfCfg->RegisterDataNotify (\r
@@ -1053,6 +1082,7 @@ IfConfigSetInterfaceInfo (
                               MappedEvt\r
                               );\r
       if (EFI_ERROR (Status)) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED), gShellNetwork1HiiHandle, Status);\r
         ShellStatus = SHELL_ACCESS_DENIED;\r
         goto ON_EXIT;\r
       }\r
@@ -1101,6 +1131,7 @@ IfConfigSetInterfaceInfo (
                               &Gateway\r
                               );\r
       if (EFI_ERROR (Status)) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED), gShellNetwork1HiiHandle, Status);\r
         ShellStatus = SHELL_ACCESS_DENIED;\r
         goto ON_EXIT;\r
       }\r
@@ -1126,6 +1157,7 @@ IfConfigSetInterfaceInfo (
       while (Tmp != NULL) {\r
         Status = NetLibStrToIp4 (Tmp->Arg, Dns + Index);\r
         if (EFI_ERROR(Status)) {\r
+          ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IPADDRESS), gShellNetwork1HiiHandle, Tmp->Arg);\r
           ShellStatus = SHELL_INVALID_PARAMETER;\r
           goto ON_EXIT;\r
         }\r
@@ -1147,6 +1179,7 @@ IfConfigSetInterfaceInfo (
                               Dns\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
         goto ON_EXIT;\r
       }\r
index 4c68e41..bc6acac 100644 (file)
 #string STR_IFCONFIG_LACK_INTERFACE           #language en-US    "Lack interface name.\n"\r
 #string STR_IFCONFIG_LACK_COMMAND             #language en-US    "Lack interface config option.\n"\r
 #string STR_IFCONFIG_INVALID_INTERFACE        #language en-US    "Invalid interface name.\n"\r
+#string STR_IFCONFIG_INVALID_IPADDRESS        #language en-US    "Invalid ipv4 address: '%H%s%N'\n"\r
 #string STR_IFCONFIG_DUPLICATE_COMMAND        #language en-US    "Duplicate commands. Bad command %H%s%N is skipped.\n"\r
 #string STR_IFCONFIG_CONFLICT_COMMAND         #language en-US    "Conflict commands. Bad command %H%s%N is skipped.\n"\r
 #string STR_IFCONFIG_UNKNOWN_COMMAND          #language en-US    "Unknown commands. Bad command %H%s%N is skipped.\n"\r
-#string STR_IFCONFIG_SET_ADDR_FAILED          #language en-US    "It failed to set .\n"\r
+#string STR_IFCONFIG_SET_ADDR_FAILED          #language en-US    "Failed to set address.\n"\r
 #string STR_IFCONFIG_ROUTES_SIZE              #language en-US           "\n%H  Routes (%d entries):\n"\r
 #string STR_IFCONFIG_ROUTES_ENTRY_INDEX       #language en-US    "%H    Entry[%d]\n"\r
 #string STR_IFCONFIG_SHOW_IP_ADDR             #language en-US    "%12s: %N%d.%d.%d.%d\n"\r
 "  3. Use '-l' to list the DNS and other address related settings for all\r\n"\r
 "     interfaces or the specified interface.\r\n"\r
 "  4. Use '-s <Name> static <IP> <SubnetMask> <GatewayMask>' with \r\n"\r
-"     static IP4 address configuration for all or specified interface.\r\n"\r
+"     static IP4 address configuration for specified interface.\r\n"\r
 "  5. Use '-s <Name> dhcp' for DHCP4 to request the IP4 address\r\n"\r
-"     configuration dynamically for all interface or specified interface.\r\n"\r
+"     configuration dynamically for specified interface.\r\n"\r
 "  6. Use '-s <Name> dns <IP>' must under manual policy.\r\n"\r
 ".SH EXAMPLES\r\n"\r
 " \r\n"\r