CNDP  22.08.0
pktmbuf.h File Reference
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <bsd/string.h>
#include <cne_atomic.h>
#include <cne_common.h>
#include <cne_branch_prediction.h>
#include <cne_log.h>
#include <cne_mmap.h>
#include <cne_prefetch.h>
#include <mempool.h>
#include "pktmbuf_ops.h"
#include "pktmbuf_offload.h"

Go to the source code of this file.

Data Structures

struct  pktmbuf_info_s
 
struct  pktmbuf_s
 
struct  pktmbuf_pending
 

Macros

#define CNE_MBUF_DEFAULT_DATAROOM   (2 * 1024)
 
#define pktmbuf_hash(m)   ((m)->hash)
 
#define pktmbuf_pooldata(m)   ((m)->pooldata)
 
#define pktmbuf_buf_addr(m)   ((m)->buf_addr)
 
#define pktmbuf_port(m)   ((m)->lport)
 
#define pktmbuf_buf_len(m)   ((m)->buf_len)
 
#define pktmbuf_tx_offload(m)   ((m)->tx_offload)
 
#define pktmbuf_userptr(m)   ((m)->userptr)
 
#define pktmbuf_udata64(m)   ((m)->udata64)
 
#define pktmbuf_data_len(m)   ((m)->data_len)
 
#define pktmbuf_data_off(m)   ((m)->data_off)
 
#define pktmbuf_refcnt(m)   ((m)->refcnt)
 
#define pktmbuf_mtod_offset(m, t, o)   ((t)((char *)pktmbuf_buf_addr(m) + pktmbuf_data_off(m) + (o)))
 
#define pktmbuf_mtod(m, t)   pktmbuf_mtod_offset(m, t, 0)
 
#define pktmbuf_meta_index(m)   ((m)->meta_index)
 
#define __pktmbuf_sanity_check(m, is_h)   do { } while (0)
 
#define CNE_MBUF_PREFETCH_TO_FREE(m)
 
#define CNE_MBUF_INVALID_PORT   UINT16_MAX
 

Typedefs

typedef struct pktmbuf_info_s pktmbuf_info_t
 
typedef struct pktmbuf_pending pktmbuf_pending_t
 
typedef int(* pktmbuf_cb_t) (pktmbuf_info_t *pi, pktmbuf_t *buf, uint32_t sz, uint32_t idx, void *ud)
 

Enumerations

enum  {
  DEFAULT_BURST_SIZE = 64 , DEFAULT_MBUF_COUNT = (16 * 1024) , DEFAULT_MBUF_SIZE = 2048 , PKTMBUF_PENDING_SZ = 128 ,
  PKTMBUF_INFO_NAME_SZ = 24
}
 

Functions

CNDP_API void pktmbuf_destroy (pktmbuf_info_t *pi)
 
CNDP_API pktmbuf_info_tpktmbuf_pool_create (char *addr, uint32_t bufcnt, uint32_t bufsz, uint32_t cache_sz, mbuf_ops_t *ops)
 
CNDP_API pktmbuf_info_tpktmbuf_pool_cfg_create (const pktmbuf_pool_cfg_t *cfg)
 
CNDP_API int pktmbuf_iterate (pktmbuf_info_t *pi, pktmbuf_cb_t cb, void *ud)
 
static void pktmbuf_prefetch (pktmbuf_t *m)
 
static char * pktmbuf_data_addr_default (pktmbuf_t *mb)
 
static uint16_t pktmbuf_refcnt_read (const pktmbuf_t *m)
 
static void pktmbuf_refcnt_set (pktmbuf_t *m, uint16_t new_value)
 
static uint16_t pktmbuf_refcnt_update (pktmbuf_t *m, int16_t value)
 
CNDP_API void pktmbuf_sanity_check (const pktmbuf_t *m, int is_header)
 
CNDP_API int pktmbuf_check (const pktmbuf_t *m, int is_header, const char **reason)
 
static void pktmbuf_info_name_set (pktmbuf_info_t *pi, const char *str)
 
static const char * pktmbuf_info_name_get (pktmbuf_info_t *pi)
 
static void pktmbuf_reset_headroom (pktmbuf_t *m)
 
static void pktmbuf_reset (pktmbuf_t *m)
 
static int pktmbuf_alloc_bulk (pktmbuf_info_t *pi, pktmbuf_t **mbufs, unsigned count)
 
