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