gonzui


Format: Advanced Search

t2ex/bsd_source/t2ex/network/net/src_bsd/sys/mbuf.hbare sourcepermlink (0.08 seconds)

Search this content:

    1: /*      $NetBSD: mbuf.h,v 1.144 2008/10/24 22:31:40 dyoung Exp $     */
    2: 
    3: /*-
    4:  * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
    5:  * All rights reserved.
    6:  *
    7:  * This code is derived from software contributed to The NetBSD Foundation
    8:  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
    9:  * NASA Ames Research Center and Matt Thomas of 3am Software Foundry.
   10:  *
   11:  * Redistribution and use in source and binary forms, with or without
   12:  * modification, are permitted provided that the following conditions
   13:  * are met:
   14:  * 1. Redistributions of source code must retain the above copyright
   15:  *    notice, this list of conditions and the following disclaimer.
   16:  * 2. Redistributions in binary form must reproduce the above copyright
   17:  *    notice, this list of conditions and the following disclaimer in the
   18:  *    documentation and/or other materials provided with the distribution.
   19:  *
   20:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   21:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   22:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   23:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   24:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   25:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   26:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   27:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   28:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   29:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   30:  * POSSIBILITY OF SUCH DAMAGE.
   31:  */
   32: 
   33: /*
   34:  * Copyright (c) 1982, 1986, 1988, 1993
   35:  *      The Regents of the University of California.  All rights reserved.
   36:  *
   37:  * Redistribution and use in source and binary forms, with or without
   38:  * modification, are permitted provided that the following conditions
   39:  * are met:
   40:  * 1. Redistributions of source code must retain the above copyright
   41:  *    notice, this list of conditions and the following disclaimer.
   42:  * 2. Redistributions in binary form must reproduce the above copyright
   43:  *    notice, this list of conditions and the following disclaimer in the
   44:  *    documentation and/or other materials provided with the distribution.
   45:  * 3. Neither the name of the University nor the names of its contributors
   46:  *    may be used to endorse or promote products derived from this software
   47:  *    without specific prior written permission.
   48:  *
   49:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   50:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   51:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   52:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   53:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   54:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   55:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   56:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   57:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   58:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   59:  * SUCH DAMAGE.
   60:  *
   61:  *      @(#)mbuf.h   8.5 (Berkeley) 2/19/95
   62:  */
   63: 
   64: #ifndef _SYS_MBUF_H_
   65: #define _SYS_MBUF_H_
   66: 
   67: #ifdef _KERNEL_OPT
   68: #include "opt_mbuftrace.h"
   69: #endif
   70: 
   71: #ifndef M_WAITOK
   72: #include <sys/malloc.h>
   73: #endif
   74: #include <sys/pool.h>
   75: #ifndef T2EX
   76: #include <sys/queue.h>
   77: #else
   78: #include <sys/_queue.h>
   79: #endif
   80: #if defined(_KERNEL)
   81: #include <sys/percpu_types.h>
   82: #endif /* defined(_KERNEL) */
   83: 
   84: /* For offsetof() */
   85: #if defined(_KERNEL) || defined(_STANDALONE)
   86: #include <sys/systm.h>
   87: #else
   88: #include <stddef.h>
   89: #endif
   90: #ifndef T2EX
   91: #include <uvm/uvm_param.h>      /* for MIN_PAGE_SIZE */
   92: #endif
   93: /*
   94:  * Mbufs are of a single size, MSIZE (machine/param.h), which
   95:  * includes overhead.  An mbuf may add a single "mbuf cluster" of size
   96:  * MCLBYTES (also in machine/param.h), which has no additional overhead
   97:  * and is used instead of the internal data area; this is done when
   98:  * at least MINCLSIZE of data must be stored.
   99:  */
  100: 
  101: /* Packet tags structure */
  102: struct m_tag {
  103:         SLIST_ENTRY(m_tag)     m_tag_link; /* List of packet tags */
  104:         uint16_t               m_tag_id;    /* Tag ID */
  105:         uint16_t               m_tag_len;   /* Length of data */
  106: };
  107: 
  108: /* mbuf ownership structure */
  109: struct mowner {
  110:         char mo_name[16];              /* owner name (fxp0) */
  111:         char mo_descr[16];             /* owner description (input) */
  112:         LIST_ENTRY(mowner) mo_link;    /* */
  113:         struct percpu *mo_counters;
  114: };
  115: 
  116: #define MOWNER_INIT(x, y) { .mo_name = x, .mo_descr = y }
  117: 
  118: enum mowner_counter_index {
  119:         MOWNER_COUNTER_CLAIMS,         /* # of small mbuf claimed */
  120:         MOWNER_COUNTER_RELEASES,       /* # of small mbuf released */
  121:         MOWNER_COUNTER_CLUSTER_CLAIMS, /* # of M_CLUSTER mbuf claimed */
  122:         MOWNER_COUNTER_CLUSTER_RELEASES,/* # of M_CLUSTER mbuf released */
  123:         MOWNER_COUNTER_EXT_CLAIMS,     /* # of M_EXT mbuf claimed */
  124:         MOWNER_COUNTER_EXT_RELEASES,   /* # of M_EXT mbuf released */
  125: 
  126:         MOWNER_COUNTER_NCOUNTERS,
  127: };
  128: 
  129: #if defined(_KERNEL)
  130: struct mowner_counter {
  131:         u_long mc_counter[MOWNER_COUNTER_NCOUNTERS];
  132: };
  133: #endif /* defined(_KERNEL) */
  134: 
  135: /* userland-exported version of struct mowner */
  136: struct mowner_user {
  137:         char mo_name[16];              /* owner name (fxp0) */
  138:         char mo_descr[16];             /* owner description (input) */
  139:         LIST_ENTRY(mowner) mo_link;    /* unused padding; for compatibility */
  140:         u_long mo_counter[MOWNER_COUNTER_NCOUNTERS]; /* counters */
  141: };
  142: 
  143: /*
  144:  * Macros for type conversion
  145:  * mtod(m,t) -  convert mbuf pointer to data pointer of correct type
  146:  */
  147: #define mtod(m, t)      ((t)((m)->m_data))
  148: 
  149: /* header at beginning of each mbuf: */
  150: struct m_hdr {
  151:         struct mbuf *mh_next;          /* next buffer in chain */
  152:         struct mbuf *mh_nextpkt;       /* next chain in queue/record */
  153:         char   *mh_data;               /* location of data */
  154:         struct mowner *mh_owner;       /* mbuf owner */
  155:         int    mh_len;                    /* amount of data in this mbuf */
  156:         int    mh_flags;          /* flags; see below */
  157:         paddr_t        mh_paddr;              /* physical address of mbuf */
  158:         short  mh_type;         /* type of data in this mbuf */
  159: };
  160: 
  161: /*
  162:  * record/packet header in first mbuf of chain; valid if M_PKTHDR set
  163:  *
  164:  * A note about csum_data: For the out-bound direction, the low 16 bits
  165:  * indicates the offset after the L4 header where the final L4 checksum value
  166:  * is to be stored and the high 16 bits is the length of the L3 header (the
  167:  * start of the data to be checksumed).  For the in-bound direction, it is only
  168:  * valid if the M_CSUM_DATA flag is set.  In this case, an L4 checksum has been
  169:  * calculated by hardware, but it is up to software to perform final
  170:  * verification.
  171:  *
  172:  * Note for in-bound TCP/UDP checksums, we expect the csum_data to NOT
  173:  * be bit-wise inverted (the final step in the calculation of an IP
  174:  * checksum) -- this is so we can accumulate the checksum for fragmented
  175:  * packets during reassembly.
  176:  */
  177: struct  pkthdr {
  178:         struct ifnet *rcvif;           /* rcv interface */
  179:         SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */
  180:         int    len;                       /* total packet length */
  181:         int    csum_flags;                /* checksum flags */
  182:         uint32_t csum_data;            /* checksum data */
  183:         u_int  segsz;                   /* segment size */
  184: };
  185: 
  186: /*
  187:  * Note: These bits are carefully arrange so that the compiler can have
  188:  * a prayer of generating a jump table.
  189:  */
  190: #define M_CSUM_TCPv4            0x00000001        /* TCP header/payload */
  191: #define M_CSUM_UDPv4            0x00000002        /* UDP header/payload */
  192: #define M_CSUM_TCP_UDP_BAD      0x00000004   /* TCP/UDP checksum bad */
  193: #define M_CSUM_DATA             0x00000008 /* consult csum_data */
  194: #define M_CSUM_TCPv6            0x00000010        /* IPv6 TCP header/payload */
  195: #define M_CSUM_UDPv6            0x00000020        /* IPv6 UDP header/payload */
  196: #define M_CSUM_IPv4             0x00000040 /* IPv4 header */
  197: #define M_CSUM_IPv4_BAD         0x00000080     /* IPv4 header checksum bad */
  198: #define M_CSUM_TSOv4            0x00000100        /* TCPv4 segmentation offload */
  199: #define M_CSUM_TSOv6            0x00000200        /* TCPv6 segmentation offload */
  200: 
  201: /* Checksum-assist quirks: keep separate from jump-table bits. */
  202: #define M_CSUM_NO_PSEUDOHDR     0x80000000  /* Rx csum_data does not include
  203:                                                  * the UDP/TCP pseudo-hdr, and
  204:                                                  * is not yet 1s-complemented.
  205:                                                  */
  206: 
  207: #define M_CSUM_BITS \
  208:     "\20\1TCPv4\2UDPv4\3TCP_UDP_BAD\4DATA\5TCPv6\6UDPv6\7IPv4\10IPv4_BAD" \
  209:     "\11TSOv4\12TSOv6\40NO_PSEUDOHDR"
  210: 
  211: /*
  212:  * Macros for manipulating csum_data on outgoing packets.  These are
  213:  * used to pass information down from the L4/L3 to the L2.
  214:  */
  215: #define M_CSUM_DATA_IPv4_IPHL(x)        ((x) >> 16)
  216: #define M_CSUM_DATA_IPv4_OFFSET(x)      ((x) & 0xffff)
  217: 
  218: /*
  219:  * Macros for M_CSUM_TCPv6 and M_CSUM_UDPv6
  220:  *
  221:  * M_CSUM_DATA_IPv6_HL: length of ip6_hdr + ext header.
  222:  * ie. offset of UDP/TCP header in the packet.
  223:  *
  224:  * M_CSUM_DATA_IPv6_OFFSET: offset of the checksum field in UDP/TCP header. 
  225:  */
  226: 
  227: #define M_CSUM_DATA_IPv6_HL(x)          ((x) >> 16)
  228: #define M_CSUM_DATA_IPv6_HL_SET(x, v)   (x) = ((x) & 0xffff) | ((v) << 16)
  229: #define M_CSUM_DATA_IPv6_OFFSET(x)      ((x) & 0xffff)
  230: 
  231: /*
  232:  * Max # of pages we can attach to m_ext.  This is carefully chosen
  233:  * to be able to handle SOSEND_LOAN_CHUNK with our minimum sized page.
  234:  */
  235: #ifdef MIN_PAGE_SIZE
  236: #define M_EXT_MAXPAGES          ((65536 / MIN_PAGE_SIZE) + 1)
  237: #endif
  238: 
  239: /* description of external storage mapped into mbuf, valid if M_EXT set */
  240: struct _m_ext_storage {
  241:         unsigned int ext_refcnt;
  242:         int ext_flags;
  243:         char *ext_buf;                 /* start of buffer */
  244:         void (*ext_free)               /* free routine if not the usual */
  245:                 (struct mbuf *, void *, size_t, void *);
  246:         void *ext_arg;                 /* argument for ext_free */
  247:         size_t ext_size;               /* size of buffer, for ext_free */
  248: #ifndef T2EX
  249:         struct malloc_type *ext_type;  /* malloc type */
  250: #endif
  251:         union {
  252:                 paddr_t extun_paddr;  /* physical address (M_EXT_CLUSTER) */
  253:                                         /* pages (M_EXT_PAGES) */
  254:         /*
  255:          * XXX This is gross, but it doesn't really matter; this is
  256:          * XXX overlaid on top of the mbuf data area.
  257:          */
  258: #ifdef M_EXT_MAXPAGES
  259:                 struct vm_page *extun_pgs[M_EXT_MAXPAGES];
  260: #endif
  261:         } ext_un;
  262: #define ext_paddr       ext_un.extun_paddr
  263: #define ext_pgs         ext_un.extun_pgs
  264: #ifdef DEBUG
  265:         const char *ext_ofile;
  266:         const char *ext_nfile;
  267:         int ext_oline;
  268:         int ext_nline;
  269: #endif
  270: };
  271: 
  272: struct _m_ext {
  273:         struct mbuf *ext_ref;
  274:         struct _m_ext_storage ext_storage;
  275: };
  276: 
  277: #define M_PADDR_INVALID         POOL_PADDR_INVALID
  278: 
  279: /*
  280:  * Definition of "struct mbuf".
  281:  * Don't change this without understanding how MHLEN/MLEN are defined.
  282:  */
  283: #define MBUF_DEFINE(name, mhlen, mlen)                                  \
  284:         struct name {                                                  \
  285:                 struct        m_hdr m_hdr;                                   \
  286:                 union {                                                       \
  287:                         struct {                                     \
  288:                                 struct      pkthdr MH_pkthdr;            \
  289:                                 union {                                     \
  290:                                         struct     _m_ext MH_ext;              \
  291:                                         char MH_databuf[(mhlen)];  \
  292:                                 } MH_dat;                           \
  293:                         } MH;                                                \
  294:                         char M_databuf[(mlen)];                              \
  295:                 } M_dat;                                              \
  296:         }
  297: #define m_next          m_hdr.mh_next
  298: #define m_len           m_hdr.mh_len
  299: #define m_data          m_hdr.mh_data
  300: #define m_owner         m_hdr.mh_owner
  301: #define m_type          m_hdr.mh_type
  302: #define m_flags         m_hdr.mh_flags
  303: #define m_nextpkt       m_hdr.mh_nextpkt
  304: #define m_paddr         m_hdr.mh_paddr
  305: #define m_pkthdr        M_dat.MH.MH_pkthdr
  306: #define m_ext_storage   M_dat.MH.MH_dat.MH_ext.ext_storage
  307: #define m_ext_ref       M_dat.MH.MH_dat.MH_ext.ext_ref
  308: #define m_ext           m_ext_ref->m_ext_storage
  309: #define m_pktdat        M_dat.MH.MH_dat.MH_databuf
  310: #define m_dat           M_dat.M_databuf
  311: 
  312: /*
  313:  * Dummy mbuf structure to calculate the right values for MLEN/MHLEN, taking
  314:  * into account inter-structure padding.
  315:  */
  316: MBUF_DEFINE(_mbuf_dummy, 1, 1);
  317: 
  318: /* normal data len */
  319: #define MLEN            (MSIZE - offsetof(struct _mbuf_dummy, m_dat))
  320: /* data len w/pkthdr */
  321: #define MHLEN           (MSIZE - offsetof(struct _mbuf_dummy, m_pktdat))
  322: 
  323: #define MINCLSIZE       (MHLEN+MLEN+1)        /* smallest amount to put in cluster */
  324: #define M_MAXCOMPRESS   (MHLEN / 2)       /* max amount to copy for compression */
  325: 
  326: /*
  327:  * The *real* struct mbuf
  328:  */
  329: MBUF_DEFINE(mbuf, MHLEN, MLEN);
  330: 
  331: /* mbuf flags */
  332: #define M_EXT           0x00001  /* has associated external storage */
  333: #define M_PKTHDR        0x00002        /* start of record */
  334: #define M_EOR           0x00004  /* end of record */
  335: #define M_PROTO1        0x00008        /* protocol-specific */
  336: 
  337: /* mbuf pkthdr flags, also in m_flags */
  338: #define M_AUTHIPHDR     0x00010     /* data origin authentication for IP header */
  339: #define M_DECRYPTED     0x00020     /* confidentiality */
  340: #define M_LOOP          0x00040 /* for Mbuf statistics */
  341: #define M_AUTHIPDGM     0x00080  /* data origin authentication */
  342: #define M_BCAST         0x00100        /* send/received as link-level broadcast */
  343: #define M_MCAST         0x00200        /* send/received as link-level multicast */
  344: #define M_CANFASTFWD    0x00400    /* used by filters to indicate packet can
  345:                                    be fast-forwarded */
  346: #define M_ANYCAST6      0x00800      /* received as IPv6 anycast */
  347: #define M_LINK0         0x01000        /* link layer specific flag */
  348: #define M_LINK1         0x02000        /* link layer specific flag */
  349: #define M_LINK2         0x04000        /* link layer specific flag */
  350: #define M_LINK3         0x08000        /* link layer specific flag */
  351: #define M_LINK4         0x10000        /* link layer specific flag */
  352: #define M_LINK5         0x20000        /* link layer specific flag */
  353: #define M_LINK6         0x40000        /* link layer specific flag */
  354: #define M_LINK7         0x80000        /* link layer specific flag */
  355: 
  356: /* additional flags for M_EXT mbufs */
  357: #define M_EXT_FLAGS     0xff000000
  358: #define M_EXT_CLUSTER   0x01000000        /* ext is a cluster */
  359: #define M_EXT_PAGES     0x02000000  /* ext_pgs is valid */
  360: #define M_EXT_ROMAP     0x04000000  /* ext mapping is r-o at MMU */
  361: #define M_EXT_RW        0x08000000     /* ext storage is writable */
  362: 
  363: /* for source-level compatibility */
  364: #define M_CLUSTER       M_EXT_CLUSTER
  365: 
  366: #define M_FLAGS_BITS \
  367:     "\20\1EXT\2PKTHDR\3EOR\4PROTO1\5AUTHIPHDR\6DECRYPTED\7LOOP\10AUTHIPDGM" \
  368:     "\11BCAST\12MCAST\13CANFASTFWD\14ANYCAST6\15LINK0\16LINK1\17LINK2\20LINK3" \
  369:     "\21LINK4\22LINK5\23LINK6\24LINK7" \
  370:     "\31EXT_CLUSTER\32EXT_PAGES\33EXT_ROMAP\34EXT_RW"
  371: 
  372: /* flags copied when copying m_pkthdr */
  373: #define M_COPYFLAGS     (M_PKTHDR|M_EOR|M_BCAST|M_MCAST|M_CANFASTFWD|M_ANYCAST6|M_LINK0|M_LINK1|M_LINK2|M_AUTHIPHDR|M_DECRYPTED|M_LOOP|M_AUTHIPDGM)
  374: 
  375: /* flag copied when shallow-copying external storage */
  376: #define M_EXTCOPYFLAGS  (M_EXT|M_EXT_FLAGS)
  377: 
  378: /* mbuf types */
  379: #define MT_FREE         0      /* should be on free list */
  380: #define MT_DATA         1      /* dynamic (data) allocation */
  381: #define MT_HEADER       2     /* packet header */
  382: #define MT_SONAME       3     /* socket name */
  383: #define MT_SOOPTS       4     /* socket options */
  384: #define MT_FTABLE       5     /* fragment reassembly header */
  385: #define MT_CONTROL      6    /* extra-data protocol message */
  386: #define MT_OOBDATA      7    /* expedited data  */
  387: 
  388: /* flags to m_get/MGET */
  389: #define M_DONTWAIT      M_NOWAIT
  390: #define M_WAIT          M_WAITOK
  391: 
  392: #ifdef MBUFTRACE
  393: /*
  394:  * mbuf allocation tracing
  395:  */
  396: void mowner_init(struct mbuf *, int);
  397: void mowner_ref(struct mbuf *, int);
  398: void m_claim(struct mbuf *, struct mowner *);
  399: void mowner_revoke(struct mbuf *, bool, int);
  400: #ifndef T2EX
  401: void mowner_attach(struct mowner *);
  402: #else
  403: int mowner_attach(struct mowner *);
  404: #endif
  405: void mowner_detach(struct mowner *);
  406: void m_claimm(struct mbuf *, struct mowner *);
  407: #else
  408: #define mowner_init(m, type)            do { } while (/* CONSTCOND */ 0)
  409: #define mowner_ref(m, flags)            do { } while (/* CONSTCOND */ 0)
  410: #define mowner_revoke(m, all, flags)    do { } while (/* CONSTCOND */ 0)
  411: #define m_claim(m, mowner)              do { } while (/* CONSTCOND */ 0)
  412: #ifndef T2EX
  413: #define mowner_attach(mo)               do { } while (/* CONSTCOND */ 0)
  414: #else
  415: #define mowner_attach(mo)               0
  416: #endif
  417: #define mowner_detach(mo)               do { } while (/* CONSTCOND */ 0)
  418: #define m_claimm(m, mo)                 do { } while (/* CONSTCOND */ 0)
  419: #endif
  420: 
  421: #define MCLAIM(m, mo)           m_claim((m), (mo))
  422: #define MOWNER_ATTACH(mo)       mowner_attach(mo)
  423: #define MOWNER_DETACH(mo)       mowner_detach(mo)
  424: 
  425: /*
  426:  * mbuf allocation/deallocation macros:
  427:  *
  428:  *      MGET(struct mbuf *m, int how, int type)
  429:  * allocates an mbuf and initializes it to contain internal data.
  430:  *
  431:  *      MGETHDR(struct mbuf *m, int how, int type)
  432:  * allocates an mbuf and initializes it to contain a packet header
  433:  * and internal data.
  434:  *
  435:  * If 'how' is M_WAIT, these macros (and the corresponding functions)
  436:  * are guaranteed to return successfully.
  437:  */
  438: #define MGET(m, how, type)      m = m_get((how), (type))
  439: #define MGETHDR(m, how, type)   m = m_gethdr((how), (type))
  440: 
  441: #if defined(_KERNEL)
  442: #define _M_
  443: /*
  444:  * Macros for tracking external storage associated with an mbuf.
  445:  */
  446: #ifdef DEBUG
  447: #define MCLREFDEBUGN(m, file, line)                                     \
  448: do {                                                                    \
  449:         (m)->m_ext.ext_nfile = (file);                                 \
  450:         (m)->m_ext.ext_nline = (line);                                 \
  451: } while (/* CONSTCOND */ 0)
  452: 
  453: #define MCLREFDEBUGO(m, file, line)                                     \
  454: do {                                                                    \
  455:         (m)->m_ext.ext_ofile = (file);                                 \
  456:         (m)->m_ext.ext_oline = (line);                                 \
  457: } while (/* CONSTCOND */ 0)
  458: #else
  459: #define MCLREFDEBUGN(m, file, line)
  460: #define MCLREFDEBUGO(m, file, line)
  461: #endif
  462: 
  463: #define MCLINITREFERENCE(m)                                             \
  464: do {                                                                    \
  465:         KDASSERT(((m)->m_flags & M_EXT) == 0);                         \
  466:         (m)->m_ext_ref = (m);                                          \
  467:         (m)->m_ext.ext_refcnt = 1;                                     \
  468:         MCLREFDEBUGO((m), __FILE__, __LINE__);                         \
  469:         MCLREFDEBUGN((m), NULL, 0);                                    \
  470: } while (/* CONSTCOND */ 0)
  471: 
  472: /*
  473:  * Macros for mbuf external storage.
  474:  *
  475:  * MCLGET allocates and adds an mbuf cluster to a normal mbuf;
  476:  * the flag M_EXT is set upon success.
  477:  *
  478:  * MEXTMALLOC allocates external storage and adds it to
  479:  * a normal mbuf; the flag M_EXT is set upon success.
  480:  *
  481:  * MEXTADD adds pre-allocated external storage to
  482:  * a normal mbuf; the flag M_EXT is set upon success.
  483:  */
  484: 
  485: #define _MCLGET(m, pool_cache, size, how)                               \
  486: do {                                                                    \
  487:         (m)->m_ext_storage.ext_buf =                                   \
  488:             pool_cache_get_paddr((pool_cache),                         \
  489:                 (how) == M_WAIT ? (PR_WAITOK|PR_LIMITFAIL) : 0,               \
  490:                 &(m)->m_ext_storage.ext_paddr);                               \
  491:         if ((m)->m_ext_storage.ext_buf != NULL) {                      \
  492:                 MCLINITREFERENCE(m);                                  \
  493:                 (m)->m_data = (m)->m_ext.ext_buf;                     \
  494:                 (m)->m_flags = ((m)->m_flags & ~M_EXTCOPYFLAGS) |     \
  495:                                 M_EXT|M_CLUSTER|M_EXT_RW;           \
  496:                 (m)->m_ext.ext_flags = 0;                             \
  497:                 (m)->m_ext.ext_size = (size);                         \
  498:                 (m)->m_ext.ext_free = NULL;                           \
  499:                 (m)->m_ext.ext_arg = (pool_cache);                    \
  500:                 /* ext_paddr initialized above */                     \
  501:                 mowner_ref((m), M_EXT|M_CLUSTER);                     \
  502:         }                                                              \
  503: } while (/* CONSTCOND */ 0)
  504: 
  505: /*
  506:  * The standard mbuf cluster pool.
  507:  */
  508: #define MCLGET(m, how)  _MCLGET((m), mcl_cache, MCLBYTES, (how))
  509: 
  510: #ifndef T2EX
  511: 
  512: #define MEXTMALLOC(m, size, how)                                        \
  513: do {                                                                    \
  514:         (m)->m_ext_storage.ext_buf =                                   \
  515:             (void *)malloc((size), mbtypes[(m)->m_type], (how));       \
  516:         if ((m)->m_ext_storage.ext_buf != NULL) {                      \
  517:                 MCLINITREFERENCE(m);                                  \
  518:                 (m)->m_data = (m)->m_ext.ext_buf;                     \
  519:                 (m)->m_flags = ((m)->m_flags & ~M_EXTCOPYFLAGS) |     \
  520:                                 M_EXT|M_EXT_RW;                             \
  521:                 (m)->m_ext.ext_flags = 0;                             \
  522:                 (m)->m_ext.ext_size = (size);                         \
  523:                 (m)->m_ext.ext_free = NULL;                           \
  524:                 (m)->m_ext.ext_arg = NULL;                            \
  525:                 (m)->m_ext.ext_type = mbtypes[(m)->m_type];           \
  526:                 mowner_ref((m), M_EXT);                                       \
  527:         }                                                              \
  528: } while (/* CONSTCOND */ 0)
  529: 
  530: #define MEXTADD(m, buf, size, type, free, arg)                          \
  531: do {                                                                    \
  532:         MCLINITREFERENCE(m);                                           \
  533:         (m)->m_data = (m)->m_ext.ext_buf = (void *)(buf);              \
  534:         (m)->m_flags = ((m)->m_flags & ~M_EXTCOPYFLAGS) | M_EXT;       \
  535:         (m)->m_ext.ext_flags = 0;                                      \
  536:         (m)->m_ext.ext_size = (size);                                  \
  537:         (m)->m_ext.ext_free = (void (*)(struct mbuf *, void *, size_t, void *))(free);                                 \
  538:         (m)->m_ext.ext_arg = (arg);                                    \
  539:         (m)->m_ext.ext_type = (type);                                  \
  540:         mowner_ref((m), M_EXT);                                                \
  541: } while (/* CONSTCOND */ 0)
  542: 
  543: #else /* T2EX */
  544: 
  545: #define MEXTMALLOC(m, size, how)                                        \
  546: do {                                                                    \
  547:         (m)->m_ext_storage.ext_buf =                                   \
  548:             (void *)malloc((size), mbtypes[(m)->m_type], (how));       \
  549:         if ((m)->m_ext_storage.ext_buf != NULL) {                      \
  550:                 MCLINITREFERENCE(m);                                  \
  551:                 (m)->m_data = (m)->m_ext.ext_buf;                     \
  552:                 (m)->m_flags = ((m)->m_flags & ~M_EXTCOPYFLAGS) |     \
  553:                                 M_EXT|M_EXT_RW;                             \
  554:                 (m)->m_ext.ext_flags = 0;                             \
  555:                 (m)->m_ext.ext_size = (size);                         \
  556:                 (m)->m_ext.ext_free = NULL;                           \
  557:                 (m)->m_ext.ext_arg = NULL;                            \
  558:                 mowner_ref((m), M_EXT);                                       \
  559:         }                                                              \
  560: } while (/* CONSTCOND */ 0)
  561: 
  562: #define MEXTADD(m, buf, size, type, free, arg)                          \
  563: do {                                                                    \
  564:         MCLINITREFERENCE(m);                                           \
  565:         (m)->m_data = (m)->m_ext.ext_buf = (void *)(buf);              \
  566:         (m)->m_flags = ((m)->m_flags & ~M_EXTCOPYFLAGS) | M_EXT;       \
  567:         (m)->m_ext.ext_flags = 0;                                      \
  568:         (m)->m_ext.ext_size = (size);                                  \
  569:         (m)->m_ext.ext_free = (void (*)(struct mbuf *, void *, size_t, void *))(free);                                 \
  570:         (m)->m_ext.ext_arg = (arg);                                    \
  571:         mowner_ref((m), M_EXT);                                                \
  572: } while (/* CONSTCOND */ 0)
  573: 
  574: #endif
  575: 
  576: /*
  577:  * Reset the data pointer on an mbuf.
  578:  */
  579: #define MRESETDATA(m)                                                   \
  580: do {                                                                    \
  581:         if ((m)->m_flags & M_EXT)                                      \
  582:                 (m)->m_data = (m)->m_ext.ext_buf;                     \
  583:         else if ((m)->m_flags & M_PKTHDR)                              \
  584:                 (m)->m_data = (m)->m_pktdat;                          \
  585:         else                                                           \
  586:                 (m)->m_data = (m)->m_dat;                             \
  587: } while (/* CONSTCOND */ 0)
  588: 
  589: /*
  590:  * MFREE(struct mbuf *m, struct mbuf *n)
  591:  * Free a single mbuf and associated external storage.
  592:  * Place the successor, if any, in n.
  593:  */
  594: #define MFREE(m, n)                                                     \
  595:         mowner_revoke((m), 1, (m)->m_flags);                           \
  596:         mbstat_type_add((m)->m_type, -1);                              \
  597:         if ((m)->m_flags & M_PKTHDR)                                   \
  598:                 m_tag_delete_chain((m), NULL);                                \
  599:         (n) = (m)->m_next;                                             \
  600:         if ((m)->m_flags & M_EXT) {                                    \
  601:                 m_ext_free(m);                                                \
  602:         } else {                                                       \
  603:                 pool_cache_put(mb_cache, (m));                                \
  604:         }                                                              \
  605: 
  606: /*
  607:  * Copy mbuf pkthdr from `from' to `to'.
  608:  * `from' must have M_PKTHDR set, and `to' must be empty.
  609:  */
  610: #define M_COPY_PKTHDR(to, from)                                         \
  611: do {                                                                    \
  612:         (to)->m_pkthdr = (from)->m_pkthdr;                             \
  613:         (to)->m_flags = (from)->m_flags & M_COPYFLAGS;                 \
  614:         SLIST_INIT(&(to)->m_pkthdr.tags);                              \
  615:         m_tag_copy_chain((to), (from));                                        \
  616:         (to)->m_data = (to)->m_pktdat;                                 \
  617: } while (/* CONSTCOND */ 0)
  618: 
  619: /*
  620:  * Move mbuf pkthdr from `from' to `to'.
  621:  * `from' must have M_PKTHDR set, and `to' must be empty.
  622:  */
  623: #define M_MOVE_PKTHDR(to, from) m_move_pkthdr(to, from)
  624: 
  625: /*
  626:  * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
  627:  * an object of the specified size at the end of the mbuf, longword aligned.
  628:  */
  629: #define M_ALIGN(m, len)                                                 \
  630: do {                                                                    \
  631:         (m)->m_data += (MLEN - (len)) &~ (sizeof(long) - 1);           \
  632: } while (/* CONSTCOND */ 0)
  633: 
  634: /*
  635:  * As above, for mbufs allocated with m_gethdr/MGETHDR
  636:  * or initialized by M_COPY_PKTHDR.
  637:  */
  638: #define MH_ALIGN(m, len)                                                \
  639: do {                                                                    \
  640:         (m)->m_data += (MHLEN - (len)) &~ (sizeof(long) - 1);          \
  641: } while (/* CONSTCOND */ 0)
  642: 
  643: /*
  644:  * Determine if an mbuf's data area is read-only.  This is true
  645:  * if external storage is read-only mapped, or not marked as R/W,
  646:  * or referenced by more than one mbuf.
  647:  */
  648: #define M_READONLY(m)                                                   \
  649:         (((m)->m_flags & M_EXT) != 0 &&                                        \
  650:           (((m)->m_flags & (M_EXT_ROMAP|M_EXT_RW)) != M_EXT_RW ||      \
  651:           (m)->m_ext.ext_refcnt > 1))
  652: 
  653: #define M_UNWRITABLE(__m, __len)                                        \
  654:         ((__m)->m_len < (__len) || M_READONLY((__m)))
  655: /*
  656:  * Determine if an mbuf's data area is read-only at the MMU.
  657:  */
  658: #define M_ROMAP(m)                                                      \
  659:         (((m)->m_flags & (M_EXT|M_EXT_ROMAP)) == (M_EXT|M_EXT_ROMAP))
  660: 
  661: /*
  662:  * Compute the amount of space available
  663:  * before the current start of data in an mbuf.
  664:  */
  665: #define _M_LEADINGSPACE(m)                                              \
  666:         (size_t)(((m)->m_flags & M_EXT ? (m)->m_data - (m)->m_ext.ext_buf :    \
  667:          (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat :       \
  668:          (m)->m_data - (m)->m_dat))
  669: 
  670: #define M_LEADINGSPACE(m)                                               \
  671:         (M_READONLY((m)) ? 0 : _M_LEADINGSPACE((m)))
  672: 
  673: /*
  674:  * Compute the amount of space available
  675:  * after the end of data in an mbuf.
  676:  */
  677: #define _M_TRAILINGSPACE(m)                                             \
  678:         ((m)->m_flags & M_EXT ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size - \
  679:          ((m)->m_data + (m)->m_len) :                                  \
  680:          &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
  681: 
  682: #define M_TRAILINGSPACE(m)                                              \
  683:         (M_READONLY((m)) ? 0 : _M_TRAILINGSPACE((m)))
  684: 
  685: /*
  686:  * Compute the address of an mbuf's data area.
  687:  */
  688: #define M_BUFADDR(m)                                                    \
  689:         (((m)->m_flags & M_PKTHDR) ? (m)->m_pktdat : (m)->m_dat)
  690: 
  691: /*
  692:  * Compute the offset of the beginning of the data buffer of a non-ext
  693:  * mbuf.
  694:  */
  695: #define M_BUFOFFSET(m)                                                  \
  696:         (((m)->m_flags & M_PKTHDR) ?                                   \
  697:          offsetof(struct mbuf, m_pktdat) : offsetof(struct mbuf, m_dat))
  698: 
  699: /*
  700:  * Arrange to prepend space of size plen to mbuf m.
  701:  * If a new mbuf must be allocated, how specifies whether to wait.
  702:  * If how is M_DONTWAIT and allocation fails, the original mbuf chain
  703:  * is freed and m is set to NULL.
  704:  */
  705: #define M_PREPEND(m, plen, how)                                         \
  706: do {                                                                    \
  707:         if (M_LEADINGSPACE(m) >= (plen)) {                             \
  708:                 (m)->m_data -= (plen);                                        \
  709:                 (m)->m_len += (plen);                                 \
  710:         } else                                                         \
  711:                 (m) = m_prepend((m), (plen), (how));                  \
  712:         if ((m) && ((m)->m_flags & M_PKTHDR))                          \
  713:                 (m)->m_pkthdr.len += (plen);                          \
  714: } while (/* CONSTCOND */ 0)
  715: 
  716: /* change mbuf to new type */
  717: #define MCHTYPE(m, t)                                                   \
  718: do {                                                                    \
  719:         mbstat_type_add((m)->m_type, -1);                              \
  720:         mbstat_type_add(t, 1);                                         \
  721:         (m)->m_type = t;                                               \
  722: } while (/* CONSTCOND */ 0)
  723: 
  724: /* length to m_copy to copy all */
  725: #define M_COPYALL       1000000000
  726: 
  727: /* compatibility with 4.3 */
  728: #define  m_copy(m, o, l)        m_copym((m), (o), (l), M_DONTWAIT)
  729: 
  730: /*
  731:  * Allow drivers and/or protocols to use the rcvif member of
  732:  * PKTHDR mbufs to store private context information.
  733:  */
  734: #define M_GETCTX(m, t)          ((t)(m)->m_pkthdr.rcvif)
  735: #define M_SETCTX(m, c)          ((void)((m)->m_pkthdr.rcvif = (void *)(c)))
  736: 
  737: #endif /* defined(_KERNEL) */
  738: 
  739: /*
  740:  * Simple mbuf queueing system
  741:  *
  742:  * this is basically a SIMPLEQ adapted to mbuf use (ie using
  743:  * m_nextpkt instead of field.sqe_next).
  744:  *
  745:  * m_next is ignored, so queueing chains of mbufs is possible
  746:  */
  747: #define MBUFQ_HEAD(name)                                        \
  748: struct name {                                                   \
  749:         struct mbuf *mq_first;                                 \
  750:         struct mbuf **mq_last;                                 \
  751: }
  752: 
  753: #define MBUFQ_INIT(q)           do {                             \
  754:         (q)->mq_first = NULL;                                  \
  755:         (q)->mq_last = &(q)->mq_first;                         \
  756: } while (/*CONSTCOND*/0)
  757: 
  758: #define MBUFQ_ENQUEUE(q, m)     do {                                \
  759:         (m)->m_nextpkt = NULL;                                 \
  760:         *(q)->mq_last = (m);                                   \
  761:         (q)->mq_last = &(m)->m_nextpkt;                                \
  762: } while (/*CONSTCOND*/0)
  763: 
  764: #define MBUFQ_PREPEND(q, m)     do {                                \
  765:         if (((m)->m_nextpkt = (q)->mq_first) == NULL)          \
  766:                 (q)->mq_last = &(m)->m_nextpkt;                       \
  767:         (q)->mq_first = (m);                                   \
  768: } while (/*CONSTCOND*/0)
  769: 
  770: #define MBUFQ_DEQUEUE(q, m)     do {                                \
  771:         if (((m) = (q)->mq_first) != NULL) {                   \
  772:                 if (((q)->mq_first = (m)->m_nextpkt) == NULL) \
  773:                         (q)->mq_last = &(q)->mq_first;               \
  774:                 else                                          \
  775:                         (m)->m_nextpkt = NULL;                       \
  776:         }                                                      \
  777: } while (/*CONSTCOND*/0)
  778: 
  779: #define MBUFQ_DRAIN(q)          do {                            \
  780:         struct mbuf *__m0;                                     \
  781:         while ((__m0 = (q)->mq_first) != NULL) {               \
  782:                 (q)->mq_first = __m0->m_nextpkt;              \
  783:                 m_freem(__m0);                                        \
  784:         }                                                      \
  785:         (q)->mq_last = &(q)->mq_first;                         \
  786: } while (/*CONSTCOND*/0)
  787: 
  788: #define MBUFQ_FIRST(q)          ((q)->mq_first)
  789: #define MBUFQ_NEXT(m)           ((m)->m_nextpkt)
  790: #define MBUFQ_LAST(q)           (*(q)->mq_last)
  791: 
  792: /*
  793:  * Mbuf statistics.
  794:  * For statistics related to mbuf and cluster allocations, see also the
  795:  * pool headers (mb_cache and mcl_cache).
  796:  */
  797: struct mbstat {
  798:         u_long _m_spare;       /* formerly m_mbufs */
  799:         u_long _m_spare1;      /* formerly m_clusters */
  800:         u_long _m_spare2;      /* spare field */
  801:         u_long _m_spare3;      /* formely m_clfree - free clusters */
  802:         u_long m_drops;        /* times failed to find space */
  803:         u_long m_wait;         /* times waited for space */
  804:         u_long m_drain;        /* times drained protocols for space */
  805:         u_short        m_mtypes[256]; /* type specific mbuf allocations */
  806: };
  807: 
  808: struct mbstat_cpu {
  809:         u_int  m_mtypes[256];   /* type specific mbuf allocations */
  810: };
  811: 
  812: /*
  813:  * Mbuf sysctl variables.
  814:  */
  815: #define MBUF_MSIZE              1   /* int: mbuf base size */
  816: #define MBUF_MCLBYTES           2        /* int: mbuf cluster size */
  817: #define MBUF_NMBCLUSTERS        3      /* int: limit on the # of clusters */
  818: #define MBUF_MBLOWAT            4 /* int: mbuf low water mark */
  819: #define MBUF_MCLLOWAT           5        /* int: mbuf cluster low water mark */
  820: #define MBUF_STATS              6   /* struct: mbstat */
  821: #define MBUF_MOWNERS            7 /* struct: m_owner[] */
  822: #define MBUF_MAXID              8   /* number of valid MBUF ids */
  823: 
  824: #define CTL_MBUF_NAMES {                                                \
  825:         { 0, 0 },                                                      \
  826:         { "msize", CTLTYPE_INT },                                      \
  827:         { "mclbytes", CTLTYPE_INT },                                   \
  828:         { "nmbclusters", CTLTYPE_INT },                                        \
  829:         { "mblowat", CTLTYPE_INT },                                    \
  830:         { "mcllowat", CTLTYPE_INT },                                   \
  831:         { 0 /* "stats" */, CTLTYPE_STRUCT },                           \
  832:         { 0 /* "mowners" */, CTLTYPE_STRUCT },                         \
  833: }
  834: 
  835: #ifdef  _KERNEL
  836: extern struct mbstat mbstat;
  837: extern int      nmbclusters;         /* limit on the # of clusters */
  838: extern int      mblowat;             /* mbuf low water mark */
  839: extern int      mcllowat;            /* mbuf cluster low water mark */
  840: extern int      max_linkhdr;         /* largest link-level header */
  841: extern int      max_protohdr;                /* largest protocol header */
  842: extern int      max_hdr;             /* largest link+protocol header */
  843: extern int      max_datalen;         /* MHLEN - max_hdr */
  844: extern const int msize;                 /* mbuf base size */
  845: extern const int mclbytes;              /* mbuf cluster size */
  846: extern pool_cache_t mb_cache;
  847: extern pool_cache_t mcl_cache;
  848: #ifdef MBUFTRACE
  849: LIST_HEAD(mownerhead, mowner);
  850: extern struct mownerhead mowners;
  851: extern struct mowner unknown_mowners[];
  852: extern struct mowner revoked_mowner;
  853: #endif
  854: 
  855: MALLOC_DECLARE(M_MBUF);
  856: MALLOC_DECLARE(M_SONAME);
  857: MALLOC_DECLARE(M_SOOPTS);
  858: 
  859: struct  mbuf *m_copym(struct mbuf *, int, int, int);
  860: struct  mbuf *m_copypacket(struct mbuf *, int);
  861: struct  mbuf *m_devget(char *, int, int, struct ifnet *,
  862:                             void (*copy)(const void *, void *, size_t));
  863: struct  mbuf *m_dup(struct mbuf *, int, int, int);
  864: struct  mbuf *m_free(struct mbuf *);
  865: struct  mbuf *m_get(int, int);
  866: struct  mbuf *m_getclr(int, int);
  867: struct  mbuf *m_gethdr(int, int);
  868: struct  mbuf *m_prepend(struct mbuf *,int, int);
  869: struct  mbuf *m_pulldown(struct mbuf *, int, int, int *);
  870: struct  mbuf *m_pullup(struct mbuf *, int);
  871: struct  mbuf *m_copyup(struct mbuf *, int, int);
  872: struct  mbuf *m_split(struct mbuf *,int, int);
  873: struct  mbuf *m_getptr(struct mbuf *, int, int *);
  874: void    m_adj(struct mbuf *, int);
  875: int     m_apply(struct mbuf *, int, int,
  876:                 int (*)(void *, void *, unsigned int), void *);
  877: void    m_cat(struct mbuf *,struct mbuf *);
  878: void    m_clget(struct mbuf *, int);
  879: int     m_mballoc(int, int);
  880: void    m_copyback(struct mbuf *, int, int, const void *);
  881: struct  mbuf *m_copyback_cow(struct mbuf *, int, int, const void *, int);
  882: int     m_makewritable(struct mbuf **, int, int, int);
  883: struct  mbuf *m_getcl(int, int, int);
  884: void    m_copydata(struct mbuf *, int, int, void *);
  885: void    m_freem(struct mbuf *);
  886: void    m_reclaim(void *, int);
  887: #ifndef T2EX
  888: void    mbinit(void);
  889: #else
  890: int     mbinit(void);
  891: int     mbfinish(void);
  892: #endif
  893: void    m_ext_free(struct mbuf *);
  894: char *  m_mapin(struct mbuf *);
  895: void    m_move_pkthdr(struct mbuf *to, struct mbuf *from);
  896: 
  897: /* Inline routines. */
  898: static __inline u_int m_length(const struct mbuf *) __unused;
  899: 
  900: /* Statistics */
  901: void mbstat_type_add(int, int);
  902: 
  903: /* Packet tag routines */
  904: struct  m_tag *m_tag_get(int, int, int);
  905: void    m_tag_free(struct m_tag *);
  906: void    m_tag_prepend(struct mbuf *, struct m_tag *);
  907: void    m_tag_unlink(struct mbuf *, struct m_tag *);
  908: void    m_tag_delete(struct mbuf *, struct m_tag *);
  909: void    m_tag_delete_chain(struct mbuf *, struct m_tag *);
  910: void    m_tag_delete_nonpersistent(struct mbuf *);
  911: struct  m_tag *m_tag_find(struct mbuf *, int, struct m_tag *);
  912: struct  m_tag *m_tag_copy(struct m_tag *);
  913: int     m_tag_copy_chain(struct mbuf *, struct mbuf *);
  914: void    m_tag_init(struct mbuf *);
  915: struct  m_tag *m_tag_first(struct mbuf *);
  916: struct  m_tag *m_tag_next(struct mbuf *, struct m_tag *);
  917: 
  918: /* Packet tag types */
  919: #define PACKET_TAG_NONE                         0  /* Nothing */
  920: #define PACKET_TAG_VLAN                         1  /* VLAN ID */
  921: #define PACKET_TAG_ENCAP                        2  /* encapsulation data */
  922: #define PACKET_TAG_ESP                          3  /* ESP information */
  923: #define PACKET_TAG_PF                           11 /* packet filter */
  924: #define PACKET_TAG_ALTQ_QID                     12 /* ALTQ queue id */
  925: 
  926: #define PACKET_TAG_IPSEC_IN_CRYPTO_DONE         16
  927: #define PACKET_TAG_IPSEC_IN_DONE                17
  928: #define PACKET_TAG_IPSEC_OUT_DONE               18
  929: #define PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED      19  /* NIC IPsec crypto req'ed */
  930: #define PACKET_TAG_IPSEC_IN_COULD_DO_CRYPTO     20  /* NIC notifies IPsec */
  931: #define PACKET_TAG_IPSEC_PENDING_TDB            21  /* Reminder to do IPsec */
  932: 
  933: #define PACKET_TAG_IPSEC_SOCKET                 22 /* IPSEC socket ref */
  934: #define PACKET_TAG_IPSEC_HISTORY                23 /* IPSEC history */
  935: 
  936: #define PACKET_TAG_IPSEC_NAT_T_PORTS            25 /* two uint16_t */
  937: 
  938: #define PACKET_TAG_INET6                        26 /* IPv6 info */
  939: 
  940: #define PACKET_TAG_ECO_RETRYPARMS               27 /* Econet retry parameters */
  941: 
  942: #define PACKET_TAG_TUNNEL_INFO                  28 /* tunnel identification and
  943:                                                     * protocol callback, for
  944:                                                     * loop detection/recovery
  945:                                                     */
  946: 
  947: /*
  948:  * Return the number of bytes in the mbuf chain, m.
  949:  */
  950: static __inline u_int
  951: m_length(const struct mbuf *m)
  952: {
  953:         const struct mbuf *m0;
  954:         u_int pktlen;
  955: 
  956:         if ((m->m_flags & M_PKTHDR) != 0)
  957:                 return m->m_pkthdr.len;
  958: 
  959:         pktlen = 0;
  960:         for (m0 = m; m0 != NULL; m0 = m0->m_next)
  961:                 pktlen += m0->m_len;
  962:         return pktlen;
  963: }
  964: 
  965: void m_print(const struct mbuf *, const char *, void (*)(const char *, ...));
  966: 
  967: #endif /* _KERNEL */
  968: #endif /* !_SYS_MBUF_H_ */
  969: 
  970: #if defined(_KERNEL) && !defined(T2EX)
  971: #ifdef MBTYPES
  972: struct malloc_type *mbtypes[] = {               /* XXX */
  973:         M_FREE,                /* MT_FREE    0  should be on free list */
  974:         M_MBUF,                /* MT_DATA    1  dynamic (data) allocation */
  975:         M_MBUF,                /* MT_HEADER  2        packet header */
  976:         M_SONAME,      /* MT_SONAME 3       socket name */
  977:         M_SOOPTS,      /* MT_SOOPTS 4       socket options */
  978:         M_FTABLE,      /* MT_FTABLE 5       fragment reassembly header */
  979:         M_MBUF,                /* MT_CONTROL 6       extra-data protocol message */
  980:         M_MBUF,                /* MT_OOBDATA 7       expedited data  */
  981: };
  982: #undef MBTYPES
  983: #else
  984: extern struct malloc_type *mbtypes[];
  985: #endif /* MBTYPES */
  986: #endif /* _KERNEL */