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