mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-28 08:04:07 +02:00
ShellPkg: Fix 'ifconfig' can't get the address from dhcp in some case
R18201 fix caused ifconfig in shell failed to get the address from dhcp with the command "ifconfig -s eth0 dhcp" since the default policy is dhcp already. We can fix it by following the rule to starting the Ip4 auto configuration. 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> Reviwed-by: Ye Ting <ting.ye@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18244 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
3e708eedd7
commit
d6cf1af908
@ -274,6 +274,85 @@ IfConfigManualAddressNotify (
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create an IP child, use it to start the auto configuration, then destroy it.
|
||||||
|
|
||||||
|
@param[in] Controller The controller which has the service installed.
|
||||||
|
@param[in] Image The image handle used to open service.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The configuration is done.
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
IfConfigStartIp4(
|
||||||
|
IN EFI_HANDLE Controller,
|
||||||
|
IN EFI_HANDLE Image
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_IP4_PROTOCOL *Ip4;
|
||||||
|
EFI_HANDLE Ip4Handle;
|
||||||
|
EFI_IP4_CONFIG_DATA Ip4ConfigData;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get the Ip4ServiceBinding Protocol
|
||||||
|
//
|
||||||
|
Ip4Handle = NULL;
|
||||||
|
Ip4 = NULL;
|
||||||
|
|
||||||
|
Status = NetLibCreateServiceChild (
|
||||||
|
Controller,
|
||||||
|
Image,
|
||||||
|
&gEfiIp4ServiceBindingProtocolGuid,
|
||||||
|
&Ip4Handle
|
||||||
|
);
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
Ip4Handle,
|
||||||
|
&gEfiIp4ProtocolGuid,
|
||||||
|
(VOID **) &Ip4,
|
||||||
|
Controller,
|
||||||
|
Image,
|
||||||
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
|
);
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
goto ON_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ip4ConfigData.DefaultProtocol = EFI_IP_PROTO_ICMP;
|
||||||
|
Ip4ConfigData.AcceptAnyProtocol = FALSE;
|
||||||
|
Ip4ConfigData.AcceptIcmpErrors = FALSE;
|
||||||
|
Ip4ConfigData.AcceptBroadcast = FALSE;
|
||||||
|
Ip4ConfigData.AcceptPromiscuous = FALSE;
|
||||||
|
Ip4ConfigData.UseDefaultAddress = TRUE;
|
||||||
|
ZeroMem (&Ip4ConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS));
|
||||||
|
ZeroMem (&Ip4ConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
|
||||||
|
Ip4ConfigData.TypeOfService = 0;
|
||||||
|
Ip4ConfigData.TimeToLive = 1;
|
||||||
|
Ip4ConfigData.DoNotFragment = FALSE;
|
||||||
|
Ip4ConfigData.RawData = FALSE;
|
||||||
|
Ip4ConfigData.ReceiveTimeout = 0;
|
||||||
|
Ip4ConfigData.TransmitTimeout = 0;
|
||||||
|
|
||||||
|
Ip4->Configure (Ip4, &Ip4ConfigData);
|
||||||
|
|
||||||
|
ON_EXIT:
|
||||||
|
NetLibDestroyServiceChild (
|
||||||
|
Controller,
|
||||||
|
Image,
|
||||||
|
&gEfiIp4ServiceBindingProtocolGuid,
|
||||||
|
Ip4Handle
|
||||||
|
);
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Print MAC address.
|
Print MAC address.
|
||||||
|
|
||||||
@ -874,21 +953,27 @@ IfConfigSetInterfaceInfo (
|
|||||||
// Process valid variables.
|
// Process valid variables.
|
||||||
//
|
//
|
||||||
if (StrCmp(VarArg->Arg, L"dhcp") == 0) {
|
if (StrCmp(VarArg->Arg, L"dhcp") == 0) {
|
||||||
//
|
if (IfCb->Policy == Ip4Config2PolicyDhcp) {
|
||||||
// Set dhcp config policy
|
Status = IfConfigStartIp4 (IfCb->NicHandle, gImageHandle);
|
||||||
//
|
if (EFI_ERROR(Status)) {
|
||||||
Policy = Ip4Config2PolicyDhcp;
|
goto ON_EXIT;
|
||||||
Status = IfCb->IfCfg->SetData (
|
}
|
||||||
IfCb->IfCfg,
|
} else {
|
||||||
Ip4Config2DataTypePolicy,
|
//
|
||||||
sizeof (EFI_IP4_CONFIG2_POLICY),
|
// Set dhcp config policy
|
||||||
&Policy
|
//
|
||||||
);
|
Policy = Ip4Config2PolicyDhcp;
|
||||||
|
Status = IfCb->IfCfg->SetData (
|
||||||
if (EFI_ERROR(Status)) {
|
IfCb->IfCfg,
|
||||||
goto ON_EXIT;
|
Ip4Config2DataTypePolicy,
|
||||||
|
sizeof (EFI_IP4_CONFIG2_POLICY),
|
||||||
|
&Policy
|
||||||
|
);
|
||||||
|
if (EFI_ERROR(Status)) {
|
||||||
|
goto ON_EXIT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VarArg= VarArg->Next;
|
VarArg= VarArg->Next;
|
||||||
|
|
||||||
} else if (StrCmp (VarArg->Arg, L"static") == 0) {
|
} else if (StrCmp (VarArg->Arg, L"static") == 0) {
|
||||||
@ -1038,7 +1123,7 @@ ON_EXIT:
|
|||||||
FreePool (Dns);
|
FreePool (Dns);
|
||||||
}
|
}
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return Status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user