]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/uipc_mbuf2.c
2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* $NetBSD: uipc_mbuf.c,v 1.40 1999/04/01 00:23:25 thorpej Exp $ */
31 * Copyright (C) 1999 WIDE Project.
32 * All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. Neither the name of the project nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * Copyright (c) 1982, 1986, 1988, 1991, 1993
61 * The Regents of the University of California. All rights reserved.
63 * Redistribution and use in source and binary forms, with or without
64 * modification, are permitted provided that the following conditions
66 * 1. Redistributions of source code must retain the above copyright
67 * notice, this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in the
70 * documentation and/or other materials provided with the distribution.
71 * 3. All advertising materials mentioning features or use of this software
72 * must display the following acknowledgement:
73 * This product includes software developed by the University of
74 * California, Berkeley and its contributors.
75 * 4. Neither the name of the University nor the names of its contributors
76 * may be used to endorse or promote products derived from this software
77 * without specific prior written permission.
79 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
80 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
85 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
87 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
88 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
91 * @(#)uipc_mbuf.c 8.4 (Berkeley) 2/14/95
94 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
95 * support for mandatory and extensible security protections. This notice
96 * is included in support of clause 2.2 (b) of the Apple Public License,
101 /*#define PULLDOWN_DEBUG*/
103 #include <sys/param.h>
104 #include <sys/systm.h>
105 #include <sys/proc_internal.h>
106 #include <sys/malloc.h>
107 #include <sys/mbuf.h>
108 #include <sys/mcache.h>
109 #include <netinet/in.h>
110 #include <netinet/ip_var.h>
112 #include <netinet/ip6.h>
113 #include <netinet6/ip6_var.h>
117 #include <security/mac_framework.h>
121 * ensure that [off, off + len) is contiguous on the mbuf chain "m".
122 * packet chain before "off" is kept untouched.
123 * if offp == NULL, the target will start at <retval, 0> on resulting chain.
124 * if offp != NULL, the target will start at <retval, *offp> on resulting chain.
126 * on error return (NULL return value), original "m" will be freed.
128 * XXX M_TRAILINGSPACE/M_LEADINGSPACE on shared cluster (sharedcluster)
131 m_pulldown(struct mbuf
*m
, int off
, int len
, int *offp
)
133 struct mbuf
*n
= NULL
, *o
= NULL
;
134 int hlen
= 0, tlen
= 0, olen
= 0;
135 int sharedcluster
= 0;
137 /* check invalid arguments. */
138 VERIFY(len
>= 0 && off
>= 0);
141 panic("m == NULL in m_pulldown()");
143 if (len
> MCLBYTES
) {
145 return NULL
; /* impossible */
148 if (os_add_overflow(off
, len
, &tmp_len
)) {
153 #ifdef PULLDOWN_DEBUG
157 for (t
= m
; t
; t
= t
->m_next
) {
158 printf(" %d", t
->m_len
);
166 * Iterate and make n point to the mbuf
167 * within which the first byte at length
168 * offset is contained from the start of
171 while (n
!= NULL
&& off
> 0) {
172 if (n
->m_len
> off
) {
179 /* be sure to point non-empty mbuf */
180 while (n
!= NULL
&& n
->m_len
== 0) {
186 return NULL
; /* mbuf chain too short */
190 * the target data is on <n, off>.
191 * if we got enough data on the mbuf "n", we're done.
193 * It should be noted, that we should only do this either
194 * when offset is 0, i.e. data is pointing to the start
195 * or when the caller specifies an out argument to get
196 * the offset value in the mbuf to work with data pointer
199 * If offset is not 0 and caller did not provide out-argument
200 * to get offset, we should split the mbuf even when the length
201 * is contained in current mbuf.
203 if ((off
== 0 || offp
) && len
<= n
->m_len
- off
) {
208 * when len <= n->m_len - off and off != 0, it is a special case.
209 * len bytes from <n, off> sits in single mbuf, but the caller does
210 * not like the starting position (off).
211 * chop the current mbuf into two pieces, set off to 0.
213 if (len
<= n
->m_len
- off
) {
214 o
= m_copym(n
, off
, n
->m_len
- off
, M_DONTWAIT
);
217 return NULL
; /* ENOBUFS */
220 o
->m_next
= n
->m_next
;
228 * we need to take hlen from <n, off> and tlen from <n->m_next, 0>,
229 * and construct contiguous mbuf with m_len == len.
230 * note that hlen + tlen == len, and tlen > 0.
232 * Read these variables as head length and tail length
234 hlen
= n
->m_len
- off
;
238 * ensure that we have enough trailing data on mbuf chain.
239 * if not, we can do nothing about the chain.
242 for (o
= n
->m_next
; o
!= NULL
; o
= o
->m_next
) {
245 if (hlen
+ olen
< len
) {
247 return NULL
; /* mbuf chain too short */
252 * we need to use m_copydata() to get data from <n->m_next, 0>.
254 if ((n
->m_flags
& M_EXT
) == 0) {
257 if (m_get_ext_free(n
) != NULL
) {
259 } else if (m_mclhasreference(n
)) {
267 * If we have enough space left in current mbuf to accomodate
268 * tail length, copy tail length worth of data starting with next mbuf
269 * and adjust the length of next one accordingly.
271 if ((off
== 0 || offp
) && M_TRAILINGSPACE(n
) >= tlen
273 m_copydata(n
->m_next
, 0, tlen
, mtod(n
, caddr_t
) + n
->m_len
);
275 m_adj(n
->m_next
, tlen
);
280 * If have enough leading space in next mbuf to accomodate head length
281 * of current mbuf, and total resulting length of next mbuf is greater
282 * than or equal to requested len bytes, then just copy hlen from
283 * current to the next one and adjust sizes accordingly.
285 if ((off
== 0 || offp
) && M_LEADINGSPACE(n
->m_next
) >= hlen
&&
286 (n
->m_next
->m_len
+ hlen
) >= len
&& !sharedcluster
) {
287 n
->m_next
->m_data
-= hlen
;
288 n
->m_next
->m_len
+= hlen
;
289 bcopy(mtod(n
, caddr_t
) + off
, mtod(n
->m_next
, caddr_t
), hlen
);
297 * now, we need to do the hard way. don't m_copy as there's no room
300 MGET(o
, M_DONTWAIT
, m
->m_type
);
303 return NULL
; /* ENOBUFS */
305 if (len
> MHLEN
) { /* use MHLEN just for safety */
306 MCLGET(o
, M_DONTWAIT
);
307 if ((o
->m_flags
& M_EXT
) == 0) {
310 return NULL
; /* ENOBUFS */
313 /* get hlen from <n, off> into <o, 0> */
315 bcopy(mtod(n
, caddr_t
) + off
, mtod(o
, caddr_t
), hlen
);
317 /* get tlen from <n->m_next, 0> into <o, hlen> */
318 m_copydata(n
->m_next
, 0, tlen
, mtod(o
, caddr_t
) + o
->m_len
);
320 m_adj(n
->m_next
, tlen
);
321 o
->m_next
= n
->m_next
;
327 #ifdef PULLDOWN_DEBUG
331 for (t
= m
; t
; t
= t
->m_next
) {
332 printf("%c%d", t
== n
? '*' : ' ', t
->m_len
);
334 printf(" (off=%d)\n", off
);
344 * Create and return an m_tag, either by re-using space in a previous tag
345 * or by allocating a new mbuf/cluster
348 m_tag_create(u_int32_t id
, u_int16_t type
, int len
, int wait
, struct mbuf
*buf
)
350 struct m_tag
*t
= NULL
;
357 if (len
+ sizeof(struct m_tag
) + sizeof(struct m_taghdr
) > MLEN
) {
358 return m_tag_alloc(id
, type
, len
, wait
);
362 * We've exhausted all external cases. Now, go through the m_tag
363 * chain and see if we can fit it in any of them.
364 * If not (t == NULL), call m_tag_alloc to store it in a new mbuf.
366 p
= SLIST_FIRST(&buf
->m_pkthdr
.tags
);
369 if (M_TAG_ALIGN(p
->m_tag_len
) +
370 sizeof(struct m_taghdr
) > MLEN
) {
371 p
= SLIST_NEXT(p
, m_tag_link
);
375 VERIFY(p
->m_tag_cookie
== M_TAG_VALID_PATTERN
);
377 struct mbuf
*m
= m_dtom(p
);
378 struct m_taghdr
*hdr
= (struct m_taghdr
*)(void *)m
->m_data
;
380 VERIFY(IS_P2ALIGNED(hdr
+ 1, sizeof(u_int64_t
)));
381 VERIFY(m
->m_flags
& M_TAGHDR
&& !(m
->m_flags
& M_EXT
));
383 /* The mbuf can store this m_tag */
384 if (M_TAG_ALIGN(len
) <= MLEN
- m
->m_len
) {
385 t
= (struct m_tag
*)(void *)(m
->m_data
+ m
->m_len
);
386 VERIFY(IS_P2ALIGNED(t
, sizeof(u_int64_t
)));
388 m
->m_len
+= M_TAG_ALIGN(len
);
389 VERIFY(m
->m_len
<= MLEN
);
393 p
= SLIST_NEXT(p
, m_tag_link
);
397 return m_tag_alloc(id
, type
, len
, wait
);
400 t
->m_tag_cookie
= M_TAG_VALID_PATTERN
;
401 t
->m_tag_type
= type
;
410 /* Get a packet tag structure along with specified data following. */
412 m_tag_alloc(u_int32_t id
, u_int16_t type
, int len
, int wait
)
420 if (M_TAG_ALIGN(len
) + sizeof(struct m_taghdr
) <= MLEN
) {
421 struct mbuf
*m
= m_get(wait
, MT_TAG
);
422 struct m_taghdr
*hdr
;
428 m
->m_flags
|= M_TAGHDR
;
430 hdr
= (struct m_taghdr
*)(void *)m
->m_data
;
431 VERIFY(IS_P2ALIGNED(hdr
+ 1, sizeof(u_int64_t
)));
433 m
->m_len
+= sizeof(struct m_taghdr
);
434 t
= (struct m_tag
*)(void *)(m
->m_data
+ m
->m_len
);
435 VERIFY(IS_P2ALIGNED(t
, sizeof(u_int64_t
)));
436 m
->m_len
+= M_TAG_ALIGN(len
);
437 VERIFY(m
->m_len
<= MLEN
);
438 } else if (len
+ sizeof(struct m_tag
) <= MCLBYTES
) {
439 t
= (struct m_tag
*)(void *)m_mclalloc(wait
);
448 VERIFY(IS_P2ALIGNED(t
, sizeof(u_int64_t
)));
449 t
->m_tag_cookie
= M_TAG_VALID_PATTERN
;
450 t
->m_tag_type
= type
;
460 /* Free a packet tag. */
462 m_tag_free(struct m_tag
*t
)
466 t
->m_tag_id
== KERNEL_MODULE_TAG_ID
&&
467 t
->m_tag_type
== KERNEL_TAG_TYPE_MACLABEL
) {
468 mac_mbuf_tag_destroy(t
);
475 VERIFY(t
->m_tag_cookie
== M_TAG_VALID_PATTERN
);
477 if (M_TAG_ALIGN(t
->m_tag_len
) + sizeof(struct m_taghdr
) <= MLEN
) {
478 struct mbuf
* m
= m_dtom(t
);
479 VERIFY(m
->m_flags
& M_TAGHDR
);
480 struct m_taghdr
*hdr
= (struct m_taghdr
*)(void *)m
->m_data
;
482 VERIFY(IS_P2ALIGNED(hdr
+ 1, sizeof(u_int64_t
)));
484 /* No other tags in this mbuf */
485 if (--hdr
->refcnt
== 0) {
490 /* Pattern-fill the header */
491 u_int64_t
*fill_ptr
= (u_int64_t
*)t
;
492 u_int64_t
*end_ptr
= (u_int64_t
*)(t
+ 1);
493 while (fill_ptr
< end_ptr
) {
494 *fill_ptr
= M_TAG_FREE_PATTERN
;
498 m_mclfree((caddr_t
)t
);
502 /* Prepend a packet tag. */
504 m_tag_prepend(struct mbuf
*m
, struct m_tag
*t
)
506 VERIFY(m
!= NULL
&& t
!= NULL
);
508 SLIST_INSERT_HEAD(&m
->m_pkthdr
.tags
, t
, m_tag_link
);
511 /* Unlink a packet tag. */
513 m_tag_unlink(struct mbuf
*m
, struct m_tag
*t
)
515 VERIFY(m
->m_flags
& M_PKTHDR
);
516 VERIFY(t
!= NULL
&& t
->m_tag_cookie
== M_TAG_VALID_PATTERN
);
518 SLIST_REMOVE(&m
->m_pkthdr
.tags
, t
, m_tag
, m_tag_link
);
521 /* Unlink and free a packet tag. */
523 m_tag_delete(struct mbuf
*m
, struct m_tag
*t
)
529 /* Unlink and free a packet tag chain, starting from given tag. */
531 m_tag_delete_chain(struct mbuf
*m
, struct m_tag
*t
)
535 VERIFY(m
->m_flags
& M_PKTHDR
);
540 p
= SLIST_FIRST(&m
->m_pkthdr
.tags
);
546 VERIFY(p
->m_tag_cookie
== M_TAG_VALID_PATTERN
);
547 while ((q
= SLIST_NEXT(p
, m_tag_link
)) != NULL
) {
548 VERIFY(q
->m_tag_cookie
== M_TAG_VALID_PATTERN
);
554 /* Find a tag, starting from a given position. */
556 m_tag_locate(struct mbuf
*m
, u_int32_t id
, u_int16_t type
, struct m_tag
*t
)
560 VERIFY(m
->m_flags
& M_PKTHDR
);
563 p
= SLIST_FIRST(&m
->m_pkthdr
.tags
);
565 VERIFY(t
->m_tag_cookie
== M_TAG_VALID_PATTERN
);
566 p
= SLIST_NEXT(t
, m_tag_link
);
569 VERIFY(p
->m_tag_cookie
== M_TAG_VALID_PATTERN
);
570 if (p
->m_tag_id
== id
&& p
->m_tag_type
== type
) {
573 p
= SLIST_NEXT(p
, m_tag_link
);
578 /* Copy a single tag. */
580 m_tag_copy(struct m_tag
*t
, int how
)
586 p
= m_tag_alloc(t
->m_tag_id
, t
->m_tag_type
, t
->m_tag_len
, how
);
592 * XXXMAC: we should probably pass off the initialization, and
593 * copying here? can we hid that KERNEL_TAG_TYPE_MACLABEL is
594 * special from the mbuf code?
597 t
->m_tag_id
== KERNEL_MODULE_TAG_ID
&&
598 t
->m_tag_type
== KERNEL_TAG_TYPE_MACLABEL
) {
599 if (mac_mbuf_tag_init(p
, how
) != 0) {
603 mac_mbuf_tag_copy(t
, p
);
606 bcopy(t
+ 1, p
+ 1, t
->m_tag_len
); /* Copy the data */
611 * Copy two tag chains. The destination mbuf (to) loses any attached
612 * tags even if the operation fails. This should not be a problem, as
613 * m_tag_copy_chain() is typically called with a newly-allocated
617 m_tag_copy_chain(struct mbuf
*to
, struct mbuf
*from
, int how
)
619 struct m_tag
*p
, *t
, *tprev
= NULL
;
621 VERIFY((to
->m_flags
& M_PKTHDR
) && (from
->m_flags
& M_PKTHDR
));
623 m_tag_delete_chain(to
, NULL
);
624 SLIST_FOREACH(p
, &from
->m_pkthdr
.tags
, m_tag_link
) {
625 VERIFY(p
->m_tag_cookie
== M_TAG_VALID_PATTERN
);
626 t
= m_tag_copy(p
, how
);
628 m_tag_delete_chain(to
, NULL
);
632 SLIST_INSERT_HEAD(&to
->m_pkthdr
.tags
, t
, m_tag_link
);
634 SLIST_INSERT_AFTER(tprev
, t
, m_tag_link
);
641 /* Initialize dynamic and static tags on an mbuf. */
643 m_tag_init(struct mbuf
*m
, int all
)
645 VERIFY(m
->m_flags
& M_PKTHDR
);
647 SLIST_INIT(&m
->m_pkthdr
.tags
);
649 * If the caller wants to preserve static mbuf tags
650 * (e.g. m_dup_pkthdr), don't zero them out.
653 bzero(&m
->m_pkthdr
.builtin_mtag
._net_mtag
,
654 sizeof(m
->m_pkthdr
.builtin_mtag
._net_mtag
));
658 /* Get first tag in chain. */
660 m_tag_first(struct mbuf
*m
)
662 VERIFY(m
->m_flags
& M_PKTHDR
);
664 return SLIST_FIRST(&m
->m_pkthdr
.tags
);
667 /* Get next tag in chain. */
669 m_tag_next(struct mbuf
*m
, struct m_tag
*t
)
673 VERIFY(t
->m_tag_cookie
== M_TAG_VALID_PATTERN
);
675 return SLIST_NEXT(t
, m_tag_link
);
679 m_set_traffic_class(struct mbuf
*m
, mbuf_traffic_class_t tc
)
681 u_int32_t val
= MBUF_TC2SCVAL(tc
); /* just the val portion */
683 return m_set_service_class(m
, m_service_class_from_val(val
));
687 m_get_traffic_class(struct mbuf
*m
)
689 return MBUF_SC2TC(m_get_service_class(m
));
693 m_set_service_class(struct mbuf
*m
, mbuf_svc_class_t sc
)
697 VERIFY(m
->m_flags
& M_PKTHDR
);
699 if (MBUF_VALID_SC(sc
)) {
700 m
->m_pkthdr
.pkt_svc
= sc
;
709 m_get_service_class(struct mbuf
*m
)
713 VERIFY(m
->m_flags
& M_PKTHDR
);
715 if (MBUF_VALID_SC(m
->m_pkthdr
.pkt_svc
)) {
716 sc
= m
->m_pkthdr
.pkt_svc
;
725 m_service_class_from_idx(u_int32_t i
)
727 mbuf_svc_class_t sc
= MBUF_SC_BE
;
731 return MBUF_SC_BK_SYS
;
770 m_service_class_from_val(u_int32_t v
)
772 mbuf_svc_class_t sc
= MBUF_SC_BE
;
776 return MBUF_SC_BK_SYS
;
815 m_adj_sum16(struct mbuf
*m
, uint32_t start
, uint32_t dataoff
,
816 uint32_t datalen
, uint32_t sum
)
818 uint32_t total_sub
= 0; /* total to subtract */
819 uint32_t mlen
= m_pktlen(m
); /* frame length */
820 uint32_t bytes
= (dataoff
+ datalen
); /* bytes covered by sum */
823 ASSERT(bytes
<= mlen
);
826 * Take care of excluding (len > 0) or including (len < 0)
827 * extraneous octets at the beginning of the packet, taking
828 * into account the start offset.
830 len
= (dataoff
- start
);
832 total_sub
= m_sum16(m
, start
, len
);
833 } else if (len
< 0) {
834 sum
+= m_sum16(m
, dataoff
, -len
);
838 * Take care of excluding any postpended extraneous octets.
840 len
= (mlen
- bytes
);
843 uint32_t extra
= m_sum16(m
, bytes
, len
);
844 uint32_t off
= bytes
, off0
= off
;
847 if (__improbable(m
== NULL
)) {
848 panic("%s: invalid mbuf chain %p [off %u, "
849 "len %u]", __func__
, m0
, off0
, len
);
852 if (off
< m
->m_len
) {
859 /* if we started on odd-alignment, swap the value */
860 if ((uintptr_t)(mtod(m
, uint8_t *) + off
) & 1) {
861 total_sub
+= ((extra
<< 8) & 0xffff) | (extra
>> 8);
866 total_sub
= (total_sub
>> 16) + (total_sub
& 0xffff);
870 * 1's complement subtract any extraneous octets.
872 if (total_sub
!= 0) {
873 if (total_sub
>= sum
) {
874 sum
= ~(total_sub
- sum
) & 0xffff;
880 /* fold 32-bit to 16-bit */
881 sum
= (sum
>> 16) + (sum
& 0xffff); /* 17-bit */
882 sum
= (sum
>> 16) + (sum
& 0xffff); /* 16-bit + carry */
883 sum
= (sum
>> 16) + (sum
& 0xffff); /* final carry */
889 m_sum16(struct mbuf
*m
, uint32_t off
, uint32_t len
)
896 * Use m_length2() instead of m_length(), as we cannot rely on
897 * the caller setting m_pkthdr.len correctly, if the mbuf is
900 if ((mlen
= m_length2(m
, NULL
)) < (off
+ len
)) {
901 panic("%s: mbuf %p len (%d) < off+len (%d+%d)\n", __func__
,
906 return os_cpu_in_cksum_mbuf(m
, len
, off
, 0);