![]() |
Zephyr API 4.4.99
A Scalable Open Source RTOS
|
Network buffer representation. More...
#include <net_buf.h>
Data Fields | ||
| sys_snode_t | node | |
| Allow placing the buffer into sys_slist_t. | ||
| struct net_buf * | frags | |
| 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. | ||
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.
| 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).
| union { ... } net_buf |
Union for convenience access to the net_buf_simple members, also preserving the old API.
| uint8_t* net_buf::data |
Pointer to the start of data in the buffer.
| uint8_t net_buf::flags |
Bit-field of buffer flags.
| struct net_buf* net_buf::frags |
Fragments associated with this buffer.
| uint16_t net_buf::len |
Length of the data behind the data pointer.
| sys_snode_t net_buf::node |
Allow placing the buffer into sys_slist_t.
| uint8_t net_buf::pool_id |
Where the buffer should go when freed up.
| uint8_t net_buf::ref |
Reference count.
| uint16_t net_buf::size |
Amount of data that this buffer can store.
| uint8_t net_buf::user_data[] |
System metadata for this buffer.
Cleared on allocation.
| uint8_t net_buf::user_data_size |
Size of user data on this buffer.