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