libosmocore 1.9.0.196-9975
Osmocom core library
Message buffers

libosmocore message buffers, inspired by Linux kernel skbuff More...

Files

file  msgb.h
 
file  msgb.c
 

Data Structures

struct  msgb
 Osmocom message buffer. More...
 

Macros

#define MSGB_DEBUG
 
#define MSGB_ABORT(msg, fmt, args ...)
 
#define msgb_l1(m)   ((void *)((m)->l1h))
 obtain L1 header of msgb More...
 
#define msgb_l2(m)   ((void *)((m)->l2h))
 obtain L2 header of msgb More...
 
#define msgb_l3(m)   ((void *)((m)->l3h))
 obtain L3 header of msgb More...
 
#define msgb_l4(m)   ((void *)((m)->l4h))
 obtain L4 header of msgb More...
 
#define msgb_sms(m)   msgb_l4(m)
 obtain SMS header of msgb More...
 
#define msgb_eq_data(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 0, msg, data, len, false)
 Compare: check data in msgb against given data. More...
 
#define msgb_eq_l1_data(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 1, msg, data, len, false)
 Compare: check L1 data in msgb against given data. More...
 
#define msgb_eq_l2_data(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 2, msg, data, len, false)
 Compare: check L2 data in msgb against given data. More...
 
#define msgb_eq_l3_data(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 3, msg, data, len, false)
 Compare: check L3 data in msgb against given data. More...
 
#define msgb_eq_l4_data(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 4, msg, data, len, false)
 Compare: check L4 data in msgb against given data. More...
 
#define msgb_eq_data_print(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 0, msg, data, len, true)
 Compare and print: check data in msgb against given data and print errors if any. More...
 
#define msgb_eq_l1_data_print(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 1, msg, data, len, true)
 Compare and print: check L1 data in msgb against given data and print errors if any. More...
 
#define msgb_eq_l2_data_print(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 2, msg, data, len, true)
 Compare and print: check L2 data in msgb against given data and print errors if any. More...
 
#define msgb_eq_l3_data_print(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 3, msg, data, len, true)
 Compare and print: check L3 data in msgb against given data and print errors if any. More...
 
#define msgb_eq_l4_data_print(msg, data, len)    _msgb_eq(__FILE__, __LINE__, __func__, 4, msg, data, len, true)
 Compare and print: check L4 data in msgb against given data and print errors if any. More...
 
#define msgb_eq(msg1, msg2)   msgb_eq_data(msg1, msgb_data(msg2), msgb_length(msg2))
 Compare msgbs. More...
 
#define msgb_eq_l1(msg1, msg2)   msgb_eq_l1_data(msg1, msgb_l1(msg2), msgb_l1len(msg2))
 Compare msgbs L1 content. More...
 
#define msgb_eq_l2(msg1, msg2)   msgb_eq_l2_data(msg1, msgb_l2(msg2), msgb_l2len(msg2))
 Compare msgbs L2 content. More...
 
#define msgb_eq_l3(msg1, msg2)   msgb_eq_l3_data(msg1, msgb_l3(msg2), msgb_l3len(msg2))
 Compare msgbs L3 content. More...
 
#define msgb_eq_l4(msg1, msg2)   msgb_eq_l4_data(msg1, msgb_l4(msg2), msgb_l4len(msg2))
 Compare msgbs L4 content. More...
 

Functions

struct msgbmsgb_alloc_c (const void *ctx, uint16_t size, const char *name)
 Allocate a new message buffer from given talloc context. More...
 
struct msgbmsgb_alloc (uint16_t size, const char *name)
 Allocate a new message buffer from tall_msgb_ctx. More...
 
void msgb_free (struct msgb *m)
 Release given message buffer. More...
 
void msgb_enqueue (struct llist_head *queue, struct msgb *msg)
 Enqueue message buffer to tail of a queue. More...
 
struct msgbmsgb_dequeue (struct llist_head *queue)
 Dequeue message buffer from head of queue. More...
 
void msgb_reset (struct msgb *msg)
 Re-set all message buffer pointers. More...
 
uint16_t msgb_length (const struct msgb *msg)
 get length of message buffer More...
 
const char * msgb_hexdump (const struct msgb *msg)
 Return a (static) buffer containing a hexdump of the msg. More...
 
char * msgb_hexdump_buf (char *buf, size_t buf_len, const struct msgb *msg)
 fill user-provided buffer with hexdump of the msg. More...
 
char * msgb_hexdump_c (const void *ctx, const struct msgb *msg)
 Return a dynamically allocated buffer containing a hexdump of the msg. More...
 
int msgb_resize_area (struct msgb *msg, uint8_t *area, int old_size, int new_size)
 Resize an area within an msgb. More...
 
struct msgbmsgb_copy (const struct msgb *msg, const char *name)
 Copy an msgb. More...
 
struct msgbmsgb_copy_c (const void *ctx, const struct msgb *msg, const char *name)
 Copy an msgb. More...
 
struct msgbmsgb_copy_resize (const struct msgb *msg, uint16_t new_len, const char *name)
 Copy an msgb with memory reallocation. More...
 
struct msgbmsgb_copy_resize_c (const void *ctx, const struct msgb *msg, uint16_t new_len, const char *name)
 Copy an msgb with memory reallocation. More...
 
static int msgb_test_invariant (const struct msgb *msg)
 Check a message buffer for consistency. More...
 
static void msgb_queue_free (struct llist_head *queue)
 Free all msgbs from a queue built with msgb_enqueue(). More...
 
