The Pedigree Project  0.1
pbuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
25 /*
26  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without modification,
30  * are permitted provided that the following conditions are met:
31  *
32  * 1. Redistributions of source code must retain the above copyright notice,
33  * this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright notice,
35  * this list of conditions and the following disclaimer in the documentation
36  * and/or other materials provided with the distribution.
37  * 3. The name of the author may not be used to endorse or promote products
38  * derived from this software without specific prior written permission.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49  * OF SUCH DAMAGE.
50  *
51  * This file is part of the lwIP TCP/IP stack.
52  *
53  * Author: Adam Dunkels <adam@sics.se>
54  *
55  */
56 
57 #ifndef LWIP_HDR_PBUF_H
58 #define LWIP_HDR_PBUF_H
59 
60 #include "lwip/opt.h"
61 #include "lwip/err.h"
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
73 #ifndef LWIP_SUPPORT_CUSTOM_PBUF
74 #define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
75 #endif
76 
77 /* @todo: We need a mechanism to prevent wasting memory in every pbuf
78  (TCP vs. UDP, IPv4 vs. IPv6: UDP/IPv4 packets may waste up to 28 bytes) */
79 
80 #define PBUF_TRANSPORT_HLEN 20
81 #if LWIP_IPV6
82 #define PBUF_IP_HLEN 40
83 #else
84 #define PBUF_IP_HLEN 20
85 #endif
86 
91 typedef enum {
114 } pbuf_layer;
115 
120 typedef enum {
143 } pbuf_type;
144 
145 
147 #define PBUF_FLAG_PUSH 0x01U
148 
150 #define PBUF_FLAG_IS_CUSTOM 0x02U
151 
152 #define PBUF_FLAG_MCASTLOOP 0x04U
153 
154 #define PBUF_FLAG_LLBCAST 0x08U
155 
156 #define PBUF_FLAG_LLMCAST 0x10U
157 
158 #define PBUF_FLAG_TCP_FIN 0x20U
159 
161 struct pbuf {
163  struct pbuf *next;
164 
166  void *payload;
167 
175  u16_t tot_len;
176 
178  u16_t len;
179 
181  u8_t /*pbuf_type*/ type;
182 
184  u8_t flags;
185 
191  u16_t ref;
192 };
193 
194 
199 struct pbuf_rom {
201  struct pbuf *next;
202 
204  const void *payload;
205 };
206 
207 #if LWIP_SUPPORT_CUSTOM_PBUF
208 
209 typedef void (*pbuf_free_custom_fn)(struct pbuf *p);
210 
212 struct pbuf_custom {
214  struct pbuf pbuf;
216  pbuf_free_custom_fn custom_free_function;
217 };
218 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
219 
221 #ifndef PBUF_POOL_FREE_OOSEQ
222 #define PBUF_POOL_FREE_OOSEQ 1
223 #endif /* PBUF_POOL_FREE_OOSEQ */
224 #if LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ
225 extern volatile u8_t pbuf_free_ooseq_pending;
226 void pbuf_free_ooseq(void);
230 #define PBUF_CHECK_FREE_OOSEQ() do { if(pbuf_free_ooseq_pending) { \
231  /* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \
232  ooseq queued pbufs now */ \
233  pbuf_free_ooseq(); }}while(0)
234 #else /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ */
235  /* Otherwise declare an empty PBUF_CHECK_FREE_OOSEQ */
236  #define PBUF_CHECK_FREE_OOSEQ()
237 #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ*/
238 
239 /* Initializes the pbuf module. This call is empty for now, but may not be in future. */
240 #define pbuf_init()
241 
242 struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type);
243 #if LWIP_SUPPORT_CUSTOM_PBUF
244 struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type,
245  struct pbuf_custom *p, void *payload_mem,
246  u16_t payload_mem_len);
247 #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
248 void pbuf_realloc(struct pbuf *p, u16_t size);
249 u8_t pbuf_header(struct pbuf *p, s16_t header_size);
250 u8_t pbuf_header_force(struct pbuf *p, s16_t header_size);
251 void pbuf_ref(struct pbuf *p);
252 u8_t pbuf_free(struct pbuf *p);
253 u16_t pbuf_clen(const struct pbuf *p);
254 void pbuf_cat(struct pbuf *head, struct pbuf *tail);
255 void pbuf_chain(struct pbuf *head, struct pbuf *tail);
256 struct pbuf *pbuf_dechain(struct pbuf *p);
257 err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from);
258 u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
259 err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len);
260 err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset);
261 struct pbuf *pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset);
262 struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer);
263 #if LWIP_CHECKSUM_ON_COPY
264 err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
265  u16_t len, u16_t *chksum);
266 #endif /* LWIP_CHECKSUM_ON_COPY */
267 #if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
268 void pbuf_split_64k(struct pbuf *p, struct pbuf **rest);
269 #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
270 
271 u8_t pbuf_get_at(const struct pbuf* p, u16_t offset);
272 int pbuf_try_get_at(const struct pbuf* p, u16_t offset);
273 void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data);
274 u16_t pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n);
275 u16_t pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset);
276 u16_t pbuf_strstr(const struct pbuf* p, const char* substr);
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #endif /* LWIP_HDR_PBUF_H */
u16_t tot_len
Definition: pbuf.h:175
void pbuf_realloc(struct pbuf *p, u16_t size)
Definition: pbuf.c:512
Definition: pbuf.h:113
struct pbuf * next
Definition: pbuf.h:163
u16_t len
Definition: pbuf.h:178
struct pbuf * pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset)
Definition: pbuf.c:1150
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:694
u16_t pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
Definition: pbuf.c:1381
Definition: pbuf.h:131
void pbuf_ref(struct pbuf *p)
Definition: pbuf.c:839
struct pbuf * pbuf_dechain(struct pbuf *p)
Definition: pbuf.c:918
u8_t pbuf_header(struct pbuf *p, s16_t header_size)
Definition: pbuf.c:684
struct pbuf * next
Definition: pbuf.h:201
err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
Definition: pbuf.c:967
u16_t pbuf_memfind(const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
Definition: pbuf.c:1423
u8_t pbuf_get_at(const struct pbuf *p, u16_t offset)
Definition: pbuf.c:1318
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1212
Definition: pbuf.h:199
void pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
Definition: pbuf.c:1358
void pbuf_chain(struct pbuf *head, struct pbuf *tail)
Definition: pbuf.c:901
u8_t flags
Definition: pbuf.h:184
Definition: pbuf.h:135
Definition: pbuf.h:161
void pbuf_cat(struct pbuf *head, struct pbuf *tail)
Definition: pbuf.c:859
pbuf_layer
Definition: pbuf.h:91
s8_t err_t
Definition: err.h:76
u16_t pbuf_strstr(const struct pbuf *p, const char *substr)
Definition: pbuf.c:1450
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)
Definition: pbuf.c:267
u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:1034
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
Definition: pbuf.c:1168
const void * payload
Definition: pbuf.h:204
Definition: pbuf.h:127
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:734
void * payload
Definition: pbuf.h:166
Definition: pbuf.h:99
Definition: mem.c:283
u16_t pbuf_clen(const struct pbuf *p)
Definition: pbuf.c:819
u8_t type
Definition: pbuf.h:181
struct pbuf * pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
Definition: pbuf.c:1248
u16_t ref
Definition: pbuf.h:191
int pbuf_try_get_at(const struct pbuf *p, u16_t offset)
Definition: pbuf.c:1336
pbuf_type
Definition: pbuf.h:120