+\r
+/**\r
+ Compute the checksum for TCP6/UDP6 pseudo header.\r
+\r
+ Src and Dst are in network byte order, and Len is in host byte order.\r
+\r
+ @param[in] Src The source address of the packet.\r
+ @param[in] Dst The destination address of the packet.\r
+ @param[in] NextHeader The protocol type of the packet.\r
+ @param[in] Len The length of the packet.\r
+\r
+ @return The computed checksum.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+NetIp6PseudoHeadChecksum (\r
+ IN EFI_IPv6_ADDRESS *Src,\r
+ IN EFI_IPv6_ADDRESS *Dst,\r
+ IN UINT8 NextHeader,\r
+ IN UINT32 Len\r
+ )\r
+{\r
+ NET_IP6_PSEUDO_HDR Hdr;\r
+\r
+ //\r
+ // Zero the memory to relieve align problems\r
+ //\r
+ ZeroMem (&Hdr, sizeof (Hdr));\r
+\r
+ IP6_COPY_ADDRESS (&Hdr.SrcIp, Src);\r
+ IP6_COPY_ADDRESS (&Hdr.DstIp, Dst);\r
+\r
+ Hdr.NextHeader = NextHeader;\r
+ Hdr.Len = HTONL (Len);\r
+\r
+ 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