static void msgb_enqueue_count (struct llist_head *queue, struct msgb *msg, unsigned int *count)
 Enqueue message buffer to tail of a queue and increment queue size counter. More...
 
static struct msgbmsgb_dequeue_count (struct llist_head *queue, unsigned int *count)
 Dequeue message buffer from head of queue and decrement queue size counter. More...
 
static unsigned int msgb_l1len (const struct msgb *msgb)
 determine length of L1 message More...
 
static unsigned int msgb_l2len (const struct msgb *msgb)
 determine length of L2 message More...
 
static unsigned int msgb_l3len (const struct msgb *msgb)
 determine length of L3 message More...
 
static unsigned int msgb_l4len (const struct msgb *msgb)
 determine length of L4 message More...
 
static unsigned int msgb_headlen (const struct msgb *msgb)
 determine the length of the header More...
 
static int msgb_tailroom (const struct msgb *msgb)
 determine how much tail room is left in msgb More...
 
static int msgb_headroom (const struct msgb *msgb)
 determine the amount of headroom in msgb More...
 
static unsigned char * msgb_put (struct msgb *msgb, unsigned int len)
 append data to end of message buffer More...
 
static void msgb_put_u8 (struct msgb *msgb, uint8_t word)
 append a uint8 value to the end of the message More...
 
static void msgb_put_u16 (struct msgb *msgb, uint16_t word)
 append a uint16 value to the end of the message More...
 
static void msgb_put_u32 (struct msgb *msgb, uint32_t word)
 append a uint32 value to the end of the message More...
 
static unsigned char * msgb_get (struct msgb *msgb, unsigned int len)
 remove data from end of message More...
 
static uint8_t msgb_get_u8 (struct msgb *msgb)
 remove uint8 from end of message More...
 
static uint16_t msgb_get_u16 (struct msgb *msgb)
 remove uint16 from end of message More...
 
static uint32_t msgb_get_u32 (struct msgb *msgb)
 remove uint32 from end of message More...
 
static unsigned char * msgb_push (struct msgb *msgb, unsigned int len)
 prepend (push) some data to start of message More...
 
static void msgb_push_u8 (struct msgb *msg, uint8_t word)
 prepend a uint8 value to the head of the message More...
 
static void msgb_push_u16 (struct msgb *msg, uint16_t word)
 prepend a uint16 value to the head of the message More...
 
static void msgb_push_u32 (struct msgb *msg, uint32_t word)
 prepend a uint32 value to the head of the message More...
 
static unsigned char * msgb_push_tl (struct msgb *msgb, uint8_t tag)
 
static unsigned char * msgb_pull (struct msgb *msgb, unsigned int len)
 remove (pull) a header from the front of the message buffer More...
 
static unsigned char * msgb_pull_to_l3 (struct msgb *msg)
 remove (pull) all headers in front of l3h from the message buffer. More...
 
static unsigned char * msgb_pull_to_l2 (struct msgb *msg)
 remove (pull) all headers in front of l2h from the message buffer. More...
 
static uint8_t msgb_pull_u8 (struct msgb *msgb)
 remove uint8 from front of message More...
 
static uint16_t msgb_pull_u16 (struct msgb *msgb)
 remove uint16 from front of message More...
 
static uint32_t msgb_pull_u32 (struct msgb *msgb)
 remove uint32 from front of message More...
 
static void msgb_reserve (struct msgb *msg, int len)
 Increase headroom of empty msgb, reducing the tailroom. More...
 
static int msgb_trim (struct msgb *msg, int len)
 Trim the msgb to a given absolute length. More...
 
static int msgb_l3trim (struct msgb *msg, int l3len)
 Trim the msgb to a given layer3 length. More...
 
static struct msgbmsgb_alloc_headroom_c (const void *ctx, uint16_t size, uint16_t headroom, const char *name)
 Allocate message buffer with specified headroom from specified talloc context. More...
 
static struct msgbmsgb_alloc_headroom (uint16_t size, uint16_t headroom, const char *name)
 Allocate message buffer with specified headroom. More...
 
bool _msgb_eq (const char *file, size_t line, const char *func, uint8_t level, const struct msgb *msg, const uint8_t *data, size_t len, bool print)
 Compare and print: check data in msgb against given data and print errors if any. More...
 
uint8_t * msgb_data (const struct msgb *msg)
 get pointer to data section of message buffer More...
 
void * msgb_talloc_ctx_init (void *root_ctx, unsigned int pool_size)
 Initialize a msgb talloc context for msgb_alloc. More...
 
void msgb_set_talloc_ctx (void *ctx)
 Set the talloc context for msgb_alloc Deprecated, use msgb_talloc_ctx_init() instead. More...
 
int msgb_printf (struct msgb *msgb, const char *format,...)
 Print a string to the end of message buffer. More...
 
static const char * msgb_hexdump_l1 (const struct msgb *msg)
 
static const char * msgb_hexdump_l2 (const struct msgb *msg)
 
static const char * msgb_hexdump_l3 (const struct msgb *msg)
 
static const char * msgb_hexdump_l4 (const struct msgb *msg)
 

Variables

void * tall_msgb_ctx = NULL
 

Detailed Description

libosmocore message buffers, inspired by Linux kernel skbuff

Inspired by the 'struct skbuff' of the Linux kernel, we implement a 'struct msgb' which we use for handling network packets aka messages aka PDUs.

A msgb consists of

We have plenty of utility functions around the msgb:

Macro Definition Documentation

◆ MSGB_ABORT

#define MSGB_ABORT (   msg,
  fmt,
  args ... 
)
Value:
do { \
osmo_panic("msgb(%p): " fmt, msg, ## args); \
} while(0)

◆ MSGB_DEBUG

#define MSGB_DEBUG

◆ msgb_eq

#define msgb_eq (   msg1,
  msg2 
)    msgb_eq_data(msg1, msgb_data(msg2), msgb_length(msg2))

Compare msgbs.

Parameters
[in]msg1message buffer
[in]msg2reference message buffer
Returns
boolean indicating whether msgb content is equal

◆ msgb_eq_data

#define msgb_eq_data (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 0, msg, data, len, false)

Compare: check data in msgb against given data.

Parameters
[in]msgmessage buffer
[in]dataexpected data
[in]lenlength of data
Returns
boolean indicating whether msgb content is equal to the given data

◆ msgb_eq_data_print

#define msgb_eq_data_print (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 0, msg, data, len, true)

Compare and print: check data in msgb against given data and print errors if any.

Parameters
[in]msgmessage buffer
[in]dataexpected data
[in]lenlength of data
Returns
boolean indicating whether msgb content is equal to the given data

◆ msgb_eq_l1

#define msgb_eq_l1 (   msg1,
  msg2 
)    msgb_eq_l1_data(msg1, msgb_l1(msg2), msgb_l1len(msg2))

Compare msgbs L1 content.

Parameters
[in]msg1message buffer
[in]msg2reference message buffer
Returns
boolean indicating whether msgb L1 content is equal

◆ msgb_eq_l1_data

#define msgb_eq_l1_data (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 1, msg, data, len, false)

Compare: check L1 data in msgb against given data.

Parameters
[in]msgmessage buffer
[in]dataexpected L1 data
[in]lenlength of data
Returns
boolean indicating whether msgb L1 content is equal to the given data

◆ msgb_eq_l1_data_print

#define msgb_eq_l1_data_print (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 1, msg, data, len, true)

Compare and print: check L1 data in msgb against given data and print errors if any.

Parameters
[in]msgmessage buffer
[in]dataexpected L1 data
[in]lenlength of data
Returns
boolean indicating whether msgb L1 content is equal to the given data

◆ msgb_eq_l2

#define msgb_eq_l2 (   msg1,
  msg2 
)    msgb_eq_l2_data(msg1, msgb_l2(msg2), msgb_l2len(msg2))

Compare msgbs L2 content.

Parameters
[in]msg1message buffer
[in]msg2reference message buffer
Returns
boolean indicating whether msgb L2 content is equal

◆ msgb_eq_l2_data

#define msgb_eq_l2_data (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 2, msg, data, len, false)

Compare: check L2 data in msgb against given data.

Parameters
[in]msgmessage buffer
[in]dataexpected L2 data
[in]lenlength of data
Returns
boolean indicating whether msgb L2 content is equal to the given data

◆ msgb_eq_l2_data_print

#define msgb_eq_l2_data_print (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 2, msg, data, len, true)

Compare and print: check L2 data in msgb against given data and print errors if any.

Parameters
[in]msgmessage buffer
[in]dataexpected L2 data
[in]lenlength of data
Returns
boolean indicating whether msgb L2 content is equal to the given data

◆ msgb_eq_l3

#define msgb_eq_l3 (   msg1,
  msg2 
)    msgb_eq_l3_data(msg1, msgb_l3(msg2), msgb_l3len(msg2))

Compare msgbs L3 content.

Parameters
[in]msg1message buffer
[in]msg2reference message buffer
Returns
boolean indicating whether msgb L3 content is equal

◆ msgb_eq_l3_data

#define msgb_eq_l3_data (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 3, msg, data, len, false)

Compare: check L3 data in msgb against given data.

Parameters
[in]msgmessage buffer
[in]dataexpected L3 data
[in]lenlength of data
Returns
boolean indicating whether msgb L3 content is equal to the given data

◆ msgb_eq_l3_data_print

#define msgb_eq_l3_data_print (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 3, msg, data, len, true)

Compare and print: check L3 data in msgb against given data and print errors if any.

Parameters
[in]msgmessage buffer
[in]dataexpected L3 data
[in]lenlength of data
Returns
boolean indicating whether msgb L3 content is equal to the given data

◆ msgb_eq_l4

#define msgb_eq_l4 (   msg1,
  msg2 
)    msgb_eq_l4_data(msg1, msgb_l4(msg2), msgb_l4len(msg2))

Compare msgbs L4 content.

Parameters
[in]msg1message buffer
[in]msg2reference message buffer
Returns
boolean indicating whether msgb L4 content is equal

◆ msgb_eq_l4_data

#define msgb_eq_l4_data (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 4, msg, data, len, false)

Compare: check L4 data in msgb against given data.

Parameters
[in]msgmessage buffer
[in]dataexpected L4 data
[in]lenlength of data
Returns
boolean indicating whether msgb L4 content is equal to the given data

◆ msgb_eq_l4_data_print

#define msgb_eq_l4_data_print (   msg,
  data,
  len 
)     _msgb_eq(__FILE__, __LINE__, __func__, 4, msg, data, len, true)

Compare and print: check L4 data in msgb against given data and print errors if any.

Parameters
[in]msgmessage buffer
[in]dataexpected L4 data
[in]lenlength of data
Returns
boolean indicating whether msgb L4 content is equal to the given data

◆ msgb_l1

#define msgb_l1 (   m)    ((void *)((m)->l1h))

obtain L1 header of msgb

◆ msgb_l2

#define msgb_l2 (   m)    ((void *)((m)->l2h))

obtain L2 header of msgb

◆ msgb_l3

#define msgb_l3 (   m)    ((void *)((m)->l3h))

obtain L3 header of msgb

◆ msgb_l4

#define msgb_l4 (   m)    ((void *)((m)->l4h))

obtain L4 header of msgb

◆ msgb_sms

#define msgb_sms (   m)    msgb_l4(m)

obtain SMS header of msgb

Function Documentation

◆ _msgb_eq()

bool _msgb_eq ( const char *  file,
size_t  line,
const char *  func,
uint8_t  level,
const struct msgb msg,
const uint8_t *  data,
size_t  len,
bool  print 
)

Compare and print: check data in msgb against given data and print errors if any.

Parameters
[in]filetext prefix, usually FILE, ignored if print == false
[in]linenumeric prefix, usually LINE, ignored if print == false
[in]functext prefix, usually func, ignored if print == false
[in]levelwhile layer (L1, L2 etc) data should be compared against
[in]msgmessage buffer
[in]dataexpected data
[in]lenlength of data
[in]printboolean indicating whether we should print anything to stdout
Returns
boolean indicating whether msgb content is equal to a given data

This function is not intended to be called directly but rather used through corresponding macro wrappers.

References data, DLGLOBAL, file(), len(), level, LOGL_FATAL, LOGPC, LOGPSRC, msg, msgb_data(), msgb_hexdump(), msgb_hexdump_l1(), msgb_hexdump_l2(), msgb_hexdump_l3(), msgb_hexdump_l4(), msgb_l1, msgb_l1len(), msgb_l2, msgb_l2len(), msgb_l3, msgb_l3len(), msgb_l4, msgb_l4len(), msgb_length(), and osmo_hexdump().

◆ msgb_alloc()

struct msgb * msgb_alloc ( uint16_t  size,
const char *  name 
)

Allocate a new message buffer from tall_msgb_ctx.

Parameters
[in]sizeLength in octets, including headroom
[in]nameHuman-readable name to be associated with msgb
Returns
dynamically-allocated Message buffers

This function allocates a 'struct msgb' as well as the underlying memory buffer for the actual message data (size specified by size) using the talloc memory context previously set by msgb_set_talloc_ctx

References msgb_alloc_c(), name, and tall_msgb_ctx.

Referenced by _gsmtap_raw_output(), gsmtap_makemsg_ex(), msgb_alloc_headroom(), and tundev_decaps().

◆ msgb_alloc_c()

struct msgb * msgb_alloc_c ( const void *  ctx,
uint16_t  size,
const char *  name 
)

Allocate a new message buffer from given talloc context.

Parameters
[in]ctxtalloc context from which to allocate
[in]sizeLength in octets, including headroom
[in]nameHuman-readable name to be associated with msgb
Returns
dynamically-allocated Message buffers

This function allocates a 'struct msgb' as well as the underlying memory buffer for the actual message data (size specified by size) using the talloc memory context previously set by msgb_set_talloc_ctx

References DLGLOBAL, LOGL_FATAL, LOGP, msg, and name.

Referenced by _file_raw_output(), msgb_alloc(), msgb_alloc_headroom_c(), msgb_copy_resize_c(), osmo_soft_uart_flush_rx(), osmo_soft_uart_set_rx(), and osmo_soft_uart_tx_ubits().

◆ msgb_alloc_headroom()

static struct msgb * msgb_alloc_headroom ( uint16_t  size,
uint16_t  headroom,
const char *  name 
)
inlinestatic

Allocate message buffer with specified headroom.

Parameters
[in]sizesize in bytes, including headroom
[in]headroomheadroom in bytes
[in]namehuman-readable name
Returns
allocated message buffer with specified headroom

This function is a convenience wrapper around msgb_alloc followed by msgb_reserve in order to create a new Message buffers with user-specified amount of headroom.

References msg, msgb_alloc(), msgb_reserve(), name, OSMO_ASSERT, and OSMO_LIKELY.

Referenced by osmo_sercomm_alloc_msgb().

◆ msgb_alloc_headroom_c()

static struct msgb * msgb_alloc_headroom_c ( const void *  ctx,
uint16_t  size,
uint16_t  headroom,
const char *  name 
)
inlinestatic

Allocate message buffer with specified headroom from specified talloc context.

Parameters
[in]ctxtalloc context from which to allocate
[in]sizesize in bytes, including headroom
[in]headroomheadroom in bytes
[in]namehuman-readable name
Returns
allocated message buffer with specified headroom

This function is a convenience wrapper around msgb_alloc followed by msgb_reserve in order to create a new Message buffers with user-specified amount of headroom.

References msg, msgb_alloc_c(), msgb_reserve(), name, OSMO_ASSERT, and OSMO_LIKELY.

Referenced by iofd_msgb_alloc().

◆ msgb_copy()

struct msgb * msgb_copy ( const struct msgb msg,
const char *  name 
)

Copy an msgb.

This function allocates a new msgb, copies the data buffer of msg, and adjusts the pointers (incl l1h-l4h) accordingly. The cb part is not copied.

Parameters
[in]msgThe old msgb object
[in]nameHuman-readable name to be associated with msgb

References msg, msgb_copy_c(), name, and tall_msgb_ctx.

◆ msgb_copy_c()

struct msgb * msgb_copy_c ( const void *  ctx,
const struct msgb msg,
const char *  name 
)

Copy an msgb.

This function allocates a new msgb, copies the data buffer of msg, and adjusts the pointers (incl l1h-l4h) accordingly. The cb part is not copied.

Parameters
[in]ctxtalloc context on which allocation happens
[in]msgThe old msgb object
[in]nameHuman-readable name to be associated with msgb

References msg, msgb_copy_resize_c(), and name.

Referenced by msgb_copy().

◆ msgb_copy_resize()

struct msgb * msgb_copy_resize ( const struct msgb msg,
uint16_t  new_len,
const char *  name 
)

Copy an msgb with memory reallocation.

This function allocates a new msgb with new_len size, copies the data buffer of msg, and adjusts the pointers (incl l1h-l4h) accordingly. The cb part is not copied.

Parameters
[in]msgThe old msgb object
[in]nameHuman-readable name to be associated with new msgb

References msg, msgb_copy_resize_c(), name, and tall_msgb_ctx.

◆ msgb_copy_resize_c()

struct msgb * msgb_copy_resize_c ( const void *  ctx,
const struct msgb msg,
uint16_t  new_len,
const char *  name 
)

Copy an msgb with memory reallocation.

This function allocates a new msgb with new_len size, copies the data buffer of msg, and adjusts the pointers (incl l1h-l4h) accordingly. The cb part is not copied.

Parameters
[in]ctxtalloc context on which allocation happens
[in]msgThe old msgb object
[in]new_lenThe length of new msgb object
[in]nameHuman-readable name to be associated with new msgb

References _data, data, DLGLOBAL, head, l1h, l2h, l3h, l4h, len, LOGL_ERROR, LOGP, msg, msgb_alloc_c(), msgb_length(), name, and tail.

Referenced by msgb_copy_c(), and msgb_copy_resize().

◆ msgb_data()

uint8_t * msgb_data ( const struct msgb msg)

get pointer to data section of message buffer

Parameters
[in]msgmessage buffer
Returns
pointer to data section of message buffer

References msg.

Referenced by _file_raw_output(), _file_wq_write_cb(), _msgb_eq(), iofd_handle_segmentation(), log_target_file_switch_to_stream(), osmo_iofd_sendmsg_msgb(), osmo_iofd_sendto_msgb(), osmo_iofd_write_msgb(), tundev_decaps(), and tundev_write_cb().

◆ msgb_dequeue()

struct msgb * msgb_dequeue ( struct llist_head queue)

Dequeue message buffer from head of queue.

Parameters
[in]queuelinked list header of queue
Returns
message buffer (if any) or NULL if queue empty

The function will remove the first message buffer from the queue implemented by llist_head queue.

References list, llist_del(), llist_empty(), llist_entry, and llist_head::next.

Referenced by log_target_file_switch_to_stream(), msgb_dequeue_count(), msgb_queue_free(), osmo_sercomm_drv_pull(), and osmo_wqueue_clear().

◆ msgb_dequeue_count()

static struct msgb * msgb_dequeue_count ( struct llist_head queue,
unsigned int *  count 
)
inlinestatic

Dequeue message buffer from head of queue and decrement queue size counter.

Parameters
[in]queuelinked list header of queue
[in]countpointer to variable holding size of the queue
Returns
message buffer (if any) or NULL if queue empty

The function will remove the first message buffer from the queue implemented by llist_head queue using function msgb_enqueue_count, and decrement count, all if queue is not empty.

References msg, and msgb_dequeue().

Referenced by osmo_wqueue_bfd_cb(), and osmo_wqueue_set_maxlen().

◆ msgb_enqueue()

void msgb_enqueue ( struct llist_head queue,
struct msgb msg 
)

Enqueue message buffer to tail of a queue.

Parameters
[in]queuelinked list header of queue
[in]msgmessage buffer to be added to the queue

The function will append the specified message buffer msg to the queue implemented by llist_head queue

References llist_add_tail(), and msg.

Referenced by msgb_enqueue_count(), and osmo_sercomm_sendmsg().

◆ msgb_enqueue_count()

static void msgb_enqueue_count ( struct llist_head queue,
struct msgb msg,
unsigned int *  count 
)
inlinestatic

Enqueue message buffer to tail of a queue and increment queue size counter.

Parameters
[in]queuelinked list header of queue
[in]msgmessage buffer to be added to the queue
[in]countpointer to variable holding size of the queue

The function will append the specified message buffer msg to the queue implemented by llist_head queue using function msgb_enqueue_count, then increment count

References msg, and msgb_enqueue().

Referenced by osmo_wqueue_enqueue_quiet().

◆ msgb_free()

◆ msgb_get()

static unsigned char * msgb_get ( struct msgb msgb,
unsigned int  len 
)
inlinestatic

remove data from end of message

Parameters
[in]msgbmessage buffer
[in]lennumber of bytes to remove from end

References len(), len, MSGB_ABORT, msgb_length(), OSMO_UNLIKELY, and tail.

Referenced by msgb_get_u16(), msgb_get_u32(), and msgb_get_u8().

◆ msgb_get_u16()

static uint16_t msgb_get_u16 ( struct msgb msgb)
inlinestatic

remove uint16 from end of message

Parameters
[in]msgbmessage buffer
Returns
16bit value taken from end of msgb

References msgb_get(), and osmo_load16be().

◆ msgb_get_u32()

static uint32_t msgb_get_u32 ( struct msgb msgb)
inlinestatic

remove uint32 from end of message

Parameters
[in]msgbmessage buffer
Returns
32bit value taken from end of msgb

References msgb_get(), and osmo_load32be().

◆ msgb_get_u8()

static uint8_t msgb_get_u8 ( struct msgb msgb)
inlinestatic

