Add m_defrag_nofree, which works like m_defrag, but doesn't free the
[dragonfly.git] / sys / sys / mbuf.h
CommitLineData
984263bc 1/*
02742ec6
JS
2 * Copyright (c) 2004 The DragonFly Project. All rights reserved.
3 *
984263bc
MD
4 * Copyright (c) 1982, 1986, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
36 * $FreeBSD: src/sys/sys/mbuf.h,v 1.44.2.17 2003/04/15 06:15:02 silby Exp $
c8f5127a 37 * $DragonFly: src/sys/sys/mbuf.h,v 1.20 2005/02/20 00:20:43 joerg Exp $
984263bc
MD
38 */
39
40#ifndef _SYS_MBUF_H_
41#define _SYS_MBUF_H_
42
43#include <sys/queue.h>
44
45/*
46 * Mbufs are of a single size, MSIZE (machine/param.h), which
47 * includes overhead. An mbuf may add a single "mbuf cluster" of size
48 * MCLBYTES (also in machine/param.h), which has no additional overhead
49 * and is used instead of the internal data area; this is done when
50 * at least MINCLSIZE of data must be stored.
51 */
52#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
53#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
54#define MINCLSIZE (MHLEN + 1) /* smallest amount to put in cluster */
55#define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
56
57/*
58 * Macros for type conversion:
59 * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type.
984263bc
MD
60 * mtocl(x) - convert pointer within cluster to cluster index #
61 * cltom(x) - convert cluster # to ptr to beginning of cluster
62 */
63#define mtod(m, t) ((t)((m)->m_data))
984263bc
MD
64
65/*
66 * Header present at the beginning of every mbuf.
67 */
68struct m_hdr {
69 struct mbuf *mh_next; /* next buffer in chain */
70 struct mbuf *mh_nextpkt; /* next chain in queue/record */
71 caddr_t mh_data; /* location of data */
72 int mh_len; /* amount of data in this mbuf */
73 short mh_type; /* type of data in this mbuf */
74 short mh_flags; /* flags; see below */
75};
76
77/*
78 * Packet tag structure (see below for details).
79 */
80struct m_tag {
81 SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
82 u_int16_t m_tag_id; /* Tag ID */
83 u_int16_t m_tag_len; /* Length of data */
84 u_int32_t m_tag_cookie; /* ABI/Module ID */
85};
86
46ca7d86
MD
87SLIST_HEAD(packet_tags, m_tag);
88
984263bc
MD
89/*
90 * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set.
4d723e5a
JS
91 *
92 * Be careful: The fields have been carefully ordered to avoid hidden padding.
93 * Keep this in mind, when adding or removing fields!
984263bc
MD
94 */
95struct pkthdr {
96 struct ifnet *rcvif; /* rcv interface */
97 int len; /* total packet length */
46ca7d86
MD
98 struct packet_tags tags; /* list of packet tags */
99
984263bc
MD
100 /* variables for ip and tcp reassembly */
101 void *header; /* pointer to packet header */
46ca7d86 102
984263bc
MD
103 /* variables for hardware checksum */
104 int csum_flags; /* flags regarding checksum */
105 int csum_data; /* data field used by csum routines */
46ca7d86 106
4d723e5a
JS
107 /* firewall flags */
108 uint32_t fw_flags; /* flags for PF */
109
02742ec6 110 /* variables for PF processing */
46ca7d86
MD
111 uint16_t pf_tag; /* PF tag id */
112 uint8_t pf_routed; /* PF routing counter */
4d723e5a
JS
113
114 /* variables for ALTQ processing */
115 uint8_t ecn_af; /* address family for ECN */
116 uint32_t altq_qid; /* queue id */
984263bc
MD
117};
118
119/*
120 * Description of external storage mapped into mbuf; valid only if M_EXT is set.
121 */
122struct m_ext {
123 caddr_t ext_buf; /* start of buffer */
7eccf245
MD
124 union {
125 void (*old)(caddr_t, u_int);
126 void (*new)(void *arg);
127 void *any;
128 } ext_nfree;
129 u_int ext_size; /* size of buffer, for ext_nfree */
130 union {
131 void (*old)(caddr_t, u_int);
132 void (*new)(void *arg);
133 void *any;
134 } ext_nref;
135 void *ext_arg;
984263bc
MD
136};
137
138/*
139 * The core of the mbuf object along with some shortcut defines for
140 * practical purposes.
141 */
142struct mbuf {
143 struct m_hdr m_hdr;
144 union {
145 struct {
146 struct pkthdr MH_pkthdr; /* M_PKTHDR set */
147 union {
148 struct m_ext MH_ext; /* M_EXT set */
149 char MH_databuf[MHLEN];
150 } MH_dat;
151 } MH;
152 char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
153 } M_dat;
154};
155#define m_next m_hdr.mh_next
156#define m_len m_hdr.mh_len
157#define m_data m_hdr.mh_data
158#define m_type m_hdr.mh_type
159#define m_flags m_hdr.mh_flags
160#define m_nextpkt m_hdr.mh_nextpkt
984263bc
MD
161#define m_pkthdr M_dat.MH.MH_pkthdr
162#define m_ext M_dat.MH.MH_dat.MH_ext
163#define m_pktdat M_dat.MH.MH_dat.MH_databuf
164#define m_dat M_dat.M_databuf
165
9a275e74
HP
166/*
167 * Code that uses m_act should be converted to use m_nextpkt
168 * instead; m_act is historical and deprecated.
169 */
170#define m_act m_nextpkt
171
984263bc
MD
172/*
173 * mbuf flags.
174 */
175#define M_EXT 0x0001 /* has associated external storage */
176#define M_PKTHDR 0x0002 /* start of record */
177#define M_EOR 0x0004 /* end of record */
178#define M_PROTO1 0x0008 /* protocol-specific */
179#define M_PROTO2 0x0010 /* protocol-specific */
180#define M_PROTO3 0x0020 /* protocol-specific */
181#define M_PROTO4 0x0040 /* protocol-specific */
182#define M_PROTO5 0x0080 /* protocol-specific */
183
184/*
185 * mbuf pkthdr flags (also stored in m_flags).
186 */
187#define M_BCAST 0x0100 /* send/received as link-level broadcast */
188#define M_MCAST 0x0200 /* send/received as link-level multicast */
189#define M_FRAG 0x0400 /* packet is a fragment of a larger packet */
190#define M_FIRSTFRAG 0x0800 /* packet is first fragment */
191#define M_LASTFRAG 0x1000 /* packet is last fragment */
7eccf245 192#define M_EXT_OLD 0x2000 /* new ext function format */
90775e29 193#define M_EXT_CLUSTER 0x4000 /* standard cluster else special */
984263bc
MD
194
195/*
196 * Flags copied when copying m_pkthdr.
197 */
198#define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_PROTO1|M_PROTO2|M_PROTO3 | \
199 M_PROTO4|M_PROTO5|M_BCAST|M_MCAST|M_FRAG | \
200 M_FIRSTFRAG|M_LASTFRAG)
201
202/*
203 * Flags indicating hw checksum support and sw checksum requirements.
204 */
205#define CSUM_IP 0x0001 /* will csum IP */
206#define CSUM_TCP 0x0002 /* will csum TCP */
207#define CSUM_UDP 0x0004 /* will csum UDP */
208#define CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */
209#define CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */
210
211#define CSUM_IP_CHECKED 0x0100 /* did csum IP */
212#define CSUM_IP_VALID 0x0200 /* ... the csum is valid */
213#define CSUM_DATA_VALID 0x0400 /* csum_data field is valid */
214#define CSUM_PSEUDO_HDR 0x0800 /* csum_data has pseudo hdr */
215
216#define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP)
217#define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */
218
02742ec6
JS
219/*
220 * Flags indicating PF processing status
221 */
222#define PF_MBUF_GENERATED 0x00000001
223#define PF_MBUF_TAGGED 0x00000002 /* pf_tag field is valid */
224#define PF_MBUF_ROUTED 0x00000004 /* pf_routed field is valid */
225#define PF_MBUF_TRANSLATE_LOCALHOST \
226 0x00000008
227#define PF_MBUF_FRAGCACHE 0x00000010
4d723e5a 228#define ALTQ_MBUF_TAGGED 0x00000020 /* altq_qid is valid */
02742ec6 229
984263bc
MD
230/*
231 * mbuf types.
232 */
233#define MT_FREE 0 /* should be on free list */
234#define MT_DATA 1 /* dynamic (data) allocation */
235#define MT_HEADER 2 /* packet header */
236#if 0
237#define MT_SOCKET 3 /* socket structure */
238#define MT_PCB 4 /* protocol control block */
239#define MT_RTABLE 5 /* routing tables */
240#define MT_HTABLE 6 /* IMP host tables */
241#define MT_ATABLE 7 /* address resolution tables */
242#endif
243#define MT_SONAME 8 /* socket name */
244#if 0
245#define MT_SOOPTS 10 /* socket options */
246#endif
247#define MT_FTABLE 11 /* fragment reassembly header */
248#if 0
249#define MT_RIGHTS 12 /* access rights */
250#define MT_IFADDR 13 /* interface address */
251#endif
252#define MT_TAG 13 /* volatile metadata associated to pkts */
253#define MT_CONTROL 14 /* extra-data protocol message */
254#define MT_OOBDATA 15 /* expedited data */
255#define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */
256
257/*
258 * General mbuf allocator statistics structure.
259 */
260struct mbstat {
261 u_long m_mbufs; /* mbufs obtained from page pool */
262 u_long m_clusters; /* clusters obtained from page pool */
263 u_long m_spare; /* spare field */
264 u_long m_clfree; /* free clusters */
265 u_long m_drops; /* times failed to find space */
266 u_long m_wait; /* times waited for space */
267 u_long m_drain; /* times drained protocols for space */
268 u_long m_mcfail; /* times m_copym failed */
269 u_long m_mpfail; /* times m_pullup failed */
270 u_long m_msize; /* length of an mbuf */
271 u_long m_mclbytes; /* length of an mbuf cluster */
272 u_long m_minclsize; /* min length of data to allocate a cluster */
273 u_long m_mlen; /* length of data in an mbuf */
274 u_long m_mhlen; /* length of data in a header mbuf */
275};
276
277/*
278 * Flags specifying how an allocation should be made.
279 */
280
74f1caca
EN
281#define MB_DONTWAIT 0x4
282#define MB_TRYWAIT 0x8
283#define MB_WAIT MB_TRYWAIT
97482992
HP
284
285/*
286 * Mbuf to Malloc Flag Conversion.
287 */
74f1caca 288#define MBTOM(how) ((how) & MB_TRYWAIT ? M_WAITOK : M_NOWAIT)
984263bc 289
984263bc
MD
290/*
291 * These are identifying numbers passed to the m_mballoc_wait function,
292 * allowing us to determine whether the call came from an MGETHDR or
293 * an MGET.
294 */
295#define MGETHDR_C 1
296#define MGET_C 2
297
298/*
299 * Wake up the next instance (if any) of m_mballoc_wait() which is
300 * waiting for an mbuf to be freed. This should be called at splimp().
301 *
302 * XXX: If there is another free mbuf, this routine will be called [again]
303 * from the m_mballoc_wait routine in order to wake another sleep instance.
304 */
305#define MMBWAKEUP() do { \
306 if (m_mballoc_wid) { \
307 m_mballoc_wid--; \
308 wakeup_one(&m_mballoc_wid); \
309 } \
310} while (0)
311
312/*
313 * Same as above, but for mbuf cluster(s).
314 */
315#define MCLWAKEUP() do { \
316 if (m_clalloc_wid) { \
317 m_clalloc_wid--; \
318 wakeup_one(&m_clalloc_wid); \
319 } \
320} while (0)
321
322/*
323 * mbuf utility macros:
324 *
325 * MBUFLOCK(code)
326 * prevents a section of code from from being interrupted by network
327 * drivers.
328 */
329#define MBUFLOCK(code) do { \
330 int _ms = splimp(); \
331 \
332 { code } \
333 splx(_ms); \
334} while (0)
335
336/*
12496bdf 337 * mbuf allocation/deallocation macros (YYY deprecated, too big):
984263bc
MD
338 *
339 * MGET(struct mbuf *m, int how, int type)
340 * allocates an mbuf and initializes it to contain internal data.
341 *
342 * MGETHDR(struct mbuf *m, int how, int type)
343 * allocates an mbuf and initializes it to contain a packet header
344 * and internal data.
345 */
346#define MGET(m, how, type) do { \
12496bdf 347 (m) = m_get((how), (type)); \
984263bc
MD
348} while (0)
349
350#define MGETHDR(m, how, type) do { \
12496bdf 351 (m) = m_gethdr((how), (type)); \
984263bc
MD
352} while (0)
353
354/*
90775e29
MD
355 * MCLGET adds such clusters to a normal mbuf. The flag M_EXT is set upon
356 * success.
984263bc 357 */
b6650ec0
MD
358#define MCLGET(m, how) do { \
359 m_mclget((m), (how)); \
984263bc
MD
360} while (0)
361
984263bc
MD
362/*
363 * NB: M_COPY_PKTHDR is deprecated; use either M_MOVE_PKTHDR
364 * or m_dup_pkthdr.
365 */
366/*
367 * Move mbuf pkthdr from "from" to "to".
368 * from should have M_PKTHDR set, and to must be empty.
369 * from no longer has a pkthdr after this operation.
370 */
371#define M_MOVE_PKTHDR(_to, _from) m_move_pkthdr((_to), (_from))
372
373/*
374 * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
375 * an object of the specified size at the end of the mbuf, longword aligned.
376 */
377#define M_ALIGN(m, len) do { \
378 (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \
379} while (0)
380
381/*
382 * As above, for mbufs allocated with m_gethdr/MGETHDR
383 * or initialized by M_COPY_PKTHDR.
384 */
385#define MH_ALIGN(m, len) do { \
386 (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \
387} while (0)
388
389/*
390 * Check if we can write to an mbuf.
391 */
90775e29
MD
392#define M_EXT_WRITABLE(m) (m_sharecount(m) == 1)
393#define M_WRITABLE(m) (!((m)->m_flags & M_EXT) || M_EXT_WRITABLE(m))
984263bc 394
84633371
JS
395/*
396 * Check if the supplied mbuf has a packet header, or else panic.
397 */
398#define M_ASSERTPKTHDR(m) \
399 KASSERT(m != NULL && m->m_flags & M_PKTHDR, \
400 ("%s: invalid mbuf or no mbuf packet header!", __func__))
401
984263bc
MD
402/*
403 * Compute the amount of space available
404 * before the current start of data in an mbuf.
405 *
406 * The M_WRITABLE() is a temporary, conservative safety measure: the burden
407 * of checking writability of the mbuf data area rests solely with the caller.
408 */
409#define M_LEADINGSPACE(m) \
410 ((m)->m_flags & M_EXT ? \
411 (M_EXT_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \
412 (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
413 (m)->m_data - (m)->m_dat)
414
415/*
416 * Compute the amount of space available
417 * after the end of data in an mbuf.
418 *
419 * The M_WRITABLE() is a temporary, conservative safety measure: the burden
420 * of checking writability of the mbuf data area rests solely with the caller.
421 */
422#define M_TRAILINGSPACE(m) \
423 ((m)->m_flags & M_EXT ? \
424 (M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size \
425 - ((m)->m_data + (m)->m_len) : 0) : \
426 &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
427
428/*
429 * Arrange to prepend space of size plen to mbuf m.
430 * If a new mbuf must be allocated, how specifies whether to wait.
74f1caca 431 * If how is MB_DONTWAIT and allocation fails, the original mbuf chain
984263bc
MD
432 * is freed and m is set to NULL.
433 */
434#define M_PREPEND(m, plen, how) do { \
435 struct mbuf **_mmp = &(m); \
436 struct mbuf *_mm = *_mmp; \
437 int _mplen = (plen); \
438 int __mhow = (how); \
439 \
440 if (M_LEADINGSPACE(_mm) >= _mplen) { \
441 _mm->m_data -= _mplen; \
442 _mm->m_len += _mplen; \
443 } else \
444 _mm = m_prepend(_mm, _mplen, __mhow); \
445 if (_mm != NULL && _mm->m_flags & M_PKTHDR) \
446 _mm->m_pkthdr.len += _mplen; \
447 *_mmp = _mm; \
448} while (0)
449
984263bc
MD
450/* Length to m_copy to copy all. */
451#define M_COPYALL 1000000000
452
453/* Compatibility with 4.3 */
74f1caca 454#define m_copy(m, o, l) m_copym((m), (o), (l), MB_DONTWAIT)
984263bc
MD
455
456#ifdef _KERNEL
457extern u_int m_clalloc_wid; /* mbuf cluster wait count */
458extern u_int m_mballoc_wid; /* mbuf wait count */
459extern int max_linkhdr; /* largest link-level header */
460extern int max_protohdr; /* largest protocol header */
461extern int max_hdr; /* largest link+protocol header */
462extern int max_datalen; /* MHLEN - max_hdr */
463extern struct mbstat mbstat;
984263bc 464extern int mbuf_wait; /* mbuf sleep time */
984263bc
MD
465extern int nmbclusters;
466extern int nmbufs;
984263bc 467
0c33f36d
JH
468struct uio;
469
984263bc
MD
470void m_adj(struct mbuf *, int);
471void m_cat(struct mbuf *, struct mbuf *);
984263bc 472void m_copyback(struct mbuf *, int, int, caddr_t);
f15db79e
MD
473void m_copydata(const struct mbuf *, int, int, caddr_t);
474struct mbuf *m_copym(const struct mbuf *, int, int, int);
984263bc
MD
475struct mbuf *m_copypacket(struct mbuf *, int);
476struct mbuf *m_defrag(struct mbuf *, int);
c8f5127a 477struct mbuf *m_defrag_nofree(struct mbuf *, int);
984263bc
MD
478struct mbuf *m_devget(char *, int, int, struct ifnet *,
479 void (*copy)(char *, caddr_t, u_int));
480struct mbuf *m_dup(struct mbuf *, int);
f15db79e 481int m_dup_pkthdr(struct mbuf *, const struct mbuf *, int);
984263bc
MD
482struct mbuf *m_free(struct mbuf *);
483void m_freem(struct mbuf *);
484struct mbuf *m_get(int, int);
485struct mbuf *m_getcl(int how, short type, int flags);
486struct mbuf *m_getclr(int, int);
487struct mbuf *m_gethdr(int, int);
488struct mbuf *m_getm(struct mbuf *, int, int, int);
984263bc
MD
489void m_move_pkthdr(struct mbuf *, struct mbuf *);
490struct mbuf *m_prepend(struct mbuf *, int, int);
491void m_print(const struct mbuf *m);
492struct mbuf *m_pulldown(struct mbuf *, int, int, int *);
493struct mbuf *m_pullup(struct mbuf *, int);
494struct mbuf *m_retry(int, int);
495struct mbuf *m_retryhdr(int, int);
496struct mbuf *m_split(struct mbuf *, int, int);
0c33f36d 497struct mbuf *m_uiomove(struct uio *, int, int);
b6650ec0 498void m_mclget(struct mbuf *m, int how);
90775e29
MD
499int m_sharecount(struct mbuf *m);
500void m_chtype(struct mbuf *m, int type);
501
984263bc
MD
502
503/*
504 * Packets may have annotations attached by affixing a list
505 * of "packet tags" to the pkthdr structure. Packet tags are
506 * dynamically allocated semi-opaque data structures that have
507 * a fixed header (struct m_tag) that specifies the size of the
508 * memory block and a <cookie,type> pair that identifies it.
509 * The cookie is a 32-bit unique unsigned value used to identify
510 * a module or ABI. By convention this value is chose as the
511 * date+time that the module is created, expressed as the number of
512 * seconds since the epoch (e.g. using date -u +'%s'). The type value
513 * is an ABI/module-specific value that identifies a particular annotation
514 * and is private to the module. For compatibility with systems
515 * like openbsd that define packet tags w/o an ABI/module cookie,
516 * the value PACKET_ABI_COMPAT is used to implement m_tag_get and
517 * m_tag_find compatibility shim functions and several tag types are
518 * defined below. Users that do not require compatibility should use
519 * a private cookie value so that packet tag-related definitions
520 * can be maintained privately.
521 *
522 * Note that the packet tag returned by m_tag_allocate has the default
523 * memory alignment implemented by malloc. To reference private data
524 * one can use a construct like:
525 *
526 * struct m_tag *mtag = m_tag_allocate(...);
527 * struct foo *p = (struct foo *)(mtag+1);
528 *
529 * if the alignment of struct m_tag is sufficient for referencing members
530 * of struct foo. Otherwise it is necessary to embed struct m_tag within
531 * the private data structure to insure proper alignment; e.g.
532 *
533 * struct foo {
534 * struct m_tag tag;
535 * ...
536 * };
537 * struct foo *p = (struct foo *) m_tag_allocate(...);
538 * struct m_tag *mtag = &p->tag;
539 */
540
541#define PACKET_TAG_NONE 0 /* Nadda */
542
543/* Packet tag for use with PACKET_ABI_COMPAT */
544#define PACKET_TAG_IPSEC_IN_DONE 1 /* IPsec applied, in */
821819dc 545/* struct tdb_indent */
984263bc 546#define PACKET_TAG_IPSEC_OUT_DONE 2 /* IPsec applied, out */
821819dc 547/* struct tdb_indent */
984263bc 548#define PACKET_TAG_IPSEC_IN_CRYPTO_DONE 3 /* NIC IPsec crypto done */
821819dc 549/* struct tdb_indent, never added */
984263bc 550#define PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED 4 /* NIC IPsec crypto req'ed */
821819dc 551/* struct tdb_indent, never added */
984263bc 552#define PACKET_TAG_IPSEC_PENDING_TDB 6 /* Reminder to do IPsec */
821819dc 553/* struct tdb_indent, never added */
984263bc 554#define PACKET_TAG_ENCAP 11 /* Encap. processing */
821819dc 555/* struct ifnet *, the GIF interface */
984263bc 556#define PACKET_TAG_IPSEC_HISTORY 13 /* IPSEC history */
821819dc 557/* struct ipsec_history */
984263bc 558#define PACKET_TAG_IPV6_INPUT 14 /* IPV6 input processing */
821819dc 559/* struct ip6aux */
984263bc
MD
560
561/*
562 * As a temporary and low impact solution to replace the even uglier
563 * approach used so far in some parts of the network stack (which relies
564 * on global variables), packet tag-like annotations are stored in MT_TAG
565 * mbufs (or lookalikes) prepended to the actual mbuf chain.
566 *
567 * m_type = MT_TAG
568 * m_flags = m_tag_id
569 * m_next = next buffer in chain.
570 *
571 * BE VERY CAREFUL not to pass these blocks to the mbuf handling routines.
572 */
573#define _m_tag_id m_hdr.mh_flags
574
575/* Packet tags used in the FreeBSD network stack */
576#define PACKET_TAG_DUMMYNET 15 /* dummynet info */
821819dc 577/* struct dn_pkt as fake mbuf */
984263bc 578#define PACKET_TAG_DIVERT 17 /* divert info */
821819dc 579/* uint16_t, encoded in m_data */
984263bc 580#define PACKET_TAG_IPFORWARD 18 /* ipforward info */
821819dc 581/* struct sockaddr_in * as m_data */
984263bc
MD
582
583/* Packet tag routines */
584struct m_tag *m_tag_alloc(u_int32_t, int, int, int);
585void m_tag_free(struct m_tag *);
586void m_tag_prepend(struct mbuf *, struct m_tag *);
587void m_tag_unlink(struct mbuf *, struct m_tag *);
588void m_tag_delete(struct mbuf *, struct m_tag *);
589void m_tag_delete_chain(struct mbuf *, struct m_tag *);
590struct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *);
591struct m_tag *m_tag_copy(struct m_tag *, int);
f15db79e 592int m_tag_copy_chain(struct mbuf *, const struct mbuf *, int);
984263bc
MD
593void m_tag_init(struct mbuf *);
594struct m_tag *m_tag_first(struct mbuf *);
595struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
596
597/* these are for openbsd compatibility */
598#define MTAG_ABI_COMPAT 0 /* compatibility ABI */
599
600static __inline struct m_tag *
601m_tag_get(int type, int length, int wait)
602{
603 return m_tag_alloc(MTAG_ABI_COMPAT, type, length, wait);
604}
605
606static __inline struct m_tag *
607m_tag_find(struct mbuf *m, int type, struct m_tag *start)
608{
609 return m_tag_locate(m, MTAG_ABI_COMPAT, type, start);
610}
611#endif /* _KERNEL */
612
613#endif /* !_SYS_MBUF_H_ */