]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c
NetworkPkg/UefiPxeBcDxe: Configure the ARP Instance/RouteTable with new address
[mirror_edk2.git] / NetworkPkg / UefiPxeBcDxe / PxeBcSupport.c
index 47bb7c5dbbbcf12816c01ef9b1f4e9ea012b2fe7..4b6f8c9c7feff899abe478e69962476b0d2f8790 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support functions implementation for UefiPxeBc Driver.\r
 \r
-  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -36,17 +36,19 @@ PxeBcFlushStationIp (
 {\r
   EFI_PXE_BASE_CODE_MODE   *Mode;\r
   EFI_STATUS               Status;\r
+  EFI_ARP_CONFIG_DATA      ArpConfigData;\r
 \r
   Mode   = Private->PxeBc.Mode;\r
   Status = EFI_SUCCESS;\r
+  ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));\r
 \r
-  if (Mode->UsingIpv6) {\r
-\r
-    if (StationIp != NULL) {\r
-      CopyMem (&Private->Udp6CfgData.StationAddress, StationIp, sizeof (EFI_IPv6_ADDRESS));\r
-      CopyMem (&Private->Ip6CfgData.StationAddress, StationIp, sizeof (EFI_IPv6_ADDRESS));\r
-    }\r
-\r
+  if (Mode->UsingIpv6 && StationIp != NULL) {\r
+    //\r
+    // Overwrite Udp6CfgData/Ip6CfgData StationAddress.\r
+    //\r
+    CopyMem (&Private->Udp6CfgData.StationAddress, StationIp, sizeof (EFI_IPv6_ADDRESS));\r
+    CopyMem (&Private->Ip6CfgData.StationAddress, StationIp, sizeof (EFI_IPv6_ADDRESS));\r
+    \r
     //\r
     // Reconfigure the Ip6 instance to capture background ICMP6 packets with new station Ip address.\r
     //\r
@@ -61,27 +63,55 @@ PxeBcFlushStationIp (
     Status = Private->Ip6->Receive (Private->Ip6, &Private->Icmp6Token);\r
   } else {\r
     if (StationIp != NULL) {\r
+      //\r
+      // Reconfigure the ARP instance with station Ip address.\r
+      //\r
+      ArpConfigData.SwAddressType   = 0x0800;\r
+      ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);\r
+      ArpConfigData.StationAddress = StationIp;\r
+\r
+      Private->Arp->Configure (Private->Arp, NULL);\r
+      Private->Arp->Configure (Private->Arp, &ArpConfigData);\r
+\r
+      //\r
+      // Overwrite Udp4CfgData/Ip4CfgData StationAddress.\r
+      //\r
       CopyMem (&Private->Udp4CfgData.StationAddress, StationIp, sizeof (EFI_IPv4_ADDRESS));\r
       CopyMem (&Private->Ip4CfgData.StationAddress, StationIp, sizeof (EFI_IPv4_ADDRESS));\r
     }\r
     \r
     if (SubnetMask != NULL) {\r
+      //\r
+      // Overwrite Udp4CfgData/Ip4CfgData SubnetMask.\r
+      //\r
       CopyMem (&Private->Udp4CfgData.SubnetMask, SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
       CopyMem (&Private->Ip4CfgData.SubnetMask, SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
     }\r
 \r
-    //\r
-    // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.\r
-    //\r
-    Private->Ip4->Cancel (Private->Ip4, &Private->IcmpToken);\r
-    Private->Ip4->Configure (Private->Ip4, NULL);\r
-\r
-    Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4CfgData);\r
-    if (EFI_ERROR (Status)) {\r
-      goto ON_EXIT;\r
+    if (StationIp != NULL && SubnetMask != NULL) {\r
+      //\r
+      // Updated the route table.\r
+      //\r
+      Mode->RouteTableEntries                = 1;\r
+      Mode->RouteTable[0].IpAddr.Addr[0]     = StationIp->Addr[0] & SubnetMask->Addr[0];\r
+      Mode->RouteTable[0].SubnetMask.Addr[0] = SubnetMask->Addr[0];\r
+      Mode->RouteTable[0].GwAddr.Addr[0]     = 0;\r
     }\r
+    \r
+    if (StationIp != NULL || SubnetMask != NULL) {\r
+      //\r
+      // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.\r
+      //\r
+      Private->Ip4->Cancel (Private->Ip4, &Private->IcmpToken);\r
+      Private->Ip4->Configure (Private->Ip4, NULL);\r
 \r
-    Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpToken);\r
+      Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4CfgData);\r
+      if (EFI_ERROR (Status)) {\r
+        goto ON_EXIT;\r
+      }\r
+\r
+      Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpToken);\r
+    }\r
   }\r
 \r
 ON_EXIT:\r