mirror of https://github.com/acidanthera/audk.git
ShellPkg: Enhance ping6 to select the interface automatically
v2: * Refine the code to make it more readable. This patch is used to support no source IP specified case while multiple NICs existed in the platform. The command will select the first both connected and configured interface automatically. Note: Source address is always required when pinging a link-local address. Cc: Bhupesh Sharma <bhupesh.sharma@nxp.com> Cc: Jaben Carsey <jaben.carsey@intel.com> Cc: Ye Ting <ting.ye@intel.com> Cc: Fu Siyuan <siyuan.fu@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> Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
This commit is contained in:
parent
9ce14ca124
commit
76cd3ffab6
|
@ -663,6 +663,8 @@ Ping6CreateIpInstance (
|
|||
UINTN HandleIndex;
|
||||
UINTN HandleNum;
|
||||
EFI_HANDLE *HandleBuffer;
|
||||
BOOLEAN UnspecifiedSrc;
|
||||
BOOLEAN MediaPresent;
|
||||
EFI_SERVICE_BINDING_PROTOCOL *Ip6Sb;
|
||||
EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg;
|
||||
EFI_IP6_CONFIG_DATA Ip6Config;
|
||||
|
@ -672,6 +674,8 @@ Ping6CreateIpInstance (
|
|||
UINTN AddrIndex;
|
||||
|
||||
HandleBuffer = NULL;
|
||||
UnspecifiedSrc = FALSE;
|
||||
MediaPresent = TRUE;
|
||||
Ip6Sb = NULL;
|
||||
IfInfo = NULL;
|
||||
IfInfoSize = 0;
|
||||
|
@ -689,17 +693,23 @@ Ping6CreateIpInstance (
|
|||
if (EFI_ERROR (Status) || (HandleNum == 0)) {
|
||||
return EFI_ABORTED;
|
||||
}
|
||||
|
||||
if (NetIp6IsUnspecifiedAddr (&Private->SrcAddress)) {
|
||||
//
|
||||
// Source address is required when pinging a link-local address on multi-
|
||||
// interfaces host.
|
||||
// SrcAddress is unspecified. So, both connected and configured interface will be automatic selected.
|
||||
//
|
||||
if (NetIp6IsLinkLocalAddr (&Private->DstAddress) &&
|
||||
NetIp6IsUnspecifiedAddr (&Private->SrcAddress) &&
|
||||
(HandleNum > 1)) {
|
||||
UnspecifiedSrc = TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// Source address is required when pinging a link-local address.
|
||||
//
|
||||
if (NetIp6IsLinkLocalAddr (&Private->DstAddress) && UnspecifiedSrc) {
|
||||
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PING6_INVALID_SOURCE), gShellNetwork2HiiHandle);
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
goto ON_ERROR;
|
||||
}
|
||||
|
||||
//
|
||||
// For each ip6 protocol, check interface addresses list.
|
||||
//
|
||||
|
@ -709,6 +719,19 @@ Ping6CreateIpInstance (
|
|||
IfInfo = NULL;
|
||||
IfInfoSize = 0;
|
||||
|
||||
if (UnspecifiedSrc) {
|
||||
//
|
||||
// Check media.
|
||||
//
|
||||
NetLibDetectMedia (HandleBuffer[HandleIndex], &MediaPresent);
|
||||
if (!MediaPresent) {
|
||||
//
|
||||
// Skip this one.
|
||||
//
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Status = gBS->HandleProtocol (
|
||||
HandleBuffer[HandleIndex],
|
||||
&gEfiIp6ServiceBindingProtocolGuid,
|
||||
|
@ -718,12 +741,6 @@ Ping6CreateIpInstance (
|
|||
goto ON_ERROR;
|
||||
}
|
||||
|
||||
if (NetIp6IsUnspecifiedAddr (&Private->SrcAddress)) {
|
||||
//
|
||||
// No need to match interface address.
|
||||
//
|
||||
break;
|
||||
} else {
|
||||
//
|
||||
// Ip6config protocol and ip6 service binding protocol are installed
|
||||
// on the same handle.
|
||||
|
@ -776,9 +793,17 @@ Ping6CreateIpInstance (
|
|||
// Check whether the source address is one of the interface addresses.
|
||||
//
|
||||
for (AddrIndex = 0; AddrIndex < IfInfo->AddressInfoCount; AddrIndex++) {
|
||||
|
||||
Addr = &(IfInfo->AddressInfo[AddrIndex].Address);
|
||||
if (EFI_IP6_EQUAL (&Private->SrcAddress, Addr)) {
|
||||
|
||||
if (UnspecifiedSrc) {
|
||||
if (!NetIp6IsUnspecifiedAddr (Addr) && !NetIp6IsLinkLocalAddr (Addr)) {
|
||||
//
|
||||
// Select the interface automatically.
|
||||
//
|
||||
CopyMem(&Private->SrcAddress, Addr, sizeof(Private->SrcAddress));
|
||||
break;
|
||||
}
|
||||
} else if (EFI_IP6_EQUAL (&Private->SrcAddress, Addr)) {
|
||||
//
|
||||
// Match a certain interface address.
|
||||
//
|
||||
|
@ -792,7 +817,6 @@ Ping6CreateIpInstance (
|
|||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FreePool (IfInfo);
|
||||
IfInfo = NULL;
|
||||
|
|
Loading…
Reference in New Issue