TianoCore EDK2 master
|
#include <Uefi.h>
#include <Library/NetLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
Go to the source code of this file.
Functions | |
NET_BUF * | NetbufAllocStruct (IN UINT32 BlockNum, IN UINT32 BlockOpNum) |
NET_BUF *EFIAPI | NetbufAlloc (IN UINT32 Len) |
VOID | NetbufFreeVector (IN NET_VECTOR *Vector) |
VOID EFIAPI | NetbufFree (IN NET_BUF *Nbuf) |
NET_BUF *EFIAPI | NetbufClone (IN NET_BUF *Nbuf) |
NET_BUF *EFIAPI | NetbufDuplicate (IN NET_BUF *Nbuf, IN OUT NET_BUF *Duplicate OPTIONAL, IN UINT32 HeadSpace) |
VOID EFIAPI | NetbufFreeList (IN OUT LIST_ENTRY *Head) |
UINT8 *EFIAPI | NetbufGetByte (IN NET_BUF *Nbuf, IN UINT32 Offset, OUT UINT32 *Index OPTIONAL) |
VOID | NetbufSetBlock (IN OUT NET_BUF *Nbuf, IN UINT8 *Bulk, IN UINT32 Len, IN UINT32 Index) |
VOID | NetbufSetBlockOp (IN OUT NET_BUF *Nbuf, IN UINT8 *Bulk, IN UINT32 Len, IN UINT32 Index) |
VOID EFIAPI | NetbufGetFragmentFree (IN VOID *Arg) |
NET_BUF *EFIAPI | NetbufGetFragment (IN NET_BUF *Nbuf, IN UINT32 Offset, IN UINT32 Len, IN UINT32 HeadSpace) |
NET_BUF *EFIAPI | NetbufFromExt (IN NET_FRAGMENT *ExtFragment, IN UINT32 ExtNum, IN UINT32 HeadSpace, IN UINT32 HeadLen, IN NET_VECTOR_EXT_FREE ExtFree, IN VOID *Arg OPTIONAL) |
EFI_STATUS EFIAPI | NetbufBuildExt (IN NET_BUF *Nbuf, IN OUT NET_FRAGMENT *ExtFragment, IN OUT UINT32 *ExtNum) |
NET_BUF *EFIAPI | NetbufFromBufList (IN LIST_ENTRY *BufList, IN UINT32 HeadSpace, IN UINT32 HeaderLen, IN NET_VECTOR_EXT_FREE ExtFree, IN VOID *Arg OPTIONAL) |
VOID EFIAPI | NetbufReserve (IN OUT NET_BUF *Nbuf, IN UINT32 Len) |
UINT8 *EFIAPI | NetbufAllocSpace (IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead) |
VOID | NetblockTrim (IN OUT NET_BLOCK_OP *BlockOp, IN UINT32 Len, IN BOOLEAN FromHead) |
UINT32 EFIAPI | NetbufTrim (IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead) |
UINT32 EFIAPI | NetbufCopy (IN NET_BUF *Nbuf, IN UINT32 Offset, IN UINT32 Len, IN UINT8 *Dest) |
VOID EFIAPI | NetbufQueInit (IN OUT NET_BUF_QUEUE *NbufQue) |
NET_BUF_QUEUE *EFIAPI | NetbufQueAlloc (VOID) |
VOID EFIAPI | NetbufQueFree (IN NET_BUF_QUEUE *NbufQue) |
VOID EFIAPI | NetbufQueAppend (IN OUT NET_BUF_QUEUE *NbufQue, IN OUT NET_BUF *Nbuf) |
NET_BUF *EFIAPI | NetbufQueRemove (IN OUT NET_BUF_QUEUE *NbufQue) |
UINT32 EFIAPI | NetbufQueCopy (IN NET_BUF_QUEUE *NbufQue, IN UINT32 Offset, IN UINT32 Len, OUT UINT8 *Dest) |
UINT32 EFIAPI | NetbufQueTrim (IN OUT NET_BUF_QUEUE *NbufQue, IN UINT32 Len) |
VOID EFIAPI | NetbufQueFlush (IN OUT NET_BUF_QUEUE *NbufQue) |
UINT16 EFIAPI | NetblockChecksum (IN UINT8 *Bulk, IN UINT32 Len) |
UINT16 EFIAPI | NetAddChecksum (IN UINT16 Checksum1, IN UINT16 Checksum2) |
UINT16 EFIAPI | NetbufChecksum (IN NET_BUF *Nbuf) |
UINT16 EFIAPI | NetPseudoHeadChecksum (IN IP4_ADDR Src, IN IP4_ADDR Dst, IN UINT8 Proto, IN UINT16 Len) |
UINT16 EFIAPI | NetIp6PseudoHeadChecksum (IN EFI_IPv6_ADDRESS *Src, IN EFI_IPv6_ADDRESS *Dst, IN UINT8 NextHeader, IN UINT32 Len) |
VOID | NetIpSecNetbufFree (NET_BUF *Nbuf) |
Network library functions providing net buffer operation support.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file NetBuffer.c.
Add two checksums.
[in] | Checksum1 | The first checksum to be added. |
[in] | Checksum2 | The second checksum to be added. |
Definition at line 1658 of file NetBuffer.c.
Compute the checksum for a bulk of data.
[in] | Bulk | Pointer to the data. |
[in] | Len | Length of the data, in bytes. |
Definition at line 1615 of file NetBuffer.c.
VOID NetblockTrim | ( | IN OUT NET_BLOCK_OP * | BlockOp, |
IN UINT32 | Len, | ||
IN BOOLEAN | FromHead | ||
) |
Trim a single NET_BLOCK by Len bytes from the header or tail.
[in,out] | BlockOp | Pointer to the NET_BLOCK. |
[in] | Len | The length of the data to be trimmed. |
[in] | FromHead | The flag to indicate whether trim data from head (TRUE) or tail (FALSE). |
Definition at line 1103 of file NetBuffer.c.
Allocate a single block NET_BUF. Upon allocation, all the free space is in the tail room.
[in] | Len | The length of the block. |
Definition at line 89 of file NetBuffer.c.
Allocate Len bytes of space from the header or tail of the buffer.
[in,out] | Nbuf | Pointer to the net buffer. |
[in] | Len | The length of the buffer to be allocated. |
[in] | FromHead | The flag to indicate whether reserve the data from head (TRUE) or tail (FALSE). |
Definition at line 1015 of file NetBuffer.c.
Allocate and build up the sketch for a NET_BUF.
The net buffer allocated has the BlockOpNum's NET_BLOCK_OP, and its associated NET_VECTOR has the BlockNum's NET_BLOCK. But all the NET_BLOCK_OP and NET_BLOCK remain un-initialized.
[in] | BlockNum | The number of NET_BLOCK in the vector of net buffer |
[in] | BlockOpNum | The number of NET_BLOCK_OP in the net buffer |
Definition at line 32 of file NetBuffer.c.
EFI_STATUS EFIAPI NetbufBuildExt | ( | IN NET_BUF * | Nbuf, |
IN OUT NET_FRAGMENT * | ExtFragment, | ||
IN OUT UINT32 * | ExtNum | ||
) |
Build a fragment table to contain the fragments in the net buffer. This is the opposite operation of the NetbufFromExt.
[in] | Nbuf | Point to the net buffer. |
[in,out] | ExtFragment | Pointer to the data block. |
[in,out] | ExtNum | The number of the data blocks. |
EFI_BUFFER_TOO_SMALL | The number of non-empty block is bigger than ExtNum. |
EFI_SUCCESS | Fragment table is built successfully. |
Definition at line 866 of file NetBuffer.c.
Compute the checksum for a NET_BUF.
[in] | Nbuf | Pointer to the net buffer. |
Definition at line 1687 of file NetBuffer.c.
Create a copy of the net buffer that shares the associated net vector.
The reference count of the newly created net buffer is set to 1. The reference count of the associated net vector is increased by one.
[in] | Nbuf | Pointer to the net buffer to be cloned. |
Definition at line 229 of file NetBuffer.c.
Copy Len bytes of data from the specific offset of the net buffer to the destination memory.
The Len bytes of data may cross the several fragments of the net buffer.
[in] | Nbuf | Pointer to the net buffer. |
[in] | Offset | The sequence number of the first byte to copy. |
[in] | Len | Length of the data to copy. |
[in] | Dest | The destination of the data to copy to. |
Definition at line 1206 of file NetBuffer.c.
NET_BUF *EFIAPI NetbufDuplicate | ( | IN NET_BUF * | Nbuf, |
IN OUT NET_BUF *Duplicate | OPTIONAL, | ||
IN UINT32 | HeadSpace | ||
) |
Create a duplicated copy of the net buffer with data copied and HeadSpace bytes of head space reserved.
The duplicated net buffer will allocate its own memory to hold the data of the source net buffer.
[in] | Nbuf | Pointer to the net buffer to be duplicated from. |
[in,out] | Duplicate | Pointer to the net buffer to duplicate to, if NULL a new net buffer is allocated. |
[in] | HeadSpace | Length of the head space to reserve. |
Definition at line 280 of file NetBuffer.c.
Free the net buffer and its associated NET_VECTOR.
Decrease the reference count of the net buffer by one. Free the associated net vector and itself if the reference count of the net buffer is decreased to 0. The net vector free operation just decrease the reference count of the net vector by one and do the real resource free operation when the reference count of the net vector is 0.
[in] | Nbuf | Pointer to the NET_BUF to be freed. |
Definition at line 195 of file NetBuffer.c.
VOID EFIAPI NetbufFreeList | ( | IN OUT LIST_ENTRY * | Head | ) |
Free a list of net buffers.
[in,out] | Head | Pointer to the head of linked net buffers. |
Definition at line 319 of file NetBuffer.c.
VOID NetbufFreeVector | ( | IN NET_VECTOR * | Vector | ) |
Free the net vector.
Decrease the reference count of the net vector by one. The real resource free operation isn't performed until the reference count of the net vector is decreased to 0.
[in] | Vector | Pointer to the NET_VECTOR to be freed. |
Definition at line 142 of file NetBuffer.c.
NET_BUF *EFIAPI NetbufFromBufList | ( | IN LIST_ENTRY * | BufList, |
IN UINT32 | HeadSpace, | ||
IN UINT32 | HeaderLen, | ||
IN NET_VECTOR_EXT_FREE | ExtFree, | ||
IN VOID *Arg | OPTIONAL | ||
) |
Build a net buffer from a list of net buffers.
All the fragments will be collected from the list of NEW_BUF and then a new net buffer will be created through NetbufFromExt.
[in] | BufList | A List of the net buffer. |
[in] | HeadSpace | The head space to be reserved. |
[in] | HeaderLen | The length of the protocol header, This function will pull that number of data into a linear block. |
[in] | ExtFree | Pointer to the caller provided free function. |
[in] | Arg | The argument passed to ExtFree when ExtFree is called. |
Definition at line 914 of file NetBuffer.c.
NET_BUF *EFIAPI NetbufFromExt | ( | IN NET_FRAGMENT * | ExtFragment, |
IN UINT32 | ExtNum, | ||
IN UINT32 | HeadSpace, | ||
IN UINT32 | HeadLen, | ||
IN NET_VECTOR_EXT_FREE | ExtFree, | ||
IN VOID *Arg | OPTIONAL | ||
) |
Build a NET_BUF from external blocks.
A new NET_BUF structure will be created from external blocks. Additional block of memory will be allocated to hold reserved HeadSpace bytes of header room and existing HeadLen bytes of header but the external blocks are shared by the net buffer to avoid data copying.
[in] | ExtFragment | Pointer to the data block. |
[in] | ExtNum | The number of the data blocks. |
[in] | HeadSpace | The head space to be reserved. |
[in] | HeadLen | The length of the protocol header, This function will pull that number of data into a linear block. |
[in] | ExtFree | Pointer to the caller provided free function. |
[in] | Arg | The argument passed to ExtFree when ExtFree is called. |
Definition at line 693 of file NetBuffer.c.
Get the index of NET_BLOCK_OP that contains the byte at Offset in the net buffer.
This can be used to, for example, retrieve the IP header in the packet. It also can be used to get the fragment that contains the byte which is used mainly by the library implementation itself.
[in] | Nbuf | Pointer to the net buffer. |
[in] | Offset | The offset of the byte. |
[out] | Index | Index of the NET_BLOCK_OP that contains the byte at Offset. |
Definition at line 359 of file NetBuffer.c.
NET_BUF *EFIAPI NetbufGetFragment | ( | IN NET_BUF * | Nbuf, |
IN UINT32 | Offset, | ||
IN UINT32 | Len, | ||
IN UINT32 | HeadSpace | ||
) |
Create a NET_BUF structure which contains Len byte data of Nbuf starting from Offset.
A new NET_BUF structure will be created but the associated data in NET_VECTOR is shared. This function exists to do IP packet fragmentation.
[in] | Nbuf | Pointer to the net buffer to be extracted. |
[in] | Offset | Starting point of the data to be included in the new net buffer. |
[in] | Len | Bytes of data to be included in the new net buffer. |
[in] | HeadSpace | Bytes of head space to reserve for protocol header. |
Definition at line 510 of file NetBuffer.c.
VOID EFIAPI NetbufGetFragmentFree | ( | IN VOID * | Arg | ) |
Helper function for NetbufGetFragment. NetbufGetFragment may allocate the first block to reserve HeadSpace bytes header space. So it needs to create a new net vector for the first block and can avoid copy for the remaining data by sharing the old net vector.
[in] | Arg | Point to the old NET_VECTOR. |
Definition at line 481 of file NetBuffer.c.
NET_BUF_QUEUE *EFIAPI NetbufQueAlloc | ( | VOID | ) |
Allocate and initialize a net buffer queue.
Definition at line 1322 of file NetBuffer.c.
Append a net buffer to the net buffer queue.
[in,out] | NbufQue | Pointer to the net buffer queue. |
[in,out] | Nbuf | Pointer to the net buffer to be appended. |
Definition at line 1374 of file NetBuffer.c.
UINT32 EFIAPI NetbufQueCopy | ( | IN NET_BUF_QUEUE * | NbufQue, |
IN UINT32 | Offset, | ||
IN UINT32 | Len, | ||
OUT UINT8 * | Dest | ||
) |
Copy Len bytes of data from the net buffer queue at the specific offset to the destination memory.
The copying operation is the same as NetbufCopy but applies to the net buffer queue instead of the net buffer.
[in] | NbufQue | Pointer to the net buffer queue. |
[in] | Offset | The sequence number of the first byte to copy. |
[in] | Len | Length of the data to copy. |
[out] | Dest | The destination of the data to copy to. |
Definition at line 1438 of file NetBuffer.c.
VOID EFIAPI NetbufQueFlush | ( | IN OUT NET_BUF_QUEUE * | NbufQue | ) |
Flush the net buffer queue.
[in,out] | NbufQue | Pointer to the queue to be flushed. |
Definition at line 1592 of file NetBuffer.c.
VOID EFIAPI NetbufQueFree | ( | IN NET_BUF_QUEUE * | NbufQue | ) |
Free a net buffer queue.
Decrease the reference count of the net buffer queue by one. The real resource free operation isn't performed until the reference count of the net buffer queue is decreased to 0.
[in] | NbufQue | Pointer to the net buffer queue to be freed. |
Definition at line 1350 of file NetBuffer.c.
VOID EFIAPI NetbufQueInit | ( | IN OUT NET_BUF_QUEUE * | NbufQue | ) |
Initiate the net buffer queue.
[in,out] | NbufQue | Pointer to the net buffer queue to be initialized. |
Definition at line 1300 of file NetBuffer.c.
NET_BUF *EFIAPI NetbufQueRemove | ( | IN OUT NET_BUF_QUEUE * | NbufQue | ) |
Remove a net buffer from the head in the specific queue and return it.
[in,out] | NbufQue | Pointer to the net buffer queue. |
Definition at line 1399 of file NetBuffer.c.
UINT32 EFIAPI NetbufQueTrim | ( | IN OUT NET_BUF_QUEUE * | NbufQue, |
IN UINT32 | Len | ||
) |
Trim Len bytes of data from the buffer queue and free any net buffer that is completely trimmed.
The trimming operation is the same as NetbufTrim but applies to the net buffer queue instead of the net buffer.
[in,out] | NbufQue | Pointer to the net buffer queue. |
[in] | Len | Length of the data to trim. |
Definition at line 1537 of file NetBuffer.c.
Reserve some space in the header room of the net buffer.
Upon allocation, all the space are in the tail room of the buffer. Call this function to move some space to the header room. This function is quite limited in that it can only reserve space from the first block of an empty NET_BUF not built from the external. But it should be enough for the network stack.
[in,out] | Nbuf | Pointer to the net buffer. |
[in] | Len | The length of buffer to be reserved from the header. |
Definition at line 984 of file NetBuffer.c.
Set the NET_BLOCK and corresponding NET_BLOCK_OP in the net buffer and corresponding net vector according to the bulk pointer and bulk length.
All the pointers in the Index'th NET_BLOCK and NET_BLOCK_OP are set to the bulk's head and tail respectively. So, this function alone can't be used by NetbufAlloc.
[in,out] | Nbuf | Pointer to the net buffer. |
[in] | Bulk | Pointer to the data. |
[in] | Len | Length of the bulk data. |
[in] | Index | The data block index in the net buffer the bulk data should belong to. |
Definition at line 410 of file NetBuffer.c.
Set the NET_BLOCK_OP in the net buffer. The corresponding NET_BLOCK structure is left untouched.
Some times, there is no 1:1 relationship between NET_BLOCK and NET_BLOCK_OP. For example, that in NetbufGetFragment.
[in,out] | Nbuf | Pointer to the net buffer. |
[in] | Bulk | Pointer to the data. |
[in] | Len | Length of the bulk data. |
[in] | Index | The data block index in the net buffer the bulk data should belong to. |
Definition at line 450 of file NetBuffer.c.
Trim Len bytes from the header or tail of the net buffer.
[in,out] | Nbuf | Pointer to the net buffer. |
[in] | Len | The length of the data to be trimmed. |
[in] | FromHead | The flag to indicate whether trim data from head (TRUE) or tail (FALSE). |
Definition at line 1134 of file NetBuffer.c.
UINT16 EFIAPI NetIp6PseudoHeadChecksum | ( | IN EFI_IPv6_ADDRESS * | Src, |
IN EFI_IPv6_ADDRESS * | Dst, | ||
IN UINT8 | NextHeader, | ||
IN UINT32 | Len | ||
) |
Compute the checksum for TCP6/UDP6 pseudo header.
Src and Dst are in network byte order, and Len is in host byte order.
[in] | Src | The source address of the packet. |
[in] | Dst | The destination address of the packet. |
[in] | NextHeader | The protocol type of the packet. |
[in] | Len | The length of the packet. |
Definition at line 1777 of file NetBuffer.c.
VOID NetIpSecNetbufFree | ( | NET_BUF * | Nbuf | ) |
The function frees the net buffer which allocated by the IP protocol. It releases only the net buffer and doesn't call the external free function.
This function should be called after finishing the process of mIpSec->ProcessExt() for outbound traffic. The (EFI_IPSEC2_PROTOCOL)->ProcessExt() allocates a new buffer for the ESP, so there needs a function to free the old net buffer.
[in] | Nbuf | The network buffer to be freed. |
Definition at line 1812 of file NetBuffer.c.
UINT16 EFIAPI NetPseudoHeadChecksum | ( | IN IP4_ADDR | Src, |
IN IP4_ADDR | Dst, | ||
IN UINT8 | Proto, | ||
IN UINT16 | Len | ||
) |
Compute the checksum for TCP/UDP pseudo header.
Src and Dst are in network byte order, and Len is in host byte order.
[in] | Src | The source address of the packet. |
[in] | Dst | The destination address of the packet. |
[in] | Proto | The protocol type of the packet. |
[in] | Len | The length of the packet. |
Definition at line 1740 of file NetBuffer.c.