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_private
  • struct 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 to rte_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 to rte_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 just rte_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. Pass NULL if 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. NULL if unknown, not to be checked.
  • reason โ€” a reference to a string pointer where to store the reason why a mbuf is considered invalid.

Returns

  • 0 if no issue has been found โ€” and reason is left untouched ๐Ÿซถ
  • -1 if a problem is detected โ€” then reason points 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 โ€” true if the mbuf is a packet header, false if it is a sub-segment of a packet (and in that case, some fields like nb_segs are 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 โ€” true 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)
  • reason โ€” a 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 ๐Ÿ˜ญ

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 ๐ŸŽ‰
  • NULL if 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 contain NULL pointers โš ๏ธ
  • 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 to rte_mempool_obj_iter() or rte_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 to rte_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 when n is a power of two minus one: n = (2^q - 1) ๐Ÿงฎ
  • cache_size โ€” size of the per-core object cache. See rte_mempool_create() for details.
  • priv_size โ€” size of application private are between the rte_mbuf structure and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN โš ๏ธ
  • data_room_size โ€” size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM.
  • socket_id โ€” the socket identifier where the memory should be allocated. The value can be SOCKET_ID_ANY if 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 to rte_config structure
  • EINVAL โ€” cache size provided is too large, or priv_size is not aligned.
  • ENOSPC โ€” the maximum number of memzones has already been allocated
  • EEXIST โ€” a memzone with the same name already exists
  • ENOMEM โ€” 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 when n is a power of two minus one: n = (2^q - 1) ๐Ÿงฎ
  • cache_size โ€” size of the per-core object cache. See rte_mempool_create() for details.
  • priv_size โ€” size of application private are between the rte_mbuf structure and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN โš ๏ธ
  • data_room_size โ€” size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM.
  • socket_id โ€” the socket identifier where the memory should be allocated. The value can be SOCKET_ID_ANY if 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 be NULL to 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 to rte_config structure
  • EINVAL โ€” cache size provided is too large, or priv_size is not aligned.
  • ENOSPC โ€” the maximum number of memzones has already been allocated
  • EEXIST โ€” a memzone with the same name already exists
  • ENOMEM โ€” 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 when n is a power of two minus one: n = (2^q - 1).
  • cache_size โ€” size of the per-core object cache. See rte_mempool_create() for details.
  • priv_size โ€” size of application private are between the rte_mbuf structure and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN.
  • data_room_size โ€” size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM.
  • socket_id โ€” the socket identifier where the memory should be allocated. The value can be SOCKET_ID_ANY if 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 with rte_extmem_register() (if needed), map this memory to appropriate physical device, etc.
  • ext_num โ€” number of elements in the ext_mem array.

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 to rte_config structure
  • EINVAL โ€” cache size provided is too large, or priv_size is not aligned.
  • ENOSPC โ€” the maximum number of memzones has already been allocated
  • EEXIST โ€” a memzone with the same name already exists
  • ENOMEM โ€” 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's data_off field 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 by rte_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 contain NULL pointers.
  • 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.
  • NULL if 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 mbufs
  • count โ€” 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 of buf_len will be reduced to RTE_PTR_DIFF(shinfo, buf_addr) after this initialization. This shall be used for rte_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 of struct rte_mbuf_ext_shared_info and padding for alignment. If not enough, this function will return NULL. 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, refcnt of the direct mbuf would be 2 as 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 own refcnt and it starts from 1. 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. - mi has to be direct).
  • mbuf we trying to attach (mi) is used by someone else e.g. it's reference counter is greater then 1.

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 refcnt and free the external/direct buffer if refcnt becomes zero.
  • restore original mbuf address and length values.
  • reset pktmbuf data and data_len to 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's NULL, 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 contain NULL pointers, 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.
  • NULL if 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 and NULL is returned. Nope, can't skip past the end ๐Ÿ’€
  • length โ€” the 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.

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 the len parameter โ€” 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_len value.
  • il3 โ€” l3_len value.
  • il4 โ€” l4_len value.
  • tso โ€” tso_segsz value.
  • ol3 โ€” outer_l3_len value.
  • ol2 โ€” outer_l2_len value.
  • 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 โ€” if dump_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, bestie
  • traffic_class โ€” where the traffic class id lands
  • color โ€” 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 setting
  • queue_id โ€” the Queue id value to be set
  • traffic_class โ€” the Traffic class id value to be set
  • color โ€” 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