Data Structures | |
struct | pbuf |
Macros | |
#define | LWIP_SUPPORT_CUSTOM_PBUF (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) |
Currently, the pbuf_custom code is only needed for one specific configuration of IP_FRAG. More... | |
#define | PBUF_CHECK_FREE_OOSEQ() |
When not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ() at regular intervals from main level to check if ooseq pbufs need to be freed! More... | |
#define | PBUF_FLAG_IS_CUSTOM 0x02U |
indicates this is a custom pbuf: pbuf_free and pbuf_header handle such a a pbuf differently 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_MCASTLOOP 0x04U |
indicates this pbuf is UDP multicast to be looped back More... | |
#define | PBUF_FLAG_PUSH 0x01U |
indicates this packet's data should be immediately passed to the application More... | |
#define | PBUF_FLAG_TCP_FIN 0x20U |
indicates this pbuf includes a TCP FIN flag More... | |
#define | pbuf_init() |
#define | PBUF_IP_HLEN 20 |
#define | PBUF_POOL_FREE_OOSEQ 1 |
Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty. More... | |
#define | PBUF_TRANSPORT_HLEN 20 |
Enumerations | |
enum | pbuf_layer { PBUF_TRANSPORT, PBUF_IP, PBUF_LINK, PBUF_RAW } |
enum | pbuf_type { PBUF_RAM, PBUF_ROM, PBUF_REF, PBUF_POOL } |
Functions | |
struct pbuf * | pbuf_alloc (pbuf_layer l, u16_t length, pbuf_type type) |
Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type). More... | |
void | pbuf_cat (struct pbuf *head, struct pbuf *tail) |
Concatenate two pbufs (each may be a pbuf chain) and take over the caller's reference of the tail pbuf. More... | |
void | pbuf_chain (struct pbuf *head, struct pbuf *tail) |
Chain two pbufs (or pbuf chains) together. More... | |
u8_t | pbuf_clen (struct pbuf *p) |
Count number of pbufs in a chain. More... | |
struct pbuf * | pbuf_coalesce (struct pbuf *p, pbuf_layer layer) |
Creates a single pbuf out of a queue of pbufs. More... | |
err_t | pbuf_copy (struct pbuf *p_to, struct pbuf *p_from) |
Create PBUF_RAM copies of pbufs. More... | |
u16_t | pbuf_copy_partial (struct pbuf *p, void *dataptr, u16_t len, u16_t offset) |
Copy (part of) the contents of a packet buffer to an application supplied buffer. More... | |
struct pbuf * | pbuf_dechain (struct pbuf *p) |
Dechains the first pbuf from its succeeding pbufs in the chain. More... | |
u8_t | pbuf_free (struct pbuf *p) |
Dereference a pbuf chain or queue and deallocate any no-longer-used pbufs at the head of this chain or queue. More... | |
void | pbuf_free_ooseq () |
Attempt to reclaim some memory from queued out-of-sequence TCP segments if we run out of pool pbufs. More... | |
u8_t | pbuf_get_at (struct pbuf *p, u16_t offset) |
Get one byte from the specified position in a pbuf WARNING: returns zero for offset >= p->tot_len. More... | |
u8_t | pbuf_header (struct pbuf *p, s16_t header_size) |
Adjusts the payload pointer to hide or reveal headers in the payload. More... | |
u16_t | pbuf_memcmp (struct pbuf *p, u16_t offset, const void *s2, u16_t n) |
Compare pbuf contents at specified offset with memory s2, both of length n. More... | |
u16_t | pbuf_memfind (struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset) |
Find occurrence of mem (with length mem_len) in pbuf p, starting at offset start_offset. More... | |
void | pbuf_realloc (struct pbuf *p, u16_t size) |
Shrink a pbuf chain to a desired length. More... | |
void | pbuf_ref (struct pbuf *p) |
Increment the reference count of the pbuf. More... | |
u16_t | pbuf_strstr (struct pbuf *p, const char *substr) |
Find occurrence of substr with length substr_len in pbuf p, start at offset start_offset WARNING: in contrast to strstr(), this one does not stop at the first \0 in the pbuf/source string! More... | |
err_t | pbuf_take (struct pbuf *buf, const void *dataptr, u16_t len) |
Copy application supplied data into a pbuf. More... | |
Variables | |
volatile u8_t | pbuf_free_ooseq_pending |
#define LWIP_SUPPORT_CUSTOM_PBUF (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) |
Currently, the pbuf_custom code is only needed for one specific configuration of IP_FRAG.
#define PBUF_CHECK_FREE_OOSEQ | ( | ) |
When not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ() at regular intervals from main level to check if ooseq pbufs need to be freed!
#define PBUF_FLAG_IS_CUSTOM 0x02U |
indicates this is a custom pbuf: pbuf_free and pbuf_header handle such a a pbuf differently
Referenced by pbuf_free().
#define PBUF_FLAG_LLBCAST 0x08U |
indicates this pbuf was received as link-level broadcast
Referenced by ethernet_input().
#define PBUF_FLAG_LLMCAST 0x10U |
indicates this pbuf was received as link-level multicast
Referenced by ethernet_input().
#define PBUF_FLAG_MCASTLOOP 0x04U |
indicates this pbuf is UDP multicast to be looped back
#define PBUF_FLAG_PUSH 0x01U |
indicates this packet's data should be immediately passed to the application
Referenced by tcp_input().
#define PBUF_FLAG_TCP_FIN 0x20U |
indicates this pbuf includes a TCP FIN flag
Referenced by tcp_input(), and tcp_process_refused_data().
#define pbuf_init | ( | ) |
Referenced by lwip_init().
#define PBUF_IP_HLEN 20 |
Referenced by icmp_input(), and pbuf_alloc().
#define PBUF_POOL_FREE_OOSEQ 1 |
Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty.
#define PBUF_TRANSPORT_HLEN 20 |
Referenced by pbuf_alloc().
enum pbuf_layer |
enum pbuf_type |
struct pbuf* pbuf_alloc | ( | pbuf_layer | layer, |
u16_t | length, | ||
pbuf_type | type | ||
) |
Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).
The actual memory allocated for the pbuf is determined by the layer at which the pbuf is allocated and the requested size (from the size parameter).
layer | flag to define header size |
length | size of the pbuf's payload |
type | this parameter decides how and where the pbuf should be allocated as follows: |
References pbuf::flags, pbuf::len, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_MEM_ALIGN, LWIP_MEM_ALIGN_SIZE, LWIP_MIN, MEM_ALIGNMENT, mem_malloc(), memp_malloc(), pbuf::next, NULL, pbuf::payload, PBUF_DEBUG, pbuf_free(), PBUF_IP, PBUF_IP_HLEN, PBUF_LINK, PBUF_POOL, PBUF_POOL_BUFSIZE_ALIGNED, PBUF_POOL_IS_EMPTY, PBUF_RAM, PBUF_RAW, PBUF_REF, PBUF_ROM, PBUF_TRANSPORT, PBUF_TRANSPORT_HLEN, pbuf::ref, SIZEOF_STRUCT_PBUF, pbuf::tot_len, pbuf::type, and U16_F.
Referenced by etharp_query(), etharp_raw(), gmac_rx_populate_queue(), icmp_input(), icmp_send_response(), ip_frag(), pbuf_coalesce(), tcp_enqueue_flags(), tcp_output_alloc_header(), tcp_pbuf_prealloc(), tcp_rst(), tcp_write(), and udp_input().
Concatenate two pbufs (each may be a pbuf chain) and take over the caller's reference of the tail pbuf.
References pbuf::len, LWIP_ASSERT, LWIP_ERROR(), pbuf::next, NULL, and pbuf::tot_len.
Referenced by ip_frag(), ip_reass(), pbuf_chain(), tcp_receive(), and tcp_write().
Chain two pbufs (or pbuf chains) together.
The caller MUST call pbuf_free(t) once it has stopped using it. Use pbuf_cat() instead if you no longer use t.
h | head pbuf (chain) |
t | tail pbuf (chain) |
The ->tot_len fields of all pbufs of the head chain are adjusted. The ->next field of the last pbuf of the head chain is adjusted. The ->ref field of the first pbuf of the tail chain is adjusted.
References LWIP_DBG_TRACE, LWIP_DEBUGF, pbuf_cat(), PBUF_DEBUG, and pbuf_ref().
Referenced by ip_frag().
Count number of pbufs in a chain.
p | first pbuf of chain |
References pbuf::next, and NULL.
Referenced by gmac_rx_populate_queue(), ip_reass(), ip_reass_chain_frag_into_datagram_and_validate(), ip_reass_free_complete_datagram(), tcp_enqueue_flags(), tcp_receive(), and tcp_write().
struct pbuf* pbuf_coalesce | ( | struct pbuf * | p, |
pbuf_layer | layer | ||
) |
Creates a single pbuf out of a queue of pbufs.
p | the source pbuf |
layer | pbuf_layer of the new pbuf |
References ERR_OK, LWIP_ASSERT, pbuf::next, NULL, pbuf_alloc(), pbuf_copy(), pbuf_free(), PBUF_RAM, and pbuf::tot_len.
Create PBUF_RAM copies of pbufs.
Used to queue packets on behalf of the lwIP stack, such as ARP based queueing.
p_to | pbuf destination of the copy |
p_from | pbuf source of the copy |
References ERR_ARG, ERR_OK, ERR_VAL, pbuf::len, LWIP_ASSERT, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_ERROR(), pbuf::next, NULL, pbuf::payload, PBUF_DEBUG, and pbuf::tot_len.
Referenced by etharp_query(), icmp_input(), pbuf_coalesce(), and udp_input().
Copy (part of) the contents of a packet buffer to an application supplied buffer.
buf | the pbuf from which to copy data |
dataptr | the application supplied buffer |
len | length of data to copy (dataptr must be big enough). No more than buf->tot_len will be copied, irrespective of len |
offset | offset into the packet buffer from where to begin copying len bytes |
References pbuf::len, LWIP_ERROR(), pbuf::next, NULL, and pbuf::payload.
Referenced by ip_frag(), and tcp_zero_window_probe().
Dechains the first pbuf from its succeeding pbufs in the chain.
Makes p->tot_len field equal to p->len.
p | pbuf to dechain |
References pbuf::len, LWIP_ASSERT, LWIP_DBG_TRACE, LWIP_DEBUGF, pbuf::next, NULL, PBUF_DEBUG, pbuf_free(), and pbuf::tot_len.
Dereference a pbuf chain or queue and deallocate any no-longer-used pbufs at the head of this chain or queue.
Decrements the pbuf reference count. If it reaches zero, the pbuf is deallocated.
For a pbuf chain, this is repeated for each pbuf in the chain, up to the first pbuf which has a non-zero reference count after decrementing. So, when all reference counts are one, the whole chain is free'd.
p | The pbuf (chain) to be dereferenced. |
examples:
Assuming existing chains a->b->c with the following reference counts, calling pbuf_free(a) results in:
1->2->3 becomes ...1->3 3->3->3 becomes 2->3->3 1->1->2 becomes ......1 2->1->1 becomes 1->1->1 1->1->1 becomes .......
References pbuf::flags, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_TRACE, LWIP_DEBUGF, mem_free(), memp_free(), pbuf::next, NULL, PBUF_DEBUG, PBUF_FLAG_IS_CUSTOM, PBUF_POOL, PBUF_RAM, PBUF_REF, PBUF_ROM, PERF_START, PERF_STOP, pbuf::ref, SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), SYS_ARCH_UNPROTECT(), pbuf::type, and U16_F.
Referenced by etharp_arp_input(), etharp_query(), etharp_raw(), etharp_update_arp_entry(), ethernet_input(), ethernetif_input(), gmac_low_level_input(), http_recv(), icmp_input(), icmp_send_response(), ip_frag(), ip_input(), ip_reass(), ip_reass_chain_frag_into_datagram_and_validate(), ip_reass_free_complete_datagram(), pbuf_alloc(), pbuf_coalesce(), pbuf_dechain(), pbuf_realloc(), tcp_create_segment(), tcp_input(), tcp_keepalive(), tcp_pcb_purge(), tcp_recv_null(), tcp_rst(), tcp_seg_free(), tcp_send_empty_ack(), tcp_shutdown(), tcp_write(), tcp_zero_window_probe(), and udp_input().
Attempt to reclaim some memory from queued out-of-sequence TCP segments if we run out of pool pbufs.
It's better to give priority to new packets if we're running out.
This must be done in the correct thread context therefore this function can only be used with NO_SYS=0 and through tcpip_callback.
Free the ooseq pbufs of one PCB only
References LWIP_DBG_TRACE, LWIP_DEBUGF, NULL, tcp_pcb::ooseq, PBUF_DEBUG, pbuf_free_ooseq_pending, SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), SYS_ARCH_UNPROTECT(), tcp_active_pcbs, and tcp_segs_free().
Get one byte from the specified position in a pbuf WARNING: returns zero for offset >= p->tot_len.
p | pbuf to parse |
offset | offset into p of the byte to return |
References pbuf::len, pbuf::next, NULL, and pbuf::payload.
Referenced by pbuf_memcmp().
Adjusts the payload pointer to hide or reveal headers in the payload.
Adjusts the ->payload pointer so that space for a header (dis)appears in the pbuf payload.
The ->payload, ->tot_len and ->len fields are adjusted.
p | pbuf to change the header size. |
header_size_increment | Number of bytes to increment header size which increases the size of the pbuf. New space is on the front. (Using a negative value decreases the header size.) If hdr_size_inc is 0, this function does nothing and returns succesful. |
PBUF_ROM and PBUF_REF type buffers cannot have their sizes increased, so the call will fail. A check is made that the increase in header size does not move the payload pointer in front of the start of the buffer.
References if(), pbuf::len, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_ERROR(), NULL, pbuf::payload, PBUF_DEBUG, PBUF_POOL, PBUF_RAM, PBUF_REF, PBUF_ROM, S16_F, SIZEOF_STRUCT_PBUF, pbuf::tot_len, and pbuf::type.
Referenced by etharp_output(), ethernet_input(), icmp_input(), ip_frag(), ip_reass(), tcp_create_segment(), tcp_input(), tcp_receive(), and udp_input().
Compare pbuf contents at specified offset with memory s2, both of length n.
p | pbuf to compare |
offset | offset into p at wich to start comparing |
s2 | buffer to compare |
n | length of buffer to compare |
References pbuf::len, pbuf::next, NULL, and pbuf_get_at().
Referenced by pbuf_memfind().
Find occurrence of mem (with length mem_len) in pbuf p, starting at offset start_offset.
p | pbuf to search, maximum length is 0xFFFE since 0xFFFF is used as return value 'not found' |
mem | search for the contents of this buffer |
mem_len | length of 'mem' |
start_offset | offset into p at which to start searching |
References max, pbuf_memcmp(), and pbuf::tot_len.
Referenced by pbuf_strstr().
Shrink a pbuf chain to a desired length.
p | pbuf to shrink. |
new_len | desired new length of pbuf chain |
Depending on the desired length, the first few pbufs in a chain might be skipped and left unchanged. The new last pbuf in the chain will be resized, and any remaining pbufs will be freed.
References pbuf::len, LWIP_ASSERT, mem_trim(), pbuf::next, NULL, pbuf::payload, pbuf_free(), PBUF_POOL, PBUF_RAM, PBUF_REF, PBUF_ROM, pbuf::tot_len, and pbuf::type.
Referenced by ip_frag(), ip_input(), tcp_oos_insert_segment(), and tcp_receive().
Increment the reference count of the pbuf.
p | pbuf to increase reference counter of |
References NULL, pbuf::ref, SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), and SYS_ARCH_UNPROTECT().
Referenced by etharp_query(), ip_frag(), pbuf_chain(), and tcp_seg_copy().
Find occurrence of substr with length substr_len in pbuf p, start at offset start_offset WARNING: in contrast to strstr(), this one does not stop at the first \0 in the pbuf/source string!
p | pbuf to search, maximum length is 0xFFFE since 0xFFFF is used as return value 'not found' |
substr | string to search for in p, maximum length is 0xFFFE |
References NULL, pbuf_memfind(), and pbuf::tot_len.
Copy application supplied data into a pbuf.
This function can only be used to copy the equivalent of buf->tot_len data.
buf | pbuf to fill with data |
dataptr | application supplied data buffer |
len | length of the application supplied data buffer |
References ERR_ARG, ERR_OK, pbuf::len, LWIP_ASSERT, LWIP_ERROR(), pbuf::next, NULL, pbuf::payload, and pbuf::tot_len.
volatile u8_t pbuf_free_ooseq_pending |
Referenced by pbuf_free_ooseq(), and pbuf_pool_is_empty().