sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
pbuf.c
Go to the documentation of this file.
1
5
38
39/*
40 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without modification,
44 * are permitted provided that the following conditions are met:
45 *
46 * 1. Redistributions of source code must retain the above copyright notice,
47 * this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright notice,
49 * this list of conditions and the following disclaimer in the documentation
50 * and/or other materials provided with the distribution.
51 * 3. The name of the author may not be used to endorse or promote products
52 * derived from this software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
55 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
56 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
57 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
59 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
61 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
62 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
63 * OF SUCH DAMAGE.
64 *
65 * This file is part of the lwIP TCP/IP stack.
66 *
67 * Author: Adam Dunkels <adam@sics.se>
68 *
69 */
70
71#include "lwip/opt.h"
72
73#include "lwip/pbuf.h"
74#include "lwip/stats.h"
75#include "lwip/def.h"
76#include "lwip/mem.h"
77#include "lwip/memp.h"
78#include "lwip/sys.h"
79#include "lwip/netif.h"
80#if LWIP_TCP && TCP_QUEUE_OOSEQ
81#include "lwip/priv/tcp_priv.h"
82#endif
83#if LWIP_CHECKSUM_ON_COPY
84#include "lwip/inet_chksum.h"
85#endif
86
87#include <string.h>
88
89#define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
90/* Since the pool is created in memp, PBUF_POOL_BUFSIZE will be automatically
91 aligned there. Therefore, PBUF_POOL_BUFSIZE_ALIGNED can be used here. */
92#define PBUF_POOL_BUFSIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE)
93
94static const struct pbuf *
95pbuf_skip_const(const struct pbuf *in, u16_t in_offset, u16_t *out_offset);
96
97#if !LWIP_TCP || !TCP_QUEUE_OOSEQ || !PBUF_POOL_FREE_OOSEQ
98#define PBUF_POOL_IS_EMPTY()
99#else /* !LWIP_TCP || !TCP_QUEUE_OOSEQ || !PBUF_POOL_FREE_OOSEQ */
100
101#if !NO_SYS
102#ifndef PBUF_POOL_FREE_OOSEQ_QUEUE_CALL
103#include "lwip/tcpip.h"
104#define PBUF_POOL_FREE_OOSEQ_QUEUE_CALL() do { \
105 if (tcpip_try_callback(pbuf_free_ooseq_callback, NULL) != ERR_OK) { \
106 SYS_ARCH_PROTECT(old_level); \
107 pbuf_free_ooseq_pending = 0; \
108 SYS_ARCH_UNPROTECT(old_level); \
109 } } while(0)
110#endif /* PBUF_POOL_FREE_OOSEQ_QUEUE_CALL */
111#endif /* !NO_SYS */
112
113volatile u8_t pbuf_free_ooseq_pending;
114#define PBUF_POOL_IS_EMPTY() pbuf_pool_is_empty()
115
124#if !NO_SYS
125static
126#endif /* !NO_SYS */
127void
128pbuf_free_ooseq(void)
129{
130 struct tcp_pcb *pcb;
131 SYS_ARCH_SET(pbuf_free_ooseq_pending, 0);
132
133 for (pcb = tcp_active_pcbs; NULL != pcb; pcb = pcb->next) {
134 if (pcb->ooseq != NULL) {
136 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free_ooseq: freeing out-of-sequence pbufs\n"));
137 tcp_free_ooseq(pcb);
138 return;
139 }
140 }
141}
142
143#if !NO_SYS
147static void
148pbuf_free_ooseq_callback(void *arg)
149{
150 LWIP_UNUSED_ARG(arg);
151 pbuf_free_ooseq();
152}
153#endif /* !NO_SYS */
154
156static void
157pbuf_pool_is_empty(void)
158{
159#ifndef PBUF_POOL_FREE_OOSEQ_QUEUE_CALL
160 SYS_ARCH_SET(pbuf_free_ooseq_pending, 1);
161#else /* PBUF_POOL_FREE_OOSEQ_QUEUE_CALL */
162 u8_t queued;
163 SYS_ARCH_DECL_PROTECT(old_level);
164 SYS_ARCH_PROTECT(old_level);
165 queued = pbuf_free_ooseq_pending;
166 pbuf_free_ooseq_pending = 1;
167 SYS_ARCH_UNPROTECT(old_level);
168
169 if (!queued) {
170 /* queue a call to pbuf_free_ooseq if not already queued */
171 PBUF_POOL_FREE_OOSEQ_QUEUE_CALL();
172 }
173#endif /* PBUF_POOL_FREE_OOSEQ_QUEUE_CALL */
174}
175#endif /* !LWIP_TCP || !TCP_QUEUE_OOSEQ || !PBUF_POOL_FREE_OOSEQ */
176
177/* Initialize members of struct pbuf after allocation */
178static void
179pbuf_init_alloced_pbuf(struct pbuf *p, void *payload, u16_t tot_len, u16_t len, pbuf_type type, u8_t flags)
180{
181 p->next = NULL;
182 p->payload = payload;
183 p->tot_len = tot_len;
184 p->len = len;
185 p->type_internal = (u8_t)type;
186 p->flags = flags;
187 p->ref = 1;
188 p->if_idx = NETIF_NO_INDEX;
189
191}
192
225struct pbuf *
226pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
227{
228 struct pbuf *p;
229 u16_t offset = (u16_t)layer;
230 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F")\n", length));
231
232 switch (type) {
233 case PBUF_REF: /* fall through */
234 case PBUF_ROM:
235 p = pbuf_alloc_reference(NULL, length, type);
236 break;
237 case PBUF_POOL: {
238 struct pbuf *q, *last;
239 u16_t rem_len; /* remaining length */
240 p = NULL;
241 last = NULL;
242 rem_len = length;
243 do {
244 u16_t qlen;
245 q = (struct pbuf *)memp_malloc(MEMP_PBUF_POOL);
246 if (q == NULL) {
247 PBUF_POOL_IS_EMPTY();
248 /* free chain so far allocated */
249 if (p) {
250 pbuf_free(p);
251 }
252 /* bail out unsuccessfully */
253 return NULL;
254 }
255 qlen = LWIP_MIN(rem_len, (u16_t)(PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset)));
256 pbuf_init_alloced_pbuf(q, LWIP_MEM_ALIGN((void *)((u8_t *)q + SIZEOF_STRUCT_PBUF + offset)),
257 rem_len, qlen, type, 0);
258 LWIP_ASSERT("pbuf_alloc: pbuf q->payload properly aligned",
259 ((mem_ptr_t)q->payload % MEM_ALIGNMENT) == 0);
260 LWIP_ASSERT("PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT",
261 (PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset)) > 0 );
262 if (p == NULL) {
263 /* allocated head of pbuf chain (into p) */
264 p = q;
265 } else {
266 /* make previous pbuf point to this pbuf */
267 last->next = q;
268 }
269 last = q;
270 rem_len = (u16_t)(rem_len - qlen);
271 offset = 0;
272 } while (rem_len > 0);
273 break;
274 }
275 case PBUF_RAM: {
276 mem_size_t payload_len = (mem_size_t)(LWIP_MEM_ALIGN_SIZE(offset) + LWIP_MEM_ALIGN_SIZE(length));
277 mem_size_t alloc_len = (mem_size_t)(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF) + payload_len);
278
279 /* bug #50040: Check for integer overflow when calculating alloc_len */
280 if ((payload_len < LWIP_MEM_ALIGN_SIZE(length)) ||
281 (alloc_len < LWIP_MEM_ALIGN_SIZE(length))) {
282 return NULL;
283 }
284
285 /* If pbuf is to be allocated in RAM, allocate memory for it. */
286 p = (struct pbuf *)mem_malloc(alloc_len);
287 if (p == NULL) {
288 return NULL;
289 }
290 pbuf_init_alloced_pbuf(p, LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset)),
291 length, length, type, 0);
292 LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
293 ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
294 break;
295 }
296 default:
297 LWIP_ASSERT("pbuf_alloc: erroneous type", 0);
298 return NULL;
299 }
300 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p));
301 return p;
302}
303
328struct pbuf *
329pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type)
330{
331 struct pbuf *p;
332 LWIP_ASSERT("invalid pbuf_type", (type == PBUF_REF) || (type == PBUF_ROM));
333 /* only allocate memory for the pbuf structure */
334 p = (struct pbuf *)memp_malloc(MEMP_PBUF);
335 if (p == NULL) {
337 ("pbuf_alloc_reference: Could not allocate MEMP_PBUF for PBUF_%s.\n",
338 (type == PBUF_ROM) ? "ROM" : "REF"));
339 return NULL;
340 }
341 pbuf_init_alloced_pbuf(p, payload, length, length, type, 0);
342 return p;
343}
344
345
346#if LWIP_SUPPORT_CUSTOM_PBUF
364struct pbuf *
365pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, struct pbuf_custom *p,
366 void *payload_mem, u16_t payload_mem_len)
367{
368 u16_t offset = (u16_t)l;
369 void *payload;
370 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloced_custom(length=%"U16_F")\n", length));
371
372 if (LWIP_MEM_ALIGN_SIZE(offset) + length > payload_mem_len) {
373 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_LEVEL_WARNING, ("pbuf_alloced_custom(length=%"U16_F") buffer too short\n", length));
374 return NULL;
375 }
376
377 if (payload_mem != NULL) {
378 payload = (u8_t *)payload_mem + LWIP_MEM_ALIGN_SIZE(offset);
379 } else {
380 payload = NULL;
381 }
382 pbuf_init_alloced_pbuf(&p->pbuf, payload, length, length, type, PBUF_FLAG_IS_CUSTOM);
383 return &p->pbuf;
384}
385#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
386
403void
404pbuf_realloc(struct pbuf *p, u16_t new_len)
405{
406 struct pbuf *q;
407 u16_t rem_len; /* remaining length */
408 u16_t shrink;
409
410 LWIP_ASSERT("pbuf_realloc: p != NULL", p != NULL);
411
412 /* desired length larger than current length? */
413 if (new_len >= p->tot_len) {
414 /* enlarging not yet supported */
415 return;
416 }
417
418 /* the pbuf chain grows by (new_len - p->tot_len) bytes
419 * (which may be negative in case of shrinking) */
420 shrink = (u16_t)(p->tot_len - new_len);
421
422 /* first, step over any pbufs that should remain in the chain */
423 rem_len = new_len;
424 q = p;
425 /* should this pbuf be kept? */
426 while (rem_len > q->len) {
427 /* decrease remaining length by pbuf length */
428 rem_len = (u16_t)(rem_len - q->len);
429 /* decrease total length indicator */
430 q->tot_len = (u16_t)(q->tot_len - shrink);
431 /* proceed to next pbuf in chain */
432 q = q->next;
433 LWIP_ASSERT("pbuf_realloc: q != NULL", q != NULL);
434 }
435 /* we have now reached the new last pbuf (in q) */
436 /* rem_len == desired length for pbuf q */
437
438 /* shrink allocated memory for PBUF_RAM */
439 /* (other types merely adjust their length fields */
440 if (pbuf_match_allocsrc(q, PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP) && (rem_len != q->len)
442 && ((q->flags & PBUF_FLAG_IS_CUSTOM) == 0)
443#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
444 ) {
445 /* reallocate and adjust the length of the pbuf that will be split */
446 struct pbuf *r = (struct pbuf *)mem_trim(q, (mem_size_t)(((u8_t *)q->payload - (u8_t *)q) + rem_len));
447 LWIP_ASSERT("mem_trim returned r == NULL", r != NULL);
448 /* help to detect faulty overridden implementation of mem_trim */
449 LWIP_ASSERT("mem_trim returned r != q", r == q);
451 }
452 /* adjust length fields for new last pbuf */
453 q->len = rem_len;
454 q->tot_len = q->len;
455
456 /* any remaining pbufs in chain? */
457 if (q->next != NULL) {
458 /* free remaining pbufs in chain */
459 pbuf_free(q->next);
460 }
461 /* q is last packet in chain */
462 q->next = NULL;
463
464}
465
477static u8_t
478pbuf_add_header_impl(struct pbuf *p, size_t header_size_increment, u8_t force)
479{
480 u16_t type_internal;
481 void *payload;
482 u16_t increment_magnitude;
483
484 LWIP_ASSERT("p != NULL", p != NULL);
485 if ((p == NULL) || (header_size_increment > 0xFFFF)) {
486 return 1;
487 }
488 if (header_size_increment == 0) {
489 return 0;
490 }
491
492 increment_magnitude = (u16_t)header_size_increment;
493 /* Do not allow tot_len to wrap as a result. */
494 if ((u16_t)(increment_magnitude + p->tot_len) < increment_magnitude) {
495 return 1;
496 }
497
498 type_internal = p->type_internal;
499
500 /* pbuf types containing payloads? */
502 /* set new payload pointer */
503 payload = (u8_t *)p->payload - header_size_increment;
504 /* boundary check fails? */
505 if ((u8_t *)payload < (u8_t *)p + SIZEOF_STRUCT_PBUF) {
506 LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE,
507 ("pbuf_add_header: failed as %p < %p (not enough space for new header size)\n",
508 (void *)payload, (void *)((u8_t *)p + SIZEOF_STRUCT_PBUF)));
509 /* bail out unsuccessfully */
510 return 1;
511 }
512 /* pbuf types referring to external payloads? */
513 } else {
514 /* hide a header in the payload? */
515 if (force) {
516 payload = (u8_t *)p->payload - header_size_increment;
517 } else {
518 /* cannot expand payload to front (yet!)
519 * bail out unsuccessfully */
520 return 1;
521 }
522 }
523 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_add_header: old %p new %p (%"U16_F")\n",
524 (void *)p->payload, (void *)payload, increment_magnitude));
525
526 /* modify pbuf fields */
527 p->payload = payload;
528 p->len = (u16_t)(p->len + increment_magnitude);
529 p->tot_len = (u16_t)(p->tot_len + increment_magnitude);
530
531
532 return 0;
533}
534
555u8_t
556pbuf_add_header(struct pbuf *p, size_t header_size_increment)
557{
558 return pbuf_add_header_impl(p, header_size_increment, 0);
559}
560
565u8_t
566pbuf_add_header_force(struct pbuf *p, size_t header_size_increment)
567{
568 return pbuf_add_header_impl(p, header_size_increment, 1);
569}
570
586u8_t
587pbuf_remove_header(struct pbuf *p, size_t header_size_decrement)
588{
589 void *payload;
590 u16_t increment_magnitude;
591
592 LWIP_ASSERT("p != NULL", p != NULL);
593 if ((p == NULL) || (header_size_decrement > 0xFFFF)) {
594 return 1;
595 }
596 if (header_size_decrement == 0) {
597 return 0;
598 }
599
600 increment_magnitude = (u16_t)header_size_decrement;
601 /* Check that we aren't going to move off the end of the pbuf */
602 LWIP_ERROR("increment_magnitude <= p->len", (increment_magnitude <= p->len), return 1;);
603
604 /* remember current payload pointer */
605 payload = p->payload;
606 LWIP_UNUSED_ARG(payload); /* only used in LWIP_DEBUGF below */
607
608 /* increase payload pointer (guarded by length check above) */
609 p->payload = (u8_t *)p->payload + header_size_decrement;
610 /* modify pbuf length fields */
611 p->len = (u16_t)(p->len - increment_magnitude);
612 p->tot_len = (u16_t)(p->tot_len - increment_magnitude);
613
614 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_remove_header: old %p new %p (%"U16_F")\n",
615 (void *)payload, (void *)p->payload, increment_magnitude));
616
617 return 0;
618}
619
620static u8_t
621pbuf_header_impl(struct pbuf *p, s16_t header_size_increment, u8_t force)
622{
623 if (header_size_increment < 0) {
624 return pbuf_remove_header(p, (size_t) - header_size_increment);
625 } else {
626 return pbuf_add_header_impl(p, (size_t)header_size_increment, force);
627 }
628}
629
650u8_t
651pbuf_header(struct pbuf *p, s16_t header_size_increment)
652{
653 return pbuf_header_impl(p, header_size_increment, 0);
654}
655
660u8_t
661pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
662{
663 return pbuf_header_impl(p, header_size_increment, 1);
664}
665
675struct pbuf *
676pbuf_free_header(struct pbuf *q, u16_t size)
677{
678 struct pbuf *p = q;
679 u16_t free_left = size;
680 while (free_left && p) {
681 if (free_left >= p->len) {
682 struct pbuf *f = p;
683 free_left = (u16_t)(free_left - p->len);
684 p = p->next;
685 f->next = NULL;
686 pbuf_free(f);
687 } else {
688 pbuf_remove_header(p, free_left);
689 free_left = 0;
690 }
691 }
692 return p;
693}
694
728u8_t
729pbuf_free(struct pbuf *p)
730{
731 u8_t alloc_src;
732 struct pbuf *q;
733 u8_t count;
734
735 if (p == NULL) {
736 LWIP_ASSERT("p != NULL", p != NULL);
737 /* if assertions are disabled, proceed with debug output */
739 ("pbuf_free(p == NULL) was called.\n"));
740 return 0;
741 }
742 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free(%p)\n", (void *)p));
743
744 PERF_START;
745
746 count = 0;
747 /* de-allocate all consecutive pbufs from the head of the chain that
748 * obtain a zero reference count after decrementing*/
749 while (p != NULL) {
751 SYS_ARCH_DECL_PROTECT(old_level);
752 /* Since decrementing ref cannot be guaranteed to be a single machine operation
753 * we must protect it. We put the new ref into a local variable to prevent
754 * further protection. */
755 SYS_ARCH_PROTECT(old_level);
756 /* all pbufs in a chain are referenced at least once */
757 LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0);
758 /* decrease reference count (number of pointers to pbuf) */
759 ref = --(p->ref);
760 SYS_ARCH_UNPROTECT(old_level);
761 /* this pbuf is no longer referenced to? */
762 if (ref == 0) {
763 /* remember next pbuf in chain for next iteration */
764 q = p->next;
765 LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: deallocating %p\n", (void *)p));
766 alloc_src = pbuf_get_allocsrc(p);
767#if LWIP_SUPPORT_CUSTOM_PBUF
768 /* is this a custom pbuf? */
769 if ((p->flags & PBUF_FLAG_IS_CUSTOM) != 0) {
770 struct pbuf_custom *pc = (struct pbuf_custom *)p;
771 LWIP_ASSERT("pc->custom_free_function != NULL", pc->custom_free_function != NULL);
772 pc->custom_free_function(p);
773 } else
774#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
775 {
776 /* is this a pbuf from the pool? */
777 if (alloc_src == PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL) {
778 memp_free(MEMP_PBUF_POOL, p);
779 /* is this a ROM or RAM referencing pbuf? */
780 } else if (alloc_src == PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF) {
781 memp_free(MEMP_PBUF, p);
782 /* type == PBUF_RAM */
783 } else if (alloc_src == PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP) {
784 mem_free(p);
785 } else {
786 /* @todo: support freeing other types */
787 LWIP_ASSERT("invalid pbuf type", 0);
788 }
789 }
790 count++;
791 /* proceed to next pbuf */
792 p = q;
793 /* p->ref > 0, this pbuf is still referenced to */
794 /* (and so the remaining pbufs in chain as well) */
795 } else {
796 LWIP_DEBUGF( PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_free: %p has ref %"U16_F", ending here.\n", (void *)p, (u16_t)ref));
797 /* stop walking through the chain */
798 p = NULL;
799 }
800 }
801 PERF_STOP("pbuf_free");
802 /* return number of de-allocated pbufs */
803 return count;
804}
805
812u16_t
813pbuf_clen(const struct pbuf *p)
814{
815 u16_t len;
816
817 len = 0;
818 while (p != NULL) {
819 ++len;
820 p = p->next;
821 }
822 return len;
823}
824
832void
833pbuf_ref(struct pbuf *p)
834{
835 /* pbuf given? */
836 if (p != NULL) {
837 SYS_ARCH_SET(p->ref, (LWIP_PBUF_REF_T)(p->ref + 1));
838 LWIP_ASSERT("pbuf ref overflow", p->ref > 0);
839 }
840}
841
856void
857pbuf_cat(struct pbuf *h, struct pbuf *t)
858{
859 struct pbuf *p;
860
861 LWIP_ERROR("(h != NULL) && (t != NULL) (programmer violates API)",
862 ((h != NULL) && (t != NULL)), return;);
863 LWIP_ASSERT("Creating an infinite loop", h != t);
864
865 /* proceed to last pbuf of chain */
866 for (p = h; p->next != NULL; p = p->next) {
867 /* add total length of second chain to all totals of first chain */
868 p->tot_len = (u16_t)(p->tot_len + t->tot_len);
869 }
870 /* { p is last pbuf of first h chain, p->next == NULL } */
871 LWIP_ASSERT("p->tot_len == p->len (of last pbuf in chain)", p->tot_len == p->len);
872 LWIP_ASSERT("p->next == NULL", p->next == NULL);
873 /* add total length of second chain to last pbuf total of first chain */
874 p->tot_len = (u16_t)(p->tot_len + t->tot_len);
875 /* chain last pbuf of head (p) with first of tail (t) */
876 p->next = t;
877 /* p->next now references t, but the caller will drop its reference to t,
878 * so netto there is no change to the reference count of t.
879 */
880}
881
899void
900pbuf_chain(struct pbuf *h, struct pbuf *t)
901{
902 pbuf_cat(h, t);
903 /* t is now referenced by h */
904 pbuf_ref(t);
905 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_chain: %p references %p\n", (void *)h, (void *)t));
906}
907
916struct pbuf *
918{
919 struct pbuf *q;
920 u8_t tail_gone = 1;
921 /* tail */
922 q = p->next;
923 /* pbuf has successor in chain? */
924 if (q != NULL) {
925 /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
926 LWIP_ASSERT("p->tot_len == p->len + q->tot_len", q->tot_len == p->tot_len - p->len);
927 /* enforce invariant if assertion is disabled */
928 q->tot_len = (u16_t)(p->tot_len - p->len);
929 /* decouple pbuf from remainder */
930 p->next = NULL;
931 /* total length of pbuf p is its own length only */
932 p->tot_len = p->len;
933 /* q is no longer referenced by p, free it */
934 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_dechain: unreferencing %p\n", (void *)q));
935 tail_gone = pbuf_free(q);
936 if (tail_gone > 0) {
937 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE,
938 ("pbuf_dechain: deallocated %p (as it is no longer referenced)\n", (void *)q));
939 }
940 /* return remaining tail or NULL if deallocated */
941 }
942 /* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */
943 LWIP_ASSERT("p->tot_len == p->len", p->tot_len == p->len);
944 return ((tail_gone > 0) ? NULL : q);
945}
946
961err_t
962pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
963{
964 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy(%p, %p)\n",
965 (const void *)p_to, (const void *)p_from));
966
967 LWIP_ERROR("pbuf_copy: invalid source", p_from != NULL, return ERR_ARG;);
968 return pbuf_copy_partial_pbuf(p_to, p_from, p_from->tot_len, 0);
969}
970
988err_t
989pbuf_copy_partial_pbuf(struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_len, u16_t offset)
990{
991 size_t offset_to = offset, offset_from = 0, len;
992
993 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy_partial_pbuf(%p, %p, %"U16_F", %"U16_F")\n",
994 (const void *)p_to, (const void *)p_from, copy_len, offset));
995
996 /* is the copy_len in range? */
997 LWIP_ERROR("pbuf_copy_partial_pbuf: copy_len bigger than source", ((p_from != NULL) &&
998 (p_from->tot_len >= copy_len)), return ERR_ARG;);
999 /* is the target big enough to hold the source? */
1000 LWIP_ERROR("pbuf_copy_partial_pbuf: target not big enough", ((p_to != NULL) &&
1001 (p_to->tot_len >= (offset + copy_len))), return ERR_ARG;);
1002
1003 /* iterate through pbuf chain */
1004 do {
1005 /* copy one part of the original chain */
1006 if ((p_to->len - offset_to) >= (p_from->len - offset_from)) {
1007 /* complete current p_from fits into current p_to */
1008 len = p_from->len - offset_from;
1009 } else {
1010 /* current p_from does not fit into current p_to */
1011 len = p_to->len - offset_to;
1012 }
1013 len = LWIP_MIN(copy_len, len);
1014 MEMCPY((u8_t *)p_to->payload + offset_to, (u8_t *)p_from->payload + offset_from, len);
1015 offset_to += len;
1016 offset_from += len;
1017 copy_len = (u16_t)(copy_len - len);
1018 LWIP_ASSERT("offset_to <= p_to->len", offset_to <= p_to->len);
1019 LWIP_ASSERT("offset_from <= p_from->len", offset_from <= p_from->len);
1020 if (offset_from >= p_from->len) {
1021 /* on to next p_from (if any) */
1022 offset_from = 0;
1023 p_from = p_from->next;
1024 LWIP_ERROR("p_from != NULL", (p_from != NULL) || (copy_len == 0), return ERR_ARG;);
1025 }
1026 if (offset_to == p_to->len) {
1027 /* on to next p_to (if any) */
1028 offset_to = 0;
1029 p_to = p_to->next;
1030 LWIP_ERROR("p_to != NULL", (p_to != NULL) || (copy_len == 0), return ERR_ARG;);
1031 }
1032
1033 if ((p_from != NULL) && (p_from->len == p_from->tot_len)) {
1034 /* don't copy more than one packet! */
1035 LWIP_ERROR("pbuf_copy_partial_pbuf() does not allow packet queues!",
1036 (p_from->next == NULL), return ERR_VAL;);
1037 }
1038 if ((p_to != NULL) && (p_to->len == p_to->tot_len)) {
1039 /* don't copy more than one packet! */
1040 LWIP_ERROR("pbuf_copy_partial_pbuf() does not allow packet queues!",
1041 (p_to->next == NULL), return ERR_VAL;);
1042 }
1043 } while (copy_len);
1044 LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy_partial_pbuf: copy complete.\n"));
1045 return ERR_OK;
1046}
1047
1060u16_t
1061pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
1062{
1063 const struct pbuf *p;
1064 u16_t left = 0;
1065 u16_t buf_copy_len;
1066 u16_t copied_total = 0;
1067
1068 LWIP_ERROR("pbuf_copy_partial: invalid buf", (buf != NULL), return 0;);
1069 LWIP_ERROR("pbuf_copy_partial: invalid dataptr", (dataptr != NULL), return 0;);
1070
1071 /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
1072 for (p = buf; len != 0 && p != NULL; p = p->next) {
1073 if ((offset != 0) && (offset >= p->len)) {
1074 /* don't copy from this buffer -> on to the next */
1075 offset = (u16_t)(offset - p->len);
1076 } else {
1077 /* copy from this buffer. maybe only partially. */
1078 buf_copy_len = (u16_t)(p->len - offset);
1079 if (buf_copy_len > len) {
1080 buf_copy_len = len;
1081 }
1082 /* copy the necessary parts of the buffer */
1083 MEMCPY(&((char *)dataptr)[left], &((char *)p->payload)[offset], buf_copy_len);
1084 copied_total = (u16_t)(copied_total + buf_copy_len);
1085 left = (u16_t)(left + buf_copy_len);
1086 len = (u16_t)(len - buf_copy_len);
1087 offset = 0;
1088 }
1089 }
1090 return copied_total;
1091}
1092
1110void *
1111pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset)
1112{
1113 const struct pbuf *q;
1114 u16_t out_offset;
1115
1116 LWIP_ERROR("pbuf_get_contiguous: invalid buf", (p != NULL), return NULL;);
1117 LWIP_ERROR("pbuf_get_contiguous: invalid bufsize", (buffer == NULL) || (bufsize >= len), return NULL;);
1118
1119 q = pbuf_skip_const(p, offset, &out_offset);
1120 if (q != NULL) {
1121 if (q->len >= (out_offset + len)) {
1122 /* all data in this pbuf, return zero-copy */
1123 return (u8_t *)q->payload + out_offset;
1124 }
1125 if (buffer == NULL) {
1126 /* the caller does not want to copy */
1127 return NULL;
1128 }
1129 /* need to copy */
1130 if (pbuf_copy_partial(q, buffer, len, out_offset) != len) {
1131 /* copying failed: pbuf is too short */
1132 return NULL;
1133 }
1134 return buffer;
1135 }
1136 /* pbuf is too short (offset does not fit in) */
1137 return NULL;
1138}
1139
1140#if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
1153void pbuf_split_64k(struct pbuf *p, struct pbuf **rest)
1154{
1155 *rest = NULL;
1156 if ((p != NULL) && (p->next != NULL)) {
1157 u16_t tot_len_front = p->len;
1158 struct pbuf *i = p;
1159 struct pbuf *r = p->next;
1160
1161 /* continue until the total length (summed up as u16_t) overflows */
1162 while ((r != NULL) && ((u16_t)(tot_len_front + r->len) >= tot_len_front)) {
1163 tot_len_front = (u16_t)(tot_len_front + r->len);
1164 i = r;
1165 r = r->next;
1166 }
1167 /* i now points to last packet of the first segment. Set next
1168 pointer to NULL */
1169 i->next = NULL;
1170
1171 if (r != NULL) {
1172 /* Update the tot_len field in the first part */
1173 for (i = p; i != NULL; i = i->next) {
1174 i->tot_len = (u16_t)(i->tot_len - r->tot_len);
1175 LWIP_ASSERT("tot_len/len mismatch in last pbuf",
1176 (i->next != NULL) || (i->tot_len == i->len));
1177 }
1178 if (p->flags & PBUF_FLAG_TCP_FIN) {
1180 }
1181
1182 /* tot_len field in rest does not need modifications */
1183 /* reference counters do not need modifications */
1184 *rest = r;
1185 }
1186 }
1187}
1188#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
1189
1190/* Actual implementation of pbuf_skip() but returning const pointer... */
1191static const struct pbuf *
1192pbuf_skip_const(const struct pbuf *in, u16_t in_offset, u16_t *out_offset)
1193{
1194 u16_t offset_left = in_offset;
1195 const struct pbuf *q = in;
1196
1197 /* get the correct pbuf */
1198 while ((q != NULL) && (q->len <= offset_left)) {
1199 offset_left = (u16_t)(offset_left - q->len);
1200 q = q->next;
1201 }
1202 if (out_offset != NULL) {
1203 *out_offset = offset_left;
1204 }
1205 return q;
1206}
1207
1217struct pbuf *
1218pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset)
1219{
1220 const struct pbuf *out = pbuf_skip_const(in, in_offset, out_offset);
1221 return LWIP_CONST_CAST(struct pbuf *, out);
1222}
1223
1235err_t
1236pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
1237{
1238 struct pbuf *p;
1239 size_t buf_copy_len;
1240 size_t total_copy_len = len;
1241 size_t copied_total = 0;
1242
1243 LWIP_ERROR("pbuf_take: invalid buf", (buf != NULL), return ERR_ARG;);
1244 LWIP_ERROR("pbuf_take: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
1245 LWIP_ERROR("pbuf_take: buf not large enough", (buf->tot_len >= len), return ERR_MEM;);
1246
1247 if ((buf == NULL) || (dataptr == NULL) || (buf->tot_len < len)) {
1248 return ERR_ARG;
1249 }
1250
1251 /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
1252 for (p = buf; total_copy_len != 0; p = p->next) {
1253 LWIP_ASSERT("pbuf_take: invalid pbuf", p != NULL);
1254 buf_copy_len = total_copy_len;
1255 if (buf_copy_len > p->len) {
1256 /* this pbuf cannot hold all remaining data */
1257 buf_copy_len = p->len;
1258 }
1259 /* copy the necessary parts of the buffer */
1260 MEMCPY(p->payload, &((const char *)dataptr)[copied_total], buf_copy_len);
1261 total_copy_len -= buf_copy_len;
1262 copied_total += buf_copy_len;
1263 }
1264 LWIP_ASSERT("did not copy all data", total_copy_len == 0 && copied_total == len);
1265 return ERR_OK;
1266}
1267
1279err_t
1280pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
1281{
1282 u16_t target_offset;
1283 struct pbuf *q = pbuf_skip(buf, offset, &target_offset);
1284
1285 /* return requested data if pbuf is OK */
1286 if ((q != NULL) && (q->tot_len >= target_offset + len)) {
1287 u16_t remaining_len = len;
1288 const u8_t *src_ptr = (const u8_t *)dataptr;
1289 /* copy the part that goes into the first pbuf */
1290 u16_t first_copy_len;
1291 LWIP_ASSERT("check pbuf_skip result", target_offset < q->len);
1292 first_copy_len = (u16_t)LWIP_MIN(q->len - target_offset, len);
1293 MEMCPY(((u8_t *)q->payload) + target_offset, dataptr, first_copy_len);
1294 remaining_len = (u16_t)(remaining_len - first_copy_len);
1295 src_ptr += first_copy_len;
1296 if (remaining_len > 0) {
1297 return pbuf_take(q->next, src_ptr, remaining_len);
1298 }
1299 return ERR_OK;
1300 }
1301 return ERR_MEM;
1302}
1303
1317struct pbuf *
1319{
1320 struct pbuf *q;
1321 if (p->next == NULL) {
1322 return p;
1323 }
1324 q = pbuf_clone(layer, PBUF_RAM, p);
1325 if (q == NULL) {
1326 /* @todo: what do we do now? */
1327 return p;
1328 }
1329 pbuf_free(p);
1330 return q;
1331}
1332
1345struct pbuf *
1346pbuf_clone(pbuf_layer layer, pbuf_type type, struct pbuf *p)
1347{
1348 struct pbuf *q;
1349 err_t err;
1350 q = pbuf_alloc(layer, p->tot_len, type);
1351 if (q == NULL) {
1352 return NULL;
1353 }
1354 err = pbuf_copy(q, p);
1355 LWIP_UNUSED_ARG(err); /* in case of LWIP_NOASSERT */
1356 LWIP_ASSERT("pbuf_copy failed", err == ERR_OK);
1357 return q;
1358}
1359
1360#if LWIP_CHECKSUM_ON_COPY
1373err_t
1374pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
1375 u16_t len, u16_t *chksum)
1376{
1377 u32_t acc;
1378 u16_t copy_chksum;
1379 char *dst_ptr;
1380 LWIP_ASSERT("p != NULL", p != NULL);
1381 LWIP_ASSERT("dataptr != NULL", dataptr != NULL);
1382 LWIP_ASSERT("chksum != NULL", chksum != NULL);
1383 LWIP_ASSERT("len != 0", len != 0);
1384
1385 if ((start_offset >= p->len) || (start_offset + len > p->len)) {
1386 return ERR_ARG;
1387 }
1388
1389 dst_ptr = ((char *)p->payload) + start_offset;
1390 copy_chksum = LWIP_CHKSUM_COPY(dst_ptr, dataptr, len);
1391 if ((start_offset & 1) != 0) {
1392 copy_chksum = SWAP_BYTES_IN_WORD(copy_chksum);
1393 }
1394 acc = *chksum;
1395 acc += copy_chksum;
1396 *chksum = FOLD_U32T(acc);
1397 return ERR_OK;
1398}
1399#endif /* LWIP_CHECKSUM_ON_COPY */
1400
1410u8_t
1411pbuf_get_at(const struct pbuf *p, u16_t offset)
1412{
1413 int ret = pbuf_try_get_at(p, offset);
1414 if (ret >= 0) {
1415 return (u8_t)ret;
1416 }
1417 return 0;
1418}
1419
1428int
1429pbuf_try_get_at(const struct pbuf *p, u16_t offset)
1430{
1431 u16_t q_idx;
1432 const struct pbuf *q = pbuf_skip_const(p, offset, &q_idx);
1433
1434 /* return requested data if pbuf is OK */
1435 if ((q != NULL) && (q->len > q_idx)) {
1436 return ((u8_t *)q->payload)[q_idx];
1437 }
1438 return -1;
1439}
1440
1450void
1451pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
1452{
1453 u16_t q_idx;
1454 struct pbuf *q = pbuf_skip(p, offset, &q_idx);
1455
1456 /* write requested data if pbuf is OK */
1457 if ((q != NULL) && (q->len > q_idx)) {
1458 ((u8_t *)q->payload)[q_idx] = data;
1459 }
1460}
1461
1473u16_t
1474pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
1475{
1476 u16_t start = offset;
1477 const struct pbuf *q = p;
1478 u16_t i;
1479
1480 /* pbuf long enough to perform check? */
1481 if (p->tot_len < (offset + n)) {
1482 return 0xffff;
1483 }
1484
1485 /* get the correct pbuf from chain. We know it succeeds because of p->tot_len check above. */
1486 while ((q != NULL) && (q->len <= start)) {
1487 start = (u16_t)(start - q->len);
1488 q = q->next;
1489 }
1490
1491 /* return requested data if pbuf is OK */
1492 for (i = 0; i < n; i++) {
1493 /* We know pbuf_get_at() succeeds because of p->tot_len check above. */
1494 u8_t a = pbuf_get_at(q, (u16_t)(start + i));
1495 u8_t b = ((const u8_t *)s2)[i];
1496 if (a != b) {
1497 return (u16_t)LWIP_MIN(i + 1, 0xFFFF);
1498 }
1499 }
1500 return 0;
1501}
1502
1515u16_t
1516pbuf_memfind(const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
1517{
1518 u16_t i;
1519 u16_t max_cmp_start = (u16_t)(p->tot_len - mem_len);
1520 if (p->tot_len >= mem_len + start_offset) {
1521 for (i = start_offset; i <= max_cmp_start; i++) {
1522 u16_t plus = pbuf_memcmp(p, i, mem, mem_len);
1523 if (plus == 0) {
1524 return i;
1525 }
1526 }
1527 }
1528 return 0xFFFF;
1529}
1530
1542u16_t
1543pbuf_strstr(const struct pbuf *p, const char *substr)
1544{
1545 size_t substr_len;
1546 if ((substr == NULL) || (substr[0] == 0) || (p->tot_len == 0xFFFF)) {
1547 return 0xFFFF;
1548 }
1549 substr_len = strlen(substr);
1550 if (substr_len >= 0xFFFF) {
1551 return 0xFFFF;
1552 }
1553 return pbuf_memfind(p, substr, (u16_t)substr_len, 0);
1554}
#define LWIP_UNUSED_ARG(x)
Definition arch.h:373
#define LWIP_CONST_CAST(target_type, val)
Definition arch.h:240
#define LWIP_MEM_ALIGN(addr)
Definition arch.h:294
#define LWIP_MEM_ALIGN_SIZE(size)
Definition arch.h:279
#define LWIP_DBG_LEVEL_SERIOUS
Definition debug.h:57
#define LWIP_DBG_LEVEL_WARNING
Definition debug.h:55
#define LWIP_DBG_TRACE
Definition debug.h:83
@ ERR_OK
Definition err.h:55
@ ERR_VAL
Definition err.h:67
@ ERR_MEM
Definition err.h:57
@ ERR_ARG
Definition err.h:88
#define PBUF_DEBUG
Definition opt.h:3373
#define MEMCPY(dst, src, len)
Definition opt.h:137
#define LWIP_PBUF_CUSTOM_DATA_INIT(p)
Definition opt.h:1644
#define LWIP_PBUF_REF_T
Definition opt.h:1625
struct pbuf * pbuf_coalesce(struct pbuf *p, pbuf_layer layer)
Definition pbuf.c:1318
u16_t pbuf_memfind(const struct pbuf *p, const void *mem, u16_t mem_len, u16_t start_offset)
Definition pbuf.c:1516
u16_t pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
Definition pbuf.c:1474
struct pbuf * pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type)
Definition pbuf.c:329
u8_t pbuf_get_at(const struct pbuf *p, u16_t offset)
Definition pbuf.c:1411
void * pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset)
Definition pbuf.c:1111
void pbuf_ref(struct pbuf *p)
Definition pbuf.c:833
void pbuf_cat(struct pbuf *head, struct pbuf *tail)
Definition pbuf.c:857
void pbuf_chain(struct pbuf *h, struct pbuf *t)
Definition pbuf.c:900
int pbuf_try_get_at(const struct pbuf *p, u16_t offset)
Definition pbuf.c:1429
u8 pbuf_free(struct pbuf *p)
Definition pbuf.c:729
pbuf_type
Definition tcpip.h:207
err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
Definition pbuf.c:962
struct pbuf * pbuf_skip(struct pbuf *in, u16_t in_offset, u16_t *out_offset)
Definition pbuf.c:1218
u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset)
Definition pbuf.c:1061
struct pbuf * pbuf_clone(pbuf_layer l, pbuf_type type, struct pbuf *p)
Definition pbuf.c:1346
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:989
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
Definition pbuf.c:1280
pbuf_layer
Definition tcpip.h:178
void pbuf_put_at(struct pbuf *p, u16_t offset, u8_t data)
Definition pbuf.c:1451
@ PBUF_ROM
Definition tcpip.h:218
@ PBUF_RAM
Definition tcpip.h:214
@ PBUF_REF
Definition tcpip.h:222
@ PBUF_POOL
Definition tcpip.h:229
#define SWAP_BYTES_IN_WORD(w)
Definition inet_chksum.h:48
#define FOLD_U32T(u)
Definition inet_chksum.h:53
void * mem_trim(void *mem, mem_size_t size)
Definition mem.c:686
void mem_free(void *mem)
Definition mem.c:604
void * mem_malloc(mem_size_t size)
Definition mem.c:818
void * memp_malloc(memp_t type)
Definition memp.c:337
void memp_free(memp_t type, void *mem)
Definition memp.c:420
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size)
Definition pbuf.c:661
u8_t pbuf_add_header(struct pbuf *p, size_t header_size_increment)
Definition pbuf.c:556
#define PBUF_FLAG_TCP_FIN
Definition pbuf.h:183
#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS
Definition pbuf.h:119
#define LWIP_SUPPORT_CUSTOM_PBUF
Definition pbuf.h:55
u16_t pbuf_strstr(const struct pbuf *p, const char *substr)
Definition pbuf.c:1543
struct pbuf * pbuf_free_header(struct pbuf *q, u16_t size)
Definition pbuf.c:676
u8_t pbuf_remove_header(struct pbuf *p, size_t header_size)
Definition pbuf.c:587
u8_t pbuf_add_header_force(struct pbuf *p, size_t header_size_increment)
Definition pbuf.c:566
#define PBUF_FLAG_IS_CUSTOM
Definition pbuf.h:175
u8 pbuf_header(struct pbuf *p, s16 header_size)
Definition pbuf.c:651
struct pbuf * pbuf_dechain(struct pbuf *p)
Definition pbuf.c:917
Definition mem.c:336
Definition tcpip.h:234
void * payload
Definition tcpip.h:239
u16 ref
Definition tcpip.h:264
struct pbuf * next
Definition tcpip.h:236
u8_t type_internal
Definition pbuf.h:208
u8 flags
Definition tcpip.h:257
u16 tot_len
Definition tcpip.h:248
u16 len
Definition tcpip.h:251
#define SYS_ARCH_DECL_PROTECT(lev)
Definition sys.h:512
u32 count
start sector of fragmented bd/file