X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FArpDxe%2FArpImpl.c;h=0e9ef103eff9c31d1f34fb5a1feae5bd97021bed;hp=b46c7047eefadaed9438b6c0e06118d77dc6deef;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=687a2e5f6902fa26c7a1d7a7705e0747c4095125 diff --git a/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c b/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c index b46c7047ee..0e9ef103ef 100644 --- a/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c +++ b/MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c @@ -1,27 +1,16 @@ /** @file + The implementation of the ARP protocol. -Copyright (c) 2006 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD License -which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -Module Name: - - ArpImpl.c - -Abstract: - +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ - #include "ArpImpl.h" -#include "ArpDebug.h" +// +// Global variable of EFI ARP Protocol Interface. +// EFI_ARP_PROTOCOL mEfiArpProtocolTemplate = { ArpConfigure, ArpAdd, @@ -36,17 +25,17 @@ EFI_ARP_PROTOCOL mEfiArpProtocolTemplate = { /** Initialize the instance context data. - @param ArpService Pointer to the arp service context data this + @param[in] ArpService Pointer to the arp service context data this instance belongs to. - @param Instance Pointer to the instance context data. + @param[out] Instance Pointer to the instance context data. @return None. **/ VOID ArpInitInstance ( - IN ARP_SERVICE_DATA *ArpService, - IN ARP_INSTANCE_DATA *Instance + IN ARP_SERVICE_DATA *ArpService, + OUT ARP_INSTANCE_DATA *Instance ) { NET_CHECK_SIGNATURE (ArpService, ARP_SERVICE_DATA_SIGNATURE); @@ -57,17 +46,16 @@ ArpInitInstance ( CopyMem (&Instance->ArpProto, &mEfiArpProtocolTemplate, sizeof (Instance->ArpProto)); Instance->Configured = FALSE; - Instance->Destroyed = FALSE; + Instance->InDestroy = FALSE; - NetListInit (&Instance->List); + InitializeListHead (&Instance->List); } /** Process the Arp packets received from Mnp, the procedure conforms to RFC826. - @param Event The Event this notify function registered to. - @param Context Pointer to the context data registerd to the + @param[in] Context Pointer to the context data registerd to the Event. @return None. @@ -75,8 +63,7 @@ ArpInitInstance ( **/ VOID EFIAPI -ArpOnFrameRcvd ( - IN EFI_EVENT Event, +ArpOnFrameRcvdDpc ( IN VOID *Context ) { @@ -87,7 +74,7 @@ ArpOnFrameRcvd ( ARP_HEAD *Head; ARP_ADDRESS ArpAddress; ARP_CACHE_ENTRY *CacheEntry; - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; ARP_INSTANCE_DATA *Instance; EFI_ARP_CONFIG_DATA *ConfigData; NET_ARP_ADDRESS SenderAddress[2]; @@ -119,15 +106,28 @@ ArpOnFrameRcvd ( // Status is EFI_SUCCESS, process the received frame. // RxData = RxToken->Packet.RxData; - Head = (ARP_HEAD *) RxData->PacketData; + // + // Sanity check. + // + if (RxData->DataLength < sizeof (ARP_HEAD)) { + // + // Restart the receiving if packet size is not correct. + // + goto RESTART_RECEIVE; + } // // Convert the byte order of the multi-byte fields. // + Head = (ARP_HEAD *) RxData->PacketData; Head->HwType = NTOHS (Head->HwType); Head->ProtoType = NTOHS (Head->ProtoType); Head->OpCode = NTOHS (Head->OpCode); + if (RxData->DataLength < (sizeof (ARP_HEAD) + 2 * Head->HwAddrLen + 2 * Head->ProtoAddrLen)) { + goto RESTART_RECEIVE; + } + if ((Head->HwType != ArpService->SnpMode.IfType) || (Head->HwAddrLen != ArpService->SnpMode.HwAddressSize) || (RxData->ProtocolType != ARP_ETHER_PROTO_TYPE)) { @@ -146,11 +146,6 @@ ArpOnFrameRcvd ( ArpAddress.TargetHwAddr = ArpAddress.SenderProtoAddr + Head->ProtoAddrLen; ArpAddress.TargetProtoAddr = ArpAddress.TargetHwAddr + Head->HwAddrLen; - if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) { - ARP_DEBUG_ERROR (("ArpOnFrameRcvd: Faild to acquire the CacheTableLock.\n")); - goto RECYCLE_RXDATA; - } - SenderAddress[Hardware].Type = Head->HwType; SenderAddress[Hardware].Length = Head->HwAddrLen; SenderAddress[Hardware].AddressPtr = ArpAddress.SenderHwAddr; @@ -172,7 +167,7 @@ ArpOnFrameRcvd ( // This address (either hardware or protocol address, or both) is configured to // be a deny entry, silently skip the normal process. // - goto UNLOCK_EXIT; + goto RECYCLE_RXDATA; } ProtoMatched = FALSE; @@ -193,7 +188,7 @@ ArpOnFrameRcvd ( // The protocol type is matched for the received arp packet. // ProtoMatched = TRUE; - if (0 == NetCompareMem ( + if (0 == CompareMem ( (VOID *)ArpAddress.TargetProtoAddr, ConfigData->StationAddress, ConfigData->SwAddressLength @@ -211,7 +206,7 @@ ArpOnFrameRcvd ( // // Protocol type unmatchable, skip. // - goto UNLOCK_EXIT; + goto RECYCLE_RXDATA; } // @@ -238,7 +233,7 @@ ArpOnFrameRcvd ( // // This arp packet isn't targeted to us, skip now. // - goto UNLOCK_EXIT; + goto RECYCLE_RXDATA; } if (!MergeFlag) { @@ -259,12 +254,12 @@ ArpOnFrameRcvd ( // CacheEntry = ArpAllocCacheEntry (NULL); if (CacheEntry == NULL) { - goto UNLOCK_EXIT; + goto RECYCLE_RXDATA; } } if (!IsListEmpty (&CacheEntry->List)) { - NetListRemoveEntry (&CacheEntry->List); + RemoveEntryList (&CacheEntry->List); } // @@ -284,7 +279,7 @@ ArpOnFrameRcvd ( // // Add this entry into the ResolvedCacheTable // - NetListInsertHead (&ArpService->ResolvedCacheTable, &CacheEntry->List); + InsertHeadList (&ArpService->ResolvedCacheTable, &CacheEntry->List); } if (Head->OpCode == ARP_OPCODE_REQUEST) { @@ -295,10 +290,6 @@ ArpOnFrameRcvd ( ArpSendFrame (Instance, CacheEntry, ARP_OPCODE_REPLY); } -UNLOCK_EXIT: - - NET_UNLOCK (&ArpService->Lock); - RECYCLE_RXDATA: // @@ -315,27 +306,47 @@ RESTART_RECEIVE: DEBUG_CODE ( if (EFI_ERROR (Status)) { - ARP_DEBUG_ERROR (("ArpOnFrameRcvd: ArpService->Mnp->Receive " + DEBUG ((EFI_D_ERROR, "ArpOnFrameRcvd: ArpService->Mnp->Receive " "failed, %r\n.", Status)); } ); } +/** + Queue ArpOnFrameRcvdDpc as a DPC at TPL_CALLBACK. + + @param[in] Event The Event this notify function registered to. + @param[in] Context Pointer to the context data registerd to the + Event. + + @return None. + +**/ +VOID +EFIAPI +ArpOnFrameRcvd ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // Request ArpOnFrameRcvdDpc as a DPC at TPL_CALLBACK + // + QueueDpc (TPL_CALLBACK, ArpOnFrameRcvdDpc, Context); +} /** Process the already sent arp packets. - @param Event The Event this notify function registered to. - @param Context Pointer to the context data registerd to the - Event. + @param[in] Context Pointer to the context data registerd to the + Event. @return None. **/ VOID EFIAPI -ArpOnFrameSent ( - IN EFI_EVENT Event, +ArpOnFrameSentDpc ( IN VOID *Context ) { @@ -349,26 +360,49 @@ ArpOnFrameSent ( DEBUG_CODE ( if (EFI_ERROR (TxToken->Status)) { - ARP_DEBUG_ERROR (("ArpOnFrameSent: TxToken->Status, %r.\n", TxToken->Status)); + DEBUG ((EFI_D_ERROR, "ArpOnFrameSent: TxToken->Status, %r.\n", TxToken->Status)); } ); // // Free the allocated memory and close the event. // - NetFreePool (TxData->FragmentTable[0].FragmentBuffer); - NetFreePool (TxData); + FreePool (TxData->FragmentTable[0].FragmentBuffer); + FreePool (TxData); gBS->CloseEvent (TxToken->Event); - NetFreePool (TxToken); + FreePool (TxToken); +} + +/** + Request ArpOnFrameSentDpc as a DPC at TPL_CALLBACK. + + @param[in] Event The Event this notify function registered to. + @param[in] Context Pointer to the context data registerd to the + Event. + + @return None. + +**/ +VOID +EFIAPI +ArpOnFrameSent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // Request ArpOnFrameSentDpc as a DPC at TPL_CALLBACK + // + QueueDpc (TPL_CALLBACK, ArpOnFrameSentDpc, Context); } /** Process the arp cache olding and drive the retrying arp requests. - @param Event The Event this notify function registered to. - @param Context Pointer to the context data registerd to the - Event. + @param[in] Event The Event this notify function registered to. + @param[in] Context Pointer to the context data registerd to the + Event. @return None. @@ -381,19 +415,15 @@ ArpTimerHandler ( ) { ARP_SERVICE_DATA *ArpService; - NET_LIST_ENTRY *Entry; - NET_LIST_ENTRY *NextEntry; - NET_LIST_ENTRY *ContextEntry; + LIST_ENTRY *Entry; + LIST_ENTRY *NextEntry; + LIST_ENTRY *ContextEntry; ARP_CACHE_ENTRY *CacheEntry; USER_REQUEST_CONTEXT *RequestContext; ASSERT (Context != NULL); ArpService = (ARP_SERVICE_DATA *)Context; - if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) { - return; - } - // // Iterate all the pending requests to see whether a retry is needed to send out // or the request finally fails because the retry time reaches the limitation. @@ -411,15 +441,15 @@ ArpTimerHandler ( // Abort this request. // ArpAddressResolved (CacheEntry, NULL, NULL); - ASSERT (NetListIsEmpty (&CacheEntry->UserRequestList)); + ASSERT (IsListEmpty (&CacheEntry->UserRequestList)); - NetListRemoveEntry (&CacheEntry->List); - NetFreePool (CacheEntry); + RemoveEntryList (&CacheEntry->List); + FreePool (CacheEntry); } else { // // resend the ARP request. // - ASSERT (!NetListIsEmpty(&CacheEntry->UserRequestList)); + ASSERT (!IsListEmpty(&CacheEntry->UserRequestList)); ContextEntry = CacheEntry->UserRequestList.ForwardLink; RequestContext = NET_LIST_USER_STRUCT (ContextEntry, USER_REQUEST_CONTEXT, List); @@ -442,7 +472,7 @@ ArpTimerHandler ( // NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &ArpService->DeniedCacheTable) { CacheEntry = NET_LIST_USER_STRUCT (Entry, ARP_CACHE_ENTRY, List); - ASSERT (NetListIsEmpty (&CacheEntry->UserRequestList)); + ASSERT (IsListEmpty (&CacheEntry->UserRequestList)); if (CacheEntry->DefaultDecayTime == 0) { // @@ -455,8 +485,8 @@ ArpTimerHandler ( // // Time out, remove it. // - NetListRemoveEntry (&CacheEntry->List); - NetFreePool (CacheEntry); + RemoveEntryList (&CacheEntry->List); + FreePool (CacheEntry); } else { // // Update the DecayTime. @@ -470,7 +500,7 @@ ArpTimerHandler ( // NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &ArpService->ResolvedCacheTable) { CacheEntry = NET_LIST_USER_STRUCT (Entry, ARP_CACHE_ENTRY, List); - ASSERT (NetListIsEmpty (&CacheEntry->UserRequestList)); + ASSERT (IsListEmpty (&CacheEntry->UserRequestList)); if (CacheEntry->DefaultDecayTime == 0) { // @@ -483,8 +513,8 @@ ArpTimerHandler ( // // Time out, remove it. // - NetListRemoveEntry (&CacheEntry->List); - NetFreePool (CacheEntry); + RemoveEntryList (&CacheEntry->List); + FreePool (CacheEntry); } else { // // Update the DecayTime. @@ -492,27 +522,26 @@ ArpTimerHandler ( CacheEntry->DecayTime -= ARP_PERIODIC_TIMER_INTERVAL; } } - - NET_UNLOCK (&ArpService->Lock); } /** Match the two NET_ARP_ADDRESSes. - @param AddressOne Pointer to the first address to match. - @param AddressTwo Pointer to the second address to match. + @param[in] AddressOne Pointer to the first address to match. + @param[in] AddressTwo Pointer to the second address to match. @return The two addresses match or not. **/ -STATIC BOOLEAN ArpMatchAddress ( IN NET_ARP_ADDRESS *AddressOne, IN NET_ARP_ADDRESS *AddressTwo ) { + ASSERT (AddressOne != NULL && AddressTwo != NULL); + if ((AddressOne->Type != AddressTwo->Type) || (AddressOne->Length != AddressTwo->Length)) { // @@ -522,7 +551,7 @@ ArpMatchAddress ( } if ((AddressOne->AddressPtr != NULL) && - (NetCompareMem ( + (CompareMem ( AddressOne->AddressPtr, AddressTwo->AddressPtr, AddressOne->Length @@ -540,26 +569,26 @@ ArpMatchAddress ( /** Find the CacheEntry which matches the requirements in the specified CacheTable. - @param CacheTable Pointer to the arp cache table. - @param StartEntry Pointer to the start entry this search begins with - in the cache table. - @param FindOpType The search type. - @param ProtocolAddress Pointer to the protocol address to match. - @param HardwareAddress Pointer to the hardware address to match. + @param[in] CacheTable Pointer to the arp cache table. + @param[in] StartEntry Pointer to the start entry this search begins with + in the cache table. + @param[in] FindOpType The search type. + @param[in] ProtocolAddress Pointer to the protocol address to match. + @param[in] HardwareAddress Pointer to the hardware address to match. @return Pointer to the matched arp cache entry, if NULL, no match is found. **/ ARP_CACHE_ENTRY * ArpFindNextCacheEntryInTable ( - IN NET_LIST_ENTRY *CacheTable, - IN NET_LIST_ENTRY *StartEntry, + IN LIST_ENTRY *CacheTable, + IN LIST_ENTRY *StartEntry, IN FIND_OPTYPE FindOpType, IN NET_ARP_ADDRESS *ProtocolAddress OPTIONAL, IN NET_ARP_ADDRESS *HardwareAddress OPTIONAL ) { - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; ARP_CACHE_ENTRY *CacheEntry; if (StartEntry == NULL) { @@ -572,7 +601,7 @@ ArpFindNextCacheEntryInTable ( for (Entry = StartEntry->ForwardLink; Entry != CacheTable; Entry = Entry->ForwardLink) { CacheEntry = NET_LIST_USER_STRUCT (Entry, ARP_CACHE_ENTRY, List); - if (FindOpType & MATCH_SW_ADDRESS) { + if ((FindOpType & MATCH_SW_ADDRESS) != 0) { // // Find by the software address. // @@ -584,7 +613,7 @@ ArpFindNextCacheEntryInTable ( } } - if (FindOpType & MATCH_HW_ADDRESS) { + if ((FindOpType & MATCH_HW_ADDRESS) != 0) { // // Find by the hardware address. // @@ -613,9 +642,9 @@ ArpFindNextCacheEntryInTable ( Find the CacheEntry, using ProtocolAddress or HardwareAddress or both, as the keyword, in the DeniedCacheTable. - @param ArpService Pointer to the arp service context data. - @param ProtocolAddress Pointer to the protocol address. - @param HardwareAddress Pointer to the hardware address. + @param[in] ArpService Pointer to the arp service context data. + @param[in] ProtocolAddress Pointer to the protocol address. + @param[in] HardwareAddress Pointer to the hardware address. @return Pointer to the matched cache entry, if NULL no match is found. @@ -673,7 +702,7 @@ ArpFindDeniedCacheEntry ( /** Allocate a cache entry and initialize it. - @param Instance Pointer to the instance context data. + @param[in] Instance Pointer to the instance context data. @return Pointer to the new created cache entry. @@ -690,7 +719,7 @@ ArpAllocCacheEntry ( // // Allocate memory for the cache entry. // - CacheEntry = NetAllocatePool (sizeof (ARP_CACHE_ENTRY)); + CacheEntry = AllocatePool (sizeof (ARP_CACHE_ENTRY)); if (CacheEntry == NULL) { return NULL; } @@ -698,8 +727,8 @@ ArpAllocCacheEntry ( // // Init the lists. // - NetListInit (&CacheEntry->List); - NetListInit (&CacheEntry->UserRequestList); + InitializeListHead (&CacheEntry->List); + InitializeListHead (&CacheEntry->UserRequestList); for (Index = 0; Index < 2; Index++) { // @@ -712,7 +741,7 @@ ArpAllocCacheEntry ( // // Zero the hardware address first. // - NetZeroMem (CacheEntry->Addresses[Hardware].AddressPtr, ARP_MAX_HARDWARE_ADDRESS_LEN); + ZeroMem (CacheEntry->Addresses[Hardware].AddressPtr, ARP_MAX_HARDWARE_ADDRESS_LEN); if (Instance != NULL) { // @@ -740,9 +769,9 @@ ArpAllocCacheEntry ( /** Turn the CacheEntry into the resolved status. - @param CacheEntry Pointer to the resolved cache entry. - @param Instance Pointer to the instance context data. - @param UserEvent Pointer to the UserEvent to notify. + @param[in] CacheEntry Pointer to the resolved cache entry. + @param[in] Instance Pointer to the instance context data. + @param[in] UserEvent Pointer to the UserEvent to notify. @return The count of notifications sent to the instance. @@ -754,8 +783,8 @@ ArpAddressResolved ( IN EFI_EVENT UserEvent OPTIONAL ) { - NET_LIST_ENTRY *Entry; - NET_LIST_ENTRY *NextEntry; + LIST_ENTRY *Entry; + LIST_ENTRY *NextEntry; USER_REQUEST_CONTEXT *Context; UINTN Count; @@ -772,7 +801,7 @@ ArpAddressResolved ( // // Copy the address to the user-provided buffer and notify the user. // - NetCopyMem ( + CopyMem ( Context->UserHwAddrBuffer, CacheEntry->Addresses[Hardware].AddressPtr, CacheEntry->Addresses[Hardware].Length @@ -782,13 +811,18 @@ ArpAddressResolved ( // // Remove this user request and free the context data. // - NetListRemoveEntry (&Context->List); - NetFreePool (Context); + RemoveEntryList (&Context->List); + FreePool (Context); Count++; } } + // + // Dispatch the DPCs queued by the NotifyFunction of the Context->UserRequestEvent. + // + DispatchDpc (); + return Count; } @@ -797,9 +831,9 @@ ArpAddressResolved ( Fill the addresses in the CacheEntry using the information passed in by HwAddr and SwAddr. - @param CacheEntry Pointer to the cache entry. - @param HwAddr Pointer to the software address. - @param SwAddr Pointer to the hardware address. + @param[in] CacheEntry Pointer to the cache entry. + @param[in] HwAddr Pointer to the software address. + @param[in] SwAddr Pointer to the hardware address. @return None. @@ -832,7 +866,7 @@ ArpFillAddressInCacheEntry ( // // Copy it if the AddressPtr points to some buffer. // - NetCopyMem ( + CopyMem ( CacheAddress->AddressPtr, Address[Index]->AddressPtr, CacheAddress->Length @@ -841,7 +875,7 @@ ArpFillAddressInCacheEntry ( // // Zero the corresponding address buffer in the CacheEntry. // - NetZeroMem (CacheAddress->AddressPtr, CacheAddress->Length); + ZeroMem (CacheAddress->AddressPtr, CacheAddress->Length); } } } @@ -851,9 +885,9 @@ ArpFillAddressInCacheEntry ( /** Configure the instance using the ConfigData. ConfigData is already validated. - @param Instance Pointer to the instance context data to be + @param[in] Instance Pointer to the instance context data to be configured. - @param ConfigData Pointer to the configuration data used to + @param[in] ConfigData Pointer to the configuration data used to configure the instance. @retval EFI_SUCCESS The instance is configured with the ConfigData. @@ -885,7 +919,7 @@ ArpConfigureInstance ( // if ((OldConfigData->SwAddressType != ConfigData->SwAddressType) || (OldConfigData->SwAddressLength != ConfigData->SwAddressLength) || - (NetCompareMem ( + (CompareMem ( OldConfigData->StationAddress, ConfigData->StationAddress, OldConfigData->SwAddressLength @@ -900,12 +934,12 @@ ArpConfigureInstance ( // The instance is not configured. // - if (ConfigData->SwAddressType == IPv4_ETHER_PROTO_TYPE) { - NetCopyMem (&Ip, ConfigData->StationAddress, sizeof (IP4_ADDR)); + if (ConfigData->SwAddressType == IPV4_ETHER_PROTO_TYPE) { + CopyMem (&Ip, ConfigData->StationAddress, sizeof (IP4_ADDR)); - if (!Ip4IsUnicast (NTOHL (Ip), 0)) { + if (IP4_IS_UNSPECIFIED (Ip) || IP4_IS_LOCAL_BROADCAST (Ip)) { // - // The station address is not a valid IPv4 unicast address. + // The station address should not be zero or broadcast address. // return EFI_INVALID_PARAMETER; } @@ -916,9 +950,9 @@ ArpConfigureInstance ( // CopyMem (OldConfigData, ConfigData, sizeof (*OldConfigData)); - OldConfigData->StationAddress = NetAllocatePool (OldConfigData->SwAddressLength); + OldConfigData->StationAddress = AllocatePool (OldConfigData->SwAddressLength); if (OldConfigData->StationAddress == NULL) { - ARP_DEBUG_ERROR (("ArpConfigInstance: NetAllocatePool for the StationAddress " + DEBUG ((EFI_D_ERROR, "ArpConfigInstance: AllocatePool for the StationAddress " "failed.\n")); return EFI_OUT_OF_RESOURCES; } @@ -926,7 +960,7 @@ ArpConfigureInstance ( // // Save the StationAddress. // - NetCopyMem ( + CopyMem ( OldConfigData->StationAddress, ConfigData->StationAddress, OldConfigData->SwAddressLength @@ -958,12 +992,12 @@ ArpConfigureInstance ( // // Cancel the arp requests issued by this instance. // - ArpCancelRequest (Instance, NULL, NULL); + Instance->ArpProto.Cancel (&Instance->ArpProto, NULL, NULL); // // Free the buffer previously allocated to hold the station address. // - NetFreePool (OldConfigData->StationAddress); + FreePool (OldConfigData->StationAddress); } Instance->Configured = FALSE; @@ -976,11 +1010,11 @@ ArpConfigureInstance ( /** Send out an arp frame using the CachEntry and the ArpOpCode. - @param Instance Pointer to the instance context data. - @param CacheEntry Pointer to the configuration data used to - configure the instance. - @param ArpOpCode The opcode used to send out this Arp frame, either - request or reply. + @param[in] Instance Pointer to the instance context data. + @param[in] CacheEntry Pointer to the configuration data used to + configure the instance. + @param[in] ArpOpCode The opcode used to send out this Arp frame, either + request or reply. @return None. @@ -1008,9 +1042,9 @@ ArpSendFrame ( // // Allocate memory for the TxToken. // - TxToken = NetAllocatePool (sizeof(EFI_MANAGED_NETWORK_COMPLETION_TOKEN)); + TxToken = AllocatePool (sizeof(EFI_MANAGED_NETWORK_COMPLETION_TOKEN)); if (TxToken == NULL) { - ARP_DEBUG_ERROR (("ArpSendFrame: Allocate memory for TxToken failed.\n")); + DEBUG ((EFI_D_ERROR, "ArpSendFrame: Allocate memory for TxToken failed.\n")); return; } @@ -1023,22 +1057,22 @@ ArpSendFrame ( // Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL, - NET_TPL_EVENT, + TPL_NOTIFY, ArpOnFrameSent, (VOID *)TxToken, &TxToken->Event ); if (EFI_ERROR (Status)) { - ARP_DEBUG_ERROR (("ArpSendFrame: CreateEvent failed for TxToken->Event.\n")); + DEBUG ((EFI_D_ERROR, "ArpSendFrame: CreateEvent failed for TxToken->Event.\n")); goto CLEAN_EXIT; } // // Allocate memory for the TxData used in the TxToken. // - TxData = NetAllocatePool (sizeof(EFI_MANAGED_NETWORK_TRANSMIT_DATA)); + TxData = AllocatePool (sizeof(EFI_MANAGED_NETWORK_TRANSMIT_DATA)); if (TxData == NULL) { - ARP_DEBUG_ERROR (("ArpSendFrame: Allocate memory for TxData failed.\n")); + DEBUG ((EFI_D_ERROR, "ArpSendFrame: Allocate memory for TxData failed.\n")); goto CLEAN_EXIT; } @@ -1055,9 +1089,10 @@ ArpSendFrame ( // // Allocate buffer for the arp frame. // - Packet = NetAllocatePool (TotalLength); + Packet = AllocatePool (TotalLength); if (Packet == NULL) { - ARP_DEBUG_ERROR (("ArpSendFrame: Allocate memory for Packet failed.\n")); + DEBUG ((EFI_D_ERROR, "ArpSendFrame: Allocate memory for Packet failed.\n")); + ASSERT (Packet != NULL); } TmpPtr = Packet; @@ -1066,9 +1101,9 @@ ArpSendFrame ( // The destination MAC address. // if (ArpOpCode == ARP_OPCODE_REQUEST) { - NetCopyMem (TmpPtr, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize); + CopyMem (TmpPtr, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize); } else { - NetCopyMem ( + CopyMem ( TmpPtr, CacheEntry->Addresses[Hardware].AddressPtr, SnpMode->HwAddressSize @@ -1079,7 +1114,7 @@ ArpSendFrame ( // // The source MAC address. // - NetCopyMem (TmpPtr, &SnpMode->CurrentAddress, SnpMode->HwAddressSize); + CopyMem (TmpPtr, &SnpMode->CurrentAddress, SnpMode->HwAddressSize); TmpPtr += SnpMode->HwAddressSize; // @@ -1102,19 +1137,19 @@ ArpSendFrame ( // // The sender hardware address. // - NetCopyMem (TmpPtr, &SnpMode->CurrentAddress, SnpMode->HwAddressSize); + CopyMem (TmpPtr, &SnpMode->CurrentAddress, SnpMode->HwAddressSize); TmpPtr += SnpMode->HwAddressSize; // // The sender protocol address. // - NetCopyMem (TmpPtr, ConfigData->StationAddress, ConfigData->SwAddressLength); + CopyMem (TmpPtr, ConfigData->StationAddress, ConfigData->SwAddressLength); TmpPtr += ConfigData->SwAddressLength; // // The target hardware address. // - NetCopyMem ( + CopyMem ( TmpPtr, CacheEntry->Addresses[Hardware].AddressPtr, SnpMode->HwAddressSize @@ -1124,7 +1159,7 @@ ArpSendFrame ( // // The target protocol address. // - NetCopyMem ( + CopyMem ( TmpPtr, CacheEntry->Addresses[Protocol].AddressPtr, ConfigData->SwAddressLength @@ -1154,7 +1189,7 @@ ArpSendFrame ( // Status = ArpService->Mnp->Transmit (ArpService->Mnp, TxToken); if (EFI_ERROR (Status)) { - ARP_DEBUG_ERROR (("Mnp->Transmit failed, %r.\n", Status)); + DEBUG ((EFI_D_ERROR, "Mnp->Transmit failed, %r.\n", Status)); goto CLEAN_EXIT; } @@ -1163,18 +1198,18 @@ ArpSendFrame ( CLEAN_EXIT: if (Packet != NULL) { - NetFreePool (Packet); + FreePool (Packet); } if (TxData != NULL) { - NetFreePool (TxData); + FreePool (TxData); } if (TxToken->Event != NULL) { gBS->CloseEvent (TxToken->Event); } - NetFreePool (TxToken); + FreePool (TxToken); } @@ -1183,29 +1218,28 @@ CLEAN_EXIT: SwAddressType, AddressBuffer combination as the matching key, if Force is TRUE, the cache is deleted event it's a static entry. - @param CacheTable Pointer to the cache table to do the deletion. - @param BySwAddress Delete the cache entry by software address or by - hardware address. - @param SwAddressType The software address used to do the deletion. - @param AddressBuffer Pointer to the buffer containing the address to - match for the deletion. - @param Force This deletion is forced or not. + @param[in] CacheTable Pointer to the cache table to do the deletion. + @param[in] BySwAddress Delete the cache entry by software address or by + hardware address. + @param[in] SwAddressType The software address used to do the deletion. + @param[in] AddressBuffer Pointer to the buffer containing the address to + match for the deletion. + @param[in] Force This deletion is forced or not. @return The count of the deleted cache entries. **/ -STATIC UINTN ArpDeleteCacheEntryInTable ( - IN NET_LIST_ENTRY *CacheTable, + IN LIST_ENTRY *CacheTable, IN BOOLEAN BySwAddress, IN UINT16 SwAddressType, IN UINT8 *AddressBuffer OPTIONAL, IN BOOLEAN Force ) { - NET_LIST_ENTRY *Entry; - NET_LIST_ENTRY *NextEntry; + LIST_ENTRY *Entry; + LIST_ENTRY *NextEntry; ARP_CACHE_ENTRY *CacheEntry; UINTN Count; @@ -1227,7 +1261,7 @@ ArpDeleteCacheEntryInTable ( // Protocol address type matched. Check the address. // if ((AddressBuffer == NULL) || - (NetCompareMem ( + (CompareMem ( AddressBuffer, CacheEntry->Addresses[Protocol].AddressPtr, CacheEntry->Addresses[Protocol].Length @@ -1240,7 +1274,7 @@ ArpDeleteCacheEntryInTable ( } } else { if ((AddressBuffer == NULL) || - (NetCompareMem ( + (CompareMem ( AddressBuffer, CacheEntry->Addresses[Hardware].AddressPtr, CacheEntry->Addresses[Hardware].Length @@ -1259,9 +1293,9 @@ MATCHED: // // Delete this entry. // - NetListRemoveEntry (&CacheEntry->List); - ASSERT (NetListIsEmpty (&CacheEntry->UserRequestList)); - NetFreePool (CacheEntry); + RemoveEntryList (&CacheEntry->List); + ASSERT (IsListEmpty (&CacheEntry->UserRequestList)); + FreePool (CacheEntry); Count++; } @@ -1273,12 +1307,12 @@ MATCHED: /** Delete cache entries in all the cache tables. - @param Instance Pointer to the instance context data. - @param BySwAddress Delete the cache entry by software address or by - hardware address. - @param AddressBuffer Pointer to the buffer containing the address to - match for the deletion. - @param Force This deletion is forced or not. + @param[in] Instance Pointer to the instance context data. + @param[in] BySwAddress Delete the cache entry by software address or by + hardware address. + @param[in] AddressBuffer Pointer to the buffer containing the address to + match for the deletion. + @param[in] Force This deletion is forced or not. @return The count of the deleted cache entries. @@ -1327,11 +1361,11 @@ ArpDeleteCacheEntry ( /** Cancel the arp request. - @param Instance Pointer to the instance context data. - @param TargetSwAddress Pointer to the buffer containing the target - software address to match the arp request. - @param UserEvent The user event used to notify this request - cancellation. + @param[in] Instance Pointer to the instance context data. + @param[in] TargetSwAddress Pointer to the buffer containing the target + software address to match the arp request. + @param[in] UserEvent The user event used to notify this request + cancellation. @return The count of the cancelled requests. @@ -1344,8 +1378,8 @@ ArpCancelRequest ( ) { ARP_SERVICE_DATA *ArpService; - NET_LIST_ENTRY *Entry; - NET_LIST_ENTRY *NextEntry; + LIST_ENTRY *Entry; + LIST_ENTRY *NextEntry; ARP_CACHE_ENTRY *CacheEntry; UINTN Count; @@ -1358,7 +1392,7 @@ ArpCancelRequest ( CacheEntry = NET_LIST_USER_STRUCT (Entry, ARP_CACHE_ENTRY, List); if ((TargetSwAddress == NULL) || - (NetCompareMem ( + (CompareMem ( TargetSwAddress, CacheEntry->Addresses[Protocol].AddressPtr, CacheEntry->Addresses[Protocol].Length @@ -1369,12 +1403,12 @@ ArpCancelRequest ( // Count += ArpAddressResolved (CacheEntry, Instance, UserEvent); - if (NetListIsEmpty (&CacheEntry->UserRequestList)) { + if (IsListEmpty (&CacheEntry->UserRequestList)) { // // No user requests any more, remove this request cache entry. // - NetListRemoveEntry (&CacheEntry->List); - NetFreePool (CacheEntry); + RemoveEntryList (&CacheEntry->List); + FreePool (CacheEntry); } } } @@ -1386,18 +1420,18 @@ ArpCancelRequest ( /** Find the cache entry in the cache table. - @param Instance Pointer to the instance context data. - @param BySwAddress Set to TRUE to look for matching software protocol + @param[in] Instance Pointer to the instance context data. + @param[in] BySwAddress Set to TRUE to look for matching software protocol addresses. Set to FALSE to look for matching hardware protocol addresses. - @param AddressBuffer Pointer to address buffer. Set to NULL to match + @param[in] AddressBuffer Pointer to address buffer. Set to NULL to match all addresses. - @param EntryLength The size of an entry in the entries buffer. - @param EntryCount The number of ARP cache entries that are found by + @param[out] EntryLength The size of an entry in the entries buffer. + @param[out] EntryCount The number of ARP cache entries that are found by the specified criteria. - @param Entries Pointer to the buffer that will receive the ARP + @param[out] Entries Pointer to the buffer that will receive the ARP cache entries. - @param Refresh Set to TRUE to refresh the timeout value of the + @param[in] Refresh Set to TRUE to refresh the timeout value of the matching ARP cache entry. @retval EFI_SUCCESS The requested ARP cache entries are copied into @@ -1421,12 +1455,13 @@ ArpFindCacheEntry ( ARP_SERVICE_DATA *ArpService; NET_ARP_ADDRESS MatchAddress; FIND_OPTYPE FindOpType; - NET_LIST_ENTRY *StartEntry; + LIST_ENTRY *StartEntry; ARP_CACHE_ENTRY *CacheEntry; NET_MAP FoundEntries; UINT32 FoundCount; EFI_ARP_FIND_DATA *FindData; - NET_LIST_ENTRY *CacheTable; + LIST_ENTRY *CacheTable; + UINT32 FoundEntryLength; ArpService = Instance->ArpService; @@ -1543,12 +1578,14 @@ ArpFindCacheEntry ( goto CLEAN_EXIT; } + // + // Found the entry length, make sure its 8 bytes alignment. + // + FoundEntryLength = (((sizeof (EFI_ARP_FIND_DATA) + Instance->ConfigData.SwAddressLength + + ArpService->SnpMode.HwAddressSize) + 3) & ~(0x3)); + if (EntryLength != NULL) { - // - // Return the entry length. - // - *EntryLength = sizeof (EFI_ARP_FIND_DATA) + Instance->ConfigData.SwAddressLength + - ArpService->SnpMode.HwAddressSize; + *EntryLength = FoundEntryLength; } if (EntryCount != NULL) { @@ -1565,9 +1602,9 @@ ArpFindCacheEntry ( // // Allocate buffer to copy the found entries. // - FindData = NetAllocatePool (FoundCount * (*EntryLength)); + FindData = AllocatePool (FoundCount * FoundEntryLength); if (FindData == NULL) { - ARP_DEBUG_ERROR (("ArpFindCacheEntry: Failed to allocate memory.\n")); + DEBUG ((EFI_D_ERROR, "ArpFindCacheEntry: Failed to allocate memory.\n")); Status = EFI_OUT_OF_RESOURCES; goto CLEAN_EXIT; } @@ -1589,7 +1626,7 @@ ArpFindCacheEntry ( // // Set the fields in FindData. // - FindData->Size = *EntryLength; + FindData->Size = FoundEntryLength; FindData->DenyFlag = (BOOLEAN)(CacheTable == &ArpService->DeniedCacheTable); FindData->StaticFlag = (BOOLEAN)(CacheEntry->DefaultDecayTime == 0); FindData->HwAddressType = ArpService->SnpMode.IfType; @@ -1600,7 +1637,7 @@ ArpFindCacheEntry ( // // Copy the software address. // - NetCopyMem ( + CopyMem ( FindData + 1, CacheEntry->Addresses[Protocol].AddressPtr, FindData->SwAddressLength @@ -1609,7 +1646,7 @@ ArpFindCacheEntry ( // // Copy the hardware address. // - NetCopyMem ( + CopyMem ( (UINT8 *)(FindData + 1) + FindData->SwAddressLength, CacheEntry->Addresses[Hardware].AddressPtr, FindData->HwAddressLength @@ -1618,7 +1655,7 @@ ArpFindCacheEntry ( // // Slip to the next FindData. // - FindData = (EFI_ARP_FIND_DATA *)((UINT8 *)FindData + *EntryLength); + FindData = (EFI_ARP_FIND_DATA *)((UINT8 *)FindData + FoundEntryLength); } CLEAN_EXIT: