]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Udp4Dxe / Udp4Impl.c
index 2751cdccbd3dc93afca73b84ab77d9dfd583abf8..fb1951fb135774591ac3cc859b6d47ce1cf531c5 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   The implementation of the Udp4 protocol.\r
-  \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
 \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -59,17 +53,17 @@ Udp4FindInstanceByPort (
 \r
   @param[in]  Status                 The completion status of the output udp datagram.\r
   @param[in]  Context                Pointer to the context data.\r
-  @param[in]  Sender                 Pointer to the Ip sender of the udp datagram.\r
+  @param[in]  Sender                 Specify a pointer of EFI_IP4_PROTOCOL for sending.\r
   @param[in]  NotifyData             Pointer to the notify data.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 Udp4DgramSent (\r
-  IN EFI_STATUS  Status,\r
-  IN VOID        *Context,\r
-  IN VOID        *Sender,\r
-  IN VOID        *NotifyData\r
+  IN EFI_STATUS        Status,\r
+  IN VOID              *Context,\r
+  IN IP_IO_IP_PROTOCOL Sender,\r
+  IN VOID              *NotifyData\r
   );\r
 \r
 /**\r
@@ -200,10 +194,10 @@ Udp4DeliverDgram (
   );\r
 \r
 /**\r
-  This function demultiplexes the received udp datagram to the apropriate instances.\r
+  This function demultiplexes the received udp datagram to the appropriate instances.\r
 \r
   @param[in]  Udp4Service            Pointer to the udp service context data.\r
-  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA abstrated from\r
+  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA abstracted from\r
                                      the received datagram.\r
   @param[in]  Packet                 Pointer to the buffer containing the received udp\r
                                      datagram.\r
@@ -431,7 +425,7 @@ Udp4CheckTimeout (
       //\r
       // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.\r
       //\r
-      if (Wrap->TimeoutTick <= (UDP4_TIMEOUT_INTERVAL / 10)) {\r
+      if (Wrap->TimeoutTick < (UDP4_TIMEOUT_INTERVAL / 10)) {\r
         //\r
         // Remove this RxData if it timeouts.\r
         //\r
@@ -484,7 +478,7 @@ Udp4InitInstance (
   Instance->IcmpError   = EFI_SUCCESS;\r
   Instance->Configured  = FALSE;\r
   Instance->IsNoMapping = FALSE;\r
-  Instance->Destroyed   = FALSE;\r
+  Instance->InDestroy   = FALSE;\r
 }\r
 \r
 \r
@@ -827,7 +821,9 @@ Udp4ValidateTxToken (
   if (TxData->GatewayAddress != NULL) {\r
     CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR));\r
 \r
-    if (!NetIp4IsUnicast (NTOHL (GatewayAddress), 0)) {\r
+    if (!Instance->ConfigData.UseDefaultAddress &&\r
+        (EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&\r
+        !NetIp4IsUnicast (NTOHL (GatewayAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {\r
       //\r
       // The specified GatewayAddress is not a unicast IPv4 address while it's not 0.\r
       //\r
@@ -842,7 +838,10 @@ Udp4ValidateTxToken (
 \r
     CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR));\r
 \r
-    if ((SourceAddress != 0) && !NetIp4IsUnicast (HTONL (SourceAddress), 0)) {\r
+    if ((SourceAddress != 0) &&\r
+        !Instance->ConfigData.UseDefaultAddress &&\r
+        (EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&\r
+        !NetIp4IsUnicast (HTONL (SourceAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {\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
@@ -989,17 +988,17 @@ Udp4RemoveToken (
 \r
   @param[in]  Status                 The completion status of the output udp datagram.\r
   @param[in]  Context                Pointer to the context data.\r
-  @param[in]  Sender                 Pointer to the Ip sender of the udp datagram.\r
+  @param[in]  Sender                 Specify a pointer of EFI_IP4_PROTOCOL for sending.\r
   @param[in]  NotifyData             Pointer to the notify data.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 Udp4DgramSent (\r
-  IN EFI_STATUS  Status,\r
-  IN VOID        *Context,\r
-  IN VOID        *Sender,\r
-  IN VOID        *NotifyData\r
+  IN EFI_STATUS        Status,\r
+  IN VOID              *Context,\r
+  IN IP_IO_IP_PROTOCOL Sender,\r
+  IN VOID              *NotifyData\r
   )\r
 {\r
   UDP4_INSTANCE_DATA         *Instance;\r
@@ -1586,10 +1585,10 @@ Udp4DeliverDgram (
 \r
 \r
 /**\r
-  This function demultiplexes the received udp datagram to the apropriate instances.\r
+  This function demultiplexes the received udp datagram to the appropriate instances.\r
 \r
   @param[in]  Udp4Service            Pointer to the udp service context data.\r
-  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA abstrated from\r
+  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA abstracted from\r
                                      the received datagram.\r
   @param[in]  Packet                 Pointer to the buffer containing the received udp\r
                                      datagram.\r
@@ -1608,10 +1607,16 @@ Udp4Demultiplex (
   EFI_UDP4_SESSION_DATA  *Udp4Session;\r
   UINTN                  Enqueued;\r
 \r
+  if (Packet->TotalSize < sizeof (EFI_UDP_HEADER)) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
+\r
   //\r
   // Get the datagram header from the packet buffer.\r
   //\r
   Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  ASSERT (Udp4Header != NULL);\r
 \r
   if (Udp4Header->Checksum != 0) {\r
     //\r
@@ -1628,12 +1633,11 @@ Udp4Demultiplex (
       //\r
       // Wrong checksum.\r
       //\r
+      NetbufFree (Packet);\r
       return;\r
     }\r
   }\r
 \r
-  gRT->GetTime (&RxData.TimeStamp, NULL);\r
-\r
   Udp4Session                  = &RxData.UdpSession;\r
   Udp4Session->SourcePort      = NTOHS (Udp4Header->SrcPort);\r
   Udp4Session->DestinationPort = NTOHS (Udp4Header->DstPort);\r
@@ -1702,7 +1706,7 @@ Udp4SendPortUnreach (
   IpSender = IpIoFindSender (&IpIo, NetSession->IpVersion, &NetSession->Dest);\r
   if (IpSender == NULL) {\r
     //\r
-    // No apropriate sender, since we cannot send out the ICMP message through\r
+    // No appropriate sender, since we cannot send out the ICMP message through\r
     // the default zero station address IP instance, abort.\r
     //\r
     return;\r
@@ -1711,7 +1715,7 @@ Udp4SendPortUnreach (
   IpHdr = NetSession->IpHdr.Ip4Hdr;\r
 \r
   //\r
-  // Calculate the requried length of the icmp error message.\r
+  // Calculate the required length of the icmp error message.\r
   //\r
   Len = sizeof (IP4_ICMP_ERROR_HEAD) + (EFI_IP4_HEADER_LEN (IpHdr) -\r
         sizeof (IP4_HEAD)) + ICMP_ERROR_PACKET_LENGTH;\r
@@ -1798,7 +1802,13 @@ Udp4IcmpHandler (
   LIST_ENTRY             *Entry;\r
   UDP4_INSTANCE_DATA     *Instance;\r
 \r
+  if (Packet->TotalSize < sizeof (EFI_UDP_HEADER)) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
+\r
   Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  ASSERT (Udp4Header != NULL);\r
 \r
   CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));\r
   CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
@@ -1896,164 +1906,3 @@ Udp4NetVectorExtFree (
 {\r
 }\r
 \r
-\r
-/**\r
-  Set the Udp4 variable data.\r
-\r
-  @param[in] Udp4Service         Udp4 service data.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES   There are not enough resources to set the\r
-                                 variable.\r
-  @retval EFI_SUCCESS            Set variable successfully.\r
-  @retval other                  Set variable failed.\r
-\r
-**/\r
-EFI_STATUS\r
-Udp4SetVariableData (\r
-  IN UDP4_SERVICE_DATA  *Udp4Service\r
-  )\r
-{\r
-  UINT32                  NumConfiguredInstance;\r
-  LIST_ENTRY              *Entry;\r
-  UINTN                   VariableDataSize;\r
-  EFI_UDP4_VARIABLE_DATA  *Udp4VariableData;\r
-  EFI_UDP4_SERVICE_POINT  *Udp4ServicePoint;\r
-  UDP4_INSTANCE_DATA      *Udp4Instance;\r
-  CHAR16                  *NewMacString;\r
-  EFI_STATUS              Status;\r
-\r
-  NumConfiguredInstance = 0;\r
-\r
-  //\r
-  // Go through the children list to count the configured children.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
-    Udp4Instance = NET_LIST_USER_STRUCT_S (\r
-                     Entry,\r
-                     UDP4_INSTANCE_DATA,\r
-                     Link,\r
-                     UDP4_INSTANCE_DATA_SIGNATURE\r
-                     );\r
-\r
-    if (Udp4Instance->Configured) {\r
-      NumConfiguredInstance++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Calculate the size of the Udp4VariableData. As there may be no Udp4 child,\r
-  // we should add extra buffer for the service points only if the number of configured\r
-  // children is more than 1.\r
-  //\r
-  VariableDataSize = sizeof (EFI_UDP4_VARIABLE_DATA);\r
-\r
-  if (NumConfiguredInstance > 1) {\r
-    VariableDataSize += sizeof (EFI_UDP4_SERVICE_POINT) * (NumConfiguredInstance - 1);\r
-  }\r
-\r
-  Udp4VariableData = AllocatePool (VariableDataSize);\r
-  if (Udp4VariableData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Udp4VariableData->DriverHandle = Udp4Service->ImageHandle;\r
-  Udp4VariableData->ServiceCount = NumConfiguredInstance;\r
-\r
-  Udp4ServicePoint = &Udp4VariableData->Services[0];\r
-\r
-  //\r
-  // Go through the children list to fill the configured children's address pairs.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
-    Udp4Instance = NET_LIST_USER_STRUCT_S (\r
-                     Entry,\r
-                     UDP4_INSTANCE_DATA,\r
-                     Link,\r
-                     UDP4_INSTANCE_DATA_SIGNATURE\r
-                     );\r
-\r
-    if (Udp4Instance->Configured) {\r
-      Udp4ServicePoint->InstanceHandle = Udp4Instance->ChildHandle;\r
-      Udp4ServicePoint->LocalAddress   = Udp4Instance->ConfigData.StationAddress;\r
-      Udp4ServicePoint->LocalPort      = Udp4Instance->ConfigData.StationPort;\r
-      Udp4ServicePoint->RemoteAddress  = Udp4Instance->ConfigData.RemoteAddress;\r
-      Udp4ServicePoint->RemotePort     = Udp4Instance->ConfigData.RemotePort;\r
-\r
-      Udp4ServicePoint++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get the mac string.\r
-  //\r
-  Status = NetLibGetMacString (\r
-             Udp4Service->ControllerHandle,\r
-             Udp4Service->ImageHandle,\r
-             &NewMacString\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  if (Udp4Service->MacString != NULL) {\r
-    //\r
-    // The variable is set already, we're going to update it.\r
-    //\r
-    if (StrCmp (Udp4Service->MacString, NewMacString) != 0) {\r
-      //\r
-      // The mac address is changed, delete the previous variable first.\r
-      //\r
-      gRT->SetVariable (\r
-             Udp4Service->MacString,\r
-             &gEfiUdp4ServiceBindingProtocolGuid,\r
-             EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-             0,\r
-             NULL\r
-             );\r
-    }\r
-\r
-    FreePool (Udp4Service->MacString);\r
-  }\r
-\r
-  Udp4Service->MacString = NewMacString;\r
-\r
-  Status = gRT->SetVariable (\r
-                  Udp4Service->MacString,\r
-                  &gEfiUdp4ServiceBindingProtocolGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                  VariableDataSize,\r
-                  (VOID *) Udp4VariableData\r
-                  );\r
-\r
-ON_ERROR:\r
-\r
-  FreePool (Udp4VariableData);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Clear the variable and free the resource.\r
-\r
-  @param[[in]  Udp4Service            Udp4 service data.\r
-\r
-**/\r
-VOID\r
-Udp4ClearVariableData (\r
-  IN UDP4_SERVICE_DATA  *Udp4Service\r
-  )\r
-{\r
-  ASSERT (Udp4Service->MacString != NULL);\r
-\r
-  gRT->SetVariable (\r
-         Udp4Service->MacString,\r
-         &gEfiUdp4ServiceBindingProtocolGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-         0,\r
-         NULL\r
-         );\r
-\r
-  FreePool (Udp4Service->MacString);\r
-  Udp4Service->MacString = NULL;\r
-}\r