Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Network Packet Library

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_bufnet_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_bufnet_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_bufnet_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_pktnet_pkt_ref (struct net_pkt *pkt)
 Increase the packet ref count. More...
 
struct net_bufnet_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_bufnet_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_pktnet_pkt_alloc (k_timeout_t timeout)
 Allocate an initialized net_pkt. More...
 
struct net_pktnet_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_pktnet_pkt_rx_alloc (k_timeout_t timeout)
 Allocate an initialized net_pkt for RX. More...
 
struct net_pktnet_pkt_alloc_on_iface (struct net_if *iface, k_timeout_t timeout)
 Allocate a network packet for a specific network interface. More...
 
struct net_pktnet_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_pktnet_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_pktnet_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 voidnet_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_pktnet_pkt_clone (struct net_pkt *pkt, k_timeout_t timeout)
 Clone pkt and its buffer. More...
 
struct net_pktnet_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)
 
voidnet_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)
 

Detailed Description

Network packet management library.

Macro Definition Documentation

◆ NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE

#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE (   _name,
  _type 
)

#include <include/net/net_pkt.h>

Value:
struct net_pkt_data_access _name = { \
.data = NULL, \
.size = sizeof(_type), \
}
Definition: net_pkt.h:2071
void * data
Definition: net_pkt.h:2073

◆ NET_PKT_DATA_ACCESS_DEFINE

#define NET_PKT_DATA_ACCESS_DEFINE (   _name,
  _type 
)

#include <include/net/net_pkt.h>

Value:
_type _hdr_##_name; \
struct net_pkt_data_access _name = { \
.data = &_hdr_##_name, \
.size = sizeof(_type), \
}

◆ NET_PKT_DATA_POOL_DEFINE

#define NET_PKT_DATA_POOL_DEFINE (   name,
  count 
)

#include <include/net/net_pkt.h>

Value:
NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
ZTEST_BMEM int count
Definition: main.c:33
#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy)
Define a new pool for buffers.
Definition: buf.h:1187
#define CONFIG_NET_BUF_USER_DATA_SIZE
Definition: buf.h:19

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).

Parameters
nameName of the pool.
countNumber of net_buf in this pool.

◆ net_pkt_print_frags

#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.

Parameters
pktNetwork pkt.

◆ NET_PKT_SLAB_DEFINE

#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).

Parameters
nameName of the slab.
countNumber of net_pkt in this slab.

◆ NET_PKT_TX_SLAB_DEFINE

#define NET_PKT_TX_SLAB_DEFINE (   name,
  count 
)    NET_PKT_SLAB_DEFINE(name, count)

Function Documentation

◆ net_pkt_acknowledge_data()

static int net_pkt_acknowledge_data ( struct net_pkt pkt,
struct net_pkt_data_access access 
)
inlinestatic

#include <include/net/net_pkt.h>

Acknowledge previously contiguous data taken from a network packet Packet needs to be set to overwrite mode.

◆ net_pkt_alloc()

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.

Parameters
timeoutMaximum time to wait for an allocation.
Returns
a pointer to a newly allocated net_pkt on success, NULL otherwise.

◆ net_pkt_alloc_buffer()

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.

Parameters
pktThe network packet requiring buffer to be allocated.
sizeThe size of buffer being requested.
protoThe IP protocol type (can be 0 for none).
timeoutMaximum time to wait for an allocation.
Returns
0 on success, negative errno code otherwise.

◆ net_pkt_alloc_from_slab()

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).

Parameters
slabThe slab to use for allocating the packet
timeoutMaximum time to wait for an allocation.
Returns
a pointer to a newly allocated net_pkt on success, NULL otherwise.

◆ net_pkt_alloc_on_iface()

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.

Parameters
ifaceThe network interface the packet is supposed to go through.
timeoutMaximum time to wait for an allocation.
Returns
a pointer to a newly allocated net_pkt on success, NULL otherwise.

◆ net_pkt_alloc_with_buffer()

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.

Parameters
ifaceThe network interface the packet is supposed to go through.
sizeThe size of buffer.
familyThe family to which the packet belongs.
protoThe IP protocol type (can be 0 for none).
timeoutMaximum time to wait for an allocation.
Returns
a pointer to a newly allocated net_pkt on success, NULL otherwise.

◆ net_pkt_append_buffer()

void net_pkt_append_buffer ( struct net_pkt pkt,
struct net_buf buffer 
)

#include <include/net/net_pkt.h>

Append a buffer in packet.

Parameters
pktNetwork packet where to append the buffer
bufferBuffer to append

◆ net_pkt_available_buffer()

size_t net_pkt_available_buffer ( struct net_pkt pkt)

#include <include/net/net_pkt.h>

Get available buffer space from a pkt.

Note
Reserved bytes (headroom) in any of the fragments are not considered to be available.
Parameters
pktThe net_pkt which buffer availability should be evaluated
Returns
the amount of buffer available

◆ net_pkt_available_payload_buffer()

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.

Note
Reserved bytes (headroom) in any of the fragments are not considered to be available.

Unlike net_pkt_available_buffer(), this will take into account the headers space.

Parameters
pktThe net_pkt which payload buffer availability should be evaluated
protoThe IP protocol type (can be 0 for none).
Returns
the amount of buffer available for payload

◆ net_pkt_clone()

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.

Parameters
pktOriginal pkt to be cloned
timeoutTimeout to wait for free buffer
Returns
NULL if error, cloned packet otherwise.

◆ net_pkt_compact()

bool net_pkt_compact ( struct net_pkt pkt)

#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.

Parameters
pktNetwork packet.
Returns
True if compact success, False otherwise.

◆ net_pkt_copy()

int net_pkt_copy ( struct net_pkt pkt_dst,
struct net_pkt pkt_src,
size_t  length 
)

#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.

Parameters
pkt_dstDestination network packet.
pkt_srcSource network packet.
lengthLength of data to be copied.
Returns
0 on success, negative errno code otherwise.

◆ net_pkt_cursor_backup()

static void net_pkt_cursor_backup ( struct net_pkt pkt,
struct net_pkt_cursor backup 
)
inlinestatic

#include <include/net/net_pkt.h>

Backup net_pkt cursor.

Parameters
pktThe net_pkt whose cursor is going to be backed up
backupThe cursor where to backup net_pkt cursor

◆ net_pkt_cursor_get_pos()

static void * net_pkt_cursor_get_pos ( struct net_pkt pkt)
inlinestatic

#include <include/net/net_pkt.h>

Returns current position of the cursor.

Parameters
pktThe net_pkt whose cursor position is going to be returned
Returns
cursor's position

◆ net_pkt_cursor_init()

void net_pkt_cursor_init ( struct net_pkt pkt)

#include <include/net/net_pkt.h>

Initialize net_pkt cursor.

This will initialize the net_pkt cursor from its buffer.

Parameters
pktThe net_pkt whose cursor is going to be initialized

◆ net_pkt_cursor_restore()

static void net_pkt_cursor_restore ( struct net_pkt pkt,
struct net_pkt_cursor backup 
)
inlinestatic

#include <include/net/net_pkt.h>

Restore net_pkt cursor from a backup.

Parameters
pktThe net_pkt whose cursor is going to be restored
backupThe cursor from where to restore net_pkt cursor

◆ net_pkt_frag_add()

void net_pkt_frag_add ( struct net_pkt pkt,
struct net_buf frag 
)

#include <include/net/net_pkt.h>

Add a fragment to a packet at the end of its fragment list.

Parameters
pktpkt Network packet where to add the fragment
fragFragment to add

◆ net_pkt_frag_del()

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.

Parameters
pktNetwork packet from which frag belongs to.
parentparent fragment of frag, or NULL if none.
fragFragment to delete.
Returns
Pointer to the following fragment, or NULL if it had no further fragments.

