]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/mbuf.h
8dafca387c015f37a77fa4a0b35e7d344b4857f8
[apple/xnu.git] / bsd / sys / mbuf.h
1 /*
2 * Copyright (c) 1999-2017 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
29 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 /*
31 * Mach Operating System
32 * Copyright (c) 1987 Carnegie-Mellon University
33 * All rights reserved. The CMU software License Agreement specifies
34 * the terms and conditions for use and redistribution.
35 */
36 /*
37 * Copyright (c) 1994 NeXT Computer, Inc. All rights reserved.
38 *
39 * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
40 * All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by the University of
53 * California, Berkeley and its contributors.
54 * 4. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 *
70 * @(#)mbuf.h 8.3 (Berkeley) 1/21/94
71 */
72 /*
73 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
74 * support for mandatory and extensible security protections. This notice
75 * is included in support of clause 2.2 (b) of the Apple Public License,
76 * Version 2.0.
77 */
78
79 #ifndef _SYS_MBUF_H_
80 #define _SYS_MBUF_H_
81
82 #include <sys/cdefs.h>
83 #include <sys/appleapiopts.h>
84 #include <sys/_types/_u_int32_t.h> /* u_int32_t */
85 #include <sys/_types/_u_int64_t.h> /* u_int64_t */
86 #include <sys/_types/_u_short.h> /* u_short */
87
88 #ifdef XNU_KERNEL_PRIVATE
89
90 #include <sys/lock.h>
91 #include <sys/queue.h>
92 #include <machine/endian.h>
93 /*
94 * Mbufs are of a single size, MSIZE (machine/param.h), which
95 * includes overhead. An mbuf may add a single "mbuf cluster" of size
96 * MCLBYTES/MBIGCLBYTES/M16KCLBYTES (also in machine/param.h), which has
97 * no additional overhead and is used instead of the internal data area;
98 * this is done when at least MINCLSIZE of data must be stored.
99 */
100
101 /*
102 * The following _MLEN and _MHLEN macros are private to xnu. Private code
103 * that are outside of xnu must use the mbuf_get_{mlen,mhlen} routines since
104 * the sizes of the structures are dependent upon specific xnu configs.
105 */
106 #define _MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
107 #define _MHLEN (_MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
108
109 #define NMBPGSHIFT (PAGE_SHIFT - MSIZESHIFT)
110 #define NMBPG (1 << NMBPGSHIFT) /* # of mbufs per page */
111
112 #define NCLPGSHIFT (PAGE_SHIFT - MCLSHIFT)
113 #define NCLPG (1 << NCLPGSHIFT) /* # of cl per page */
114
115 #define NBCLPGSHIFT (PAGE_SHIFT - MBIGCLSHIFT)
116 #define NBCLPG (1 << NBCLPGSHIFT) /* # of big cl per page */
117
118 #define NMBPCLSHIFT (MCLSHIFT - MSIZESHIFT)
119 #define NMBPCL (1 << NMBPCLSHIFT) /* # of mbufs per cl */
120
121 #define NCLPJCLSHIFT (M16KCLSHIFT - MCLSHIFT)
122 #define NCLPJCL (1 << NCLPJCLSHIFT) /* # of cl per jumbo cl */
123
124 #define NCLPBGSHIFT (MBIGCLSHIFT - MCLSHIFT)
125 #define NCLPBG (1 << NCLPBGSHIFT) /* # of cl per big cl */
126
127 #define NMBPBGSHIFT (MBIGCLSHIFT - MSIZESHIFT)
128 #define NMBPBG (1 << NMBPBGSHIFT) /* # of mbufs per big cl */
129
130 /*
131 * Macros for type conversion
132 * mtod(m,t) - convert mbuf pointer to data pointer of correct type
133 * mtodo(m, o) -- Same as above but with offset 'o' into data.
134 * dtom(x) - convert data pointer within mbuf to mbuf pointer (XXX)
135 */
136 #define mtod(m, t) ((t)m_mtod(m))
137 #define mtodo(m, o) ((void *)(mtod(m, uint8_t *) + (o)))
138 #define dtom(x) m_dtom(x)
139
140 /* header at beginning of each mbuf: */
141 struct m_hdr {
142 struct mbuf *mh_next; /* next buffer in chain */
143 struct mbuf *mh_nextpkt; /* next chain in queue/record */
144 caddr_t mh_data; /* location of data */
145 int32_t mh_len; /* amount of data in this mbuf */
146 u_int16_t mh_type; /* type of data in this mbuf */
147 u_int16_t mh_flags; /* flags; see below */
148 #if __arm__ && (__BIGGEST_ALIGNMENT__ > 4)
149 /* This is needed because of how _MLEN is defined and used. Ideally, _MLEN
150 * should be defined using the offsetof(struct mbuf, M_dat), since there is
151 * no guarantee that mbuf.M_dat will start where mbuf.m_hdr ends. The compiler
152 * may (and does in the armv7k case) insert padding between m_hdr and M_dat in
153 * mbuf. We cannot easily use offsetof, however, since _MLEN is referenced
154 * in the definition of mbuf.
155 */
156 } __attribute__((aligned(8)));
157 #else
158 };
159 #endif
160
161 /*
162 * Packet tag structure (see below for details).
163 */
164 struct m_tag {
165 u_int64_t m_tag_cookie; /* Error checking */
166 #ifndef __LP64__
167 u_int32_t pad; /* For structure alignment */
168 #endif /* !__LP64__ */
169 SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
170 u_int16_t m_tag_type; /* Module specific type */
171 u_int16_t m_tag_len; /* Length of data */
172 u_int32_t m_tag_id; /* Module ID */
173 };
174
175 #define M_TAG_ALIGN(len) \
176 (P2ROUNDUP(len, sizeof (u_int64_t)) + sizeof (struct m_tag))
177
178 #define M_TAG_VALID_PATTERN 0xfeedfacefeedfaceULL
179 #define M_TAG_FREE_PATTERN 0xdeadbeefdeadbeefULL
180
181 /*
182 * Packet tag header structure (at the top of mbuf). Pointers are
183 * 32-bit in ILP32; m_tag needs 64-bit alignment, hence padded.
184 */
185 struct m_taghdr {
186 #ifndef __LP64__
187 u_int32_t pad; /* For structure alignment */
188 #endif /* !__LP64__ */
189 u_int64_t refcnt; /* Number of tags in this mbuf */
190 };
191
192 /*
193 * Driver auxiliary metadata tag (KERNEL_TAG_TYPE_DRVAUX).
194 */
195 struct m_drvaux_tag {
196 u_int32_t da_family; /* IFNET_FAMILY values */
197 u_int32_t da_subfamily; /* IFNET_SUBFAMILY values */
198 u_int32_t da_reserved; /* for future */
199 u_int32_t da_length; /* length of following data */
200 };
201
202 /* Values for pftag_flags (16-bit wide) */
203 #define PF_TAG_GENERATED 0x1 /* pkt generated by PF */
204 #define PF_TAG_FRAGCACHE 0x2
205 #define PF_TAG_TRANSLATE_LOCALHOST 0x4
206 #if PF_ECN
207 #define PF_TAG_HDR_INET 0x8 /* hdr points to IPv4 */
208 #define PF_TAG_HDR_INET6 0x10 /* hdr points to IPv6 */
209 #endif /* PF_ECN */
210 /*
211 * PF mbuf tag
212 */
213 struct pf_mtag {
214 u_int16_t pftag_flags; /* PF_TAG flags */
215 u_int16_t pftag_rtableid; /* alternate routing table id */
216 u_int16_t pftag_tag;
217 u_int16_t pftag_routed;
218 #if PF_ECN
219 void *pftag_hdr; /* saved hdr pos in mbuf, for ECN */
220 #endif /* PF_ECN */
221 };
222
223 /*
224 * TCP mbuf tag
225 */
226 struct tcp_pktinfo {
227 union {
228 struct {
229 u_int32_t segsz; /* segment size (actual MSS) */
230 u_int32_t start_seq; /* start seq of this packet */
231 } __tx;
232 struct {
233 u_int16_t lro_pktlen; /* max seg size encountered */
234 u_int8_t lro_npkts; /* # of coalesced TCP pkts */
235 u_int8_t lro_timediff; /* time spent in LRO */
236 } __rx;
237 } __offload;
238 union {
239 u_int32_t pri; /* send msg priority */
240 u_int32_t seq; /* recv msg sequence # */
241 } __msgattr;
242 #define tso_segsz proto_mtag.__pr_u.tcp.tm_tcp.__offload.__tx.segsz
243 #define tx_start_seq proto_mtag.__pr_u.tcp.tm_tcp.__offload.__tx.start_seq
244 #define lro_pktlen proto_mtag.__pr_u.tcp.tm_tcp.__offload.__rx.lro_pktlen
245 #define lro_npkts proto_mtag.__pr_u.tcp.tm_tcp.__offload.__rx.lro_npkts
246 #define lro_elapsed proto_mtag.__pr_u.tcp.tm_tcp.__offload.__rx.lro_timediff
247 #define msg_pri proto_mtag.__pr_u.tcp.tm_tcp.__msgattr.pri
248 #define msg_seq proto_mtag.__pr_u.tcp.tm_tcp.__msgattr.seq
249 };
250
251 /*
252 * MPTCP mbuf tag
253 */
254 struct mptcp_pktinfo {
255 u_int64_t mtpi_dsn; /* MPTCP Data Sequence Number */
256 u_int32_t mtpi_rel_seq; /* Relative Seq Number */
257 u_int16_t mtpi_length; /* Length of mapping */
258 u_int16_t mtpi_csum;
259 #define mp_dsn proto_mtag.__pr_u.tcp.tm_mptcp.mtpi_dsn
260 #define mp_rseq proto_mtag.__pr_u.tcp.tm_mptcp.mtpi_rel_seq
261 #define mp_rlen proto_mtag.__pr_u.tcp.tm_mptcp.mtpi_length
262 #define mp_csum proto_mtag.__pr_u.tcp.tm_mptcp.mtpi_csum
263 };
264
265 /*
266 * TCP specific mbuf tag. Note that the current implementation uses
267 * MPTCP metadata strictly between MPTCP and the TCP subflow layers,
268 * hence tm_tcp and tm_mptcp are mutually exclusive. This also means
269 * that TCP messages functionality is currently incompatible with MPTCP.
270 */
271 struct tcp_mtag {
272 union {
273 struct tcp_pktinfo tm_tcp; /* TCP and below */
274 struct mptcp_pktinfo tm_mptcp; /* MPTCP-TCP only */
275 };
276 };
277
278 struct driver_mtag_ {
279 uintptr_t _drv_tx_compl_arg;
280 uintptr_t _drv_tx_compl_data;
281 kern_return_t _drv_tx_status;
282 uint16_t _drv_flowid;
283 #define drv_tx_compl_arg builtin_mtag._drv_mtag._drv_tx_compl_arg
284 #define drv_tx_compl_data builtin_mtag._drv_mtag._drv_tx_compl_data
285 #define drv_tx_status builtin_mtag._drv_mtag._drv_tx_status
286 #define drv_flowid builtin_mtag._drv_mtag._drv_flowid
287 };
288
289 /*
290 * Protocol specific mbuf tag (at most one protocol metadata per mbuf).
291 *
292 * Care must be taken to ensure that they are mutually exclusive, e.g.
293 * IPSec policy ID implies no TCP segment offload (which is fine given
294 * that the former is used on the virtual ipsec interface that does
295 * not advertise the TSO capability.)
296 */
297 struct proto_mtag_ {
298 union {
299 struct tcp_mtag tcp; /* TCP specific */
300 } __pr_u;
301 };
302
303 /*
304 * NECP specific mbuf tag.
305 */
306 struct necp_mtag_ {
307 u_int32_t necp_policy_id;
308 u_int32_t necp_last_interface_index;
309 u_int32_t necp_route_rule_id;
310 u_int32_t necp_app_id;
311 };
312
313 union builtin_mtag {
314 struct {
315 struct proto_mtag_ _proto_mtag; /* built-in protocol-specific tag */
316 struct pf_mtag _pf_mtag; /* built-in PF tag */
317 struct necp_mtag_ _necp_mtag; /* built-in NECP tag */
318 } _net_mtag;
319 struct driver_mtag_ _drv_mtag;
320 #define necp_mtag builtin_mtag._net_mtag._necp_mtag
321 #define proto_mtag builtin_mtag._net_mtag._proto_mtag
322 #define driver_mtag builtin_mtag._drv_mtag
323 };
324
325 /*
326 * Record/packet header in first mbuf of chain; valid only if M_PKTHDR set.
327 */
328 struct pkthdr {
329 struct ifnet *rcvif; /* rcv interface */
330 /* variables for ip and tcp reassembly */
331 void *pkt_hdr; /* pointer to packet header */
332 int32_t len; /* total packet length */
333 /* variables for hardware checksum */
334 /* Note: csum_flags is used for hardware checksum and VLAN */
335 u_int32_t csum_flags; /* flags regarding checksum */
336 union {
337 struct {
338 u_int16_t val; /* checksum value */
339 u_int16_t start; /* checksum start offset */
340 } _csum_rx;
341 #define csum_rx_val _csum_rx.val
342 #define csum_rx_start _csum_rx.start
343 struct {
344 u_int16_t start; /* checksum start offset */
345 u_int16_t stuff; /* checksum stuff offset */
346 } _csum_tx;
347 #define csum_tx_start _csum_tx.start
348 #define csum_tx_stuff _csum_tx.stuff
349 u_int32_t csum_data; /* data field used by csum routines */
350 };
351 u_int16_t vlan_tag; /* VLAN tag, host byte order */
352 /*
353 * Packet classifier info
354 *
355 * PKTF_FLOW_ID set means valid flow ID. A non-zero flow ID value
356 * means the packet has been classified by one of the flow sources.
357 * It is also a prerequisite for flow control advisory, which is
358 * enabled by additionally setting PKTF_FLOW_ADV.
359 *
360 * The protocol value is a best-effort representation of the payload.
361 * It is opportunistically updated and used only for optimization.
362 * It is not a substitute for parsing the protocol header(s); use it
363 * only as a hint.
364 *
365 * If PKTF_IFAINFO is set, pkt_ifainfo contains one or both of the
366 * indices of interfaces which own the source and/or destination
367 * addresses of the packet. For the local/loopback case (PKTF_LOOP),
368 * both should be valid, and thus allows for the receiving end to
369 * quickly determine the actual interfaces used by the the addresses;
370 * they may not necessarily be the same or refer to the loopback
371 * interface. Otherwise, in the non-local/loopback case, the indices
372 * are opportunistically set, and because of that only one may be set
373 * (0 means the index has not been determined.) In addition, the
374 * interface address flags are also recorded. This allows us to avoid
375 * storing the corresponding {in,in6}_ifaddr in an mbuf tag. Ideally
376 * this would be a superset of {ia,ia6}_flags, but the namespaces are
377 * overlapping at present, so we'll need a new set of values in future
378 * to achieve this. For now, we will just rely on the address family
379 * related code paths examining this mbuf to interpret the flags.
380 */
381 u_int8_t pkt_proto; /* IPPROTO value */
382 u_int8_t pkt_flowsrc; /* FLOWSRC values */
383 u_int32_t pkt_flowid; /* flow ID */
384 u_int32_t pkt_flags; /* PKTF flags (see below) */
385 u_int32_t pkt_svc; /* MBUF_SVC value */
386
387 u_int32_t pkt_compl_context; /* Packet completion context */
388
389 union {
390 struct {
391 u_int16_t src; /* ifindex of src addr i/f */
392 u_int16_t src_flags; /* src PKT_IFAIFF flags */
393 u_int16_t dst; /* ifindex of dst addr i/f */
394 u_int16_t dst_flags; /* dst PKT_IFAIFF flags */
395 } _pkt_iaif;
396 #define src_ifindex _pkt_iaif.src
397 #define src_iff _pkt_iaif.src_flags
398 #define dst_ifindex _pkt_iaif.dst
399 #define dst_iff _pkt_iaif.dst_flags
400 u_int64_t pkt_ifainfo; /* data field used by ifainfo */
401 struct {
402 u_int32_t if_data; /* bytes in interface queue */
403 u_int32_t sndbuf_data; /* bytes in socket buffer */
404 } _pkt_bsr; /* Buffer status report used by cellular interface */
405 #define bufstatus_if _pkt_bsr.if_data
406 #define bufstatus_sndbuf _pkt_bsr.sndbuf_data
407 };
408 u_int64_t pkt_timestamp; /* enqueue time */
409
410 /*
411 * Tags (external and built-in)
412 */
413 SLIST_HEAD(packet_tags, m_tag) tags; /* list of external tags */
414 union builtin_mtag builtin_mtag;
415 /*
416 * Module private scratch space (32-bit aligned), currently 16-bytes
417 * large. Anything stored here is not guaranteed to survive across
418 * modules. The AQM layer (outbound) uses all 16-bytes for both
419 * packet scheduling and flow advisory information.
420 */
421 struct {
422 union {
423 u_int8_t __mpriv8[16];
424 u_int16_t __mpriv16[8];
425 struct {
426 union {
427 u_int8_t __val8[4];
428 u_int16_t __val16[2];
429 u_int32_t __val32;
430 } __mpriv32_u;
431 } __mpriv32[4];
432 u_int64_t __mpriv64[2];
433 } __mpriv_u;
434 } pkt_mpriv __attribute__((aligned(4)));
435 #define pkt_mpriv_hash pkt_mpriv.__mpriv_u.__mpriv32[0].__mpriv32_u.__val32
436 #define pkt_mpriv_flags pkt_mpriv.__mpriv_u.__mpriv32[1].__mpriv32_u.__val32
437 #define pkt_mpriv_srcid pkt_mpriv.__mpriv_u.__mpriv32[2].__mpriv32_u.__val32
438 #define pkt_mpriv_fidx pkt_mpriv.__mpriv_u.__mpriv32[3].__mpriv32_u.__val32
439
440 u_int32_t redzone; /* red zone */
441 u_int32_t pkt_compl_callbacks; /* Packet completion callbacks */
442 };
443
444 /*
445 * Flow data source type. A data source module is responsible for generating
446 * a unique flow ID and associating it to each data flow as pkt_flowid.
447 * This is required for flow control/advisory, as it allows the output queue
448 * to identify the data source object and inform that it can resume its
449 * transmission (in the event it was flow controlled.)
450 */
451 #define FLOWSRC_INPCB 1 /* flow ID generated by INPCB */
452 #define FLOWSRC_IFNET 2 /* flow ID generated by interface */
453 #define FLOWSRC_PF 3 /* flow ID generated by PF */
454 #define FLOWSRC_CHANNEL 4 /* flow ID generated by channel */
455
456 /*
457 * Packet flags. Unlike m_flags, all packet flags are copied along when
458 * copying m_pkthdr, i.e. no equivalent of M_COPYFLAGS here. These flags
459 * (and other classifier info) will be cleared during DLIL input.
460 *
461 * Some notes about M_LOOP and PKTF_LOOP:
462 *
463 * - M_LOOP flag is overloaded, and its use is discouraged. Historically,
464 * that flag was used by the KAME implementation for allowing certain
465 * certain exceptions to be made in the IP6_EXTHDR_CHECK() logic; this
466 * was originally meant to be set as the packet is looped back to the
467 * system, and in some circumstances temporarily set in ip6_output().
468 * Over time, this flag was used by the pre-output routines to indicate
469 * to the DLIL frameout and output routines, that the packet may be
470 * looped back to the system under the right conditions. In addition,
471 * this is an mbuf flag rather than an mbuf packet header flag.
472 *
473 * - PKTF_LOOP is an mbuf packet header flag, which is set if and only
474 * if the packet was looped back to the system. This flag should be
475 * used instead for newer code.
476 */
477 #define PKTF_FLOW_ID 0x1 /* pkt has valid flowid value */
478 #define PKTF_FLOW_ADV 0x2 /* pkt triggers local flow advisory */
479 #define PKTF_FLOW_LOCALSRC 0x4 /* pkt is locally originated */
480 #define PKTF_FLOW_RAWSOCK 0x8 /* pkt locally generated by raw sock */
481 #define PKTF_PRIO_PRIVILEGED 0x10 /* packet priority is privileged */
482 #define PKTF_PROXY_DST 0x20 /* processed but not locally destined */
483 #define PKTF_INET_RESOLVE 0x40 /* IPv4 resolver packet */
484 #define PKTF_INET6_RESOLVE 0x80 /* IPv6 resolver packet */
485 #define PKTF_RESOLVE_RTR 0x100 /* pkt is for resolving router */
486 #define PKTF_SW_LRO_PKT 0x200 /* pkt is a large coalesced pkt */
487 #define PKTF_SW_LRO_DID_CSUM 0x400 /* IP and TCP checksums done by LRO */
488 #define PKTF_MPTCP 0x800 /* TCP with MPTCP metadata */
489 #define PKTF_MPSO 0x1000 /* MPTCP socket meta data */
490 #define PKTF_LOOP 0x2000 /* loopbacked packet */
491 #define PKTF_IFAINFO 0x4000 /* pkt has valid interface addr info */
492 #define PKTF_SO_BACKGROUND 0x8000 /* data is from background source */
493 #define PKTF_FORWARDED 0x10000 /* pkt was forwarded from another i/f */
494 #define PKTF_PRIV_GUARDED 0x20000 /* pkt_mpriv area guard enabled */
495 #define PKTF_KEEPALIVE 0x40000 /* pkt is kernel-generated keepalive */
496 #define PKTF_SO_REALTIME 0x80000 /* data is realtime traffic */
497 #define PKTF_VALID_UNSENT_DATA 0x100000 /* unsent data is valid */
498 #define PKTF_TCP_REXMT 0x200000 /* packet is TCP retransmission */
499 #define PKTF_REASSEMBLED 0x400000 /* Packet was reassembled */
500 #define PKTF_TX_COMPL_TS_REQ 0x800000 /* tx completion timestamp requested */
501 #define PKTF_TS_VALID 0x1000000 /* pkt timestamp is valid */
502 #define PKTF_DRIVER_MTAG 0x2000000 /* driver mbuf tags fields inited */
503 #define PKTF_NEW_FLOW 0x4000000 /* Data from a new flow */
504 #define PKTF_START_SEQ 0x8000000 /* valid start sequence */
505 #define PKTF_LAST_PKT 0x10000000 /* last packet in the flow */
506 #define PKTF_MPTCP_REINJ 0x20000000 /* Packet has been reinjected for MPTCP */
507 #define PKTF_MPTCP_DFIN 0x40000000 /* Packet is a data-fin */
508 #define PKTF_HBH_CHKED 0x80000000 /* HBH option is checked */
509
510 /* flags related to flow control/advisory and identification */
511 #define PKTF_FLOW_MASK \
512 (PKTF_FLOW_ID | PKTF_FLOW_ADV | PKTF_FLOW_LOCALSRC | PKTF_FLOW_RAWSOCK)
513
514 /*
515 * Description of external storage mapped into mbuf, valid only if M_EXT set.
516 */
517 typedef void (*m_ext_free_func_t)(caddr_t, u_int, caddr_t);
518 struct m_ext {
519 caddr_t ext_buf; /* start of buffer */
520 m_ext_free_func_t ext_free; /* free routine if not the usual */
521 u_int ext_size; /* size of buffer, for ext_free */
522 caddr_t ext_arg; /* additional ext_free argument */
523 struct ext_ref {
524 struct mbuf *paired;
525 u_int16_t minref;
526 u_int16_t refcnt;
527 u_int16_t prefcnt;
528 u_int16_t flags;
529 u_int32_t priv;
530 uintptr_t ext_token;
531 } *ext_refflags;
532 };
533
534 /* define m_ext to a type since it gets redefined below */
535 typedef struct m_ext _m_ext_t;
536
537 /*
538 * The mbuf object
539 */
540 struct mbuf {
541 struct m_hdr m_hdr;
542 union {
543 struct {
544 struct pkthdr MH_pkthdr; /* M_PKTHDR set */
545 union {
546 struct m_ext MH_ext; /* M_EXT set */
547 char MH_databuf[_MHLEN];
548 } MH_dat;
549 } MH;
550 char M_databuf[_MLEN]; /* !M_PKTHDR, !M_EXT */
551 } M_dat;
552 };
553
554 #define m_next m_hdr.mh_next
555 #define m_len m_hdr.mh_len
556 #define m_data m_hdr.mh_data
557 #define m_type m_hdr.mh_type
558 #define m_flags m_hdr.mh_flags
559 #define m_nextpkt m_hdr.mh_nextpkt
560 #define m_act m_nextpkt
561 #define m_pkthdr M_dat.MH.MH_pkthdr
562 #define m_ext M_dat.MH.MH_dat.MH_ext
563 #define m_pktdat M_dat.MH.MH_dat.MH_databuf
564 #define m_dat M_dat.M_databuf
565 #define m_pktlen(_m) ((_m)->m_pkthdr.len)
566 #define m_pftag(_m) (&(_m)->m_pkthdr.builtin_mtag._net_mtag._pf_mtag)
567
568 /* mbuf flags (private) */
569 #define M_EXT 0x0001 /* has associated external storage */
570 #define M_PKTHDR 0x0002 /* start of record */
571 #define M_EOR 0x0004 /* end of record */
572 #define M_PROTO1 0x0008 /* protocol-specific */
573 #define M_PROTO2 0x0010 /* protocol-specific */
574 #define M_PROTO3 0x0020 /* protocol-specific */
575 #define M_LOOP 0x0040 /* packet is looped back (also see PKTF_LOOP) */
576 #define M_PROTO5 0x0080 /* protocol-specific */
577
578 /* mbuf pkthdr flags, also in m_flags (private) */
579 #define M_BCAST 0x0100 /* send/received as link-level broadcast */
580 #define M_MCAST 0x0200 /* send/received as link-level multicast */
581 #define M_FRAG 0x0400 /* packet is a fragment of a larger packet */
582 #define M_FIRSTFRAG 0x0800 /* packet is first fragment */
583 #define M_LASTFRAG 0x1000 /* packet is last fragment */
584 #define M_PROMISC 0x2000 /* packet is promiscuous (shouldn't go to stack) */
585 #define M_HASFCS 0x4000 /* packet has FCS */
586 #define M_TAGHDR 0x8000 /* m_tag hdr structure at top of mbuf data */
587
588 /*
589 * Flags to purge when crossing layers.
590 */
591 #define M_PROTOFLAGS \
592 (M_PROTO1|M_PROTO2|M_PROTO3|M_PROTO5)
593
594 /* flags copied when copying m_pkthdr */
595 #define M_COPYFLAGS \
596 (M_PKTHDR|M_EOR|M_PROTO1|M_PROTO2|M_PROTO3 | \
597 M_LOOP|M_PROTO5|M_BCAST|M_MCAST|M_FRAG | \
598 M_FIRSTFRAG|M_LASTFRAG|M_PROMISC|M_HASFCS)
599
600 /* flags indicating hw checksum support and sw checksum requirements */
601 #define CSUM_IP 0x0001 /* will csum IP */
602 #define CSUM_TCP 0x0002 /* will csum TCP */
603 #define CSUM_UDP 0x0004 /* will csum UDP */
604 #define CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */
605 #define CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */
606 #define CSUM_TCPIPV6 0x0020 /* will csum TCP for IPv6 */
607 #define CSUM_UDPIPV6 0x0040 /* will csum UDP for IPv6 */
608 #define CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation */
609
610 #define CSUM_IP_CHECKED 0x0100 /* did csum IP */
611 #define CSUM_IP_VALID 0x0200 /* ... the csum is valid */
612 #define CSUM_DATA_VALID 0x0400 /* csum_data field is valid */
613 #define CSUM_PSEUDO_HDR 0x0800 /* csum_data has pseudo hdr */
614 #define CSUM_PARTIAL 0x1000 /* simple Sum16 computation */
615 #define CSUM_ZERO_INVERT 0x2000 /* invert 0 to -0 (0xffff) */
616
617 #define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP)
618 #define CSUM_DELAY_IP (CSUM_IP) /* IPv4 only: no IPv6 IP cksum */
619 #define CSUM_DELAY_IPV6_DATA (CSUM_TCPIPV6 | CSUM_UDPIPV6)
620 #define CSUM_DATA_IPV6_VALID CSUM_DATA_VALID /* csum_data field is valid */
621
622 #define CSUM_TX_FLAGS \
623 (CSUM_DELAY_IP | CSUM_DELAY_DATA | CSUM_DELAY_IPV6_DATA | \
624 CSUM_DATA_VALID | CSUM_PARTIAL | CSUM_ZERO_INVERT)
625
626 #define CSUM_RX_FLAGS \
627 (CSUM_IP_CHECKED | CSUM_IP_VALID | CSUM_PSEUDO_HDR | \
628 CSUM_DATA_VALID | CSUM_PARTIAL)
629
630 /*
631 * Note: see also IF_HWASSIST_CSUM defined in <net/if_var.h>
632 */
633
634 /* VLAN tag present */
635 #define CSUM_VLAN_TAG_VALID 0x10000 /* vlan_tag field is valid */
636
637 /* TCP Segment Offloading requested on this mbuf */
638 #define CSUM_TSO_IPV4 0x100000 /* This mbuf needs to be segmented by the NIC */
639 #define CSUM_TSO_IPV6 0x200000 /* This mbuf needs to be segmented by the NIC */
640
641 #define TSO_IPV4_OK(_ifp, _m) \
642 (((_ifp)->if_hwassist & IFNET_TSO_IPV4) && \
643 ((_m)->m_pkthdr.csum_flags & CSUM_TSO_IPV4)) \
644
645 #define TSO_IPV4_NOTOK(_ifp, _m) \
646 (!((_ifp)->if_hwassist & IFNET_TSO_IPV4) && \
647 ((_m)->m_pkthdr.csum_flags & CSUM_TSO_IPV4)) \
648
649 #define TSO_IPV6_OK(_ifp, _m) \
650 (((_ifp)->if_hwassist & IFNET_TSO_IPV6) && \
651 ((_m)->m_pkthdr.csum_flags & CSUM_TSO_IPV6)) \
652
653 #define TSO_IPV6_NOTOK(_ifp, _m) \
654 (!((_ifp)->if_hwassist & IFNET_TSO_IPV6) && \
655 ((_m)->m_pkthdr.csum_flags & CSUM_TSO_IPV6)) \
656
657 #endif /* XNU_KERNEL_PRIVATE */
658
659 /* mbuf types */
660 #define MT_FREE 0 /* should be on free list */
661 #define MT_DATA 1 /* dynamic (data) allocation */
662 #define MT_HEADER 2 /* packet header */
663 #define MT_SOCKET 3 /* socket structure */
664 #define MT_PCB 4 /* protocol control block */
665 #define MT_RTABLE 5 /* routing tables */
666 #define MT_HTABLE 6 /* IMP host tables */
667 #define MT_ATABLE 7 /* address resolution tables */
668 #define MT_SONAME 8 /* socket name */
669 #define MT_SOOPTS 10 /* socket options */
670 #define MT_FTABLE 11 /* fragment reassembly header */
671 #define MT_RIGHTS 12 /* access rights */
672 #define MT_IFADDR 13 /* interface address */
673 #define MT_CONTROL 14 /* extra-data protocol message */
674 #define MT_OOBDATA 15 /* expedited data */
675 #define MT_TAG 16 /* volatile metadata associated to pkts */
676 #define MT_MAX 32 /* enough? */
677
678 #ifdef XNU_KERNEL_PRIVATE
679 /*
680 * mbuf allocation/deallocation macros:
681 *
682 * MGET(struct mbuf *m, int how, int type)
683 * allocates an mbuf and initializes it to contain internal data.
684 *
685 * MGETHDR(struct mbuf *m, int how, int type)
686 * allocates an mbuf and initializes it to contain a packet header
687 * and internal data.
688 */
689
690 #if 1
691 #define MCHECK(m) m_mcheck(m)
692 #else
693 #define MCHECK(m)
694 #endif
695
696 #define MGET(m, how, type) ((m) = m_get((how), (type)))
697
698 #define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type)))
699
700 /*
701 * Mbuf cluster macros.
702 * MCLALLOC(caddr_t p, int how) allocates an mbuf cluster.
703 * MCLGET adds such clusters to a normal mbuf;
704 * the flag M_EXT is set upon success.
705 * MCLFREE releases a reference to a cluster allocated by MCLALLOC,
706 * freeing the cluster if the reference count has reached 0.
707 *
708 * Normal mbuf clusters are normally treated as character arrays
709 * after allocation, but use the first word of the buffer as a free list
710 * pointer while on the free list.
711 */
712 union mcluster {
713 union mcluster *mcl_next;
714 char mcl_buf[MCLBYTES];
715 };
716
717 #define MCLALLOC(p, how) ((p) = m_mclalloc(how))
718
719 #define MCLFREE(p) m_mclfree(p)
720
721 #define MCLGET(m, how) ((m) = m_mclget(m, how))
722
723 /*
724 * Mbuf big cluster
725 */
726 union mbigcluster {
727 union mbigcluster *mbc_next;
728 char mbc_buf[MBIGCLBYTES];
729 };
730
731 /*
732 * Mbuf jumbo cluster
733 */
734 union m16kcluster {
735 union m16kcluster *m16kcl_next;
736 char m16kcl_buf[M16KCLBYTES];
737 };
738
739 #define MCLHASREFERENCE(m) m_mclhasreference(m)
740
741 /*
742 * MFREE(struct mbuf *m, struct mbuf *n)
743 * Free a single mbuf and associated external storage.
744 * Place the successor, if any, in n.
745 */
746
747 #define MFREE(m, n) ((n) = m_free(m))
748
749 /*
750 * Copy mbuf pkthdr from from to to.
751 * from must have M_PKTHDR set, and to must be empty.
752 * aux pointer will be moved to `to'.
753 */
754 #define M_COPY_PKTHDR(to, from) m_copy_pkthdr(to, from)
755
756 #define M_COPY_PFTAG(to, from) m_copy_pftag(to, from)
757
758 #define M_COPY_CLASSIFIER(to, from) m_copy_classifier(to, from)
759
760 /*
761 * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
762 * an object of the specified size at the end of the mbuf, longword aligned.
763 */
764 #define M_ALIGN(m, len) \
765 do { \
766 (m)->m_data += (MLEN - (len)) &~ (sizeof (long) - 1); \
767 } while (0)
768
769 /*
770 * As above, for mbufs allocated with m_gethdr/MGETHDR
771 * or initialized by M_COPY_PKTHDR.
772 */
773 #define MH_ALIGN(m, len) \
774 do { \
775 (m)->m_data += (MHLEN - (len)) &~ (sizeof (long) - 1); \
776 } while (0)
777
778 /*
779 * Compute the amount of space available
780 * before the current start of data in an mbuf.
781 * Subroutine - data not available if certain references.
782 */
783 #define M_LEADINGSPACE(m) m_leadingspace(m)
784
785 /*
786 * Compute the amount of space available
787 * after the end of data in an mbuf.
788 * Subroutine - data not available if certain references.
789 */
790 #define M_TRAILINGSPACE(m) m_trailingspace(m)
791
792 /*
793 * Arrange to prepend space of size plen to mbuf m.
794 * If a new mbuf must be allocated, how specifies whether to wait.
795 * If how is M_DONTWAIT and allocation fails, the original mbuf chain
796 * is freed and m is set to NULL.
797 */
798 #define M_PREPEND(m, plen, how, align) \
799 ((m) = m_prepend_2((m), (plen), (how), (align)))
800
801 /* change mbuf to new type */
802 #define MCHTYPE(m, t) m_mchtype(m, t)
803
804 /* compatiblity with 4.3 */
805 #define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
806
807 #define MBSHIFT 20 /* 1MB */
808 #define MBSIZE (1 << MBSHIFT)
809 #define GBSHIFT 30 /* 1GB */
810 #define GBSIZE (1 << GBSHIFT)
811
812 /*
813 * M_STRUCT_GET ensures that intermediate protocol header (from "off" to
814 * "off+len") is located in single mbuf, on contiguous memory region.
815 * The pointer to the region will be returned to pointer variable "val",
816 * with type "typ".
817 *
818 * M_STRUCT_GET0 does the same, except that it aligns the structure at
819 * very top of mbuf. GET0 is likely to make memory copy than GET.
820 */
821 #define M_STRUCT_GET(val, typ, m, off, len) \
822 do { \
823 struct mbuf *t; \
824 int tmp; \
825 \
826 if ((m)->m_len >= (off) + (len)) { \
827 (val) = (typ)(mtod((m), caddr_t) + (off)); \
828 } else { \
829 t = m_pulldown((m), (off), (len), &tmp); \
830 if (t != NULL) { \
831 if (t->m_len < tmp + (len)) \
832 panic("m_pulldown malfunction"); \
833 (val) = (typ)(mtod(t, caddr_t) + tmp); \
834 } else { \
835 (val) = (typ)NULL; \
836 (m) = NULL; \
837 } \
838 } \
839 } while (0)
840
841 #define M_STRUCT_GET0(val, typ, m, off, len) \
842 do { \
843 struct mbuf *t; \
844 \
845 if ((off) == 0 && ((m)->m_len >= (len))) { \
846 (val) = (typ)(void *)mtod(m, caddr_t); \
847 } else { \
848 t = m_pulldown((m), (off), (len), NULL); \
849 if (t != NULL) { \
850 if (t->m_len < (len)) \
851 panic("m_pulldown malfunction"); \
852 (val) = (typ)(void *)mtod(t, caddr_t); \
853 } else { \
854 (val) = (typ)NULL; \
855 (m) = NULL; \
856 } \
857 } \
858 } while (0)
859
860 #define MBUF_INPUT_CHECK(m, rcvif) \
861 do { \
862 if (!(m->m_flags & MBUF_PKTHDR) || \
863 m->m_len < 0 || \
864 m->m_len > ((njcl > 0) ? njclbytes : MBIGCLBYTES) || \
865 m->m_type == MT_FREE || \
866 ((m->m_flags & M_EXT) != 0 && m->m_ext.ext_buf == NULL)) { \
867 panic_plain("Failed mbuf validity check: mbuf %p len %d " \
868 "type %d flags 0x%x data %p rcvif %s ifflags 0x%x", \
869 m, m->m_len, m->m_type, m->m_flags, \
870 ((m->m_flags & M_EXT) ? m->m_ext.ext_buf : m->m_data), \
871 if_name(rcvif), \
872 (rcvif->if_flags & 0xffff)); \
873 } \
874 } while (0)
875
876 /*
877 * Simple mbuf queueing system
878 *
879 * This is basically a SIMPLEQ adapted to mbuf use (i.e. using
880 * m_nextpkt instead of field.sqe_next).
881 *
882 * m_next is ignored, so queueing chains of mbufs is possible
883 */
884 #define MBUFQ_HEAD(name) \
885 struct name { \
886 struct mbuf *mq_first; /* first packet */ \
887 struct mbuf **mq_last; /* addr of last next packet */ \
888 }
889
890 #define MBUFQ_INIT(q) do { \
891 MBUFQ_FIRST(q) = NULL; \
892 (q)->mq_last = &MBUFQ_FIRST(q); \
893 } while (0)
894
895 #define MBUFQ_PREPEND(q, m) do { \
896 if ((MBUFQ_NEXT(m) = MBUFQ_FIRST(q)) == NULL) \
897 (q)->mq_last = &MBUFQ_NEXT(m); \
898 MBUFQ_FIRST(q) = (m); \
899 } while (0)
900
901 #define MBUFQ_ENQUEUE(q, m) do { \
902 MBUFQ_NEXT(m) = NULL; \
903 *(q)->mq_last = (m); \
904 (q)->mq_last = &MBUFQ_NEXT(m); \
905 } while (0)
906
907 #define MBUFQ_ENQUEUE_MULTI(q, m, n) do { \
908 MBUFQ_NEXT(n) = NULL; \
909 *(q)->mq_last = (m); \
910 (q)->mq_last = &MBUFQ_NEXT(n); \
911 } while (0)
912
913 #define MBUFQ_DEQUEUE(q, m) do { \
914 if (((m) = MBUFQ_FIRST(q)) != NULL) { \
915 if ((MBUFQ_FIRST(q) = MBUFQ_NEXT(m)) == NULL) \
916 (q)->mq_last = &MBUFQ_FIRST(q); \
917 else \
918 MBUFQ_NEXT(m) = NULL; \
919 } \
920 } while (0)
921
922 #define MBUFQ_REMOVE(q, m) do { \
923 if (MBUFQ_FIRST(q) == (m)) { \
924 MBUFQ_DEQUEUE(q, m); \
925 } else { \
926 struct mbuf *_m = MBUFQ_FIRST(q); \
927 while (MBUFQ_NEXT(_m) != (m)) \
928 _m = MBUFQ_NEXT(_m); \
929 if ((MBUFQ_NEXT(_m) = \
930 MBUFQ_NEXT(MBUFQ_NEXT(_m))) == NULL) \
931 (q)->mq_last = &MBUFQ_NEXT(_m); \
932 } \
933 } while (0)
934
935 #define MBUFQ_DRAIN(q) do { \
936 struct mbuf *__m0; \
937 while ((__m0 = MBUFQ_FIRST(q)) != NULL) { \
938 MBUFQ_FIRST(q) = MBUFQ_NEXT(__m0); \
939 MBUFQ_NEXT(__m0) = NULL; \
940 m_freem(__m0); \
941 } \
942 (q)->mq_last = &MBUFQ_FIRST(q); \
943 } while (0)
944
945 #define MBUFQ_FOREACH(m, q) \
946 for ((m) = MBUFQ_FIRST(q); \
947 (m); \
948 (m) = MBUFQ_NEXT(m))
949
950 #define MBUFQ_FOREACH_SAFE(m, q, tvar) \
951 for ((m) = MBUFQ_FIRST(q); \
952 (m) && ((tvar) = MBUFQ_NEXT(m), 1); \
953 (m) = (tvar))
954
955 #define MBUFQ_EMPTY(q) ((q)->mq_first == NULL)
956 #define MBUFQ_FIRST(q) ((q)->mq_first)
957 #define MBUFQ_NEXT(m) ((m)->m_nextpkt)
958 /*
959 * mq_last is initialized to point to mq_first, so check if they're
960 * equal and return NULL when the list is empty. Otherwise, we need
961 * to subtract the offset of MBUQ_NEXT (i.e. m_nextpkt field) to get
962 * to the base mbuf address to return to caller.
963 */
964 #define MBUFQ_LAST(head) \
965 (((head)->mq_last == &MBUFQ_FIRST(head)) ? NULL : \
966 ((struct mbuf *)(void *)((char *)(head)->mq_last - \
967 (size_t)(&MBUFQ_NEXT((struct mbuf *)0)))))
968
969 #define max_linkhdr P2ROUNDUP(_max_linkhdr, sizeof (u_int32_t))
970 #define max_protohdr P2ROUNDUP(_max_protohdr, sizeof (u_int32_t))
971 #endif /* XNU_KERNEL_PRIVATE */
972
973 /*
974 * Mbuf statistics (legacy).
975 */
976 struct mbstat {
977 u_int32_t m_mbufs; /* mbufs obtained from page pool */
978 u_int32_t m_clusters; /* clusters obtained from page pool */
979 u_int32_t m_spare; /* spare field */
980 u_int32_t m_clfree; /* free clusters */
981 u_int32_t m_drops; /* times failed to find space */
982 u_int32_t m_wait; /* times waited for space */
983 u_int32_t m_drain; /* times drained protocols for space */
984 u_short m_mtypes[256]; /* type specific mbuf allocations */
985 u_int32_t m_mcfail; /* times m_copym failed */
986 u_int32_t m_mpfail; /* times m_pullup failed */
987 u_int32_t m_msize; /* length of an mbuf */
988 u_int32_t m_mclbytes; /* length of an mbuf cluster */
989 u_int32_t m_minclsize; /* min length of data to allocate a cluster */
990 u_int32_t m_mlen; /* length of data in an mbuf */
991 u_int32_t m_mhlen; /* length of data in a header mbuf */
992 u_int32_t m_bigclusters; /* clusters obtained from page pool */
993 u_int32_t m_bigclfree; /* free clusters */
994 u_int32_t m_bigmclbytes; /* length of an mbuf cluster */
995 };
996
997 /* Compatibillity with 10.3 */
998 struct ombstat {
999 u_int32_t m_mbufs; /* mbufs obtained from page pool */
1000 u_int32_t m_clusters; /* clusters obtained from page pool */
1001 u_int32_t m_spare; /* spare field */
1002 u_int32_t m_clfree; /* free clusters */
1003 u_int32_t m_drops; /* times failed to find space */
1004 u_int32_t m_wait; /* times waited for space */
1005 u_int32_t m_drain; /* times drained protocols for space */
1006 u_short m_mtypes[256]; /* type specific mbuf allocations */
1007 u_int32_t m_mcfail; /* times m_copym failed */
1008 u_int32_t m_mpfail; /* times m_pullup failed */
1009 u_int32_t m_msize; /* length of an mbuf */
1010 u_int32_t m_mclbytes; /* length of an mbuf cluster */
1011 u_int32_t m_minclsize; /* min length of data to allocate a cluster */
1012 u_int32_t m_mlen; /* length of data in an mbuf */
1013 u_int32_t m_mhlen; /* length of data in a header mbuf */
1014 };
1015
1016 /*
1017 * mbuf class statistics.
1018 */
1019 #define MAX_MBUF_CNAME 15
1020
1021 #if defined(XNU_KERNEL_PRIVATE)
1022 /* For backwards compatibility with 32-bit userland process */
1023 struct omb_class_stat {
1024 char mbcl_cname[MAX_MBUF_CNAME + 1]; /* class name */
1025 u_int32_t mbcl_size; /* buffer size */
1026 u_int32_t mbcl_total; /* # of buffers created */
1027 u_int32_t mbcl_active; /* # of active buffers */
1028 u_int32_t mbcl_infree; /* # of available buffers */
1029 u_int32_t mbcl_slab_cnt; /* # of available slabs */
1030 u_int64_t mbcl_alloc_cnt; /* # of times alloc is called */
1031 u_int64_t mbcl_free_cnt; /* # of times free is called */
1032 u_int64_t mbcl_notified; /* # of notified wakeups */
1033 u_int64_t mbcl_purge_cnt; /* # of purges so far */
1034 u_int64_t mbcl_fail_cnt; /* # of allocation failures */
1035 u_int32_t mbcl_ctotal; /* total only for this class */
1036 u_int32_t mbcl_release_cnt; /* amount of memory returned */
1037 /*
1038 * Cache layer statistics
1039 */
1040 u_int32_t mbcl_mc_state; /* cache state (see below) */
1041 u_int32_t mbcl_mc_cached; /* # of cached buffers */
1042 u_int32_t mbcl_mc_waiter_cnt; /* # waiters on the cache */
1043 u_int32_t mbcl_mc_wretry_cnt; /* # of wait retries */
1044 u_int32_t mbcl_mc_nwretry_cnt; /* # of no-wait retry attempts */
1045 u_int64_t mbcl_reserved[4]; /* for future use */
1046 } __attribute__((__packed__));
1047 #endif /* XNU_KERNEL_PRIVATE */
1048
1049 typedef struct mb_class_stat {
1050 char mbcl_cname[MAX_MBUF_CNAME + 1]; /* class name */
1051 u_int32_t mbcl_size; /* buffer size */
1052 u_int32_t mbcl_total; /* # of buffers created */
1053 u_int32_t mbcl_active; /* # of active buffers */
1054 u_int32_t mbcl_infree; /* # of available buffers */
1055 u_int32_t mbcl_slab_cnt; /* # of available slabs */
1056 #if defined(KERNEL) || defined(__LP64__)
1057 u_int32_t mbcl_pad; /* padding */
1058 #endif /* KERNEL || __LP64__ */
1059 u_int64_t mbcl_alloc_cnt; /* # of times alloc is called */
1060 u_int64_t mbcl_free_cnt; /* # of times free is called */
1061 u_int64_t mbcl_notified; /* # of notified wakeups */
1062 u_int64_t mbcl_purge_cnt; /* # of purges so far */
1063 u_int64_t mbcl_fail_cnt; /* # of allocation failures */
1064 u_int32_t mbcl_ctotal; /* total only for this class */
1065 u_int32_t mbcl_release_cnt; /* amount of memory returned */
1066 /*
1067 * Cache layer statistics
1068 */
1069 u_int32_t mbcl_mc_state; /* cache state (see below) */
1070 u_int32_t mbcl_mc_cached; /* # of cached buffers */
1071 u_int32_t mbcl_mc_waiter_cnt; /* # waiters on the cache */
1072 u_int32_t mbcl_mc_wretry_cnt; /* # of wait retries */
1073 u_int32_t mbcl_mc_nwretry_cnt; /* # of no-wait retry attempts */
1074 u_int32_t mbcl_peak_reported; /* last usage peak reported */
1075 u_int32_t mbcl_reserved[7]; /* for future use */
1076 } mb_class_stat_t;
1077
1078 #define MCS_DISABLED 0 /* cache is permanently disabled */
1079 #define MCS_ONLINE 1 /* cache is online */
1080 #define MCS_PURGING 2 /* cache is being purged */
1081 #define MCS_OFFLINE 3 /* cache is offline (resizing) */
1082
1083 #if defined(XNU_KERNEL_PRIVATE)
1084 /* For backwards compatibility with 32-bit userland process */
1085 struct omb_stat {
1086 u_int32_t mbs_cnt; /* number of classes */
1087 struct omb_class_stat mbs_class[1]; /* class array */
1088 } __attribute__((__packed__));
1089 #endif /* XNU_KERNEL_PRIVATE */
1090
1091 typedef struct mb_stat {
1092 u_int32_t mbs_cnt; /* number of classes */
1093 #if defined(KERNEL) || defined(__LP64__)
1094 u_int32_t mbs_pad; /* padding */
1095 #endif /* KERNEL || __LP64__ */
1096 mb_class_stat_t mbs_class[1]; /* class array */
1097 } mb_stat_t;
1098
1099 #ifdef PRIVATE
1100 #define MLEAK_STACK_DEPTH 16 /* Max PC stack depth */
1101
1102 typedef struct mleak_trace_stat {
1103 u_int64_t mltr_collisions;
1104 u_int64_t mltr_hitcount;
1105 u_int64_t mltr_allocs;
1106 u_int64_t mltr_depth;
1107 u_int64_t mltr_addr[MLEAK_STACK_DEPTH];
1108 } mleak_trace_stat_t;
1109
1110 typedef struct mleak_stat {
1111 u_int32_t ml_isaddr64; /* 64-bit KVA? */
1112 u_int32_t ml_cnt; /* number of traces */
1113 mleak_trace_stat_t ml_trace[1]; /* trace array */
1114 } mleak_stat_t;
1115
1116 struct mleak_table {
1117 u_int32_t mleak_capture; /* sampling capture counter */
1118 u_int32_t mleak_sample_factor; /* sample factor */
1119
1120 /* Times two active records want to occupy the same spot */
1121 u_int64_t alloc_collisions;
1122 u_int64_t trace_collisions;
1123
1124 /* Times new record lands on spot previously occupied by freed alloc */
1125 u_int64_t alloc_overwrites;
1126 u_int64_t trace_overwrites;
1127
1128 /* Times a new alloc or trace is put into the hash table */
1129 u_int64_t alloc_recorded;
1130 u_int64_t trace_recorded;
1131
1132 /* Total number of outstanding allocs */
1133 u_int64_t outstanding_allocs;
1134
1135 /* Times mleak_log returned false because couldn't acquire the lock */
1136 u_int64_t total_conflicts;
1137 };
1138 #endif /* PRIVATE */
1139
1140 #ifdef KERNEL_PRIVATE
1141 __BEGIN_DECLS
1142
1143 /*
1144 * Exported (private)
1145 */
1146
1147 extern struct mbstat mbstat; /* statistics */
1148
1149 __END_DECLS
1150 #endif /* KERNEL_PRIVATE */
1151
1152 #ifdef XNU_KERNEL_PRIVATE
1153 __BEGIN_DECLS
1154
1155 /*
1156 * Not exported (xnu private)
1157 */
1158
1159 /* flags to m_get/MGET */
1160 /* Need to include malloc.h to get right options for malloc */
1161 #include <sys/malloc.h>
1162
1163 struct mbuf;
1164
1165 /* length to m_copy to copy all */
1166 #define M_COPYALL 1000000000
1167
1168 #define M_DONTWAIT M_NOWAIT
1169 #define M_WAIT M_WAITOK
1170
1171 /* modes for m_copym and variants */
1172 #define M_COPYM_NOOP_HDR 0 /* don't copy/move pkthdr contents */
1173 #define M_COPYM_COPY_HDR 1 /* copy pkthdr from old to new */
1174 #define M_COPYM_MOVE_HDR 2 /* move pkthdr from old to new */
1175 #define M_COPYM_MUST_COPY_HDR 3 /* MUST copy pkthdr from old to new */
1176 #define M_COPYM_MUST_MOVE_HDR 4 /* MUST move pkthdr from old to new */
1177
1178 /*
1179 * These macros are mapped to the appropriate KPIs, so that private code
1180 * can be simply recompiled in order to be forward-compatible with future
1181 * changes toward the struture sizes.
1182 */
1183 #define MLEN mbuf_get_mlen() /* normal data len */
1184 #define MHLEN mbuf_get_mhlen() /* data len w/pkthdr */
1185
1186 #define MINCLSIZE mbuf_get_minclsize() /* cluster usage threshold */
1187
1188 extern void m_freem(struct mbuf *);
1189 extern u_int64_t mcl_to_paddr(char *);
1190 extern void m_adj(struct mbuf *, int);
1191 extern void m_cat(struct mbuf *, struct mbuf *);
1192 extern void m_copydata(struct mbuf *, int, int, void *);
1193 extern struct mbuf *m_copym(struct mbuf *, int, int, int);
1194 extern struct mbuf *m_copym_mode(struct mbuf *, int, int, int, uint32_t);
1195 extern struct mbuf *m_get(int, int);
1196 extern struct mbuf *m_gethdr(int, int);
1197 extern struct mbuf *m_getpacket(void);
1198 extern struct mbuf *m_getpackets(int, int, int);
1199 extern struct mbuf *m_mclget(struct mbuf *, int);
1200 extern void *m_mtod(struct mbuf *);
1201 extern struct mbuf *m_prepend_2(struct mbuf *, int, int, int);
1202 extern struct mbuf *m_pullup(struct mbuf *, int);
1203 extern struct mbuf *m_split(struct mbuf *, int, int);
1204 extern void m_mclfree(caddr_t p);
1205
1206 /*
1207 * On platforms which require strict alignment (currently for anything but
1208 * i386 or x86_64), this macro checks whether the data pointer of an mbuf
1209 * is 32-bit aligned (this is the expected minimum alignment for protocol
1210 * headers), and assert otherwise.
1211 */
1212 #if defined(__i386__) || defined(__x86_64__)
1213 #define MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(_m)
1214 #else /* !__i386__ && !__x86_64__ */
1215 #define MBUF_STRICT_DATA_ALIGNMENT_CHECK_32(_m) do { \
1216 if (!IS_P2ALIGNED((_m)->m_data, sizeof (u_int32_t))) { \
1217 if (((_m)->m_flags & M_PKTHDR) && \
1218 (_m)->m_pkthdr.rcvif != NULL) { \
1219 panic_plain("\n%s: mbuf %p data ptr %p is not " \
1220 "32-bit aligned [%s: alignerrs=%lld]\n", \
1221 __func__, (_m), (_m)->m_data, \
1222 if_name((_m)->m_pkthdr.rcvif), \
1223 (_m)->m_pkthdr.rcvif->if_alignerrs); \
1224 } else { \
1225 panic_plain("\n%s: mbuf %p data ptr %p is not " \
1226 "32-bit aligned\n", \
1227 __func__, (_m), (_m)->m_data); \
1228 } \
1229 } \
1230 } while (0)
1231 #endif /* !__i386__ && !__x86_64__ */
1232
1233 /* Maximum number of MBUF_SC values (excluding MBUF_SC_UNSPEC) */
1234 #define MBUF_SC_MAX_CLASSES 10
1235
1236 /*
1237 * These conversion macros rely on the corresponding MBUF_SC and
1238 * MBUF_TC values in order to establish the following mapping:
1239 *
1240 * MBUF_SC_BK_SYS ] ==> MBUF_TC_BK
1241 * MBUF_SC_BK ]
1242 *
1243 * MBUF_SC_BE ] ==> MBUF_TC_BE
1244 * MBUF_SC_RD ]
1245 * MBUF_SC_OAM ]
1246 *
1247 * MBUF_SC_AV ] ==> MBUF_TC_VI
1248 * MBUF_SC_RV ]
1249 * MBUF_SC_VI ]
1250 *
1251 * MBUF_SC_VO ] ==> MBUF_TC_VO
1252 * MBUF_SC_CTL ]
1253 *
1254 * The values assigned to each service class allows for a fast mapping to
1255 * the corresponding MBUF_TC traffic class values, as well as to retrieve the
1256 * assigned index; therefore care must be taken when comparing against these
1257 * values. Use the corresponding class and index macros to retrieve the
1258 * corresponding portion, and never assume that a higher class corresponds
1259 * to a higher index.
1260 */
1261 #define MBUF_SCVAL(x) ((x) & 0xffff)
1262 #define MBUF_SCIDX(x) ((((x) >> 16) & 0xff) >> 3)
1263 #define MBUF_SC2TC(_sc) (MBUF_SCVAL(_sc) >> 7)
1264 #define MBUF_TC2SCVAL(_tc) ((_tc) << 7)
1265 #define IS_MBUF_SC_BACKGROUND(_sc) (((_sc) == MBUF_SC_BK_SYS) || \
1266 ((_sc) == MBUF_SC_BK))
1267 #define IS_MBUF_SC_REALTIME(_sc) ((_sc) >= MBUF_SC_AV && (_sc) <= MBUF_SC_VO)
1268 #define IS_MBUF_SC_BESTEFFORT(_sc) ((_sc) == MBUF_SC_BE || \
1269 (_sc) == MBUF_SC_RD || (_sc) == MBUF_SC_OAM)
1270
1271 #define SCIDX_BK_SYS MBUF_SCIDX(MBUF_SC_BK_SYS)
1272 #define SCIDX_BK MBUF_SCIDX(MBUF_SC_BK)
1273 #define SCIDX_BE MBUF_SCIDX(MBUF_SC_BE)
1274 #define SCIDX_RD MBUF_SCIDX(MBUF_SC_RD)
1275 #define SCIDX_OAM MBUF_SCIDX(MBUF_SC_OAM)
1276 #define SCIDX_AV MBUF_SCIDX(MBUF_SC_AV)
1277 #define SCIDX_RV MBUF_SCIDX(MBUF_SC_RV)
1278 #define SCIDX_VI MBUF_SCIDX(MBUF_SC_VI)
1279 #define SCIDX_VO MBUF_SCIDX(MBUF_SC_VO)
1280 #define SCIDX_CTL MBUF_SCIDX(MBUF_SC_CTL)
1281
1282 #define SCVAL_BK_SYS MBUF_SCVAL(MBUF_SC_BK_SYS)
1283 #define SCVAL_BK MBUF_SCVAL(MBUF_SC_BK)
1284 #define SCVAL_BE MBUF_SCVAL(MBUF_SC_BE)
1285 #define SCVAL_RD MBUF_SCVAL(MBUF_SC_RD)
1286 #define SCVAL_OAM MBUF_SCVAL(MBUF_SC_OAM)
1287 #define SCVAL_AV MBUF_SCVAL(MBUF_SC_AV)
1288 #define SCVAL_RV MBUF_SCVAL(MBUF_SC_RV)
1289 #define SCVAL_VI MBUF_SCVAL(MBUF_SC_VI)
1290 #define SCVAL_VO MBUF_SCVAL(MBUF_SC_VO)
1291 #define SCVAL_CTL MBUF_SCVAL(MBUF_SC_CTL)
1292
1293 #define MBUF_VALID_SC(c) \
1294 (c == MBUF_SC_BK_SYS || c == MBUF_SC_BK || c == MBUF_SC_BE || \
1295 c == MBUF_SC_RD || c == MBUF_SC_OAM || c == MBUF_SC_AV || \
1296 c == MBUF_SC_RV || c == MBUF_SC_VI || c == MBUF_SC_VO || \
1297 c == MBUF_SC_CTL)
1298
1299 #define MBUF_VALID_SCIDX(c) \
1300 (c == SCIDX_BK_SYS || c == SCIDX_BK || c == SCIDX_BE || \
1301 c == SCIDX_RD || c == SCIDX_OAM || c == SCIDX_AV || \
1302 c == SCIDX_RV || c == SCIDX_VI || c == SCIDX_VO || \
1303 c == SCIDX_CTL)
1304
1305 #define MBUF_VALID_SCVAL(c) \
1306 (c == SCVAL_BK_SYS || c == SCVAL_BK || c == SCVAL_BE || \
1307 c == SCVAL_RD || c == SCVAL_OAM || c == SCVAL_AV || \
1308 c == SCVAL_RV || c == SCVAL_VI || c == SCVAL_VO || \
1309 c == SCVAL_CTL)
1310
1311 extern unsigned char *mbutl; /* start VA of mbuf pool */
1312 extern unsigned char *embutl; /* end VA of mbuf pool */
1313 extern unsigned int nmbclusters; /* number of mapped clusters */
1314 extern int njcl; /* # of jumbo clusters */
1315 extern int njclbytes; /* size of a jumbo cluster */
1316 extern int max_hdr; /* largest link+protocol header */
1317 extern int max_datalen; /* MHLEN - max_hdr */
1318
1319 /* Use max_linkhdr instead of _max_linkhdr */
1320 extern int _max_linkhdr; /* largest link-level header */
1321
1322 /* Use max_protohdr instead of _max_protohdr */
1323 extern int _max_protohdr; /* largest protocol header */
1324
1325 __private_extern__ unsigned int mbuf_default_ncl(int, u_int64_t);
1326 __private_extern__ void mbinit(void);
1327 __private_extern__ struct mbuf *m_clattach(struct mbuf *, int, caddr_t,
1328 void (*)(caddr_t, u_int, caddr_t), u_int, caddr_t, int, int);
1329 __private_extern__ caddr_t m_bigalloc(int);
1330 __private_extern__ void m_bigfree(caddr_t, u_int, caddr_t);
1331 __private_extern__ struct mbuf *m_mbigget(struct mbuf *, int);
1332 __private_extern__ caddr_t m_16kalloc(int);
1333 __private_extern__ void m_16kfree(caddr_t, u_int, caddr_t);
1334 __private_extern__ struct mbuf *m_m16kget(struct mbuf *, int);
1335 __private_extern__ int m_reinit(struct mbuf *, int);
1336 __private_extern__ struct mbuf *m_free(struct mbuf *);
1337 __private_extern__ struct mbuf *m_getclr(int, int);
1338 __private_extern__ struct mbuf *m_getptr(struct mbuf *, int, int *);
1339 __private_extern__ unsigned int m_length(struct mbuf *);
1340 __private_extern__ unsigned int m_length2(struct mbuf *, struct mbuf **);
1341 __private_extern__ unsigned int m_fixhdr(struct mbuf *);
1342 __private_extern__ struct mbuf *m_defrag(struct mbuf *, int);
1343 __private_extern__ struct mbuf *m_defrag_offset(struct mbuf *, u_int32_t, int);
1344 __private_extern__ struct mbuf *m_prepend(struct mbuf *, int, int);
1345 __private_extern__ struct mbuf *m_copyup(struct mbuf *, int, int);
1346 __private_extern__ struct mbuf *m_retry(int, int);
1347 __private_extern__ struct mbuf *m_retryhdr(int, int);
1348 __private_extern__ int m_freem_list(struct mbuf *);
1349 __private_extern__ int m_append(struct mbuf *, int, caddr_t);
1350 __private_extern__ struct mbuf *m_last(struct mbuf *);
1351 __private_extern__ struct mbuf *m_devget(char *, int, int, struct ifnet *,
1352 void (*)(const void *, void *, size_t));
1353 __private_extern__ struct mbuf *m_pulldown(struct mbuf *, int, int, int *);
1354
1355 __private_extern__ struct mbuf *m_getcl(int, int, int);
1356 __private_extern__ caddr_t m_mclalloc(int);
1357 __private_extern__ int m_mclhasreference(struct mbuf *);
1358 __private_extern__ void m_copy_pkthdr(struct mbuf *, struct mbuf *);
1359 __private_extern__ void m_copy_pftag(struct mbuf *, struct mbuf *);
1360 __private_extern__ void m_copy_classifier(struct mbuf *, struct mbuf *);
1361
1362 __private_extern__ struct mbuf *m_dtom(void *);
1363 __private_extern__ int m_mtocl(void *);
1364 __private_extern__ union mcluster *m_cltom(int);
1365
1366 __private_extern__ int m_trailingspace(struct mbuf *);
1367 __private_extern__ int m_leadingspace(struct mbuf *);
1368
1369 __private_extern__ struct mbuf *m_normalize(struct mbuf *m);
1370 __private_extern__ void m_mchtype(struct mbuf *m, int t);
1371 __private_extern__ void m_mcheck(struct mbuf *);
1372
1373 __private_extern__ void m_copyback(struct mbuf *, int, int, const void *);
1374 __private_extern__ struct mbuf *m_copyback_cow(struct mbuf *, int, int,
1375 const void *, int);
1376 __private_extern__ int m_makewritable(struct mbuf **, int, int, int);
1377 __private_extern__ struct mbuf *m_dup(struct mbuf *m, int how);
1378 __private_extern__ struct mbuf *m_copym_with_hdrs(struct mbuf *, int, int, int,
1379 struct mbuf **, int *, uint32_t);
1380 __private_extern__ struct mbuf *m_getpackethdrs(int, int);
1381 __private_extern__ struct mbuf *m_getpacket_how(int);
1382 __private_extern__ struct mbuf *m_getpackets_internal(unsigned int *, int,
1383 int, int, size_t);
1384 __private_extern__ struct mbuf *m_allocpacket_internal(unsigned int *, size_t,
1385 unsigned int *, int, int, size_t);
1386
1387 __private_extern__ int m_ext_set_prop(struct mbuf *, uint32_t, uint32_t);
1388 __private_extern__ uint32_t m_ext_get_prop(struct mbuf *);
1389 __private_extern__ int m_ext_paired_is_active(struct mbuf *);
1390 __private_extern__ void m_ext_paired_activate(struct mbuf *);
1391
1392 __private_extern__ void m_drain(void);
1393
1394 /*
1395 * Packets may have annotations attached by affixing a list of "packet
1396 * tags" to the pkthdr structure. Packet tags are dynamically allocated
1397 * semi-opaque data structures that have a fixed header (struct m_tag)
1398 * that specifies the size of the memory block and an <id,type> pair that
1399 * identifies it. The id identifies the module and the type identifies the
1400 * type of data for that module. The id of zero is reserved for the kernel.
1401 *
1402 * Note that the packet tag returned by m_tag_allocate has the default
1403 * memory alignment implemented by malloc. To reference private data one
1404 * can use a construct like:
1405 *
1406 * struct m_tag *mtag = m_tag_allocate(...);
1407 * struct foo *p = (struct foo *)(mtag+1);
1408 *
1409 * if the alignment of struct m_tag is sufficient for referencing members
1410 * of struct foo. Otherwise it is necessary to embed struct m_tag within
1411 * the private data structure to insure proper alignment; e.g.
1412 *
1413 * struct foo {
1414 * struct m_tag tag;
1415 * ...
1416 * };
1417 * struct foo *p = (struct foo *) m_tag_allocate(...);
1418 * struct m_tag *mtag = &p->tag;
1419 */
1420
1421 #define KERNEL_MODULE_TAG_ID 0
1422
1423 enum {
1424 KERNEL_TAG_TYPE_NONE = 0,
1425 KERNEL_TAG_TYPE_DUMMYNET = 1,
1426 KERNEL_TAG_TYPE_DIVERT = 2,
1427 KERNEL_TAG_TYPE_IPFORWARD = 3,
1428 KERNEL_TAG_TYPE_IPFILT = 4,
1429 KERNEL_TAG_TYPE_MACLABEL = 5,
1430 KERNEL_TAG_TYPE_MAC_POLICY_LABEL = 6,
1431 KERNEL_TAG_TYPE_ENCAP = 8,
1432 KERNEL_TAG_TYPE_INET6 = 9,
1433 KERNEL_TAG_TYPE_IPSEC = 10,
1434 KERNEL_TAG_TYPE_DRVAUX = 11,
1435 };
1436
1437 /* Packet tag routines */
1438 __private_extern__ struct m_tag *m_tag_alloc(u_int32_t, u_int16_t, int, int);
1439 __private_extern__ struct m_tag *m_tag_create(u_int32_t, u_int16_t, int, int,
1440 struct mbuf *);
1441 __private_extern__ void m_tag_free(struct m_tag *);
1442 __private_extern__ void m_tag_prepend(struct mbuf *, struct m_tag *);
1443 __private_extern__ void m_tag_unlink(struct mbuf *, struct m_tag *);
1444 __private_extern__ void m_tag_delete(struct mbuf *, struct m_tag *);
1445 __private_extern__ void m_tag_delete_chain(struct mbuf *, struct m_tag *);
1446 __private_extern__ struct m_tag *m_tag_locate(struct mbuf *, u_int32_t,
1447 u_int16_t, struct m_tag *);
1448 __private_extern__ struct m_tag *m_tag_copy(struct m_tag *, int);
1449 __private_extern__ int m_tag_copy_chain(struct mbuf *, struct mbuf *, int);
1450 __private_extern__ void m_tag_init(struct mbuf *, int);
1451 __private_extern__ struct m_tag *m_tag_first(struct mbuf *);
1452 __private_extern__ struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
1453
1454 __END_DECLS
1455 #endif /* XNU_KERNEL_PRIVATE */
1456 #ifdef KERNEL
1457 #include <sys/kpi_mbuf.h>
1458 #ifdef XNU_KERNEL_PRIVATE
1459 __BEGIN_DECLS
1460
1461 __private_extern__ void m_scratch_init(struct mbuf *);
1462 __private_extern__ u_int32_t m_scratch_get(struct mbuf *, u_int8_t **);
1463
1464 __private_extern__ void m_classifier_init(struct mbuf *, uint32_t);
1465
1466 __private_extern__ int m_set_service_class(struct mbuf *, mbuf_svc_class_t);
1467 __private_extern__ mbuf_svc_class_t m_get_service_class(struct mbuf *);
1468 __private_extern__ mbuf_svc_class_t m_service_class_from_idx(u_int32_t);
1469 __private_extern__ mbuf_svc_class_t m_service_class_from_val(u_int32_t);
1470 __private_extern__ int m_set_traffic_class(struct mbuf *, mbuf_traffic_class_t);
1471 __private_extern__ mbuf_traffic_class_t m_get_traffic_class(struct mbuf *);
1472
1473 #define ADDCARRY(_x) do { \
1474 while (((_x) >> 16) != 0) \
1475 (_x) = ((_x) >> 16) + ((_x) & 0xffff); \
1476 } while (0)
1477
1478 __private_extern__ u_int16_t m_adj_sum16(struct mbuf *, u_int32_t,
1479 u_int32_t, u_int32_t, u_int32_t);
1480 __private_extern__ u_int16_t m_sum16(struct mbuf *, u_int32_t, u_int32_t);
1481
1482 __private_extern__ void m_set_ext(struct mbuf *, struct ext_ref *,
1483 m_ext_free_func_t, caddr_t);
1484 __private_extern__ struct ext_ref *m_get_rfa(struct mbuf *);
1485 __private_extern__ m_ext_free_func_t m_get_ext_free(struct mbuf *);
1486 __private_extern__ caddr_t m_get_ext_arg(struct mbuf *);
1487
1488 extern void m_do_tx_compl_callback(struct mbuf *, struct ifnet *);
1489
1490 __END_DECLS
1491 #endif /* XNU_KERNEL_PRIVATE */
1492 #endif /* KERNEL */
1493 #endif /* !_SYS_MBUF_H_ */