remove uint8 from end of message

Parameters
[in]msgbmessage buffer
Returns
8bit value taken from end of msgb

References msgb_get().

◆ msgb_headlen()

static unsigned int msgb_headlen ( const struct msgb msgb)
inlinestatic

determine the length of the header

Parameters
[in]msgbmessage buffer
Returns
number of bytes between start of buffer and start of msg

This function computes the length difference between the underlying data buffer and the used section of the msgb.

References data_len, and len.

◆ msgb_headroom()

static int msgb_headroom ( const struct msgb msgb)
inlinestatic

determine the amount of headroom in msgb

Parameters
[in]msgbmessage buffer
Returns
number of bytes left ahead of message start in msgb

This function computes the amount of bytes left in the underlying data buffer before the start of the actual message.

References data, and head.

Referenced by msgb_push().

◆ msgb_hexdump()

const char * msgb_hexdump ( const struct msgb msg)

Return a (static) buffer containing a hexdump of the msg.

Parameters
[in]msgmessage buffer
Returns
a pointer to a static char array

References msg, and msgb_hexdump_buf().

Referenced by _msgb_eq().

◆ msgb_hexdump_buf()

char * msgb_hexdump_buf ( char *  buf,
size_t  buf_len,
const struct msgb msg 
)

fill user-provided buffer with hexdump of the msg.

Parameters
[out]bufcaller-allocated buffer for output string
[in]buf_lenlength of buf
[in]msgmessage buffer to be dumped
Returns
buf

References ARRAY_SIZE, msg, osmo_hexdump(), and start.

Referenced by msgb_hexdump(), and msgb_hexdump_c().

◆ msgb_hexdump_c()

char * msgb_hexdump_c ( const void *  ctx,
const struct msgb msg 
)

Return a dynamically allocated buffer containing a hexdump of the msg.

Parameters
[in]ctxtalloc context from where to allocate the output string
[in]msgmessage buffer
Returns
a pointer to a static char array

References msg, msgb_hexdump_buf(), and msgb_length().

◆ msgb_hexdump_l1()

static const char * msgb_hexdump_l1 ( const struct msgb msg)
inlinestatic

References msg, msgb_l1, msgb_l1len(), and osmo_hexdump().

Referenced by _msgb_eq().

◆ msgb_hexdump_l2()

static const char * msgb_hexdump_l2 ( const struct msgb msg)
inlinestatic

References msg, msgb_l2, msgb_l2len(), and osmo_hexdump().

Referenced by _msgb_eq().

◆ msgb_hexdump_l3()

static const char * msgb_hexdump_l3 ( const struct msgb msg)
inlinestatic

References msg, msgb_l3, msgb_l3len(), and osmo_hexdump().

Referenced by _msgb_eq().

◆ msgb_hexdump_l4()

static const char * msgb_hexdump_l4 ( const struct msgb msg)
inlinestatic

References msg, msgb_l4, msgb_l4len(), and osmo_hexdump().

Referenced by _msgb_eq().

◆ msgb_l1len()

static unsigned int msgb_l1len ( const struct msgb msgb)
inlinestatic

determine length of L1 message

Parameters
[in]msgbmessage buffer
Returns
size of L1 message in bytes

This function computes the number of bytes between the tail of the message and the layer 1 header.

References l1h, msgb_l1, OSMO_ASSERT, and tail.

Referenced by _msgb_eq(), and msgb_hexdump_l1().

◆ msgb_l2len()

static unsigned int msgb_l2len ( const struct msgb msgb)
inlinestatic

determine length of L2 message

Parameters
[in]msgbmessage buffer
Returns
size of L2 message in bytes

This function computes the number of bytes between the tail of the message and the layer 2 header.

References l2h, msgb_l2, OSMO_ASSERT, and tail.

Referenced by _msgb_eq(), and msgb_hexdump_l2().

◆ msgb_l3len()

static unsigned int msgb_l3len ( const struct msgb msgb)
inlinestatic

determine length of L3 message

Parameters
[in]msgbmessage buffer
Returns
size of L3 message in bytes

This function computes the number of bytes between the tail of the message and the layer 3 header.

References l3h, msgb_l3, OSMO_ASSERT, and tail.

Referenced by _msgb_eq(), and msgb_hexdump_l3().

◆ msgb_l3trim()

static int msgb_l3trim ( struct msgb msg,
int  l3len 
)
inlinestatic

Trim the msgb to a given layer3 length.

Parameters
[in]msgmessage buffer
[in]l3lennew layer3 length
Returns
0 in case of success, negative in case of error

References msg, and msgb_trim().

◆ msgb_l4len()

static unsigned int msgb_l4len ( const struct msgb msgb)
inlinestatic

determine length of L4 message

Parameters
[in]msgbmessage buffer
Returns
size of L4 message in bytes

This function computes the number of bytes between the tail of the message and the layer 4 header.

References l4h, msgb_l4, OSMO_ASSERT, and tail.

Referenced by _msgb_eq(), and msgb_hexdump_l4().

◆ msgb_length()

◆ msgb_printf()

int msgb_printf ( struct msgb msgb,
const char *  format,
  ... 
)

Print a string to the end of message buffer.

Parameters
[in]msgbmessage buffer.
[in]formatformat string.
Returns
0 on success, -EINVAL on error.

The resulting string is printed to the msgb without a trailing nul character. A nul following the data tail may be written as an implementation detail, but a trailing nul is never part of the msgb data in terms of msgb_length().

Note: the tailroom must always be one byte longer than the string to be written. The msgb is filled only up to tailroom=1. This is an implementation detail that allows leaving a nul character behind the valid data.

