2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
29 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
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.
37 * Copyright (c) 1994 NeXT Computer, Inc. All rights reserved.
39 * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
40 * All rights reserved.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
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.
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
70 * @(#)mbuf.h 8.3 (Berkeley) 1/21/94
71 **********************************************************************
73 * 20-May-95 Mac Gillon (mgillon) at NeXT
74 * New version based on 4.4
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,
87 #include <sys/cdefs.h>
88 #include <sys/appleapiopts.h>
93 #include <sys/queue.h>
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.
103 #define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
104 #define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
106 #define MINCLSIZE (MHLEN + MLEN) /* smallest amount to put in cluster */
107 #define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
109 #define NMBPCL (sizeof(union mcluster) / sizeof(struct mbuf))
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)
116 #define mtod(m,t) ((t)m_mtod(m))
117 #define dtom(x) m_dtom(x)
119 /* header at beginning of each mbuf: */
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 */
130 * Packet tag structure (see below for details).
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 */
139 /* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
141 int len
; /* total packet length */
142 struct ifnet
*rcvif
; /* rcv interface */
144 /* variables for ip and tcp reassembly */
145 void *header
; /* pointer to packet header */
146 /* variables for hardware checksum */
147 #ifdef KERNEL_PRIVATE
148 /* Note: csum_flags is used for hardware checksum and VLAN */
149 #endif KERNEL_PRIVATE
150 int csum_flags
; /* flags regarding checksum */
151 int csum_data
; /* data field used by csum routines */
152 void *reserved0
; /* unused, for future use */
153 #ifdef KERNEL_PRIVATE
154 u_short vlan_tag
; /* VLAN tag, host byte order */
155 u_short socket_id
; /* socket id */
157 u_int reserved1
; /* for future use */
158 #endif KERNEL_PRIVATE
159 SLIST_HEAD(packet_tags
, m_tag
) tags
; /* list of packet tags */
163 /* description of external storage mapped into mbuf, valid if M_EXT set */
165 caddr_t ext_buf
; /* start of buffer */
166 void (*ext_free
)(caddr_t
, u_int
, caddr_t
); /* free routine if not the usual */
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
;
182 struct pkthdr MH_pkthdr
; /* M_PKTHDR set */
184 struct m_ext MH_ext
; /* M_EXT set */
185 char MH_databuf
[MHLEN
];
188 char M_databuf
[MLEN
]; /* !M_PKTHDR, !M_EXT */
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
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 */
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 */
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 */
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 */
220 #define M_PROMISC 0x2000 /* packet is promiscuous (shouldn't go to stack) */
222 /* flags copied when copying m_pkthdr */
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)
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 */
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 */
238 #define CSUM_TCP_SUM16 0x1000 /* simple TCP Sum16 computation */
240 #define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP)
241 #define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */
243 * Note: see also IF_HWASSIST_CSUM defined in <net/if_var.h>
245 /* bottom 16 bits reserved for hardware checksum */
246 #define CSUM_CHECKSUM_MASK 0xffff
248 /* VLAN tag present */
249 #define CSUM_VLAN_TAG_VALID 0x10000 /* vlan_tag field is valid */
250 #endif KERNEL_PRIVATE
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 */
269 #define MT_TAG 16 /* volatile metadata associated to pkts */
270 #define MT_MAX 32 /* enough? */
272 #ifdef KERNEL_PRIVATE
274 /* flags to m_get/MGET */
275 /* Need to include malloc.h to get right options for malloc */
276 #include <sys/malloc.h>
278 #define M_DONTWAIT M_NOWAIT
279 #define M_WAIT M_WAITOK
282 * mbuf allocation/deallocation macros:
284 * MGET(struct mbuf *m, int how, int type)
285 * allocates an mbuf and initializes it to contain internal data.
287 * MGETHDR(struct mbuf *m, int how, int type)
288 * allocates an mbuf and initializes it to contain a packet header
293 #define MCHECK(m) m_mcheck(m)
298 #define MGET(m, how, type) ((m) = m_get((how), (type)))
300 #define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type)))
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.
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.
315 union mcluster
*mcl_next
;
316 char mcl_buf
[MCLBYTES
];
319 #define MCLALLOC(p, how) ((p) = m_mclalloc(how))
321 #define MCLFREE(p) m_mclfree(p)
323 #define MCLGET(m, how) ((m) = m_mclget(m, how))
330 union mbigcluster
*mbc_next
;
334 #define M16KCLBYTES (16 * 1024)
337 union m16kcluster
*m16kcl_next
;
338 char m16kcl_buf
[M16KCLBYTES
];
341 #define MCLHASREFERENCE(m) m_mclhasreference(m)
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.
349 #define MFREE(m, n) ((n) = m_free(m))
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'.
356 #define M_COPY_PKTHDR(to, from) m_copy_pkthdr(to, from)
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.
362 #define M_ALIGN(m, len) \
363 { (m)->m_data += (MLEN - (len)) &~ (sizeof(long) - 1); }
365 * As above, for mbufs allocated with m_gethdr/MGETHDR
366 * or initialized by M_COPY_PKTHDR.
368 #define MH_ALIGN(m, len) \
369 { (m)->m_data += (MHLEN - (len)) &~ (sizeof(long) - 1); }
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.
376 #define M_LEADINGSPACE(m) m_leadingspace(m)
379 * Compute the amount of space available
380 * after the end of data in an mbuf.
381 * Subroutine - data not available if certain references.
383 #define M_TRAILINGSPACE(m) m_trailingspace(m)
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.
391 #define M_PREPEND(m, plen, how) ((m) = m_prepend_2((m), (plen), (how)))
393 /* change mbuf to new type */
394 #define MCHTYPE(m, t) m_mchtype(m, t)
396 /* length to m_copy to copy all */
397 #define M_COPYALL 1000000000
399 /* compatiblity with 4.3 */
400 #define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
402 #endif /* KERNEL_PRIVATE */
405 * Mbuf statistics (legacy).
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 */
428 /* Compatibillity with 10.3 */
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 */
448 * mbuf class statistics.
450 #define MAX_MBUF_CNAME 15
452 typedef 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 */
466 * Cache layer statistics
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 */
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) */
481 typedef struct mb_stat
{
482 u_int32_t mbs_cnt
; /* number of classes */
483 mb_class_stat_t mbs_class
[1]; /* class array */
486 #ifdef KERNEL_PRIVATE
489 extern union mcluster
*mbutl
; /* virtual address of mclusters */
490 extern union mcluster
*embutl
; /* ending virtual address of mclusters */
491 extern struct mbstat mbstat
; /* statistics */
492 extern int nmbclusters
; /* number of mapped clusters */
493 extern int njcl
; /* # of clusters for jumbo sizes */
494 extern int njclbytes
; /* size of a jumbo cluster */
495 extern int max_linkhdr
; /* largest link-level header */
496 extern int max_protohdr
; /* largest protocol header */
497 extern int max_hdr
; /* largest link+protocol header */
498 extern int max_datalen
; /* MHLEN - max_hdr */
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);
513 struct mbuf
*m_copym(struct mbuf
*, int, int, int);
514 struct mbuf
*m_split(struct mbuf
*, int, int);
515 struct mbuf
*m_free(struct mbuf
*);
516 struct mbuf
*m_get(int, int);
517 struct mbuf
*m_getpacket(void);
518 struct mbuf
*m_getclr(int, int);
519 struct mbuf
*m_gethdr(int, int);
520 struct mbuf
*m_prepend(struct mbuf
*, int, int);
521 struct mbuf
*m_prepend_2(struct mbuf
*, int, int);
522 struct mbuf
*m_pullup(struct mbuf
*, int);
523 struct mbuf
*m_retry(int, int);
524 struct mbuf
*m_retryhdr(int, int);
525 void m_adj(struct mbuf
*, int);
526 void m_freem(struct mbuf
*);
527 int m_freem_list(struct mbuf
*);
528 struct mbuf
*m_devget(char *, int, int, struct ifnet
*, void (*)(const void *, void *, size_t));
529 char *mcl_to_paddr(char *);
530 struct mbuf
*m_pulldown(struct mbuf
*, int, int, int*);
532 struct mbuf
*m_mclget(struct mbuf
*, int);
533 caddr_t
m_mclalloc(int);
534 void m_mclfree(caddr_t p
);
535 int m_mclhasreference(struct mbuf
*);
536 void m_copy_pkthdr(struct mbuf
*, struct mbuf
*);
538 int m_mclref(struct mbuf
*);
539 int m_mclunref(struct mbuf
*);
541 void * m_mtod(struct mbuf
*);
542 struct mbuf
* m_dtom(void *);
544 union mcluster
*m_cltom(int );
546 int m_trailingspace(struct mbuf
*);
547 int m_leadingspace(struct mbuf
*);
549 struct mbuf
*m_normalize(struct mbuf
*m
);
550 void m_mchtype(struct mbuf
*m
, int t
);
551 void m_mcheck(struct mbuf
*);
553 void m_copyback(struct mbuf
*, int , int , caddr_t
);
554 void m_copydata(struct mbuf
*, int , int , caddr_t
);
555 struct mbuf
* m_dup(struct mbuf
*m
, int how
);
556 void m_cat(struct mbuf
*, struct mbuf
*);
557 struct mbuf
*m_copym_with_hdrs(struct mbuf
*, int, int, int, struct mbuf
**, int*);
558 struct mbuf
*m_getpackets(int, int, int);
559 struct mbuf
* m_getpackethdrs(int , int );
560 struct mbuf
* m_getpacket_how(int );
561 struct mbuf
* m_getpackets_internal(unsigned int *, int , int , int , size_t);
562 struct mbuf
* m_allocpacket_internal(unsigned int * , size_t , unsigned int *, int , int , size_t );
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.
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:
578 struct m_tag *mtag = m_tag_allocate(...);
579 struct foo *p = (struct foo *)(mtag+1);
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.
589 struct foo *p = (struct foo *) m_tag_allocate(...);
590 struct m_tag *mtag = &p->tag;
593 #define KERNEL_MODULE_TAG_ID 0
596 KERNEL_TAG_TYPE_NONE
= 0,
597 KERNEL_TAG_TYPE_DUMMYNET
= 1,
598 KERNEL_TAG_TYPE_DIVERT
= 2,
599 KERNEL_TAG_TYPE_IPFORWARD
= 3,
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
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.
616 * m_next = next buffer in chain.
618 * BE VERY CAREFUL not to pass these blocks to the mbuf handling routines.
620 #define _m_tag_id m_hdr.mh_flags
624 /* Packet tag routines */
625 struct m_tag
*m_tag_alloc(u_int32_t id
, u_int16_t type
, int len
, int wait
);
626 void m_tag_free(struct m_tag
*);
627 void m_tag_prepend(struct mbuf
*, struct m_tag
*);
628 void m_tag_unlink(struct mbuf
*, struct m_tag
*);
629 void m_tag_delete(struct mbuf
*, struct m_tag
*);
630 void m_tag_delete_chain(struct mbuf
*, struct m_tag
*);
631 struct m_tag
*m_tag_locate(struct mbuf
*,u_int32_t id
, u_int16_t type
,
633 struct m_tag
*m_tag_copy(struct m_tag
*, int wait
);
634 int m_tag_copy_chain(struct mbuf
*to
, struct mbuf
*from
, int wait
);
635 void m_tag_init(struct mbuf
*);
636 struct m_tag
*m_tag_first(struct mbuf
*);
637 struct m_tag
*m_tag_next(struct mbuf
*, struct m_tag
*);
643 #endif /* KERNEL_PRIVATE */
645 #include <sys/kpi_mbuf.h>
647 #endif /* !_SYS_MBUF_H_ */