static pktmbuf_tpktmbuf_alloc (pktmbuf_info_t *pi)
 
static __cne_always_inline pktmbuf_tpktmbuf_refcnt_free (pktmbuf_t *m)
 
static __cne_always_inline void pktmbuf_free (pktmbuf_t *m)
 
static void pktmbuf_free_bulk (pktmbuf_t **mbufs, unsigned int count)
 
CNDP_API pktmbuf_tpktmbuf_copy (const pktmbuf_t *m, pktmbuf_info_t *pi, uint32_t offset, uint32_t length)
 
static uint16_t pktmbuf_headroom (const pktmbuf_t *m)
 
static uint16_t pktmbuf_tailroom (const pktmbuf_t *m)
 
static char * pktmbuf_mtod_last (const pktmbuf_t *m)
 
static char * pktmbuf_mtod_end (const pktmbuf_t *m)
 
static char * pktmbuf_prepend (pktmbuf_t *m, uint16_t len)
 
static char * pktmbuf_adj_offset (pktmbuf_t *m, int16_t len)
 
static char * pktmbuf_append (pktmbuf_t *m, uint16_t len)
 
static int pktmbuf_trim (pktmbuf_t *m, uint16_t len)
 
static const void * pktmbuf_read (const pktmbuf_t *m, uint32_t off, uint32_t len, void *buf)
 
static const void * pktmbuf_write (const void *buf, uint32_t len, pktmbuf_t *m, uint32_t off)
 
static uint16_t pktmbuf_data_room_size (mempool_t *mp)
 
CNDP_API pktmbuf_tpktmbuf_clone (pktmbuf_t *md, pktmbuf_info_t *pi)
 
CNDP_API void pktmbuf_dump (const char *msg, const pktmbuf_t *m, unsigned dump_len)
 
const char * cne_get_rx_ol_flag_name (uint64_t mask)
 
int cne_get_rx_ol_flag_list (uint64_t mask, char *buf, size_t buflen)
 
const char * cne_get_tx_ol_flag_name (uint64_t mask)
 
int cne_get_tx_ol_flag_list (uint64_t mask, char *buf, size_t buflen)
 
static void * pktmbuf_metadata (const pktmbuf_t *m)
 
static int32_t pktmbuf_metadata_bufsz (const pktmbuf_t *m)
 
CNDP_API int pktmbuf_pool_cfg (pktmbuf_pool_cfg_t *c, void *addr, uint32_t bufcnt, uint32_t bufsz, uint32_t cache_sz, void *metadata, uint32_t metadata_bufsz, mbuf_ops_t *ops)
 
CNDP_API void pktmbuf_info_dump (void)
 

Detailed Description

Pktmbuf

The mbuf library provides the ability to create and destroy buffers that may be used by the CNE application to store message buffers. The message buffers are stored in a mempool, using the CNE mempool library.

The preferred way to create a mbuf pool is to use pktmbuf_pool_create(). However, in some situations, an application may want to have more control (ex: populate the pool with specific memory), in this case it is possible to use functions from mempool. See how pktmbuf_pool_create() is implemented for details.

This library provides an API to allocate/free packet mbufs, which are used to carry network packets.

To understand the concepts of packet buffers or mbufs, you should read "TCP/IP Illustrated, Volume 2: The Implementation, Addison-Wesley, 1995, ISBN 0-201-63354-X from Richard Stevens" http://www.kohala.com/start/tcpipiv2.html

Definition in file pktmbuf.h.

Macro Definition Documentation

◆ CNE_MBUF_DEFAULT_DATAROOM

#define CNE_MBUF_DEFAULT_DATAROOM   (2 * 1024)

Some NICs need at least 2KB buffer to RX standard Ethernet frame without splitting it into multiple segments. So, for mbufs that planned to be involved in RX/TX, the recommended minimal buffer length is 2KB.

Definition at line 96 of file pktmbuf.h.

◆ pktmbuf_hash

#define pktmbuf_hash (   m)    ((m)->hash)

A macro to access the hash value in the mbuf

Parameters
mThe mbuf pointer.

Definition at line 306 of file pktmbuf.h.

◆ pktmbuf_pooldata

#define pktmbuf_pooldata (   m)    ((m)->pooldata)

A macro that returns the pool pointer.

