ReactOS 0.4.16-dev-555-g690643f
pbuf.h
Go to the documentation of this file.
1
6/*
7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 *
32 * This file is part of the lwIP TCP/IP stack.
33 *
34 * Author: Adam Dunkels <adam@sics.se>
35 *
36 */
37
38#ifndef LWIP_HDR_PBUF_H
39#define LWIP_HDR_PBUF_H
40
41#include "lwip/opt.h"
42#include "lwip/err.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
54#ifndef LWIP_SUPPORT_CUSTOM_PBUF
55#define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
56#endif
57
71#ifndef PBUF_NEEDS_COPY
72#define PBUF_NEEDS_COPY(p) ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE)
73#endif /* PBUF_NEEDS_COPY */
74
75/* @todo: We need a mechanism to prevent wasting memory in every pbuf
76 (TCP vs. UDP, IPv4 vs. IPv6: UDP/IPv4 packets may waste up to 28 bytes) */
77
78#define PBUF_TRANSPORT_HLEN 20
79#if LWIP_IPV6
80#define PBUF_IP_HLEN 40
81#else
82#define PBUF_IP_HLEN 20
83#endif
84
89typedef enum {
111 PBUF_RAW = 0
113
114
115/* Base flags for pbuf_type definitions: */
116
119#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS 0x80
122#define PBUF_TYPE_FLAG_DATA_VOLATILE 0x40
125#define PBUF_TYPE_ALLOC_SRC_MASK 0x0F
129#define PBUF_ALLOC_FLAG_RX 0x0100
131#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS 0x0200
132
133#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP 0x00
134#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF 0x01
135#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL 0x02
137#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN 0x03
139#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX PBUF_TYPE_ALLOC_SRC_MASK
140
145typedef enum {
169
170
172#define PBUF_FLAG_PUSH 0x01U
175#define PBUF_FLAG_IS_CUSTOM 0x02U
177#define PBUF_FLAG_MCASTLOOP 0x04U
179#define PBUF_FLAG_LLBCAST 0x08U
181#define PBUF_FLAG_LLMCAST 0x10U
183#define PBUF_FLAG_TCP_FIN 0x20U
184
186struct pbuf {
188 struct pbuf *next;
189
191 void *payload;
192
201
204
209
212
219
222
225};
226
227
232struct pbuf_rom {
234 struct pbuf *next;
235
237 const void *payload;
238};
239
240#if LWIP_SUPPORT_CUSTOM_PBUF
242typedef void (*pbuf_free_custom_fn)(struct pbuf *p);
243
245struct pbuf_custom {
247 struct pbuf pbuf;
249 pbuf_free_custom_fn custom_free_function;
250};
251#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
252
254#ifndef PBUF_POOL_FREE_OOSEQ
255#define PBUF_POOL_FREE_OOSEQ 1
256#endif /* PBUF_POOL_FREE_OOSEQ */
257#if LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ
258extern volatile u8_t pbuf_free_ooseq_pending;
259void pbuf_free_ooseq(void);
263#define PBUF_CHECK_FREE_OOSEQ() do { if(pbuf_free_ooseq_pending) { \
264 /* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \
265 ooseq queued pbufs now */ \
266 pbuf_free_ooseq(); }}while(0)
267#else /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ */
268 /* Otherwise declare an empty PBUF_CHECK_FREE_OOSEQ */
269 #define PBUF_CHECK_FREE_OOSEQ()
270#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ*/
271
272/* Initializes the pbuf module. This call is empty for now, but may not be in future. */
273#define pbuf_init()
274
277#if LWIP_SUPPORT_CUSTOM_PBUF
278struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type,
279 struct pbuf_custom *p, void *payload_mem,
280 u16_t payload_mem_len);
281#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
282void pbuf_realloc(struct pbuf *p, u16_t size);
283#define pbuf_get_allocsrc(p) ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK)
284#define pbuf_match_allocsrc(p, type) (pbuf_get_allocsrc(p) == ((type) & PBUF_TYPE_ALLOC_SRC_MASK))
285#define pbuf_match_type(p, type) pbuf_match_allocsrc(p, type)
286u8_t pbuf_header(struct pbuf *p, s16_t header_size);
287u8_t pbuf_header_force(struct pbuf *p, s16_t header_size);
288u8_t pbuf_add_header(struct pbuf *p, size_t header_size_increment);
289u8_t pbuf_add_header_force(struct pbuf *p, size_t header_size_increment);
290u8_t pbuf_remove_header(struct pbuf *p, size_t header_size);
291struct pbuf *pbuf_free_header(struct pbuf *q, u16_t size);
292void pbuf_ref(struct pbuf *p);
293u8_t pbuf_free(struct pbuf *p);
294u16_t pbuf_clen(const struct pbuf *p);
295void pbuf_cat(struct pbuf *head, struct pbuf *tail);
296void pbuf_chain(struct pbuf *head, struct pbuf *tail);
297struct pbuf *pbuf_dechain(struct pbuf *p);
298err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from);
299err_t pbuf_copy_partial_pbuf(struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_len, u16_t offset);
300u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
301void *pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset);
302err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len);
303err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset);
304struct pbuf *pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset);
305struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer);
306struct pbuf *pbuf_clone(pbuf_layer l, pbuf_type type, struct pbuf *p);
307#if LWIP_CHECKSUM_ON_COPY
308err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
309 u16_t len, u16_t *chksum);
310#endif /* LWIP_CHECKSUM_ON_COPY */
311#if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
312void pbuf_split_64k(struct pbuf *p, struct pbuf **rest);
313#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
314
315u8_t pbuf_get_at(const struct pbuf* p, u16_t offset);
316int pbuf_try_get_at(const struct pbuf* p, u16_t offset);
317void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data);
318u16_t pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n);
319u16_t pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset);
320u16_t pbuf_strstr(const struct pbuf* p, const char* substr);
321
322#ifdef __cplusplus
323}
324#endif
325
326#endif /* LWIP_HDR_PBUF_H */
struct outqueuenode * tail
Definition: adnsresfilter.c:66
struct outqueuenode * head
Definition: adnsresfilter.c:66
r l[0]
Definition: byte_order.h:168
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLintptr offset
Definition: glext.h:5920
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint in
Definition: glext.h:9616
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
GLenum GLuint GLint GLint layer
Definition: glext.h:7007
GLenum GLsizei len
Definition: glext.h:6722
uint8_t u8_t
Definition: arch.h:125
uint16_t u16_t
Definition: arch.h:127
int16_t s16_t
Definition: arch.h:128
s8_t err_t
Definition: err.h:96
#define PBUF_LINK_HLEN
Definition: opt.h:1581
#define LWIP_PBUF_CUSTOM_DATA
Definition: opt.h:1615
#define PBUF_LINK_ENCAPSULATION_HLEN
Definition: opt.h:1590
#define LWIP_PBUF_REF_T
Definition: opt.h:1607
struct pbuf * pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
Definition: pbuf.c:1309
u16_t pbuf_memfind(const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
Definition: pbuf.c:1507
u16_t pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
Definition: pbuf.c:1465
void pbuf_realloc(struct pbuf *p, u16_t size)
Definition: pbuf.c:402
struct pbuf * pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type)
Definition: pbuf.c:327
u8_t pbuf_get_at(const struct pbuf *p, u16_t offset)
Definition: pbuf.c:1402
void * pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset)
Definition: pbuf.c:1105
void pbuf_ref(struct pbuf *p)
Definition: pbuf.c:831
void pbuf_cat(struct pbuf *head, struct pbuf *tail)
Definition: pbuf.c:855
void pbuf_chain(struct pbuf *head, struct pbuf *tail)
Definition: pbuf.c:897
int pbuf_try_get_at(const struct pbuf *p, u16_t offset)
Definition: pbuf.c:1420
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)
Definition: pbuf.c:224
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
pbuf_type
Definition: pbuf.h:145
err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
Definition: pbuf.c:959
struct pbuf * pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset)
Definition: pbuf.c:1209
u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1058
struct pbuf * pbuf_clone(pbuf_layer l, pbuf_type type, struct pbuf *p)
Definition: pbuf.c:1337
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
Definition: pbuf.c:1227
err_t pbuf_copy_partial_pbuf(struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_len, u16_t offset)
Definition: pbuf.c:986
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1271
pbuf_layer
Definition: pbuf.h:89
void pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
Definition: pbuf.c:1442
@ PBUF_ROM
Definition: pbuf.h:156
@ PBUF_RAM
Definition: pbuf.h:152
@ PBUF_REF
Definition: pbuf.h:160
@ PBUF_POOL
Definition: pbuf.h:167
@ PBUF_RAW_TX
Definition: pbuf.h:108
@ PBUF_RAW
Definition: pbuf.h:111
@ PBUF_TRANSPORT
Definition: pbuf.h:93
@ PBUF_LINK
Definition: pbuf.h:102
@ PBUF_IP
Definition: pbuf.h:97
static substr_t substr(const WCHAR *str, size_t len)
Definition: internet.h:203
int const JOCTET * dataptr
Definition: jpeglib.h:1031
struct S2 s2
#define PBUF_TYPE_FLAG_DATA_VOLATILE
Definition: pbuf.h:122
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL
Definition: pbuf.h:135
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:659
u8_t pbuf_add_header(struct pbuf *p, size_t header_size_increment)
Definition: pbuf.c:554
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF
Definition: pbuf.h:134
#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS
Definition: pbuf.h:131
#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS
Definition: pbuf.h:119
#define PBUF_ALLOC_FLAG_RX
Definition: pbuf.h:129
u16_t pbuf_clen(const struct pbuf *p)
Definition: pbuf.c:811
#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP
Definition: pbuf.h:133
u16_t pbuf_strstr(const struct pbuf *p, const char *substr)
Definition: pbuf.c:1534
u8_t pbuf_header(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:649
#define PBUF_IP_HLEN
Definition: pbuf.h:82
struct pbuf * pbuf_free_header(struct pbuf *q, u16_t size)
Definition: pbuf.c:674
u8_t pbuf_remove_header(struct pbuf *p, size_t header_size)
Definition: pbuf.c:585
struct pbuf * pbuf_dechain(struct pbuf *p)
Definition: pbuf.c:914
u8_t pbuf_add_header_force(struct pbuf *p, size_t header_size_increment)
Definition: pbuf.c:564
#define PBUF_TRANSPORT_HLEN
Definition: pbuf.h:78
Definition: mem.c:349
Definition: pbuf.h:232
const void * payload
Definition: pbuf.h:237
struct pbuf * next
Definition: pbuf.h:234
Definition: pbuf.h:186
LWIP_PBUF_REF_T ref
Definition: pbuf.h:218
u16_t tot_len
Definition: pbuf.h:200
struct pbuf * next
Definition: pbuf.h:188
u8_t type_internal
Definition: pbuf.h:208
u8_t if_idx
Definition: pbuf.h:221
u16_t len
Definition: pbuf.h:203
void * payload
Definition: pbuf.h:191
u8_t flags
Definition: pbuf.h:211