]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
1. Sync the latest network stack. Add NetLibCreateIPv4DPathNode () in netlib library.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Udp4Dxe / Udp4Impl.c
index e6fddd80520498f0f39a39fcb981555c674d014d..dd4ed1bf3241ad8e5d8d47e68ba30dec93d78224 100644 (file)
@@ -172,7 +172,7 @@ Udp4CreateService (
   //\r
   // Set the OpenData used to open the IpIo.\r
   //\r
-  CopyMem (&OpenData.IpConfigData, &mIpIoDefaultIpConfigData, sizeof (EFI_IP4_CONFIG_DATA));\r
+  CopyMem (&OpenData.IpConfigData, &mIpIoDefaultIpConfigData, sizeof (OpenData.IpConfigData));\r
   OpenData.IpConfigData.AcceptBroadcast = TRUE;\r
   OpenData.RcvdContext                  = (VOID *) Udp4Service;\r
   OpenData.SndContext                   = NULL;\r
@@ -359,7 +359,7 @@ Udp4InitInstance (
   // Save the pointer to the UDP4_SERVICE_DATA, and initialize other members.\r
   //\r
   Instance->Udp4Service = Udp4Service;\r
-  CopyMem (&Instance->Udp4Proto, &mUdp4Protocol, sizeof (EFI_UDP4_PROTOCOL));\r
+  CopyMem (&Instance->Udp4Proto, &mUdp4Protocol, sizeof (Instance->Udp4Proto));\r
   Instance->IcmpError   = EFI_SUCCESS;\r
   Instance->Configured  = FALSE;\r
   Instance->IsNoMapping = FALSE;\r
@@ -424,7 +424,7 @@ Udp4FindInstanceByPort (
       continue;\r
     }\r
 \r
-    if (EFI_IP_EQUAL (ConfigData->StationAddress, *Address) &&\r
+    if (EFI_IP4_EQUAL (&ConfigData->StationAddress, Address) &&\r
       (ConfigData->StationPort == Port)) {\r
       //\r
       // if both the address and the port are the same, return TRUE.\r
@@ -566,8 +566,8 @@ Udp4IsReconfigurable (
     }\r
 \r
     if (!NewConfigData->UseDefaultAddress &&\r
-      (!EFI_IP_EQUAL (NewConfigData->StationAddress, OldConfigData->StationAddress) ||\r
-      !EFI_IP_EQUAL (NewConfigData->SubnetMask, OldConfigData->SubnetMask))) {\r
+      (!EFI_IP4_EQUAL (&NewConfigData->StationAddress, &OldConfigData->StationAddress) ||\r
+      !EFI_IP4_EQUAL (&NewConfigData->SubnetMask, &OldConfigData->SubnetMask))) {\r
       //\r
       // If the instance doesn't use the default address, and the new address or\r
       // new subnet mask is different from the old values.\r
@@ -576,15 +576,14 @@ Udp4IsReconfigurable (
     }\r
   }\r
 \r
-  if (!EFI_IP_EQUAL (NewConfigData->RemoteAddress, OldConfigData->RemoteAddress)) {\r
+  if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &OldConfigData->RemoteAddress)) {\r
     //\r
     // The remoteaddress is not the same.\r
     //\r
     return FALSE;\r
   }\r
 \r
-  if ((EFI_IP4 (NewConfigData->RemoteAddress) != 0) &&\r
-    (NewConfigData->RemotePort != OldConfigData->RemotePort)) {\r
+  if (!EFI_IP4_EQUAL (&NewConfigData->RemoteAddress, &mZeroIp4Addr) && (NewConfigData->RemotePort != OldConfigData->RemotePort)) {\r
     //\r
     // The RemotePort differs if it's designated in the configdata.\r
     //\r
@@ -613,7 +612,7 @@ Udp4BuildIp4ConfigData (
   IN EFI_IP4_CONFIG_DATA   *Ip4ConfigData\r
   )\r
 {\r
-  CopyMem (Ip4ConfigData, &mIpIoDefaultIpConfigData, sizeof (EFI_IP4_CONFIG_DATA));\r
+  CopyMem (Ip4ConfigData, &mIpIoDefaultIpConfigData, sizeof (*Ip4ConfigData));\r
 \r
   Ip4ConfigData->DefaultProtocol   = EFI_IP_PROTO_UDP;\r
   Ip4ConfigData->AcceptBroadcast   = Udp4ConfigData->AcceptBroadcast;\r
@@ -667,6 +666,7 @@ Udp4ValidateTxToken (
   EFI_UDP4_CONFIG_DATA    *ConfigData;\r
   EFI_UDP4_SESSION_DATA   *UdpSessionData;\r
   IP4_ADDR                SourceAddress;\r
+  IP4_ADDR                GatewayAddress;\r
 \r
   if (TxToken->Event == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -700,12 +700,15 @@ Udp4ValidateTxToken (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if ((TxData->GatewayAddress != NULL) &&\r
-    !Ip4IsUnicast(EFI_NTOHL (*(TxData->GatewayAddress)), 0)) {\r
-    //\r
-    // The specified GatewayAddress is not a unicast IPv4 address while it's not 0.\r
-    //\r
-    return EFI_INVALID_PARAMETER;\r
+  if (TxData->GatewayAddress != NULL) {\r
+    NetCopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR));\r
+\r
+    if (!Ip4IsUnicast (NTOHL (GatewayAddress), 0)) {\r
+      //\r
+      // The specified GatewayAddress is not a unicast IPv4 address while it's not 0.\r
+      //\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
   }\r
 \r
   ConfigData     = &Instance->ConfigData;\r
@@ -713,9 +716,9 @@ Udp4ValidateTxToken (
 \r
   if (UdpSessionData != NULL) {\r
 \r
-    SourceAddress = EFI_NTOHL (UdpSessionData->SourceAddress);\r
+    NetCopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR));\r
 \r
-    if ((SourceAddress != 0) && !Ip4IsUnicast (SourceAddress, 0)) {\r
+    if ((SourceAddress != 0) && !Ip4IsUnicast (HTONL (SourceAddress), 0)) {\r
       //\r
       // Check whether SourceAddress is a valid IPv4 address in case it's not zero.\r
       // The configured station address is used if SourceAddress is zero.\r
@@ -730,13 +733,13 @@ Udp4ValidateTxToken (
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    if (EFI_IP4 (UdpSessionData->DestinationAddress) == 0) {\r
+    if (EFI_IP4_EQUAL (&UdpSessionData->DestinationAddress, &mZeroIp4Addr)) {\r
       //\r
       // The DestinationAddress specified in the UdpSessionData is 0.\r
       //\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-  } else if (EFI_IP4 (ConfigData->RemoteAddress) == 0) {\r
+  } else if (EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &mZeroIp4Addr)) {\r
     //\r
     // the configured RemoteAddress is all zero, and the user doens't override the\r
     // destination address.\r
@@ -814,7 +817,7 @@ Udp4Checksum (
 \r
   Checksum  = NetAddChecksum (Checksum, HTONS ((UINT16) Packet->TotalSize));\r
 \r
-  return ~Checksum;\r
+  return (UINT16) ~Checksum;\r
 }\r
 \r
 \r
@@ -959,7 +962,7 @@ Udp4LeaveGroup (
 \r
   McastIp = Arg;\r
 \r
-  if ((McastIp != NULL) && ((UINTN) EFI_IP4 (*McastIp) != (UINTN) (Item->Key))) {\r
+  if ((McastIp != NULL) && (!EFI_IP4_EQUAL (McastIp, &(Item->Key)))) {\r
     //\r
     // McastIp is not NULL and the multicast address contained in the Item\r
     // is not the same as McastIp.\r
@@ -1169,16 +1172,16 @@ Udp4MatchDgram (
     return FALSE;\r
   }\r
 \r
-  if ((EFI_IP4 (ConfigData->RemoteAddress) != 0) &&\r
-    !EFI_IP_EQUAL (ConfigData->RemoteAddress, Udp4Session->SourceAddress)) {\r
+  if (!EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &mZeroIp4Addr) &&\r
+    !EFI_IP4_EQUAL (&ConfigData->RemoteAddress, &Udp4Session->SourceAddress)) {\r
     //\r
     // This datagram doesn't come from the instance's specified sender.\r
     //\r
     return FALSE;\r
   }\r
 \r
-  if ((EFI_IP4 (ConfigData->StationAddress) == 0) ||\r
-    EFI_IP_EQUAL (Udp4Session->DestinationAddress, ConfigData->StationAddress)) {\r
+  if (EFI_IP4_EQUAL (&ConfigData->StationAddress, &mZeroIp4Addr) ||\r
+    EFI_IP4_EQUAL (&Udp4Session->DestinationAddress, &ConfigData->StationAddress)) {\r
     //\r
     // The instance is configured to receive datagrams destinated to any station IP or\r
     // the destination address of this datagram matches the configured station IP.\r
@@ -1186,7 +1189,7 @@ Udp4MatchDgram (
     return TRUE;\r
   }\r
 \r
-  Destination = EFI_IP4 (Udp4Session->DestinationAddress);\r
+  NetCopyMem (&Destination, &Udp4Session->DestinationAddress, sizeof (IP4_ADDR));\r
 \r
   if (IP4_IS_LOCAL_BROADCAST (Destination) && ConfigData->AcceptBroadcast) {\r
     //\r
@@ -1281,7 +1284,7 @@ Udp4WrapRxData (
 \r
   NetListInit (&Wrap->Link);\r
 \r
-  CopyMem (&Wrap->RxData, RxData, sizeof (EFI_UDP4_RECEIVE_DATA));\r
+  CopyMem (&Wrap->RxData, RxData, sizeof (Wrap->RxData));\r
 \r
   //\r
   // Create the Recycle event.\r
@@ -1346,7 +1349,7 @@ Udp4EnqueueDgram (
       //\r
       // Wrap the RxData and put this Wrap into the instances RcvdDgramQue.\r
       //\r
-      CopyMem (&Wrap, Udp4WrapRxData (Instance, Packet, RxData), sizeof (UDP4_RXDATA_WRAP));\r
+      Wrap = Udp4WrapRxData (Instance, Packet, RxData);\r
       if (Wrap == NULL) {\r
         continue;\r
       }\r
@@ -1513,11 +1516,12 @@ Udp4Demultiplex (
 \r
   gRT->GetTime (&RxData.TimeStamp, NULL);\r
 \r
-  Udp4Session                               = &RxData.UdpSession;\r
-  EFI_IP4 (Udp4Session->SourceAddress)      = NetSession->Source;\r
-  EFI_IP4 (Udp4Session->DestinationAddress) = NetSession->Dest;\r
-  Udp4Session->SourcePort                   = NTOHS (Udp4Header->SrcPort);\r
-  Udp4Session->DestinationPort              = NTOHS (Udp4Header->DstPort);\r
+  Udp4Session                  = &RxData.UdpSession;\r
+  Udp4Session->SourcePort      = NTOHS (Udp4Header->SrcPort);\r
+  Udp4Session->DestinationPort = NTOHS (Udp4Header->DstPort);\r
+\r
+  NetCopyMem (&Udp4Session->SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));\r
+  NetCopyMem (&Udp4Session->DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   //\r
   // Trim the UDP header.\r
@@ -1632,17 +1636,18 @@ Udp4SendPortUnreach (
   //\r
   // Calculate the checksum.\r
   //\r
-  IcmpErrHdr->Head.Checksum = ~(NetbufChecksum (Packet));\r
+  IcmpErrHdr->Head.Checksum = (UINT16) ~(NetbufChecksum (Packet));\r
 \r
   //\r
   // Fill the override data.\r
   //\r
-  Override.DoNotFragment            = FALSE;\r
-  Override.TypeOfService            = 0;\r
-  Override.TimeToLive               = 255;\r
-  Override.Protocol                 = EFI_IP_PROTO_ICMP;\r
-  EFI_IP4 (Override.SourceAddress)  = NetSession->Dest;\r
-  EFI_IP4 (Override.GatewayAddress) = 0;\r
+  Override.DoNotFragment = FALSE;\r
+  Override.TypeOfService = 0;\r
+  Override.TimeToLive    = 255;\r
+  Override.Protocol      = EFI_IP_PROTO_ICMP;\r
+\r
+  NetCopyMem (&Override.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
+  NetZeroMem (&Override.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   //\r
   // Send out this icmp packet.\r
@@ -1682,10 +1687,11 @@ Udp4IcmpHandler (
 \r
   Udp4Header = (EFI_UDP4_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
 \r
-  EFI_IP4 (Udp4Session.SourceAddress)      = NetSession->Source;\r
-  EFI_IP4 (Udp4Session.DestinationAddress) = NetSession->Dest;\r
-  Udp4Session.SourcePort                   = NTOHS (Udp4Header->DstPort);\r
-  Udp4Session.DestinationPort              = NTOHS (Udp4Header->SrcPort);\r
+  NetCopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));\r
+  NetCopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
+\r
+  Udp4Session.SourcePort      = NTOHS (Udp4Header->DstPort);\r
+  Udp4Session.DestinationPort = NTOHS (Udp4Header->SrcPort);\r
 \r
   NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
     //\r
@@ -1696,7 +1702,7 @@ Udp4IcmpHandler (
     if (!Instance->Configured ||\r
       Instance->ConfigData.AcceptPromiscuous ||\r
       Instance->ConfigData.AcceptAnyPort ||\r
-      (EFI_IP4 (Instance->ConfigData.StationAddress) == 0)) {\r
+      EFI_IP4_EQUAL (&Instance->ConfigData.StationAddress, &mZeroIp4Addr)) {\r
       //\r
       // Don't try to deliver the ICMP error to this instance if it is not configured,\r
       // or it's configured to be promiscuous or accept any port or accept all the\r