Parameters
mThe packet mbuf.

Definition at line 314 of file pktmbuf.h.

◆ pktmbuf_buf_addr

#define pktmbuf_buf_addr (   m)    ((m)->buf_addr)

A macro that returns the buffer address

Parameters
mThe packet mbuf.

Definition at line 322 of file pktmbuf.h.

◆ pktmbuf_port

#define pktmbuf_port (   m)    ((m)->lport)

A macro that returns the lport number

Parameters
mThe packet mbuf.

Definition at line 330 of file pktmbuf.h.

◆ pktmbuf_buf_len

#define pktmbuf_buf_len (   m)    ((m)->buf_len)

A macro that returns the total buffer length

Parameters
mThe packet mbuf.

Definition at line 338 of file pktmbuf.h.

◆ pktmbuf_tx_offload

#define pktmbuf_tx_offload (   m)    ((m)->tx_offload)

A macro that returns the TX offload value

Parameters
mThe packet mbuf.

Definition at line 346 of file pktmbuf.h.

◆ pktmbuf_userptr

#define pktmbuf_userptr (   m)    ((m)->userptr)

A macro that returns the user pointer value, which is a union with udata64.

Parameters
mThe packet mbuf.

Definition at line 354 of file pktmbuf.h.

◆ pktmbuf_udata64

#define pktmbuf_udata64 (   m)    ((m)->udata64)

A macro that returns the udata64 value, which is a union with userptr.

Parameters
mThe packet mbuf.

Definition at line 362 of file pktmbuf.h.

◆ pktmbuf_data_len

#define pktmbuf_data_len (   m)    ((m)->data_len)

A macro that returns the length of the segment.

Parameters
mThe packet mbuf.
Examples
examples/cndpfwd/main.c, examples/cnet-graph/cnet-graph.c, and examples/cnet-quic/quic-cli.c.

Definition at line 370 of file pktmbuf.h.

◆ pktmbuf_data_off

#define pktmbuf_data_off (   m)    ((m)->data_off)

A macro that returns the data offset of the packet.

Parameters
mThe packet mbuf.

Definition at line 378 of file pktmbuf.h.

◆ pktmbuf_refcnt

#define pktmbuf_refcnt (   m)    ((m)->refcnt)

A macro that returns the refcnt non-atomic

Parameters
mThe packet mbuf.

Definition at line 386 of file pktmbuf.h.

◆ pktmbuf_mtod_offset

#define pktmbuf_mtod_offset (   m,
  t,
 
)    ((t)((char *)pktmbuf_buf_addr(m) + pktmbuf_data_off(m) + (o)))

A macro that points to an offset into the data in the mbuf.

The returned pointer is cast to type t. Before using this function, the user must ensure that the first segment is large enough to accommodate its data.

Parameters
mThe packet mbuf.
oThe offset into the mbuf data.
tThe type to cast the result into.
Examples
examples/cndpfwd/acl-func.c.

Definition at line 402 of file pktmbuf.h.

◆ pktmbuf_mtod

#define pktmbuf_mtod (   m,
 
)    pktmbuf_mtod_offset(m, t, 0)

A macro that points to the start of the data in the mbuf.

The returned pointer is cast to type t. Before using this function, the user must ensure that the segment is large enough to accommodate its data.

Parameters
mThe packet mbuf.
tThe type to cast the result into.
Examples
examples/cndpfwd/acl-func.c, examples/cndpfwd/main.c, examples/cnet-graph/cnet-graph.c, examples/cnet-quic/quic-cli.c, and examples/dlb_test/dlb_test.c.

Definition at line 416 of file pktmbuf.h.

◆ pktmbuf_meta_index

#define pktmbuf_meta_index (   m)    ((m)->meta_index)

Return the metadata index value from the pktmbuf header.

Parameters
mThe pktmbuf_t pointer.

Definition at line 424 of file pktmbuf.h.

◆ __pktmbuf_sanity_check

#define __pktmbuf_sanity_check (   m,
  is_h 
)    do { } while (0)

check mbuf type in debug mode

Definition at line 468 of file pktmbuf.h.

◆ CNE_MBUF_PREFETCH_TO_FREE

#define CNE_MBUF_PREFETCH_TO_FREE (   m)
Value:
do { \
if ((m) != NULL) \
cne_prefetch0(m); \
} while (0)

Mbuf prefetch

