TianoCore EDK2 master
Loading...
Searching...
No Matches
NetBuffer.c File Reference

Go to the source code of this file.

Functions

NET_BUFNetbufAllocStruct (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)
 

Detailed Description

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.

Function Documentation

◆ NetAddChecksum()

UINT16 EFIAPI NetAddChecksum ( IN UINT16  Checksum1,
IN UINT16  Checksum2 
)

Add two checksums.

Parameters
[in]Checksum1The first checksum to be added.
[in]Checksum2The second checksum to be added.
Returns
The new checksum.

Definition at line 1658 of file NetBuffer.c.

◆ NetblockChecksum()

UINT16 EFIAPI NetblockChecksum ( IN UINT8 *  Bulk,
IN UINT32  Len 
)

Compute the checksum for a bulk of data.

Parameters
[in]BulkPointer to the data.
[in]LenLength of the data, in bytes.
Returns
The computed checksum.

Definition at line 1615 of file NetBuffer.c.

◆ NetblockTrim()

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.

Parameters
[in,out]BlockOpPointer to the NET_BLOCK.
[in]LenThe length of the data to be trimmed.
[in]FromHeadThe flag to indicate whether trim data from head (TRUE) or tail (FALSE).

Definition at line 1103 of file NetBuffer.c.

◆ NetbufAlloc()

NET_BUF *EFIAPI NetbufAlloc ( IN UINT32  Len)

Allocate a single block NET_BUF. Upon allocation, all the free space is in the tail room.

Parameters
[in]LenThe length of the block.
Returns
Pointer to the allocated NET_BUF, or NULL if the allocation failed due to resource limit.

Definition at line 89 of file NetBuffer.c.

◆ NetbufAllocSpace()

UINT8 *EFIAPI NetbufAllocSpace ( IN OUT NET_BUF Nbuf,
IN UINT32  Len,
IN BOOLEAN  FromHead 
)

Allocate Len bytes of space from the header or tail of the buffer.

Parameters
[in,out]NbufPointer to the net buffer.
[in]LenThe length of the buffer to be allocated.
[in]FromHeadThe flag to indicate whether reserve the data from head (TRUE) or tail (FALSE).
Returns
Pointer to the first byte of the allocated buffer, or NULL if there is no sufficient space.

Definition at line 1015 of file NetBuffer.c.

◆ NetbufAllocStruct()

NET_BUF * NetbufAllocStruct ( IN UINT32  BlockNum,
IN UINT32  BlockOpNum 
)

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.

Parameters
[in]BlockNumThe number of NET_BLOCK in the vector of net buffer
[in]BlockOpNumThe number of NET_BLOCK_OP in the net buffer
Returns
Pointer to the allocated NET_BUF, or NULL if the allocation failed due to resource limit.

Definition at line 32 of file NetBuffer.c.

◆ NetbufBuildExt()

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.

Parameters
[in]NbufPoint to the net buffer.
[in,out]ExtFragmentPointer to the data block.
[in,out]ExtNumThe number of the data blocks.
Return values
EFI_BUFFER_TOO_SMALLThe number of non-empty block is bigger than ExtNum.
EFI_SUCCESSFragment table is built successfully.

Definition at line 866 of file NetBuffer.c.

◆ NetbufChecksum()

UINT16 EFIAPI NetbufChecksum ( IN NET_BUF Nbuf)

Compute the checksum for a NET_BUF.

Parameters
[in]NbufPointer to the net buffer.
Returns
The computed checksum.

Definition at line 1687 of file NetBuffer.c.

◆ NetbufClone()

NET_BUF *EFIAPI NetbufClone ( IN NET_BUF Nbuf)

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.

Parameters
[in]NbufPointer to the net buffer to be cloned.
Returns
Pointer to the cloned net buffer, or NULL if the allocation failed due to resource limit.

Definition at line 229 of file NetBuffer.c.

◆ NetbufCopy()

UINT32 EFIAPI NetbufCopy ( IN NET_BUF Nbuf,
IN UINT32  Offset,
IN UINT32  Len,
IN UINT8 *  Dest 
)

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.

Parameters
[in]NbufPointer to the net buffer.
[in]OffsetThe sequence number of the first byte to copy.
[in]LenLength of the data to copy.
[in]DestThe destination of the data to copy to.
Returns
The length of the actual copied data, or 0 if the offset specified exceeds the total size of net buffer.

