Zephyr API Documentation
2.7.0-rc2
A Scalable Open Source RTOS
|
Network packet management library. More...
Data Structures | |
struct | net_pkt_cursor |
struct | net_pkt |
Network packet. More... | |
struct | net_pkt_data_access |
Macros | |
#define | NET_PKT_SLAB_DEFINE(name, count) K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4) |
Create a net_pkt slab. More... | |
#define | NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count) |
#define | NET_PKT_DATA_POOL_DEFINE(name, count) |
Create a data fragment net_buf pool. More... | |
#define | net_pkt_print_frags(pkt) |
Print fragment list and the fragment sizes. More... | |
#define | NET_PKT_DATA_ACCESS_DEFINE(_name, _type) |
#define | NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) |
Functions | |
struct net_buf * | net_pkt_get_reserve_rx_data (k_timeout_t timeout) |
Get RX DATA buffer from pool. Normally you should use net_pkt_get_frag() instead. More... | |
struct net_buf * | net_pkt_get_reserve_tx_data (k_timeout_t timeout) |
Get TX DATA buffer from pool. Normally you should use net_pkt_get_frag() instead. More... | |
struct net_buf * | net_pkt_get_frag (struct net_pkt *pkt, k_timeout_t timeout) |
Get a data fragment that might be from user specific buffer pool or from global DATA pool. More... | |
void | net_pkt_unref (struct net_pkt *pkt) |
Place packet back into the available packets slab. More... | |
struct net_pkt * | net_pkt_ref (struct net_pkt *pkt) |
Increase the packet ref count. More... | |
struct net_buf * | net_pkt_frag_ref (struct net_buf *frag) |
Increase the packet fragment ref count. More... | |
void | net_pkt_frag_unref (struct net_buf *frag) |
Decrease the packet fragment ref count. More... | |
struct net_buf * | net_pkt_frag_del (struct net_pkt *pkt, struct net_buf *parent, struct net_buf *frag) |
Delete existing fragment from a packet. More... | |
void | net_pkt_frag_add (struct net_pkt *pkt, struct net_buf *frag) |
Add a fragment to a packet at the end of its fragment list. More... | |
void | net_pkt_frag_insert (struct net_pkt *pkt, struct net_buf *frag) |
Insert a fragment to a packet at the beginning of its fragment list. More... | |
bool | net_pkt_compact (struct net_pkt *pkt) |
Compact the fragment list of a packet. More... | |
void | net_pkt_get_info (struct k_mem_slab **rx, struct k_mem_slab **tx, struct net_buf_pool **rx_data, struct net_buf_pool **tx_data) |
Get information about predefined RX, TX and DATA pools. More... | |
struct net_pkt * | net_pkt_alloc (k_timeout_t timeout) |
Allocate an initialized net_pkt. More... | |
struct net_pkt * | net_pkt_alloc_from_slab (struct k_mem_slab *slab, k_timeout_t timeout) |
Allocate an initialized net_pkt from a specific slab. More... | |
struct net_pkt * | net_pkt_rx_alloc (k_timeout_t timeout) |
Allocate an initialized net_pkt for RX. More... | |
struct net_pkt * | net_pkt_alloc_on_iface (struct net_if *iface, k_timeout_t timeout) |
Allocate a network packet for a specific network interface. More... | |
struct net_pkt * | net_pkt_rx_alloc_on_iface (struct net_if *iface, k_timeout_t timeout) |
int | net_pkt_alloc_buffer (struct net_pkt *pkt, size_t size, enum net_ip_protocol proto, k_timeout_t timeout) |
Allocate buffer for a net_pkt. More... | |
struct net_pkt * | net_pkt_alloc_with_buffer (struct net_if *iface, size_t size, sa_family_t family, enum net_ip_protocol proto, k_timeout_t timeout) |
Allocate a network packet and buffer at once. More... | |
struct net_pkt * | net_pkt_rx_alloc_with_buffer (struct net_if *iface, size_t size, sa_family_t family, enum net_ip_protocol proto, k_timeout_t timeout) |
void | net_pkt_append_buffer (struct net_pkt *pkt, struct net_buf *buffer) |
Append a buffer in packet. More... | |
size_t | net_pkt_available_buffer (struct net_pkt *pkt) |
Get available buffer space from a pkt. More... | |
size_t | net_pkt_available_payload_buffer (struct net_pkt *pkt, enum net_ip_protocol proto) |
Get available buffer space for payload from a pkt. More... | |
void | net_pkt_trim_buffer (struct net_pkt *pkt) |
Trim net_pkt buffer. More... | |
int | net_pkt_remove_tail (struct net_pkt *pkt, size_t length) |
Remove length bytes from tail of packet. More... | |
void | net_pkt_cursor_init (struct net_pkt *pkt) |
Initialize net_pkt cursor. More... | |
static void | net_pkt_cursor_backup (struct net_pkt *pkt, struct net_pkt_cursor *backup) |
Backup net_pkt cursor. More... | |
static void | net_pkt_cursor_restore (struct net_pkt *pkt, struct net_pkt_cursor *backup) |
Restore net_pkt cursor from a backup. More... | |
static void * | net_pkt_cursor_get_pos (struct net_pkt *pkt) |
Returns current position of the cursor. More... | |
int | net_pkt_skip (struct net_pkt *pkt, size_t length) |
Skip some data from a net_pkt. More... | |
int | net_pkt_memset (struct net_pkt *pkt, int byte, size_t length) |
Memset some data in a net_pkt. More... | |
int | net_pkt_copy (struct net_pkt *pkt_dst, struct net_pkt *pkt_src, size_t length) |
Copy data from a packet into another one. More... | |
struct net_pkt * | net_pkt_clone (struct net_pkt *pkt, k_timeout_t timeout) |
Clone pkt and its buffer. More... | |
struct net_pkt * | net_pkt_shallow_clone (struct net_pkt *pkt, k_timeout_t timeout) |
Clone pkt and increase the refcount of its buffer. More... | |
int | net_pkt_read (struct net_pkt *pkt, void *data, size_t length) |
Read some data from a net_pkt. More... | |
static int | net_pkt_read_u8 (struct net_pkt *pkt, uint8_t *data) |
int | net_pkt_read_be16 (struct net_pkt *pkt, uint16_t *data) |
Read uint16_t big endian data from a net_pkt. More... | |
int | net_pkt_read_le16 (struct net_pkt *pkt, uint16_t *data) |
Read uint16_t little endian data from a net_pkt. More... | |
int | net_pkt_read_be32 (struct net_pkt *pkt, uint32_t *data) |
Read uint32_t big endian data from a net_pkt. More... | |
int | net_pkt_write (struct net_pkt *pkt, const void *data, size_t length) |
Write data into a net_pkt. More... | |
static int | net_pkt_write_u8 (struct net_pkt *pkt, uint8_t data) |
static int | net_pkt_write_be16 (struct net_pkt *pkt, uint16_t data) |
static int | net_pkt_write_be32 (struct net_pkt *pkt, uint32_t data) |
static int | net_pkt_write_le32 (struct net_pkt *pkt, uint32_t data) |
static int | net_pkt_write_le16 (struct net_pkt *pkt, uint16_t data) |
size_t | net_pkt_remaining_data (struct net_pkt *pkt) |
Get the amount of data which can be read from current cursor position. More... | |
int | net_pkt_update_length (struct net_pkt *pkt, size_t length) |
Update the overall length of a packet. More... | |
int | net_pkt_pull (struct net_pkt *pkt, size_t length) |
Remove data from the packet at current location. More... | |
uint16_t | net_pkt_get_current_offset (struct net_pkt *pkt) |
Get the actual offset in the packet from its cursor. More... | |
bool | net_pkt_is_contiguous (struct net_pkt *pkt, size_t size) |
Check if a data size could fit contiguously. More... | |
size_t | net_pkt_get_contiguous_len (struct net_pkt *pkt) |
void * | net_pkt_get_data (struct net_pkt *pkt, struct net_pkt_data_access *access) |
Get data from a network packet in a contiguous way. More... | |
int | net_pkt_set_data (struct net_pkt *pkt, struct net_pkt_data_access *access) |
Set contiguous data into a network packet. More... | |
static int | net_pkt_acknowledge_data (struct net_pkt *pkt, struct net_pkt_data_access *access) |
Network packet management library.
#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE | ( | _name, | |
_type | |||
) |
#include <include/net/net_pkt.h>
#define NET_PKT_DATA_ACCESS_DEFINE | ( | _name, | |
_type | |||
) |
#include <include/net/net_pkt.h>
#define NET_PKT_DATA_POOL_DEFINE | ( | name, | |
count | |||
) |
#include <include/net/net_pkt.h>
Create a data fragment net_buf pool.
A net_buf pool is used to store actual data for network packets. It must be coupled with a net_pkt slab (:c:macro:NET_PKT_SLAB_DEFINE
) used to store the packet meta-information. The macro can be used by an application to define additional custom per-context TX packet pools (see :c:func:net_context_setup_pools
).
name | Name of the pool. |
count | Number of net_buf in this pool. |
#define net_pkt_print_frags | ( | pkt | ) |
#include <include/net/net_pkt.h>
Print fragment list and the fragment sizes.
Only available if debugging is activated.
pkt | Network pkt. |
#define NET_PKT_SLAB_DEFINE | ( | name, | |
count | |||
) | K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4) |
#include <include/net/net_pkt.h>
Create a net_pkt slab.
A net_pkt slab is used to store meta-information about network packets. It must be coupled with a data fragment pool (:c:macro:NET_PKT_DATA_POOL_DEFINE
) used to store the actual packet data. The macro can be used by an application to define additional custom per-context TX packet slabs (see :c:func:net_context_setup_pools
).
name | Name of the slab. |
count | Number of net_pkt in this slab. |
#define NET_PKT_TX_SLAB_DEFINE | ( | name, | |
count | |||
) | NET_PKT_SLAB_DEFINE(name, count) |
#include <include/net/net_pkt.h>
|
inlinestatic |
#include <include/net/net_pkt.h>
Acknowledge previously contiguous data taken from a network packet Packet needs to be set to overwrite mode.
struct net_pkt * net_pkt_alloc | ( | k_timeout_t | timeout | ) |
#include <include/net/net_pkt.h>
Allocate an initialized net_pkt.
for the time being, 2 pools are used. One for TX and one for RX. This allocator has to be used for TX.
timeout | Maximum time to wait for an allocation. |
int net_pkt_alloc_buffer | ( | struct net_pkt * | pkt, |
size_t | size, | ||
enum net_ip_protocol | proto, | ||
k_timeout_t | timeout | ||
) |
#include <include/net/net_pkt.h>
Allocate buffer for a net_pkt.
: such allocator will take into account space necessary for headers, MTU, and existing buffer (if any). Beware that, due to all these criteria, the allocated size might be smaller/bigger than requested one.
pkt | The network packet requiring buffer to be allocated. |
size | The size of buffer being requested. |
proto | The IP protocol type (can be 0 for none). |
timeout | Maximum time to wait for an allocation. |
struct net_pkt * net_pkt_alloc_from_slab | ( | struct k_mem_slab * | slab, |
k_timeout_t | timeout | ||
) |
#include <include/net/net_pkt.h>
Allocate an initialized net_pkt from a specific slab.
unlike net_pkt_alloc() which uses core slabs, this one will use an external slab (see NET_PKT_SLAB_DEFINE()). Do not use it unless you know what you are doing. Basically, only net_context should be using this, in order to allocate packet and then buffer on its local slab/pool (if any).
slab | The slab to use for allocating the packet |
timeout | Maximum time to wait for an allocation. |
struct net_pkt * net_pkt_alloc_on_iface | ( | struct net_if * | iface, |
k_timeout_t | timeout | ||
) |
#include <include/net/net_pkt.h>
Allocate a network packet for a specific network interface.
iface | The network interface the packet is supposed to go through. |
timeout | Maximum time to wait for an allocation. |
struct net_pkt * net_pkt_alloc_with_buffer | ( | struct net_if * | iface, |
size_t | size, | ||
sa_family_t | family, | ||
enum net_ip_protocol | proto, | ||
k_timeout_t | timeout | ||
) |
#include <include/net/net_pkt.h>
Allocate a network packet and buffer at once.
iface | The network interface the packet is supposed to go through. |
size | The size of buffer. |
family | The family to which the packet belongs. |
proto | The IP protocol type (can be 0 for none). |
timeout | Maximum time to wait for an allocation. |
#include <include/net/net_pkt.h>
Append a buffer in packet.
pkt | Network packet where to append the buffer |
buffer | Buffer to append |
size_t net_pkt_available_buffer | ( | struct net_pkt * | pkt | ) |
#include <include/net/net_pkt.h>
Get available buffer space from a pkt.
pkt | The net_pkt which buffer availability should be evaluated |
size_t net_pkt_available_payload_buffer | ( | struct net_pkt * | pkt, |
enum net_ip_protocol | proto | ||
) |
#include <include/net/net_pkt.h>
Get available buffer space for payload from a pkt.
Unlike net_pkt_available_buffer(), this will take into account the headers space.
pkt | The net_pkt which payload buffer availability should be evaluated |
proto | The IP protocol type (can be 0 for none). |
struct net_pkt * net_pkt_clone | ( | struct net_pkt * | pkt, |
k_timeout_t | timeout | ||
) |
#include <include/net/net_pkt.h>
Clone pkt and its buffer.
pkt | Original pkt to be cloned |
timeout | Timeout to wait for free buffer |
#include <include/net/net_pkt.h>
Compact the fragment list of a packet.
After this there is no more any free space in individual fragments.
pkt | Network packet. |
#include <include/net/net_pkt.h>
Copy data from a packet into another one.
Both net_pkt cursors should be properly initialized and, if needed, positioned using net_pkt_skip. The cursors will be updated after the operation.
pkt_dst | Destination network packet. |
pkt_src | Source network packet. |
length | Length of data to be copied. |
|
inlinestatic |
#include <include/net/net_pkt.h>
Backup net_pkt cursor.
#include <include/net/net_pkt.h>
Returns current position of the cursor.
pkt | The net_pkt whose cursor position is going to be returned |
#include <include/net/net_pkt.h>
Initialize net_pkt cursor.
This will initialize the net_pkt cursor from its buffer.
pkt | The net_pkt whose cursor is going to be initialized |
|
inlinestatic |
#include <include/net/net_pkt.h>
Restore net_pkt cursor from a backup.
#include <include/net/net_pkt.h>
Add a fragment to a packet at the end of its fragment list.
pkt | pkt Network packet where to add the fragment |
frag | Fragment to add |
struct net_buf * net_pkt_frag_del | ( | struct net_pkt * | pkt, |
struct net_buf * | parent, | ||
struct net_buf * | frag | ||
) |
#include <include/net/net_pkt.h>
Delete existing fragment from a packet.
pkt | Network packet from which frag belongs to. |
parent | parent fragment of frag, or NULL if none. |
frag | Fragment to delete. |
#include <include/net/net_pkt.h>
Insert a fragment to a packet at the beginning of its fragment list.
pkt | pkt Network packet where to insert the fragment |
frag | Fragment to insert |
#include <include/net/net_pkt.h>
Increase the packet fragment ref count.
Mark the fragment to be used still.
frag | Network fragment to ref. |
#include <include/net/net_pkt.h>
Decrease the packet fragment ref count.
frag | Network fragment to unref. |
size_t net_pkt_get_contiguous_len | ( | struct net_pkt * | pkt | ) |
#include <include/net/net_pkt.h>
Get the contiguous buffer space
pkt | Network packet |
#include <include/net/net_pkt.h>
Get the actual offset in the packet from its cursor.
pkt | Network packet. |
void * net_pkt_get_data | ( | struct net_pkt * | pkt, |
struct net_pkt_data_access * | access | ||
) |
#include <include/net/net_pkt.h>
Get data from a network packet in a contiguous way.
net_pkt's cursor should be properly initialized and, if needed, positioned using net_pkt_skip. Cursor position will be updated after the operation.
pkt | The network packet from where to get the data. |
access | A pointer to a valid net_pkt_data_access describing the data to get in a contiguous way. |
struct net_buf * net_pkt_get_frag | ( | struct net_pkt * | pkt, |
k_timeout_t | timeout | ||
) |
#include <include/net/net_pkt.h>
Get a data fragment that might be from user specific buffer pool or from global DATA pool.
pkt | Network packet. |
timeout | Affects the action taken should the net buf pool be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait up to the specified time. |
void net_pkt_get_info | ( | struct k_mem_slab ** | rx, |
struct k_mem_slab ** | tx, | ||
struct net_buf_pool ** | rx_data, | ||
struct net_buf_pool ** | tx_data | ||
) |
#include <include/net/net_pkt.h>
Get information about predefined RX, TX and DATA pools.
rx | Pointer to RX pool is returned. |
tx | Pointer to TX pool is returned. |
rx_data | Pointer to RX DATA pool is returned. |
tx_data | Pointer to TX DATA pool is returned. |
struct net_buf * net_pkt_get_reserve_rx_data | ( | k_timeout_t | timeout | ) |
#include <include/net/net_pkt.h>
Get RX DATA buffer from pool. Normally you should use net_pkt_get_frag() instead.
Normally this version is not useful for applications but is mainly used by network fragmentation code.
timeout | Affects the action taken should the net buf pool be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait up to the specified time. |
struct net_buf * net_pkt_get_reserve_tx_data | ( | k_timeout_t | timeout | ) |
#include <include/net/net_pkt.h>
Get TX DATA buffer from pool. Normally you should use net_pkt_get_frag() instead.
Normally this version is not useful for applications but is mainly used by network fragmentation code.
timeout | Affects the action taken should the net buf pool be empty. If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as long as necessary. Otherwise, wait up to the specified time. |
#include <include/net/net_pkt.h>
Check if a data size could fit contiguously.
net_pkt's cursor should be properly initialized and, if needed, positioned using net_pkt_skip.
pkt | Network packet. |
size | The size to check for contiguity |
int net_pkt_memset | ( | struct net_pkt * | pkt, |
int | byte, | ||
size_t | length | ||
) |
#include <include/net/net_pkt.h>
Memset some data in a net_pkt.
net_pkt's cursor should be properly initialized and, if needed, positioned using net_pkt_skip. Cursor position will be updated after the operation.
pkt | The net_pkt whose buffer to fill starting at the current cursor position. |
byte | The byte to write in memory |
length | Amount of data to memset with given byte |
int net_pkt_pull | ( | struct net_pkt * | pkt, |
size_t | length | ||
) |
#include <include/net/net_pkt.h>
Remove data from the packet at current location.
net_pkt's cursor should be properly initialized and, eventually, properly positioned using net_pkt_skip/read/write. Note that net_pkt's cursor is reset by this function.
pkt | Network packet |
length | Number of bytes to be removed |
#include <include/net/net_pkt.h>
Read some data from a net_pkt.
net_pkt's cursor should be properly initialized and, if needed, positioned using net_pkt_skip. Cursor position will be updated after the operation.
pkt | The network packet from where to read some data |
data | The destination buffer where to copy the data |
length | The amount of data to copy |
#include <include/net/net_pkt.h>
Read uint16_t big endian data from a net_pkt.
net_pkt's cursor should be properly initialized and, if needed, positioned using net_pkt_skip. Cursor position will be updated after the operation.
pkt | The network packet from where to read |
data | The destination uint16_t where to copy the data |
#include <include/net/net_pkt.h>
Read uint32_t big endian data from a net_pkt.
net_pkt's cursor should be properly initialized and, if needed, positioned using net_pkt_skip. Cursor position will be updated after the operation.
pkt | The network packet from where to read |
data | The destination uint32_t where to copy the data |
#include <include/net/net_pkt.h>
Read uint16_t little endian data from a net_pkt.
net_pkt's cursor should be properly initialized and, if needed, positioned using net_pkt_skip. Cursor position will be updated after the operation.
pkt | The network packet from where to read |
data | The destination uint16_t where to copy the data |
#include <include/net/net_pkt.h>
#include <include/net/net_pkt.h>
Increase the packet ref count.
Mark the packet to be used still.
pkt | Network packet to ref. |
size_t net_pkt_remaining_data | ( | struct net_pkt * | pkt | ) |
#include <include/net/net_pkt.h>
Get the amount of data which can be read from current cursor position.
pkt | Network packet |
int net_pkt_remove_tail | ( | struct net_pkt * | pkt, |
size_t | length | ||
) |
#include <include/net/net_pkt.h>
Remove length bytes from tail of packet.
This function does not take packet cursor into account. It is a helper to remove unneeded bytes from tail of packet (like appended CRC). It takes care of buffer deallocation if removed bytes span whole buffer(s).
pkt | Network packet |
length | Number of bytes to be removed |
0 | On success. |
-EINVAL | If packet length is shorter than length. |
struct net_pkt * net_pkt_rx_alloc | ( | k_timeout_t | timeout | ) |
#include <include/net/net_pkt.h>
Allocate an initialized net_pkt for RX.
for the time being, 2 pools are used. One for TX and one for RX. This allocator has to be used for RX.
timeout | Maximum time to wait for an allocation. |
struct net_pkt * net_pkt_rx_alloc_on_iface | ( | struct net_if * | iface, |
k_timeout_t | timeout | ||
) |
#include <include/net/net_pkt.h>
struct net_pkt * net_pkt_rx_alloc_with_buffer | ( | struct net_if * | iface, |
size_t | size, | ||
sa_family_t | family, | ||
enum net_ip_protocol | proto, | ||
k_timeout_t | timeout | ||
) |
#include <include/net/net_pkt.h>
int net_pkt_set_data | ( | struct net_pkt * | pkt, |
struct net_pkt_data_access * | access | ||
) |
#include <include/net/net_pkt.h>
Set contiguous data into a network packet.
net_pkt's cursor should be properly initialized and, if needed, positioned using net_pkt_skip. Cursor position will be updated after the operation.
pkt | The network packet to where the data should be set. |
access | A pointer to a valid net_pkt_data_access describing the data to set. |
struct net_pkt * net_pkt_shallow_clone | ( | struct net_pkt * | pkt, |
k_timeout_t | timeout | ||
) |
#include <include/net/net_pkt.h>
Clone pkt and increase the refcount of its buffer.
pkt | Original pkt to be shallow cloned |
timeout | Timeout to wait for free packet |
int net_pkt_skip | ( | struct net_pkt * | pkt, |
size_t | length | ||
) |
#include <include/net/net_pkt.h>
Skip some data from a net_pkt.
net_pkt's cursor should be properly initialized Cursor position will be updated after the operation. Depending on the value of pkt->overwrite bit, this function will affect the buffer length or not. If it's true, it will advance the cursor to the requested length. If it's false, it will do the same but if the cursor was already also at the end of existing data, it will increment the buffer length. So in this case, its behavior is just like net_pkt_write or net_pkt_memset, difference being that it will not affect the buffer content itself (which may be just garbage then).
pkt | The net_pkt whose cursor will be updated to skip given amount of data from the buffer. |
length | Amount of data to skip in the buffer |
#include <include/net/net_pkt.h>
Trim net_pkt buffer.
This will basically check for unused buffers and deallocates them relevantly
pkt | The net_pkt which buffer will be trimmed |
#include <include/net/net_pkt.h>
Place packet back into the available packets slab.
Releases the packet to other use. This needs to be called by application after it has finished with the packet.
pkt | Network packet to release. |
int net_pkt_update_length | ( | struct net_pkt * | pkt, |
size_t | length | ||
) |
#include <include/net/net_pkt.h>
Update the overall length of a packet.
Unlike net_pkt_pull() below, this does not take packet cursor into account. It's mainly a helper dedicated for ipv4 and ipv6 input functions. It shrinks the overall length by given parameter.
pkt | Network packet |
length | The new length of the packet |
#include <include/net/net_pkt.h>
Write data into a net_pkt.
net_pkt's cursor should be properly initialized and, if needed, positioned using net_pkt_skip. Cursor position will be updated after the operation.
pkt | The network packet where to write |
data | Data to be written |
length | Length of the data to be written |
#include <include/net/net_pkt.h>
#include <include/net/net_pkt.h>
#include <include/net/net_pkt.h>
#include <include/net/net_pkt.h>
#include <include/net/net_pkt.h>