Definition at line 541 of file pktmbuf.h.

◆ CNE_MBUF_INVALID_PORT

#define CNE_MBUF_INVALID_PORT   UINT16_MAX

Reset the fields of a packet mbuf to their default values.

Parameters
mThe packet mbuf to be reset.

Definition at line 638 of file pktmbuf.h.

Typedef Documentation

◆ pktmbuf_info_t

Information structure for pktmbuf buffer and related information.

◆ pktmbuf_pending_t

Structure to help with bulk free of mbufs.

As the pktmbuf_free_bulk is called this structure holds all of the mbufs allocated from the same pool. When a different pool is found in the array of mbufs pointers they are freed and the set of mbufs to a given pool is created.

◆ pktmbuf_cb_t

typedef int(* pktmbuf_cb_t) (pktmbuf_info_t *pi, pktmbuf_t *buf, uint32_t sz, uint32_t idx, void *ud)

Object or pktmbuf callback routine to initialize the allocated pktmbuf_t structure.

Parameters
piThe pktmbuf_info_t pointer
bufThe buffer pointer to pktmbuf_t structure to initialize
szThe size of the buffer to use in initialing the buffer, if needed.
idxThe index of the pktmbuf structure
udUser data pointer supplied by the caller
Returns
0 on successfully initialized buffer or -1 on error

Definition at line 282 of file pktmbuf.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DEFAULT_BURST_SIZE 

Default burst size

DEFAULT_MBUF_COUNT 

Default mbuf count

DEFAULT_MBUF_SIZE 

Default mbuf size data + sizeof(pktmbuf_t) + extra

PKTMBUF_PENDING_SZ 

Size of the pending free mbuf pointers

PKTMBUF_INFO_NAME_SZ 

Size of the the info name

Definition at line 53 of file pktmbuf.h.

Function Documentation

◆ pktmbuf_destroy()

CNDP_API void pktmbuf_destroy ( pktmbuf_info_t pi)

Destroy the pktmbuf_info_t structure

Parameters
piFree the data and pktmbuf_info_t structure data.
Examples
examples/cndpfwd/main.c.

◆ pktmbuf_pool_create()

CNDP_API pktmbuf_info_t* pktmbuf_pool_create ( char *  addr,
uint32_t  bufcnt,
uint32_t  bufsz,
uint32_t  cache_sz,
mbuf_ops_t ops 
)

Create the pktmbuf_info_t structure with no external metadata information.

Parameters
addrThe starting address of the buffer space
bufcntNumber of buffers to create or allocate
bufszThe size of each buffer to be allocated
cache_szCache size for mempool or other user needs, can be zero for no cache.
opsPointer to mbuf_ops_t structure for mbuf operator function pointers. This structure is copied into the pktmbuf_info_t.ops structure and can be NULL.
Returns
NULL on error or a valid pktmbuf_info_t pointer.
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, and examples/l3fwd-graph/parse-args.c.

◆ pktmbuf_pool_cfg_create()

CNDP_API pktmbuf_info_t* pktmbuf_pool_cfg_create ( const pktmbuf_pool_cfg_t *  cfg)

Create the pktmbuf_info_t structure and setup some of the fields

Parameters
cfgPointer to a configuration structure. addr - The starting address of the buffer space bufcnt - Number of buffers to create or allocate, using the mtype for mmap_alloc() bufsz - The size of each buffer to be allocated cache_sz - Cache size for mempool or other user needs ops - Pointer to mbuf_ops_t structure for mbuf operator function pointers. This structure is copied into the pktmbuf_info_t.ops structure and can be NULL. metadata_bufsz - is the size of the external metadata buffers. metadata - is a pointer to the start of the metadata, can be NULL for no external metadata.
Returns
NULL on error or a valid pktmbuf_info_t pointer.

◆ pktmbuf_iterate()

CNDP_API int pktmbuf_iterate ( pktmbuf_info_t pi,
pktmbuf_cb_t  cb,
void *  ud 
)

Iterate over the set of buffers while calling the supplied callback function.

Parameters
piPointer to pktmbuf_info_t structure, returned from pktmbuf_pool_init().
cbThe callback routine to call to initialize the buffer. The callback uses the pktmbuf_cb_t prototype.
udThe user data pointer for the callback function
Returns
0 on successfully initializing the buffer or -1 on error

