FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
buffer.h File Reference

vlib buffer structure definition and a few select access methods. More...

+ Include dependency graph for buffer.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  vlib_buffer_t
 
struct  vlib_buffer_free_list_t
 
struct  vlib_buffer_callbacks_t
 
struct  vlib_buffer_pool_t
 
struct  vlib_buffer_main_t
 

Macros

#define VLIB_BUFFER_DATA_SIZE   (2048)
 
#define VLIB_BUFFER_PRE_DATA_SIZE   __PRE_DATA_SIZE
 
#define VLIB_BUFFER_MIN_CHAIN_SEG_SIZE   (128)
 
#define VLIB_BUFFER_CLONE_HEAD_SIZE   (256)
 
#define foreach_vlib_buffer_flag
 Buffer Flags. More...
 
#define LOG2_VLIB_BUFFER_FLAG_USER(n)   (32 - (n))
 
#define VLIB_BUFFER_FLAG_USER(n)   (1 << LOG2_VLIB_BUFFER_FLAG_USER(n))
 
#define VLIB_BUFFER_FLAGS_ALL   (0x1f)
 
#define VLIB_BUFFER_HDR_SIZE   (sizeof(vlib_buffer_t) - VLIB_BUFFER_PRE_DATA_SIZE)
 
#define vlib_prefetch_buffer_header(b, type)   CLIB_PREFETCH (b, 64, type)
 Prefetch buffer metadata. More...
 
#define vlib_prefetch_buffer_data(b, type)   CLIB_PREFETCH (vlib_buffer_get_current(b), CLIB_CACHE_LINE_BYTES, type)
 
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX   (0)
 
#define VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES   VLIB_BUFFER_DATA_SIZE
 
#define VLIB_BUFFER_TRACE_TRAJECTORY   0
 Compile time buffer trajectory tracing option Turn this on if you run into "bad monkey" contexts, and you want to know exactly which nodes they've visited... More...
 
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
 
#define VLIB_BUFFER_REGISTER_CALLBACKS(x, ...)
 

Typedefs

typedef u8 vlib_buffer_free_list_index_t
 
typedef struct vlib_buffer_free_list_t vlib_buffer_free_list_t
 
typedef uword() vlib_buffer_fill_free_list_cb_t(struct vlib_main_t *vm, vlib_buffer_free_list_t *fl, uword min_free_buffers)
 
typedef void() vlib_buffer_free_cb_t(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers)
 
typedef void() vlib_buffer_free_no_next_cb_t(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers)
 

Enumerations

enum  { foreach_vlib_buffer_flag }
 
enum  { foreach_vlib_buffer_flag }
 

Functions

static void vlib_buffer_struct_is_sane (vlib_buffer_t *b)
 
static uword vlib_buffer_get_va (vlib_buffer_t *b)
 
static void * vlib_buffer_get_current (vlib_buffer_t *b)
 Get pointer to current data to process. More...
 
static uword vlib_buffer_get_current_va (vlib_buffer_t *b)
 
static void vlib_buffer_advance (vlib_buffer_t *b, word l)
 Advance current data pointer by the supplied (signed!) amount. More...
 
static u8 vlib_buffer_has_space (vlib_buffer_t *b, word l)
 Check if there is enough space in buffer to advance. More...
 
static void vlib_buffer_reset (vlib_buffer_t *b)
 Reset current header & length to state they were in when packet was received. More...
 
static void * vlib_get_buffer_opaque (vlib_buffer_t *b)
 Get pointer to buffer's opaque data array. More...
 
static void * vlib_get_buffer_opaque2 (vlib_buffer_t *b)
 Get pointer to buffer's opaque2 data array. More...
 
static u8vlib_buffer_get_tail (vlib_buffer_t *b)
 Get pointer to the end of buffer's data. More...
 
static void * vlib_buffer_put_uninit (vlib_buffer_t *b, u16 size)
 Append uninitialized data to buffer. More...
 
static void * vlib_buffer_push_uninit (vlib_buffer_t *b, u8 size)
 Prepend uninitialized data to buffer. More...
 
static void * vlib_buffer_make_headroom (vlib_buffer_t *b, u8 size)
 Make head room, typically for packet headers. More...
 
static void * vlib_buffer_pull (vlib_buffer_t *b, u8 size)
 Retrieve bytes from buffer head. More...
 
static_always_inline vlib_buffer_pool_tvlib_buffer_pool_get (u8 buffer_pool_index)
 
u8 vlib_buffer_register_physmem_map (struct vlib_main_t *vm, u32 physmem_map_index)
 
clib_error_tvlib_buffer_main_init (struct vlib_main_t *vm)
 
void * vlib_set_buffer_free_callback (struct vlib_main_t *vm, void *fp)
 

Variables

vlib_buffer_callbacks_tvlib_buffer_callbacks
 
vlib_buffer_main_t buffer_main
 

Detailed Description

vlib buffer structure definition and a few select access methods.

This structure and the buffer allocation mechanism should perhaps live in vnet, but it would take a lot of typing to make it so.

Definition in file buffer.h.

Macro Definition Documentation

◆ foreach_vlib_buffer_flag

foreach_vlib_buffer_flag
Value:
_( 0, NON_DEFAULT_FREELIST, "non-default-fl") \
_( 1, IS_TRACED, 0) \
_( 2, NEXT_PRESENT, 0) \
_( 3, TOTAL_LENGTH_VALID, 0) \
_( 4, EXT_HDR_VALID, "ext-hdr-valid")

Buffer Flags.

Definition at line 74 of file buffer.h.

◆ LOG2_VLIB_BUFFER_FLAG_USER

#define LOG2_VLIB_BUFFER_FLAG_USER (   n)    (32 - (n))

Definition at line 99 of file buffer.h.

◆ VLIB_BUFFER_CLONE_HEAD_SIZE

#define VLIB_BUFFER_CLONE_HEAD_SIZE   (256)

Definition at line 60 of file buffer.h.

◆ VLIB_BUFFER_DATA_SIZE

#define VLIB_BUFFER_DATA_SIZE   (2048)

Definition at line 51 of file buffer.h.

◆ VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES

#define VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES   VLIB_BUFFER_DATA_SIZE

Definition at line 443 of file buffer.h.

◆ VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX

#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX   (0)

Definition at line 442 of file buffer.h.

◆ VLIB_BUFFER_FLAG_USER

#define VLIB_BUFFER_FLAG_USER (   n)    (1 << LOG2_VLIB_BUFFER_FLAG_USER(n))

Definition at line 100 of file buffer.h.

◆ VLIB_BUFFER_FLAGS_ALL

#define VLIB_BUFFER_FLAGS_ALL   (0x1f)

Definition at line 101 of file buffer.h.

◆ VLIB_BUFFER_HDR_SIZE

#define VLIB_BUFFER_HDR_SIZE   (sizeof(vlib_buffer_t) - VLIB_BUFFER_PRE_DATA_SIZE)

Definition at line 179 of file buffer.h.

◆ VLIB_BUFFER_MIN_CHAIN_SEG_SIZE

#define VLIB_BUFFER_MIN_CHAIN_SEG_SIZE   (128)

Definition at line 57 of file buffer.h.

◆ VLIB_BUFFER_PRE_DATA_SIZE

#define VLIB_BUFFER_PRE_DATA_SIZE   __PRE_DATA_SIZE

Definition at line 52 of file buffer.h.

◆ VLIB_BUFFER_REGISTER_CALLBACKS

#define VLIB_BUFFER_REGISTER_CALLBACKS (   x,
  ... 
)
Value:
__VA_ARGS__ vlib_buffer_callbacks_t __##x##_buffer_callbacks; \
static void __vlib_add_buffer_callbacks_t_##x (void) \
__attribute__((__constructor__)) ; \
static void __vlib_add_buffer_callbacks_t_##x (void) \
{ \
clib_panic ("vlib buffer callbacks already registered"); \
vlib_buffer_callbacks = &__##x##_buffer_callbacks; \
} \
static void __vlib_rm_buffer_callbacks_t_##x (void) \
__attribute__((__destructor__)) ; \
static void __vlib_rm_buffer_callbacks_t_##x (void) \
__VA_ARGS__ vlib_buffer_callbacks_t __##x##_buffer_callbacks
vlib_buffer_callbacks_t * vlib_buffer_callbacks
Definition: buffer.c:49

Definition at line 500 of file buffer.h.

◆ VLIB_BUFFER_TRACE_TRAJECTORY

#define VLIB_BUFFER_TRACE_TRAJECTORY   0

Compile time buffer trajectory tracing option Turn this on if you run into "bad monkey" contexts, and you want to know exactly which nodes they've visited...

See vlib/main.c...

Definition at line 486 of file buffer.h.

◆ VLIB_BUFFER_TRACE_TRAJECTORY_INIT

#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT (   b)

Definition at line 495 of file buffer.h.

◆ vlib_prefetch_buffer_data

#define vlib_prefetch_buffer_data (   b,
  type 
)    CLIB_PREFETCH (vlib_buffer_get_current(b), CLIB_CACHE_LINE_BYTES, type)

Definition at line 189 of file buffer.h.

◆ vlib_prefetch_buffer_header

#define vlib_prefetch_buffer_header (   b,
  type 
)    CLIB_PREFETCH (b, 64, type)

Prefetch buffer metadata.

The first 64 bytes of buffer contains most header information

Parameters
b- (vlib_buffer_t *) pointer to the buffer
type- LOAD, STORE. In most cases, STORE is the right answer

Definition at line 188 of file buffer.h.

Typedef Documentation

◆ vlib_buffer_fill_free_list_cb_t

typedef uword() vlib_buffer_fill_free_list_cb_t(struct vlib_main_t *vm, vlib_buffer_free_list_t *fl, uword min_free_buffers)

Definition at line 397 of file buffer.h.

◆ vlib_buffer_free_cb_t

typedef void() vlib_buffer_free_cb_t(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers)

Definition at line 400 of file buffer.h.

◆ vlib_buffer_free_list_index_t

Definition at line 62 of file buffer.h.

◆ vlib_buffer_free_list_t

◆ vlib_buffer_free_no_next_cb_t

typedef void() vlib_buffer_free_no_next_cb_t(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers)

Definition at line 402 of file buffer.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
foreach_vlib_buffer_flag 

Definition at line 84 of file buffer.h.

◆ anonymous enum

anonymous enum
Enumerator
foreach_vlib_buffer_flag 

Definition at line 91 of file buffer.h.

Function Documentation

◆ vlib_buffer_advance()

static void vlib_buffer_advance ( vlib_buffer_t b,
word  l 
)
inlinestatic

Advance current data pointer by the supplied (signed!) amount.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
l- (word) signed increment

Definition at line 233 of file buffer.h.

◆ vlib_buffer_get_current()

static void* vlib_buffer_get_current ( vlib_buffer_t b)
inlinestatic

Get pointer to current data to process.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
Returns
- (void *) (b->data + b->current_data)

Definition at line 214 of file buffer.h.

◆ vlib_buffer_get_current_va()

static uword vlib_buffer_get_current_va ( vlib_buffer_t b)
inlinestatic

Definition at line 222 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_get_tail()

static u8* vlib_buffer_get_tail ( vlib_buffer_t b)
inlinestatic

Get pointer to the end of buffer's data.

Parameters
bpointer to the buffer
Returns
pointer to tail of packet's data

Definition at line 295 of file buffer.h.

+ Here is the caller graph for this function:

◆ vlib_buffer_get_va()

static uword vlib_buffer_get_va ( vlib_buffer_t b)
inlinestatic

Definition at line 202 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_has_space()

static u8 vlib_buffer_has_space ( vlib_buffer_t b,
word  l 
)
inlinestatic

Check if there is enough space in buffer to advance.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
l- (word) size to check
Returns
- 0 if there is less space than 'l' in buffer

Definition at line 250 of file buffer.h.

+ Here is the caller graph for this function:

◆ vlib_buffer_main_init()

clib_error_t* vlib_buffer_main_init ( struct vlib_main_t vm)

Definition at line 907 of file buffer.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_make_headroom()

static void* vlib_buffer_make_headroom ( vlib_buffer_t b,
u8  size 
)
inlinestatic

Make head room, typically for packet headers.

Parameters
bpointer to the buffer
sizenumber of head room bytes
Returns
pointer to start of buffer (current data)

Definition at line 335 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_pool_get()

static_always_inline vlib_buffer_pool_t* vlib_buffer_pool_get ( u8  buffer_pool_index)

Definition at line 464 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_pull()

static void* vlib_buffer_pull ( vlib_buffer_t b,
u8  size 
)
inlinestatic

Retrieve bytes from buffer head.

Parameters
bpointer to the buffer
sizenumber of bytes to pull
Returns
pointer to start of buffer (current data)

Definition at line 348 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_push_uninit()

static void* vlib_buffer_push_uninit ( vlib_buffer_t b,
u8  size 
)
inlinestatic

Prepend uninitialized data to buffer.

Parameters
bpointer to the buffer
sizenumber of uninitialized bytes
Returns
pointer to beginning of uninitialized data

Definition at line 320 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_put_uninit()

static void* vlib_buffer_put_uninit ( vlib_buffer_t b,
u16  size 
)
inlinestatic

Append uninitialized data to buffer.

Parameters
bpointer to the buffer
sizenumber of uninitialized bytes
Returns
pointer to beginning of uninitialized data

Definition at line 306 of file buffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_register_physmem_map()

u8 vlib_buffer_register_physmem_map ( struct vlib_main_t vm,
u32  physmem_map_index 
)

Definition at line 804 of file buffer.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlib_buffer_reset()

static void vlib_buffer_reset ( vlib_buffer_t b)
inlinestatic

Reset current header & length to state they were in when packet was received.

Parameters
b- (vlib_buffer_t *) pointer to the buffer

Definition at line 262 of file buffer.h.

+ Here is the caller graph for this function:

◆ vlib_buffer_struct_is_sane()

static void vlib_buffer_struct_is_sane ( vlib_buffer_t b)
inlinestatic

Definition at line 193 of file buffer.h.

◆ vlib_get_buffer_opaque()

static void* vlib_get_buffer_opaque ( vlib_buffer_t b)
inlinestatic

Get pointer to buffer's opaque data array.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
Returns
- (void *) b->opaque

Definition at line 274 of file buffer.h.

◆ vlib_get_buffer_opaque2()

static void* vlib_get_buffer_opaque2 ( vlib_buffer_t b)
inlinestatic

Get pointer to buffer's opaque2 data array.

Parameters
b- (vlib_buffer_t *) pointer to the buffer
Returns
- (void *) b->opaque2

Definition at line 285 of file buffer.h.

◆ vlib_set_buffer_free_callback()

void* vlib_set_buffer_free_callback ( struct vlib_main_t vm,
void *  fp 
)

Definition at line 556 of file buffer.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ buffer_main

vlib_buffer_main_t buffer_main

Definition at line 56 of file buffer.c.

◆ vlib_buffer_callbacks

vlib_buffer_callbacks_t* vlib_buffer_callbacks

Definition at line 49 of file buffer.c.