/** @file\r
-\r
-Copyright (c) 2005 - 2007, Intel Corporation \r
+ IP4 input process.\r
+ \r
+Copyright (c) 2005 - 2009, 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\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
\r
-Module Name:\r
-\r
- Ip4Input.c\r
-\r
-Abstract:\r
-\r
- IP4 input process.\r
-\r
-\r
**/\r
\r
#include "Ip4Impl.h"\r
\r
\r
/**\r
- Create a empty assemble entry for the packet identified by\r
+ Create an empty assemble entry for the packet identified by\r
(Dst, Src, Id, Protocol). The default life for the packet is\r
120 seconds.\r
\r
- @param Dst The destination address\r
- @param Src The source address\r
- @param Id The ID field in IP header\r
- @param Protocol The protocol field in IP header\r
+ @param[in] Dst The destination address\r
+ @param[in] Src The source address\r
+ @param[in] Id The ID field in IP header\r
+ @param[in] Protocol The protocol field in IP header\r
\r
@return NULL if failed to allocate memory for the entry, otherwise\r
- @return the point to just created reassemble entry.\r
+ the point to just created reassemble entry.\r
\r
**/\r
-STATIC\r
IP4_ASSEMBLE_ENTRY *\r
Ip4CreateAssembleEntry (\r
IN IP4_ADDR Dst,\r
\r
IP4_ASSEMBLE_ENTRY *Assemble;\r
\r
- Assemble = NetAllocatePool (sizeof (IP4_ASSEMBLE_ENTRY));\r
+ Assemble = AllocatePool (sizeof (IP4_ASSEMBLE_ENTRY));\r
\r
if (Assemble == NULL) {\r
return NULL;\r
}\r
\r
- NetListInit (&Assemble->Link);\r
- NetListInit (&Assemble->Fragments);\r
+ InitializeListHead (&Assemble->Link);\r
+ InitializeListHead (&Assemble->Fragments);\r
\r
Assemble->Dst = Dst;\r
Assemble->Src = Src;\r
\r
\r
/**\r
- Release all the fragments of a packet, then free the assemble entry\r
-\r
- @param Assemble The assemble entry to free\r
+ Release all the fragments of a packet, then free the assemble entry.\r
\r
- @return None\r
+ @param[in] Assemble The assemble entry to free\r
\r
**/\r
-STATIC\r
VOID\r
Ip4FreeAssembleEntry (\r
IN IP4_ASSEMBLE_ENTRY *Assemble\r
)\r
{\r
- NET_LIST_ENTRY *Entry;\r
- NET_LIST_ENTRY *Next;\r
+ LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Next;\r
NET_BUF *Fragment;\r
\r
NET_LIST_FOR_EACH_SAFE (Entry, Next, &Assemble->Fragments) {\r
Fragment = NET_LIST_USER_STRUCT (Entry, NET_BUF, List);\r
\r
- NetListRemoveEntry (Entry);\r
+ RemoveEntryList (Entry);\r
NetbufFree (Fragment);\r
}\r
\r
- NetFreePool (Assemble);\r
+ gBS->FreePool (Assemble);\r
}\r
\r
\r
Initialize an already allocated assemble table. This is generally\r
the assemble table embedded in the IP4 service instance.\r
\r
- @param Table The assemble table to initialize.\r
-\r
- @return NONE\r
+ @param[in, out] Table The assemble table to initialize.\r
\r
**/\r
VOID\r
Ip4InitAssembleTable (\r
- IN IP4_ASSEMBLE_TABLE *Table\r
+ IN OUT IP4_ASSEMBLE_TABLE *Table\r
)\r
{\r
UINT32 Index;\r
\r
for (Index = 0; Index < IP4_ASSEMLE_HASH_SIZE; Index++) {\r
- NetListInit (&Table->Bucket[Index]);\r
+ InitializeListHead (&Table->Bucket[Index]);\r
}\r
}\r
\r
Clean up the assemble table: remove all the fragments\r
and assemble entries.\r
\r
- @param Table The assemble table to clean up\r
-\r
- @return None\r
+ @param[in] Table The assemble table to clean up\r
\r
**/\r
VOID\r
IN IP4_ASSEMBLE_TABLE *Table\r
)\r
{\r
- NET_LIST_ENTRY *Entry;\r
- NET_LIST_ENTRY *Next;\r
+ LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Next;\r
IP4_ASSEMBLE_ENTRY *Assemble;\r
UINT32 Index;\r
\r
NET_LIST_FOR_EACH_SAFE (Entry, Next, &Table->Bucket[Index]) {\r
Assemble = NET_LIST_USER_STRUCT (Entry, IP4_ASSEMBLE_ENTRY, Link);\r
\r
- NetListRemoveEntry (Entry);\r
+ RemoveEntryList (Entry);\r
Ip4FreeAssembleEntry (Assemble);\r
}\r
}\r
@param Start The sequence of the first byte to fit in\r
@param End One beyond the sequence of last byte to fit in.\r
\r
- @return None\r
-\r
**/\r
-STATIC\r
VOID\r
Ip4TrimPacket (\r
- IN NET_BUF *Packet,\r
- IN INTN Start,\r
- IN INTN End\r
+ IN OUT NET_BUF *Packet,\r
+ IN INTN Start,\r
+ IN INTN End\r
)\r
{\r
IP4_CLIP_INFO *Info;\r
the assembled packet's OnFree. It will free the assemble entry,\r
which in turn will free all the fragments of the packet.\r
\r
- @param Arg The assemble entry to free\r
-\r
- @return None\r
+ @param[in] Arg The assemble entry to free\r
\r
**/\r
-STATIC\r
VOID\r
Ip4OnFreeFragments (\r
IN VOID *Arg\r
return it to caller. If the packet can't be assembled, NULL is\r
return.\r
\r
- @param Table The assemble table used.\r
- @param Packet The fragment to assemble\r
+ @param Table The assemble table used. New assemble entry will be created\r
+ if the Packet is from a new chain of fragments.\r
+ @param Packet The fragment to assemble. It might be freed if the fragment\r
+ can't be re-assembled.\r
\r
@return NULL if the packet can't be reassemble. The point to just assembled\r
- @return packet if all the fragments of the packet have arrived.\r
+ packet if all the fragments of the packet have arrived.\r
\r
**/\r
-STATIC\r
NET_BUF *\r
Ip4Reassemble (\r
- IN IP4_ASSEMBLE_TABLE *Table,\r
- IN NET_BUF *Packet\r
+ IN OUT IP4_ASSEMBLE_TABLE *Table,\r
+ IN OUT NET_BUF *Packet\r
)\r
{\r
IP4_HEAD *IpHead;\r
IP4_CLIP_INFO *This;\r
IP4_CLIP_INFO *Node;\r
IP4_ASSEMBLE_ENTRY *Assemble;\r
- NET_LIST_ENTRY *Head;\r
- NET_LIST_ENTRY *Prev;\r
- NET_LIST_ENTRY *Cur;\r
+ LIST_ENTRY *Head;\r
+ LIST_ENTRY *Prev;\r
+ LIST_ENTRY *Cur;\r
NET_BUF *Fragment;\r
NET_BUF *NewPacket;\r
INTN Index;\r
goto DROP;\r
}\r
\r
- NetListInsertHead (&Table->Bucket[Index], &Assemble->Link);\r
+ InsertHeadList (&Table->Bucket[Index], &Assemble->Link);\r
}\r
+ //\r
+ // Assemble shouldn't be NULL here\r
+ //\r
+ ASSERT (Assemble != NULL);\r
\r
//\r
// Find the point to insert the packet: before the first\r
if (Node->End <= This->End) {\r
Cur = Cur->ForwardLink;\r
\r
- NetListRemoveEntry (&Fragment->List);\r
+ RemoveEntryList (&Fragment->List);\r
Assemble->CurLen -= Node->Length;\r
\r
NetbufFree (Fragment);\r
//\r
if (Node->Start < This->End) {\r
if (This->Start == Node->Start) {\r
- NetListRemoveEntry (&Packet->List);\r
+ RemoveEntryList (&Packet->List);\r
goto DROP;\r
}\r
\r
//\r
// Deliver the whole packet if all the fragments received.\r
// All fragments received if:\r
- // 1. received the last one, so, the totoal length is know\r
+ // 1. received the last one, so, the total length is know\r
// 2. received all the data. If the last fragment on the\r
// queue ends at the total length, all data is received.\r
//\r
if ((Assemble->TotalLen != 0) && (Assemble->CurLen >= Assemble->TotalLen)) {\r
\r
- NetListRemoveEntry (&Assemble->Link);\r
+ RemoveEntryList (&Assemble->Link);\r
\r
//\r
// If the packet is properly formated, the last fragment's End\r
return NULL;\r
}\r
\r
- NewPacket->Ip = Assemble->Head;\r
+ NewPacket->Ip = Assemble->Head;\r
CopyMem (IP4_GET_CLIP_INFO (NewPacket), Assemble->Info, sizeof (*IP4_GET_CLIP_INFO (NewPacket)));\r
return NewPacket;\r
}\r
The IP4 input routine. It is called by the IP4_INTERFACE when a\r
IP4 fragment is received from MNP.\r
\r
- @param Ip4Instance The IP4 child that request the receive, most like\r
+ @param[in] Ip4Instance The IP4 child that request the receive, most like\r
it is NULL.\r
- @param Packet The IP4 packet received.\r
- @param IoStatus The return status of receive request.\r
- @param Flag The link layer flag for the packet received, such\r
+ @param[in] Packet The IP4 packet received.\r
+ @param[in] IoStatus The return status of receive request.\r
+ @param[in] Flag The link layer flag for the packet received, such\r
as multicast.\r
- @param Context The IP4 service instance that own the MNP.\r
-\r
- @return None\r
+ @param[in] Context The IP4 service instance that own the MNP.\r
\r
**/\r
VOID\r
}\r
\r
//\r
- // Check that the IP4 header is correctly formated\r
+ // Check that the IP4 header is correctly formatted\r
//\r
if (Packet->TotalSize < IP4_MIN_HEADLEN) {\r
goto RESTART;\r
// fragment if its head has MF (more fragment) set, or it starts\r
// at non-zero byte.\r
//\r
- if ((Head->Fragment & IP4_HEAD_MF_MASK) || (Info->Start != 0)) {\r
+ if (((Head->Fragment & IP4_HEAD_MF_MASK) != 0) || (Info->Start != 0)) {\r
//\r
// Drop the fragment if DF is set but it is fragmented. Gateway\r
// need to send a type 4 destination unreache ICMP message here.\r
//\r
- if (Head->Fragment & IP4_HEAD_DF_MASK) {\r
+ if ((Head->Fragment & IP4_HEAD_DF_MASK) != 0) {\r
goto RESTART;\r
}\r
\r
//\r
// The length of all but the last fragments is in the unit of 8 bytes.\r
//\r
- if ((Head->Fragment & IP4_HEAD_MF_MASK) && (Info->Length % 8 != 0)) {\r
+ if (((Head->Fragment & IP4_HEAD_MF_MASK) != 0) && (Info->Length % 8 != 0)) {\r
goto RESTART;\r
}\r
\r
// Dispatch the DPCs queued by the NotifyFunction of the rx token's events\r
// which are signaled with received data.\r
//\r
- NetLibDispatchDpc ();\r
+ DispatchDpc ();\r
\r
RESTART:\r
Ip4ReceiveFrame (IpSb->DefaultInterface, NULL, Ip4AccpetFrame, IpSb);\r
/**\r
Check whether this IP child accepts the packet.\r
\r
- @param IpInstance The IP child to check\r
- @param Head The IP header of the packet\r
- @param Packet The data of the packet\r
+ @param[in] IpInstance The IP child to check\r
+ @param[in] Head The IP header of the packet\r
+ @param[in] Packet The data of the packet\r
\r
- @return TRUE if the child wants to receive the packet, otherwise return FALSE.\r
+ @retval TRUE If the child wants to receive the packet.\r
+ @retval FALSE Otherwise.\r
\r
**/\r
BOOLEAN\r
//\r
// Dirty trick for the Tiano UEFI network stack implmentation. If\r
// ReceiveTimeout == -1, the receive of the packet for this instance\r
- // is disabled. The UEFI spec don't have such captibility. We add\r
+ // is disabled. The UEFI spec don't have such capability. We add\r
// this to improve the performance because IP will make a copy of\r
// the received packet for each accepting instance. Some IP instances\r
// used by UDP/TCP only send packets, they don't wants to receive.\r
packet is acceptable to it. Here the data of the packet is\r
shared, but the net buffer isn't.\r
\r
- @param IpInstance The IP4 child to enqueue the packet to\r
- @param Head The IP header of the received packet\r
- @param Packet The data of the received packet\r
+ @param[in] IpInstance The IP4 child to enqueue the packet to\r
+ @param[in] Head The IP header of the received packet\r
+ @param[in] Packet The data of the received packet\r
\r
@retval EFI_NOT_STARTED The IP child hasn't been configured.\r
@retval EFI_INVALID_PARAMETER The child doesn't want to receive the packet\r
Info = IP4_GET_CLIP_INFO (Clone);\r
Info->Life = IP4_US_TO_SEC (IpInstance->ConfigData.ReceiveTimeout);\r
\r
- NetListInsertTail (&IpInstance->Received, &Clone->List);\r
+ InsertTailList (&IpInstance->Received, &Clone->List);\r
return EFI_SUCCESS;\r
}\r
\r
The signal handle of IP4's recycle event. It is called back\r
when the upper layer release the packet.\r
\r
- @param Event The IP4's recycle event.\r
- @param Context The context of the handle, which is a\r
- IP4_RXDATA_WRAP\r
-\r
- @return None\r
+ @param Event The IP4's recycle event.\r
+ @param Context The context of the handle, which is a\r
+ IP4_RXDATA_WRAP\r
\r
**/\r
-STATIC\r
VOID\r
EFIAPI\r
Ip4OnRecyclePacket (\r
\r
Wrap = (IP4_RXDATA_WRAP *) Context;\r
\r
- NET_TRYLOCK (&Wrap->IpInstance->RecycleLock);\r
- NetListRemoveEntry (&Wrap->Link);\r
- NET_UNLOCK (&Wrap->IpInstance->RecycleLock);\r
+ EfiAcquireLockOrFail (&Wrap->IpInstance->RecycleLock);\r
+ RemoveEntryList (&Wrap->Link);\r
+ EfiReleaseLock (&Wrap->IpInstance->RecycleLock);\r
\r
ASSERT (!NET_BUF_SHARED (Wrap->Packet));\r
NetbufFree (Wrap->Packet);\r
\r
gBS->CloseEvent (Wrap->RxData.RecycleSignal);\r
- NetFreePool (Wrap);\r
+ gBS->FreePool (Wrap);\r
}\r
\r
\r
to the upper layer. Upper layer will signal the recycle event in\r
it when it is done with the packet.\r
\r
- @param IpInstance The IP4 child to receive the packet\r
- @param Packet The packet to deliver up.\r
+ @param[in] IpInstance The IP4 child to receive the packet\r
+ @param[in] Packet The packet to deliver up.\r
\r
- @return NULL if failed to wrap the packet, otherwise the wrapper.\r
+ @retval Wrap if warp the packet succeed.\r
+ @retval NULL failed to wrap the packet .\r
\r
**/\r
IP4_RXDATA_WRAP *\r
EFI_IP4_RECEIVE_DATA *RxData;\r
EFI_STATUS Status;\r
\r
- Wrap = NetAllocatePool (IP4_RXDATA_WRAP_SIZE (Packet->BlockOpNum));\r
+ Wrap = AllocatePool (IP4_RXDATA_WRAP_SIZE (Packet->BlockOpNum));\r
\r
if (Wrap == NULL) {\r
return NULL;\r
}\r
\r
- NetListInit (&Wrap->Link);\r
+ InitializeListHead (&Wrap->Link);\r
\r
Wrap->IpInstance = IpInstance;\r
Wrap->Packet = Packet;\r
RxData = &Wrap->RxData;\r
\r
- NetZeroMem (&RxData->TimeStamp, sizeof (EFI_TIME));\r
+ ZeroMem (&RxData->TimeStamp, sizeof (EFI_TIME));\r
\r
Status = gBS->CreateEvent (\r
EVT_NOTIFY_SIGNAL,\r
- NET_TPL_RECYCLE,\r
+ TPL_NOTIFY,\r
Ip4OnRecyclePacket,\r
Wrap,\r
&RxData->RecycleSignal\r
);\r
\r
if (EFI_ERROR (Status)) {\r
- NetFreePool (Wrap);\r
+ gBS->FreePool (Wrap);\r
return NULL;\r
}\r
\r
duplicate it to a non-shared packet, release the shared packet, then\r
deliver the non-shared packet up.\r
\r
- @param IpInstance The IP child to deliver the packet up.\r
+ @param[in] IpInstance The IP child to deliver the packet up.\r
\r
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the\r
packets.\r
//\r
// Deliver a packet if there are both a packet and a receive token.\r
//\r
- while (!NetListIsEmpty (&IpInstance->Received) &&\r
+ while (!IsListEmpty (&IpInstance->Received) &&\r
!NetMapIsEmpty (&IpInstance->RxTokens)) {\r
\r
Packet = NET_LIST_HEAD (&IpInstance->Received, NET_BUF, List);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- NetListRemoveEntry (&Packet->List);\r
+ RemoveEntryList (&Packet->List);\r
\r
} else {\r
//\r
Head = NetbufAllocSpace (Dup, IP4_MAX_HEADLEN, NET_BUF_HEAD);\r
Dup->Ip = (IP4_HEAD *) Head;\r
\r
- NetCopyMem (Head, Packet->Ip, Packet->Ip->HeadLen << 2);\r
+ CopyMem (Head, Packet->Ip, Packet->Ip->HeadLen << 2);\r
NetbufTrim (Dup, IP4_MAX_HEADLEN, TRUE);\r
\r
Wrap = Ip4WrapRxData (IpInstance, Dup);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- NetListRemoveEntry (&Packet->List);\r
+ RemoveEntryList (&Packet->List);\r
NetbufFree (Packet);\r
\r
Packet = Dup;\r
// Insert it into the delivered packet, then get a user's\r
// receive token, pass the wrapped packet up.\r
//\r
- NET_TRYLOCK (&IpInstance->RecycleLock);\r
- NetListInsertHead (&IpInstance->Delivered, &Wrap->Link);\r
- NET_UNLOCK (&IpInstance->RecycleLock);\r
+ EfiAcquireLockOrFail (&IpInstance->RecycleLock);\r
+ InsertHeadList (&IpInstance->Delivered, &Wrap->Link);\r
+ EfiReleaseLock (&IpInstance->RecycleLock);\r
\r
Token = NetMapRemoveHead (&IpInstance->RxTokens, NULL);\r
Token->Status = IP4_GET_CLIP_INFO (Packet)->Status;\r
Enqueue a received packet to all the IP children that share\r
the same interface.\r
\r
- @param IpSb The IP4 service instance that receive the packet\r
- @param Head The header of the received packet\r
- @param Packet The data of the received packet\r
- @param IpIf The interface to enqueue the packet to\r
+ @param[in] IpSb The IP4 service instance that receive the packet\r
+ @param[in] Head The header of the received packet\r
+ @param[in] Packet The data of the received packet\r
+ @param[in] IpIf The interface to enqueue the packet to\r
\r
@return The number of the IP4 children that accepts the packet\r
\r
{\r
IP4_PROTOCOL *IpInstance;\r
IP4_CLIP_INFO *Info;\r
- NET_LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Entry;\r
INTN Enqueued;\r
INTN LocalType;\r
INTN SavedType;\r
/**\r
Deliver the packet for each IP4 child on the interface.\r
\r
- @param IpSb The IP4 service instance that received the packet\r
- @param IpIf The IP4 interface to deliver the packet.\r
+ @param[in] IpSb The IP4 service instance that received the packet\r
+ @param[in] IpIf The IP4 interface to deliver the packet.\r
\r
@retval EFI_SUCCESS It always returns EFI_SUCCESS now\r
\r
)\r
{\r
IP4_PROTOCOL *Ip4Instance;\r
- NET_LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Entry;\r
\r
NET_LIST_FOR_EACH (Entry, &IpIf->IpInstances) {\r
Ip4Instance = NET_LIST_USER_STRUCT (Entry, IP4_PROTOCOL, AddrLink);\r
to each IP4 child that accepts the packet. The second pass will\r
deliver a non-shared copy of the packet to each IP4 child that\r
has pending receive requests. Data is copied if more than one\r
- child wants to consume the packet bacause each IP child need\r
+ child wants to consume the packet because each IP child needs\r
its own copy of the packet to make changes.\r
\r
- @param IpSb The IP4 service instance that received the packet\r
- @param Head The header of the received packet\r
- @param Packet The data of the received packet\r
+ @param[in] IpSb The IP4 service instance that received the packet\r
+ @param[in] Head The header of the received packet\r
+ @param[in] Packet The data of the received packet\r
\r
@retval EFI_NOT_FOUND No IP child accepts the packet\r
@retval EFI_SUCCESS The packet is enqueued or delivered to some IP\r
IN NET_BUF *Packet\r
)\r
{\r
- NET_LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Entry;\r
IP4_INTERFACE *IpIf;\r
INTN Enqueued;\r
\r
/**\r
Timeout the fragment and enqueued packets.\r
\r
- @param IpSb The IP4 service instance to timeout\r
-\r
- @return None\r
+ @param[in] IpSb The IP4 service instance to timeout\r
\r
**/\r
VOID\r
IN IP4_SERVICE *IpSb\r
)\r
{\r
- NET_LIST_ENTRY *InstanceEntry;\r
- NET_LIST_ENTRY *Entry;\r
- NET_LIST_ENTRY *Next;\r
+ LIST_ENTRY *InstanceEntry;\r
+ LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Next;\r
IP4_PROTOCOL *IpInstance;\r
IP4_ASSEMBLE_ENTRY *Assemble;\r
NET_BUF *Packet;\r
Assemble = NET_LIST_USER_STRUCT (Entry, IP4_ASSEMBLE_ENTRY, Link);\r
\r
if ((Assemble->Life > 0) && (--Assemble->Life == 0)) {\r
- NetListRemoveEntry (Entry);\r
+ RemoveEntryList (Entry);\r
Ip4FreeAssembleEntry (Assemble);\r
}\r
}\r
Info = IP4_GET_CLIP_INFO (Packet);\r
\r
if ((Info->Life > 0) && (--Info->Life == 0)) {\r
- NetListRemoveEntry (Entry);\r
+ RemoveEntryList (Entry);\r
NetbufFree (Packet);\r
}\r
}\r