]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeNetLib/NetBuffer.c
1. Define a netlib library function NetLibGetSystemGuid()
[mirror_edk2.git] / MdeModulePkg / Library / DxeNetLib / NetBuffer.c
index eadffbb45d6ae88c0e3d1a4567bb63d54ead4bdd..bbbdbc048aedc45acacc1b462f57e20d1beb69e1 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Network library functions providing net buffer operation support.\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
+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
 http://opensource.org/licenses/bsd-license.php\r
@@ -497,6 +497,7 @@ NetbufSetBlockOp (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 NetbufGetFragmentFree (\r
   IN VOID                   *Arg\r
   )\r
@@ -508,7 +509,6 @@ NetbufGetFragmentFree (
 }\r
 \r
 \r
-\r
 /**\r
   Create a NET_BUF structure which contains Len byte data of Nbuf starting from\r
   Offset.\r
@@ -579,9 +579,6 @@ NetbufGetFragment (
   FirstSkip = Offset - Cur;\r
   FirstLen  = BlockOp[Index].Size - FirstSkip;\r
 \r
-  //\r
-  //redundant assignment to make compiler happy.\r
-  //\r
   Last      = 0;\r
   LastLen   = 0;\r
 \r
@@ -605,6 +602,7 @@ NetbufGetFragment (
     FirstLen = Len;\r
   }\r
 \r
+  ASSERT (Last >= First);\r
   BlockOpNum = Last - First + 1;\r
   CurBlockOp = 0;\r
 \r
@@ -640,7 +638,7 @@ NetbufGetFragment (
     Child->BlockOp[0].Size =  0;\r
     CurBlockOp++;\r
 \r
-  }else {\r
+  } else {\r
     Child = NetbufAllocStruct (0, BlockOpNum);\r
 \r
     if (Child == NULL) {\r
@@ -664,7 +662,7 @@ NetbufGetFragment (
     CurBlockOp++\r
     );\r
 \r
-  for (Index = First + 1; Index <= Last - 1 ; Index++) {\r
+  for (Index = First + 1; Index < Last; Index++) {\r
     NetbufSetBlockOp (\r
       Child,\r
       BlockOp[Index].Head,\r
@@ -1053,6 +1051,8 @@ NetbufAllocSpace (
   UINT32                    Index;\r
   UINT8                     *SavedTail;\r
 \r
+  Index = 0;\r
+\r
   NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE);\r
   NET_CHECK_SIGNATURE (Nbuf->Vector, NET_VECTOR_SIGNATURE);\r
 \r
@@ -1557,8 +1557,8 @@ NetbufQueCopy (
 \r
 \r
 /**\r
-  Trim Len bytes of data from the queue header, release any of the net buffer\r
-  whom is trimmed wholely.\r
+  Trim Len bytes of data from the buffer queue and free any net buffer\r
+  that is completely trimmed.\r
 \r
   The trimming operation is the same as NetbufTrim but applies to the net buffer\r
   queue instead of the net buffer.\r
@@ -1818,6 +1818,7 @@ NetPseudoHeadChecksum (
 \r
 **/\r
 UINT16\r
+EFIAPI\r
 NetIp6PseudoHeadChecksum (\r
   IN EFI_IPv6_ADDRESS       *Src,\r
   IN EFI_IPv6_ADDRESS       *Dst,\r
@@ -1841,3 +1842,51 @@ NetIp6PseudoHeadChecksum (
   return NetblockChecksum ((UINT8 *) &Hdr, sizeof (Hdr));\r
 }\r
 \r
+/**\r
+  The function frees the net buffer which allocated by the IP protocol. It releases \r
+  only the net buffer and doesn't call the external free function. \r
+\r
+  This function should be called after finishing the process of mIpSec->ProcessExt() \r
+  for outbound traffic. The (EFI_IPSEC2_PROTOCOL)->ProcessExt() allocates a new \r
+  buffer for the ESP, so there needs a function to free the old net buffer.\r
+\r
+  @param[in]  Nbuf       The network buffer to be freed.\r
+\r
+**/\r
+VOID\r
+NetIpSecNetbufFree (\r
+  NET_BUF   *Nbuf\r
+  )\r
+{\r
+  NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE);\r
+  ASSERT (Nbuf->RefCnt > 0);\r
+\r
+  Nbuf->RefCnt--;\r
+\r
+  if (Nbuf->RefCnt == 0) {\r
+    \r
+    //\r
+    // Update Vector only when NBuf is to be released. That is,\r
+    // all the sharing of Nbuf increse Vector's RefCnt by one\r
+    //\r
+    NET_CHECK_SIGNATURE (Nbuf->Vector, NET_VECTOR_SIGNATURE);\r
+    ASSERT (Nbuf->Vector->RefCnt > 0);\r
+\r
+    Nbuf->Vector->RefCnt--;\r
+\r
+    if (Nbuf->Vector->RefCnt > 0) {\r
+      return;\r
+    }\r
+\r
+    //\r
+    // If NET_VECTOR_OWN_FIRST is set, release the first block since it is \r
+    // allocated by us\r
+    //\r
+    if ((Nbuf->Vector->Flag & NET_VECTOR_OWN_FIRST) != 0) {\r
+      FreePool (Nbuf->Vector->Block[0].Bulk);\r
+    }\r
+    FreePool (Nbuf->Vector);\r
+    FreePool (Nbuf); \r
+  } \r
+}\r
+\r