Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Network buffer representation. More...

#include <zephyr/net_buf.h>

Data Fields

sys_snode_t node
 Allow placing the buffer into sys_slist_t.
struct net_buffrags
 Fragments associated with this buffer.
union { 
   struct { 
      uint8_t   ref 
 Reference count. More...
      uint8_t   flags 
 Bit-field of buffer flags. More...
      uint8_t   pool_id 
 Where the buffer should go when freed up. More...
      uint8_t   user_data_size 
 Size of user data on this buffer. More...
   } 
}; 
 Reference count, packed alongside three adjacent uint8_t fields (flags, pool_id, user_data_size) in a single atomic_t-sized slot.
union { 
   struct { 
      uint8_t *   data 
 Pointer to the start of data in the buffer. More...
      uint16_t   len 
 Length of the data behind the data pointer. More...
      uint16_t   size 
 Amount of data that this buffer can store. More...
   } 
}; 
 Union for convenience access to the net_buf_simple members, also preserving the old API.
uint8_t user_data []
 System metadata for this buffer.

Detailed Description

Network buffer representation.

This struct is used to represent network buffers. Such buffers are normally defined through the NET_BUF_POOL_*_DEFINE() APIs and allocated using the net_buf_alloc() API.

Field Documentation

◆ [union]

union { ... } net_buf

Union for convenience access to the net_buf_simple members, also preserving the old API.

◆ [union]

union { ... } net_buf

Reference count, packed alongside three adjacent uint8_t fields (flags, pool_id, user_data_size) in a single atomic_t-sized slot.

ref_word is the atomic_t view used by net_buf internals for ref/unref; ref, flags, pool_id and user_data_size are byte-level views into the same storage.

atomic_inc/dec on ref_word add/subtract 1 to/from the whole word, but because the byte-struct layout below places ref at the least-significant byte of ref_word regardless of endianness, and because the ref count never overflows past 254 (already implicit in its uint8_t domain), only the ref byte changes – the other three bytes are untouched.

On 32-bit architectures atomic_t is 4 bytes and the byte struct fills the slot exactly. On 64-bit, atomic_t is 8 bytes; the upper 4 bytes are alignment padding that struct net_buf already required (the next field is an 8-byte-aligned pointer), so this union does not grow struct net_buf there either. On big-endian 64-bit, the byte struct is shifted by 4 bytes of explicit padding so ref still sits at the LSB of ref_word.

flags, pool_id and user_data_size are written exactly once at allocation time on a single thread and are read-only thereafter, so plain uint8_t reads from non-atomic call sites remain safe. flags is also legally written from a context that owns the buf exclusively (e.g. bt_buf_make_view on a just-allocated view).

◆ data

uint8_t* net_buf::data

Pointer to the start of data in the buffer.

◆ flags

uint8_t net_buf::flags

Bit-field of buffer flags.

◆ frags

struct net_buf* net_buf::frags

Fragments associated with this buffer.

◆ len

uint16_t net_buf::len

Length of the data behind the data pointer.

◆ node

sys_snode_t net_buf::node

Allow placing the buffer into sys_slist_t.

◆ pool_id

uint8_t net_buf::pool_id

Where the buffer should go when freed up.

◆ ref

uint8_t net_buf::ref

Reference count.

◆ size

uint16_t net_buf::size

Amount of data that this buffer can store.

◆ user_data

uint8_t net_buf::user_data[]

System metadata for this buffer.

Cleared on allocation.

◆ user_data_size

uint8_t net_buf::user_data_size

Size of user data on this buffer.


The documentation for this struct was generated from the following file: