ReactOS 0.4.16-dev-470-g91b8923
pbuf.h File Reference
#include "lwip/opt.h"
#include "lwip/err.h"
Include dependency graph for pbuf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pbuf
 
struct  pbuf_rom
 

Macros

#define LWIP_SUPPORT_CUSTOM_PBUF   ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
 
#define PBUF_NEEDS_COPY(p)   ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE)
 
#define PBUF_TRANSPORT_HLEN   20
 
#define PBUF_IP_HLEN   20
 
#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS   0x80
 
#define PBUF_TYPE_FLAG_DATA_VOLATILE   0x40
 
#define PBUF_TYPE_ALLOC_SRC_MASK   0x0F
 
#define PBUF_ALLOC_FLAG_RX   0x0100
 
#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS   0x0200
 
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP   0x00
 
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF   0x01
 
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL   0x02
 
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN   0x03
 
#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX   PBUF_TYPE_ALLOC_SRC_MASK
 
#define PBUF_FLAG_PUSH   0x01U
 
#define PBUF_FLAG_IS_CUSTOM   0x02U
 
#define PBUF_FLAG_MCASTLOOP   0x04U
 
#define PBUF_FLAG_LLBCAST   0x08U
 
#define PBUF_FLAG_LLMCAST   0x10U
 
#define PBUF_FLAG_TCP_FIN   0x20U
 
#define PBUF_POOL_FREE_OOSEQ   1
 
#define PBUF_CHECK_FREE_OOSEQ()
 
#define pbuf_init()
 
#define pbuf_get_allocsrc(p)   ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK)
 
#define pbuf_match_allocsrc(p, type)   (pbuf_get_allocsrc(p) == ((type) & PBUF_TYPE_ALLOC_SRC_MASK))
 
#define pbuf_match_type(p, type)   pbuf_match_allocsrc(p, type)
 

Enumerations

enum  pbuf_layer {
  PBUF_TRANSPORT = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN , PBUF_IP = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN , PBUF_LINK = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN , PBUF_RAW_TX = PBUF_LINK_ENCAPSULATION_HLEN ,
  PBUF_RAW = 0
}
 
enum  pbuf_type { PBUF_RAM = (PBUF_ALLOC_FLAG_DATA_CONTIGUOUS | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP) , PBUF_ROM = PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF , PBUF_REF = (PBUF_TYPE_FLAG_DATA_VOLATILE | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF) , PBUF_POOL = (PBUF_ALLOC_FLAG_RX | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL) }
 

Functions

struct pbufpbuf_alloc (pbuf_layer l, u16_t length, pbuf_type type)
 
struct pbufpbuf_alloc_reference (void *payload, u16_t length, pbuf_type type)
 
void pbuf_realloc (struct pbuf *p, u16_t size)
 
u8_t pbuf_header (struct pbuf *p, s16_t header_size)
 
u8_t pbuf_header_force (struct pbuf *p, s16_t header_size)
 
u8_t pbuf_add_header (struct pbuf *p, size_t header_size_increment)
 
u8_t pbuf_add_header_force (struct pbuf *p, size_t header_size_increment)
 
u8_t pbuf_remove_header (struct pbuf *p, size_t header_size)
 
struct pbufpbuf_free_header (struct pbuf *q, u16_t size)
 
void pbuf_ref (struct pbuf *p)
 
u8_t pbuf_free (struct pbuf *p)
 
u16_t pbuf_clen (const struct pbuf *p)
 
void pbuf_cat (struct pbuf *head, struct pbuf *tail)
 
void pbuf_chain (struct pbuf *head, struct pbuf *tail)
 
struct pbufpbuf_dechain (struct pbuf *p)
 
err_t pbuf_copy (struct pbuf *p_to, const struct pbuf *p_from)
 
err_t pbuf_copy_partial_pbuf (struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_len, u16_t offset)
 
u16_t pbuf_copy_partial (const struct pbuf *p, void *dataptr, u16_t len, u16_t offset)
 
voidpbuf_get_contiguous (const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset)
 
err_t pbuf_take (struct pbuf *buf, const void *dataptr, u16_t len)
 
err_t pbuf_take_at (struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
 
struct pbufpbuf_skip (struct pbuf *in, u16_t in_offset, u16_t *out_offset)
 
struct pbufpbuf_coalesce (struct pbuf *p, pbuf_layer layer)
 
struct pbufpbuf_clone (pbuf_layer l, pbuf_type type, struct pbuf *p)
 
u8_t pbuf_get_at (const struct pbuf *p, u16_t offset)
 
int pbuf_try_get_at (const struct pbuf *p, u16_t offset)
 
void pbuf_put_at (struct pbuf *p, u16_t offset, u8_t data)
 
u16_t pbuf_memcmp (const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
 
u16_t pbuf_memfind (const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
 
u16_t pbuf_strstr (const struct pbuf *p, const char *substr)
 

Detailed Description

pbuf API

Definition in file pbuf.h.

Macro Definition Documentation

◆ LWIP_SUPPORT_CUSTOM_PBUF

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

◆ PBUF_ALLOC_FLAG_DATA_CONTIGUOUS

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

◆ PBUF_ALLOC_FLAG_RX

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

◆ PBUF_CHECK_FREE_OOSEQ

#define PBUF_CHECK_FREE_OOSEQ ( )

Definition at line 269 of file pbuf.h.

◆ PBUF_FLAG_IS_CUSTOM

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

◆ PBUF_FLAG_LLBCAST

#define PBUF_FLAG_LLBCAST   0x08U

indicates this pbuf was received as link-level broadcast

Definition at line 179 of file pbuf.h.

◆ PBUF_FLAG_LLMCAST

#define PBUF_FLAG_LLMCAST   0x10U

indicates this pbuf was received as link-level multicast

Definition at line 181 of file pbuf.h.

◆ PBUF_FLAG_MCASTLOOP

#define PBUF_FLAG_MCASTLOOP   0x04U

indicates this pbuf is UDP multicast to be looped back

Definition at line 177 of file pbuf.h.

◆ PBUF_FLAG_PUSH

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

◆ PBUF_FLAG_TCP_FIN

#define PBUF_FLAG_TCP_FIN   0x20U

indicates this pbuf includes a TCP FIN flag

Definition at line 183 of file pbuf.h.

◆ pbuf_get_allocsrc

#define pbuf_get_allocsrc (   p)    ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK)

Definition at line 283 of file pbuf.h.

◆ pbuf_init

#define pbuf_init ( )

Definition at line 273 of file pbuf.h.

◆ PBUF_IP_HLEN

#define PBUF_IP_HLEN   20

Definition at line 82 of file pbuf.h.

◆ pbuf_match_allocsrc

#define pbuf_match_allocsrc (   p,
  type 
)    (pbuf_get_allocsrc(p) == ((type) & PBUF_TYPE_ALLOC_SRC_MASK))

Definition at line 284 of file pbuf.h.

◆ pbuf_match_type

#define pbuf_match_type (   p,
  type 
)    pbuf_match_allocsrc(p, type)

Definition at line 285 of file pbuf.h.

◆ PBUF_POOL_FREE_OOSEQ

#define PBUF_POOL_FREE_OOSEQ   1

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

Definition at line 255 of file pbuf.h.

◆ PBUF_TRANSPORT_HLEN

#define PBUF_TRANSPORT_HLEN   20

Definition at line 78 of file pbuf.h.

◆ PBUF_TYPE_ALLOC_SRC_MASK

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

◆ PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX

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

◆ PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN

#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN   0x03

First pbuf allocation type for applications

Definition at line 137 of file pbuf.h.

◆ PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP

#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP   0x00

Definition at line 133 of file pbuf.h.

◆ PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF

#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF   0x01

Definition at line 134 of file pbuf.h.

◆ PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL

#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL   0x02

Definition at line 135 of file pbuf.h.

◆ PBUF_TYPE_FLAG_DATA_VOLATILE

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

◆ PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS

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

Function Documentation

◆ pbuf_add_header()

u8_t pbuf_add_header ( struct pbuf p,
size_t  header_size_increment 
)

Adjusts the payload pointer to reveal headers in the payload.

Adjusts the ->payload pointer so that space for a header appears in the pbuf payload.

The ->payload, ->tot_len and ->len fields are adjusted.

Parameters
ppbuf to change the header size.
header_size_incrementNumber of bytes to increment header size which increases the size of the pbuf. New space is on the front. If header_size_increment is 0, this function does nothing and returns successful.

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.

Returns
non-zero on failure, zero on success.

Definition at line 554 of file pbuf.c.

555{
556 return pbuf_add_header_impl(p, header_size_increment, 0);
557}
GLfloat GLfloat p
Definition: glext.h:8902
static u8_t pbuf_add_header_impl(struct pbuf *p, size_t header_size_increment, u8_t force)
Definition: pbuf.c:476

Referenced by test_udp_create_test_packet().

◆ pbuf_add_header_force()

u8_t pbuf_add_header_force ( struct pbuf p,
size_t  header_size_increment 
)

Same as pbuf_add_header but does not check if 'header_size > 0' is allowed. This is used internally only, to allow PBUF_REF for RX.

Definition at line 564 of file pbuf.c.

565{
566 return pbuf_add_header_impl(p, header_size_increment, 1);
567}

◆ pbuf_clen()

u16_t pbuf_clen ( const struct pbuf p)

Count number of pbufs in a chain

Parameters
pfirst pbuf of chain
Returns
the number of pbufs in a chain

Definition at line 811 of file pbuf.c.

812{
813 u16_t len;
814
815 len = 0;
816 while (p != NULL) {
817 ++len;
818 p = p->next;
819 }
820 return len;
821}
#define NULL
Definition: types.h:112
GLenum GLsizei len
Definition: glext.h:6722
uint16_t u16_t
Definition: arch.h:127

◆ pbuf_dechain()

struct pbuf * pbuf_dechain ( struct pbuf p)

Dechains the first pbuf from its succeeding pbufs in the chain.

Makes p->tot_len field equal to p->len.

Parameters
ppbuf to dechain
Returns
remainder of the pbuf chain, or NULL if it was de-allocated.
Note
May not be called on a packet queue.

Definition at line 914 of file pbuf.c.

915{
916 struct pbuf *q;
917 u8_t tail_gone = 1;
918 /* tail */
919 q = p->next;
920 /* pbuf has successor in chain? */
921 if (q != NULL) {
922 /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
923 LWIP_ASSERT("p->tot_len == p->len + q->tot_len", q->tot_len == p->tot_len - p->len);
924 /* enforce invariant if assertion is disabled */
925 q->tot_len = (u16_t)(p->tot_len - p->len);
926 /* decouple pbuf from remainder */
927 p->next = NULL;
928 /* total length of pbuf p is its own length only */
929 p->tot_len = p->len;
930 /* q is no longer referenced by p, free it */
931 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_dechain: unreferencing %p\n", (void *)q));
932 tail_gone = pbuf_free(q);
933 if (tail_gone > 0) {
935 ("pbuf_dechain: deallocated %p (as it is no longer referenced)\n", (void *)q));
936 }
937 /* return remaining tail or NULL if deallocated */
938 }
939 /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
940 LWIP_ASSERT("p->tot_len == p->len", p->tot_len == p->len);
941 return ((tail_gone > 0) ? NULL : q);
942}
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:158
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
uint8_t u8_t
Definition: arch.h:125
#define LWIP_DBG_TRACE
Definition: debug.h:83
#define PBUF_DEBUG
Definition: opt.h:3343
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
Definition: pbuf.h:186

◆ pbuf_free_header()

struct pbuf * pbuf_free_header ( struct pbuf q,
u16_t  size 
)

Similar to pbuf_header(-size) but de-refs header pbufs for (size >= p->len)

Parameters
qpbufs to operate on
sizeThe number of bytes to remove from the beginning of the pbuf list. While size >= p->len, pbufs are freed. ATTENTION: this is the opposite direction as pbuf_header, but takes an u16_t not s16_t!
Returns
the new head pbuf

Definition at line 674 of file pbuf.c.

675{
676 struct pbuf *p = q;
677 u16_t free_left = size;
678 while (free_left && p) {
679 if (free_left >= p->len) {
680 struct pbuf *f = p;
681 free_left = (u16_t)(free_left - p->len);
682 p = p->next;
683 f->next = NULL;
684 pbuf_free(f);
685 } else {
686 pbuf_remove_header(p, free_left);
687 free_left = 0;
688 }
689 }
690 return p;
691}
GLsizeiptr size
Definition: glext.h:5919
GLfloat f
Definition: glext.h:7540
u8_t pbuf_remove_header(struct pbuf *p, size_t header_size_decrement)
Definition: pbuf.c:585

◆ pbuf_header()

u8_t pbuf_header ( struct pbuf p,
s16_t  header_size_increment 
)

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.

