summaryrefslogtreecommitdiffstats
path: root/ShellPkg
diff options
context:
space:
mode:
authorZhang Lubo <lubo.zhang@intel.com>2017-01-06 17:15:27 +0800
committerJiaxin Wu <jiaxin.wu@intel.com>2017-01-19 11:32:14 +0800
commit266746561d454d3d35938886e61a02b1ee1abaff (patch)
tree95b1f3a4e07785cf99501c75fc850404b5533d90 /ShellPkg
parenteabc6e59b9a718a44ab292f7e5c447c4c06d21c4 (diff)
downloadedk2-266746561d454d3d35938886e61a02b1ee1abaff.tar.gz
edk2-266746561d454d3d35938886e61a02b1ee1abaff.tar.bz2
edk2-266746561d454d3d35938886e61a02b1ee1abaff.zip
ShellPkg: Add check logic for the gateway validity.
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>
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c19
-rw-r--r--ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni3
2 files changed, 20 insertions, 2 deletions
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
index 5e243d5884..4db07b207d 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
@@ -2,7 +2,7 @@
The implementation for Shell command ifconfig based on IP4Config2 protocol.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
- Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -837,6 +837,8 @@ IfConfigSetInterfaceInfo (
EFI_IP4_CONFIG2_MANUAL_ADDRESS ManualAddress;
UINTN DataSize;
EFI_IPv4_ADDRESS Gateway;
+ IP4_ADDR SubnetMask;
+ IP4_ADDR TempGateway;
EFI_IPv4_ADDRESS *Dns;
ARG_LIST *Tmp;
UINTN Index;
@@ -1019,6 +1021,21 @@ IfConfigSetInterfaceInfo (
}
//
+ // Need to check the gateway validity before set Manual Address.
+ // In case we can set manual address but fail to configure Gateway.
+ //
+ CopyMem (&SubnetMask, &ManualAddress.SubnetMask, sizeof (IP4_ADDR));
+ CopyMem (&TempGateway, &Gateway, sizeof (IP4_ADDR));
+ SubnetMask = NTOHL (SubnetMask);
+ TempGateway = NTOHL (TempGateway);
+ if ((SubnetMask != 0) &&
+ !NetIp4IsUnicast (TempGateway, SubnetMask)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_INVALID_GATEWAY), gShellNetwork1HiiHandle, VarArg->Arg);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto ON_EXIT;
+ }
+
+ //
// Set manual config policy.
//
Policy = Ip4Config2PolicyStatic;
diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
index 4566cd110e..d9bbb209cd 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.uni
@@ -1,7 +1,7 @@
// /**
//
// (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
-// Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved. <BR>
+// Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
// This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
@@ -66,6 +66,7 @@
#string STR_IFCONFIG_LACK_COMMAND #language en-US "Lack interface config option.\n"
#string STR_IFCONFIG_INVALID_INTERFACE #language en-US "Invalid interface name.\n"
#string STR_IFCONFIG_INVALID_IPADDRESS #language en-US "Invalid ipv4 address: '%H%s%N'\n"
+#string STR_IFCONFIG_INVALID_GATEWAY #language en-US "Invalid gateway address: '%H%s%N'\n"
#string STR_IFCONFIG_DUPLICATE_COMMAND #language en-US "Duplicate commands. Bad command %H%s%N is skipped.\n"
#string STR_IFCONFIG_CONFLICT_COMMAND #language en-US "Conflict commands. Bad command %H%s%N is skipped.\n"
#string STR_IFCONFIG_UNKNOWN_COMMAND #language en-US "Unknown commands. Bad command %H%s%N is skipped.\n"