]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/mbuf.h
xnu-792.10.96.tar.gz
[apple/xnu.git] / bsd / sys / mbuf.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
23 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 /*
25 * Mach Operating System
26 * Copyright (c) 1987 Carnegie-Mellon University
27 * All rights reserved. The CMU software License Agreement specifies
28 * the terms and conditions for use and redistribution.
29 */
30 /*
31 * Copyright (c) 1994 NeXT Computer, Inc. All rights reserved.
32 *
33 * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 * @(#)mbuf.h 8.3 (Berkeley) 1/21/94
65 **********************************************************************
66 * HISTORY
67 * 20-May-95 Mac Gillon (mgillon) at NeXT
68 * New version based on 4.4
69 * Purged old history
70 */
71
72 #ifndef _SYS_MBUF_H_
73 #define _SYS_MBUF_H_
74
75 #include <sys/cdefs.h>
76 #include <sys/appleapiopts.h>
77
78 #ifdef KERNEL_PRIVATE
79
80 #include <sys/lock.h>
81 #include <sys/queue.h>
82
83 /*
84 * Mbufs are of a single size, MSIZE (machine/param.h), which
85 * includes overhead. An mbuf may add a single "mbuf cluster" of size
86 * MCLBYTES (also in machine/param.h), which has no additional overhead
87 * and is used instead of the internal data area; this is done when
88 * at least MINCLSIZE of data must be stored.
89 */
90
91 #define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
92 #define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
93
94 #define MINCLSIZE (MHLEN + MLEN) /* smallest amount to put in cluster */
95 #define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
96
97 #define NMBPCL (sizeof(union mcluster) / sizeof(struct mbuf))
98
99 /*
100 * Macros for type conversion
101 * mtod(m,t) - convert mbuf pointer to data pointer of correct type
102 * dtom(x) - convert data pointer within mbuf to mbuf pointer (XXX)
103 * mtocl(x) - convert pointer within cluster to cluster index #
104 * cltom(x) - convert cluster # to ptr to beginning of cluster
105 */
106 #define mtod(m,t) ((t)m_mtod(m))
107 #define dtom(x) m_dtom(x)
108 #define mtocl(x) m_mtocl(x)
109 #define cltom(x) m_cltom(x)
110
111 #define MCLREF(p) m_mclref(p)
112 #define MCLUNREF(p) m_mclunref(p)
113
114 /* header at beginning of each mbuf: */
115 struct m_hdr {
116 struct mbuf *mh_next; /* next buffer in chain */
117 struct mbuf *mh_nextpkt; /* next chain in queue/record */
118 long mh_len; /* amount of data in this mbuf */
119 caddr_t mh_data; /* location of data */
120 short mh_type; /* type of data in this mbuf */
121 short mh_flags; /* flags; see below */
122 };
123
124 /*
125 * Packet tag structure (see below for details).
126 */
127 struct m_tag {
128 SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
129 u_int16_t m_tag_type; /* Module specific type */
130 u_int16_t m_tag_len; /* Length of data */
131 u_int32_t m_tag_id; /* Module ID */
132 };
133
134 /* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
135 struct pkthdr {
136 int len; /* total packet length */
137 struct ifnet *rcvif; /* rcv interface */
138
139 /* variables for ip and tcp reassembly */
140 void *header; /* pointer to packet header */
141 /* variables for hardware checksum */
142 #ifdef KERNEL_PRIVATE
143 /* Note: csum_flags is used for hardware checksum and VLAN */
144 #endif KERNEL_PRIVATE
145 int csum_flags; /* flags regarding checksum */
146 int csum_data; /* data field used by csum routines */
147 struct mbuf *aux; /* extra data buffer; ipsec/others */
148 #ifdef KERNEL_PRIVATE
149 u_short vlan_tag; /* VLAN tag, host byte order */
150 u_short socket_id; /* socket id */
151 #else KERNEL_PRIVATE
152 u_int reserved1; /* for future use */
153 #endif KERNEL_PRIVATE
154 SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */
155 };
156
157
158 /* description of external storage mapped into mbuf, valid if M_EXT set */
159 struct m_ext {
160 caddr_t ext_buf; /* start of buffer */
161 void (*ext_free)(caddr_t , u_int, caddr_t); /* free routine if not the usual */
162 u_int ext_size; /* size of buffer, for ext_free */
163 caddr_t ext_arg; /* additional ext_free argument */
164 struct ext_refsq { /* references held */
165 struct ext_refsq *forward, *backward;
166 } ext_refs;
167 };
168
169 struct mbuf {
170 struct m_hdr m_hdr;
171 union {
172 struct {
173 struct pkthdr MH_pkthdr; /* M_PKTHDR set */
174 union {
175 struct m_ext MH_ext; /* M_EXT set */
176 char MH_databuf[MHLEN];
177 } MH_dat;
178 } MH;
179 char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
180 } M_dat;
181 };
182
183 #define m_next m_hdr.mh_next
184 #define m_len m_hdr.mh_len
185 #define m_data m_hdr.mh_data
186 #define m_type m_hdr.mh_type
187 #define m_flags m_hdr.mh_flags
188 #define m_nextpkt m_hdr.mh_nextpkt
189 #define m_act m_nextpkt
190 #define m_pkthdr M_dat.MH.MH_pkthdr
191 #define m_ext M_dat.MH.MH_dat.MH_ext
192 #define m_pktdat M_dat.MH.MH_dat.MH_databuf
193 #define m_dat M_dat.M_databuf
194
195 /* mbuf flags */
196 #define M_EXT 0x0001 /* has associated external storage */
197 #define M_PKTHDR 0x0002 /* start of record */
198 #define M_EOR 0x0004 /* end of record */
199 #define M_PROTO1 0x0008 /* protocol-specific */
200 #define M_PROTO2 0x0010 /* protocol-specific */
201 #define M_PROTO3 0x0020 /* protocol-specific */
202 #define M_PROTO4 0x0040 /* protocol-specific */
203 #define M_PROTO5 0x0080 /* protocol-specific */
204
205 /* mbuf pkthdr flags, also in m_flags */
206 #define M_BCAST 0x0100 /* send/received as link-level broadcast */
207 #define M_MCAST 0x0200 /* send/received as link-level multicast */
208 #define M_FRAG 0x0400 /* packet is a fragment of a larger packet */
209 #define M_FIRSTFRAG 0x0800 /* packet is first fragment */
210 #define M_LASTFRAG 0x1000 /* packet is last fragment */
211 #define M_PROMISC 0x2000 /* packet is promiscuous (shouldn't go to stack) */
212
213 /* flags copied when copying m_pkthdr */
214 #define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_PROTO2|M_PROTO3 | \
215 M_PROTO4|M_PROTO5|M_BCAST|M_MCAST|M_FRAG | \
216 M_FIRSTFRAG|M_LASTFRAG|M_PROMISC)
217
218 /* flags indicating hw checksum support and sw checksum requirements [freebsd4.1]*/
219 #define CSUM_IP 0x0001 /* will csum IP */
220 #define CSUM_TCP 0x0002 /* will csum TCP */
221 #define CSUM_UDP 0x0004 /* will csum UDP */
222 #define CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */
223 #define CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */
224
225 #define CSUM_IP_CHECKED 0x0100 /* did csum IP */
226 #define CSUM_IP_VALID 0x0200 /* ... the csum is valid */
227 #define CSUM_DATA_VALID 0x0400 /* csum_data field is valid */
228 #define CSUM_PSEUDO_HDR 0x0800 /* csum_data has pseudo hdr */
229 #define CSUM_TCP_SUM16 0x1000 /* simple TCP Sum16 computation */
230
231 #define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP)
232 #define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */
233 /*
234 * Note: see also IF_HWASSIST_CSUM defined in <net/if_var.h>
235 */
236 /* bottom 16 bits reserved for hardware checksum */
237 #define CSUM_CHECKSUM_MASK 0xffff
238
239 /* VLAN tag present */
240 #define CSUM_VLAN_TAG_VALID 0x10000 /* vlan_tag field is valid */
241 #endif KERNEL_PRIVATE
242
243
244 /* mbuf types */
245 #define MT_FREE 0 /* should be on free list */
246 #define MT_DATA 1 /* dynamic (data) allocation */
247 #define MT_HEADER 2 /* packet header */
248 #define MT_SOCKET 3 /* socket structure */
249 #define MT_PCB 4 /* protocol control block */
250 #define MT_RTABLE 5 /* routing tables */
251 #define MT_HTABLE 6 /* IMP host tables */
252 #define MT_ATABLE 7 /* address resolution tables */
253 #define MT_SONAME 8 /* socket name */
254 #define MT_SOOPTS 10 /* socket options */
255 #define MT_FTABLE 11 /* fragment reassembly header */
256 #define MT_RIGHTS 12 /* access rights */
257 #define MT_IFADDR 13 /* interface address */
258 #define MT_CONTROL 14 /* extra-data protocol message */
259 #define MT_OOBDATA 15 /* expedited data */
260 #define MT_TAG 16 /* volatile metadata associated to pkts */
261 #define MT_MAX 32 /* enough? */
262
263 #ifdef KERNEL_PRIVATE
264
265 /* flags to m_get/MGET */
266 /* Need to include malloc.h to get right options for malloc */
267 #include <sys/malloc.h>
268
269 #define M_DONTWAIT M_NOWAIT
270 #define M_WAIT M_WAITOK
271
272 /*
273 * mbuf utility macros:
274 *
275 * MBUFLOCK(code)
276 * prevents a section of code from from being interrupted by network
277 * drivers.
278 */
279
280 #ifdef _KERN_LOCKS_H_
281 extern lck_mtx_t * mbuf_mlock;
282 #else
283 extern void * mbuf_mlock;
284 #endif
285
286 #define MBUF_LOCK() lck_mtx_lock(mbuf_mlock);
287 #define MBUF_UNLOCK() lck_mtx_unlock(mbuf_mlock);
288
289 /*
290 * mbuf allocation/deallocation macros:
291 *
292 * MGET(struct mbuf *m, int how, int type)
293 * allocates an mbuf and initializes it to contain internal data.
294 *
295 * MGETHDR(struct mbuf *m, int how, int type)
296 * allocates an mbuf and initializes it to contain a packet header
297 * and internal data.
298 */
299
300 #if 1
301 #define MCHECK(m) m_mcheck(m)
302 #else
303 #define MCHECK(m)
304 #endif
305
306 extern struct mbuf *mfree; /* mbuf free list */
307
308 #define MGET(m, how, type) ((m) = m_get((how), (type)))
309
310 #define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type)))
311
312 /*
313 * Mbuf cluster macros.
314 * MCLALLOC(caddr_t p, int how) allocates an mbuf cluster.
315 * MCLGET adds such clusters to a normal mbuf;
316 * the flag M_EXT is set upon success.
317 * MCLFREE releases a reference to a cluster allocated by MCLALLOC,
318 * freeing the cluster if the reference count has reached 0.
319 *
320 * Normal mbuf clusters are normally treated as character arrays
321 * after allocation, but use the first word of the buffer as a free list
322 * pointer while on the free list.
323 */
324 union mcluster {
325 union mcluster *mcl_next;
326 char mcl_buf[MCLBYTES];
327 };
328
329 #define MCLALLOC(p, how) ((p) = m_mclalloc(how))
330
331 #define MCLFREE(p) m_mclfree(p)
332
333 #define MCLGET(m, how) ((m) = m_mclget(m, how))
334
335 /*
336 * Mbuf big cluster
337 */
338
339 union mbigcluster {
340 union mbigcluster *mbc_next;
341 char mbc_buf[NBPG];
342 };
343
344
345 #define MCLHASREFERENCE(m) m_mclhasreference(m)
346
347 /*
348 * MFREE(struct mbuf *m, struct mbuf *n)
349 * Free a single mbuf and associated external storage.
350 * Place the successor, if any, in n.
351 */
352
353 #define MFREE(m, n) ((n) = m_free(m))
354
355 /*
356 * Copy mbuf pkthdr from from to to.
357 * from must have M_PKTHDR set, and to must be empty.
358 * aux pointer will be moved to `to'.
359 */
360 #define M_COPY_PKTHDR(to, from) m_copy_pkthdr(to, from)
361
362 /*
363 * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
364 * an object of the specified size at the end of the mbuf, longword aligned.
365 */
366 #define M_ALIGN(m, len) \
367 { (m)->m_data += (MLEN - (len)) &~ (sizeof(long) - 1); }
368 /*
369 * As above, for mbufs allocated with m_gethdr/MGETHDR
370 * or initialized by M_COPY_PKTHDR.
371 */
372 #define MH_ALIGN(m, len) \
373 { (m)->m_data += (MHLEN - (len)) &~ (sizeof(long) - 1); }
374
375 /*
376 * Compute the amount of space available
377 * before the current start of data in an mbuf.
378 * Subroutine - data not available if certain references.
379 */
380 #define M_LEADINGSPACE(m) m_leadingspace(m)
381
382 /*
383 * Compute the amount of space available
384 * after the end of data in an mbuf.
385 * Subroutine - data not available if certain references.
386 */
387 #define M_TRAILINGSPACE(m) m_trailingspace(m)
388
389 /*
390 * Arrange to prepend space of size plen to mbuf m.
391 * If a new mbuf must be allocated, how specifies whether to wait.
392 * If how is M_DONTWAIT and allocation fails, the original mbuf chain
393 * is freed and m is set to NULL.
394 */
395 #define M_PREPEND(m, plen, how) ((m) = m_prepend_2((m), (plen), (how)))
396
397 /* change mbuf to new type */
398 #define MCHTYPE(m, t) m_mchtype(m, t)
399
400 /* length to m_copy to copy all */
401 #define M_COPYALL 1000000000
402
403 /* compatiblity with 4.3 */
404 #define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
405
406 #endif /* KERNEL_PRIVATE */
407
408 /*
409 * Mbuf statistics.
410 */
411 /* LP64todo - not 64-bit safe */
412 struct mbstat {
413 u_long m_mbufs; /* mbufs obtained from page pool */
414 u_long m_clusters; /* clusters obtained from page pool */
415 u_long m_spare; /* spare field */
416 u_long m_clfree; /* free clusters */
417 u_long m_drops; /* times failed to find space */
418 u_long m_wait; /* times waited for space */
419 u_long m_drain; /* times drained protocols for space */
420 u_short m_mtypes[256]; /* type specific mbuf allocations */
421 u_long m_mcfail; /* times m_copym failed */
422 u_long m_mpfail; /* times m_pullup failed */
423 u_long m_msize; /* length of an mbuf */
424 u_long m_mclbytes; /* length of an mbuf cluster */
425 u_long m_minclsize; /* min length of data to allocate a cluster */
426 u_long m_mlen; /* length of data in an mbuf */
427 u_long m_mhlen; /* length of data in a header mbuf */
428 u_long m_bigclusters; /* clusters obtained from page pool */
429 u_long m_bigclfree; /* free clusters */
430 u_long m_bigmclbytes; /* length of an mbuf cluster */
431 };
432
433 /* Compatibillity with 10.3 */
434 struct ombstat {
435 u_long m_mbufs; /* mbufs obtained from page pool */
436 u_long m_clusters; /* clusters obtained from page pool */
437 u_long m_spare; /* spare field */
438 u_long m_clfree; /* free clusters */
439 u_long m_drops; /* times failed to find space */
440 u_long m_wait; /* times waited for space */
441 u_long m_drain; /* times drained protocols for space */
442 u_short m_mtypes[256]; /* type specific mbuf allocations */
443 u_long m_mcfail; /* times m_copym failed */
444 u_long m_mpfail; /* times m_pullup failed */
445 u_long m_msize; /* length of an mbuf */
446 u_long m_mclbytes; /* length of an mbuf cluster */
447 u_long m_minclsize; /* min length of data to allocate a cluster */
448 u_long m_mlen; /* length of data in an mbuf */
449 u_long m_mhlen; /* length of data in a header mbuf */
450 };
451 #ifdef KERNEL_PRIVATE
452
453 /*
454 * pkthdr.aux type tags.
455 */
456 struct mauxtag {
457 int af;
458 int type;
459 };
460
461 #ifdef KERNEL
462 extern union mcluster *mbutl; /* virtual address of mclusters */
463 extern union mcluster *embutl; /* ending virtual address of mclusters */
464 extern short *mclrefcnt; /* cluster reference counts */
465 extern int *mcl_paddr; /* physical addresses of clusters */
466 extern struct mbstat mbstat; /* statistics */
467 extern int nmbclusters; /* number of mapped clusters */
468 extern union mcluster *mclfree; /* free mapped cluster list */
469 extern int max_linkhdr; /* largest link-level header */
470 extern int max_protohdr; /* largest protocol header */
471 extern int max_hdr; /* largest link+protocol header */
472 extern int max_datalen; /* MHLEN - max_hdr */
473
474 __BEGIN_DECLS
475 struct mbuf *m_copym(struct mbuf *, int, int, int);
476 struct mbuf *m_split(struct mbuf *, int, int);
477 struct mbuf *m_free(struct mbuf *);
478 struct mbuf *m_get(int, int);
479 struct mbuf *m_getpacket(void);
480 struct mbuf *m_getclr(int, int);
481 struct mbuf *m_gethdr(int, int);
482 struct mbuf *m_prepend(struct mbuf *, int, int);
483 struct mbuf *m_prepend_2(struct mbuf *, int, int);
484 struct mbuf *m_pullup(struct mbuf *, int);
485 struct mbuf *m_retry(int, int);
486 struct mbuf *m_retryhdr(int, int);
487 void m_adj(struct mbuf *, int);
488 void m_freem(struct mbuf *);
489 int m_freem_list(struct mbuf *);
490 struct mbuf *m_devget(char *, int, int, struct ifnet *, void (*)(const void *, void *, size_t));
491 char *mcl_to_paddr(char *);
492 struct mbuf *m_pulldown(struct mbuf*, int, int, int*);
493 struct mbuf *m_aux_add(struct mbuf *, int, int);
494 struct mbuf *m_aux_find(struct mbuf *, int, int);
495 void m_aux_delete(struct mbuf *, struct mbuf *);
496
497 struct mbuf *m_mclget(struct mbuf *, int);
498 caddr_t m_mclalloc(int);
499 void m_mclfree(caddr_t p);
500 int m_mclhasreference(struct mbuf *);
501 void m_copy_pkthdr(struct mbuf *, struct mbuf*);
502
503 int m_mclref(struct mbuf *);
504 int m_mclunref(struct mbuf *);
505
506 void * m_mtod(struct mbuf *);
507 struct mbuf * m_dtom(void *);
508 int m_mtocl(void *);
509 union mcluster *m_cltom(int );
510
511 int m_trailingspace(struct mbuf *);
512 int m_leadingspace(struct mbuf *);
513
514 void m_mchtype(struct mbuf *m, int t);
515 void m_mcheck(struct mbuf*);
516
517 void m_copyback(struct mbuf *, int , int , caddr_t);
518 void m_copydata(struct mbuf *, int , int , caddr_t);
519 struct mbuf* m_dup(struct mbuf *m, int how);
520 void m_cat(struct mbuf *, struct mbuf *);
521 struct mbuf *m_copym_with_hdrs(struct mbuf*, int, int, int, struct mbuf**, int*);
522 struct mbuf *m_getpackets(int, int, int);
523 struct mbuf * m_getpackethdrs(int , int );
524 struct mbuf* m_getpacket_how(int );
525 struct mbuf * m_getpackets_internal(unsigned int *, int , int , int , size_t);
526 struct mbuf * m_allocpacket_internal(unsigned int * , size_t , unsigned int *, int , int , size_t );
527
528 __END_DECLS
529
530 /*
531 Packets may have annotations attached by affixing a list of "packet
532 tags" to the pkthdr structure. Packet tags are dynamically allocated
533 semi-opaque data structures that have a fixed header (struct m_tag)
534 that specifies the size of the memory block and an <id,type> pair that
535 identifies it. The id identifies the module and the type identifies the
536 type of data for that module. The id of zero is reserved for the kernel.
537
538 Note that the packet tag returned by m_tag_allocate has the default
539 memory alignment implemented by malloc. To reference private data one
540 can use a construct like:
541
542 struct m_tag *mtag = m_tag_allocate(...);
543 struct foo *p = (struct foo *)(mtag+1);
544
545 if the alignment of struct m_tag is sufficient for referencing members
546 of struct foo. Otherwise it is necessary to embed struct m_tag within
547 the private data structure to insure proper alignment; e.g.
548
549 struct foo {
550 struct m_tag tag;
551 ...
552 };
553 struct foo *p = (struct foo *) m_tag_allocate(...);
554 struct m_tag *mtag = &p->tag;
555 */
556
557 #define KERNEL_MODULE_TAG_ID 0
558
559 enum {
560 KERNEL_TAG_TYPE_NONE = 0,
561 KERNEL_TAG_TYPE_DUMMYNET = 1,
562 KERNEL_TAG_TYPE_DIVERT = 2,
563 KERNEL_TAG_TYPE_IPFORWARD = 3,
564 KERNEL_TAG_TYPE_IPFILT = 4
565 };
566
567 /*
568 * As a temporary and low impact solution to replace the even uglier
569 * approach used so far in some parts of the network stack (which relies
570 * on global variables), packet tag-like annotations are stored in MT_TAG
571 * mbufs (or lookalikes) prepended to the actual mbuf chain.
572 *
573 * m_type = MT_TAG
574 * m_flags = m_tag_id
575 * m_next = next buffer in chain.
576 *
577 * BE VERY CAREFUL not to pass these blocks to the mbuf handling routines.
578 */
579 #define _m_tag_id m_hdr.mh_flags
580
581 __BEGIN_DECLS
582
583 /* Packet tag routines */
584 struct m_tag *m_tag_alloc(u_int32_t id, u_int16_t type, int len, int wait);
585 void m_tag_free(struct m_tag *);
586 void m_tag_prepend(struct mbuf *, struct m_tag *);
587 void m_tag_unlink(struct mbuf *, struct m_tag *);
588 void m_tag_delete(struct mbuf *, struct m_tag *);
589 void m_tag_delete_chain(struct mbuf *, struct m_tag *);
590 struct m_tag *m_tag_locate(struct mbuf *,u_int32_t id, u_int16_t type,
591 struct m_tag *);
592 struct m_tag *m_tag_copy(struct m_tag *, int wait);
593 int m_tag_copy_chain(struct mbuf *to, struct mbuf *from, int wait);
594 void m_tag_init(struct mbuf *);
595 struct m_tag *m_tag_first(struct mbuf *);
596 struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
597
598 __END_DECLS
599
600 #endif /* KERNEL */
601
602 #endif /* KERNEL_PRIVATE */
603 #ifdef KERNEL
604 #include <sys/kpi_mbuf.h>
605 #endif
606 #endif /* !_SYS_MBUF_H_ */