◆ pktmbuf_prefetch()

static void pktmbuf_prefetch ( pktmbuf_t m)
inlinestatic

Prefetch the first part of the mbuf

The first 64 bytes of the mbuf corresponds to fields that are used early in the receive path. If the cache line of the architecture is higher than 64B, the second part will also be prefetched.

Parameters
mThe pointer to the mbuf.

Definition at line 437 of file pktmbuf.h.

◆ pktmbuf_data_addr_default()

static char* pktmbuf_data_addr_default ( pktmbuf_t mb)
inlinestatic

Return the default address of the beginning of the mbuf data.

Parameters
mbThe pointer to the mbuf.
Returns
The pointer of the beginning of the mbuf data.

Definition at line 451 of file pktmbuf.h.

◆ pktmbuf_refcnt_read()

static uint16_t pktmbuf_refcnt_read ( const pktmbuf_t m)
inlinestatic

Reads the value of an mbuf's refcnt.

Parameters
mMbuf to read
Returns
Reference count number.

Definition at line 481 of file pktmbuf.h.

◆ pktmbuf_refcnt_set()

static void pktmbuf_refcnt_set ( pktmbuf_t m,
uint16_t  new_value 
)
inlinestatic

Sets an mbuf's refcnt to a defined value.

Parameters
mMbuf to update
new_valueValue set

Definition at line 494 of file pktmbuf.h.

◆ pktmbuf_refcnt_update()

static uint16_t pktmbuf_refcnt_update ( pktmbuf_t m,
int16_t  value 
)
inlinestatic

Adds given value to an mbuf's refcnt and returns its new value.

Parameters
mMbuf to update
valueValue to add/subtract
Returns
Updated value

Definition at line 516 of file pktmbuf.h.

◆ pktmbuf_sanity_check()

CNDP_API void pktmbuf_sanity_check ( const pktmbuf_t m,
int  is_header 
)

Sanity checks on an mbuf.

Check the consistency of the given mbuf. The function will cause a panic if corruption is detected.

Parameters
mThe mbuf to be checked.
is_headerTrue if the mbuf is a packet header, false if it is a sub-segment of a packet (in this case, some fields like nb_segs are not checked)

◆ pktmbuf_check()

CNDP_API int pktmbuf_check ( const pktmbuf_t m,
int  is_header,
const char **  reason 
)

Sanity checks on a mbuf.

Almost like pktmbuf_sanity_check(), but this function gives the reason if corruption is detected rather than panic.

Parameters
mThe mbuf to be checked.
is_headerTrue if the mbuf is a packet header, false if it is a sub-segment of a packet (in this case, some fields like nb_segs are not checked)
reasonA reference to a string pointer where to store the reason why a mbuf is considered invalid.
Returns
  • 0 if no issue has been found, reason is left untouched.
  • -1 if a problem is detected, reason then points to a string describing the reason why the mbuf is deemed invalid.

◆ pktmbuf_info_name_set()

static void pktmbuf_info_name_set ( pktmbuf_info_t pi,
const char *  str 
)
inlinestatic

Set the pktmbuf_info_t.name field with given string, does not need to be unique.

The string passed will be copied into the field. If pi is NULL return without setting the name field.

Parameters
piThe pktmbuf_info_t pointer to set the name field.
strThe string to copy into the name field, can be NULL and the string will cleared.
Returns
N/A
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, and examples/l3fwd-graph/parse-args.c.

Definition at line 596 of file pktmbuf.h.

◆ pktmbuf_info_name_get()

static const char* pktmbuf_info_name_get ( pktmbuf_info_t pi)
inlinestatic

Get the pktmbuf_info_t.name field.

Parameters
piThe pktmbuf_info_t pointer to set the name field.
Returns
NULL if pi is NULL or pointer to pktmbuf_info_t.name field which could be empty.

Definition at line 615 of file pktmbuf.h.

◆ pktmbuf_reset_headroom()

static void pktmbuf_reset_headroom ( pktmbuf_t m)
inlinestatic

Reset the data_off field of a packet mbuf to its default value.

Parameters
mThe packet mbuf's data_off field has to be reset.

Definition at line 627 of file pktmbuf.h.

◆ pktmbuf_reset()

static void pktmbuf_reset ( pktmbuf_t m)
inlinestatic

Reset a mbuf internal fields to valid known states.

