]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeNetLib/NetBuffer.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Library / DxeNetLib / NetBuffer.c
index 139735e2cb313e75a3c58492c81df5d7d0273c68..9d333659d6d4a27be2581767d66130ef44a2288e 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Network library functions providing net buffer operation support.\r
 \r
-Copyright (c) 2005 - 2010, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2018, 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
@@ -1174,6 +1175,10 @@ NetbufTrim (
 \r
   NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE);\r
 \r
+  if (Len == 0 || Nbuf->TotalSize == 0) {\r
+    return 0;\r
+  }\r
+\r
   if (Len > Nbuf->TotalSize) {\r
     Len = Nbuf->TotalSize;\r
   }\r
@@ -1660,19 +1665,19 @@ NetblockChecksum (
 \r
   Sum = 0;\r
 \r
+  //\r
+  // Add left-over byte, if any\r
+  //\r
+  if (Len % 2 != 0) {\r
+    Sum += *(Bulk + Len - 1);\r
+  }\r
+\r
   while (Len > 1) {\r
     Sum += *(UINT16 *) Bulk;\r
     Bulk += 2;\r
     Len -= 2;\r
   }\r
 \r
-  //\r
-  // Add left-over byte, if any\r
-  //\r
-  if (Len > 0) {\r
-    Sum += *(UINT8 *) Bulk;\r
-  }\r
-\r
   //\r
   // Fold 32-bit sum to 16 bits\r
   //\r
@@ -1817,6 +1822,7 @@ NetPseudoHeadChecksum (
 \r
 **/\r
 UINT16\r
+EFIAPI\r
 NetIp6PseudoHeadChecksum (\r
   IN EFI_IPv6_ADDRESS       *Src,\r
   IN EFI_IPv6_ADDRESS       *Dst,\r
@@ -1840,3 +1846,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