◆ net_pkt_frag_insert()

void net_pkt_frag_insert ( struct net_pkt pkt,
struct net_buf frag 
)

#include <include/net/net_pkt.h>

Insert a fragment to a packet at the beginning of its fragment list.

Parameters
pktpkt Network packet where to insert the fragment
fragFragment to insert

◆ net_pkt_frag_ref()

struct net_buf * net_pkt_frag_ref ( struct net_buf frag)

#include <include/net/net_pkt.h>

Increase the packet fragment ref count.

Mark the fragment to be used still.

Parameters
fragNetwork fragment to ref.
Returns
a pointer on the referenced Network fragment.

◆ net_pkt_frag_unref()

void net_pkt_frag_unref ( struct net_buf frag)

#include <include/net/net_pkt.h>

Decrease the packet fragment ref count.

Parameters
fragNetwork fragment to unref.

◆ net_pkt_get_contiguous_len()

size_t net_pkt_get_contiguous_len ( struct net_pkt pkt)

#include <include/net/net_pkt.h>

Get the contiguous buffer space

Parameters
pktNetwork packet
Returns
The available contiguous buffer space in bytes starting from the current cursor position. 0 in case of an error.

◆ net_pkt_get_current_offset()

uint16_t net_pkt_get_current_offset ( struct net_pkt pkt)

#include <include/net/net_pkt.h>

Get the actual offset in the packet from its cursor.

Parameters
pktNetwork packet.
Returns
a valid offset on success, 0 otherwise as there is nothing that can be done to evaluate the offset.

◆ net_pkt_get_data()

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.

Parameters
pktThe network packet from where to get the data.
accessA pointer to a valid net_pkt_data_access describing the data to get in a contiguous way.
Returns
a pointer to the requested contiguous data, NULL otherwise.

◆ net_pkt_get_frag()

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.

Parameters
pktNetwork packet.
timeoutAffects 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.
Returns
Network buffer if successful, NULL otherwise.

◆ net_pkt_get_info()

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.

Parameters
rxPointer to RX pool is returned.
txPointer to TX pool is returned.
rx_dataPointer to RX DATA pool is returned.
tx_dataPointer to TX DATA pool is returned.

◆ net_pkt_get_reserve_rx_data()

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.

Parameters
timeoutAffects 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.
Returns
Network buffer if successful, NULL otherwise.

◆ net_pkt_get_reserve_tx_data()

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.

Parameters
timeoutAffects 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.
Returns
Network buffer if successful, NULL otherwise.

◆ net_pkt_is_contiguous()

bool net_pkt_is_contiguous ( struct net_pkt pkt,
size_t  size 
)

#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.

Parameters
pktNetwork packet.
sizeThe size to check for contiguity
Returns
true if that is the case, false otherwise.

◆ net_pkt_memset()

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.

Parameters
pktThe net_pkt whose buffer to fill starting at the current cursor position.
byteThe byte to write in memory
lengthAmount of data to memset with given byte
Returns
0 in success, negative errno code otherwise.

◆ net_pkt_pull()

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.

Parameters
pktNetwork packet
lengthNumber of bytes to be removed
Returns
0 on success, negative errno code otherwise.

◆ net_pkt_read()

int net_pkt_read ( struct net_pkt pkt,
void data,
size_t  length 
)

#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.

Parameters
pktThe network packet from where to read some data
dataThe destination buffer where to copy the data
lengthThe amount of data to copy
Returns
0 on success, negative errno code otherwise.

◆ net_pkt_read_be16()

int net_pkt_read_be16 ( struct net_pkt pkt,
uint16_t data 
)

#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.

Parameters
pktThe network packet from where to read
dataThe destination uint16_t where to copy the data
Returns
0 on success, negative errno code otherwise.

◆ net_pkt_read_be32()

