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