netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Netlink message batch helpers

This library provides helpers to batch several messages into one single datagram. More...

Collaboration diagram for Netlink message batch helpers:

Data Structures

struct  mnl_nlmsg_batch
 

Functions

struct mnl_nlmsg_batchmnl_nlmsg_batch_start (void *buf, size_t limit)
 mnl_nlmsg_batch_start - initialize a batch More...
 
 EXPORT_SYMBOL (mnl_nlmsg_batch_start)
 
void mnl_nlmsg_batch_stop (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_stop - release a batch More...
 
 EXPORT_SYMBOL (mnl_nlmsg_batch_stop)
 
bool mnl_nlmsg_batch_next (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_next - get room for the next message in the batch More...
 
 EXPORT_SYMBOL (mnl_nlmsg_batch_next)
 
void mnl_nlmsg_batch_reset (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_reset - reset the batch More...
 
 EXPORT_SYMBOL (mnl_nlmsg_batch_reset)
 
size_t mnl_nlmsg_batch_size (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_size - get current size of the batch More...
 
 EXPORT_SYMBOL (mnl_nlmsg_batch_size)
 
void * mnl_nlmsg_batch_head (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_head - get head of this batch More...
 
 EXPORT_SYMBOL (mnl_nlmsg_batch_head)
 
void * mnl_nlmsg_batch_current (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_current - returns current position in the batch More...
 
 EXPORT_SYMBOL (mnl_nlmsg_batch_current)
 
bool mnl_nlmsg_batch_is_empty (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_is_empty - check if there is any message in the batch More...
 
 EXPORT_SYMBOL (mnl_nlmsg_batch_is_empty)
 

Variables

struct mnl_nlmsg_batch __attribute__
 

Detailed Description

This library provides helpers to batch several messages into one single datagram.

These helpers do not perform strict memory boundary checkings.

The following figure represents a Netlink message batch:

|<-----------— MNL_SOCKET_BUFFER_SIZE ----------—>| |<-----------------— batch ---------------—>| | |--------—|--------—|--------—|--------—|--------—| |<- nlmsg ->|<- nlmsg ->|<- nlmsg ->|<- nlmsg ->|<- nlmsg ->| |--------—|--------—|--------—|--------—|--------—| ^ ^ | | message N message N+1

To start the batch, you have to call mnl_nlmsg_batch_start() and you can use mnl_nlmsg_batch_stop() to release it.

You have to invoke mnl_nlmsg_batch_next() to get room for a new message in the batch. If this function returns NULL, it means that the last message that was added (message N+1 in the figure above) does not fit the batch. Thus, you have to send the batch (which includes until message N) and, then, you have to call mnl_nlmsg_batch_reset() to re-initialize the batch (this moves message N+1 to the head of the buffer). For that reason, the buffer that you have to use to store the batch must be double of MNL_SOCKET_BUFFER_SIZE to ensure that the last message (message N+1) that did not fit into the batch is written inside valid memory boundaries.

Function Documentation

EXPORT_SYMBOL ( mnl_nlmsg_batch_start  )
EXPORT_SYMBOL ( mnl_nlmsg_batch_stop  )
EXPORT_SYMBOL ( mnl_nlmsg_batch_next  )
EXPORT_SYMBOL ( mnl_nlmsg_batch_reset  )
EXPORT_SYMBOL ( mnl_nlmsg_batch_size  )
EXPORT_SYMBOL ( mnl_nlmsg_batch_head  )
EXPORT_SYMBOL ( mnl_nlmsg_batch_current  )
EXPORT_SYMBOL ( mnl_nlmsg_batch_is_empty  )
void* mnl_nlmsg_batch_current ( struct mnl_nlmsg_batch b)

mnl_nlmsg_batch_current - returns current position in the batch

Parameters
bpointer to batch

This function returns a pointer to the current position in the buffer that is used to store the batch.

References mnl_nlmsg_batch::cur.

Referenced by mnl_batch_supported(), and nft_batch_is_supported().

Here is the caller graph for this function:

void* mnl_nlmsg_batch_head ( struct mnl_nlmsg_batch b)

mnl_nlmsg_batch_head - get head of this batch

Parameters
bpointer to batch

This function returns a pointer to the head of the batch, which is the beginning of the buffer that is used.

References mnl_nlmsg_batch::buf.

Referenced by mnl_batch_supported(), nft_batch_is_supported(), and nft_fini().

Here is the caller graph for this function:

bool mnl_nlmsg_batch_is_empty ( struct mnl_nlmsg_batch b)

mnl_nlmsg_batch_is_empty - check if there is any message in the batch

Parameters
bpointer to batch

This function returns true if the batch is empty.

References mnl_nlmsg_batch::buflen.

Referenced by mnl_batch_talk().

Here is the caller graph for this function:

bool mnl_nlmsg_batch_next ( struct mnl_nlmsg_batch b)

mnl_nlmsg_batch_next - get room for the next message in the batch

Parameters
bpointer to batch

This function returns false if the last message did not fit into the batch. Otherwise, it prepares the batch to provide room for the new Netlink message in the batch and returns true.

You have to put at least one message in the batch before calling this function, otherwise your application is likely to crash.

References mnl_nlmsg_batch::buf, mnl_nlmsg_batch::buflen, mnl_nlmsg_batch::cur, mnl_nlmsg_batch::limit, nlmsghdr::nlmsg_len, and mnl_nlmsg_batch::overflow.

Referenced by mnl_batch_supported(), and nft_batch_is_supported().

Here is the caller graph for this function:

void mnl_nlmsg_batch_reset ( struct mnl_nlmsg_batch b)

mnl_nlmsg_batch_reset - reset the batch

Parameters
bpointer to batch

This function allows to reset a batch, so you can reuse it to create a new one. This function moves the last message which does not fit the batch to the head of the buffer, if any.

References mnl_nlmsg_batch::buf, mnl_nlmsg_batch::buflen, mnl_nlmsg_batch::cur, nlmsghdr::nlmsg_len, and mnl_nlmsg_batch::overflow.

size_t mnl_nlmsg_batch_size ( struct mnl_nlmsg_batch b)

mnl_nlmsg_batch_size - get current size of the batch

Parameters
bpointer to batch

This function returns the current size of the batch.

References mnl_nlmsg_batch::buflen.

Referenced by mnl_batch_ready(), mnl_batch_supported(), and nft_batch_is_supported().

Here is the caller graph for this function:

struct mnl_nlmsg_batch* mnl_nlmsg_batch_start ( void *  buf,
size_t  limit 
)

mnl_nlmsg_batch_start - initialize a batch

Parameters
bufpointer to the buffer that will store this batch
limitmaximum size of the batch (should be MNL_SOCKET_BUFFER_SIZE).

The buffer that you pass must be double of MNL_SOCKET_BUFFER_SIZE. The limit must be half of the buffer size, otherwise expect funny memory corruptions 8-).

You can allocate the buffer that you use to store the batch in the stack or the heap, no restrictions in this regard. This function returns NULL on error.

References buf, mnl_nlmsg_batch::buf, mnl_nlmsg_batch::buflen, mnl_nlmsg_batch::cur, mnl_nlmsg_batch::limit, NULL, and mnl_nlmsg_batch::overflow.

Referenced by mnl_batch_supported(), and nft_batch_is_supported().

Here is the caller graph for this function:

void mnl_nlmsg_batch_stop ( struct mnl_nlmsg_batch b)

mnl_nlmsg_batch_stop - release a batch

Parameters
bpointer to batch

This function releases the batch allocated by mnl_nlmsg_batch_start().

Referenced by mnl_batch_supported(), nft_batch_is_supported(), and nft_fini().

Here is the caller graph for this function:

Variable Documentation

struct mnl_nlmsg_batch __attribute__