]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / ArpDxe / ArpImpl.c
index d42937ef347de3c8a480d7d6c1560775b0853d27..0e9ef103eff9c31d1f34fb5a1feae5bd97021bed 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   The implementation of the ARP protocol.\r
-  \r
-Copyright (c) 2006 - 2008, Intel Corporation.<BR>\r
-All rights reserved. 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<BR>\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
@@ -52,7 +46,7 @@ ArpInitInstance (
   CopyMem (&Instance->ArpProto, &mEfiArpProtocolTemplate, sizeof (Instance->ArpProto));\r
 \r
   Instance->Configured = FALSE;\r
-  Instance->Destroyed  = FALSE;\r
+  Instance->InDestroy  = FALSE;\r
 \r
   InitializeListHead (&Instance->List);\r
 }\r
@@ -112,15 +106,28 @@ ArpOnFrameRcvdDpc (
   // Status is EFI_SUCCESS, process the received frame.\r
   //\r
   RxData = RxToken->Packet.RxData;\r
-  Head   = (ARP_HEAD *) RxData->PacketData;\r
+  //\r
+  // Sanity check.\r
+  //\r
+  if (RxData->DataLength < sizeof (ARP_HEAD)) {\r
+    //\r
+    // Restart the receiving if packet size is not correct.\r
+    //\r
+    goto RESTART_RECEIVE;\r
+  }\r
 \r
   //\r
   // Convert the byte order of the multi-byte fields.\r
   //\r
+  Head   = (ARP_HEAD *) RxData->PacketData;\r
   Head->HwType    = NTOHS (Head->HwType);\r
   Head->ProtoType = NTOHS (Head->ProtoType);\r
   Head->OpCode    = NTOHS (Head->OpCode);\r
 \r
+  if (RxData->DataLength < (sizeof (ARP_HEAD) + 2 * Head->HwAddrLen + 2 * Head->ProtoAddrLen)) {\r
+    goto RESTART_RECEIVE;\r
+  }\r
+\r
   if ((Head->HwType != ArpService->SnpMode.IfType) ||\r
     (Head->HwAddrLen != ArpService->SnpMode.HwAddressSize) ||\r
     (RxData->ProtocolType != ARP_ETHER_PROTO_TYPE)) {\r
@@ -325,12 +332,12 @@ ArpOnFrameRcvd (
   //\r
   // Request ArpOnFrameRcvdDpc as a DPC at TPL_CALLBACK\r
   //\r
-  NetLibQueueDpc (TPL_CALLBACK, ArpOnFrameRcvdDpc, Context);\r
+  QueueDpc (TPL_CALLBACK, ArpOnFrameRcvdDpc, Context);\r
 }\r
 \r
 /**\r
   Process the already sent arp packets.\r
-  \r
+\r
   @param[in]  Context                Pointer to the context data registerd to the\r
                                      Event.\r
 \r
@@ -360,10 +367,10 @@ ArpOnFrameSentDpc (
   //\r
   // Free the allocated memory and close the event.\r
   //\r
-  gBS->FreePool (TxData->FragmentTable[0].FragmentBuffer);\r
-  gBS->FreePool (TxData);\r
+  FreePool (TxData->FragmentTable[0].FragmentBuffer);\r
+  FreePool (TxData);\r
   gBS->CloseEvent (TxToken->Event);\r
-  gBS->FreePool (TxToken);\r
+  FreePool (TxToken);\r
 }\r
 \r
 /**\r
@@ -386,7 +393,7 @@ ArpOnFrameSent (
   //\r
   // Request ArpOnFrameSentDpc as a DPC at TPL_CALLBACK\r
   //\r
-  NetLibQueueDpc (TPL_CALLBACK, ArpOnFrameSentDpc, Context);\r
+  QueueDpc (TPL_CALLBACK, ArpOnFrameSentDpc, Context);\r
 }\r
 \r
 \r
@@ -437,7 +444,7 @@ ArpTimerHandler (
         ASSERT (IsListEmpty (&CacheEntry->UserRequestList));\r
 \r
         RemoveEntryList (&CacheEntry->List);\r
-        gBS->FreePool (CacheEntry);\r
+        FreePool (CacheEntry);\r
       } else {\r
         //\r
         // resend the ARP request.\r
@@ -479,7 +486,7 @@ ArpTimerHandler (
       // Time out, remove it.\r
       //\r
       RemoveEntryList (&CacheEntry->List);\r
-      gBS->FreePool (CacheEntry);\r
+      FreePool (CacheEntry);\r
     } else {\r
       //\r
       // Update the DecayTime.\r
@@ -507,7 +514,7 @@ ArpTimerHandler (
       // Time out, remove it.\r
       //\r
       RemoveEntryList (&CacheEntry->List);\r
-      gBS->FreePool (CacheEntry);\r
+      FreePool (CacheEntry);\r
     } else {\r
       //\r
       // Update the DecayTime.\r
@@ -533,6 +540,8 @@ ArpMatchAddress (
   IN NET_ARP_ADDRESS  *AddressTwo\r
   )\r
 {\r
+  ASSERT (AddressOne != NULL && AddressTwo != NULL);\r
+\r
   if ((AddressOne->Type != AddressTwo->Type) ||\r
     (AddressOne->Length != AddressTwo->Length)) {\r
     //\r
@@ -803,7 +812,7 @@ ArpAddressResolved (
       // Remove this user request and free the context data.\r
       //\r
       RemoveEntryList (&Context->List);\r
-      gBS->FreePool (Context);\r
+      FreePool (Context);\r
 \r
       Count++;\r
     }\r
@@ -812,7 +821,7 @@ ArpAddressResolved (
   //\r
   // Dispatch the DPCs queued by the NotifyFunction of the Context->UserRequestEvent.\r
   //\r
-  NetLibDispatchDpc ();\r
+  DispatchDpc ();\r
 \r
   return Count;\r
 }\r
@@ -928,9 +937,9 @@ ArpConfigureInstance (
       if (ConfigData->SwAddressType == IPV4_ETHER_PROTO_TYPE) {\r
         CopyMem (&Ip, ConfigData->StationAddress, sizeof (IP4_ADDR));\r
 \r
-        if (!Ip4IsUnicast (NTOHL (Ip), 0)) {\r
+        if (IP4_IS_UNSPECIFIED (Ip) || IP4_IS_LOCAL_BROADCAST (Ip)) {\r
           //\r
-          // The station address is not a valid IPv4 unicast address.\r
+          // The station address should not be zero or broadcast address.\r
           //\r
           return EFI_INVALID_PARAMETER;\r
         }\r
@@ -988,7 +997,7 @@ ArpConfigureInstance (
       //\r
       // Free the buffer previously allocated to hold the station address.\r
       //\r
-      gBS->FreePool (OldConfigData->StationAddress);\r
+      FreePool (OldConfigData->StationAddress);\r
     }\r
 \r
     Instance->Configured = FALSE;\r
@@ -1083,6 +1092,7 @@ ArpSendFrame (
   Packet = AllocatePool (TotalLength);\r
   if (Packet == NULL) {\r
     DEBUG ((EFI_D_ERROR, "ArpSendFrame: Allocate memory for Packet failed.\n"));\r
+    ASSERT (Packet != NULL);\r
   }\r
 \r
   TmpPtr = Packet;\r
@@ -1188,18 +1198,18 @@ ArpSendFrame (
 CLEAN_EXIT:\r
 \r
   if (Packet != NULL) {\r
-    gBS->FreePool (Packet);\r
+    FreePool (Packet);\r
   }\r
 \r
   if (TxData != NULL) {\r
-    gBS->FreePool (TxData);\r
+    FreePool (TxData);\r
   }\r
 \r
   if (TxToken->Event != NULL) {\r
     gBS->CloseEvent (TxToken->Event);\r
   }\r
 \r
-  gBS->FreePool (TxToken);\r
+  FreePool (TxToken);\r
 }\r
 \r
 \r
@@ -1285,7 +1295,7 @@ MATCHED:
     //\r
     RemoveEntryList (&CacheEntry->List);\r
     ASSERT (IsListEmpty (&CacheEntry->UserRequestList));\r
-    gBS->FreePool (CacheEntry);\r
+    FreePool (CacheEntry);\r
 \r
     Count++;\r
   }\r
@@ -1398,7 +1408,7 @@ ArpCancelRequest (
         // No user requests any more, remove this request cache entry.\r
         //\r
         RemoveEntryList (&CacheEntry->List);\r
-        gBS->FreePool (CacheEntry);\r
+        FreePool (CacheEntry);\r
       }\r
     }\r
   }\r
@@ -1451,6 +1461,7 @@ ArpFindCacheEntry (
   UINT32             FoundCount;\r
   EFI_ARP_FIND_DATA  *FindData;\r
   LIST_ENTRY         *CacheTable;\r
+  UINT32             FoundEntryLength;\r
 \r
   ArpService = Instance->ArpService;\r
 \r
@@ -1567,12 +1578,14 @@ ArpFindCacheEntry (
     goto CLEAN_EXIT;\r
   }\r
 \r
+  //\r
+  // Found the entry length, make sure its 8 bytes alignment.\r
+  //\r
+  FoundEntryLength = (((sizeof (EFI_ARP_FIND_DATA) + Instance->ConfigData.SwAddressLength +\r
+                       ArpService->SnpMode.HwAddressSize) + 3) & ~(0x3));\r
+\r
   if (EntryLength != NULL) {\r
-    //\r
-    // Return the entry length, make sure its 8 bytes alignment.\r
-    //\r
-    *EntryLength = (((sizeof (EFI_ARP_FIND_DATA) + Instance->ConfigData.SwAddressLength +\r
-                   ArpService->SnpMode.HwAddressSize) + 3) & ~(0x3));\r
+    *EntryLength = FoundEntryLength;\r
   }\r
 \r
   if (EntryCount != NULL) {\r
@@ -1589,7 +1602,7 @@ ArpFindCacheEntry (
   //\r
   // Allocate buffer to copy the found entries.\r
   //\r
-  FindData = AllocatePool (FoundCount * (*EntryLength));\r
+  FindData = AllocatePool (FoundCount * FoundEntryLength);\r
   if (FindData == NULL) {\r
     DEBUG ((EFI_D_ERROR, "ArpFindCacheEntry: Failed to allocate memory.\n"));\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -1613,7 +1626,7 @@ ArpFindCacheEntry (
     //\r
     // Set the fields in FindData.\r
     //\r
-    FindData->Size            = *EntryLength;\r
+    FindData->Size            = FoundEntryLength;\r
     FindData->DenyFlag        = (BOOLEAN)(CacheTable == &ArpService->DeniedCacheTable);\r
     FindData->StaticFlag      = (BOOLEAN)(CacheEntry->DefaultDecayTime == 0);\r
     FindData->HwAddressType   = ArpService->SnpMode.IfType;\r
@@ -1642,7 +1655,7 @@ ArpFindCacheEntry (
     //\r
     // Slip to the next FindData.\r
     //\r
-    FindData = (EFI_ARP_FIND_DATA *)((UINT8 *)FindData + *EntryLength);\r
+    FindData = (EFI_ARP_FIND_DATA *)((UINT8 *)FindData + FoundEntryLength);\r
   }\r
 \r
 CLEAN_EXIT:\r