Definition at line 644 of file pktmbuf.h.

◆ pktmbuf_alloc_bulk()

static int pktmbuf_alloc_bulk ( pktmbuf_info_t pi,
pktmbuf_t **  mbufs,
unsigned  count 
)
inlinestatic

Allocate a bulk of mbufs, initialize refcnt and reset the fields to default values.

Parameters
piThe mempool from which mbufs are allocated.
mbufsArray of pointers to mbufs
countArray size
Returns
number of mbufs allocated or 0 if not able to allocate request number of mbufs
Examples
examples/cndpfwd/main.c.

Definition at line 670 of file pktmbuf.h.

◆ pktmbuf_alloc()

static pktmbuf_t* pktmbuf_alloc ( pktmbuf_info_t pi)
inlinestatic

Allocate a new mbuf from a mempool.

This new mbuf, which has a length of 0. The pointer to data is initialized to have some bytes of headroom in the buffer (if buffer size allows).

Parameters
piThe mempool from which the mbuf is allocated.
Returns
  • The pointer to the new mbuf on success.
  • NULL if allocation failed.

Definition at line 689 of file pktmbuf.h.

◆ pktmbuf_refcnt_free()

static __cne_always_inline pktmbuf_t* pktmbuf_refcnt_free ( pktmbuf_t m)
static

Decrease reference counter of an mbuf

This function does the same thing as a free. It decreases the reference counter, and if it reaches 0 it is freed.

Parameters
mThe mbuf to be unlinked
Returns
  • (m) if it is the last reference. It can be recycled or freed.
  • (NULL) if the mbuf still has remaining references on it.

Definition at line 721 of file pktmbuf.h.

◆ pktmbuf_free()

static __cne_always_inline void pktmbuf_free ( pktmbuf_t m)
static

Free a packet mbuf back into its original pool.

Parameters
mThe packet mbuf to be freed. If NULL, the function does nothing.
Examples
examples/cndpfwd/acl-func.c.

Definition at line 741 of file pktmbuf.h.

◆ pktmbuf_free_bulk()

static void pktmbuf_free_bulk ( pktmbuf_t **  mbufs,
unsigned int  count 
)
inlinestatic

Free a bulk of packet mbufs back into their original pools.

Parameters
mbufsArray of pointers to packet mbufs. The array may contain NULL pointers.
countArray size.
Examples
examples/cndpfwd/main.c, examples/cnet-graph/cnet-graph.c, and examples/cnet-quic/quic-cli.c.

Definition at line 801 of file pktmbuf.h.

◆ pktmbuf_copy()

CNDP_API pktmbuf_t* pktmbuf_copy ( const pktmbuf_t m,
pktmbuf_info_t pi,
uint32_t  offset,
uint32_t  length 
)

Create a full copy of a given packet mbuf.

Copies all the data from a given packet mbuf to a newly allocated set of mbufs. The private data are is not copied.

Parameters
mThe packet mbuf to be copiedd.
piThe pktmbuf_info_t from which the "clone" mbufs are allocated.
offsetThe number of bytes to skip before copying. If the mbuf does not have that many bytes, it is an error and NULL is returned.
lengthThe upper limit on bytes to copy. Passing UINT32_MAX means all data (after offset).
Returns
  • The pointer to the new "clone" mbuf on success.
  • NULL if allocation fails.

◆ pktmbuf_headroom()

static uint16_t pktmbuf_headroom ( const pktmbuf_t m)
inlinestatic

Get the headroom in a packet mbuf.

Parameters
mThe packet mbuf.
Returns
The length of the headroom.

Definition at line 853 of file pktmbuf.h.

◆ pktmbuf_tailroom()

static uint16_t pktmbuf_tailroom ( const pktmbuf_t m)
inlinestatic

Get the tailroom of a packet mbuf.

Parameters
mThe packet mbuf.
Returns
The length of the tailroom.

Definition at line 868 of file pktmbuf.h.

◆ pktmbuf_mtod_last()

static char* pktmbuf_mtod_last ( const pktmbuf_t m)
inlinestatic

Return pointer to the end or last of the packet data in the mbuf.

Note: The pointer returned is just past the last byte of the data.

Parameters
mPointer to mbuf to get the end of the packet
Returns
Pointer to the end of the packet data.

Definition at line 885 of file pktmbuf.h.

