rte_mbuf.h(3)
๐ฆ rte_mbuf.h(3) โ the DPDK mbuf page, bestie edition ๐ฆ
okay so this is the rte_mbuf.h(3) page from DPDK, and it is a lot, but we're gonna get through it together. this is part 1 of 6, so hydrate ๐
โจ NAME โจ
rte_mbuf.h โ like, the whole mbuf header. that's the name. she's self-titled, main character energy ๐
๐ SYNOPSIS ๐
first up, the includes โ this header pulls in its whole friend group:
#include <stdbool.h>
#include <stdint.h>
#include <rte_common.h>
#include <rte_config.h>
#include <rte_mempool.h>
#include <rte_prefetch.h>
#include <rte_branch_prediction.h>
#include <rte_mbuf_ptype.h>
#include <rte_mbuf_core.h>
#include <rte_mbuf_history.h>
๐ธ Data Structures ๐ธ
two structs living their best lives in here:
struct rte_pktmbuf_pool_privatestruct rte_pktmbuf_extmem
๐ Macros ๐
the macros, and yes there are a few that are literally just "do the thing you'd think":
RTE_PKTMBUF_POOL_F_PINNED_EXT_BUFโ a flag, defined as(1 << 0). baby's first bit.RTE_MBUF_HAS_PINNED_EXTBUFโ checks if the pool's priv flags have the pinned ext buf bit:
#define RTE_MBUF_HAS_PINNED_EXTBUF(mb) (rte_pktmbuf_priv_flags(mb->pool) & \
RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF)
__rte_mbuf_raw_sanity_check_mpโ just forwards torte_mbuf_raw_sanity_check(m, mp):
#define __rte_mbuf_raw_sanity_check_mp(m, mp) rte_mbuf_raw_sanity_check(m, mp)
__rte_mbuf_sanity_checkโ forwards torte_mbuf_sanity_check(m, is_h):
#define __rte_mbuf_sanity_check(m, is_h) rte_mbuf_sanity_check(m, is_h)
RTE_MBUF_PREFETCH_TO_FREEโ defined with no body at all, like:
#define RTE_MBUF_PREFETCH_TO_FREE(m)
__rte_mbuf_raw_sanity_checkโ calls__rte_mbuf_raw_sanity_check_mp(m, NULL):
#define __rte_mbuf_raw_sanity_check(m) __rte_mbuf_raw_sanity_check_mp(m, NULL)
MBUF_RAW_ALLOC_CHECKโ same deal,__rte_mbuf_raw_sanity_check_mp(m, NULL):
#define MBUF_RAW_ALLOC_CHECK(m) __rte_mbuf_raw_sanity_check_mp(m, NULL)
rte_pktmbuf_detach_extbufโ and this one is literally justrte_pktmbuf_detach(m):
#define rte_pktmbuf_detach_extbuf(m) rte_pktmbuf_detach(m)
rte_pktmbuf_pkt_lenโ grabs((m)->pkt_len)directly, no thoughts, head empty:
#define rte_pktmbuf_pkt_len(m) ((m)->pkt_len)
rte_pktmbuf_data_lenโ same vibe,((m)->data_len):
#define rte_pktmbuf_data_len(m) ((m)->data_len)
๐ง Functions ๐ง
okay brace yourself, this is the whole roster, in order, no skipping (i promised) ๐ซถ
const char * rte_get_rx_ol_flag_name (uint64_t mask)int rte_get_rx_ol_flag_list (uint64_t mask, char *buf, size_t buflen)const char * rte_get_tx_ol_flag_name (uint64_t mask)int rte_get_tx_ol_flag_list (uint64_t mask, char *buf, size_t buflen)static void rte_mbuf_prefetch_part1 (struct rte_mbuf *m)static void rte_mbuf_prefetch_part2 (struct rte_mbuf *m)static uint16_t rte_pktmbuf_priv_size (struct rte_mempool *mp)static rte_iova_t rte_mbuf_iova_get (const struct rte_mbuf *m)static void rte_mbuf_iova_set (struct rte_mbuf *m, rte_iova_t iova)static rte_iova_t rte_mbuf_data_iova (const struct rte_mbuf *mb)static rte_iova_t rte_mbuf_data_iova_default (const struct rte_mbuf *mb)static struct rte_mbuf * rte_mbuf_from_indirect (struct rte_mbuf *mi)static char * rte_mbuf_buf_addr (struct rte_mbuf *mb, struct rte_mempool *mp)static char * rte_mbuf_data_addr_default (struct rte_mbuf *mb)static char * rte_mbuf_to_baddr (struct rte_mbuf *md)static void * rte_mbuf_to_priv (struct rte_mbuf *m)static uint32_t rte_pktmbuf_priv_flags (struct rte_mempool *mp)static uint16_t rte_mbuf_refcnt_update (struct rte_mbuf *m, int16_t value)static uint16_t rte_mbuf_refcnt_read (const struct rte_mbuf *m)static void rte_mbuf_refcnt_set (struct rte_mbuf *m, uint16_t new_value)static uint16_t rte_mbuf_ext_refcnt_read (const struct rte_mbuf_ext_shared_info *shinfo)static void rte_mbuf_ext_refcnt_set (struct rte_mbuf_ext_shared_info *shinfo, uint16_t new_value)static uint16_t rte_mbuf_ext_refcnt_update (struct rte_mbuf_ext_shared_info *shinfo, int16_t value)void rte_mbuf_raw_sanity_check (const struct rte_mbuf *m, const struct rte_mempool *mp)int rte_mbuf_raw_check (const struct rte_mbuf *m, const struct rte_mempool *mp, const char **reason)void rte_mbuf_sanity_check (const struct rte_mbuf *m, int is_header)int rte_mbuf_check (const struct rte_mbuf *m, int is_header, const char **reason)static struct rte_mbuf * rte_mbuf_raw_alloc (struct rte_mempool *mp)static __rte_always_inline int rte_mbuf_raw_alloc_bulk (struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)static __rte_always_inline void rte_mbuf_raw_free (struct rte_mbuf *m)static __rte_always_inline void rte_mbuf_raw_free_bulk (struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)void rte_pktmbuf_init (struct rte_mempool *mp, void *opaque_arg, void *m, unsigned i)void rte_pktmbuf_pool_init (struct rte_mempool *mp, void *opaque_arg)struct rte_mempool * rte_pktmbuf_pool_create (const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id)struct rte_mempool * rte_pktmbuf_pool_create_by_ops (const char *name, unsigned int n, unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id, const char *ops_name)struct rte_mempool * rte_pktmbuf_pool_create_extbuf (const char *name, unsigned int n, unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id, const struct rte_pktmbuf_extmem *ext_mem, unsigned int ext_num)static uint16_t rte_pktmbuf_data_room_size (struct rte_mempool *mp)static void rte_pktmbuf_reset_headroom (struct rte_mbuf *m)static void rte_mbuf_raw_reset_bulk (struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)static void rte_pktmbuf_reset (struct rte_mbuf *m)static struct rte_mbuf * rte_pktmbuf_alloc (struct rte_mempool *mp)static int rte_pktmbuf_alloc_bulk (struct rte_mempool *pool, struct rte_mbuf **mbufs, unsigned count)static struct rte_mbuf_ext_shared_info * rte_pktmbuf_ext_shinfo_init_helper (void *buf_addr, uint16_t *buf_len, rte_mbuf_extbuf_free_callback_t free_cb, void *fcb_opaque)static void rte_pktmbuf_attach_extbuf (struct rte_mbuf *m, void *buf_addr, rte_iova_t buf_iova, uint16_t buf_len, struct rte_mbuf_ext_shared_info *shinfo)static void rte_mbuf_dynfield_copy (struct rte_mbuf *mdst, const struct rte_mbuf *msrc)static void rte_pktmbuf_attach (struct rte_mbuf *mi, struct rte_mbuf *m)static void rte_pktmbuf_detach (struct rte_mbuf *m)static __rte_always_inline struct rte_mbuf * rte_pktmbuf_prefree_seg (struct rte_mbuf *m)static __rte_always_inline void rte_pktmbuf_free_seg (struct rte_mbuf *m)static void rte_pktmbuf_free (struct rte_mbuf *m)void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs, unsigned int count)struct rte_mbuf * rte_pktmbuf_clone (struct rte_mbuf *md, struct rte_mempool *mp)struct rte_mbuf * rte_pktmbuf_copy (const struct rte_mbuf *m, struct rte_mempool *mp, uint32_t offset, uint32_t length)static void rte_pktmbuf_refcnt_update (struct rte_mbuf *m, int16_t v)static uint16_t rte_pktmbuf_headroom (const struct rte_mbuf *m)static uint16_t rte_pktmbuf_tailroom (const struct rte_mbuf *m)static struct rte_mbuf * rte_pktmbuf_lastseg (struct rte_mbuf *m)static char * rte_pktmbuf_prepend (struct rte_mbuf *m, uint16_t len)static char * rte_pktmbuf_append (struct rte_mbuf *m, uint16_t len)static char * rte_pktmbuf_adj (struct rte_mbuf *m, uint16_t len)static int rte_pktmbuf_trim (struct rte_mbuf *m, uint16_t len)static int rte_pktmbuf_is_contiguous (const struct rte_mbuf *m)static const void * rte_pktmbuf_read (const struct rte_mbuf *m, uint32_t off, uint32_t len, void *buf)static int rte_pktmbuf_chain (struct rte_mbuf *head, struct rte_mbuf *tail)static __rte_always_inline uint64_t rte_mbuf_tx_offload (uint64_t il2, uint64_t il3, uint64_t il4, uint64_t tso, uint64_t ol3, uint64_t ol2, uint64_t unused)static int rte_validate_tx_offload (const struct rte_mbuf *m)static int rte_pktmbuf_linearize (struct rte_mbuf *mbuf)void rte_pktmbuf_dump (FILE *f, const struct rte_mbuf *m, unsigned dump_len)static uint32_t rte_mbuf_sched_queue_get (const struct rte_mbuf *m)static uint8_t rte_mbuf_sched_traffic_class_get (const struct rte_mbuf *m)static uint8_t rte_mbuf_sched_color_get (const struct rte_mbuf *m)static void rte_mbuf_sched_get (const struct rte_mbuf *m, uint32_t *queue_id, uint8_t *traffic_class, uint8_t *color)static void rte_mbuf_sched_queue_set (struct rte_mbuf *m, uint32_t queue_id)static void rte_mbuf_sched_traffic_class_set (struct rte_mbuf *m, uint8_t traffic_class)static void rte_mbuf_sched_color_set (struct rte_mbuf *m, uint8_t color)static void rte_mbuf_sched_set (struct rte_mbuf *m, uint32_t queue_id, uint8_t traffic_class, uint8_t color)
likeโฆ that's 76 functions. she's thorough. we respect it ๐
๐ Detailed Description ๐
RTE Mbuf โ that's the title, capital letters and all.
okay so the mbuf library gives you the ability to create and destroy buffers that your RTE application can use to store message buffers. those message buffers live in a mempool, and it's the RTE mempool library doing the hosting ๐ซถ
the preferred way to create an mbuf pool is to use rte_pktmbuf_pool_create(). but โ and this is the important bit โ sometimes your app wants more control (their example is literally "populate the pool with specific memory"), and in that case you can absolutely just use functions from rte_mempool. go look at how rte_pktmbuf_pool_create() is implemented if you want the deets ๐
this library also gives you an API to allocate/free packet mbufs, which are the things that carry network packets. that's the whole job, she's a courier ๐
and if you actually want to understand packet buffers / mbufs conceptually, the page says you should read 'TCP/IP Illustrated, Volume 2: The Implementation, Addison-Wesley, 1995, ISBN 0-201-63354-X from Richard Stevens' โ link: http://www.kohala.com/start/tcpipiv2.html. not me dropping required reading in a manpage ๐ญ but ok, slay, learn the lore.
Definition in file rte_mbuf.h.
that's the synopsis + description wrapped up, bestie โ the actual per-function lore is coming in the next parts, so don't go anywhere ๐ธ๐
๐ Macro Definition Documentation ๐
#define RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF (1 << 0)
Okay so when this flag is set, the pktmbuf mempool is gonna hold only mbufs with a pinned external buffer. The external buffer gets attached to the mbuf right at the memory pool creation, and it will never be detached by the mbuf free calls. Also important: the mbuf should not contain any room for data after the mbuf structure. ๐
Definition at line 330 of file rte_mbuf.h.
#define RTE_MBUF_HAS_PINNED_EXTBUF(mb)
(rte_pktmbuf_priv_flags(mb->pool) &
RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF)
Returns non-zero if the given mbuf has a pinned external buffer, or zero otherwise. The pinned external buffer is allocated at pool creation time and should not be freed when the mbuf is freed, no cap.
Just so we're clear: an external buffer here is a user-provided anonymous buffer. ๐ซถ
Definition at line 339 of file rte_mbuf.h.
#define __rte_mbuf_raw_sanity_check_mp(m, mp) rte_mbuf_raw_sanity_check(m, mp)
Checks the reinitialized mbuf type when you're in debug mode. โจ
Definition at line 345 of file rte_mbuf.h.
#define __rte_mbuf_sanity_check(m, is_h) rte_mbuf_sanity_check(m, is_h)
Checks the mbuf type in debug mode.
Definition at line 347 of file rte_mbuf.h.
#define RTE_MBUF_PREFETCH_TO_FREE(m)
The value is literally:
do { if ((m) != NULL) rte_prefetch0(m); } while (0)
Mbuf prefetch. That's it, that's the whole vibe. ๐
Definition at line 514 of file rte_mbuf.h.
#define __rte_mbuf_raw_sanity_check(m) __rte_mbuf_raw_sanity_check_mp(m, NULL)
It's here for backwards compatibility. Yeah, we keep the old ones around. ๐
Definition at line 598 of file rte_mbuf.h.
#define MBUF_RAW_ALLOC_CHECK(m) __rte_mbuf_raw_sanity_check_mp(m, NULL)
Also for backwards compatibility. Twins, honestly.
Definition at line 601 of file rte_mbuf.h.
#define rte_pktmbuf_detach_extbuf(m) rte_pktmbuf_detach(m)
Detaches the external buffer attached to an mbuf โ it's the same thing as rte_pktmbuf_detach(), so don't overthink it bestie.
Parameters
mโ the mbuf that has the external buffer.
Definition at line 1225 of file rte_mbuf.h.
#define rte_pktmbuf_pkt_len(m) ((m)->pkt_len)
A macro that returns the length of the packet. ๐ซ
And the cute part? The value can be read or assigned. Not just a read-only icon, she's flexible.
Parameters
mโ the packet mbuf.
Definition at line 1660 of file rte_mbuf.h.
#define rte_pktmbuf_data_len(m) ((m)->data_len)
A macro that returns the length of the segment.
Value can be read or assigned, same deal as above. ๐ธ
Parameters
mโ the packet mbuf.
Definition at line 1670 of file rte_mbuf.h.
โจ Function Documentation โจ
const char* rte_get_rx_ol_flag_name (uint64_t mask)
Gets the name of a RX offload flag. Like, the actual human-readable name of the thing. ๐ท๏ธ
Parameters
maskโ the mask describing the flag.
Returns
The name of this flag, or NULL if it's not a valid RX flag. So if you get NULL back, that flag is not invited to the party. ๐
int rte_get_rx_ol_flag_list (uint64_t mask, char * buf, size_t buflen)
Dumps the whole list of RX offload flags into a buffer. โจ
Parameters
maskโ the mask describing the RX flags.bufโ the output buffer.buflenโ the length of the buffer.
Returns
0 on success, (-1) on error.
const char* rte_get_tx_ol_flag_name (uint64_t mask)
Gets the name of a TX offload flag.
Parameters
maskโ the mask describing the flag. Usually only one bit must be set. Several bits can be given if they belong to the same mask. For example:RTE_MBUF_F_TX_L4_MASK. ๐
Returns
The name of this flag, or NULL if it's not a valid TX flag.
int rte_get_tx_ol_flag_list (uint64_t mask, char * buf, size_t buflen)
Dumps the list of TX offload flags into a buffer. ๐ฆ
Parameters
maskโ the mask describing the TX flags.bufโ the output buffer.buflenโ the length of the buffer.
Returns
0 on success, (-1) on error.
static void rte_mbuf_prefetch_part1 (struct rte_mbuf * m) [inline], [static]
Prefetches the first part of the mbuf. ๐จ
The first 64 bytes of the mbuf correspond to the fields that get used early in the receive path. And here's the cute detail: if the cache line of the architecture is higher than 64B, the second part gets prefetched too. Overachiever behavior, honestly.
Parameters
mโ the pointer to the mbuf.
Definition at line 111 of file rte_mbuf.h.
static void rte_mbuf_prefetch_part2 (struct rte_mbuf * m) [inline], [static]
Prefetches the second part of the mbuf. โจ
The next 64 bytes of the mbuf correspond to the fields that get used in the transmit path. But if the cache line of the architecture is higher than 64B, this function literally does nothing โ because the expectation is that the full mbuf is already in cache. She's not doing unnecessary work. Main character energy. ๐
Parameters
mโ the pointer to the mbuf.
Definition at line 128 of file rte_mbuf.h.
static uint16_t rte_pktmbuf_priv_size (struct rte_mempool * mp) [inline], [static]
Gets the application private size of mbufs stored in a pktmbuf_pool.
And what even is the private size? It's a zone sitting between the rte_mbuf structure and the data buffer, where an application can stash data associated with a packet. Little secret compartment. ๐
Parameters
mpโ the packet mbuf pool.
Returns
The private size of mbufs stored in this mempool.
Definition at line 941 of file rte_mbuf.h.
static rte_iova_t rte_mbuf_iova_get (const struct rte_mbuf * m) [inline], [static]
Gets the IOVA address of the mbuf data buffer. ๐ฆ
Parameters
mโ the pointer to the mbuf.
Returns
The IOVA address of the mbuf.
Definition at line 149 of file rte_mbuf.h.
static void rte_mbuf_iova_set (struct rte_mbuf * m, rte_iova_t iova) [inline], [static]
Sets the IOVA address of the mbuf data buffer. ๐ซถ
Parameters
mโ the pointer to the mbuf.iovaโ value to set as IOVA address of the mbuf.
Definition at line 167 of file rte_mbuf.h.
static rte_iova_t rte_mbuf_data_iova (const struct rte_mbuf * mb) [inline], [static]
Returns the IO address of the beginning of the mbuf data.
Parameters
mbโ the pointer to the mbuf.
Returns
The IO address of the beginning of the mbuf data.
Definition at line 186 of file rte_mbuf.h.
static rte_iova_t rte_mbuf_data_iova_default (const struct rte_mbuf * mb) [inline], [static]
Returns the default IO address of the beginning of the mbuf data. โจ
This one gets used by drivers in their receive function, because it returns the location where data should be written by the NIC โ and it takes the default headroom into account. Considerate king. ๐
Parameters
mbโ the pointer to the mbuf.
Returns
The IO address of the beginning of the mbuf data.
Definition at line 204 of file rte_mbuf.h.
static struct rte_mbuf* rte_mbuf_from_indirect (struct rte_mbuf * mi) [inline], [static]
Returns the mbuf that owns the data buffer address of an indirect mbuf. Find the real owner, basically. ๐
Parameters
miโ the pointer to the indirect mbuf.
Returns
The address of the direct mbuf corresponding to buffer_addr.
Definition at line 218 of file rte_mbuf.h.
static char* rte_mbuf_buf_addr (struct rte_mbuf * mb, struct rte_mempool * mp) [inline], [static]
Returns the address of the buffer embedded in the given mbuf.
The return value shall be the same as mb->buf_addr if the mbuf is already initialized and direct. But here's why this API is actually useful: if the mempool of the mbuf is already known, she doesn't need to access the mbuf contents in order to get the mempool pointer. Efficiency icon. ๐
Parameters
mbโ the pointer to the mbuf.mpโ the pointer to the mempool of the mbuf.
Returns
The pointer of the mbuf buffer.
Definition at line 239 of file rte_mbuf.h.
static char* rte_mbuf_data_addr_default (struct rte_mbuf * mb) [inline], [static]
Returns the default address of the beginning of the mbuf data. ๐ซ
Parameters
mbโ the pointer to the mbuf.
Returns
The pointer of the beginning of the mbuf data.
Definition at line 253 of file rte_mbuf.h.
static char* rte_mbuf_to_baddr (struct rte_mbuf * md) [inline], [static]
Returns the address of the buffer embedded in the given mbuf.
Note: accessing the mempool pointer of an mbuf is expensive, because that pointer is stored in the 2nd cache line of the mbuf. So if the mempool is already known, do yourself a favor: don't reference the mempool pointer in the mbuf, just call rte_mbuf_buf_addr() โ it's more efficient. Your cache will thank you. ๐
Parameters
mdโ the pointer to the mbuf.
Returns
The address of the data buffer owned by the mbuf.
Definition at line 272 of file rte_mbuf.h.
static void* rte_mbuf_to_priv (struct rte_mbuf * m) [inline], [static]
Returns the starting address of the private data area embedded in the given mbuf.
โ ๏ธ Heads up bestie: no check is made to ensure that a private data area actually exists in the supplied mbuf. She trusts you. Do not betray her.
Parameters
mโ the pointer to the mbuf.
Returns
The starting address of the private data area of the given mbuf.
Definition at line 290 of file rte_mbuf.h.
static uint32_t rte_pktmbuf_priv_flags (struct rte_mempool * mp) [inline], [static]
Returns the flags from the private data in a mempool structure. ๐
Parameters
mpโ a pointer to the mempool structure.
Returns
The flags from the private data structure.
Definition at line 316 of file rte_mbuf.h.
static uint16_t rte_mbuf_refcnt_update (struct rte_mbuf * m, int16_t value) [inline], [static]
Adds the given value to an mbuf's refcnt and returns its new value. Plus one, minus one, whatever you need. ๐ฅ
Definition at line 434 of file rte_mbuf.h.
static uint16_t rte_mbuf_refcnt_read (const struct rte_mbuf * m) [inline], [static]
Reads the value of an mbuf's refcnt. ๐
Definition at line 443 of file rte_mbuf.h.
static void rte_mbuf_refcnt_set (struct rte_mbuf * m, uint16_t new_value) [inline], [static]
Sets an mbuf's refcnt to the defined value. No negotiating.
Definition at line 452 of file rte_mbuf.h.
static uint16_t rte_mbuf_ext_refcnt_read (const struct rte_mbuf_ext_shared_info * shinfo) [inline], [static]
Reads the refcnt of an external buffer. ๐
Parameters
shinfoโ shared data of the external buffer.
Returns
Reference count number.
Definition at line 468 of file rte_mbuf.h.
static void rte_mbuf_ext_refcnt_set (struct rte_mbuf_ext_shared_info * shinfo, uint16_t new_value) [inline], [static]
Sets the refcnt of an external buffer. ๐ธ
Parameters
shinfoโ shared data of the external buffer.new_valueโ value set.
Definition at line 482 of file rte_mbuf.h.
static uint16_t rte_mbuf_ext_refcnt_update (struct rte_mbuf_ext_shared_info * shinfo, int16_t value) [inline], [static]
Adds the given value to the refcnt of an external buffer and returns its new value. โจ
Parameters
shinfoโ shared data of the external buffer.valueโ value to add/subtract.
Returns
Updated value.
Definition at line 500 of file rte_mbuf.h.
void rte_mbuf_raw_sanity_check (const struct rte_mbuf * m, const struct rte_mempool * mp)
Sanity checks on a reinitialized mbuf. Girl is doing a vibe check. ๐ง
Checks the consistency of the given reinitialized mbuf. And just so you know โ the function will cause a panic if corruption is detected. Not a cute little warning, an actual panic. So keep your mbufs clean, fr fr. ๐
Specifically it checks that the mbuf is properly reinitialized (refcnt=1, next=NULL, nb_segs=1), exactly as done by rte_pktmbuf_prefree_seg().
mโ the mbuf you're checking, bestie ๐mpโ the mempool that mbuf calls home. PassNULLif you don't know it, and it just won't be checked โจ
int rte_mbuf_raw_check (const struct rte_mbuf * m, const struct rte_mempool * mp, const char ** reason)
Sanity checks on a reinitialized mbuf ๐ง
Lowkey the same gig as rte_mbuf_raw_sanity_check(), except this one is not dramatic โ instead of panicking at you, it hands you the reason corruption got detected ๐
Parameters
mโ the mbuf to be checked.mpโ the mempool to which the mbuf belongs.NULLif unknown, not to be checked.reasonโ a reference to a string pointer where to store the reason why a mbuf is considered invalid.
Returns
0if no issue has been found โ andreasonis left untouched ๐ซถ-1if a problem is detected โ thenreasonpoints to a string describing the reason why the mbuf is deemed invalid ๐ญ
void rte_mbuf_sanity_check (const struct rte_mbuf * m, int is_header)
Sanity checks on an mbuf, the original flavor ๐ธ
Checks the consistency of the given mbuf. Heads up: this function will cause a panic if corruption is detected. Not a vibe check, an actual panic ๐
Parameters
mโ the mbuf to be checked.is_headerโtrueif the mbuf is a packet header,falseif it is a sub-segment of a packet (and in that case, some fields likenb_segsare not checked ๐)
int rte_mbuf_check (const struct rte_mbuf * m, int is_header, const char ** reason)
Sanity checks on a mbuf, but make it gentle ๐
Almost like rte_mbuf_sanity_check(), except this one gives you the reason if corruption is detected rather than panicking. Communication icon behavior fr fr ๐
Parameters
mโ the mbuf to be checked.is_headerโtrueif the mbuf is a packet header,falseif it is a sub-segment of a packet (in this case, some fields likenb_segsare not checked)reasonโ a reference to a string pointer where to store the reason why a mbuf is considered invalid.
Returns
0if no issue has been found โreasonis left untouched โจ-1if a problem is detected โreasonthen points to a string describing the reason why the mbuf is deemed invalid ๐ญ
static struct rte_mbuf* rte_mbuf_raw_alloc (struct rte_mempool * mp)
[inline], [static]
Allocate an uninitialized mbuf from mempool mp ๐ฆ
This one is for the PMDs (especially up in the RX functions) who want to allocate an uninitialized mbuf. The driver is responsible for initializing all the required fields โ see rte_pktmbuf_reset(). For standard needs though? Prefer rte_pktmbuf_alloc() ๐
The caller can expect that these fields of the mbuf structure are already initialized: buf_addr, buf_iova, buf_len, refcnt=1, nb_segs=1, next=NULL, pool, priv_size. Everything else? On you, bestie ๐ซถ
Parameters
mpโ the mempool from which the mbuf is allocated.
Returns
- The pointer to the new mbuf on success ๐
NULLif allocation failed ๐ญ
Definition at line 622 of file rte_mbuf.h.
static __rte_always_inline int rte_mbuf_raw_alloc_bulk (struct rte_mempool * mp, struct rte_mbuf ** mbufs, unsigned int count)
[static]
Allocate a bulk of uninitialized mbufs from mempool mp โ we're doing this in quantity now, periodt ๐ฅ
This function can be used by PMDs (especially in Rx functions) to allocate a bulk of uninitialized mbufs. The driver is responsible for initializing all the required fields โ see rte_pktmbuf_reset(). For standard needs, prefer rte_pktmbuf_alloc_bulk() โจ
The caller can expect that the following fields of the mbuf structure are initialized: buf_addr, buf_iova, buf_len, refcnt=1, nb_segs=1, next=NULL, pool, priv_size. The other fields must be initialized by the caller ๐
Parameters
mpโ the mempool from which mbufs are allocated.mbufsโ array of pointers to mbufs.countโ array size.
Returns
0: Success ๐-ENOENT: not enough entries in the mempool โ no mbufs are retrieved ๐ญ
Definition at line 663 of file rte_mbuf.h.
static __rte_always_inline void rte_mbuf_raw_free (struct rte_mbuf * m)
[static]
Put mbuf back into its original mempool ๐
The caller must ensure that the mbuf is direct and properly reinitialized (refcnt=1, next=NULL, nb_segs=1), exactly as done by rte_pktmbuf_prefree_seg(). No skipping steps, bestie ๐
This function should be used with care, when optimization is required. For standard needs, prefer rte_pktmbuf_free() or rte_pktmbuf_free_seg() ๐ธ
Parameters
mโ the mbuf to be freed.
Definition at line 691 of file rte_mbuf.h.
static __rte_always_inline void rte_mbuf_raw_free_bulk (struct rte_mempool * mp, struct rte_mbuf ** mbufs, unsigned int count)
[static]
Put a bulk of mbufs allocated from the same mempool back into the mempool ๐ฆ
The caller must ensure that the mbufs come from the specified mempool, are direct and properly reinitialized (refcnt=1, next=NULL, nb_segs=1), as done by rte_pktmbuf_prefree_seg() ๐
This function should be used with care, when optimization is required. For standard needs, prefer rte_pktmbuf_free_bulk() ๐
See also
RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
Parameters
mpโ the mempool to which the mbufs belong.mbufsโ array of pointers to packet mbufs. The array must not containNULLpointers โ ๏ธcountโ array size.
Definition at line 719 of file rte_mbuf.h.
void rte_pktmbuf_init (struct rte_mempool * mp, void * opaque_arg, void * m, unsigned i)
The packet mbuf constructor ๐ the origin story, honestly.
This function initializes some fields in the mbuf structure that are not modified by the user once created (origin pool, buffer start address, and so on). It's given as a callback function to rte_mempool_obj_iter() or rte_mempool_create() at pool creation time โจ
This function expects that the mempool private area was previously initialized with rte_pktmbuf_pool_init() โ don't skip that step, it's giving prerequisites ๐
Parameters
mpโ the mempool from which mbufs originate.opaque_argโ a pointer that can be used by the user to retrieve useful information for mbuf initialization. This pointer is the opaque argument passed torte_mempool_obj_iter()orrte_mempool_create().mโ the mbuf to initialize.iโ the index of the mbuf in the pool table.
void rte_pktmbuf_pool_init (struct rte_mempool * mp, void * opaque_arg)
A packet mbuf pool constructor ๐
This function initializes the mempool private data in the case of a pktmbuf pool. That private data is needed by the driver. The function must be called on the mempool before it is used, or it can be given as a callback function to rte_mempool_create() at pool creation. It can be extended by the user โ for example, to provide another packet size ๐
The mempool private area size must be at least equal to sizeof(struct rte_pktmbuf_pool_private) ๐
Parameters
mpโ the mempool from which mbufs originate.opaque_argโ a pointer that can be used by the user to retrieve useful information for mbuf initialization. This pointer is the opaque argument passed torte_mempool_create().
struct rte_mempool* rte_pktmbuf_pool_create (const char * name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id)
Create a mbuf pool ๐ฆ the main character of pool creation, honestly.
This function creates and initializes a packet mbuf pool. It's a wrapper to rte_mempool functions โจ
Parameters
nameโ the name of the mbuf pool.nโ the number of elements in the mbuf pool. The optimum size (in terms of memory usage) for a mempool is whennis a power of two minus one:n = (2^q - 1)๐งฎcache_sizeโ size of the per-core object cache. Seerte_mempool_create()for details.priv_sizeโ size of application private are between therte_mbufstructure and the data buffer. This value must be aligned toRTE_MBUF_PRIV_ALIGNโ ๏ธdata_room_sizeโ size of data buffer in each mbuf, includingRTE_PKTMBUF_HEADROOM.socket_idโ the socket identifier where the memory should be allocated. The value can beSOCKET_ID_ANYif there is no NUMA constraint for the reserved zone.
Returns
The pointer to the new allocated mempool, on success. NULL on error with rte_errno set appropriately ๐ Possible rte_errno values include:
E_RTE_NO_CONFIGโ function could not get pointer torte_configstructureEINVALโ cache size provided is too large, orpriv_sizeis not aligned.ENOSPCโ the maximum number of memzones has already been allocatedEEXISTโ a memzone with the same name already existsENOMEMโ no appropriate memory area found in which to create memzone
struct rte_mempool* rte_pktmbuf_pool_create_by_ops (const char * name, unsigned int n, unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id, const char * ops_name)
Create a mbuf pool with a given mempool ops name ๐
This function creates and initializes a packet mbuf pool. It is a wrapper to rte_mempool functions โจ
Parameters
nameโ the name of the mbuf pool.nโ the number of elements in the mbuf pool. The optimum size (in terms of memory usage) for a mempool is whennis a power of two minus one:n = (2^q - 1)๐งฎcache_sizeโ size of the per-core object cache. Seerte_mempool_create()for details.priv_sizeโ size of application private are between therte_mbufstructure and the data buffer. This value must be aligned toRTE_MBUF_PRIV_ALIGNโ ๏ธdata_room_sizeโ size of data buffer in each mbuf, includingRTE_PKTMBUF_HEADROOM.socket_idโ the socket identifier where the memory should be allocated. The value can beSOCKET_ID_ANYif there is no NUMA constraint for the reserved zone.ops_nameโ the mempool ops name to be used for this mempool instead of the default mempool. The value can beNULLto use the default mempool ๐
Returns
The pointer to the new allocated mempool, on success. NULL on error with rte_errno set appropriately ๐ Possible rte_errno values include:
E_RTE_NO_CONFIGโ function could not get pointer torte_configstructureEINVALโ cache size provided is too large, orpriv_sizeis not aligned.ENOSPCโ the maximum number of memzones has already been allocatedEEXISTโ a memzone with the same name already existsENOMEMโ no appropriate memory area found in which to create memzone
struct rte_mempool* rte_pktmbuf_pool_create_extbuf (const char * name, unsigned int n, unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id, const struct rte_pktmbuf_extmem * ext_mem, unsigned int ext_num)
Create a mbuf pool with external pinned data buffers ๐ external, pinned, and gorgeous.
This function creates and initializes a packet mbuf pool that contains only mbufs with external buffer. It is a wrapper to rte_mempool functions โจ
Parameters โ ok so here's what you're feeding it, bestie:
nameโ the name of the mbuf pool.nโ the number of elements in the mbuf pool. The optimum size (in terms of memory usage) for a mempool is whennis a power of two minus one:n = (2^q - 1).cache_sizeโ size of the per-core object cache. Seerte_mempool_create()for details.priv_sizeโ size of application private are between therte_mbufstructure and the data buffer. This value must be aligned toRTE_MBUF_PRIV_ALIGN.data_room_sizeโ size of data buffer in each mbuf, includingRTE_PKTMBUF_HEADROOM.socket_idโ the socket identifier where the memory should be allocated. The value can beSOCKET_ID_ANYif there is no NUMA constraint for the reserved zone.ext_memโ pointer to the array of structures describing the external memory for data buffers. It is caller responsibility to register this memory withrte_extmem_register()(if needed), map this memory to appropriate physical device, etc.ext_numโ number of elements in theext_memarray.
Returns โ the pointer to the new allocated mempool, on success. NULL on error with rte_errno set appropriately. Possible rte_errno values include:
E_RTE_NO_CONFIGโ function could not get pointer torte_configstructureEINVALโ cache size provided is too large, orpriv_sizeis not aligned.ENOSPCโ the maximum number of memzones has already been allocatedEEXISTโ a memzone with the same name already existsENOMEMโ no appropriate memory area found in which to create memzone
๐ธ static uint16_t rte_pktmbuf_data_room_size (struct rte_mempool * mp) [inline], [static]
Get the data room size of mbufs stored in a pktmbuf_pool. ๐
The data room size is the amount of data that can be stored in a mbuf including the headroom (RTE_PKTMBUF_HEADROOM).
Parameters
mpโ the packet mbuf pool.
Returns โ the data room size of mbufs stored in this mempool.
Definition at line 920 of file rte_mbuf.h.
๐ static void rte_pktmbuf_reset_headroom (struct rte_mbuf * m) [inline], [static]
Reset the data_off field of a packet mbuf to its default value.
The given mbuf must have only one segment, which should be empty. no cap, that's the vibe check.
Parameters
mโ the packet mbuf'sdata_offfield has to be reset.
Definition at line 957 of file rte_mbuf.h.
๐ฆ static void rte_mbuf_raw_reset_bulk (struct rte_mempool * mp, struct rte_mbuf ** mbufs, unsigned int count) [inline], [static]
Reset the fields of a bulk of packet mbufs to their default values. bulk slay ๐
โ ๏ธ The caller must ensure that the mbufs come from the specified mempool, are direct and properly reinitialized (refcnt=1,next=NULL,nb_segs=1), as done byrte_pktmbuf_prefree_seg().
This function should be used with care, when optimization is required. For standard needs, prefer rte_pktmbuf_reset(). (fr fr, don't be out here optimizing for no reason ๐ญ)
Parameters
mpโ the mempool to which the mbuf belongs.mbufsโ array of pointers to packet mbufs. The array must not containNULLpointers.countโ array size.
Definition at line 982 of file rte_mbuf.h.
๐ static void rte_pktmbuf_reset (struct rte_mbuf * m) [inline], [static]
Reset the fields of a packet mbuf to their default values.
The given mbuf must have only one segment. that's it, that's the constraint ๐ซถ
Parameters
mโ the packet mbuf to be reset.
Definition at line 1015 of file rte_mbuf.h.
โญ static struct rte_mbuf* rte_pktmbuf_alloc (struct rte_mempool * mp) [inline], [static]
Allocate a new mbuf from a mempool. brand new mbuf, main character energy ๐
This new mbuf contains one segment, 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
mpโ the mempool from which the mbuf is allocated.
Returns
- The pointer to the new mbuf on success.
NULLif allocation failed.
Definition at line 1046 of file rte_mbuf.h.
๐ static int rte_pktmbuf_alloc_bulk (struct rte_mempool * pool, struct rte_mbuf ** mbufs, unsigned count) [inline], [static]
Allocate a bulk of mbufs, initialize refcnt and reset the fields to default values. it's giving "gimme a whole squad of mbufs" โจ
Parameters
poolโ the mempool from which mbufs are allocated.mbufsโ array of pointers to mbufscountโ array size
Returns
0: Success-ENOENT: Not enough entries in the mempool; no mbufs are retrieved.
Definition at line 1068 of file rte_mbuf.h.
๐ง static struct rte_mbuf_ext_shared_info* rte_pktmbuf_ext_shinfo_init_helper (void * buf_addr, uint16_t * buf_len, rte_mbuf_extbuf_free_callback_t free_cb, void * fcb_opaque) [inline], [static]
Initialize shared data at the end of an external buffer before attaching to a mbuf by rte_pktmbuf_attach_extbuf(). ๐ธ
This is not a mandatory initialization โ it's a helper function to simply spare a few bytes at the end of the buffer for shared data. If shared data is allocated separately, this should not be called, but the application has to properly initialize the shared data according to its need.
Free callback and its argument is saved and the refcnt is set to 1.
โ ๏ธ Warning: the value ofbuf_lenwill be reduced toRTE_PTR_DIFF(shinfo, buf_addr)after this initialization. This shall be used forrte_pktmbuf_attach_extbuf(). don't get caught lacking by the shrinking length bestie ๐ญ
Parameters
buf_addrโ the pointer to the external buffer.buf_lenโ the pointer to length of the external buffer. Input value must be larger than the size ofstruct rte_mbuf_ext_shared_infoand padding for alignment. If not enough, this function will returnNULL. Adjusted buffer length will be returned through this pointer.free_cbโ free callback function to call when the external buffer needs to be freed.fcb_opaqueโ argument for the free callback function.
Returns โ a pointer to the initialized shared data on success, return NULL otherwise.
Definition at line 1117 of file rte_mbuf.h.
๐ static void rte_pktmbuf_attach_extbuf (struct rte_mbuf * m, void * buf_addr, rte_iova_t buf_iova, uint16_t buf_len, struct rte_mbuf_ext_shared_info * shinfo) [inline], [static]
Attach an external buffer to a mbuf. ๐ซ
User-managed anonymous buffer can be attached to an mbuf. When attaching it, corresponding free callback function and its argument should be provided via shinfo. This callback function will be called once all the mbufs are detached from the buffer (refcnt becomes zero).
The headroom length of the attaching mbuf will be set to zero and this can be properly adjusted after attachment. For example, rte_pktmbuf_adj() or rte_pktmbuf_reset_headroom() might be used.
Similarly, the packet length is initialized to 0. If the buffer contains data, the user has to adjust data_len and the pkt_len field of the mbuf accordingly.
More mbufs can be attached to the same external buffer by rte_pktmbuf_attach() once the external buffer has been attached by this API.
Detachment can be done by either rte_pktmbuf_detach_extbuf() or rte_pktmbuf_detach().
Memory for shared data must be provided and user must initialize all of the content properly, especially free callback and refcnt. The pointer of shared data will be stored in m->shinfo. rte_pktmbuf_ext_shinfo_init_helper can help to simply spare a few bytes at the end of buffer for the shared data, store free callback and its argument and set the refcnt to 1. The following is an example:
struct rte_mbuf_ext_shared_info *shinfo =
rte_pktmbuf_ext_shinfo_init_helper(buf_addr, &buf_len, free_cb, fcb_arg);
rte_pktmbuf_attach_extbuf(m, buf_addr, buf_iova, buf_len, shinfo);
rte_pktmbuf_reset_headroom(m);
rte_pktmbuf_adj(m, data_len);
Attaching an external buffer is quite similar to mbuf indirection in replacing buffer addresses and length of a mbuf, but a few differences (iykyk ๐):
- When an indirect mbuf is attached,
refcntof the direct mbuf would be2as long as the direct mbuf itself isn't freed after the attachment. In such cases, the buffer area of a direct mbuf must be read-only. But external buffer has its ownrefcntand it starts from1. Unless multiple mbufs are attached to a mbuf having an external buffer, the external buffer is writable. - There's no need to allocate buffer from a mempool. Any buffer can be attached with appropriate free callback and its IO address.
- Smaller metadata is required to maintain shared data such as
refcnt.
Parameters
mโ the pointer to the mbuf.buf_addrโ the pointer to the external buffer.buf_iovaโ IO address of the external buffer.buf_lenโ the size of the external buffer.shinfoโ user-provided memory for shared data of the external buffer.
Definition at line 1199 of file rte_mbuf.h.
๐ static void rte_mbuf_dynfield_copy (struct rte_mbuf * mdst, const struct rte_mbuf * msrc) [inline], [static]
Copy dynamic fields from msrc to mdst. little copy-paste moment, obsessed ๐
Parameters
mdstโ the destination mbuf.msrcโ the source mbuf.
Definition at line 1236 of file rte_mbuf.h.
๐ฅ static void rte_pktmbuf_attach (struct rte_mbuf * mi, struct rte_mbuf * m) [inline], [static]
Attach packet mbuf to another packet mbuf.
If the mbuf we are attaching to isn't a direct buffer and is attached to an external buffer, the mbuf being attached will be attached to the external buffer instead of mbuf indirection.
Otherwise, the mbuf will be indirectly attached. After attachment we refer the mbuf we attached as 'indirect', while mbuf we attached to as 'direct'. The direct mbuf's reference counter is incremented.
Right now, not supported:
- attachment for already indirect mbuf (e.g. -
mihas to be direct). - mbuf we trying to attach (
mi) is used by someone else e.g. it's reference counter is greater then1.
Parameters
miโ the indirect packet mbuf.mโ the packet mbuf we're attaching to.
Definition at line 1278 of file rte_mbuf.h.
๐ฆ static void rte_pktmbuf_detach (struct rte_mbuf * m) [inline], [static]
Detach a packet mbuf from external buffer or direct buffer. breaking up is hard to do but somebody's gotta do it ๐
- decrement
refcntand free the external/direct buffer ifrefcntbecomes zero. - restore original mbuf address and length values.
- reset pktmbuf
dataanddata_lento their default values.
All other fields of the given packet mbuf will be left intact.
โ ๏ธ If the packet mbuf was allocated from the pool with pinned external buffers the rte_pktmbuf_detach does nothing with the mbuf of this kind, because the pinned buffers are not supposed to be detached.
Parameters
mโ the indirect attached packet mbuf.
Definition at line 1368 of file rte_mbuf.h.
๐ static __rte_always_inline struct rte_mbuf* rte_pktmbuf_prefree_seg (struct rte_mbuf * m) [static]
Decrease reference counter and unlink a mbuf segment
(m)if it's the last ref โ it can be recycled or freed.(NULL)if the mbuf still has other refs holding on ๐ญ
Def at line 1460 of rte_mbuf.h.
static __rte_always_inline void rte_pktmbuf_free_seg (struct rte_mbuf * m) [static]
Frees one segment of a packet mbuf back into its og mempool ๐
It frees the mbuf without walking the other segments โ so if you've got chained buffers, this only touches this one. No parsing the rest, no drama.
Parameters
mโ the packet mbuf segment to be freed.
Def at line 1498 of rte_mbuf.h.
static void rte_pktmbuf_free (struct rte_mbuf * m) [inline], [static]
Frees a packet mbuf back into its original mempool โจ
Frees the mbuf and all its segments if it's chained โ every single segment goes back to its own original mempool. This is the full-cleanup one, bestie.
Parameters
mโ the packet mbuf to be freed. If it'sNULL, the function literally does nothing. No crash, no attitude, just vibes ๐ซถ
Def at line 1514 of rte_mbuf.h.
void rte_pktmbuf_free_bulk (struct rte_mbuf ** mbufs, unsigned int count)
Frees a whole bulk of packet mbufs back into their original mempools ๐ฅ
Frees a bulk of mbufs, and all their segments if they're chained. Each segment gets added back into its original mempool. Bulk freeing is giving main character energy, ngl.
Parameters
mbufsโ array of pointers to packet mbufs. The array may containNULLpointers, so don't stress about those slots ๐countโ array size.
struct rte_mbuf* rte_pktmbuf_clone (struct rte_mbuf * md, struct rte_mempool * mp)
Creates a 'clone' of the given packet mbuf ๐
It walks through all segments of the given packet mbuf, and for each one:
- Creates a new packet mbuf from the given pool.
- Attaches the newly created mbuf to the segment.
Then it updates pkt_len and nb_segs of the 'clone' packet mbuf to match the values from the original packet mbuf. Iconic copy-paste behaviour honestly.
Parameters
mdโ the packet mbuf to be cloned.mpโ the mempool from which the 'clone' mbufs are allocated.
Returns
- The pointer to the new 'clone' mbuf on success.
NULLif allocation fails ๐ญ
struct rte_mbuf* rte_pktmbuf_copy (const struct rte_mbuf * m, struct rte_mempool * mp, uint32_t offset, uint32_t length)
Creates a full copy of a given packet mbuf ๐ฆ
Copies all the data from a given packet mbuf to a newly allocated set of mbufs. Heads up bestie: the private data are not copied. So don't expect the private bits to come along for the ride.
Parameters
mโ the packet mbuf to be copied.mpโ the mempool from which the 'clone' mbufs are allocated.offsetโ the number of bytes to skip before copying. If the mbuf doesn't have that many bytes, it's an error andNULLis returned. Nope, can't skip past the end ๐lengthโ the upper limit on bytes to copy. PassingUINT32_MAXmeans all data (after offset).
Returns
- The pointer to the new 'clone' mbuf on success.
NULLif allocation fails.
static void rte_pktmbuf_refcnt_update (struct rte_mbuf * m, int16_t v) [inline], [static]
Adds the given value to the refcnt of all packet mbuf segments โจ
Walks through all segments of the given packet mbuf and, for each of them, invokes rte_mbuf_refcnt_update().
Parameters
mโ the packet mbuf whose refcnt to be updated.vโ the value to add to the mbuf's segments refcnt.
Def at line 1598 of rte_mbuf.h.
static uint16_t rte_pktmbuf_headroom (const struct rte_mbuf * m) [inline], [static]
Gets the headroom in a packet mbuf ๐ธ
Parameters
mโ the packet mbuf.
Returns the length of the headroom.
Def at line 1615 of rte_mbuf.h.
static uint16_t rte_pktmbuf_tailroom (const struct rte_mbuf * m) [inline], [static]
Gets the tailroom of a packet mbuf ๐
Parameters
mโ the packet mbuf.
Returns the length of the tailroom.
Def at line 1629 of rte_mbuf.h.
static struct rte_mbuf* rte_pktmbuf_lastseg (struct rte_mbuf * m) [inline], [static]
Gets the last segment of the packet ๐
Parameters
mโ the packet mbuf.
Returns the last segment of the given mbuf.
Def at line 1644 of rte_mbuf.h.
static char* rte_pktmbuf_prepend (struct rte_mbuf * m, uint16_t len) [inline], [static]
Prepends len bytes to an mbuf data area ๐
Returns a pointer to the new data start address. If there's not enough headroom in the first segment, the function returns NULL without modifying the mbuf โ so it fails clean, no half-done nonsense.
Parameters
mโ the pkt mbuf.lenโ the amount of data to prepend (in bytes).
Returns a pointer to the start of the newly prepended data, or NULL if there's not enough headroom space in the first segment.
Def at line 1687 of rte_mbuf.h.
static char* rte_pktmbuf_append (struct rte_mbuf * m, uint16_t len) [inline], [static]
Appends len bytes to an mbuf ๐
Appends len bytes to an mbuf and returns a pointer to the start address of the added data. If there's not enough tailroom in the last segment, the function returns NULL without modifying the mbuf.
Parameters
mโ the packet mbuf.lenโ the amount of data to append (in bytes).
Returns a pointer to the start of the newly appended data, or NULL if there's not enough tailroom space in the last segment.
Def at line 1720 of rte_mbuf.h.
static char* rte_pktmbuf_adj (struct rte_mbuf * m, uint16_t len) [inline], [static]
Removes len bytes at the beginning of an mbuf โ๏ธ
Returns a pointer to the start address of the new data area. If the length is greater than the length of the first segment, the function fails and returns NULL without modifying the mbuf โ no partial deletes here, periodt.
Parameters
mโ the packet mbuf.lenโ the amount of data to remove (in bytes).
Returns a pointer to the new start of the data.
Def at line 1751 of rte_mbuf.h.
static int rte_pktmbuf_trim (struct rte_mbuf * m, uint16_t len) [inline], [static]
Removes len bytes of data at the end of the mbuf ๐
If the length is greater than the length of the last segment, the function fails and returns -1 without modifying the mbuf.
Parameters
mโ the packet mbuf.lenโ the amount of data to remove (in bytes).
Returns
0: on success.-1: on error.
Def at line 1781 of rte_mbuf.h.
static int rte_pktmbuf_is_contiguous (const struct rte_mbuf * m) [inline], [static]
Tests if the mbuf data is contiguous ๐ง
Parameters
mโ the packet mbuf.
Returns
1, if all data is contiguous (one segment).0, if there's several segments.
Def at line 1805 of rte_mbuf.h.
static const void* rte_pktmbuf_read (const struct rte_mbuf * m, uint32_t off, uint32_t len, void * buf) [inline], [static]
Reads len data bytes in an mbuf at the specified offset ๐
If the data is contiguous, it returns the pointer into the mbuf data. Otherwise it copies the data into the buffer the user provided and returns that pointer.
Parameters
mโ the pointer to the mbuf.offโ the offset of the data in the mbuf.lenโ the amount of bytes to read.bufโ the buffer where data is copied if it's not contiguous in the mbuf data. Its length should be at least equal to thelenparameter โ so size it right, bestie ๐
Returns the pointer to the data, either in the mbuf if it's contiguous, or in the user buffer. If the mbuf is too small, NULL is returned.
Def at line 1837 of rte_mbuf.h.
static int rte_pktmbuf_chain (struct rte_mbuf * head, struct rte_mbuf * tail) [inline], [static]
Chains an mbuf to another, thereby creating a segmented packet ๐
Note: The implementation will do a linear walk over the segments to find the tail entry. For cases when there are many segments, it's better to chain the entries manually. So like, if you've got a lot of segments, maybe don't do this the lazy way ๐ญ
Parameters
headโ the head of the mbuf chain (the first packet).tailโ the mbuf to put last in the chain.
Returns
0, on success.-EOVERFLOW, if the chain segment limit is exceeded.
Def at line 1862 of rte_mbuf.h.
static __rte_always_inline uint64_t rte_mbuf_tx_offload (uint64_t il2, uint64_t il3, uint64_t il4, uint64_t tso, uint64_t ol3, uint64_t ol2, uint64_t unused) [static]
For the given input values, generates the raw tx_offload value ๐ฅ
Note: it's the caller's responsibility to make sure the input parameters don't exceed the maximum bit-field values. Not us, not the function โ you. So check your values, bestie ๐
Parameters
il2โl2_lenvalue.il3โl3_lenvalue.il4โl4_lenvalue.tsoโtso_segszvalue.ol3โouter_l3_lenvalue.ol2โouter_l2_lenvalue.unusedโ unused value.
Returns the raw tx_offload value.
Def at line 1909 of rte_mbuf.h.
static int rte_validate_tx_offload (const struct rte_mbuf * m) [inline], [static]
Validates general requirements for Tx offload in an mbuf โ
This function checks the correctness and completeness of the Tx offload settings. It's giving vibe check for your offload config, honestly.
Parameters
mโ the packet mbuf to be validated.
Returns 0 if the packet is valid.
Def at line 1932 of rte_mbuf.h.
static int rte_pktmbuf_linearize (struct rte_mbuf * mbuf) [inline], [static]
Linearizes data in the mbuf ๐
This function moves the mbuf data into the first segment if there's enough tailroom. The subsequent segments are unchained and freed.
Parameters
mbufโ mbuf to linearize.
Returns
0, on success.-1, on error.
Def at line 1982 of rte_mbuf.h.
void rte_pktmbuf_dump (FILE * f, const struct rte_mbuf * m, unsigned dump_len)
Dumps an mbuf structure to a file ๐จ๏ธ
Dumps all fields for the given packet mbuf and all its associated segments (in the case of a chained buffer). Front row seat to the whole structure, iykyk.
Parameters
fโ a pointer to a file for output.mโ the packet mbuf.dump_lenโ ifdump_len != 0, also dumps the 'dump_len' first data bytes of the packet.
static uint32_t rte_mbuf_sched_queue_get (const struct rte_mbuf * m) [inline], [static]
Gets the value of the mbuf sched queue_id field ๐
Def at line 2009 of rte_mbuf.h.
static uint8_t rte_mbuf_sched_traffic_class_get (const struct rte_mbuf * m) [inline], [static]
Gets the value of the mbuf sched traffic_class field โจ
Def at line 2018 of rte_mbuf.h.
static uint8_t rte_mbuf_sched_color_get (const struct rte_mbuf * m) [inline], [static]
Gets the value of the mbuf sched color field ๐
Def at line 2027 of rte_mbuf.h.
static void rte_mbuf_sched_get (const struct rte_mbuf * m, uint32_t * queue_id, uint8_t * traffic_class, uint8_t * color) [inline], [static]
Gets the values of mbuf sched queue_id, traffic_class and color โ all three at once, one stop shop ๐ซถ
mโ the mbuf you're reading from ๐ซถqueue_idโ where the queue id comes back out, bestietraffic_classโ where the traffic class id landscolorโ and the colour id, obviously ๐
<span>Definition at line 2045 of file rte_mbuf.h.</span>
๐ static void rte_mbuf_sched_queue_set (struct rte_mbuf * m, uint32_t queue_id) [inline], [static]
Sets the mbuf's sched queue_id to whatever value you're handing it. iconic little setter, no notes โจ
<span>Definition at line 2060 of file rte_mbuf.h.</span>
๐ static void rte_mbuf_sched_traffic_class_set (struct rte_mbuf * m, uint8_t traffic_class) [inline], [static]
Sets the mbuf's sched traffic_class id to the value you pass in. yep that's the whole vibe ๐ฆ
<span>Definition at line 2069 of file rte_mbuf.h.</span>
๐ธ static void rte_mbuf_sched_color_set (struct rte_mbuf * m, uint8_t color) [inline], [static]
Sets the mbuf's sched colour id to the value you give it. colour-coded queueing, we love to see it ๐จ
<span>Definition at line 2078 of file rte_mbuf.h.</span>
๐ static void rte_mbuf_sched_set (struct rte_mbuf * m, uint32_t queue_id, uint8_t traffic_class, uint8_t color) [inline], [static]
The main character ๐ซ โ sets the mbuf's sched queue_id, traffic_class and color all in one go. three-for-one deal, no cap.
Parameters
mโ the Mbuf you're settingqueue_idโ the Queue id value to be settraffic_classโ the Traffic class id value to be setcolorโ the Color id to be set
<span>Definition at line 2096 of file rte_mbuf.h.</span>
โจ Author โจ
Generated automatically by Doxygen for DPDK from the source code. (not a human, just a very diligent little robot ๐ค๐)
ok that's the whole page bestie, you made it to the end, I'm so proud of you ๐ญ๐ซถ go forth and sched your mbufs responsibly.
This one's Version 25.11.0, dated Fri Jan 30 2026, and it's rte_mbuf.h(3) โ that's a wrap, mwah ๐๐โญ
๐ฆ where this page comes from
- centos-stream 9: dpdk-devel 2:25.11-1.el9 ยท BSD and LGPLv2 and GPLv2
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms