Re: [edk2] [Patch] NetworkPkg/UefiPxeBcDxe: Configure the ARP Instance/RouteTable with new address

2018-03-20 Thread Fu, Siyuan
Reviewed-by: Fu Siyuan 


> -Original Message-
> From: Wu, Jiaxin
> Sent: Tuesday, March 20, 2018 9:10 AM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Ye, Ting 
> Subject: [Patch] NetworkPkg/UefiPxeBcDxe: Configure the ARP
> Instance/RouteTable with new address
> 
> After completed a DHCP D.O.R.A process and got the new address, the ARP
> Instance
> and RouteTable should be configured so as to avoid the later Pxe.Arp
> failure.
> 
> Cc: Fu Siyuan 
> Cc: Ye Ting 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiaxin Wu 
> ---
>  NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c| 26 +++---
>  NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c | 66 -
> -
>  2 files changed, 52 insertions(+), 40 deletions(-)
> 
> diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> index d3146c3a7e..b828d24288 100644
> --- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> @@ -2001,11 +2001,10 @@ EfiPxeBcSetStationIP (
>)
>  {
>EFI_STATUS  Status;
>PXEBC_PRIVATE_DATA  *Private;
>EFI_PXE_BASE_CODE_MODE  *Mode;
> -  EFI_ARP_CONFIG_DATA ArpConfigData;
> 
>if (This == NULL) {
>  return EFI_INVALID_PARAMETER;
>}
> 
> @@ -2041,31 +2040,10 @@ EfiPxeBcSetStationIP (
>  //
>  Status = PxeBcRegisterIp6Address (Private, >v6);
>  if (EFI_ERROR (Status)) {
>goto ON_EXIT;
>  }
> -  } else if (!Mode->UsingIpv6 && NewStationIp != NULL) {
> -//
> -// Configure the corresponding ARP with the IPv4 address.
> -//
> -ZeroMem (, sizeof (EFI_ARP_CONFIG_DATA));
> -
> -ArpConfigData.SwAddressType   = 0x0800;
> -ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);
> -ArpConfigData.StationAddress  = >v4;
> -
> -Private->Arp->Configure (Private->Arp, NULL);
> -Private->Arp->Configure (Private->Arp, );
> -
> -if (NewSubnetMask != NULL) {
> -  Mode->RouteTableEntries= 1;
> -  Mode->RouteTable[0].IpAddr.Addr[0] = NewStationIp->Addr[0] &
> NewSubnetMask->Addr[0];
> -  Mode->RouteTable[0].SubnetMask.Addr[0] = NewSubnetMask->Addr[0];
> -  Mode->RouteTable[0].GwAddr.Addr[0] = 0;
> -}
> -
> -Private->IsAddressOk = TRUE;
>}
> 
>if (NewStationIp != NULL) {
>  CopyMem (>StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));
>  CopyMem (>StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));
> @@ -2075,10 +2053,14 @@ EfiPxeBcSetStationIP (
>  CopyMem (>SubnetMask, NewSubnetMask, sizeof (EFI_IP_ADDRESS));
>  CopyMem (>SubnetMask ,NewSubnetMask, sizeof
> (EFI_IP_ADDRESS));
>}
> 
>Status = PxeBcFlushStationIp (Private, NewStationIp, NewSubnetMask);
> +  if (!EFI_ERROR (Status)) {
> +Private->IsAddressOk = TRUE;
> +  }
> +
>  ON_EXIT:
>return Status;
>  }
> 
> 
> diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
> b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
> index 47bb7c5dbb..4b6f8c9c7f 100644
> --- a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
> +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
> @@ -1,9 +1,9 @@
>  /** @file
>Support functions implementation for UefiPxeBc Driver.
> 
> -  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
> +  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
> 
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of the
> BSD License
>which accompanies this distribution.  The full text of the license may
> be found at
>http://opensource.org/licenses/bsd-license.php.
> @@ -34,21 +34,23 @@ PxeBcFlushStationIp (
>EFI_IP_ADDRESS   *SubnetMask OPTIONAL
>)
>  {
>EFI_PXE_BASE_CODE_MODE   *Mode;
>EFI_STATUS   Status;
> +  EFI_ARP_CONFIG_DATA  ArpConfigData;
> 
>Mode   = Private->PxeBc.Mode;
>Status = EFI_SUCCESS;
> +  ZeroMem (, sizeof (EFI_ARP_CONFIG_DATA));
> 
> -  if (Mode->UsingIpv6) {
> -
> -if (StationIp != NULL) {
> -  CopyMem (>Udp6CfgData.StationAddress, StationIp, sizeof
> (EFI_IPv6_ADDRESS));
> -  CopyMem (>Ip6CfgData.StationAddress, StationIp, sizeof
> (EFI_IPv6_ADDRESS));
> -}
> -
> +  if (Mode->UsingIpv6 && StationIp != NULL) {
> +//
> +// Overwrite Udp6CfgData/Ip6CfgData StationAddress.
> +//
> +CopyMem (>Udp6CfgData.StationAddress, StationIp, sizeof
> (EFI_IPv6_ADDRESS));
> +CopyMem (>Ip6CfgData.StationAddress, StationIp, sizeof
> (EFI_IPv6_ADDRESS));
> +
>  //
>  // Reconfigure the Ip6 instance to capture background ICMP6 packets
> with new station Ip address.
>  //
>  Private->Ip6->Cancel (Private->Ip6, >Icmp6Token);
>  Private->Ip6->Configure (Private->Ip6, NULL);
> @@ -59,31 +61,59 @@ PxeBcFlushStationIp (
>  }
> 
>  Status = Private->Ip6->Receive (Private->Ip6, 

[edk2] [Patch] NetworkPkg/UefiPxeBcDxe: Configure the ARP Instance/RouteTable with new address

2018-03-19 Thread Jiaxin Wu
After completed a DHCP D.O.R.A process and got the new address, the ARP Instance
and RouteTable should be configured so as to avoid the later Pxe.Arp failure.

Cc: Fu Siyuan 
Cc: Ye Ting 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu 
---
 NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c| 26 +++---
 NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c | 66 --
 2 files changed, 52 insertions(+), 40 deletions(-)

diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c 
b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
index d3146c3a7e..b828d24288 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
@@ -2001,11 +2001,10 @@ EfiPxeBcSetStationIP (
   )
 {
   EFI_STATUS  Status;
   PXEBC_PRIVATE_DATA  *Private;
   EFI_PXE_BASE_CODE_MODE  *Mode;
-  EFI_ARP_CONFIG_DATA ArpConfigData;
 
   if (This == NULL) {
 return EFI_INVALID_PARAMETER;
   }
 
@@ -2041,31 +2040,10 @@ EfiPxeBcSetStationIP (
 //
 Status = PxeBcRegisterIp6Address (Private, >v6);
 if (EFI_ERROR (Status)) {
   goto ON_EXIT;
 }
-  } else if (!Mode->UsingIpv6 && NewStationIp != NULL) {
-//
-// Configure the corresponding ARP with the IPv4 address.
-//
-ZeroMem (, sizeof (EFI_ARP_CONFIG_DATA));
-
-ArpConfigData.SwAddressType   = 0x0800;
-ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);
-ArpConfigData.StationAddress  = >v4;
-
-Private->Arp->Configure (Private->Arp, NULL);
-Private->Arp->Configure (Private->Arp, );
-
-if (NewSubnetMask != NULL) {
-  Mode->RouteTableEntries= 1;
-  Mode->RouteTable[0].IpAddr.Addr[0] = NewStationIp->Addr[0] & 
NewSubnetMask->Addr[0];
-  Mode->RouteTable[0].SubnetMask.Addr[0] = NewSubnetMask->Addr[0];
-  Mode->RouteTable[0].GwAddr.Addr[0] = 0;
-}
-
-Private->IsAddressOk = TRUE;
   }
 
   if (NewStationIp != NULL) {
 CopyMem (>StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));
 CopyMem (>StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));
@@ -2075,10 +2053,14 @@ EfiPxeBcSetStationIP (
 CopyMem (>SubnetMask, NewSubnetMask, sizeof (EFI_IP_ADDRESS));
 CopyMem (>SubnetMask ,NewSubnetMask, sizeof (EFI_IP_ADDRESS));
   }
 
   Status = PxeBcFlushStationIp (Private, NewStationIp, NewSubnetMask);
+  if (!EFI_ERROR (Status)) {
+Private->IsAddressOk = TRUE;
+  }
+  
 ON_EXIT:
   return Status;
 }
 
 
diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c 
b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
index 47bb7c5dbb..4b6f8c9c7f 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
@@ -1,9 +1,9 @@
 /** @file
   Support functions implementation for UefiPxeBc Driver.
 
-  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
+  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
   http://opensource.org/licenses/bsd-license.php.
@@ -34,21 +34,23 @@ PxeBcFlushStationIp (
   EFI_IP_ADDRESS   *SubnetMask OPTIONAL
   )
 {
   EFI_PXE_BASE_CODE_MODE   *Mode;
   EFI_STATUS   Status;
+  EFI_ARP_CONFIG_DATA  ArpConfigData;
 
   Mode   = Private->PxeBc.Mode;
   Status = EFI_SUCCESS;
+  ZeroMem (, sizeof (EFI_ARP_CONFIG_DATA));
 
-  if (Mode->UsingIpv6) {
-
-if (StationIp != NULL) {
-  CopyMem (>Udp6CfgData.StationAddress, StationIp, sizeof 
(EFI_IPv6_ADDRESS));
-  CopyMem (>Ip6CfgData.StationAddress, StationIp, sizeof 
(EFI_IPv6_ADDRESS));
-}
-
+  if (Mode->UsingIpv6 && StationIp != NULL) {
+//
+// Overwrite Udp6CfgData/Ip6CfgData StationAddress.
+//
+CopyMem (>Udp6CfgData.StationAddress, StationIp, sizeof 
(EFI_IPv6_ADDRESS));
+CopyMem (>Ip6CfgData.StationAddress, StationIp, sizeof 
(EFI_IPv6_ADDRESS));
+
 //
 // Reconfigure the Ip6 instance to capture background ICMP6 packets with 
new station Ip address.
 //
 Private->Ip6->Cancel (Private->Ip6, >Icmp6Token);
 Private->Ip6->Configure (Private->Ip6, NULL);
@@ -59,31 +61,59 @@ PxeBcFlushStationIp (
 }
 
 Status = Private->Ip6->Receive (Private->Ip6, >Icmp6Token);
   } else {
 if (StationIp != NULL) {
+  //
+  // Reconfigure the ARP instance with station Ip address.
+  //
+  ArpConfigData.SwAddressType   = 0x0800;
+  ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);
+  ArpConfigData.StationAddress = StationIp;
+
+  Private->Arp->Configure (Private->Arp, NULL);
+  Private->Arp->Configure (Private->Arp, );
+
+  //
+  // Overwrite Udp4CfgData/Ip4CfgData StationAddress.
+  //
   CopyMem (>Udp4CfgData.StationAddress, StationIp, sizeof 
(EFI_IPv4_ADDRESS));