]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/mbuf.h
xnu-1504.3.12.tar.gz
[apple/xnu.git] / bsd / sys / mbuf.h
1 /*
2 * Copyright (c) 2008 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 * HISTORY
73 * 20-May-95 Mac Gillon (mgillon) at NeXT
74 * New version based on 4.4
75 * Purged old history
76 */
77 /*
78 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
79 * support for mandatory and extensible security protections. This notice
80 * is included in support of clause 2.2 (b) of the Apple Public License,
81 * Version 2.0.
82 */
83
84 #ifndef _SYS_MBUF_H_
85 #define _SYS_MBUF_H_
86
87 #include <sys/cdefs.h>
88 #include <sys/appleapiopts.h>
89
90 #ifdef KERNEL_PRIVATE
91
92 #include <sys/lock.h>
93 #include <sys/queue.h>
94
95 #if PF_PKTHDR
96 #include <net/pf_mtag.h>
97 #endif /* PF_PKTHDR */
98
99 /*
100 * Mbufs are of a single size, MSIZE (machine/param.h), which
101 * includes overhead. An mbuf may add a single "mbuf cluster" of size
102 * MCLBYTES (also in machine/param.h), which has no additional overhead
103 * and is used instead of the internal data area; this is done when
104 * at least MINCLSIZE of data must be stored.
105 */
106
107 /*
108 * These macros are mapped to the appropriate KPIs, so that private code
109 * can be simply recompiled in order to be forward-compatible with future
110 * changes toward the struture sizes.
111 */
112 #define MLEN mbuf_get_mlen() /* normal data len */
113 #define MHLEN mbuf_get_mhlen() /* data len w/pkthdr */
114
115 /*
116 * The following _MLEN and _MHLEN macros are private to xnu. Private code
117 * that are outside of xnu must use the mbuf_get_{mlen,mhlen} routines since
118 * the sizes of the structures are dependent upon specific xnu configs.
119 */
120 #define _MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
121 #define _MHLEN (_MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
122
123 #define MINCLSIZE (MHLEN + MLEN) /* smallest amount to put in cluster */
124 #define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
125
126 #define NMBPCL (sizeof(union mcluster) / sizeof(struct mbuf))
127
128 /*
129 * Macros for type conversion
130 * mtod(m,t) - convert mbuf pointer to data pointer of correct type
131 * dtom(x) - convert data pointer within mbuf to mbuf pointer (XXX)
132 */
133 #define mtod(m,t) ((t)m_mtod(m))
134 #define dtom(x) m_dtom(x)
135
136 /* header at beginning of each mbuf: */
137 struct m_hdr {
138 struct mbuf *mh_next; /* next buffer in chain */
139 struct mbuf *mh_nextpkt; /* next chain in queue/record */
140 int32_t mh_len; /* amount of data in this mbuf */
141 caddr_t mh_data; /* location of data */
142 short mh_type; /* type of data in this mbuf */
143 short mh_flags; /* flags; see below */
144 };
145
146 /*
147 * Packet tag structure (see below for details).
148 */
149 struct m_tag {
150 SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
151 u_int16_t m_tag_type; /* Module specific type */
152 u_int16_t m_tag_len; /* Length of data */
153 u_int32_t m_tag_id; /* Module ID */
154 };
155
156 /* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
157 struct pkthdr {
158 int len; /* total packet length */
159 struct ifnet *rcvif; /* rcv interface */
160
161 /* variables for ip and tcp reassembly */
162 void *header; /* pointer to packet header */
163 /* variables for hardware checksum */
164 /* Note: csum_flags is used for hardware checksum and VLAN */
165 int csum_flags; /* flags regarding checksum */
166 int csum_data; /* data field used by csum routines */
167 u_int tso_segsz; /* TSO segment size (actual MSS) */
168 u_short vlan_tag; /* VLAN tag, host byte order */
169 u_short socket_id; /* socket id */
170 SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */
171 #if PF_PKTHDR
172 /*
173 * Be careful; {en,dis}abling PF_PKTHDR will require xnu recompile;
174 * private code outside of xnu must use mbuf_get_mhlen() instead
175 * of MHLEN.
176 */
177 struct pf_mtag pf_mtag;
178 #endif /* PF_PKTHDR */
179 };
180
181
182 /* description of external storage mapped into mbuf, valid if M_EXT set */
183 struct m_ext {
184 caddr_t ext_buf; /* start of buffer */
185 void (*ext_free)(caddr_t , u_int, caddr_t); /* free routine if not the usual */
186 u_int ext_size; /* size of buffer, for ext_free */
187 caddr_t ext_arg; /* additional ext_free argument */
188 struct ext_refsq { /* references held */
189 struct ext_refsq *forward, *backward;
190 } ext_refs;
191 struct ext_ref {
192 u_int32_t refcnt;
193 u_int32_t flags;
194 } *ext_refflags;
195 };
196
197 /* define m_ext to a type since it gets redefined below */
198 typedef struct m_ext _m_ext_t;
199
200 struct mbuf {
201 struct m_hdr m_hdr;
202 union {
203 struct {
204 struct pkthdr MH_pkthdr; /* M_PKTHDR set */
205 union {
206 struct m_ext MH_ext; /* M_EXT set */
207 char MH_databuf[_MHLEN];
208 } MH_dat;
209 } MH;
210 char M_databuf[_MLEN]; /* !M_PKTHDR, !M_EXT */
211 } M_dat;
212 };
213
214 #define m_next m_hdr.mh_next
215 #define m_len m_hdr.mh_len
216 #define m_data m_hdr.mh_data
217 #define m_type m_hdr.mh_type
218 #define m_flags m_hdr.mh_flags
219 #define m_nextpkt m_hdr.mh_nextpkt
220 #define m_act m_nextpkt
221 #define m_pkthdr M_dat.MH.MH_pkthdr
222 #define m_ext M_dat.MH.MH_dat.MH_ext
223 #define m_pktdat M_dat.MH.MH_dat.MH_databuf
224 #define m_dat M_dat.M_databuf
225
226 /* mbuf flags */
227 #define M_EXT 0x0001 /* has associated external storage */
228 #define M_PKTHDR 0x0002 /* start of record */
229 #define M_EOR 0x0004 /* end of record */
230 #define M_PROTO1 0x0008 /* protocol-specific */
231 #define M_PROTO2 0x0010 /* protocol-specific */
232 #define M_PROTO3 0x0020 /* protocol-specific */
233 #define M_PROTO4 0x0040 /* protocol-specific */
234 #define M_PROTO5 0x0080 /* protocol-specific */
235
236 /* mbuf pkthdr flags, also in m_flags */
237 #define M_BCAST 0x0100 /* send/received as link-level broadcast */
238 #define M_MCAST 0x0200 /* send/received as link-level multicast */
239 #define M_FRAG 0x0400 /* packet is a fragment of a larger packet */
240 #define M_FIRSTFRAG 0x0800 /* packet is first fragment */
241 #define M_LASTFRAG 0x1000 /* packet is last fragment */
242 #define M_PROMISC 0x2000 /* packet is promiscuous (shouldn't go to stack) */
243
244 /* flags copied when copying m_pkthdr */
245 #define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_PROTO2|M_PROTO3 | \
246 M_PROTO4|M_PROTO5|M_BCAST|M_MCAST|M_FRAG | \
247 M_FIRSTFRAG|M_LASTFRAG|M_PROMISC)
248
249 /* flags indicating hw checksum support and sw checksum requirements [freebsd4.1]*/
250 #define CSUM_IP 0x0001 /* will csum IP */
251 #define CSUM_TCP 0x0002 /* will csum TCP */
252 #define CSUM_UDP 0x0004 /* will csum UDP */
253 #define CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */
254 #define CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */
255
256 #define CSUM_IP_CHECKED 0x0100 /* did csum IP */
257 #define CSUM_IP_VALID 0x0200 /* ... the csum is valid */
258 #define CSUM_DATA_VALID 0x0400 /* csum_data field is valid */
259 #define CSUM_PSEUDO_HDR 0x0800 /* csum_data has pseudo hdr */
260 #define CSUM_TCP_SUM16 0x1000 /* simple TCP Sum16 computation */
261
262 #define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP)
263 #define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */
264 /*
265 * Note: see also IF_HWASSIST_CSUM defined in <net/if_var.h>
266 */
267 /* bottom 16 bits reserved for hardware checksum */
268 #define CSUM_CHECKSUM_MASK 0xffff
269
270 /* VLAN tag present */
271 #define CSUM_VLAN_TAG_VALID 0x10000 /* vlan_tag field is valid */
272
273 /* TCP Segment Offloading requested on this mbuf */
274 #define CSUM_TSO_IPV4 0x100000 /* This mbuf needs to be segmented by the NIC */
275 #define CSUM_TSO_IPV6 0x200000 /* This mbuf needs to be segmented by the NIC */
276 #endif /* KERNEL_PRIVATE */
277
278
279 /* mbuf types */
280 #define MT_FREE 0 /* should be on free list */
281 #define MT_DATA 1 /* dynamic (data) allocation */
282 #define MT_HEADER 2 /* packet header */
283 #define MT_SOCKET 3 /* socket structure */
284 #define MT_PCB 4 /* protocol control block */
285 #define MT_RTABLE 5 /* routing tables */
286 #define MT_HTABLE 6 /* IMP host tables */
287 #define MT_ATABLE 7 /* address resolution tables */
288 #define MT_SONAME 8 /* socket name */
289 #define MT_SOOPTS 10 /* socket options */
290 #define MT_FTABLE 11 /* fragment reassembly header */
291 #define MT_RIGHTS 12 /* access rights */
292 #define MT_IFADDR 13 /* interface address */
293 #define MT_CONTROL 14 /* extra-data protocol message */
294 #define MT_OOBDATA 15 /* expedited data */
295 #define MT_TAG 16 /* volatile metadata associated to pkts */
296 #define MT_MAX 32 /* enough? */
297
298 #ifdef KERNEL_PRIVATE
299
300 /* flags to m_get/MGET */
301 /* Need to include malloc.h to get right options for malloc */
302 #include <sys/malloc.h>
303
304 #define M_DONTWAIT M_NOWAIT
305 #define M_WAIT M_WAITOK
306
307 /*
308 * mbuf allocation/deallocation macros:
309 *
310 * MGET(struct mbuf *m, int how, int type)
311 * allocates an mbuf and initializes it to contain internal data.
312 *
313 * MGETHDR(struct mbuf *m, int how, int type)
314 * allocates an mbuf and initializes it to contain a packet header
315 * and internal data.
316 */
317
318 #if 1
319 #define MCHECK(m) m_mcheck(m)
320 #else
321 #define MCHECK(m)
322 #endif
323
324 #define MGET(m, how, type) ((m) = m_get((how), (type)))
325
326 #define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type)))
327
328 /*
329 * Mbuf cluster macros.
330 * MCLALLOC(caddr_t p, int how) allocates an mbuf cluster.
331 * MCLGET adds such clusters to a normal mbuf;
332 * the flag M_EXT is set upon success.
333 * MCLFREE releases a reference to a cluster allocated by MCLALLOC,
334 * freeing the cluster if the reference count has reached 0.
335 *
336 * Normal mbuf clusters are normally treated as character arrays
337 * after allocation, but use the first word of the buffer as a free list
338 * pointer while on the free list.
339 */
340 union mcluster {
341 union mcluster *mcl_next;
342 char mcl_buf[MCLBYTES];
343 };
344
345 #define MCLALLOC(p, how) ((p) = m_mclalloc(how))
346
347 #define MCLFREE(p) m_mclfree(p)
348
349 #define MCLGET(m, how) ((m) = m_mclget(m, how))
350
351 /*
352 * Mbuf big cluster
353 */
354
355 union mbigcluster {
356 union mbigcluster *mbc_next;
357 char mbc_buf[NBPG];
358 };
359
360 #define M16KCLBYTES (16 * 1024)
361
362 union m16kcluster {
363 union m16kcluster *m16kcl_next;
364 char m16kcl_buf[M16KCLBYTES];
365 };
366
367 #define MCLHASREFERENCE(m) m_mclhasreference(m)
368
369 /*
370 * MFREE(struct mbuf *m, struct mbuf *n)
371 * Free a single mbuf and associated external storage.
372 * Place the successor, if any, in n.
373 */
374
375 #define MFREE(m, n) ((n) = m_free(m))
376
377 /*
378 * Copy mbuf pkthdr from from to to.
379 * from must have M_PKTHDR set, and to must be empty.
380 * aux pointer will be moved to `to'.
381 */
382 #define M_COPY_PKTHDR(to, from) m_copy_pkthdr(to, from)
383
384 /*
385 * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
386 * an object of the specified size at the end of the mbuf, longword aligned.
387 */
388 #define M_ALIGN(m, len) \
389 { (m)->m_data += (MLEN - (len)) &~ (sizeof(long) - 1); }
390 /*
391 * As above, for mbufs allocated with m_gethdr/MGETHDR
392 * or initialized by M_COPY_PKTHDR.
393 */
394 #define MH_ALIGN(m, len) \
395 { (m)->m_data += (MHLEN - (len)) &~ (sizeof(long) - 1); }
396
397 /*
398 * Compute the amount of space available
399 * before the current start of data in an mbuf.
400 * Subroutine - data not available if certain references.
401 */
402 #define M_LEADINGSPACE(m) m_leadingspace(m)
403
404 /*
405 * Compute the amount of space available
406 * after the end of data in an mbuf.
407 * Subroutine - data not available if certain references.
408 */
409 #define M_TRAILINGSPACE(m) m_trailingspace(m)
410
411 /*
412 * Arrange to prepend space of size plen to mbuf m.
413 * If a new mbuf must be allocated, how specifies whether to wait.
414 * If how is M_DONTWAIT and allocation fails, the original mbuf chain
415 * is freed and m is set to NULL.
416 */
417 #define M_PREPEND(m, plen, how) ((m) = m_prepend_2((m), (plen), (how)))
418
419 /* change mbuf to new type */
420 #define MCHTYPE(m, t) m_mchtype(m, t)
421
422 /* length to m_copy to copy all */
423 #define M_COPYALL 1000000000
424
425 /* compatiblity with 4.3 */
426 #define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
427
428 #define MBSHIFT 20 /* 1MB */
429 #define GBSHIFT 30 /* 1GB */
430
431 #endif /* KERNEL_PRIVATE */
432
433 /*
434 * Mbuf statistics (legacy).
435 */
436 struct mbstat {
437 u_int32_t m_mbufs; /* mbufs obtained from page pool */
438 u_int32_t m_clusters; /* clusters obtained from page pool */
439 u_int32_t m_spare; /* spare field */
440 u_int32_t m_clfree; /* free clusters */
441 u_int32_t m_drops; /* times failed to find space */
442 u_int32_t m_wait; /* times waited for space */
443 u_int32_t m_drain; /* times drained protocols for space */
444 u_short m_mtypes[256]; /* type specific mbuf allocations */
445 u_int32_t m_mcfail; /* times m_copym failed */
446 u_int32_t m_mpfail; /* times m_pullup failed */
447 u_int32_t m_msize; /* length of an mbuf */
448 u_int32_t m_mclbytes; /* length of an mbuf cluster */
449 u_int32_t m_minclsize; /* min length of data to allocate a cluster */
450 u_int32_t m_mlen; /* length of data in an mbuf */
451 u_int32_t m_mhlen; /* length of data in a header mbuf */
452 u_int32_t m_bigclusters; /* clusters obtained from page pool */
453 u_int32_t m_bigclfree; /* free clusters */
454 u_int32_t m_bigmclbytes; /* length of an mbuf cluster */
455 };
456
457 /* Compatibillity with 10.3 */
458 struct ombstat {
459 u_int32_t m_mbufs; /* mbufs obtained from page pool */
460 u_int32_t m_clusters; /* clusters obtained from page pool */
461 u_int32_t m_spare; /* spare field */
462 u_int32_t m_clfree; /* free clusters */
463 u_int32_t m_drops; /* times failed to find space */
464 u_int32_t m_wait; /* times waited for space */
465 u_int32_t m_drain; /* times drained protocols for space */
466 u_short m_mtypes[256]; /* type specific mbuf allocations */
467 u_int32_t m_mcfail; /* times m_copym failed */
468 u_int32_t m_mpfail; /* times m_pullup failed */
469 u_int32_t m_msize; /* length of an mbuf */
470 u_int32_t m_mclbytes; /* length of an mbuf cluster */
471 u_int32_t m_minclsize; /* min length of data to allocate a cluster */
472 u_int32_t m_mlen; /* length of data in an mbuf */
473 u_int32_t m_mhlen; /* length of data in a header mbuf */
474 };
475
476 /*
477 * mbuf class statistics.
478 */
479 #define MAX_MBUF_CNAME 15
480
481 #if defined(KERNEL_PRIVATE)
482 /* For backwards compatibility with 32-bit userland process */
483 struct omb_class_stat {
484 char mbcl_cname[MAX_MBUF_CNAME + 1]; /* class name */
485 u_int32_t mbcl_size; /* buffer size */
486 u_int32_t mbcl_total; /* # of buffers created */
487 u_int32_t mbcl_active; /* # of active buffers */
488 u_int32_t mbcl_infree; /* # of available buffers */
489 u_int32_t mbcl_slab_cnt; /* # of available slabs */
490 u_int64_t mbcl_alloc_cnt; /* # of times alloc is called */
491 u_int64_t mbcl_free_cnt; /* # of times free is called */
492 u_int64_t mbcl_notified; /* # of notified wakeups */
493 u_int64_t mbcl_purge_cnt; /* # of purges so far */
494 u_int64_t mbcl_fail_cnt; /* # of allocation failures */
495 u_int32_t mbcl_ctotal; /* total only for this class */
496 /*
497 * Cache layer statistics
498 */
499 u_int32_t mbcl_mc_state; /* cache state (see below) */
500 u_int32_t mbcl_mc_cached; /* # of cached buffers */
501 u_int32_t mbcl_mc_waiter_cnt; /* # waiters on the cache */
502 u_int32_t mbcl_mc_wretry_cnt; /* # of wait retries */
503 u_int32_t mbcl_mc_nwretry_cnt; /* # of no-wait retry attempts */
504 u_int64_t mbcl_reserved[4]; /* for future use */
505 } __attribute__((__packed__));
506 #endif /* KERNEL_PRIVATE */
507
508 typedef struct mb_class_stat {
509 char mbcl_cname[MAX_MBUF_CNAME + 1]; /* class name */
510 u_int32_t mbcl_size; /* buffer size */
511 u_int32_t mbcl_total; /* # of buffers created */
512 u_int32_t mbcl_active; /* # of active buffers */
513 u_int32_t mbcl_infree; /* # of available buffers */
514 u_int32_t mbcl_slab_cnt; /* # of available slabs */
515 #if defined(KERNEL) || defined(__LP64__)
516 u_int32_t mbcl_pad; /* padding */
517 #endif /* KERNEL || __LP64__ */
518 u_int64_t mbcl_alloc_cnt; /* # of times alloc is called */
519 u_int64_t mbcl_free_cnt; /* # of times free is called */
520 u_int64_t mbcl_notified; /* # of notified wakeups */
521 u_int64_t mbcl_purge_cnt; /* # of purges so far */
522 u_int64_t mbcl_fail_cnt; /* # of allocation failures */
523 u_int32_t mbcl_ctotal; /* total only for this class */
524 /*
525 * Cache layer statistics
526 */
527 u_int32_t mbcl_mc_state; /* cache state (see below) */
528 u_int32_t mbcl_mc_cached; /* # of cached buffers */
529 u_int32_t mbcl_mc_waiter_cnt; /* # waiters on the cache */
530 u_int32_t mbcl_mc_wretry_cnt; /* # of wait retries */
531 u_int32_t mbcl_mc_nwretry_cnt; /* # of no-wait retry attempts */
532 u_int64_t mbcl_reserved[4]; /* for future use */
533 } mb_class_stat_t;
534
535 #define MCS_DISABLED 0 /* cache is permanently disabled */
536 #define MCS_ONLINE 1 /* cache is online */
537 #define MCS_PURGING 2 /* cache is being purged */
538 #define MCS_OFFLINE 3 /* cache is offline (resizing) */
539
540 #if defined(KERNEL_PRIVATE)
541 /* For backwards compatibility with 32-bit userland process */
542 struct omb_stat {
543 u_int32_t mbs_cnt; /* number of classes */
544 struct omb_class_stat mbs_class[1]; /* class array */
545 } __attribute__((__packed__));
546 #endif /* KERNEL_PRIVATE */
547
548 typedef struct mb_stat {
549 u_int32_t mbs_cnt; /* number of classes */
550 #if defined(KERNEL) || defined(__LP64__)
551 u_int32_t mbs_pad; /* padding */
552 #endif /* KERNEL || __LP64__ */
553 mb_class_stat_t mbs_class[1]; /* class array */
554 } mb_stat_t;
555
556 #ifdef KERNEL_PRIVATE
557
558 #ifdef KERNEL
559 extern union mcluster *mbutl; /* virtual address of mclusters */
560 extern union mcluster *embutl; /* ending virtual address of mclusters */
561 extern struct mbstat mbstat; /* statistics */
562 extern unsigned int nmbclusters; /* number of mapped clusters */
563 extern int njcl; /* # of clusters for jumbo sizes */
564 extern int njclbytes; /* size of a jumbo cluster */
565 extern int max_linkhdr; /* largest link-level header */
566 extern int max_protohdr; /* largest protocol header */
567 extern int max_hdr; /* largest link+protocol header */
568 extern int max_datalen; /* MHLEN - max_hdr */
569
570 __BEGIN_DECLS
571 /* Not exported */
572 __private_extern__ unsigned int mbuf_default_ncl(int, uint64_t);
573 __private_extern__ void mbinit(void);
574 __private_extern__ struct mbuf *m_clattach(struct mbuf *, int, caddr_t,
575 void (*)(caddr_t , u_int, caddr_t), u_int, caddr_t, int);
576 __private_extern__ caddr_t m_bigalloc(int);
577 __private_extern__ void m_bigfree(caddr_t, u_int, caddr_t);
578 __private_extern__ struct mbuf *m_mbigget(struct mbuf *, int);
579 __private_extern__ caddr_t m_16kalloc(int);
580 __private_extern__ void m_16kfree(caddr_t, u_int, caddr_t);
581 __private_extern__ struct mbuf *m_m16kget(struct mbuf *, int);
582 __private_extern__ void mbuf_growth_aggressive(void);
583 __private_extern__ void mbuf_growth_normal(void);
584
585 /* Exported */
586 struct mbuf *m_copym(struct mbuf *, int, int, int);
587 struct mbuf *m_split(struct mbuf *, int, int);
588 struct mbuf *m_free(struct mbuf *);
589 struct mbuf *m_get(int, int);
590 struct mbuf *m_getpacket(void);
591 struct mbuf *m_getclr(int, int);
592 struct mbuf *m_gethdr(int, int);
593 struct mbuf *m_prepend(struct mbuf *, int, int);
594 struct mbuf *m_prepend_2(struct mbuf *, int, int);
595 struct mbuf *m_pullup(struct mbuf *, int);
596 struct mbuf *m_retry(int, int);
597 struct mbuf *m_retryhdr(int, int);
598 void m_adj(struct mbuf *, int);
599 void m_freem(struct mbuf *);
600 int m_freem_list(struct mbuf *);
601 struct mbuf *m_devget(char *, int, int, struct ifnet *, void (*)(const void *, void *, size_t));
602 char *mcl_to_paddr(char *);
603 struct mbuf *m_pulldown(struct mbuf*, int, int, int*);
604
605 extern struct mbuf *m_getcl(int, int, int);
606 struct mbuf *m_mclget(struct mbuf *, int);
607 caddr_t m_mclalloc(int);
608 void m_mclfree(caddr_t p);
609 int m_mclhasreference(struct mbuf *);
610 void m_copy_pkthdr(struct mbuf *, struct mbuf*);
611
612 int m_mclref(struct mbuf *);
613 int m_mclunref(struct mbuf *);
614
615 void * m_mtod(struct mbuf *);
616 struct mbuf * m_dtom(void *);
617 int m_mtocl(void *);
618 union mcluster *m_cltom(int );
619
620 int m_trailingspace(struct mbuf *);
621 int m_leadingspace(struct mbuf *);
622
623 struct mbuf *m_normalize(struct mbuf *m);
624 void m_mchtype(struct mbuf *m, int t);
625 void m_mcheck(struct mbuf*);
626
627 extern void m_copyback(struct mbuf *, int , int , const void *);
628 extern struct mbuf *m_copyback_cow(struct mbuf *, int, int, const void *, int);
629 extern int m_makewritable(struct mbuf **, int, int, int);
630 void m_copydata(struct mbuf *, int , int , void *);
631 struct mbuf* m_dup(struct mbuf *m, int how);
632 void m_cat(struct mbuf *, struct mbuf *);
633 struct mbuf *m_copym_with_hdrs(struct mbuf*, int, int, int, struct mbuf**, int*);
634 struct mbuf *m_getpackets(int, int, int);
635 struct mbuf * m_getpackethdrs(int , int );
636 struct mbuf* m_getpacket_how(int );
637 struct mbuf * m_getpackets_internal(unsigned int *, int , int , int , size_t);
638 struct mbuf * m_allocpacket_internal(unsigned int * , size_t , unsigned int *, int , int , size_t );
639
640 __END_DECLS
641
642 /*
643 Packets may have annotations attached by affixing a list of "packet
644 tags" to the pkthdr structure. Packet tags are dynamically allocated
645 semi-opaque data structures that have a fixed header (struct m_tag)
646 that specifies the size of the memory block and an <id,type> pair that
647 identifies it. The id identifies the module and the type identifies the
648 type of data for that module. The id of zero is reserved for the kernel.
649
650 Note that the packet tag returned by m_tag_allocate has the default
651 memory alignment implemented by malloc. To reference private data one
652 can use a construct like:
653
654 struct m_tag *mtag = m_tag_allocate(...);
655 struct foo *p = (struct foo *)(mtag+1);
656
657 if the alignment of struct m_tag is sufficient for referencing members
658 of struct foo. Otherwise it is necessary to embed struct m_tag within
659 the private data structure to insure proper alignment; e.g.
660
661 struct foo {
662 struct m_tag tag;
663 ...
664 };
665 struct foo *p = (struct foo *) m_tag_allocate(...);
666 struct m_tag *mtag = &p->tag;
667 */
668
669 #define KERNEL_MODULE_TAG_ID 0
670
671 enum {
672 KERNEL_TAG_TYPE_NONE = 0,
673 KERNEL_TAG_TYPE_DUMMYNET = 1,
674 KERNEL_TAG_TYPE_DIVERT = 2,
675 KERNEL_TAG_TYPE_IPFORWARD = 3,
676 KERNEL_TAG_TYPE_IPFILT = 4,
677 KERNEL_TAG_TYPE_MACLABEL = 5,
678 KERNEL_TAG_TYPE_MAC_POLICY_LABEL = 6,
679 KERNEL_TAG_TYPE_ENCAP = 8,
680 KERNEL_TAG_TYPE_INET6 = 9,
681 KERNEL_TAG_TYPE_IPSEC = 10,
682 KERNEL_TAG_TYPE_PF = 11
683 };
684
685 /*
686 * As a temporary and low impact solution to replace the even uglier
687 * approach used so far in some parts of the network stack (which relies
688 * on global variables), packet tag-like annotations are stored in MT_TAG
689 * mbufs (or lookalikes) prepended to the actual mbuf chain.
690 *
691 * m_type = MT_TAG
692 * m_flags = m_tag_id
693 * m_next = next buffer in chain.
694 *
695 * BE VERY CAREFUL not to pass these blocks to the mbuf handling routines.
696 */
697 #define _m_tag_id m_hdr.mh_flags
698
699 __BEGIN_DECLS
700
701 /* Packet tag routines */
702 struct m_tag *m_tag_alloc(u_int32_t id, u_int16_t type, int len, int wait);
703 void m_tag_free(struct m_tag *);
704 void m_tag_prepend(struct mbuf *, struct m_tag *);
705 void m_tag_unlink(struct mbuf *, struct m_tag *);
706 void m_tag_delete(struct mbuf *, struct m_tag *);
707 void m_tag_delete_chain(struct mbuf *, struct m_tag *);
708 struct m_tag *m_tag_locate(struct mbuf *,u_int32_t id, u_int16_t type,
709 struct m_tag *);
710 struct m_tag *m_tag_copy(struct m_tag *, int wait);
711 int m_tag_copy_chain(struct mbuf *to, struct mbuf *from, int wait);
712 void m_tag_init(struct mbuf *);
713 struct m_tag *m_tag_first(struct mbuf *);
714 struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
715
716 __END_DECLS
717
718 #endif /* KERNEL */
719
720 #endif /* KERNEL_PRIVATE */
721 #ifdef KERNEL
722 #include <sys/kpi_mbuf.h>
723 #endif /* KERNEL */
724 #endif /* !_SYS_MBUF_H_ */