In case of error, the msgb remains unchanged, though data may have been written to the (unused) memory after the tail pointer.

References msgb_put(), msgb_tailroom(), OSMO_ASSERT, and tail.

◆ msgb_pull()

static unsigned char * msgb_pull ( struct msgb msgb,
unsigned int  len 
)
inlinestatic

remove (pull) a header from the front of the message buffer

Parameters
[in]msgbmessage buffer
[in]lennumber of octets to be pulled
Returns
pointer to new start of msgb

This function moves the data pointer of the Message buffers further back in the message, thereby shrinking the size of the message by len bytes.

References data, len(), len, MSGB_ABORT, msgb_length(), and OSMO_UNLIKELY.

Referenced by _file_wq_write_cb(), iofd_handle_send_completion(), msgb_pull_to_l2(), msgb_pull_to_l3(), msgb_pull_u16(), msgb_pull_u32(), and msgb_pull_u8().

◆ msgb_pull_to_l2()

static unsigned char * msgb_pull_to_l2 ( struct msgb msg)
inlinestatic

remove (pull) all headers in front of l2h from the message buffer.

Parameters
[in]msgmessage buffer with a valid l2h
Returns
pointer to new start of msgb (l2h)

This function moves the data pointer of the Message buffers further back in the message, thereby shrinking the size of the message. l1h will be cleared.

References msg, and msgb_pull().

◆ msgb_pull_to_l3()

static unsigned char * msgb_pull_to_l3 ( struct msgb msg)
inlinestatic

remove (pull) all headers in front of l3h from the message buffer.

Parameters
[in]msgmessage buffer with a valid l3h
Returns
pointer to new start of msgb (l3h)

This function moves the data pointer of the Message buffers further back in the message, thereby shrinking the size of the message. l1h and l2h will be cleared.

References msg, and msgb_pull().

◆ msgb_pull_u16()

static uint16_t msgb_pull_u16 ( struct msgb msgb)
inlinestatic

remove uint16 from front of message

Parameters
[in]msgbmessage buffer
Returns
16bit value taken from the front of msgb

References msgb_pull(), and osmo_load16be().

◆ msgb_pull_u32()

static uint32_t msgb_pull_u32 ( struct msgb msgb)
inlinestatic

remove uint32 from front of message

Parameters
[in]msgbmessage buffer
Returns
32bit value taken from the front of msgb

References msgb_pull(), and osmo_load32be().

◆ msgb_pull_u8()

static uint8_t msgb_pull_u8 ( struct msgb msgb)
inlinestatic

remove uint8 from front of message

Parameters
[in]msgbmessage buffer
Returns
8bit value taken from the front of msgb

References msgb_pull().

Referenced by suart_tx_bit().

◆ msgb_push()

static unsigned char * msgb_push ( struct msgb msgb,
unsigned int  len 
)
inlinestatic

prepend (push) some data to start of message

Parameters
[in]msgbmessage buffer
[in]lennumber of bytes to pre-pend
Returns
pointer to newly added portion at start of msgb

This function moves the data pointer of the Message buffers further to the front (by len bytes), thereby enlarging the message by len bytes.

The return value is a pointer to the newly added section in the beginning of the message. It can be used to fill/copy data into it.

References _data, data, data_len, head, len(), len, MSGB_ABORT, msgb_headroom(), msgb_tailroom(), and OSMO_UNLIKELY.

Referenced by msgb_push_tl(), msgb_push_u16(), msgb_push_u32(), msgb_push_u8(), and osmo_sercomm_sendmsg().

◆ msgb_push_tl()

static unsigned char * msgb_push_tl ( struct msgb msgb,
uint8_t  tag 
)
inlinestatic

References data, len, and msgb_push().

◆ msgb_push_u16()

static void msgb_push_u16 ( struct msgb msg,
uint16_t  word 
)
inlinestatic

prepend a uint16 value to the head of the message

Parameters
[in]msgmessage buffer
[in]wordunsigned 16bit byte to be prepended

References msg, msgb_push(), and osmo_store16be().

◆ msgb_push_u32()

static void msgb_push_u32 ( struct msgb msg,
uint32_t  word 
)
inlinestatic

prepend a uint32 value to the head of the message

Parameters
[in]msgmessage buffer
[in]wordunsigned 32bit byte to be prepended

References msg, msgb_push(), and osmo_store32be().

◆ msgb_push_u8()

static void msgb_push_u8 ( struct msgb msg,
uint8_t  word 
)
inlinestatic

prepend a uint8 value to the head of the message

Parameters
[in]msgmessage buffer
[in]wordunsigned 8bit byte to be prepended

References msg, and msgb_push().

◆ msgb_put()

static unsigned char * msgb_put ( struct msgb msgb,
unsigned int  len 
)
inlinestatic

append data to end of message buffer

Parameters
[in]msgbmessage buffer
[in]lennumber of bytes to append to message
Returns
pointer to start of newly-appended data

This function will move the tail pointer of the message buffer len bytes further, thus enlarging the message by len bytes.

The return value is a pointer to start of the newly added section at the end of the message and can be used for actually filling/copying data into it.

References _data, data_len, head, len(), len, MSGB_ABORT, msgb_tailroom(), OSMO_UNLIKELY, and tail.

Referenced by _file_raw_output(), _gsmtap_raw_output(), gsmtap_makemsg_ex(), iofd_handle_segmentation(), iofd_poll_ofd_cb_recvmsg_sendmsg(), msgb_printf(), msgb_put_u16(), msgb_put_u32(), msgb_put_u8(), osmo_sercomm_drv_rx_char(), osmo_stats_reporter_statsd_send(), and tundev_decaps().

