]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
1. Update the UdpIo to a combined UdpIo to support both v4 and v6 stack.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Impl.c
index a4b8fa8137d3860dc19d3abcae531c3cb9c1a84b..acacec7bb150d2c187bacb0d32b3f85e56cd27b5 100644 (file)
@@ -826,7 +826,7 @@ EfiDhcp4Start (
 \r
   if (CompletionEvent == NULL) {\r
     while (DhcpSb->IoStatus == EFI_ALREADY_STARTED) {\r
-      DhcpSb->UdpIo->Udp->Poll (DhcpSb->UdpIo->Udp);\r
+      DhcpSb->UdpIo->Protocol.Udp4->Poll (DhcpSb->UdpIo->Protocol.Udp4);\r
     }\r
 \r
     return DhcpSb->IoStatus;\r
@@ -951,7 +951,8 @@ EfiDhcp4RenewRebind (
 \r
   if (CompletionEvent == NULL) {\r
     while (DhcpSb->IoStatus == EFI_ALREADY_STARTED) {\r
-      DhcpSb->UdpIo->Udp->Poll (DhcpSb->UdpIo->Udp);\r
+      DhcpSb->UdpIo->Protocol.Udp4->Poll (DhcpSb->UdpIo->Protocol.Udp4);\r
+\r
     }\r
 \r
     return DhcpSb->IoStatus;\r
@@ -1173,7 +1174,7 @@ EfiDhcp4Build (
 **/\r
 EFI_STATUS\r
 Dhcp4InstanceConfigUdpIo (\r
-  IN UDP_IO_PORT  *UdpIo,\r
+  IN UDP_IO       *UdpIo,\r
   IN VOID         *Context\r
   )\r
 {\r
@@ -1206,7 +1207,7 @@ Dhcp4InstanceConfigUdpIo (
     UdpConfigData.StationPort = Token->ListenPoints[0].ListenPort;\r
   }\r
 \r
-  return UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfigData);\r
+  return UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData);\r
 }\r
 \r
 /**\r
@@ -1228,7 +1229,13 @@ Dhcp4InstanceCreateUdpIo (
   ASSERT (Instance->Token != NULL);\r
 \r
   DhcpSb          = Instance->Service;\r
-  Instance->UdpIo = UdpIoCreatePort (DhcpSb->Controller, DhcpSb->Image, Dhcp4InstanceConfigUdpIo, Instance);\r
+  Instance->UdpIo = UdpIoCreateIo (\r
+                      DhcpSb->Controller,\r
+                      DhcpSb->Image,\r
+                      Dhcp4InstanceConfigUdpIo,\r
+                      UDP_IO_UDP4_VERSION,\r
+                      Instance\r
+                      );\r
   if (Instance->UdpIo == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   } else {\r
@@ -1256,7 +1263,7 @@ DhcpDummyExtFree (
   sent out. The packet will be queued to the response queue.\r
   \r
   @param UdpPacket        The Dhcp4 packet.\r
-  @param Points           Udp4 address pair.\r
+  @param EndPoint         Udp4 address pair.\r
   @param IoStatus         Status of the input.\r
   @param Context          Extra info for the input.\r
   \r
@@ -1264,7 +1271,7 @@ DhcpDummyExtFree (
 VOID\r
 PxeDhcpInput (\r
   NET_BUF                   *UdpPacket,\r
-  UDP_POINTS                *Points,\r
+  UDP_END_POINT             *EndPoint,\r
   EFI_STATUS                IoStatus,\r
   VOID                      *Context\r
   )\r
@@ -1397,8 +1404,8 @@ SIGNAL_USER:
   // Clean up the resources dedicated for this transmit receive transaction.\r
   //\r
   NetbufQueFlush (&Instance->ResponseQueue);\r
-  UdpIoCleanPort (Instance->UdpIo);\r
-  UdpIoFreePort (Instance->UdpIo);\r
+  UdpIoCleanIo (Instance->UdpIo);\r
+  UdpIoFreeIo (Instance->UdpIo);\r
   Instance->UdpIo = NULL;\r
   Instance->Token = NULL;\r
 \r
@@ -1439,10 +1446,10 @@ EfiDhcp4TransmitReceive (
   EFI_STATUS     Status;\r
   NET_FRAGMENT   Frag;\r
   NET_BUF        *Wrap;\r
-  UDP_POINTS     EndPoint;\r
+  UDP_END_POINT  EndPoint;\r
   IP4_ADDR       Ip;\r
   DHCP_SERVICE   *DhcpSb;\r
-  IP4_ADDR       Gateway;\r
+  EFI_IP_ADDRESS Gateway;\r
   IP4_ADDR       SubnetMask;\r
 \r
   if ((This == NULL) || (Token == NULL) || (Token->Packet == NULL)) {\r
@@ -1516,16 +1523,15 @@ EfiDhcp4TransmitReceive (
   }\r
 \r
   //\r
-  // Set the local address and local port.\r
+  // Set the local address and local port to ZERO.\r
   //\r
-  EndPoint.LocalAddr = 0;\r
-  EndPoint.LocalPort = 0;\r
+  ZeroMem (&EndPoint, sizeof (UDP_END_POINT));\r
 \r
   //\r
   // Set the destination address and destination port.\r
   //\r
   CopyMem (&Ip, &Token->RemoteAddress, sizeof (EFI_IPv4_ADDRESS));\r
-  EndPoint.RemoteAddr = NTOHL (Ip);\r
+  EndPoint.RemoteAddr.Addr[0] = NTOHL (Ip);\r
 \r
   if (Token->RemotePort == 0) {\r
     EndPoint.RemotePort = DHCP_SERVER_PORT;\r
@@ -1537,16 +1543,16 @@ EfiDhcp4TransmitReceive (
   // Get the gateway.\r
   //\r
   SubnetMask = DhcpSb->Netmask;\r
-  Gateway    = 0;\r
-  if (!IP4_NET_EQUAL (DhcpSb->ClientAddr, EndPoint.RemoteAddr, SubnetMask)) {\r
-    CopyMem (&Gateway, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
-    Gateway = NTOHL (Gateway);\r
+  ZeroMem (&Gateway, sizeof (Gateway));\r
+  if (!IP4_NET_EQUAL (DhcpSb->ClientAddr, EndPoint.RemoteAddr.Addr[0], SubnetMask)) {\r
+    CopyMem (&Gateway.v4, &Token->GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
+    Gateway.Addr[0] = NTOHL (Gateway.Addr[0]);\r
   }\r
 \r
   //\r
   // Transmit the DHCP packet.\r
   //\r
-  Status = UdpIoSendDatagram (Instance->UdpIo, Wrap, &EndPoint, Gateway, DhcpOnPacketSent, NULL);\r
+  Status = UdpIoSendDatagram (Instance->UdpIo, Wrap, &EndPoint, &Gateway, DhcpOnPacketSent, NULL);\r
   if (EFI_ERROR (Status)) {\r
     NetbufFree (Wrap);\r
     goto ON_ERROR;\r
@@ -1563,8 +1569,8 @@ EfiDhcp4TransmitReceive (
 ON_ERROR:\r
 \r
   if (EFI_ERROR (Status) && (Instance->UdpIo != NULL)) {\r
-    UdpIoCleanPort (Instance->UdpIo);\r
-    UdpIoFreePort (Instance->UdpIo);\r
+    UdpIoCleanIo (Instance->UdpIo);\r
+    UdpIoFreeIo (Instance->UdpIo);\r
     Instance->UdpIo = NULL;\r
     Instance->Token = NULL;\r
   }\r
@@ -1583,7 +1589,7 @@ ON_ERROR:
       // free it when timeout.\r
       //\r
       if (Instance->Timeout > 0) {\r
-        Instance->UdpIo->Udp->Poll (Instance->UdpIo->Udp);\r
+        Instance->UdpIo->Protocol.Udp4->Poll (Instance->UdpIo->Protocol.Udp4);\r
         gBS->RestoreTPL (OldTpl);\r
       } else {\r
         gBS->RestoreTPL (OldTpl);\r