Parameters
ppbuf to change the header size.
header_size_incrementNumber 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 header_size_increment is 0, this function does nothing and returns successful.

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.

Returns
non-zero on failure, zero on success.

Definition at line 649 of file pbuf.c.

650{
651 return pbuf_header_impl(p, header_size_increment, 0);
652}
static u8_t pbuf_header_impl(struct pbuf *p, s16_t header_size_increment, u8_t force)
Definition: pbuf.c:619

Referenced by START_TEST(), tcp_create_segment_wnd(), and test_tcp_input().

◆ pbuf_header_force()

u8_t pbuf_header_force ( struct pbuf p,
s16_t  header_size_increment 
)

Same as pbuf_header but does not check if 'header_size > 0' is allowed. This is used internally only, to allow PBUF_REF for RX.

Definition at line 659 of file pbuf.c.

660{
661 return pbuf_header_impl(p, header_size_increment, 1);
662}

◆ pbuf_remove_header()

u8_t pbuf_remove_header ( struct pbuf p,
size_t  header_size_decrement 
)

Adjusts the payload pointer to hide headers in the payload.

Adjusts the ->payload pointer so that space for a header disappears in the pbuf payload.

The ->payload, ->tot_len and ->len fields are adjusted.

Parameters
ppbuf to change the header size.
header_size_decrementNumber of bytes to decrement header size which decreases the size of the pbuf. If header_size_decrement is 0, this function does nothing and returns successful.
Returns
non-zero on failure, zero on success.

Definition at line 585 of file pbuf.c.

586{
587 void *payload;
588 u16_t increment_magnitude;
589
590 LWIP_ASSERT("p != NULL", p != NULL);
591 if ((p == NULL) || (header_size_decrement > 0xFFFF)) {
592 return 1;
593 }
594 if (header_size_decrement == 0) {
595 return 0;
596 }
597
598 increment_magnitude = (u16_t)header_size_decrement;
599 /* Check that we aren't going to move off the end of the pbuf */
600 LWIP_ERROR("increment_magnitude <= p->len", (increment_magnitude <= p->len), return 1;);
601
602 /* remember current payload pointer */
603 payload = p->payload;
604 LWIP_UNUSED_ARG(payload); /* only used in LWIP_DEBUGF below */
605
606 /* increase payload pointer (guarded by length check above) */
607 p->payload = (u8_t *)p->payload + header_size_decrement;
608 /* modify pbuf length fields */
609 p->len = (u16_t)(p->len - increment_magnitude);
610 p->tot_len = (u16_t)(p->tot_len - increment_magnitude);
611
612 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_remove_header: old %p new %p (%"U16_F")\n",
613 (void *)payload, (void *)p->payload, increment_magnitude));
614
615 return 0;
616}
#define U16_F
Definition: cc.h:19
#define LWIP_ERROR(message, expression, handler)
Definition: debug.h:130
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373

Referenced by pbuf_free_header(), and pbuf_header_impl().

◆ pbuf_strstr()

u16_t pbuf_strstr ( const 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!

Parameters
ppbuf to search, maximum length is 0xFFFE since 0xFFFF is used as return value 'not found'
substrstring to search for in p, maximum length is 0xFFFE
Returns
0xFFFF if substr was not found in p or the index where it was found

Definition at line 1534 of file pbuf.c.

1535{
1536 size_t substr_len;
1537 if ((substr == NULL) || (substr[0] == 0) || (p->tot_len == 0xFFFF)) {
1538 return 0xFFFF;
1539 }
1540 substr_len = strlen(substr);
1541 if (substr_len >= 0xFFFF) {
1542 return 0xFFFF;
1543 }
1544 return pbuf_memfind(p, substr, (u16_t)substr_len, 0);
1545}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
u16_t pbuf_memfind(const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
Definition: pbuf.c:1507
static substr_t substr(const WCHAR *str, size_t len)
Definition: internet.h:203