◆ pktmbuf_mtod_end()

static char* pktmbuf_mtod_end ( const pktmbuf_t m)
inlinestatic

Return pointer to the end of the mbuf buffer

Note: The pointer returned is just past the last byte of the buffer.

Parameters
mPointer to mbuf to use in finding the end of the buffer
Returns
Pointer to the end of the mbuf buffer.

Definition at line 902 of file pktmbuf.h.

◆ pktmbuf_prepend()

static char* pktmbuf_prepend ( pktmbuf_t m,
uint16_t  len 
)
inlinestatic

Prepend len bytes to an mbuf data area.

Returns a pointer to the new data start address. If there is not enough headroom in the mbuf, the function will return NULL, without modifying the mbuf.

Parameters
mThe pkt mbuf.
lenThe amount of data to prepend (in bytes).
Returns
A pointer to the start of the newly prepended data, or NULL if there is not enough headroom space in the first segment

Definition at line 924 of file pktmbuf.h.

◆ pktmbuf_adj_offset()

static char* pktmbuf_adj_offset ( pktmbuf_t m,
int16_t  len 
)
inlinestatic

Remove len bytes of an mbuf, by increasing mbuf.data_off value

Returns a pointer to the new data start address. If the request length to move the data_off exceeds the mbuf len then return NULL or return the new start address.

Parameters
mThe pkt mbuf.
lenThe amount of data to remove/added in bytes from the start of the mbuf.
Returns
A pointer to the new offset into the mbuf where the data begins.

Definition at line 955 of file pktmbuf.h.

◆ pktmbuf_append()

static char* pktmbuf_append ( pktmbuf_t m,
uint16_t  len 
)
inlinestatic

Append len bytes to an mbuf.

Append len bytes to an mbuf and return a pointer to the start address of the added data.

Parameters
mThe packet mbuf.
lenThe amount of data to append (in bytes).
Returns
A pointer to the start of the newly appended data, or NULL if there is not enough tailroom space in the last segment

Definition at line 1002 of file pktmbuf.h.

◆ pktmbuf_trim()

static int pktmbuf_trim ( pktmbuf_t m,
uint16_t  len 
)
inlinestatic

Remove len bytes of data at the end of the mbuf.

If the length is greater than the length of the segment, the function will fail and return -1 without modifying the mbuf.

Parameters
mThe packet mbuf.
lenThe amount of data to remove (in bytes).
Returns
  • 0: On success.
  • -1: On error.

Definition at line 1031 of file pktmbuf.h.

◆ pktmbuf_read()

static const void* pktmbuf_read ( const pktmbuf_t m,
uint32_t  off,
uint32_t  len,
void *  buf 
)
inlinestatic

Read len data bytes in a mbuf at specified offset.

Copy the data in the buffer provided by the user and return its pointer.

Parameters
mThe pointer to the mbuf.
offThe offset of the data in the mbuf.
lenThe amount of bytes to read.
bufThe buffer where data is copied in mbuf data. Its length should be at least equal to the len parameter.
Returns
The pointer to the data or in the user buffer. If mbuf is too small, NULL is returned.

Definition at line 1066 of file pktmbuf.h.

◆ pktmbuf_write()

static const void* pktmbuf_write ( const void *  buf,
uint32_t  len,
pktmbuf_t m,
uint32_t  off 
)
inlinestatic

Write len data bytes into the mbuf at specified offset.

Copy the data in the buffer provided by the user into the mbuf.

Parameters
bufThe buffer where data is copied to in mbuf buffer. Its length should be at least equal to the len parameter.
lenThe amount of bytes to write from buffer to mbuf.
mThe pointer to the mbuf.
offThe offset of the data in the mbuf.
Returns
The pointer to the data or in the user buffer. If mbuf is too small, NULL is returned.
Examples
examples/cnet-quic/quic-cli.c.

Definition at line 1097 of file pktmbuf.h.

◆ pktmbuf_data_room_size()

static uint16_t pktmbuf_data_room_size ( mempool_t mp)
inlinestatic

Amount of total data space available for packet data.

This value is the max space available for packet data in a pktmbuf_t, which means the value for a 2K buffer would be (2K - sizeof(pktmbuf_t)).

Parameters
mpThe mempool pointer to get the element size.
Returns
The total amount of space available for packet data in a pktmbuf_t.

