Re: [edk2] [PATCH v2] MdeModulePkg: IP4 should re-initiate a DHCP while network reconnection
Reviewed-by: Ye Ting ting...@intel.com -Original Message- From: Wu, Jiaxin Sent: Monday, August 17, 2015 11:25 AM To: edk2-devel@lists.01.org Cc: Ye, Ting; Zhang, Lubo Subject: [PATCH v2] MdeModulePkg: IP4 should re-initiate a DHCP while network reconnection v2: * Update the MediaPresent detect declaring. IP4 driver should re-initiate a DHCP if it detects that there is a network reconnection. To fix this issue, we can implement the DHCP re-initiate policy while the media change detected. The Ip4 driver should set a timer to signal the Ip4 to run the DHCP configuration again(D.O.R.A). IP4 driver should free old IP address related resource, then initiate a DHCP process to acquire new IP. Cc: Ye Ting ting...@intel.com Cc: Zhang Lubo lubo.zh...@intel.com Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu jiaxin...@intel.com --- .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c | 1 + MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c | 10 ++ MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c| 121 - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h| 7 ++ 4 files changed, 133 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c index fcb2bdd..caf84fb 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c @@ -490,10 +490,11 @@ Ip4Config2SetDefaultAddr ( IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance); IpIf = IpSb-DefaultInterface; ASSERT (IpIf != NULL); if ((IpIf-Ip == StationAddress) (IpIf-SubnetMask == SubnetMask)) { +IpSb-State = IP4_SERVICE_CONFIGED; return EFI_SUCCESS; } // // The default address is changed, free the previous interface first. diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c index 101390c..4d3ccec 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c @@ -208,10 +208,14 @@ Ip4CreateService ( ZeroMem (IpSb-SnpMode, sizeof (EFI_SIMPLE_NETWORK_MODE)); IpSb-Timer = NULL; + IpSb-ReconfigEvent = NULL; + + IpSb-MediaPresent = TRUE; + // // Create various resources. First create the route table, timer // event and MNP child. IGMP, interface's initialization depend // on the MNP child. // @@ -384,10 +388,16 @@ Ip4CleanService ( gBS-CloseEvent (IpSb-Timer); IpSb-Timer = NULL; } + if (IpSb-ReconfigEvent != NULL) { +gBS-CloseEvent (IpSb-ReconfigEvent); + +IpSb-ReconfigEvent = NULL; + } + if (IpSb-MacString != NULL) { FreePool (IpSb-MacString); } Ip4Config2CleanInstance (IpSb-Ip4Config2Instance); diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c index 2fb4f4c..ac8fb1a 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c @@ -561,10 +561,58 @@ Ip4InitProtocol ( EfiInitializeLock (IpInstance-RecycleLock, TPL_NOTIFY); } +/** + The event handle for IP4 auto reconfiguration. The original default + interface and route table will be removed as the default. + + @param[in] ContextThe IP4 service binding instance. + +**/ +VOID +EFIAPI +Ip4AutoReconfigCallBackDpc ( + IN VOID *Context + ) +{ + IP4_SERVICE *IpSb; + + IpSb = (IP4_SERVICE *) Context; + NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE); + + if (IpSb-State IP4_SERVICE_UNSTARTED) { +IpSb-State = IP4_SERVICE_UNSTARTED; } + + Ip4StartAutoConfig (IpSb-Ip4Config2Instance); + + return ; +} + + +/** + Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK. + + @param Event The event that is signalled. + @param Context The IP4 service binding instance. + +**/ +VOID +EFIAPI +Ip4AutoReconfigCallBack ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK + // + QueueDpc (TPL_CALLBACK, Ip4AutoReconfigCallBackDpc, Context); } + /** Configure the IP4 child. If the child is already configured, change the configuration parameter. Otherwise configure it for the first time. The caller should validate the configuration @@ -676,14 +724,31 @@ Ip4ConfigProtocol ( // // Use the default address. If the default configuration hasn't // been started, start it. // if (IpSb-State == IP4_SERVICE_UNSTARTED) { + // + // Create the ReconfigEvent to start the new configuration. + // + if (IpSb-ReconfigEvent == NULL) { +Status = gBS-CreateEvent ( +EVT_NOTIFY_SIGNAL, +TPL_NOTIFY, +Ip4AutoReconfigCallBack, +IpSb, +
[edk2] [PATCH v2] MdeModulePkg: IP4 should re-initiate a DHCP while network reconnection
v2: * Update the MediaPresent detect declaring. IP4 driver should re-initiate a DHCP if it detects that there is a network reconnection. To fix this issue, we can implement the DHCP re-initiate policy while the media change detected. The Ip4 driver should set a timer to signal the Ip4 to run the DHCP configuration again(D.O.R.A). IP4 driver should free old IP address related resource, then initiate a DHCP process to acquire new IP. Cc: Ye Ting ting...@intel.com Cc: Zhang Lubo lubo.zh...@intel.com Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu jiaxin...@intel.com --- .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c | 1 + MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c | 10 ++ MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c| 121 - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h| 7 ++ 4 files changed, 133 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c index fcb2bdd..caf84fb 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c @@ -490,10 +490,11 @@ Ip4Config2SetDefaultAddr ( IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance); IpIf = IpSb-DefaultInterface; ASSERT (IpIf != NULL); if ((IpIf-Ip == StationAddress) (IpIf-SubnetMask == SubnetMask)) { +IpSb-State = IP4_SERVICE_CONFIGED; return EFI_SUCCESS; } // // The default address is changed, free the previous interface first. diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c index 101390c..4d3ccec 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c @@ -208,10 +208,14 @@ Ip4CreateService ( ZeroMem (IpSb-SnpMode, sizeof (EFI_SIMPLE_NETWORK_MODE)); IpSb-Timer = NULL; + IpSb-ReconfigEvent = NULL; + + IpSb-MediaPresent = TRUE; + // // Create various resources. First create the route table, timer // event and MNP child. IGMP, interface's initialization depend // on the MNP child. // @@ -384,10 +388,16 @@ Ip4CleanService ( gBS-CloseEvent (IpSb-Timer); IpSb-Timer = NULL; } + if (IpSb-ReconfigEvent != NULL) { +gBS-CloseEvent (IpSb-ReconfigEvent); + +IpSb-ReconfigEvent = NULL; + } + if (IpSb-MacString != NULL) { FreePool (IpSb-MacString); } Ip4Config2CleanInstance (IpSb-Ip4Config2Instance); diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c index 2fb4f4c..ac8fb1a 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c @@ -561,10 +561,58 @@ Ip4InitProtocol ( EfiInitializeLock (IpInstance-RecycleLock, TPL_NOTIFY); } +/** + The event handle for IP4 auto reconfiguration. The original default + interface and route table will be removed as the default. + + @param[in] ContextThe IP4 service binding instance. + +**/ +VOID +EFIAPI +Ip4AutoReconfigCallBackDpc ( + IN VOID *Context + ) +{ + IP4_SERVICE *IpSb; + + IpSb = (IP4_SERVICE *) Context; + NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE); + + if (IpSb-State IP4_SERVICE_UNSTARTED) { +IpSb-State = IP4_SERVICE_UNSTARTED; + } + + Ip4StartAutoConfig (IpSb-Ip4Config2Instance); + + return ; +} + + +/** + Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK. + + @param Event The event that is signalled. + @param Context The IP4 service binding instance. + +**/ +VOID +EFIAPI +Ip4AutoReconfigCallBack ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK + // + QueueDpc (TPL_CALLBACK, Ip4AutoReconfigCallBackDpc, Context); +} + /** Configure the IP4 child. If the child is already configured, change the configuration parameter. Otherwise configure it for the first time. The caller should validate the configuration @@ -676,14 +724,31 @@ Ip4ConfigProtocol ( // // Use the default address. If the default configuration hasn't // been started, start it. // if (IpSb-State == IP4_SERVICE_UNSTARTED) { + // + // Create the ReconfigEvent to start the new configuration. + // + if (IpSb-ReconfigEvent == NULL) { +Status = gBS-CreateEvent ( +EVT_NOTIFY_SIGNAL, +TPL_NOTIFY, +Ip4AutoReconfigCallBack, +IpSb, +IpSb-ReconfigEvent +); + +if (EFI_ERROR (Status)) { + goto ON_ERROR; +} + } + Status = Ip4StartAutoConfig (IpSb-Ip4Config2Instance); if (EFI_ERROR (Status)) { -goto