]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
[Change summary]:
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Input.c
index 9498d056e16eb06d99d99742ccc62f431c6a8922..725735330129ae820cea598dc5077dde3f07f4da 100644 (file)
@@ -1,6 +1,7 @@
 /** @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
@@ -9,35 +10,25 @@ http://opensource.org/licenses/bsd-license.php
 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
@@ -73,14 +64,11 @@ Ip4CreateAssembleEntry (
 \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
@@ -105,14 +93,12 @@ Ip4FreeAssembleEntry (
   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
@@ -127,9 +113,7 @@ Ip4InitAssembleTable (
   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
@@ -161,15 +145,12 @@ Ip4CleanAssembleTable (
   @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
@@ -203,12 +184,9 @@ Ip4TrimPacket (
   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
@@ -224,18 +202,19 @@ Ip4OnFreeFragments (
   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
@@ -249,7 +228,7 @@ Ip4Reassemble (
   NET_BUF                   *NewPacket;\r
   INTN                      Index;\r
 \r
-  IpHead  = Packet->Ip;\r
+  IpHead  = Packet->Ip.Ip4;\r
   This    = IP4_GET_CLIP_INFO (Packet);\r
 \r
   ASSERT (IpHead != NULL);\r
@@ -286,6 +265,10 @@ Ip4Reassemble (
 \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
@@ -398,7 +381,7 @@ Ip4Reassemble (
   //\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
@@ -434,7 +417,7 @@ Ip4Reassemble (
       return NULL;\r
     }\r
 \r
-    NewPacket->Ip                  = Assemble->Head;\r
+    NewPacket->Ip.Ip4 = Assemble->Head;\r
     CopyMem (IP4_GET_CLIP_INFO (NewPacket), Assemble->Info, sizeof (*IP4_GET_CLIP_INFO (NewPacket)));\r
     return NewPacket;\r
   }\r
@@ -451,15 +434,13 @@ DROP:
   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
@@ -486,7 +467,7 @@ Ip4AccpetFrame (
   }\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
@@ -520,7 +501,7 @@ Ip4AccpetFrame (
   //\r
   // Convert the IP header to host byte order, then get the per packet info.\r
   //\r
-  Packet->Ip      = Ip4NtohHead (Head);\r
+  Packet->Ip.Ip4  = Ip4NtohHead (Head);\r
 \r
   Info            = IP4_GET_CLIP_INFO (Packet);\r
   Info->LinkFlag  = Flag;\r
@@ -558,19 +539,19 @@ Ip4AccpetFrame (
   // 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
@@ -589,11 +570,11 @@ Ip4AccpetFrame (
   // info must be reloaded bofore use. The ownership of the packet\r
   // is transfered to the packet process logic.\r
   //\r
-  Head  = Packet->Ip;\r
+  Head  = Packet->Ip.Ip4;\r
   IP4_GET_CLIP_INFO (Packet)->Status = EFI_SUCCESS;\r
 \r
   switch (Head->Protocol) {\r
-  case IP4_PROTO_ICMP:\r
+  case EFI_IP_PROTO_ICMP:\r
     Ip4IcmpHandle (IpSb, Head, Packet);\r
     break;\r
 \r
@@ -611,7 +592,7 @@ Ip4AccpetFrame (
   // 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
@@ -628,11 +609,12 @@ DROP:
 /**\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
@@ -653,7 +635,7 @@ Ip4InstanceFrameAcceptable (
   //\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
@@ -673,7 +655,7 @@ Ip4InstanceFrameAcceptable (
   //\r
   Proto = Head->Protocol;\r
 \r
-  if (Proto == IP4_PROTO_ICMP) {\r
+  if (Proto == EFI_IP_PROTO_ICMP) {\r
     NetbufCopy (Packet, 0, sizeof (Icmp.Head), (UINT8 *) &Icmp.Head);\r
 \r
     if (mIcmpClass[Icmp.Head.Type].IcmpClass == ICMP_ERROR_MESSAGE) {\r
@@ -732,9 +714,9 @@ Ip4InstanceFrameAcceptable (
   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
@@ -788,14 +770,11 @@ Ip4InstanceEnquePacket (
   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
@@ -827,10 +806,11 @@ Ip4OnRecyclePacket (
   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
@@ -870,13 +850,13 @@ Ip4WrapRxData (
     return NULL;\r
   }\r
 \r
-  ASSERT (Packet->Ip != NULL);\r
+  ASSERT (Packet->Ip.Ip4 != NULL);\r
 \r
   //\r
   // The application expects a network byte order header.\r
   //\r
-  RxData->HeaderLength  = (Packet->Ip->HeadLen << 2);\r
-  RxData->Header        = (EFI_IP4_HEADER *) Ip4NtohHead (Packet->Ip);\r
+  RxData->HeaderLength  = (Packet->Ip.Ip4->HeadLen << 2);\r
+  RxData->Header        = (EFI_IP4_HEADER *) Ip4NtohHead (Packet->Ip.Ip4);\r
 \r
   RxData->OptionsLength = RxData->HeaderLength - IP4_MIN_HEADLEN;\r
   RxData->Options       = NULL;\r
@@ -903,7 +883,7 @@ Ip4WrapRxData (
   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
@@ -958,9 +938,9 @@ Ip4InstanceDeliverPacket (
       // may be not continuous before the data.\r
       //\r
       Head    = NetbufAllocSpace (Dup, IP4_MAX_HEADLEN, NET_BUF_HEAD);\r
-      Dup->Ip = (IP4_HEAD *) Head;\r
+      Dup->Ip.Ip4 = (IP4_HEAD *) Head;\r
 \r
-      CopyMem (Head, Packet->Ip, Packet->Ip->HeadLen << 2);\r
+      CopyMem (Head, Packet->Ip.Ip4, Packet->Ip.Ip4->HeadLen << 2);\r
       NetbufTrim (Dup, IP4_MAX_HEADLEN, TRUE);\r
 \r
       Wrap = Ip4WrapRxData (IpInstance, Dup);\r
@@ -999,10 +979,10 @@ Ip4InstanceDeliverPacket (
   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
@@ -1090,8 +1070,8 @@ Ip4InterfaceEnquePacket (
 /**\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
@@ -1120,12 +1100,12 @@ Ip4InterfaceDeliverPacket (
   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
@@ -1183,9 +1163,7 @@ Ip4Demultiplex (
 /**\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