Definition at line 1117 of file pktmbuf.h.

◆ pktmbuf_clone()

CNDP_API pktmbuf_t* pktmbuf_clone ( pktmbuf_t md,
pktmbuf_info_t pi 
)

Clone a pktmbuf from a given pool.

Parameters
mdThe mbuf to clone
piThe pktmbuf_info pointer to allocate the new mbuf from.
Returns
NULL on error or the new cloned mbuf pointer.

◆ pktmbuf_dump()

CNDP_API void pktmbuf_dump ( const char *  msg,
const pktmbuf_t m,
unsigned  dump_len 
)

Dump an mbuf structure to a file.

Dump all fields for the given packet mbuf and all its associated segments (in the case of a chained buffer).

Parameters
msgTitle message, can be NULL
mThe packet mbuf.
dump_lenIf dump_len != 0, also dump the "dump_len" first data bytes of the packet.

◆ cne_get_rx_ol_flag_name()

const char* cne_get_rx_ol_flag_name ( uint64_t  mask)

Get the name of a RX offload flag

Parameters
maskThe mask describing the flag.
Returns
The name of this flag, or NULL if it's not a valid RX flag.

◆ cne_get_rx_ol_flag_list()

int cne_get_rx_ol_flag_list ( uint64_t  mask,
char *  buf,
size_t  buflen 
)

Dump the list of RX offload flags in a buffer

Parameters
maskThe mask describing the RX flags.
bufThe output buffer.
buflenThe length of the buffer.
Returns
0 on success, (-1) on error.

◆ cne_get_tx_ol_flag_name()

const char* cne_get_tx_ol_flag_name ( uint64_t  mask)

Get the name of a TX offload flag

Parameters
maskThe mask describing the flag. Usually only one bit must be set. Several bits can be given if they belong to the same mask. Ex: PKT_TX_L4_MASK.
Returns
The name of this flag, or NULL if it's not a valid TX flag.

◆ cne_get_tx_ol_flag_list()

int cne_get_tx_ol_flag_list ( uint64_t  mask,
char *  buf,
size_t  buflen 
)

Dump the list of TX offload flags in a buffer

Parameters
maskThe mask describing the TX flags.
bufThe output buffer.
buflenThe length of the buffer.
Returns
0 on success, (-1) on error.

◆ pktmbuf_metadata()

static void* pktmbuf_metadata ( const pktmbuf_t m)
inlinestatic

Return the metadata buffer address

Parameters
mThe pktmbuf_t structure pointer
Returns
NULL on error or pointer to metadata buffer
Examples
examples/cnet-quic/quic-cli.c.

Definition at line 1209 of file pktmbuf.h.

◆ pktmbuf_metadata_bufsz()

static int32_t pktmbuf_metadata_bufsz ( const pktmbuf_t m)
inlinestatic

Return the size of the metadata buffer if external or headroom size if internal buffer.

Parameters
mThe pktmbuf_t structure pointer
Returns
-1 if pktmbuf pointer is NULL or size of metadata buffer or headroom size if internal.

Definition at line 1231 of file pktmbuf.h.

◆ pktmbuf_pool_cfg()

CNDP_API int pktmbuf_pool_cfg ( pktmbuf_pool_cfg_t *  c,
void *  addr,
uint32_t  bufcnt,
uint32_t  bufsz,
uint32_t  cache_sz,
void *  metadata,
uint32_t  metadata_bufsz,
mbuf_ops_t ops 
)

Construct a pktmbuf_pool_cfg_t structure with the given parameters.

Parameters
cPointer to the pktmbuf_pool_cfg_t structure
addrAddress of the pktmbuf buffers, must not be NULL
bufcntNumber of buffers in the pktmbuf pool, can be zero to use default
bufszSize of each buffer in the pktmbuf pool, can be zero to use default
cache_szCache size of the mempool to use in allocate/free buffers, can be zero
metadataThe pointer of the metadata buffer pool, can be NULL.
metadata_bufszThe size of each metadata buffer in the pool, if metadata is valid can not be zero and needs to be a multiple of a cacheline.
opsThe pktmbuf ops structure pointer, can be NULL.
Returns
0 on success or -1 on error.

◆ pktmbuf_info_dump()

CNDP_API void pktmbuf_info_dump ( void  )

Dump out the list of pktmbuf_info_t structures

Returns
N/A