Re: [edk2] [Patch] ShellPkg: Fix 'ifconfig' getting the address from dhcp error
Reviewed-by: Ye Ting -Original Message- From: Wu, Jiaxin Sent: Wednesday, August 19, 2015 4:56 PM To: edk2-devel@lists.01.org Cc: Ye, Ting; Zhang, Lubo Subject: [Patch] ShellPkg: Fix 'ifconfig' getting the address from dhcp error 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 Cc: Zhang Lubo Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu --- .../UefiShellNetwork1CommandsLib/Ifconfig.c| 115 ++--- 1 file changed, 100 insertions(+), 15 deletions(-) diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c index df19a9f..273f1a8 100644 --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c @@ -273,10 +273,89 @@ IfConfigManualAddressNotify ( *((BOOLEAN *) Context) = TRUE; } /** + 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] ImageThe image handle used to open service. + + @retval EFI_SUCCESS The configuration is done. +**/ +EFI_STATUS +EFIAPI +IfConfigStartIp4( + IN EFI_HANDLEController, + IN EFI_HANDLEImage + ) +{ + EFI_IP4_PROTOCOL *Ip4; + EFI_HANDLEIp4Handle; + EFI_IP4_CONFIG_DATA Ip4ConfigData; + EFI_STATUSStatus; + + // + // 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. @param[in]NodeThe pointer of MAC address buffer. @param[in]SizeThe size of MAC address buffer. @@ -872,25 +951,31 @@ IfConfigSetInterfaceInfo ( // // Process valid variables. // if (StrCmp(VarArg->Arg, L"dhcp") == 0) { - // - // Set dhcp config policy - // - Policy = Ip4Config2PolicyDhcp; - Status = IfCb->IfCfg->SetData ( - IfCb->IfCfg, - Ip4Config2DataTypePolicy, - sizeof (EFI_IP4_CONFIG2_POLICY), - &Policy - ); - - if (EFI_ERROR(Status)) { -goto ON_EXIT; + if (IfCb->Policy == Ip4Config2PolicyDhcp) { +Status = IfConfigStartIp4 (IfCb->NicHandle, gImageHandle); +if (EFI_ERROR(Status)) { + goto ON_EXIT; +} + } else { +// +// Set dhcp config policy +// +Policy = Ip4Config2PolicyDhcp; +Status = IfCb->IfCfg->SetData ( +IfCb->IfCfg, +Ip4Config2DataTypePolicy, +sizeof (EFI_IP4_CONFIG2_POLICY), +&Policy +); +if (EFI_ERROR(Status)) { + goto ON_EXIT; +} } - + VarArg= VarArg->Next; } else if (StrCmp (VarArg->Arg, L"static") == 0) { // // Set manual config policy. @@ -1036,11 +1121,11 @@ IfConfigSetInterfaceInfo ( ON_EXIT: if (Dns != NULL) { FreePool (Dns); } - return EFI_SUCCESS; + return S
Re: [edk2] [Patch] ShellPkg: Fix 'ifconfig' getting the address from dhcp error
Reviewed-by: Jaben Carsey > -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of > Jiaxin Wu > Sent: Wednesday, August 19, 2015 1:56 AM > To: edk2-devel@lists.01.org > Cc: Ye, Ting ; Zhang, Lubo > Subject: [edk2] [Patch] ShellPkg: Fix 'ifconfig' getting the address from dhcp > error > Importance: High > > 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 > Cc: Zhang Lubo > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jiaxin Wu > --- > .../UefiShellNetwork1CommandsLib/Ifconfig.c| 115 > ++--- > 1 file changed, 100 insertions(+), 15 deletions(-) > > diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c > index df19a9f..273f1a8 100644 > --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c > +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c > @@ -273,10 +273,89 @@ IfConfigManualAddressNotify ( >*((BOOLEAN *) Context) = TRUE; > } > > > /** > + 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] ImageThe image handle used to open service. > + > + @retval EFI_SUCCESS The configuration is done. > +**/ > +EFI_STATUS > +EFIAPI > +IfConfigStartIp4( > + IN EFI_HANDLEController, > + IN EFI_HANDLEImage > + ) > +{ > + EFI_IP4_PROTOCOL *Ip4; > + EFI_HANDLEIp4Handle; > + EFI_IP4_CONFIG_DATA Ip4ConfigData; > + EFI_STATUSStatus; > + > + // > + // 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. > >@param[in]NodeThe pointer of MAC address buffer. >@param[in]SizeThe size of MAC address buffer. > > @@ -872,25 +951,31 @@ IfConfigSetInterfaceInfo ( > > // > // Process valid variables. > // > if (StrCmp(VarArg->Arg, L"dhcp") == 0) { > - // > - // Set dhcp config policy > - // > - Policy = Ip4Config2PolicyDhcp; > - Status = IfCb->IfCfg->SetData ( > - IfCb->IfCfg, > - Ip4Config2DataTypePolicy, > - sizeof (EFI_IP4_CONFIG2_POLICY), > - &Policy > - ); > - > - if (EFI_ERROR(Status)) { > -goto ON_EXIT; > + if (IfCb->Policy == Ip4Config2PolicyDhcp) { > +Status = IfC
[edk2] [Patch] ShellPkg: Fix 'ifconfig' getting the address from dhcp error
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 Cc: Zhang Lubo Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu --- .../UefiShellNetwork1CommandsLib/Ifconfig.c| 115 ++--- 1 file changed, 100 insertions(+), 15 deletions(-) diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c index df19a9f..273f1a8 100644 --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c @@ -273,10 +273,89 @@ IfConfigManualAddressNotify ( *((BOOLEAN *) Context) = TRUE; } /** + 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] ImageThe image handle used to open service. + + @retval EFI_SUCCESS The configuration is done. +**/ +EFI_STATUS +EFIAPI +IfConfigStartIp4( + IN EFI_HANDLEController, + IN EFI_HANDLEImage + ) +{ + EFI_IP4_PROTOCOL *Ip4; + EFI_HANDLEIp4Handle; + EFI_IP4_CONFIG_DATA Ip4ConfigData; + EFI_STATUSStatus; + + // + // 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. @param[in]NodeThe pointer of MAC address buffer. @param[in]SizeThe size of MAC address buffer. @@ -872,25 +951,31 @@ IfConfigSetInterfaceInfo ( // // Process valid variables. // if (StrCmp(VarArg->Arg, L"dhcp") == 0) { - // - // Set dhcp config policy - // - Policy = Ip4Config2PolicyDhcp; - Status = IfCb->IfCfg->SetData ( - IfCb->IfCfg, - Ip4Config2DataTypePolicy, - sizeof (EFI_IP4_CONFIG2_POLICY), - &Policy - ); - - if (EFI_ERROR(Status)) { -goto ON_EXIT; + if (IfCb->Policy == Ip4Config2PolicyDhcp) { +Status = IfConfigStartIp4 (IfCb->NicHandle, gImageHandle); +if (EFI_ERROR(Status)) { + goto ON_EXIT; +} + } else { +// +// Set dhcp config policy +// +Policy = Ip4Config2PolicyDhcp; +Status = IfCb->IfCfg->SetData ( +IfCb->IfCfg, +Ip4Config2DataTypePolicy, +sizeof (EFI_IP4_CONFIG2_POLICY), +&Policy +); +if (EFI_ERROR(Status)) { + goto ON_EXIT; +} } - + VarArg= VarArg->Next; } else if (StrCmp (VarArg->Arg, L"static") == 0) { // // Set manual config policy. @@ -1036,11 +1121,11 @@ IfConfigSetInterfaceInfo ( ON_EXIT: if (Dns != NULL) { FreePool (Dns); } - return EFI_SUCCESS; + return Status; } /** The ifconfig command main process. -- 1.9.5.msysgit.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel