]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Add check logic for the gateway validity.
authorZhang Lubo <lubo.zhang@intel.com>
Fri, 6 Jan 2017 09:15:27 +0000 (17:15 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Thu, 19 Jan 2017 03:32:14 +0000 (11:32 +0800)
if we set a static IP using command
'ifconfig -s eth0 static 192.168.0.121 255.255.255.0 0.0.0.0'
The system says 'Failed to set address.' but using
'ifconfig -l', the static IP can be assigned successfully.
so we need to check the gateway validity before setting manual
address to keep the ifconfig -s command more consistent.

Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Cc: Santhapur Naveen <naveens@amiindia.co.in>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni

index 5e243d58843017810d57dd7c688ca4748cf75e30..4db07b207d58bc2896a6e4d21590608f6660d376 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
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 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
@@ -837,6 +837,8 @@ IfConfigSetInterfaceInfo (
   EFI_IP4_CONFIG2_MANUAL_ADDRESS   ManualAddress;\r
   UINTN                            DataSize;\r
   EFI_IPv4_ADDRESS                 Gateway;\r
+  IP4_ADDR                         SubnetMask;\r
+  IP4_ADDR                         TempGateway;\r
   EFI_IPv4_ADDRESS                 *Dns;\r
   ARG_LIST                         *Tmp;\r
   UINTN                            Index;\r
@@ -1018,6 +1020,21 @@ IfConfigSetInterfaceInfo (
         goto ON_EXIT;\r
       }\r
 \r
+      //\r
+      // Need to check the gateway validity before set Manual Address.\r
+      // In case we can set manual address but fail to configure Gateway.\r
+      //\r
+      CopyMem (&SubnetMask, &ManualAddress.SubnetMask, sizeof (IP4_ADDR));\r
+      CopyMem (&TempGateway, &Gateway, sizeof (IP4_ADDR));\r
+      SubnetMask  = NTOHL (SubnetMask);\r
+      TempGateway = NTOHL (TempGateway);\r
+      if ((SubnetMask != 0) &&\r
+          !NetIp4IsUnicast (TempGateway, SubnetMask)) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY), gShellNetwork1HiiHandle, VarArg->Arg);\r
+        ShellStatus = SHELL_INVALID_PARAMETER;\r
+        goto ON_EXIT;\r
+      }\r
+\r
       //\r
       // Set manual config policy.\r
       //\r
index 4566cd110e8c29a615fde85e908e62f21ec679e7..d9bbb209cd5ebe5cdf6776f6a3367aad92b9d08d 100644 (file)
@@ -1,7 +1,7 @@
 // /**\r
 //\r
 // (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-// Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved. <BR>\r
+// Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>\r
 // This program and the accompanying materials\r
 // are licensed and made available under the terms and conditions of the BSD License\r
 // which accompanies this distribution. The full text of the license may be found at\r
@@ -66,6 +66,7 @@
 #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_INVALID_GATEWAY          #language en-US    "Invalid gateway 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