Mistake on this page?
Report an issue in GitHub or email us
Data Structures | Macros | Enumerations
pbuf.h File Reference

pbuf API More...

#include "lwip/opt.h"
#include "lwip/err.h"

Go to the source code of this file.

Data Structures

struct  pbuf
 Main packet buffer struct. More...
 
struct  pbuf_rom
 Helper struct for const-correctness only. More...
 

Macros

#define LWIP_SUPPORT_CUSTOM_PBUF   ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
 LWIP_SUPPORT_CUSTOM_PBUF==1: Custom pbufs behave much like their pbuf type but they are allocated by external code (initialised by calling pbuf_alloced_custom()) and when pbuf_free gives up their last reference, they are freed by calling pbuf_custom->custom_free_function(). More...
 
#define PBUF_NEEDS_COPY(p)   ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE)
 PBUF_NEEDS_COPY(p): return a boolean value indicating whether the given pbuf needs to be copied in order to be kept around beyond the current call stack without risking being corrupted. More...
 
#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS   0x80
 Indicates that the payload directly follows the struct pbuf. More...
 
#define PBUF_TYPE_FLAG_DATA_VOLATILE   0x40
 Indicates the data stored in this pbuf can change. More...
 
#define PBUF_TYPE_ALLOC_SRC_MASK   0x0F
 4 bits are reserved for 16 allocation sources (e.g. More...
 
#define PBUF_ALLOC_FLAG_RX   0x0100
 Indicates this pbuf is used for RX (if not set, indicates use for TX). More...
 
#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS   0x0200
 Indicates the application needs the pbuf payload to be in one piece. More...
 
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN   0x03
 First pbuf allocation type for applications. More...
 
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX   PBUF_TYPE_ALLOC_SRC_MASK
 Last pbuf allocation type for applications. More...
 
#define PBUF_FLAG_PUSH   0x01U
 indicates this packet's data should be immediately passed to the application More...
 
#define PBUF_FLAG_IS_CUSTOM   0x02U
 indicates this is a custom pbuf: pbuf_free calls pbuf_custom->custom_free_function() when the last reference is released (plus custom PBUF_RAM cannot be trimmed) More...
 
#define PBUF_FLAG_MCASTLOOP   0x04U
 indicates this pbuf is UDP multicast to be looped back More...
 
#define PBUF_FLAG_LLBCAST   0x08U
 indicates this pbuf was received as link-level broadcast More...
 
#define PBUF_FLAG_LLMCAST   0x10U
 indicates this pbuf was received as link-level multicast More...
 
#define PBUF_FLAG_TCP_FIN   0x20U
 indicates this pbuf includes a TCP FIN flag More...
 
#define PBUF_POOL_FREE_OOSEQ   1
 Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty. More...
 

Enumerations

Detailed Description

pbuf API

Definition in file pbuf.h.

Macro Definition Documentation

#define LWIP_SUPPORT_CUSTOM_PBUF   ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))

LWIP_SUPPORT_CUSTOM_PBUF==1: Custom pbufs behave much like their pbuf type but they are allocated by external code (initialised by calling pbuf_alloced_custom()) and when pbuf_free gives up their last reference, they are freed by calling pbuf_custom->custom_free_function().

Currently, the pbuf_custom code is only needed for one specific configuration of IP_FRAG, unless required by external driver/application code.

Definition at line 55 of file pbuf.h.

#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS   0x0200

Indicates the application needs the pbuf payload to be in one piece.

Definition at line 131 of file pbuf.h.

#define PBUF_ALLOC_FLAG_RX   0x0100

Indicates this pbuf is used for RX (if not set, indicates use for TX).

This information can be used to keep some spare RX buffers e.g. for receiving TCP ACKs to unblock a connection)

Definition at line 129 of file pbuf.h.

#define PBUF_FLAG_IS_CUSTOM   0x02U

indicates this is a custom pbuf: pbuf_free calls pbuf_custom->custom_free_function() when the last reference is released (plus custom PBUF_RAM cannot be trimmed)

Definition at line 175 of file pbuf.h.

#define PBUF_FLAG_LLBCAST   0x08U

indicates this pbuf was received as link-level broadcast

Definition at line 179 of file pbuf.h.

#define PBUF_FLAG_LLMCAST   0x10U

indicates this pbuf was received as link-level multicast

Definition at line 181 of file pbuf.h.

#define PBUF_FLAG_MCASTLOOP   0x04U

indicates this pbuf is UDP multicast to be looped back

Definition at line 177 of file pbuf.h.

#define PBUF_FLAG_PUSH   0x01U

indicates this packet's data should be immediately passed to the application

Definition at line 172 of file pbuf.h.

#define PBUF_FLAG_TCP_FIN   0x20U

indicates this pbuf includes a TCP FIN flag

Definition at line 183 of file pbuf.h.

#define PBUF_NEEDS_COPY (   p)    ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE)

PBUF_NEEDS_COPY(p): return a boolean value indicating whether the given pbuf needs to be copied in order to be kept around beyond the current call stack without risking being corrupted.

The default setting provides safety: it will make a copy iof any pbuf chain that does not consist entirely of PBUF_ROM type pbufs. For setups with zero-copy support, it may be redefined to evaluate to true in all cases, for example. However, doing so also has an effect on the application side: any buffers that are not copied must also not be reused by the application after passing them to lwIP. For example, when setting PBUF_NEEDS_COPY to (0), after using udp_send() with a PBUF_RAM pbuf, the application must free the pbuf immediately, rather than reusing it for other purposes. For more background information on this, see tasks #6735 and #7896, and bugs #11400 and #49914.

Definition at line 72 of file pbuf.h.

#define PBUF_POOL_FREE_OOSEQ   1

Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty.

Definition at line 252 of file pbuf.h.

#define PBUF_TYPE_ALLOC_SRC_MASK   0x0F

4 bits are reserved for 16 allocation sources (e.g.

heap, pool1, pool2, etc) Internally, we use: 0=heap, 1=MEMP_PBUF, 2=MEMP_PBUF_POOL -> 13 types free

Definition at line 125 of file pbuf.h.

#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX   PBUF_TYPE_ALLOC_SRC_MASK

Last pbuf allocation type for applications.

Definition at line 139 of file pbuf.h.

#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN   0x03

First pbuf allocation type for applications.

Definition at line 137 of file pbuf.h.

#define PBUF_TYPE_FLAG_DATA_VOLATILE   0x40

Indicates the data stored in this pbuf can change.

If this pbuf needs to be queued, it must be copied/duplicated.

Definition at line 122 of file pbuf.h.

#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS   0x80

Indicates that the payload directly follows the struct pbuf.

This makes pbuf_header work in both directions.

Definition at line 119 of file pbuf.h.

Enumeration Type Documentation

enum pbuf_layer

Enumeration of pbuf layers.

Enumerator
PBUF_TRANSPORT 

Includes spare room for transport layer header, e.g.

UDP header. Use this if you intend to pass the pbuf to functions like udp_send().

PBUF_IP 

Includes spare room for IP header.

Use this if you intend to pass the pbuf to functions like raw_send().

PBUF_LINK 

Includes spare room for link layer header (ethernet header).

Use this if you intend to pass the pbuf to functions like ethernet_output().

See also
PBUF_LINK_HLEN
PBUF_RAW_TX 

Includes spare room for additional encapsulation header before ethernet headers (e.g.

802.11). Use this if you intend to pass the pbuf to functions like netif->linkoutput().

See also
PBUF_LINK_ENCAPSULATION_HLEN
PBUF_RAW 

Use this for input packets in a netif driver when calling netif->input() in the most common case - ethernet-layer netif driver.

Definition at line 89 of file pbuf.h.

enum pbuf_type

Enumeration of pbuf types.

Enumerator
PBUF_RAM 

pbuf data is stored in RAM, used for TX mostly, struct pbuf and its payload are allocated in one piece of contiguous memory (so the first payload byte can be calculated from struct pbuf).

pbuf_alloc() allocates PBUF_RAM pbufs as unchained pbufs (although that might change in future versions). This should be used for all OUTGOING packets (TX).

PBUF_ROM 

pbuf data is stored in ROM, i.e.

struct pbuf and its payload are located in totally different memory areas. Since it points to ROM, payload does not have to be copied when queued for transmission.

PBUF_REF 

pbuf comes from the pbuf pool.

Much like PBUF_ROM but payload might change so it has to be duplicated when queued before transmitting, depending on who has a 'ref' to it.

PBUF_POOL 

pbuf payload refers to RAM.

This one comes from a pool and should be used for RX. Payload can be chained (scatter-gather RX) but like PBUF_RAM, struct pbuf and its payload are allocated in one piece of contiguous memory (so the first payload byte can be calculated from struct pbuf). Don't use this for TX, if the pool becomes empty e.g. because of TCP queuing, you are unable to receive TCP acks!

Definition at line 145 of file pbuf.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.