Line data Source code
1 : /* $OpenBSD: mbuf.h,v 1.238 2018/09/10 16:14:08 bluhm Exp $ */
2 : /* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
3 :
4 : /*
5 : * Copyright (c) 1982, 1986, 1988, 1993
6 : * The Regents of the University of California. All rights reserved.
7 : *
8 : * Redistribution and use in source and binary forms, with or without
9 : * modification, are permitted provided that the following conditions
10 : * are met:
11 : * 1. Redistributions of source code must retain the above copyright
12 : * notice, this list of conditions and the following disclaimer.
13 : * 2. Redistributions in binary form must reproduce the above copyright
14 : * notice, this list of conditions and the following disclaimer in the
15 : * documentation and/or other materials provided with the distribution.
16 : * 3. Neither the name of the University nor the names of its contributors
17 : * may be used to endorse or promote products derived from this software
18 : * without specific prior written permission.
19 : *
20 : * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 : * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 : * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 : * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 : * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 : * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 : * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 : * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 : * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 : * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 : * SUCH DAMAGE.
31 : *
32 : * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
33 : */
34 :
35 : #ifndef _SYS_MBUF_H_
36 : #define _SYS_MBUF_H_
37 :
38 : #include <sys/queue.h>
39 :
40 : /*
41 : * Constants related to network buffer management.
42 : * MCLBYTES must be no larger than PAGE_SIZE (the software page size) and,
43 : * on machines that exchange pages of input or output buffers with mbuf
44 : * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
45 : * of the hardware page size.
46 : */
47 : #define MSIZE 256 /* size of an mbuf */
48 :
49 : /*
50 : * Mbufs are of a single size, MSIZE, which includes overhead. An mbuf may
51 : * add a single "mbuf cluster" of size MCLBYTES, which has no additional
52 : * overhead and is used instead of the internal data area; this is done when
53 : * at least MINCLSIZE of data must be stored.
54 : */
55 :
56 : #define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
57 : #define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
58 :
59 : #define MAXMCLBYTES (64 * 1024) /* largest cluster from the stack */
60 : #define MINCLSIZE (MHLEN + MLEN + 1) /* smallest amount to put in cluster */
61 : #define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
62 :
63 : #define MCLSHIFT 11 /* convert bytes to m_buf clusters */
64 : /* 2K cluster can hold Ether frame */
65 : #define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */
66 : #define MCLOFSET (MCLBYTES - 1)
67 :
68 : /* Packet tags structure */
69 : struct m_tag {
70 : SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
71 : u_int16_t m_tag_id; /* Tag ID */
72 : u_int16_t m_tag_len; /* Length of data */
73 : };
74 :
75 : /*
76 : * Macros for type conversion
77 : * mtod(m,t) - convert mbuf pointer to data pointer of correct type
78 : */
79 : #define mtod(m,t) ((t)((m)->m_data))
80 :
81 : /* header at beginning of each mbuf: */
82 : struct m_hdr {
83 : struct mbuf *mh_next; /* next buffer in chain */
84 : struct mbuf *mh_nextpkt; /* next chain in queue/record */
85 : caddr_t mh_data; /* location of data */
86 : u_int mh_len; /* amount of data in this mbuf */
87 : short mh_type; /* type of data in this mbuf */
88 : u_short mh_flags; /* flags; see below */
89 : #ifndef __LP64__
90 : u_int mh_pad; /* pad to 8-byte boundary */
91 : #endif
92 : };
93 :
94 : /* pf stuff */
95 : struct pf_state_key;
96 : struct inpcb;
97 :
98 : struct pkthdr_pf {
99 : struct pf_state_key *statekey; /* pf stackside statekey */
100 : struct inpcb *inp; /* connected pcb for outgoing packet */
101 : u_int32_t qid; /* queue id */
102 : u_int16_t tag; /* tag id */
103 : u_int16_t delay; /* delay packet by X ms */
104 : u_int8_t flags;
105 : u_int8_t routed;
106 : u_int8_t prio;
107 : u_int8_t pad[1];
108 : };
109 :
110 : /* pkthdr_pf.flags */
111 : #define PF_TAG_GENERATED 0x01
112 : #define PF_TAG_SYNCOOKIE_RECREATED 0x02
113 : #define PF_TAG_TRANSLATE_LOCALHOST 0x04
114 : #define PF_TAG_DIVERTED 0x08
115 : #define PF_TAG_DIVERTED_PACKET 0x10
116 : #define PF_TAG_REROUTE 0x20
117 : #define PF_TAG_REFRAGMENTED 0x40 /* refragmented ipv6 packet */
118 : #define PF_TAG_PROCESSED 0x80 /* packet was checked by pf */
119 :
120 : #ifdef _KERNEL
121 : #define MPF_BITS \
122 : ("\20\1GENERATED\3TRANSLATE_LOCALHOST\4DIVERTED\5DIVERTED_PACKET" \
123 : "\6REROUTE\7REFRAGMENTED\10PROCESSED")
124 : #endif
125 :
126 : /* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
127 : struct pkthdr {
128 : void *ph_cookie; /* additional data */
129 : SLIST_HEAD(, m_tag) ph_tags; /* list of packet tags */
130 : int64_t ph_timestamp; /* packet timestamp */
131 : int len; /* total packet length */
132 : u_int16_t ph_tagsset; /* mtags attached */
133 : u_int16_t ph_flowid; /* pseudo unique flow id */
134 : u_int16_t csum_flags; /* checksum flags */
135 : u_int16_t ether_vtag; /* Ethernet 802.1p+Q vlan tag */
136 : u_int ph_rtableid; /* routing table id */
137 : u_int ph_ifidx; /* rcv interface index */
138 : u_int8_t ph_loopcnt; /* mbuf is looping in kernel */
139 : u_int8_t ph_family; /* af, used when queueing */
140 : struct pkthdr_pf pf;
141 : };
142 :
143 : /* description of external storage mapped into mbuf, valid if M_EXT set */
144 : struct mbuf_ext {
145 : caddr_t ext_buf; /* start of buffer */
146 : void *ext_arg;
147 : u_int ext_free_fn; /* index of free function */
148 : u_int ext_size; /* size of buffer, for ext_free_fn */
149 : struct mbuf *ext_nextref;
150 : struct mbuf *ext_prevref;
151 : #ifdef DEBUG
152 : const char *ext_ofile;
153 : const char *ext_nfile;
154 : int ext_oline;
155 : int ext_nline;
156 : #endif
157 : };
158 :
159 : struct mbuf {
160 : struct m_hdr m_hdr;
161 : union {
162 : struct {
163 : struct pkthdr MH_pkthdr; /* M_PKTHDR set */
164 : union {
165 : struct mbuf_ext MH_ext; /* M_EXT set */
166 : char MH_databuf[MHLEN];
167 : } MH_dat;
168 : } MH;
169 : char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
170 : } M_dat;
171 : };
172 : #define m_next m_hdr.mh_next
173 : #define m_len m_hdr.mh_len
174 : #define m_data m_hdr.mh_data
175 : #define m_type m_hdr.mh_type
176 : #define m_flags m_hdr.mh_flags
177 : #define m_nextpkt m_hdr.mh_nextpkt
178 : #define m_pkthdr M_dat.MH.MH_pkthdr
179 : #define m_ext M_dat.MH.MH_dat.MH_ext
180 : #define m_pktdat M_dat.MH.MH_dat.MH_databuf
181 : #define m_dat M_dat.M_databuf
182 :
183 : /* mbuf flags */
184 : #define M_EXT 0x0001 /* has associated external storage */
185 : #define M_PKTHDR 0x0002 /* start of record */
186 : #define M_EOR 0x0004 /* end of record */
187 : #define M_EXTWR 0x0008 /* external storage is writable */
188 : #define M_PROTO1 0x0010 /* protocol-specific */
189 :
190 : /* mbuf pkthdr flags, also in m_flags */
191 : #define M_VLANTAG 0x0020 /* ether_vtag is valid */
192 : #define M_LOOP 0x0040 /* packet has been sent from local machine */
193 : #define M_ACAST 0x0080 /* received as IPv6 anycast */
194 : #define M_BCAST 0x0100 /* sent/received as link-level broadcast */
195 : #define M_MCAST 0x0200 /* sent/received as link-level multicast */
196 : #define M_CONF 0x0400 /* payload was encrypted (ESP-transport) */
197 : #define M_AUTH 0x0800 /* payload was authenticated (AH or ESP auth) */
198 : #define M_TUNNEL 0x1000 /* IP-in-IP added by tunnel mode IPsec */
199 : #define M_ZEROIZE 0x2000 /* Zeroize data part on free */
200 : #define M_COMP 0x4000 /* header was decompressed */
201 : #define M_LINK0 0x8000 /* link layer specific flag */
202 :
203 : #ifdef _KERNEL
204 : #define M_BITS \
205 : ("\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_EXTWR\5M_PROTO1\6M_VLANTAG\7M_LOOP" \
206 : "\10M_ACAST\11M_BCAST\12M_MCAST\13M_CONF\14M_AUTH\15M_TUNNEL" \
207 : "\16M_ZEROIZE\17M_COMP\20M_LINK0")
208 : #endif
209 :
210 : /* flags copied when copying m_pkthdr */
211 : #define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_BCAST|M_MCAST|M_CONF|M_COMP|\
212 : M_AUTH|M_LOOP|M_TUNNEL|M_LINK0|M_VLANTAG|M_ACAST|\
213 : M_ZEROIZE)
214 :
215 : /* Checksumming flags */
216 : #define M_IPV4_CSUM_OUT 0x0001 /* IPv4 checksum needed */
217 : #define M_TCP_CSUM_OUT 0x0002 /* TCP checksum needed */
218 : #define M_UDP_CSUM_OUT 0x0004 /* UDP checksum needed */
219 : #define M_IPV4_CSUM_IN_OK 0x0008 /* IPv4 checksum verified */
220 : #define M_IPV4_CSUM_IN_BAD 0x0010 /* IPv4 checksum bad */
221 : #define M_TCP_CSUM_IN_OK 0x0020 /* TCP checksum verified */
222 : #define M_TCP_CSUM_IN_BAD 0x0040 /* TCP checksum bad */
223 : #define M_UDP_CSUM_IN_OK 0x0080 /* UDP checksum verified */
224 : #define M_UDP_CSUM_IN_BAD 0x0100 /* UDP checksum bad */
225 : #define M_ICMP_CSUM_OUT 0x0200 /* ICMP/ICMPv6 checksum needed */
226 : #define M_ICMP_CSUM_IN_OK 0x0400 /* ICMP/ICMPv6 checksum verified */
227 : #define M_ICMP_CSUM_IN_BAD 0x0800 /* ICMP/ICMPv6 checksum bad */
228 : #define M_IPV6_DF_OUT 0x1000 /* don't fragment outgoing IPv6 */
229 :
230 : #ifdef _KERNEL
231 : #define MCS_BITS \
232 : ("\20\1IPV4_CSUM_OUT\2TCP_CSUM_OUT\3UDP_CSUM_OUT\4IPV4_CSUM_IN_OK" \
233 : "\5IPV4_CSUM_IN_BAD\6TCP_CSUM_IN_OK\7TCP_CSUM_IN_BAD\10UDP_CSUM_IN_OK" \
234 : "\11UDP_CSUM_IN_BAD\12ICMP_CSUM_OUT\13ICMP_CSUM_IN_OK\14ICMP_CSUM_IN_BAD" \
235 : "\15IPV6_NODF_OUT")
236 : #endif
237 :
238 : /* mbuf types */
239 : #define MT_FREE 0 /* should be on free list */
240 : #define MT_DATA 1 /* dynamic (data) allocation */
241 : #define MT_HEADER 2 /* packet header */
242 : #define MT_SONAME 3 /* socket name */
243 : #define MT_SOOPTS 4 /* socket options */
244 : #define MT_FTABLE 5 /* fragment reassembly header */
245 : #define MT_CONTROL 6 /* extra-data protocol message */
246 : #define MT_OOBDATA 7 /* expedited data */
247 : #define MT_NTYPES 8
248 :
249 : /* flowid field */
250 : #define M_FLOWID_VALID 0x8000 /* is the flowid set */
251 : #define M_FLOWID_MASK 0x7fff /* flow id to map to path */
252 :
253 : /* flags to m_get/MGET */
254 : #include <sys/malloc.h>
255 : #define M_DONTWAIT M_NOWAIT
256 : #define M_WAIT M_WAITOK
257 :
258 : /*
259 : * mbuf allocation/deallocation macros:
260 : *
261 : * MGET(struct mbuf *m, int how, int type)
262 : * allocates an mbuf and initializes it to contain internal data.
263 : *
264 : * MGETHDR(struct mbuf *m, int how, int type)
265 : * allocates an mbuf and initializes it to contain a packet header
266 : * and internal data.
267 : */
268 : #define MGET(m, how, type) m = m_get((how), (type))
269 :
270 : #define MGETHDR(m, how, type) m = m_gethdr((how), (type))
271 :
272 : /*
273 : * Macros for tracking external storage associated with an mbuf.
274 : */
275 : #ifdef DEBUG
276 : #define MCLREFDEBUGN(m, file, line) do { \
277 : (m)->m_ext.ext_nfile = (file); \
278 : (m)->m_ext.ext_nline = (line); \
279 : } while (/* CONSTCOND */ 0)
280 : #define MCLREFDEBUGO(m, file, line) do { \
281 : (m)->m_ext.ext_ofile = (file); \
282 : (m)->m_ext.ext_oline = (line); \
283 : } while (/* CONSTCOND */ 0)
284 : #else
285 : #define MCLREFDEBUGN(m, file, line)
286 : #define MCLREFDEBUGO(m, file, line)
287 : #endif
288 :
289 : #define MCLISREFERENCED(m) ((m)->m_ext.ext_nextref != (m))
290 :
291 : #define MCLADDREFERENCE(o, n) m_extref((o), (n))
292 :
293 : #define MCLINITREFERENCE(m) do { \
294 : (m)->m_ext.ext_prevref = (m); \
295 : (m)->m_ext.ext_nextref = (m); \
296 : MCLREFDEBUGO((m), __FILE__, __LINE__); \
297 : MCLREFDEBUGN((m), NULL, 0); \
298 : } while (/* CONSTCOND */ 0)
299 :
300 : /*
301 : * Macros for mbuf external storage.
302 : *
303 : * MEXTADD adds pre-allocated external storage to
304 : * a normal mbuf; the flag M_EXT is set.
305 : *
306 : * MCLGET allocates and adds an mbuf cluster to a normal mbuf;
307 : * the flag M_EXT is set upon success.
308 : */
309 : #define MEXTADD(m, buf, size, mflags, freefn, arg) do { \
310 : (m)->m_data = (m)->m_ext.ext_buf = (caddr_t)(buf); \
311 : (m)->m_flags |= M_EXT | (mflags & M_EXTWR); \
312 : (m)->m_ext.ext_size = (size); \
313 : (m)->m_ext.ext_free_fn = (freefn); \
314 : (m)->m_ext.ext_arg = (arg); \
315 : MCLINITREFERENCE(m); \
316 : } while (/* CONSTCOND */ 0)
317 :
318 : #define MCLGET(m, how) (void) m_clget((m), (how), MCLBYTES)
319 : #define MCLGETI(m, how, ifp, l) m_clget((m), (how), (l))
320 :
321 : u_int mextfree_register(void (*)(caddr_t, u_int, void *));
322 : #define MEXTFREE_POOL 0
323 :
324 : /*
325 : * Move just m_pkthdr from from to to,
326 : * remove M_PKTHDR and clean flags/tags for from.
327 : */
328 : #define M_MOVE_HDR(to, from) do { \
329 : (to)->m_pkthdr = (from)->m_pkthdr; \
330 : (from)->m_flags &= ~M_PKTHDR; \
331 : SLIST_INIT(&(from)->m_pkthdr.ph_tags); \
332 : (from)->m_pkthdr.pf.statekey = NULL; \
333 : } while (/* CONSTCOND */ 0)
334 :
335 : /*
336 : * MOVE mbuf pkthdr from from to to.
337 : * from must have M_PKTHDR set, and to must be empty.
338 : */
339 : #define M_MOVE_PKTHDR(to, from) do { \
340 : (to)->m_flags = ((to)->m_flags & (M_EXT | M_EXTWR)); \
341 : (to)->m_flags |= (from)->m_flags & M_COPYFLAGS; \
342 : M_MOVE_HDR((to), (from)); \
343 : if (((to)->m_flags & M_EXT) == 0) \
344 : (to)->m_data = (to)->m_pktdat; \
345 : } while (/* CONSTCOND */ 0)
346 :
347 : /*
348 : * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
349 : * an object of the specified size at the end of the mbuf, longword aligned.
350 : */
351 : #define M_ALIGN(m, len) \
352 : (m)->m_data += (MLEN - (len)) &~ (sizeof(long) - 1)
353 : /*
354 : * As above, for mbufs allocated with m_gethdr/MGETHDR
355 : * or initialized by M_MOVE_PKTHDR.
356 : */
357 : #define MH_ALIGN(m, len) \
358 : (m)->m_data += (MHLEN - (len)) &~ (sizeof(long) - 1)
359 :
360 : /*
361 : * Determine if an mbuf's data area is read-only. This is true for
362 : * non-cluster external storage and for clusters that are being
363 : * referenced by more than one mbuf.
364 : */
365 : #define M_READONLY(m) \
366 : (((m)->m_flags & M_EXT) != 0 && \
367 : (((m)->m_flags & M_EXTWR) == 0 || MCLISREFERENCED(m)))
368 :
369 : /*
370 : * Compute the amount of space available
371 : * before the current start of data in an mbuf.
372 : */
373 : #define M_LEADINGSPACE(m) m_leadingspace(m)
374 :
375 : /*
376 : * Compute the amount of space available
377 : * after the end of data in an mbuf.
378 : */
379 : #define M_TRAILINGSPACE(m) m_trailingspace(m)
380 :
381 : /*
382 : * Arrange to prepend space of size plen to mbuf m.
383 : * If a new mbuf must be allocated, how specifies whether to wait.
384 : * If how is M_DONTWAIT and allocation fails, the original mbuf chain
385 : * is freed and m is set to NULL.
386 : */
387 : #define M_PREPEND(m, plen, how) \
388 : (m) = m_prepend((m), (plen), (how))
389 :
390 : /* length to m_copy to copy all */
391 : #define M_COPYALL 1000000000
392 :
393 : /*
394 : * Mbuf statistics.
395 : * For statistics related to mbuf and cluster allocations, see also the
396 : * pool headers (mbpool and mclpool).
397 : */
398 : struct mbstat {
399 : u_long m_drops; /* times failed to find space */
400 : u_long m_wait; /* times waited for space */
401 : u_long m_drain; /* times drained protocols for space */
402 : u_short m_mtypes[256]; /* type specific mbuf allocations */
403 : };
404 :
405 : #define MBSTAT_TYPES MT_NTYPES
406 : #define MBSTAT_DROPS (MBSTAT_TYPES + 0)
407 : #define MBSTAT_WAIT (MBSTAT_TYPES + 1)
408 : #define MBSTAT_DRAIN (MBSTAT_TYPES + 2)
409 : #define MBSTAT_COUNT (MBSTAT_TYPES + 3)
410 :
411 : #include <sys/mutex.h>
412 :
413 : struct mbuf_list {
414 : struct mbuf *ml_head;
415 : struct mbuf *ml_tail;
416 : u_int ml_len;
417 : };
418 :
419 : struct mbuf_queue {
420 : struct mutex mq_mtx;
421 : struct mbuf_list mq_list;
422 : u_int mq_maxlen;
423 : u_int mq_drops;
424 : };
425 :
426 : #ifdef _KERNEL
427 : struct pool;
428 :
429 : extern int nmbclust; /* limit on the # of clusters */
430 : extern int mblowat; /* mbuf low water mark */
431 : extern int mcllowat; /* mbuf cluster low water mark */
432 : extern int max_linkhdr; /* largest link-level header */
433 : extern int max_protohdr; /* largest protocol header */
434 : extern int max_hdr; /* largest link+protocol header */
435 :
436 : void mbinit(void);
437 : void mbcpuinit(void);
438 : struct mbuf *m_copym(struct mbuf *, int, int, int);
439 : struct mbuf *m_free(struct mbuf *);
440 : struct mbuf *m_get(int, int);
441 : struct mbuf *m_getclr(int, int);
442 : struct mbuf *m_gethdr(int, int);
443 : struct mbuf *m_inithdr(struct mbuf *);
444 : void m_removehdr(struct mbuf *);
445 : void m_resethdr(struct mbuf *);
446 : void m_calchdrlen(struct mbuf *);
447 : int m_defrag(struct mbuf *, int);
448 : struct mbuf *m_prepend(struct mbuf *, int, int);
449 : struct mbuf *m_pulldown(struct mbuf *, int, int, int *);
450 : struct mbuf *m_pullup(struct mbuf *, int);
451 : struct mbuf *m_split(struct mbuf *, int, int);
452 : struct mbuf *m_makespace(struct mbuf *, int, int, int *);
453 : struct mbuf *m_getptr(struct mbuf *, int, int *);
454 : int m_leadingspace(struct mbuf *);
455 : int m_trailingspace(struct mbuf *);
456 : struct mbuf *m_clget(struct mbuf *, int, u_int);
457 : void m_extref(struct mbuf *, struct mbuf *);
458 : void m_pool_init(struct pool *, u_int, u_int, const char *);
459 : void m_extfree_pool(caddr_t, u_int, void *);
460 : void m_adj(struct mbuf *, int);
461 : int m_copyback(struct mbuf *, int, int, const void *, int);
462 : struct mbuf *m_freem(struct mbuf *);
463 : void m_purge(struct mbuf *);
464 : void m_reclaim(void *, int);
465 : void m_copydata(struct mbuf *, int, int, caddr_t);
466 : void m_cat(struct mbuf *, struct mbuf *);
467 : struct mbuf *m_devget(char *, int, int);
468 : int m_apply(struct mbuf *, int, int,
469 : int (*)(caddr_t, caddr_t, unsigned int), caddr_t);
470 : struct mbuf *m_dup_pkt(struct mbuf *, unsigned int, int);
471 : int m_dup_pkthdr(struct mbuf *, struct mbuf *, int);
472 :
473 : static inline struct mbuf *
474 0 : m_freemp(struct mbuf **mp)
475 : {
476 0 : struct mbuf *m = *mp;
477 :
478 0 : *mp = NULL;
479 0 : return m_freem(m);
480 : }
481 :
482 : /* Packet tag routines */
483 : struct m_tag *m_tag_get(int, int, int);
484 : void m_tag_prepend(struct mbuf *, struct m_tag *);
485 : void m_tag_delete(struct mbuf *, struct m_tag *);
486 : void m_tag_delete_chain(struct mbuf *);
487 : struct m_tag *m_tag_find(struct mbuf *, int, struct m_tag *);
488 : struct m_tag *m_tag_copy(struct m_tag *, int);
489 : int m_tag_copy_chain(struct mbuf *, struct mbuf *, int);
490 : void m_tag_init(struct mbuf *);
491 : struct m_tag *m_tag_first(struct mbuf *);
492 : struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
493 :
494 : /* Packet tag types */
495 : #define PACKET_TAG_IPSEC_IN_DONE 0x0001 /* IPsec applied, in */
496 : #define PACKET_TAG_IPSEC_OUT_DONE 0x0002 /* IPsec applied, out */
497 : #define PACKET_TAG_GIF 0x0040 /* GIF processing done */
498 : #define PACKET_TAG_GRE 0x0080 /* GRE processing done */
499 : #define PACKET_TAG_DLT 0x0100 /* data link layer type */
500 : #define PACKET_TAG_PF_DIVERT 0x0200 /* pf(4) diverted packet */
501 : #define PACKET_TAG_PF_REASSEMBLED 0x0800 /* pf reassembled ipv6 packet */
502 : #define PACKET_TAG_SRCROUTE 0x1000 /* IPv4 source routing options */
503 : #define PACKET_TAG_TUNNEL 0x2000 /* Tunnel endpoint address */
504 : #define PACKET_TAG_CARP_BAL_IP 0x4000 /* carp(4) ip balanced marker */
505 :
506 : #define MTAG_BITS \
507 : ("\20\1IPSEC_IN_DONE\2IPSEC_OUT_DONE\3IPSEC_IN_CRYPTO_DONE" \
508 : "\4IPSEC_OUT_CRYPTO_NEEDED\5IPSEC_PENDING_TDB\6BRIDGE\7GIF\10GRE\11DLT" \
509 : "\12PF_DIVERT\14PF_REASSEMBLED\15SRCROUTE\16TUNNEL\17CARP_BAL_IP")
510 :
511 : /*
512 : * Maximum tag payload length (that is excluding the m_tag structure).
513 : * Please make sure to update this value when increasing the payload
514 : * length for an existing packet tag type or when adding a new one that
515 : * has payload larger than the value below.
516 : */
517 : #define PACKET_TAG_MAXSIZE 60
518 :
519 : /* Detect mbufs looping in the kernel when spliced too often. */
520 : #define M_MAXLOOP 128
521 :
522 : /*
523 : * mbuf lists
524 : */
525 :
526 : #define MBUF_LIST_INITIALIZER() { NULL, NULL, 0 }
527 :
528 : void ml_init(struct mbuf_list *);
529 : void ml_enqueue(struct mbuf_list *, struct mbuf *);
530 : struct mbuf * ml_dequeue(struct mbuf_list *);
531 : void ml_enlist(struct mbuf_list *, struct mbuf_list *);
532 : struct mbuf * ml_dechain(struct mbuf_list *);
533 : unsigned int ml_purge(struct mbuf_list *);
534 :
535 : #define ml_len(_ml) ((_ml)->ml_len)
536 : #define ml_empty(_ml) ((_ml)->ml_len == 0)
537 :
538 : #define MBUF_LIST_FIRST(_ml) ((_ml)->ml_head)
539 : #define MBUF_LIST_NEXT(_m) ((_m)->m_nextpkt)
540 :
541 : #define MBUF_LIST_FOREACH(_ml, _m) \
542 : for ((_m) = MBUF_LIST_FIRST(_ml); \
543 : (_m) != NULL; \
544 : (_m) = MBUF_LIST_NEXT(_m))
545 :
546 : /*
547 : * mbuf queues
548 : */
549 :
550 : #define MBUF_QUEUE_INITIALIZER(_maxlen, _ipl) \
551 : { MUTEX_INITIALIZER(_ipl), MBUF_LIST_INITIALIZER(), (_maxlen), 0 }
552 :
553 : void mq_init(struct mbuf_queue *, u_int, int);
554 : int mq_enqueue(struct mbuf_queue *, struct mbuf *);
555 : struct mbuf * mq_dequeue(struct mbuf_queue *);
556 : int mq_enlist(struct mbuf_queue *, struct mbuf_list *);
557 : void mq_delist(struct mbuf_queue *, struct mbuf_list *);
558 : struct mbuf * mq_dechain(struct mbuf_queue *);
559 : unsigned int mq_purge(struct mbuf_queue *);
560 :
561 : #define mq_len(_mq) ml_len(&(_mq)->mq_list)
562 : #define mq_empty(_mq) ml_empty(&(_mq)->mq_list)
563 : #define mq_full(_mq) (mq_len((_mq)) >= (_mq)->mq_maxlen)
564 : #define mq_drops(_mq) ((_mq)->mq_drops)
565 : #define mq_set_maxlen(_mq, _l) ((_mq)->mq_maxlen = (_l))
566 :
567 : #endif /* _KERNEL */
568 : #endif /* _SYS_MBUF_H_ */
|