1/*- 2 * Copyright (c) 1982, 1986, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
| 1/*- 2 * Copyright (c) 1982, 1986, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
|
34 * $FreeBSD: head/sys/sys/mbuf.h 105530 2002-10-20 16:55:52Z phk $
| 34 * $FreeBSD: head/sys/sys/mbuf.h 108466 2002-12-30 20:22:40Z sam $
|
35 */ 36 37#ifndef _SYS_MBUF_H_ 38#define _SYS_MBUF_H_ 39 40#include <sys/_label.h> 41#include <sys/queue.h> 42 43/* 44 * Mbufs are of a single size, MSIZE (machine/param.h), which 45 * includes overhead. An mbuf may add a single "mbuf cluster" of size 46 * MCLBYTES (also in machine/param.h), which has no additional overhead 47 * and is used instead of the internal data area; this is done when 48 * at least MINCLSIZE of data must be stored. Additionally, it is possible 49 * to allocate a separate buffer externally and attach it to the mbuf in 50 * a way similar to that of mbuf clusters. 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#ifdef _KERNEL 58/*- 59 * Macros for type conversion: 60 * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type. 61 * dtom(x) -- Convert data pointer within mbuf to mbuf pointer (XXX). 62 */ 63#define mtod(m, t) ((t)((m)->m_data)) 64#define dtom(x) ((struct mbuf *)((intptr_t)(x) & ~(MSIZE-1))) 65#endif /* _KERNEL */ 66 67/* 68 * Header present at the beginning of every mbuf. 69 */ 70struct m_hdr { 71 struct mbuf *mh_next; /* next buffer in chain */ 72 struct mbuf *mh_nextpkt; /* next chain in queue/record */ 73 caddr_t mh_data; /* location of data */ 74 int mh_len; /* amount of data in this mbuf */ 75 int mh_flags; /* flags; see below */ 76 short mh_type; /* type of data in this mbuf */ 77}; 78 79/* 80 * Packet tag structure (see below for details). 81 */ 82struct m_tag { 83 SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */ 84 u_int16_t m_tag_id; /* Tag ID */ 85 u_int16_t m_tag_len; /* Length of data */ 86 u_int32_t m_tag_cookie; /* ABI/Module ID */ 87}; 88 89/* 90 * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set. 91 */ 92struct pkthdr { 93 struct ifnet *rcvif; /* rcv interface */ 94 int len; /* total packet length */ 95 /* variables for ip and tcp reassembly */ 96 void *header; /* pointer to packet header */ 97 /* variables for hardware checksum */ 98 int csum_flags; /* flags regarding checksum */ 99 int csum_data; /* data field used by csum routines */ 100 SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */ 101 struct label label; /* MAC label of data in packet */ 102}; 103 104/* 105 * Description of external storage mapped into mbuf; valid only if M_EXT is set. 106 */ 107struct m_ext { 108 caddr_t ext_buf; /* start of buffer */ 109 void (*ext_free) /* free routine if not the usual */ 110 (void *, void *); 111 void *ext_args; /* optional argument pointer */ 112 u_int ext_size; /* size of buffer, for ext_free */ 113 u_int *ref_cnt; /* pointer to ref count info */ 114 int ext_type; /* type of external storage */ 115}; 116 117/* 118 * The core of the mbuf object along with some shortcut defines for 119 * practical purposes. 120 */ 121struct mbuf { 122 struct m_hdr m_hdr; 123 union { 124 struct { 125 struct pkthdr MH_pkthdr; /* M_PKTHDR set */ 126 union { 127 struct m_ext MH_ext; /* M_EXT set */ 128 char MH_databuf[MHLEN]; 129 } MH_dat; 130 } MH; 131 char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */ 132 } M_dat; 133}; 134#define m_next m_hdr.mh_next 135#define m_len m_hdr.mh_len 136#define m_data m_hdr.mh_data 137#define m_type m_hdr.mh_type 138#define m_flags m_hdr.mh_flags 139#define m_nextpkt m_hdr.mh_nextpkt 140#define m_act m_nextpkt 141#define m_pkthdr M_dat.MH.MH_pkthdr 142#define m_ext M_dat.MH.MH_dat.MH_ext 143#define m_pktdat M_dat.MH.MH_dat.MH_databuf 144#define m_dat M_dat.M_databuf 145 146/* 147 * mbuf flags. 148 */ 149#define M_EXT 0x0001 /* has associated external storage */ 150#define M_PKTHDR 0x0002 /* start of record */ 151#define M_EOR 0x0004 /* end of record */ 152#define M_RDONLY 0x0008 /* associated data is marked read-only */ 153#define M_PROTO1 0x0010 /* protocol-specific */ 154#define M_PROTO2 0x0020 /* protocol-specific */ 155#define M_PROTO3 0x0040 /* protocol-specific */ 156#define M_PROTO4 0x0080 /* protocol-specific */ 157#define M_PROTO5 0x0100 /* protocol-specific */ 158 159/* 160 * mbuf pkthdr flags (also stored in m_flags). 161 */ 162#define M_BCAST 0x0200 /* send/received as link-level broadcast */ 163#define M_MCAST 0x0400 /* send/received as link-level multicast */ 164#define M_FRAG 0x0800 /* packet is a fragment of a larger packet */ 165#define M_FIRSTFRAG 0x1000 /* packet is first fragment */ 166#define M_LASTFRAG 0x2000 /* packet is last fragment */ 167 168/* 169 * External buffer types: identify ext_buf type. 170 */ 171#define EXT_CLUSTER 1 /* mbuf cluster */ 172#define EXT_SFBUF 2 /* sendfile(2)'s sf_bufs */ 173#define EXT_NET_DRV 100 /* custom ext_buf provided by net driver(s) */ 174#define EXT_MOD_TYPE 200 /* custom module's ext_buf type */ 175#define EXT_DISPOSABLE 300 /* can throw this buffer away w/page flipping */ 176 177/* 178 * Flags copied when copying m_pkthdr. 179 */
| 35 */ 36 37#ifndef _SYS_MBUF_H_ 38#define _SYS_MBUF_H_ 39 40#include <sys/_label.h> 41#include <sys/queue.h> 42 43/* 44 * Mbufs are of a single size, MSIZE (machine/param.h), which 45 * includes overhead. An mbuf may add a single "mbuf cluster" of size 46 * MCLBYTES (also in machine/param.h), which has no additional overhead 47 * and is used instead of the internal data area; this is done when 48 * at least MINCLSIZE of data must be stored. Additionally, it is possible 49 * to allocate a separate buffer externally and attach it to the mbuf in 50 * a way similar to that of mbuf clusters. 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#ifdef _KERNEL 58/*- 59 * Macros for type conversion: 60 * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type. 61 * dtom(x) -- Convert data pointer within mbuf to mbuf pointer (XXX). 62 */ 63#define mtod(m, t) ((t)((m)->m_data)) 64#define dtom(x) ((struct mbuf *)((intptr_t)(x) & ~(MSIZE-1))) 65#endif /* _KERNEL */ 66 67/* 68 * Header present at the beginning of every mbuf. 69 */ 70struct m_hdr { 71 struct mbuf *mh_next; /* next buffer in chain */ 72 struct mbuf *mh_nextpkt; /* next chain in queue/record */ 73 caddr_t mh_data; /* location of data */ 74 int mh_len; /* amount of data in this mbuf */ 75 int mh_flags; /* flags; see below */ 76 short mh_type; /* type of data in this mbuf */ 77}; 78 79/* 80 * Packet tag structure (see below for details). 81 */ 82struct m_tag { 83 SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */ 84 u_int16_t m_tag_id; /* Tag ID */ 85 u_int16_t m_tag_len; /* Length of data */ 86 u_int32_t m_tag_cookie; /* ABI/Module ID */ 87}; 88 89/* 90 * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set. 91 */ 92struct pkthdr { 93 struct ifnet *rcvif; /* rcv interface */ 94 int len; /* total packet length */ 95 /* variables for ip and tcp reassembly */ 96 void *header; /* pointer to packet header */ 97 /* variables for hardware checksum */ 98 int csum_flags; /* flags regarding checksum */ 99 int csum_data; /* data field used by csum routines */ 100 SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */ 101 struct label label; /* MAC label of data in packet */ 102}; 103 104/* 105 * Description of external storage mapped into mbuf; valid only if M_EXT is set. 106 */ 107struct m_ext { 108 caddr_t ext_buf; /* start of buffer */ 109 void (*ext_free) /* free routine if not the usual */ 110 (void *, void *); 111 void *ext_args; /* optional argument pointer */ 112 u_int ext_size; /* size of buffer, for ext_free */ 113 u_int *ref_cnt; /* pointer to ref count info */ 114 int ext_type; /* type of external storage */ 115}; 116 117/* 118 * The core of the mbuf object along with some shortcut defines for 119 * practical purposes. 120 */ 121struct mbuf { 122 struct m_hdr m_hdr; 123 union { 124 struct { 125 struct pkthdr MH_pkthdr; /* M_PKTHDR set */ 126 union { 127 struct m_ext MH_ext; /* M_EXT set */ 128 char MH_databuf[MHLEN]; 129 } MH_dat; 130 } MH; 131 char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */ 132 } M_dat; 133}; 134#define m_next m_hdr.mh_next 135#define m_len m_hdr.mh_len 136#define m_data m_hdr.mh_data 137#define m_type m_hdr.mh_type 138#define m_flags m_hdr.mh_flags 139#define m_nextpkt m_hdr.mh_nextpkt 140#define m_act m_nextpkt 141#define m_pkthdr M_dat.MH.MH_pkthdr 142#define m_ext M_dat.MH.MH_dat.MH_ext 143#define m_pktdat M_dat.MH.MH_dat.MH_databuf 144#define m_dat M_dat.M_databuf 145 146/* 147 * mbuf flags. 148 */ 149#define M_EXT 0x0001 /* has associated external storage */ 150#define M_PKTHDR 0x0002 /* start of record */ 151#define M_EOR 0x0004 /* end of record */ 152#define M_RDONLY 0x0008 /* associated data is marked read-only */ 153#define M_PROTO1 0x0010 /* protocol-specific */ 154#define M_PROTO2 0x0020 /* protocol-specific */ 155#define M_PROTO3 0x0040 /* protocol-specific */ 156#define M_PROTO4 0x0080 /* protocol-specific */ 157#define M_PROTO5 0x0100 /* protocol-specific */ 158 159/* 160 * mbuf pkthdr flags (also stored in m_flags). 161 */ 162#define M_BCAST 0x0200 /* send/received as link-level broadcast */ 163#define M_MCAST 0x0400 /* send/received as link-level multicast */ 164#define M_FRAG 0x0800 /* packet is a fragment of a larger packet */ 165#define M_FIRSTFRAG 0x1000 /* packet is first fragment */ 166#define M_LASTFRAG 0x2000 /* packet is last fragment */ 167 168/* 169 * External buffer types: identify ext_buf type. 170 */ 171#define EXT_CLUSTER 1 /* mbuf cluster */ 172#define EXT_SFBUF 2 /* sendfile(2)'s sf_bufs */ 173#define EXT_NET_DRV 100 /* custom ext_buf provided by net driver(s) */ 174#define EXT_MOD_TYPE 200 /* custom module's ext_buf type */ 175#define EXT_DISPOSABLE 300 /* can throw this buffer away w/page flipping */ 176 177/* 178 * Flags copied when copying m_pkthdr. 179 */
|
180#define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_PROTO1|M_PROTO2|M_PROTO3 | \ 181 M_PROTO4|M_PROTO5|M_BCAST|M_MCAST|M_FRAG|M_RDONLY)
| 180#define M_COPYFLAGS (M_PKTHDR|M_EOR|M_RDONLY|M_PROTO1|M_PROTO1|M_PROTO2|\ 181 M_PROTO3|M_PROTO4|M_PROTO5|M_BCAST|M_MCAST|\ 182 M_FRAG|M_FIRSTFRAG|M_LASTFRAG)
|
182 183/* 184 * Flags indicating hw checksum support and sw checksum requirements. 185 */ 186#define CSUM_IP 0x0001 /* will csum IP */ 187#define CSUM_TCP 0x0002 /* will csum TCP */ 188#define CSUM_UDP 0x0004 /* will csum UDP */ 189#define CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */ 190#define CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */ 191 192#define CSUM_IP_CHECKED 0x0100 /* did csum IP */ 193#define CSUM_IP_VALID 0x0200 /* ... the csum is valid */ 194#define CSUM_DATA_VALID 0x0400 /* csum_data field is valid */ 195#define CSUM_PSEUDO_HDR 0x0800 /* csum_data has pseudo hdr */ 196 197#define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP) 198#define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */ 199 200/* 201 * mbuf types. 202 */ 203#define MT_NOTMBUF 0 /* USED INTERNALLY ONLY! Object is not mbuf */ 204#define MT_DATA 1 /* dynamic (data) allocation */ 205#define MT_HEADER 2 /* packet header */ 206#if 0 207#define MT_SOCKET 3 /* socket structure */ 208#define MT_PCB 4 /* protocol control block */ 209#define MT_RTABLE 5 /* routing tables */ 210#define MT_HTABLE 6 /* IMP host tables */ 211#define MT_ATABLE 7 /* address resolution tables */ 212#endif 213#define MT_SONAME 8 /* socket name */ 214#if 0 215#define MT_SOOPTS 10 /* socket options */ 216#endif 217#define MT_FTABLE 11 /* fragment reassembly header */ 218#if 0 219#define MT_RIGHTS 12 /* access rights */ 220#define MT_IFADDR 13 /* interface address */ 221#endif 222#define MT_TAG 13 /* volatile metadata associated to pkts */ 223#define MT_CONTROL 14 /* extra-data protocol message */ 224#define MT_OOBDATA 15 /* expedited data */ 225#define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */ 226 227/* 228 * Mbuf and cluster allocation statistics PCPU structure. 229 */ 230struct mbpstat { 231 u_long mb_mbfree; 232 u_long mb_mbpgs; 233 u_long mb_clfree; 234 u_long mb_clpgs; 235 long mb_mbtypes[MT_NTYPES]; 236 short mb_active; 237}; 238 239/* 240 * General mbuf allocator statistics structure. 241 * XXX: Modifications of these are not protected by any mutex locks nor by 242 * any atomic() manipulations. As a result, we may occasionally lose 243 * a count or two. Luckily, not all of these fields are modified at all 244 * and remain static, and those that are manipulated are only manipulated 245 * in failure situations, which do not occur (hopefully) very often. 246 */ 247struct mbstat { 248 u_long m_drops; /* times failed to allocate */ 249 u_long m_wait; /* times succesfully returned from wait */ 250 u_long m_drain; /* times drained protocols for space */ 251 u_long m_mcfail; /* XXX: times m_copym failed */ 252 u_long m_mpfail; /* XXX: times m_pullup failed */ 253 u_long m_msize; /* length of an mbuf */ 254 u_long m_mclbytes; /* length of an mbuf cluster */ 255 u_long m_minclsize; /* min length of data to allocate a cluster */ 256 u_long m_mlen; /* length of data in an mbuf */ 257 u_long m_mhlen; /* length of data in a header mbuf */ 258 /* Number of mbtypes (gives # elems in mbpstat's mb_mbtypes[] array: */ 259 short m_numtypes; 260}; 261 262/* 263 * Flags specifying how an allocation should be made. 264 * M_DONTWAIT means "don't block if nothing is available" whereas 265 * M_TRYWAIT means "block for mbuf_wait ticks at most if nothing is 266 * available." 267 */ 268#define M_DONTWAIT 1 269#define M_TRYWAIT 0 270#define M_WAIT M_TRYWAIT /* XXX: Deprecated. */ 271 272#ifdef _KERNEL 273/*- 274 * mbuf external reference count management macros. 275 * 276 * MEXT_IS_REF(m): true if (m) is not the only mbuf referencing 277 * the external buffer ext_buf. 278 * 279 * MEXT_REM_REF(m): remove reference to m_ext object. 280 * 281 * MEXT_ADD_REF(m): add reference to m_ext object already 282 * referred to by (m). 283 */ 284#define MEXT_IS_REF(m) (*((m)->m_ext.ref_cnt) > 1) 285 286#define MEXT_REM_REF(m) do { \ 287 KASSERT(*((m)->m_ext.ref_cnt) > 0, ("m_ext refcnt < 0")); \ 288 atomic_subtract_int((m)->m_ext.ref_cnt, 1); \ 289} while(0) 290 291#define MEXT_ADD_REF(m) atomic_add_int((m)->m_ext.ref_cnt, 1) 292 293/* 294 * mbuf, cluster, and external object allocation macros 295 * (for compatibility purposes). 296 */
| 183 184/* 185 * Flags indicating hw checksum support and sw checksum requirements. 186 */ 187#define CSUM_IP 0x0001 /* will csum IP */ 188#define CSUM_TCP 0x0002 /* will csum TCP */ 189#define CSUM_UDP 0x0004 /* will csum UDP */ 190#define CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */ 191#define CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */ 192 193#define CSUM_IP_CHECKED 0x0100 /* did csum IP */ 194#define CSUM_IP_VALID 0x0200 /* ... the csum is valid */ 195#define CSUM_DATA_VALID 0x0400 /* csum_data field is valid */ 196#define CSUM_PSEUDO_HDR 0x0800 /* csum_data has pseudo hdr */ 197 198#define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP) 199#define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */ 200 201/* 202 * mbuf types. 203 */ 204#define MT_NOTMBUF 0 /* USED INTERNALLY ONLY! Object is not mbuf */ 205#define MT_DATA 1 /* dynamic (data) allocation */ 206#define MT_HEADER 2 /* packet header */ 207#if 0 208#define MT_SOCKET 3 /* socket structure */ 209#define MT_PCB 4 /* protocol control block */ 210#define MT_RTABLE 5 /* routing tables */ 211#define MT_HTABLE 6 /* IMP host tables */ 212#define MT_ATABLE 7 /* address resolution tables */ 213#endif 214#define MT_SONAME 8 /* socket name */ 215#if 0 216#define MT_SOOPTS 10 /* socket options */ 217#endif 218#define MT_FTABLE 11 /* fragment reassembly header */ 219#if 0 220#define MT_RIGHTS 12 /* access rights */ 221#define MT_IFADDR 13 /* interface address */ 222#endif 223#define MT_TAG 13 /* volatile metadata associated to pkts */ 224#define MT_CONTROL 14 /* extra-data protocol message */ 225#define MT_OOBDATA 15 /* expedited data */ 226#define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */ 227 228/* 229 * Mbuf and cluster allocation statistics PCPU structure. 230 */ 231struct mbpstat { 232 u_long mb_mbfree; 233 u_long mb_mbpgs; 234 u_long mb_clfree; 235 u_long mb_clpgs; 236 long mb_mbtypes[MT_NTYPES]; 237 short mb_active; 238}; 239 240/* 241 * General mbuf allocator statistics structure. 242 * XXX: Modifications of these are not protected by any mutex locks nor by 243 * any atomic() manipulations. As a result, we may occasionally lose 244 * a count or two. Luckily, not all of these fields are modified at all 245 * and remain static, and those that are manipulated are only manipulated 246 * in failure situations, which do not occur (hopefully) very often. 247 */ 248struct mbstat { 249 u_long m_drops; /* times failed to allocate */ 250 u_long m_wait; /* times succesfully returned from wait */ 251 u_long m_drain; /* times drained protocols for space */ 252 u_long m_mcfail; /* XXX: times m_copym failed */ 253 u_long m_mpfail; /* XXX: times m_pullup failed */ 254 u_long m_msize; /* length of an mbuf */ 255 u_long m_mclbytes; /* length of an mbuf cluster */ 256 u_long m_minclsize; /* min length of data to allocate a cluster */ 257 u_long m_mlen; /* length of data in an mbuf */ 258 u_long m_mhlen; /* length of data in a header mbuf */ 259 /* Number of mbtypes (gives # elems in mbpstat's mb_mbtypes[] array: */ 260 short m_numtypes; 261}; 262 263/* 264 * Flags specifying how an allocation should be made. 265 * M_DONTWAIT means "don't block if nothing is available" whereas 266 * M_TRYWAIT means "block for mbuf_wait ticks at most if nothing is 267 * available." 268 */ 269#define M_DONTWAIT 1 270#define M_TRYWAIT 0 271#define M_WAIT M_TRYWAIT /* XXX: Deprecated. */ 272 273#ifdef _KERNEL 274/*- 275 * mbuf external reference count management macros. 276 * 277 * MEXT_IS_REF(m): true if (m) is not the only mbuf referencing 278 * the external buffer ext_buf. 279 * 280 * MEXT_REM_REF(m): remove reference to m_ext object. 281 * 282 * MEXT_ADD_REF(m): add reference to m_ext object already 283 * referred to by (m). 284 */ 285#define MEXT_IS_REF(m) (*((m)->m_ext.ref_cnt) > 1) 286 287#define MEXT_REM_REF(m) do { \ 288 KASSERT(*((m)->m_ext.ref_cnt) > 0, ("m_ext refcnt < 0")); \ 289 atomic_subtract_int((m)->m_ext.ref_cnt, 1); \ 290} while(0) 291 292#define MEXT_ADD_REF(m) atomic_add_int((m)->m_ext.ref_cnt, 1) 293 294/* 295 * mbuf, cluster, and external object allocation macros 296 * (for compatibility purposes). 297 */
|
297#define M_COPY_PKTHDR(to, from) m_copy_pkthdr((to), (from))
| 298/* NB: M_COPY_PKTHDR is deprecated, use M_MOVE_PKTHDR or m_dup_pktdr */ 299#define M_MOVE_PKTHDR(to, from) m_move_pkthdr((to), (from))
|
298#define m_getclr(how, type) m_get_clrd((how), (type)) 299#define MGET(m, how, type) ((m) = m_get((how), (type))) 300#define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) 301#define MCLGET(m, how) m_clget((m), (how)) 302#define MEXTADD(m, buf, size, free, args, flags, type) \ 303 m_extadd((m), (caddr_t)(buf), (size), (free), (args), (flags), (type)) 304 305/* 306 * MEXTFREE(m): disassociate (and possibly free) an external object from (m). 307 * 308 * If the atomic_cmpset_int() returns 0, then we effectively do nothing 309 * in terms of "cleaning up" (freeing the ext buf and ref. counter) as 310 * this means that either there are still references, or another thread 311 * is taking care of the clean-up. 312 */ 313#define MEXTFREE(m) do { \ 314 struct mbuf *_mb = (m); \ 315 \ 316 MEXT_REM_REF(_mb); \ 317 if (atomic_cmpset_int(_mb->m_ext.ref_cnt, 0, 1)) \ 318 _mext_free(_mb); \ 319 _mb->m_flags &= ~M_EXT; \ 320} while (0) 321 322/* 323 * Evaluate TRUE if it's safe to write to the mbuf m's data region (this 324 * can be both the local data payload, or an external buffer area, 325 * depending on whether M_EXT is set). 326 */ 327#define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && (!((m)->m_flags \ 328 & M_EXT) || !MEXT_IS_REF(m))) 329 330/* 331 * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place 332 * an object of the specified size at the end of the mbuf, longword aligned. 333 */ 334#define M_ALIGN(m, len) do { \ 335 (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \ 336} while (0) 337 338/* 339 * As above, for mbufs allocated with m_gethdr/MGETHDR 340 * or initialized by M_COPY_PKTHDR. 341 */ 342#define MH_ALIGN(m, len) do { \ 343 (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \ 344} while (0) 345 346/* 347 * Compute the amount of space available 348 * before the current start of data in an mbuf. 349 * 350 * The M_WRITABLE() is a temporary, conservative safety measure: the burden 351 * of checking writability of the mbuf data area rests solely with the caller. 352 */ 353#define M_LEADINGSPACE(m) \ 354 ((m)->m_flags & M_EXT ? \ 355 (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \ 356 (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \ 357 (m)->m_data - (m)->m_dat) 358 359/* 360 * Compute the amount of space available 361 * after the end of data in an mbuf. 362 * 363 * The M_WRITABLE() is a temporary, conservative safety measure: the burden 364 * of checking writability of the mbuf data area rests solely with the caller. 365 */ 366#define M_TRAILINGSPACE(m) \ 367 ((m)->m_flags & M_EXT ? \ 368 (M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size \ 369 - ((m)->m_data + (m)->m_len) : 0) : \ 370 &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len)) 371 372/* 373 * Arrange to prepend space of size plen to mbuf m. 374 * If a new mbuf must be allocated, how specifies whether to wait. 375 * If the allocation fails, the original mbuf chain is freed and m is 376 * set to NULL. 377 */ 378#define M_PREPEND(m, plen, how) do { \ 379 struct mbuf **_mmp = &(m); \ 380 struct mbuf *_mm = *_mmp; \ 381 int _mplen = (plen); \ 382 int __mhow = (how); \ 383 \ 384 if (M_LEADINGSPACE(_mm) >= _mplen) { \ 385 _mm->m_data -= _mplen; \ 386 _mm->m_len += _mplen; \ 387 } else \ 388 _mm = m_prepend(_mm, _mplen, __mhow); \ 389 if (_mm != NULL && _mm->m_flags & M_PKTHDR) \ 390 _mm->m_pkthdr.len += _mplen; \ 391 *_mmp = _mm; \ 392} while (0) 393 394/* 395 * Change mbuf to new type. 396 * This is a relatively expensive operation and should be avoided. 397 */ 398#define MCHTYPE(m, t) m_chtype((m), (t)) 399 400/* Length to m_copy to copy all. */ 401#define M_COPYALL 1000000000 402 403/* Compatibility with 4.3. */ 404#define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT) 405 406extern int max_datalen; /* MHLEN - max_hdr */ 407extern int max_hdr; /* Largest link + protocol header */ 408extern int max_linkhdr; /* Largest link-level header */ 409extern int max_protohdr; /* Largest protocol header */ 410extern struct mbstat mbstat; /* General mbuf stats/infos */ 411extern int nmbclusters; /* Maximum number of clusters */ 412extern int nmbcnt; /* Scale kmem_map for counter space */ 413extern int nmbufs; /* Maximum number of mbufs */ 414extern int nsfbufs; /* Number of sendfile(2) bufs */ 415 416void _mext_free(struct mbuf *); 417void m_adj(struct mbuf *, int); 418void m_cat(struct mbuf *, struct mbuf *); 419void m_chtype(struct mbuf *, short); 420void m_clget(struct mbuf *, int); 421void m_extadd(struct mbuf *, caddr_t, u_int, 422 void (*)(void *, void *), void *, int, int); 423void m_copyback(struct mbuf *, int, int, caddr_t); 424void m_copydata(const struct mbuf *, int, int, caddr_t); 425struct mbuf *m_copym(struct mbuf *, int, int, int); 426struct mbuf *m_copypacket(struct mbuf *, int); 427void m_copy_pkthdr(struct mbuf *, struct mbuf *); 428struct mbuf *m_devget(char *, int, int, struct ifnet *, 429 void (*)(char *, caddr_t, u_int)); 430struct mbuf *m_dup(struct mbuf *, int);
| 300#define m_getclr(how, type) m_get_clrd((how), (type)) 301#define MGET(m, how, type) ((m) = m_get((how), (type))) 302#define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) 303#define MCLGET(m, how) m_clget((m), (how)) 304#define MEXTADD(m, buf, size, free, args, flags, type) \ 305 m_extadd((m), (caddr_t)(buf), (size), (free), (args), (flags), (type)) 306 307/* 308 * MEXTFREE(m): disassociate (and possibly free) an external object from (m). 309 * 310 * If the atomic_cmpset_int() returns 0, then we effectively do nothing 311 * in terms of "cleaning up" (freeing the ext buf and ref. counter) as 312 * this means that either there are still references, or another thread 313 * is taking care of the clean-up. 314 */ 315#define MEXTFREE(m) do { \ 316 struct mbuf *_mb = (m); \ 317 \ 318 MEXT_REM_REF(_mb); \ 319 if (atomic_cmpset_int(_mb->m_ext.ref_cnt, 0, 1)) \ 320 _mext_free(_mb); \ 321 _mb->m_flags &= ~M_EXT; \ 322} while (0) 323 324/* 325 * Evaluate TRUE if it's safe to write to the mbuf m's data region (this 326 * can be both the local data payload, or an external buffer area, 327 * depending on whether M_EXT is set). 328 */ 329#define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && (!((m)->m_flags \ 330 & M_EXT) || !MEXT_IS_REF(m))) 331 332/* 333 * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place 334 * an object of the specified size at the end of the mbuf, longword aligned. 335 */ 336#define M_ALIGN(m, len) do { \ 337 (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \ 338} while (0) 339 340/* 341 * As above, for mbufs allocated with m_gethdr/MGETHDR 342 * or initialized by M_COPY_PKTHDR. 343 */ 344#define MH_ALIGN(m, len) do { \ 345 (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \ 346} while (0) 347 348/* 349 * Compute the amount of space available 350 * before the current start of data in an mbuf. 351 * 352 * The M_WRITABLE() is a temporary, conservative safety measure: the burden 353 * of checking writability of the mbuf data area rests solely with the caller. 354 */ 355#define M_LEADINGSPACE(m) \ 356 ((m)->m_flags & M_EXT ? \ 357 (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \ 358 (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \ 359 (m)->m_data - (m)->m_dat) 360 361/* 362 * Compute the amount of space available 363 * after the end of data in an mbuf. 364 * 365 * The M_WRITABLE() is a temporary, conservative safety measure: the burden 366 * of checking writability of the mbuf data area rests solely with the caller. 367 */ 368#define M_TRAILINGSPACE(m) \ 369 ((m)->m_flags & M_EXT ? \ 370 (M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size \ 371 - ((m)->m_data + (m)->m_len) : 0) : \ 372 &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len)) 373 374/* 375 * Arrange to prepend space of size plen to mbuf m. 376 * If a new mbuf must be allocated, how specifies whether to wait. 377 * If the allocation fails, the original mbuf chain is freed and m is 378 * set to NULL. 379 */ 380#define M_PREPEND(m, plen, how) do { \ 381 struct mbuf **_mmp = &(m); \ 382 struct mbuf *_mm = *_mmp; \ 383 int _mplen = (plen); \ 384 int __mhow = (how); \ 385 \ 386 if (M_LEADINGSPACE(_mm) >= _mplen) { \ 387 _mm->m_data -= _mplen; \ 388 _mm->m_len += _mplen; \ 389 } else \ 390 _mm = m_prepend(_mm, _mplen, __mhow); \ 391 if (_mm != NULL && _mm->m_flags & M_PKTHDR) \ 392 _mm->m_pkthdr.len += _mplen; \ 393 *_mmp = _mm; \ 394} while (0) 395 396/* 397 * Change mbuf to new type. 398 * This is a relatively expensive operation and should be avoided. 399 */ 400#define MCHTYPE(m, t) m_chtype((m), (t)) 401 402/* Length to m_copy to copy all. */ 403#define M_COPYALL 1000000000 404 405/* Compatibility with 4.3. */ 406#define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT) 407 408extern int max_datalen; /* MHLEN - max_hdr */ 409extern int max_hdr; /* Largest link + protocol header */ 410extern int max_linkhdr; /* Largest link-level header */ 411extern int max_protohdr; /* Largest protocol header */ 412extern struct mbstat mbstat; /* General mbuf stats/infos */ 413extern int nmbclusters; /* Maximum number of clusters */ 414extern int nmbcnt; /* Scale kmem_map for counter space */ 415extern int nmbufs; /* Maximum number of mbufs */ 416extern int nsfbufs; /* Number of sendfile(2) bufs */ 417 418void _mext_free(struct mbuf *); 419void m_adj(struct mbuf *, int); 420void m_cat(struct mbuf *, struct mbuf *); 421void m_chtype(struct mbuf *, short); 422void m_clget(struct mbuf *, int); 423void m_extadd(struct mbuf *, caddr_t, u_int, 424 void (*)(void *, void *), void *, int, int); 425void m_copyback(struct mbuf *, int, int, caddr_t); 426void m_copydata(const struct mbuf *, int, int, caddr_t); 427struct mbuf *m_copym(struct mbuf *, int, int, int); 428struct mbuf *m_copypacket(struct mbuf *, int); 429void m_copy_pkthdr(struct mbuf *, struct mbuf *); 430struct mbuf *m_devget(char *, int, int, struct ifnet *, 431 void (*)(char *, caddr_t, u_int)); 432struct mbuf *m_dup(struct mbuf *, int);
|
| 433int m_dup_pkthdr(struct mbuf *, struct mbuf *, int);
|
431u_int m_fixhdr(struct mbuf *); 432struct mbuf *m_free(struct mbuf *); 433void m_freem(struct mbuf *); 434struct mbuf *m_get(int, short); 435struct mbuf *m_get_clrd(int, short); 436struct mbuf *m_getcl(int, short, int); 437struct mbuf *m_gethdr(int, short); 438struct mbuf *m_gethdr_clrd(int, short); 439struct mbuf *m_getm(struct mbuf *, int, int, short); 440u_int m_length(struct mbuf *, struct mbuf **);
| 434u_int m_fixhdr(struct mbuf *); 435struct mbuf *m_free(struct mbuf *); 436void m_freem(struct mbuf *); 437struct mbuf *m_get(int, short); 438struct mbuf *m_get_clrd(int, short); 439struct mbuf *m_getcl(int, short, int); 440struct mbuf *m_gethdr(int, short); 441struct mbuf *m_gethdr_clrd(int, short); 442struct mbuf *m_getm(struct mbuf *, int, int, short); 443u_int m_length(struct mbuf *, struct mbuf **);
|
| 444void m_move_pkthdr(struct mbuf *, struct mbuf *);
|
441struct mbuf *m_prepend(struct mbuf *, int, int); 442void m_print(const struct mbuf *); 443struct mbuf *m_pulldown(struct mbuf *, int, int, int *); 444struct mbuf *m_pullup(struct mbuf *, int); 445struct mbuf *m_split(struct mbuf *, int, int); 446 447/* 448 * Packets may have annotations attached by affixing a list 449 * of "packet tags" to the pkthdr structure. Packet tags are 450 * dynamically allocated semi-opaque data structures that have 451 * a fixed header (struct m_tag) that specifies the size of the 452 * memory block and a <cookie,type> pair that identifies it. 453 * The cookie is a 32-bit unique unsigned value used to identify 454 * a module or ABI. By convention this value is chose as the 455 * date+time that the module is created, expressed as the number of 456 * seconds since the epoch (e.g. using date -u +'%s'). The type value 457 * is an ABI/module-specific value that identifies a particular annotation 458 * and is private to the module. For compatibility with systems 459 * like openbsd that define packet tags w/o an ABI/module cookie, 460 * the value PACKET_ABI_COMPAT is used to implement m_tag_get and 461 * m_tag_find compatibility shim functions and several tag types are 462 * defined below. Users that do not require compatibility should use 463 * a private cookie value so that packet tag-related definitions 464 * can be maintained privately. 465 * 466 * Note that the packet tag returned by m_tag_allocate has the default 467 * memory alignment implemented by malloc. To reference private data 468 * one can use a construct like: 469 * 470 * struct m_tag *mtag = m_tag_allocate(...); 471 * struct foo *p = (struct foo *)(mtag+1); 472 * 473 * if the alignment of struct m_tag is sufficient for referencing members 474 * of struct foo. Otherwise it is necessary to embed struct m_tag within 475 * the private data structure to insure proper alignment; e.g. 476 * 477 * struct foo { 478 * struct m_tag tag; 479 * ... 480 * }; 481 * struct foo *p = (struct foo *) m_tag_allocate(...); 482 * struct m_tag *mtag = &p->tag; 483 */ 484 485#define PACKET_TAG_NONE 0 /* Nadda */ 486 487/* Packet tag for use with PACKET_ABI_COMPAT */ 488#define PACKET_TAG_IPSEC_IN_DONE 1 /* IPsec applied, in */ 489#define PACKET_TAG_IPSEC_OUT_DONE 2 /* IPsec applied, out */ 490#define PACKET_TAG_IPSEC_IN_CRYPTO_DONE 3 /* NIC IPsec crypto done */ 491#define PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED 4 /* NIC IPsec crypto req'ed */ 492#define PACKET_TAG_IPSEC_IN_COULD_DO_CRYPTO 5 /* NIC notifies IPsec */ 493#define PACKET_TAG_IPSEC_PENDING_TDB 6 /* Reminder to do IPsec */ 494#define PACKET_TAG_BRIDGE 7 /* Bridge processing done */ 495#define PACKET_TAG_GIF 8 /* GIF processing done */ 496#define PACKET_TAG_GRE 9 /* GRE processing done */ 497#define PACKET_TAG_IN_PACKET_CHECKSUM 10 /* NIC checksumming done */ 498#define PACKET_TAG_ENCAP 11 /* Encap. processing */ 499#define PACKET_TAG_IPSEC_SOCKET 12 /* IPSEC socket ref */ 500#define PACKET_TAG_IPSEC_HISTORY 13 /* IPSEC history */ 501#define PACKET_TAG_IPV6_INPUT 14 /* IPV6 input processing */ 502 503/* 504 * As a temporary and low impact solution to replace the even uglier 505 * approach used so far in some parts of the network stack (which relies 506 * on global variables), packet tag-like annotations are stored in MT_TAG 507 * mbufs (or lookalikes) prepended to the actual mbuf chain. 508 * 509 * m_type = MT_TAG 510 * m_flags = m_tag_id 511 * m_next = next buffer in chain. 512 * 513 * BE VERY CAREFUL not to pass these blocks to the mbuf handling routines. 514 */ 515#define _m_tag_id m_hdr.mh_flags 516 517/* Packet tags used in the FreeBSD network stack */ 518#define PACKET_TAG_DUMMYNET 15 /* dummynet info */ 519#define PACKET_TAG_IPFW 16 /* ipfw classification */ 520#define PACKET_TAG_DIVERT 17 /* divert info */ 521#define PACKET_TAG_IPFORWARD 18 /* ipforward info */ 522 523/* Packet tag routines */ 524struct m_tag *m_tag_alloc(u_int32_t, int, int, int); 525void m_tag_free(struct m_tag *); 526void m_tag_prepend(struct mbuf *, struct m_tag *); 527void m_tag_unlink(struct mbuf *, struct m_tag *); 528void m_tag_delete(struct mbuf *, struct m_tag *); 529void m_tag_delete_chain(struct mbuf *, struct m_tag *); 530struct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *);
| 445struct mbuf *m_prepend(struct mbuf *, int, int); 446void m_print(const struct mbuf *); 447struct mbuf *m_pulldown(struct mbuf *, int, int, int *); 448struct mbuf *m_pullup(struct mbuf *, int); 449struct mbuf *m_split(struct mbuf *, int, int); 450 451/* 452 * Packets may have annotations attached by affixing a list 453 * of "packet tags" to the pkthdr structure. Packet tags are 454 * dynamically allocated semi-opaque data structures that have 455 * a fixed header (struct m_tag) that specifies the size of the 456 * memory block and a <cookie,type> pair that identifies it. 457 * The cookie is a 32-bit unique unsigned value used to identify 458 * a module or ABI. By convention this value is chose as the 459 * date+time that the module is created, expressed as the number of 460 * seconds since the epoch (e.g. using date -u +'%s'). The type value 461 * is an ABI/module-specific value that identifies a particular annotation 462 * and is private to the module. For compatibility with systems 463 * like openbsd that define packet tags w/o an ABI/module cookie, 464 * the value PACKET_ABI_COMPAT is used to implement m_tag_get and 465 * m_tag_find compatibility shim functions and several tag types are 466 * defined below. Users that do not require compatibility should use 467 * a private cookie value so that packet tag-related definitions 468 * can be maintained privately. 469 * 470 * Note that the packet tag returned by m_tag_allocate has the default 471 * memory alignment implemented by malloc. To reference private data 472 * one can use a construct like: 473 * 474 * struct m_tag *mtag = m_tag_allocate(...); 475 * struct foo *p = (struct foo *)(mtag+1); 476 * 477 * if the alignment of struct m_tag is sufficient for referencing members 478 * of struct foo. Otherwise it is necessary to embed struct m_tag within 479 * the private data structure to insure proper alignment; e.g. 480 * 481 * struct foo { 482 * struct m_tag tag; 483 * ... 484 * }; 485 * struct foo *p = (struct foo *) m_tag_allocate(...); 486 * struct m_tag *mtag = &p->tag; 487 */ 488 489#define PACKET_TAG_NONE 0 /* Nadda */ 490 491/* Packet tag for use with PACKET_ABI_COMPAT */ 492#define PACKET_TAG_IPSEC_IN_DONE 1 /* IPsec applied, in */ 493#define PACKET_TAG_IPSEC_OUT_DONE 2 /* IPsec applied, out */ 494#define PACKET_TAG_IPSEC_IN_CRYPTO_DONE 3 /* NIC IPsec crypto done */ 495#define PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED 4 /* NIC IPsec crypto req'ed */ 496#define PACKET_TAG_IPSEC_IN_COULD_DO_CRYPTO 5 /* NIC notifies IPsec */ 497#define PACKET_TAG_IPSEC_PENDING_TDB 6 /* Reminder to do IPsec */ 498#define PACKET_TAG_BRIDGE 7 /* Bridge processing done */ 499#define PACKET_TAG_GIF 8 /* GIF processing done */ 500#define PACKET_TAG_GRE 9 /* GRE processing done */ 501#define PACKET_TAG_IN_PACKET_CHECKSUM 10 /* NIC checksumming done */ 502#define PACKET_TAG_ENCAP 11 /* Encap. processing */ 503#define PACKET_TAG_IPSEC_SOCKET 12 /* IPSEC socket ref */ 504#define PACKET_TAG_IPSEC_HISTORY 13 /* IPSEC history */ 505#define PACKET_TAG_IPV6_INPUT 14 /* IPV6 input processing */ 506 507/* 508 * As a temporary and low impact solution to replace the even uglier 509 * approach used so far in some parts of the network stack (which relies 510 * on global variables), packet tag-like annotations are stored in MT_TAG 511 * mbufs (or lookalikes) prepended to the actual mbuf chain. 512 * 513 * m_type = MT_TAG 514 * m_flags = m_tag_id 515 * m_next = next buffer in chain. 516 * 517 * BE VERY CAREFUL not to pass these blocks to the mbuf handling routines. 518 */ 519#define _m_tag_id m_hdr.mh_flags 520 521/* Packet tags used in the FreeBSD network stack */ 522#define PACKET_TAG_DUMMYNET 15 /* dummynet info */ 523#define PACKET_TAG_IPFW 16 /* ipfw classification */ 524#define PACKET_TAG_DIVERT 17 /* divert info */ 525#define PACKET_TAG_IPFORWARD 18 /* ipforward info */ 526 527/* Packet tag routines */ 528struct m_tag *m_tag_alloc(u_int32_t, int, int, int); 529void m_tag_free(struct m_tag *); 530void m_tag_prepend(struct mbuf *, struct m_tag *); 531void m_tag_unlink(struct mbuf *, struct m_tag *); 532void m_tag_delete(struct mbuf *, struct m_tag *); 533void m_tag_delete_chain(struct mbuf *, struct m_tag *); 534struct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *);
|
531struct m_tag *m_tag_copy(struct m_tag *); 532int m_tag_copy_chain(struct mbuf *, struct mbuf *);
| 535struct m_tag *m_tag_copy(struct m_tag *, int); 536int m_tag_copy_chain(struct mbuf *, struct mbuf *, int);
|
533void m_tag_init(struct mbuf *); 534struct m_tag *m_tag_first(struct mbuf *); 535struct m_tag *m_tag_next(struct mbuf *, struct m_tag *); 536 537/* these are for openbsd compatibility */ 538#define MTAG_ABI_COMPAT 0 /* compatibility ABI */ 539 540static __inline struct m_tag * 541m_tag_get(int type, int length, int wait) 542{ 543 return m_tag_alloc(MTAG_ABI_COMPAT, type, length, wait); 544} 545 546static __inline struct m_tag * 547m_tag_find(struct mbuf *m, int type, struct m_tag *start) 548{ 549 return m_tag_locate(m, MTAG_ABI_COMPAT, type, start); 550} 551#endif /* _KERNEL */ 552 553#endif /* !_SYS_MBUF_H_ */
| 537void m_tag_init(struct mbuf *); 538struct m_tag *m_tag_first(struct mbuf *); 539struct m_tag *m_tag_next(struct mbuf *, struct m_tag *); 540 541/* these are for openbsd compatibility */ 542#define MTAG_ABI_COMPAT 0 /* compatibility ABI */ 543 544static __inline struct m_tag * 545m_tag_get(int type, int length, int wait) 546{ 547 return m_tag_alloc(MTAG_ABI_COMPAT, type, length, wait); 548} 549 550static __inline struct m_tag * 551m_tag_find(struct mbuf *m, int type, struct m_tag *start) 552{ 553 return m_tag_locate(m, MTAG_ABI_COMPAT, type, start); 554} 555#endif /* _KERNEL */ 556 557#endif /* !_SYS_MBUF_H_ */
|