int net_pkt_read_be32 ( struct net_pkt pkt,
uint32_t 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.

Parameters
pktThe network packet from where to read
dataThe destination uint32_t where to copy the data
Returns
0 on success, negative errno code otherwise.

◆ net_pkt_read_le16()

int net_pkt_read_le16 ( struct net_pkt pkt,
uint16_t 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.

Parameters
pktThe network packet from where to read
dataThe destination uint16_t where to copy the data
Returns
0 on success, negative errno code otherwise.

◆ net_pkt_read_u8()

static int net_pkt_read_u8 ( struct net_pkt pkt,
uint8_t data 
)
inlinestatic

◆ net_pkt_ref()

struct net_pkt * net_pkt_ref ( struct net_pkt pkt)

#include <include/net/net_pkt.h>

Increase the packet ref count.

Mark the packet to be used still.

Parameters
pktNetwork packet to ref.
Returns
Network packet if successful, NULL otherwise.

◆ net_pkt_remaining_data()

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.

Parameters
pktNetwork packet
Returns
Amount of data which can be read from current pkt cursor

◆ net_pkt_remove_tail()

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).

Parameters
pktNetwork packet
lengthNumber of bytes to be removed
Return values
0On success.
-EINVALIf packet length is shorter than length.

◆ net_pkt_rx_alloc()

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.

Parameters
timeoutMaximum time to wait for an allocation.
Returns
a pointer to a newly allocated net_pkt on success, NULL otherwise.

◆ net_pkt_rx_alloc_on_iface()

struct net_pkt * net_pkt_rx_alloc_on_iface ( struct net_if iface,
k_timeout_t  timeout 
)

◆ net_pkt_rx_alloc_with_buffer()

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 
)

◆ net_pkt_set_data()

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.

Parameters
pktThe network packet to where the data should be set.
accessA pointer to a valid net_pkt_data_access describing the data to set.
Returns
0 on success, a negative errno otherwise.

◆ net_pkt_shallow_clone()

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.

Parameters
pktOriginal pkt to be shallow cloned
timeoutTimeout to wait for free packet
Returns
NULL if error, cloned packet otherwise.

◆ net_pkt_skip()

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).

Parameters
pktThe net_pkt whose cursor will be updated to skip given amount of data from the buffer.
lengthAmount of data to skip in the buffer
Returns
0 in success, negative errno code otherwise.

◆ net_pkt_trim_buffer()

void net_pkt_trim_buffer ( struct net_pkt pkt)

#include <include/net/net_pkt.h>

Trim net_pkt buffer.

This will basically check for unused buffers and deallocates them relevantly

Parameters
pktThe net_pkt which buffer will be trimmed

◆ net_pkt_unref()

void net_pkt_unref ( struct net_pkt pkt)

#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.

Parameters
pktNetwork packet to release.

◆ net_pkt_update_length()

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.

Parameters
pktNetwork packet
lengthThe new length of the packet
Returns
0 on success, negative errno code otherwise.

◆ net_pkt_write()

int net_pkt_write ( struct net_pkt pkt,
const void data,
size_t  length 
)

#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.

Parameters
pktThe network packet where to write
dataData to be written
lengthLength of the data to be written
Returns
0 on success, negative errno code otherwise.

◆ net_pkt_write_be16()

static int net_pkt_write_be16 ( struct net_pkt pkt,
uint16_t  data 
)
inlinestatic

◆ net_pkt_write_be32()

static int net_pkt_write_be32 ( struct net_pkt pkt,
uint32_t  data 
)
inlinestatic

◆ net_pkt_write_le16()

static int net_pkt_write_le16 ( struct net_pkt pkt,
uint16_t  data 
)
inlinestatic

◆ net_pkt_write_le32()

static int net_pkt_write_le32 ( struct net_pkt pkt,
uint32_t  data 
)
inlinestatic

◆ net_pkt_write_u8()

static int net_pkt_write_u8 ( struct net_pkt pkt,
uint8_t  data 
)
inlinestatic