]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Udp6Dxe/Udp6Impl.c
MdeModulePkg: Add new driver to publish EDKII_PI_SMM_COMMUNICATION_REGION_TABLE.
[mirror_edk2.git] / NetworkPkg / Udp6Dxe / Udp6Impl.c
index 8e259319b9d4280ac775b290f44d801368401d7d..7ed50411c66b5bff32865117b3c6196598377e68 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Udp6 driver's whole implementation.\r
 \r
 /** @file\r
   Udp6 driver's whole implementation.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2016 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
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -363,7 +363,8 @@ ON_ERROR:
   }\r
 \r
   IpIoDestroy (Udp6Service->IpIo);\r
   }\r
 \r
   IpIoDestroy (Udp6Service->IpIo);\r
-\r
+  Udp6Service->IpIo = NULL;\r
+  \r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
@@ -388,6 +389,9 @@ Udp6CleanService (
   // Destroy the IpIo.\r
   //\r
   IpIoDestroy (Udp6Service->IpIo);\r
   // Destroy the IpIo.\r
   //\r
   IpIoDestroy (Udp6Service->IpIo);\r
+  Udp6Service->IpIo = NULL;\r
+  \r
+  ZeroMem (Udp6Service, sizeof (UDP6_SERVICE_DATA));\r
 }\r
 \r
 \r
 }\r
 \r
 \r
@@ -491,7 +495,7 @@ Udp6InitInstance (
   Instance->IcmpError   = EFI_SUCCESS;\r
   Instance->Configured  = FALSE;\r
   Instance->IsNoMapping = FALSE;\r
   Instance->IcmpError   = EFI_SUCCESS;\r
   Instance->Configured  = FALSE;\r
   Instance->IsNoMapping = FALSE;\r
-  Instance->Destroyed   = FALSE;\r
+  Instance->InDestroy   = FALSE;\r
 }\r
 \r
 \r
 }\r
 \r
 \r
@@ -1594,6 +1598,11 @@ Udp6Demultiplex (
   EFI_UDP6_SESSION_DATA  *Udp6Session;\r
   UINTN                  Enqueued;\r
 \r
   EFI_UDP6_SESSION_DATA  *Udp6Session;\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
   //\r
   // Get the datagram header from the packet buffer.\r
   //\r
@@ -1615,12 +1624,11 @@ Udp6Demultiplex (
       //\r
       // Wrong checksum.\r
       //\r
       //\r
       // Wrong checksum.\r
       //\r
+      NetbufFree (Packet);\r
       return;\r
     }\r
   }\r
 \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
   Udp6Session                  = &RxData.UdpSession;\r
   Udp6Session->SourcePort      = NTOHS (Udp6Header->SrcPort);\r
   Udp6Session->DestinationPort = NTOHS (Udp6Header->DstPort);\r
@@ -1832,6 +1840,11 @@ Udp6IcmpHandler (
   LIST_ENTRY             *Entry;\r
   UDP6_INSTANCE_DATA     *Instance;\r
 \r
   LIST_ENTRY             *Entry;\r
   UDP6_INSTANCE_DATA     *Instance;\r
 \r
+  if (Packet->TotalSize < sizeof (EFI_UDP_HEADER)) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
+  \r
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
   ASSERT (Udp6Header != NULL);\r
 \r
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
   ASSERT (Udp6Header != NULL);\r
 \r
@@ -1929,175 +1942,7 @@ Udp6NetVectorExtFree (
   IN VOID  *Context\r
   )\r
 {\r
   IN VOID  *Context\r
   )\r
 {\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
 /**\r
   Find the key in the netmap.\r
 \r
 /**\r
   Find the key in the netmap.\r