]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Udp6Dxe/Udp6Impl.c
NetworkPkg/Udp6Dxe: Fix various typos
[mirror_edk2.git] / NetworkPkg / Udp6Dxe / Udp6Impl.c
index 3830b14415e6bdb2a8fcccd6b177c32a9ccd4b53..ba939fdbfc3136c8b5e2b08a8c3fd3346fa781fc 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
   Udp6 driver's whole implementation.\r
 \r
-  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
-  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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -57,6 +51,9 @@ Udp6FindInstanceByPort (
   interface. It's called to signal the udp TxToken when the IpIo layer completes\r
   transmitting of the udp datagram.\r
 \r
+  If Context is NULL, then ASSERT().\r
+  If NotifyData is NULL, then ASSERT().\r
+\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            Specify a EFI_IP6_PROTOCOL for sending.\r
@@ -75,6 +72,10 @@ Udp6DgramSent (
 /**\r
   This function processes the received datagram passed up by the IpIo layer.\r
 \r
+  If NetSession is NULL, then ASSERT().\r
+  If Packet is NULL, then ASSERT().\r
+  If Context is NULL, then ASSERT().\r
+\r
   @param[in]  Status            The status of this udp datagram.\r
   @param[in]  IcmpError         The IcmpError code, only available when Status is\r
                                 EFI_ICMP_ERROR.\r
@@ -95,7 +96,7 @@ Udp6DgramRcvd (
   );\r
 \r
 /**\r
-  This function cancle the token specified by Arg in the Map.\r
+  This function cancel the token specified by Arg in the Map.\r
 \r
   @param[in]  Map             Pointer to the NET_MAP.\r
   @param[in]  Item            Pointer to the NET_MAP_ITEM.\r
@@ -158,7 +159,8 @@ Udp6RecycleRxDataWrap (
   @param[in]  RxData             Pointer to the EFI_UDP6_RECEIVE_DATA of this\r
                                  datagram.\r
 \r
-  @return Pointer to the structure wrapping the RxData and the Packet.\r
+  @return Pointer to the structure wrapping the RxData and the Packet. NULL will\r
+          be returned if any error occurs.\r
 \r
 **/\r
 UDP6_RXDATA_WRAP *\r
@@ -199,10 +201,10 @@ Udp6DeliverDgram (
   );\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]  Udp6Service        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
@@ -364,7 +366,7 @@ ON_ERROR:
 \r
   IpIoDestroy (Udp6Service->IpIo);\r
   Udp6Service->IpIo = NULL;\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -390,7 +392,7 @@ Udp6CleanService (
   //\r
   IpIoDestroy (Udp6Service->IpIo);\r
   Udp6Service->IpIo = NULL;\r
-  \r
+\r
   ZeroMem (Udp6Service, sizeof (UDP6_SERVICE_DATA));\r
 }\r
 \r
@@ -456,7 +458,7 @@ Udp6CheckTimeout (
 \r
 \r
 /**\r
-  This function intializes the new created udp instance.\r
+  This function initializes the new created udp instance.\r
 \r
   @param[in]       Udp6Service      Pointer to the UDP6_SERVICE_DATA.\r
   @param[in, out]  Instance         Pointer to the un-initialized UDP6_INSTANCE_DATA.\r
@@ -573,7 +575,7 @@ Udp6FindInstanceByPort (
 \r
 /**\r
   This function tries to bind the udp instance according to the configured port\r
-  allocation stragety.\r
+  allocation strategy.\r
 \r
   @param[in]  InstanceList       Pointer to the head of the list linking the udp\r
                                  instances.\r
@@ -830,7 +832,7 @@ Udp6ValidateTxToken (
 \r
     if ((UdpSessionData->DestinationPort == 0) && (ConfigData->RemotePort == 0)) {\r
       //\r
-      // Ambiguous; no avalaible DestinationPort for this token.\r
+      // Ambiguous; no available DestinationPort for this token.\r
       //\r
       return EFI_INVALID_PARAMETER;\r
     }\r
@@ -839,7 +841,7 @@ Udp6ValidateTxToken (
         NetIp6IsUnspecifiedAddr (&ConfigData->RemoteAddress)\r
         ) {\r
       //\r
-      // The DestinationAddress is not specificed.\r
+      // The DestinationAddress is not specified.\r
       //\r
       return EFI_INVALID_PARAMETER;\r
     }\r
@@ -913,7 +915,7 @@ Udp6TokenExist (
   pseudo HeadSum to reduce some overhead.\r
 \r
   @param[in]  Packet           Pointer to the NET_BUF contains the udp datagram.\r
-  @param[in]  HeadSum          Checksum of the pseudo header, execpt the length\r
+  @param[in]  HeadSum          Checksum of the pseudo header, except the length\r
                                field.\r
 \r
   @return The 16-bit checksum of this udp datagram.\r
@@ -976,6 +978,9 @@ Udp6RemoveToken (
   interface. It's called to signal the udp TxToken when IpIo layer completes the\r
   transmitting of the udp datagram.\r
 \r
+  If Context is NULL, then ASSERT().\r
+  If NotifyData is NULL, then ASSERT().\r
+\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            Specify a EFI_IP6_PROTOCOL for sending.\r
@@ -994,6 +999,8 @@ Udp6DgramSent (
   UDP6_INSTANCE_DATA         *Instance;\r
   EFI_UDP6_COMPLETION_TOKEN  *Token;\r
 \r
+  ASSERT (Context != NULL && NotifyData != NULL);\r
+\r
   Instance = (UDP6_INSTANCE_DATA *) Context;\r
   Token    = (EFI_UDP6_COMPLETION_TOKEN *) NotifyData;\r
 \r
@@ -1011,6 +1018,10 @@ Udp6DgramSent (
 /**\r
   This function processes the received datagram passed up by the IpIo layer.\r
 \r
+  If NetSession is NULL, then ASSERT().\r
+  If Packet is NULL, then ASSERT().\r
+  If Context is NULL, then ASSERT().\r
+\r
   @param[in]  Status            The status of this udp datagram.\r
   @param[in]  IcmpError         The IcmpError code, only available when Status is\r
                                 EFI_ICMP_ERROR.\r
@@ -1030,6 +1041,7 @@ Udp6DgramRcvd (
   IN VOID                  *Context\r
   )\r
 {\r
+  ASSERT (NetSession != NULL && Packet != NULL && Context != NULL);\r
   NET_CHECK_SIGNATURE (Packet, NET_BUF_SIGNATURE);\r
 \r
   //\r
@@ -1111,7 +1123,7 @@ Udp6LeaveGroup (
 \r
 \r
 /**\r
-  This function cancle the token specified by Arg in the Map.\r
+  This function cancel the token specified by Arg in the Map.\r
 \r
   @param[in]  Map             Pointer to the NET_MAP.\r
   @param[in]  Item            Pointer to the NET_MAP_ITEM.\r
@@ -1264,7 +1276,7 @@ Udp6InstanceCancelToken (
                                  from the received udp datagram.\r
 \r
   @retval TRUE     The udp datagram matches the receiving requirements of the Instance.\r
-  @retval FALSE    The udp datagram does not matche the receiving requirements of the Instance.\r
+  @retval FALSE    The udp datagram does not match the receiving requirements of the Instance.\r
 \r
 **/\r
 BOOLEAN\r
@@ -1374,7 +1386,8 @@ Udp6RecycleRxDataWrap (
   @param[in]  RxData             Pointer to the EFI_UDP6_RECEIVE_DATA of this\r
                                  datagram.\r
 \r
-  @return Pointer to the structure wrapping the RxData and the Packet.\r
+  @return Pointer to the structure wrapping the RxData and the Packet. NULL will\r
+          be returned if any error occurs.\r
 \r
 **/\r
 UDP6_RXDATA_WRAP *\r
@@ -1579,7 +1592,7 @@ Udp6DeliverDgram (
   This function demultiplexes the received udp datagram to the appropriate instances.\r
 \r
   @param[in]  Udp6Service        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
@@ -1598,11 +1611,20 @@ Udp6Demultiplex (
   EFI_UDP6_SESSION_DATA  *Udp6Session;\r
   UINTN                  Enqueued;\r
 \r
+  if (Packet->TotalSize < UDP6_HEADER_SIZE) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
+\r
   //\r
   // Get the datagram header from the packet buffer.\r
   //\r
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
   ASSERT (Udp6Header != NULL);\r
+  if (Udp6Header == NULL) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
 \r
   if (Udp6Header->Checksum != 0) {\r
     //\r
@@ -1619,12 +1641,11 @@ Udp6Demultiplex (
       //\r
       // Wrong checksum.\r
       //\r
+      NetbufFree (Packet);\r
       return;\r
     }\r
   }\r
 \r
-  gRT->GetTime (&RxData.TimeStamp, NULL);\r
-\r
   Udp6Session                  = &RxData.UdpSession;\r
   Udp6Session->SourcePort      = NTOHS (Udp6Header->SrcPort);\r
   Udp6Session->DestinationPort = NTOHS (Udp6Header->DstPort);\r
@@ -1714,6 +1735,9 @@ Udp6SendPortUnreach (
   //\r
   Ip6ModeData = AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA));\r
   ASSERT (Ip6ModeData != NULL);\r
+  if (Ip6ModeData == NULL) {\r
+    goto EXIT;\r
+  }\r
 \r
   //\r
   // If not finding the related IpSender use the default IpIo to send out\r
@@ -1762,6 +1786,9 @@ Udp6SendPortUnreach (
   //\r
   IcmpErrHdr = (IP6_ICMP_ERROR_HEAD *) NetbufAllocSpace (Packet, Len, FALSE);\r
   ASSERT (IcmpErrHdr != NULL);\r
+  if (IcmpErrHdr == NULL) {\r
+    goto EXIT;\r
+  }\r
 \r
   //\r
   // Set the required fields for the icmp port unreachable message.\r
@@ -1787,7 +1814,7 @@ Udp6SendPortUnreach (
     );\r
 \r
   //\r
-  // Set the checksum as zero, and IP6 driver will calcuate it with pseudo header.\r
+  // Set the checksum as zero, and IP6 driver will calculate it with pseudo header.\r
   //\r
   IcmpErrHdr->Head.Checksum = 0;\r
 \r
@@ -1836,8 +1863,17 @@ Udp6IcmpHandler (
   LIST_ENTRY             *Entry;\r
   UDP6_INSTANCE_DATA     *Instance;\r
 \r
+  if (Packet->TotalSize < UDP6_HEADER_SIZE) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
+\r
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
   ASSERT (Udp6Header != NULL);\r
+  if (Udp6Header == NULL) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
 \r
   IP6_COPY_ADDRESS (&Udp6Session.SourceAddress, &NetSession->Source);\r
   IP6_COPY_ADDRESS (&Udp6Session.DestinationAddress, &NetSession->Dest);\r
@@ -1935,174 +1971,6 @@ Udp6NetVectorExtFree (
 {\r
 }\r
 \r
-\r
-/**\r
-  Set the Udp6 variable data.\r
-\r
-  @param[in]  Udp6Service            Udp6 service data.\r
-\r
-  @retval     EFI_OUT_OF_RESOURCES   There are not enough resources to set the\r
-                                     variable.\r
-  @retval     other                  Set variable failed.\r
-\r
-**/\r
-EFI_STATUS\r
-Udp6SetVariableData (\r
-  IN UDP6_SERVICE_DATA  *Udp6Service\r
-  )\r
-{\r
-  UINT32                  NumConfiguredInstance;\r
-  LIST_ENTRY              *Entry;\r
-  UINTN                   VariableDataSize;\r
-  EFI_UDP6_VARIABLE_DATA  *Udp6VariableData;\r
-  EFI_UDP6_SERVICE_POINT  *Udp6ServicePoint;\r
-  UDP6_INSTANCE_DATA      *Udp6Instance;\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, &Udp6Service->ChildrenList) {\r
-    Udp6Instance = NET_LIST_USER_STRUCT_S (\r
-                     Entry,\r
-                     UDP6_INSTANCE_DATA,\r
-                     Link,\r
-                     UDP6_INSTANCE_DATA_SIGNATURE\r
-                     );\r
-\r
-    if (Udp6Instance->Configured) {\r
-      NumConfiguredInstance++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Calculate the size of the Udp6VariableData. As there may be no Udp6 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_UDP6_VARIABLE_DATA);\r
-\r
-  if (NumConfiguredInstance > 1) {\r
-    VariableDataSize += sizeof (EFI_UDP6_SERVICE_POINT) * (NumConfiguredInstance - 1);\r
-  }\r
-\r
-  Udp6VariableData = AllocateZeroPool (VariableDataSize);\r
-  if (Udp6VariableData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Udp6VariableData->DriverHandle = Udp6Service->ImageHandle;\r
-  Udp6VariableData->ServiceCount = NumConfiguredInstance;\r
-\r
-  Udp6ServicePoint = &Udp6VariableData->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, &Udp6Service->ChildrenList) {\r
-    Udp6Instance = NET_LIST_USER_STRUCT_S (\r
-                     Entry,\r
-                     UDP6_INSTANCE_DATA,\r
-                     Link,\r
-                     UDP6_INSTANCE_DATA_SIGNATURE\r
-                     );\r
-\r
-    if (Udp6Instance->Configured) {\r
-      Udp6ServicePoint->InstanceHandle = Udp6Instance->ChildHandle;\r
-      Udp6ServicePoint->LocalPort      = Udp6Instance->ConfigData.StationPort;\r
-      Udp6ServicePoint->RemotePort     = Udp6Instance->ConfigData.RemotePort;\r
-\r
-      IP6_COPY_ADDRESS (\r
-        &Udp6ServicePoint->LocalAddress,\r
-        &Udp6Instance->ConfigData.StationAddress\r
-        );\r
-      IP6_COPY_ADDRESS (\r
-        &Udp6ServicePoint->RemoteAddress,\r
-        &Udp6Instance->ConfigData.RemoteAddress\r
-        );\r
-      Udp6ServicePoint++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get the MAC string.\r
-  //\r
-  Status = NetLibGetMacString (\r
-             Udp6Service->ControllerHandle,\r
-             Udp6Service->ImageHandle,\r
-             &NewMacString\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    goto EXIT;\r
-  }\r
-\r
-  if (Udp6Service->MacString != NULL) {\r
-    //\r
-    // The variable is set already, we're going to update it.\r
-    //\r
-    if (StrCmp (Udp6Service->MacString, NewMacString) != 0) {\r
-      //\r
-      // The MAC address is changed, delete the previous variable first.\r
-      //\r
-      gRT->SetVariable (\r
-             Udp6Service->MacString,\r
-             &gEfiUdp6ServiceBindingProtocolGuid,\r
-             EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-             0,\r
-             NULL\r
-             );\r
-    }\r
-\r
-    FreePool (Udp6Service->MacString);\r
-  }\r
-\r
-  Udp6Service->MacString = NewMacString;\r
-\r
-  Status = gRT->SetVariable (\r
-                  Udp6Service->MacString,\r
-                  &gEfiUdp6ServiceBindingProtocolGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                  VariableDataSize,\r
-                  (VOID *) Udp6VariableData\r
-                  );\r
-\r
-EXIT:\r
-\r
-  FreePool (Udp6VariableData);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Clear the variable and free the resource.\r
-\r
-  @param[in, out]  Udp6Service            Udp6 service data.\r
-\r
-**/\r
-VOID\r
-Udp6ClearVariableData (\r
-  IN OUT UDP6_SERVICE_DATA  *Udp6Service\r
-  )\r
-{\r
-  ASSERT (Udp6Service->MacString != NULL);\r
-\r
-  gRT->SetVariable (\r
-         Udp6Service->MacString,\r
-         &gEfiUdp6ServiceBindingProtocolGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-         0,\r
-         NULL\r
-         );\r
-\r
-  FreePool (Udp6Service->MacString);\r
-  Udp6Service->MacString = NULL;\r
-}\r
-\r
-\r
 /**\r
   Find the key in the netmap.\r
 \r