ShellPkg: Fix ifconfig hang issue with incomplete parameters

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
This commit is contained in:
Jiaxin Wu 2015-12-10 10:59:29 +00:00 committed by jiaxinwu
parent 2d675c1c8c
commit d1baf355b1
2 changed files with 70 additions and 36 deletions

View File

@ -828,6 +828,7 @@ IfConfigClearInterfaceInfo (
&Policy
);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork1HiiHandle, L"ifconfig");
ShellStatus = SHELL_ACCESS_DENIED;
break;
}
@ -904,6 +905,7 @@ IfConfigSetInterfaceInfo (
&TimeOutEvt
);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork1HiiHandle, L"ifconfig");
ShellStatus = SHELL_ACCESS_DENIED;
goto ON_EXIT;
}
@ -916,6 +918,7 @@ IfConfigSetInterfaceInfo (
&MappedEvt
);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork1HiiHandle, L"ifconfig");
ShellStatus = SHELL_ACCESS_DENIED;
goto ON_EXIT;
}
@ -974,6 +977,7 @@ IfConfigSetInterfaceInfo (
if (IfCb->Policy == Ip4Config2PolicyDhcp) {
Status = IfConfigStartIp4 (IfCb->NicHandle, gImageHandle);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork1HiiHandle, L"ifconfig");
ShellStatus = SHELL_ACCESS_DENIED;
goto ON_EXIT;
}
@ -989,6 +993,7 @@ IfConfigSetInterfaceInfo (
&Policy
);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork1HiiHandle, L"ifconfig");
ShellStatus = SHELL_ACCESS_DENIED;
goto ON_EXIT;
}
@ -997,6 +1002,59 @@ IfConfigSetInterfaceInfo (
VarArg= VarArg->Next;
} else if (StrCmp (VarArg->Arg, L"static") == 0) {
VarArg= VarArg->Next;
if (VarArg == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
ZeroMem (&ManualAddress, sizeof (ManualAddress));
//
// Get manual IP address.
//
Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.Address);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IPADDRESS), gShellNetwork1HiiHandle, VarArg->Arg);
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
//
// Get subnetmask.
//
VarArg = VarArg->Next;
if (VarArg == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.SubnetMask);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IPADDRESS), gShellNetwork1HiiHandle, VarArg->Arg);
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
//
// Get gateway.
//
VarArg = VarArg->Next;
if (VarArg == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_LACK_COMMAND), gShellNetwork1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = NetLibStrToIp4 (VarArg->Arg, &Gateway);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IPADDRESS), gShellNetwork1HiiHandle, VarArg->Arg);
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
//
// Set manual config policy.
//
@ -1008,43 +1066,14 @@ IfConfigSetInterfaceInfo (
&Policy
);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork1HiiHandle, L"ifconfig");
ShellStatus = SHELL_ACCESS_DENIED;
goto ON_EXIT;
}
VarArg= VarArg->Next;
ZeroMem (&ManualAddress, sizeof (ManualAddress));
//
// Get manual IP address.
//
Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.Address);
if (EFI_ERROR(Status)) {
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
//
// Get subnetmask.
//
VarArg = VarArg->Next;
Status = NetLibStrToIp4 (VarArg->Arg, &ManualAddress.SubnetMask);
if (EFI_ERROR(Status)) {
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
//
// Get gateway.
//
VarArg = VarArg->Next;
Status = NetLibStrToIp4 (VarArg->Arg, &Gateway);
if (EFI_ERROR(Status)) {
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
//
// Set Manual Address.
//
IsAddressOk = FALSE;
Status = IfCb->IfCfg->RegisterDataNotify (
@ -1053,6 +1082,7 @@ IfConfigSetInterfaceInfo (
MappedEvt
);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED), gShellNetwork1HiiHandle, Status);
ShellStatus = SHELL_ACCESS_DENIED;
goto ON_EXIT;
}
@ -1101,6 +1131,7 @@ IfConfigSetInterfaceInfo (
&Gateway
);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IFCONFIG_SET_ADDR_FAILED), gShellNetwork1HiiHandle, Status);
ShellStatus = SHELL_ACCESS_DENIED;
goto ON_EXIT;
}
@ -1126,6 +1157,7 @@ IfConfigSetInterfaceInfo (
while (Tmp != NULL) {
Status = NetLibStrToIp4 (Tmp->Arg, Dns + Index);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INVALID_IPADDRESS), gShellNetwork1HiiHandle, Tmp->Arg);
ShellStatus = SHELL_INVALID_PARAMETER;
goto ON_EXIT;
}
@ -1147,6 +1179,7 @@ IfConfigSetInterfaceInfo (
Dns
);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellNetwork1HiiHandle, L"ifconfig");
ShellStatus = SHELL_ACCESS_DENIED;
goto ON_EXIT;
}

View File

@ -63,10 +63,11 @@
#string STR_IFCONFIG_LACK_INTERFACE #language en-US "Lack interface name.\n"
#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_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"
#string STR_IFCONFIG_SET_ADDR_FAILED #language en-US "It failed to set .\n"
#string STR_IFCONFIG_SET_ADDR_FAILED #language en-US "Failed to set address.\n"
#string STR_IFCONFIG_ROUTES_SIZE #language en-US "\n%H Routes (%d entries):\n"
#string STR_IFCONFIG_ROUTES_ENTRY_INDEX #language en-US "%H Entry[%d]\n"
#string STR_IFCONFIG_SHOW_IP_ADDR #language en-US "%12s: %N%d.%d.%d.%d\n"
@ -156,9 +157,9 @@
" 3. Use '-l' to list the DNS and other address related settings for all\r\n"
" interfaces or the specified interface.\r\n"
" 4. Use '-s <Name> static <IP> <SubnetMask> <GatewayMask>' with \r\n"
" static IP4 address configuration for all or specified interface.\r\n"
" static IP4 address configuration for specified interface.\r\n"
" 5. Use '-s <Name> dhcp' for DHCP4 to request the IP4 address\r\n"
" configuration dynamically for all interface or specified interface.\r\n"
" configuration dynamically for specified interface.\r\n"
" 6. Use '-s <Name> dns <IP>' must under manual policy.\r\n"
".SH EXAMPLES\r\n"
" \r\n"