Definition at line 1206 of file NetBuffer.c.

◆ NetbufDuplicate()

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.

Parameters
[in]NbufPointer to the net buffer to be duplicated from.
[in,out]DuplicatePointer to the net buffer to duplicate to, if NULL a new net buffer is allocated.
[in]HeadSpaceLength of the head space to reserve.
Returns
Pointer to the duplicated net buffer, or NULL if the allocation failed due to resource limit.

Definition at line 280 of file NetBuffer.c.

◆ NetbufFree()

VOID EFIAPI NetbufFree ( IN NET_BUF Nbuf)

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.

Parameters
[in]NbufPointer to the NET_BUF to be freed.

Definition at line 195 of file NetBuffer.c.

◆ NetbufFreeList()

VOID EFIAPI NetbufFreeList ( IN OUT LIST_ENTRY Head)

Free a list of net buffers.

Parameters
[in,out]HeadPointer to the head of linked net buffers.

Definition at line 319 of file NetBuffer.c.

◆ NetbufFreeVector()

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.

Parameters
[in]VectorPointer to the NET_VECTOR to be freed.

Definition at line 142 of file NetBuffer.c.

◆ NetbufFromBufList()

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.

Parameters
[in]BufListA List of the net buffer.
[in]HeadSpaceThe head space to be reserved.
[in]HeaderLenThe length of the protocol header, This function will pull that number of data into a linear block.
[in]ExtFreePointer to the caller provided free function.
[in]ArgThe argument passed to ExtFree when ExtFree is called.
Returns
Pointer to the net buffer built from the list of net buffers.

Definition at line 914 of file NetBuffer.c.

◆ NetbufFromExt()

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.

Parameters
[in]ExtFragmentPointer to the data block.
[in]ExtNumThe number of the data blocks.
[in]HeadSpaceThe head space to be reserved.
[in]HeadLenThe length of the protocol header, This function will pull that number of data into a linear block.
[in]ExtFreePointer to the caller provided free function.
[in]ArgThe argument passed to ExtFree when ExtFree is called.
Returns
Pointer to the net buffer built from the data blocks, or NULL if the allocation failed due to resource limit.

Definition at line 693 of file NetBuffer.c.

◆ NetbufGetByte()

UINT8 *EFIAPI NetbufGetByte ( IN NET_BUF Nbuf,
IN UINT32  Offset,
OUT UINT32 *Index  OPTIONAL 
)

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.

Parameters
[in]NbufPointer to the net buffer.
[in]OffsetThe offset of the byte.
[out]IndexIndex of the NET_BLOCK_OP that contains the byte at Offset.
Returns
Pointer to the Offset'th byte of data in the net buffer, or NULL if there is no such data in the net buffer.

Definition at line 359 of file NetBuffer.c.

◆ NetbufGetFragment()

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.

Parameters
[in]NbufPointer to the net buffer to be extracted.
[in]OffsetStarting point of the data to be included in the new net buffer.
[in]LenBytes of data to be included in the new net buffer.
[in]HeadSpaceBytes of head space to reserve for protocol header.
Returns
Pointer to the cloned net buffer, or NULL if the allocation failed due to resource limit.

Definition at line 510 of file NetBuffer.c.

◆ NetbufGetFragmentFree()

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.

Parameters
[in]ArgPoint to the old NET_VECTOR.

Definition at line 481 of file NetBuffer.c.

◆ NetbufQueAlloc()

NET_BUF_QUEUE *EFIAPI NetbufQueAlloc ( VOID  )

Allocate and initialize a net buffer queue.

Returns
Pointer to the allocated net buffer queue, or NULL if the allocation failed due to resource limit.

Definition at line 1322 of file NetBuffer.c.

◆ NetbufQueAppend()

VOID EFIAPI NetbufQueAppend ( IN OUT NET_BUF_QUEUE NbufQue,
IN OUT NET_BUF Nbuf 
)

Append a net buffer to the net buffer queue.

Parameters
[in,out]NbufQuePointer to the net buffer queue.
[in,out]NbufPointer to the net buffer to be appended.

Definition at line 1374 of file NetBuffer.c.

◆ NetbufQueCopy()

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.

Parameters
[in]NbufQuePointer to the net buffer queue.
[in]OffsetThe sequence number of the first byte to copy.
[in]LenLength of the data to copy.
[out]DestThe destination of the data to copy to.
Returns
The length of the actual copied data, or 0 if the offset specified exceeds the total size of net buffer queue.