◆ msgb_put_u16()

static void msgb_put_u16 ( struct msgb msgb,
uint16_t  word 
)
inlinestatic

append a uint16 value to the end of the message

Parameters
[in]msgbmessage buffer
[in]wordunsigned 16bit byte to be appended

References msgb_put(), and osmo_store16be().

◆ msgb_put_u32()

static void msgb_put_u32 ( struct msgb msgb,
uint32_t  word 
)
inlinestatic

append a uint32 value to the end of the message

Parameters
[in]msgbmessage buffer
[in]wordunsigned 32bit byte to be appended

References msgb_put(), and osmo_store32be().

◆ msgb_put_u8()

static void msgb_put_u8 ( struct msgb msgb,
uint8_t  word 
)
inlinestatic

append a uint8 value to the end of the message

Parameters
[in]msgbmessage buffer
[in]wordunsigned 8bit byte to be appended

References msgb_put().

Referenced by osmo_stats_reporter_statsd_send(), and suart_rx_ch().

◆ msgb_queue_free()

static void msgb_queue_free ( struct llist_head queue)
inlinestatic

Free all msgbs from a queue built with msgb_enqueue().

Parameters
[in]queuelist head of a msgb queue.

References msg, msgb_dequeue(), and msgb_free().

◆ msgb_reserve()

static void msgb_reserve ( struct msgb msg,
int  len 
)
inlinestatic

Increase headroom of empty msgb, reducing the tailroom.

Parameters
[in]msgmessage buffer
[in]lenamount of extra octets to be reserved as headroom

This function reserves some memory at the beginning of the underlying data buffer. The idea is to reserve space in case further headers have to be pushed to the Message buffers during further processing.

Calling this function leads to undefined reusults if it is called on a non-empty Message buffers.

References len(), and msg.

Referenced by msgb_alloc_headroom(), and msgb_alloc_headroom_c().

◆ msgb_reset()

void msgb_reset ( struct msgb msg)

Re-set all message buffer pointers.

Parameters
[in]msgmessage buffer that is to be resetted

This will re-set the various internal pointers into the underlying message buffer, i.e. remove all headroom and treat the msgb as completely empty. It also initializes the control buffer to zero.

References msg.

Referenced by osmo_soft_uart_flush_rx().

◆ msgb_resize_area()

int msgb_resize_area ( struct msgb msg,
uint8_t *  area,
int  old_size,
int  new_size 
)

Resize an area within an msgb.

This resizes a sub area of the msgb data and adjusts the pointers (incl l1h-l4h) accordingly. The cb part is not updated. If the area is extended, the contents of the extension is undefined. The complete sub area must be a part of [data,tail].

Parameters
[in,out]msgThe msgb object
[in]areaA pointer to the sub-area
[in]old_sizeThe old size of the sub-area
[in]new_sizeThe new size of the sub-area
Returns
0 on success, -1 if there is not enough space to extend the area

References data, msg, MSGB_ABORT, and msgb_trim().

◆ msgb_set_talloc_ctx()

void msgb_set_talloc_ctx ( void *  ctx)

Set the talloc context for msgb_alloc Deprecated, use msgb_talloc_ctx_init() instead.

Parameters
[in]ctxtalloc context to be used as root for msgb allocations

References tall_msgb_ctx.

◆ msgb_tailroom()

static int msgb_tailroom ( const struct msgb msgb)
inlinestatic

determine how much tail room is left in msgb

Parameters
[in]msgbmessage buffer
Returns
number of bytes remaining at end of msgb

This function computes the amount of octets left in the underlying data buffer after the end of the message.

References data_len, head, and tail.

Referenced by _file_raw_output(), _gsmtap_raw_output(), iofd_poll_ofd_cb_recvmsg_sendmsg(), msgb_printf(), msgb_push(), msgb_put(), osmo_sercomm_drv_rx_char(), and osmo_stats_reporter_statsd_send().

◆ msgb_talloc_ctx_init()

void * msgb_talloc_ctx_init ( void *  root_ctx,
unsigned int  pool_size 
)

Initialize a msgb talloc context for msgb_alloc.

Create a talloc context called "msgb". If pool_size is 0, create a named const as msgb talloc context. If pool_size is nonzero, create a talloc pool, possibly for faster msgb allocations (see talloc_pool()).

Parameters
[in]root_ctxtalloc context used as parent for the new "msgb" ctx.
[in]pool_sizeif nonzero, create a talloc pool of this size.
Returns
the new msgb talloc context, e.g. for reporting

References tall_msgb_ctx.

◆ msgb_test_invariant()

static int msgb_test_invariant ( const struct msgb msg)
inlinestatic

Check a message buffer for consistency.

Parameters
[in]msgmessage buffer
Returns
0 (false) if inconsistent, != 0 (true) otherwise

References msg.

◆ msgb_trim()

static int msgb_trim ( struct msgb msg,
int  len 
)
inlinestatic

Trim the msgb to a given absolute length.

Parameters
[in]msgmessage buffer
[in]lennew total length of buffer
Returns
0 in case of success, negative in case of error

References len(), msg, MSGB_ABORT, and OSMO_UNLIKELY.

Referenced by msgb_l3trim(), msgb_resize_area(), and osmo_stats_reporter_statsd_send().

Variable Documentation

◆ tall_msgb_ctx

void* tall_msgb_ctx = NULL