Definition at line 1438 of file NetBuffer.c.

◆ NetbufQueFlush()

VOID EFIAPI NetbufQueFlush ( IN OUT NET_BUF_QUEUE NbufQue)

Flush the net buffer queue.

Parameters
[in,out]NbufQuePointer to the queue to be flushed.

Definition at line 1592 of file NetBuffer.c.

◆ NetbufQueFree()

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.

Parameters
[in]NbufQuePointer to the net buffer queue to be freed.

Definition at line 1350 of file NetBuffer.c.

◆ NetbufQueInit()

VOID EFIAPI NetbufQueInit ( IN OUT NET_BUF_QUEUE NbufQue)

Initiate the net buffer queue.

Parameters
[in,out]NbufQuePointer to the net buffer queue to be initialized.

Definition at line 1300 of file NetBuffer.c.

◆ NetbufQueRemove()

NET_BUF *EFIAPI NetbufQueRemove ( IN OUT NET_BUF_QUEUE NbufQue)

Remove a net buffer from the head in the specific queue and return it.

Parameters
[in,out]NbufQuePointer to the net buffer queue.
Returns
Pointer to the net buffer removed from the specific queue, or NULL if there is no net buffer in the specific queue.

Definition at line 1399 of file NetBuffer.c.

◆ NetbufQueTrim()

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.

Parameters
[in,out]NbufQuePointer to the net buffer queue.
[in]LenLength of the data to trim.
Returns
The actual length of the data trimmed.

Definition at line 1537 of file NetBuffer.c.

◆ NetbufReserve()

VOID EFIAPI NetbufReserve ( IN OUT NET_BUF Nbuf,
IN UINT32  Len 
)

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.

Parameters
[in,out]NbufPointer to the net buffer.
[in]LenThe length of buffer to be reserved from the header.

Definition at line 984 of file NetBuffer.c.

◆ NetbufSetBlock()

VOID NetbufSetBlock ( IN OUT NET_BUF Nbuf,
IN UINT8 *  Bulk,
IN UINT32  Len,
IN UINT32  Index 
)

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.

Parameters
[in,out]NbufPointer to the net buffer.
[in]BulkPointer to the data.
[in]LenLength of the bulk data.
[in]IndexThe data block index in the net buffer the bulk data should belong to.

Definition at line 410 of file NetBuffer.c.

◆ NetbufSetBlockOp()

VOID NetbufSetBlockOp ( IN OUT NET_BUF Nbuf,
IN UINT8 *  Bulk,
IN UINT32  Len,
IN UINT32  Index 
)

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.

Parameters
[in,out]NbufPointer to the net buffer.
[in]BulkPointer to the data.
[in]LenLength of the bulk data.
[in]IndexThe data block index in the net buffer the bulk data should belong to.

Definition at line 450 of file NetBuffer.c.

◆ NetbufTrim()

UINT32 EFIAPI NetbufTrim ( IN OUT NET_BUF Nbuf,
IN UINT32  Len,
IN BOOLEAN  FromHead 
)

Trim Len bytes from the header or tail of the net buffer.

Parameters
[in,out]NbufPointer to the net buffer.
[in]LenThe length of the data to be trimmed.
[in]FromHeadThe flag to indicate whether trim data from head (TRUE) or tail (FALSE).
Returns
Length of the actually trimmed data, which is possible to be less than Len because the TotalSize of Nbuf is less than Len.

Definition at line 1134 of file NetBuffer.c.

◆ NetIp6PseudoHeadChecksum()

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.

Parameters
[in]SrcThe source address of the packet.
[in]DstThe destination address of the packet.
[in]NextHeaderThe protocol type of the packet.
[in]LenThe length of the packet.
Returns
The computed checksum.

Definition at line 1777 of file NetBuffer.c.

◆ NetIpSecNetbufFree()

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.

Parameters
[in]NbufThe network buffer to be freed.

Definition at line 1812 of file NetBuffer.c.

◆ NetPseudoHeadChecksum()

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.

Parameters
[in]SrcThe source address of the packet.
[in]DstThe destination address of the packet.
[in]ProtoThe protocol type of the packet.
[in]LenThe length of the packet.
Returns
The computed checksum.

Definition at line 1740 of file NetBuffer.c.