46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*-
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Copyright (c) 1982, 1986, 1988, 1993
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * The Regents of the University of California.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * All rights reserved.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Redistribution and use in source and binary forms, with or without
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * modification, are permitted provided that the following conditions
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * are met:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * 1. Redistributions of source code must retain the above copyright
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * notice, this list of conditions and the following disclaimer.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * 2. Redistributions in binary form must reproduce the above copyright
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * notice, this list of conditions and the following disclaimer in the
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * documentation and/or other materials provided with the distribution.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * 3. Neither the name of the University nor the names of its contributors
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * may be used to endorse or promote products derived from this software
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * without specific prior written permission.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * SUCH DAMAGE.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * $FreeBSD: src/sys/sys/mbuf.h,v 1.217.2.3.4.1 2009/04/15 03:14:26 kensmith Exp $
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef _SYS_MBUF_H_
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define _SYS_MBUF_H_
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* XXX: These includes suck. Sorry! */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#include <sys/queue.h>
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifdef _KERNEL
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#include <sys/systm.h>
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#include <vm/uma.h>
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifdef WITNESS
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#include <sys/lock.h>
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else /* VBOX */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# include <iprt/param.h>
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# include "misc.h"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# include "ext.h"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsynctypedef const char *c_caddr_t;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
7439c7d4531e7d7371582dc180c138a747aa6d0bvboxsyncDECLNORETURN(static void) panic (char *fmt, ...)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync va_list args;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync va_start(args, fmt);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync vbox_slirp_printV(fmt, args);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync va_end(args);
7439c7d4531e7d7371582dc180c138a747aa6d0bvboxsync AssertFatalFailed();
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* for non-gnu compilers */
e6ca555ca95db3d710e106b8f0920ea99be7c4a5vboxsync# define __func__ RT_GCC_EXTENSION __FUNCTION__
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# ifndef __inline
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define __inline
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define bzero(a1, len) memset((a1), 0, (len))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* (vvl) some definitions from sys/param.h */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Constants related to network buffer management.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * MCLBYTES must be no larger than PAGE_SIZE.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# ifndef MSIZE
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define MSIZE 256 /* size of an mbuf */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# endif /* MSIZE */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# ifndef MCLSHIFT
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define MCLSHIFT 11 /* convert bytes to mbuf clusters */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# endif /* MCLSHIFT */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# ifndef MCLBYTES
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define MCLBYTES (1 << MCLSHIFT) /* size of an mbuf cluster */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# endif /*MCLBYTES*/
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define MJUMPAGESIZE PAGE_SIZE /* jumbo cluster 4k */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define MJUM9BYTES (9 * 1024) /* jumbo cluster 9k */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define MJUM16BYTES (16 * 1024) /* jumbo cluster 16k */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif /* VBOX */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Mbufs are of a single size, MSIZE (sys/param.h), which includes overhead.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * An mbuf may add a single "mbuf cluster" of size MCLBYTES (also in
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * sys/param.h), which has no additional overhead and is used instead of the
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * internal data area; this is done when at least MINCLSIZE of data must be
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * stored. Additionally, it is possible to allocate a separate buffer
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * externally and attach it to the mbuf in a way similar to that of mbuf
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * clusters.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MINCLSIZE (MHLEN + 1) /* smallest amount to put in cluster */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#if defined(_KERNEL) || defined(VBOX)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*-
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Macros for type conversion:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * dtom(x) -- Convert data pointer within mbuf to mbuf pointer (XXX).
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define mtod(m, t) ((t)((m)->m_data))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define dtom(x) ((struct mbuf *)((intptr_t)(x) & ~(MSIZE-1)))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Argument structure passed to UMA routines during mbuf and packet
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * allocations.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mb_args {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int flags; /* Flags for mbuf being allocated */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync short type; /* Type of mbuf being allocated */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync};
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif /* _KERNEL */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#if defined(__LP64__)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_HDR_PAD 6
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_HDR_PAD 2
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Header present at the beginning of every mbuf.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct m_hdr {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mbuf *mh_next; /* next buffer in chain */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mbuf *mh_nextpkt; /* next chain in queue/record */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync caddr_t mh_data; /* location of data */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int mh_len; /* amount of data in this mbuf */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int mh_flags; /* flags; see below */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync short mh_type; /* type of data in this mbuf */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifdef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct socket *mh_so; /*socket assotiated with mbuf*/
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync TAILQ_ENTRY(mbuf) mh_ifq;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uint8_t pad[M_HDR_PAD];/* word align */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync};
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Packet tag structure (see below for details).
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct m_tag {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_int16_t m_tag_id; /* Tag ID */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_int16_t m_tag_len; /* Length of data */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_int32_t m_tag_cookie; /* ABI/Module ID */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync void (*m_tag_free)(struct m_tag *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync};
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct pkthdr {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct ifnet *rcvif; /* rcv interface */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync /* variables for ip and tcp reassembly */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync void *header; /* pointer to packet header */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int len; /* total packet length */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync /* variables for hardware checksum */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int csum_flags; /* flags regarding checksum */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int csum_data; /* data field used by csum routines */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_int16_t tso_segsz; /* TSO segment size */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_int16_t ether_vtag; /* Ethernet 802.1p+q vlan tag */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync};
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Description of external storage mapped into mbuf; valid only if M_EXT is
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * set.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct m_ext {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync caddr_t ext_buf; /* start of buffer */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync void (*ext_free) /* free routine if not the usual */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (void *, void *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync void *ext_args; /* optional argument pointer */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_int ext_size; /* size of buffer, for ext_free */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifdef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync volatile uint32_t *ref_cnt; /* pointer to ref count info */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync volatile u_int *ref_cnt; /* pointer to ref count info */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int ext_type; /* type of external storage */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync};
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * The core of the mbuf object along with some shortcut defines for practical
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * purposes.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct m_hdr m_hdr;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync union {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct pkthdr MH_pkthdr; /* M_PKTHDR set */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync union {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct m_ext MH_ext; /* M_EXT set */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync char MH_databuf[MHLEN];
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync } MH_dat;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync } MH;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync } M_dat;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync};
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_next m_hdr.mh_next
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_len m_hdr.mh_len
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_data m_hdr.mh_data
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_type m_hdr.mh_type
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_flags m_hdr.mh_flags
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_nextpkt m_hdr.mh_nextpkt
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_act m_nextpkt
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_pkthdr M_dat.MH.MH_pkthdr
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_ext M_dat.MH.MH_dat.MH_ext
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_pktdat M_dat.MH.MH_dat.MH_databuf
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_dat M_dat.M_databuf
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifdef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define m_so m_hdr.mh_so
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define ifq_so m_hdr.mh_so
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define m_ifq m_hdr.mh_ifq
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * mbuf flags.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_EXT 0x00000001 /* has associated external storage */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PKTHDR 0x00000002 /* start of record */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_EOR 0x00000004 /* end of record */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_RDONLY 0x00000008 /* associated data is marked read-only */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROTO1 0x00000010 /* protocol-specific */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROTO2 0x00000020 /* protocol-specific */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROTO3 0x00000040 /* protocol-specific */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROTO4 0x00000080 /* protocol-specific */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROTO5 0x00000100 /* protocol-specific */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_BCAST 0x00000200 /* send/received as link-level broadcast */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_MCAST 0x00000400 /* send/received as link-level multicast */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_FRAG 0x00000800 /* packet is a fragment of a larger packet */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_FIRSTFRAG 0x00001000 /* packet is first fragment */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_LASTFRAG 0x00002000 /* packet is last fragment */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_SKIP_FIREWALL 0x00004000 /* skip firewall processing */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_FREELIST 0x00008000 /* mbuf is on the free list */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_VLANTAG 0x00010000 /* ether_vtag is valid */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROMISC 0x00020000 /* packet was not for us */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_NOFREE 0x00040000 /* do not free mbuf, embedded in cluster */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROTO6 0x00080000 /* protocol-specific */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROTO7 0x00100000 /* protocol-specific */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROTO8 0x00200000 /* protocol-specific */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * For RELENG_{6,7} steal these flags for limited multiple routing table
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * support. In RELENG_8 and beyond, use just one flag and a tag.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_FIB 0xF0000000 /* steal some bits to store fib number. */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_NOTIFICATION M_PROTO5 /* SCTP notification */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Flags to purge when crossing layers.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PROTOFLAGS \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (M_PROTO1|M_PROTO2|M_PROTO3|M_PROTO4|M_PROTO5|M_PROTO6|M_PROTO7|M_PROTO8)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Flags preserved when copying m_pkthdr.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_COPYFLAGS \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (M_PKTHDR|M_EOR|M_RDONLY|M_PROTOFLAGS|M_SKIP_FIREWALL|M_BCAST|M_MCAST|\
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_VLANTAG|M_PROMISC|M_FIB)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * External buffer types: identify ext_buf type.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_CLUSTER 1 /* mbuf cluster */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_SFBUF 2 /* sendfile(2)'s sf_bufs */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_JUMBOP 3 /* jumbo cluster 4096 bytes */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_JUMBO9 4 /* jumbo cluster 9216 bytes */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_JUMBO16 5 /* jumbo cluster 16184 bytes */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_PACKET 6 /* mbuf+cluster from packet zone */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_MBUF 7 /* external mbuf reference (M_IOVEC) */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_NET_DRV 100 /* custom ext_buf provided by net driver(s) */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_MOD_TYPE 200 /* custom module's ext_buf type */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_DISPOSABLE 300 /* can throw this buffer away w/page flipping */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define EXT_EXTREF 400 /* has externally maintained ref_cnt ptr */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Flags indicating hw checksum support and sw checksum requirements. This
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * field can be directly tested against if_data.ifi_hwassist.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_IP 0x0001 /* will csum IP */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_TCP 0x0002 /* will csum TCP */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_UDP 0x0004 /* will csum UDP */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_TSO 0x0020 /* will do TSO */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_IP_CHECKED 0x0100 /* did csum IP */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_IP_VALID 0x0200 /* ... the csum is valid */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_DATA_VALID 0x0400 /* csum_data field is valid */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_PSEUDO_HDR 0x0800 /* csum_data has pseudo hdr */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * mbuf types.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MT_NOTMBUF 0 /* USED INTERNALLY ONLY! Object is not mbuf */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MT_DATA 1 /* dynamic (data) allocation */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MT_HEADER MT_DATA /* packet header, use M_PKTHDR instead */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MT_SONAME 8 /* socket name */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MT_CONTROL 14 /* extra-data protocol message */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MT_OOBDATA 15 /* expedited data */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MT_NOINIT 255 /* Not a type but a flag to allocate
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync a non-initialized mbuf */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MB_NOTAGS 0x1UL /* no tags attached to mbuf */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * General mbuf allocator statistics structure.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Many of these statistics are no longer used; we instead track many
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * allocator statistics through UMA's built in statistics mechanism.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbstat {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_mbufs; /* XXX */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_mclusts; /* XXX */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_drain; /* times drained protocols for space */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_mcfail; /* XXX: times m_copym failed */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_mpfail; /* XXX: times m_pullup failed */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_msize; /* length of an mbuf */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_mclbytes; /* length of an mbuf cluster */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_minclsize; /* min length of data to allocate a cluster */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_mlen; /* length of data in an mbuf */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long m_mhlen; /* length of data in a header mbuf */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync /* Number of mbtypes (gives # elems in mbtypes[] array) */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync short m_numtypes;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync /* XXX: Sendfile stats should eventually move to their own struct */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long sf_iocnt; /* times sendfile had to do disk I/O */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long sf_allocfail; /* times sfbuf allocation failed */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync u_long sf_allocwait; /* times sfbuf allocation had to wait */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync};
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Flags specifying how an allocation should be made.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * The flag to use is as follows:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * - M_DONTWAIT or M_NOWAIT from an interrupt handler to not block allocation.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * - M_WAIT or M_WAITOK or M_TRYWAIT from wherever it is safe to block.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * M_DONTWAIT/M_NOWAIT means that we will not block the thread explicitly and
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * if we cannot allocate immediately we may return NULL, whereas
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * M_WAIT/M_WAITOK/M_TRYWAIT means that if we cannot allocate resources we
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * will block until they are available, and thus never return NULL.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * XXX Eventually just phase this out to use M_WAITOK/M_NOWAIT.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBTOM(how) (how)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_DONTWAIT M_NOWAIT
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_TRYWAIT M_WAITOK
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_WAIT M_WAITOK
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* @todo (r=vvl) not sure we can do it in NAT */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define M_WAITOK 0
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define M_NOWAIT 0
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define M_DONTWAIT 0
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define M_TRYWAI 0
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync# define M_WAIT 0
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * String names of mbuf-related UMA(9) and malloc(9) types. Exposed to
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * !_KERNEL so that monitoring tools can look up the zones with
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * libmemstat(3).
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_MEM_NAME "mbuf"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_CLUSTER_MEM_NAME "mbuf_cluster"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_PACKET_MEM_NAME "mbuf_packet"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_JUMBOP_MEM_NAME "mbuf_jumbo_pagesize"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_JUMBO9_MEM_NAME "mbuf_jumbo_9k"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_JUMBO16_MEM_NAME "mbuf_jumbo_16k"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_TAG_MEM_NAME "mbuf_tag"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_EXTREFCNT_MEM_NAME "mbuf_ext_refcnt"
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#if defined(_KERNEL) || defined(VBOX)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifdef WITNESS
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_CHECKSLEEP(how) do { \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (how == M_WAITOK) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync "Sleeping in \"%s\"", __func__); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync} while (0)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MBUF_CHECKSLEEP(how)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Network buffer allocation API
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * The rest of it is defined in kern/kern_mbuf.c
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern uma_zone_t zone_mbuf;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern uma_zone_t zone_clust;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern uma_zone_t zone_pack;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern uma_zone_t zone_jumbop;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern uma_zone_t zone_jumbo9;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern uma_zone_t zone_jumbo16;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern uma_zone_t zone_ext_refcnt;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_getcl(int how, short type, int flags);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_get(int how, short type);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_gethdr(int how, short type);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_getjcl(int how, short type, int flags,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int size);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_getclr(int how, short type); /* XXX */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_free(struct mbuf *m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void m_clget(struct mbuf *m, int how);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void *m_cljget(struct mbuf *m, int how, int size);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid mb_free_ext(struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_getcl(PNATState pData, int how, short type, int flags);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_get(PNATState pData, int how, short type);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_gethdr(PNATState pData, int how, short type);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_getjcl(PNATState pData, int how,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync short type, int flags, int size);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_getclr(PNATState pData, int how, short type); /* XXX */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_free(PNATState pData, struct mbuf *m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void m_clget(PNATState pData, struct mbuf *m, int how);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void *m_cljget(PNATState pData, struct mbuf *m, int how, int size);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid mb_free_ext(PNATState, struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void m_chtype(struct mbuf *m, short new_type);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *m_last(struct mbuf *m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline int
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_gettype(int size)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int type;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync switch (size) {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MSIZE:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync type = EXT_MBUF;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MCLBYTES:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync type = EXT_CLUSTER;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#if MJUMPAGESIZE != MCLBYTES
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MJUMPAGESIZE:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync type = EXT_JUMBOP;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MJUM9BYTES:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync type = EXT_JUMBO9;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MJUM16BYTES:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync type = EXT_JUMBO16;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync default:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync panic("%s: m_getjcl: invalid cluster size", __func__);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync }
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (type);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline uma_zone_t
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_getzone(int size)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_getzone(PNATState pData, int size)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zone_t zone;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync switch (size) {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MSIZE:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = zone_mbuf;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MCLBYTES:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = zone_clust;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#if MJUMPAGESIZE != MCLBYTES
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MJUMPAGESIZE:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = zone_jumbop;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MJUM9BYTES:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = zone_jumbo9;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case MJUM16BYTES:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = zone_jumbo16;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync default:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync panic("%s: m_getjcl: invalid cluster type", __func__);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync }
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (zone);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_get(int how, short type)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_get(PNATState pData, int how, short type)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mb_args args;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.flags = 0;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.type = type;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return ((struct mbuf *)(uma_zalloc_arg(zone_mbuf, &args, how)));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * XXX This should be deprecated, very little use.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_getclr(int how, short type)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_getclr(PNATState pData, int how, short type)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mbuf *m;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mb_args args;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.flags = 0;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.type = type;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m = uma_zalloc_arg(zone_mbuf, &args, how);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (m != NULL)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync bzero(m->m_data, MLEN);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_gethdr(int how, short type)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_gethdr(PNATState pData, int how, short type)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mb_args args;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.flags = M_PKTHDR;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.type = type;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return ((struct mbuf *)(uma_zalloc_arg(zone_mbuf, &args, how)));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_getcl(int how, short type, int flags)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_getcl(PNATState pData, int how, short type, int flags)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mb_args args;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.flags = flags;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.type = type;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return ((struct mbuf *)(uma_zalloc_arg(zone_pack, &args, how)));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * m_getjcl() returns an mbuf with a cluster of the specified size attached.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * For size it takes MCLBYTES, MJUMPAGESIZE, MJUM9BYTES, MJUM16BYTES.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * XXX: This is rather large, should be real function maybe.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_getjcl(int how, short type, int flags, int size)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_getjcl(PNATState pData, int how, short type, int flags, int size)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mb_args args;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mbuf *m, *n;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zone_t zone;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.flags = flags;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync args.type = type;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m = uma_zalloc_arg(zone_mbuf, &args, how);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (m == NULL)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (NULL);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = m_getzone(size);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = m_getzone(pData, size);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync n = uma_zalloc_arg(zone, m, how);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (n == NULL) {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zfree(zone_mbuf, m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (NULL);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync }
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_free_fast(struct mbuf *m)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync KASSERT(SLIST_EMPTY(&m->m_pkthdr.tags), ("doing fast free of mbuf with tags"));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zfree_arg(zone_mbuf, m, (void *)MB_NOTAGS);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_free_fast(PNATState pData, struct mbuf *m)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync AssertMsg(SLIST_EMPTY(&m->m_pkthdr.tags), ("doing fast free of mbuf with tags"));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zfree_arg(zone_mbuf, m, (void *)MB_NOTAGS);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_free(struct mbuf *m)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_free(PNATState pData, struct mbuf *m)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mbuf *n = m->m_next;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (m->m_flags & M_EXT)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync mb_free_ext(m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync mb_free_ext(pData, m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync else if ((m->m_flags & M_NOFREE) == 0)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zfree(zone_mbuf, m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (n);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_clget(struct mbuf *m, int how)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_clget(PNATState pData, struct mbuf *m, int how)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (m->m_flags & M_EXT)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync printf("%s: %p mbuf already has cluster\n", __func__, m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_ext.ext_buf = (char *)NULL;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zalloc_arg(zone_clust, m, how);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync /*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * On a cluster allocation failure, drain the packet zone and retry,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * we might be able to loosen a few clusters up on the drain.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if ((how & M_NOWAIT) && (m->m_ext.ext_buf == NULL)) {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone_drain(zone_pack);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zalloc_arg(zone_clust, m, how);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync }
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * m_cljget() is different from m_clget() as it can allocate clusters without
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * attaching them to an mbuf. In that case the return value is the pointer
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * to the cluster of the requested size. If an mbuf was specified, it gets
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * the cluster attached to it and the return value can be safely ignored.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * For size it takes MCLBYTES, MJUMPAGESIZE, MJUM9BYTES, MJUM16BYTES.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_cljget(struct mbuf *m, int how, int size)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_cljget(PNATState pData, struct mbuf *m, int how, int size)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zone_t zone;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (m && m->m_flags & M_EXT)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync printf("%s: %p mbuf already has cluster\n", __func__, m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (m != NULL)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_ext.ext_buf = NULL;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = m_getzone(size);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = m_getzone(pData, size);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (uma_zalloc_arg(zone, m, how));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_cljset(struct mbuf *m, void *cl, int type)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_cljset(PNATState pData, struct mbuf *m, void *cl, int type)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync uma_zone_t zone;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int size;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync switch (type) {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case EXT_CLUSTER:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync size = MCLBYTES;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = zone_clust;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#if MJUMPAGESIZE != MCLBYTES
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case EXT_JUMBOP:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync size = MJUMPAGESIZE;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = zone_jumbop;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case EXT_JUMBO9:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync size = MJUM9BYTES;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = zone_jumbo9;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync case EXT_JUMBO16:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync size = MJUM16BYTES;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync zone = zone_jumbo16;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync default:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync panic("unknown cluster type");
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync break;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync }
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_data = m->m_ext.ext_buf = cl;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifdef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_ext.ext_free = (void (*)(void *, void *))0;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_ext.ext_args = NULL;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_ext.ext_free = m->m_ext.ext_args = NULL;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_ext.ext_size = size;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_ext.ext_type = type;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_ext.ref_cnt = uma_find_refcnt(zone, cl);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_flags |= M_EXT;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_chtype(struct mbuf *m, short new_type)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m->m_type = new_type;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct mbuf *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_last(struct mbuf *m)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync while (m->m_next)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m = m->m_next;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * mbuf, cluster, and external object allocation macros (for compatibility
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * purposes).
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_MOVE_PKTHDR(to, from) m_move_pkthdr((to), (from))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MGET(m, how, type) ((m) = m_get((how), (type)))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type)))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MCLGET(m, how) m_clget((m), (how))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MEXTADD(m, buf, size, free, args, flags, type) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m_extadd((m), (caddr_t)(buf), (size), (free), (args), (flags), (type))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_getm(m, len, how, type) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m_getm2((m), (len), (how), (type), M_PKTHDR)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else /*!VBOX*/
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MGET(m, how, type) ((m) = m_get(pData, (how), (type)))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MGETHDR(m, how, type) ((m) = m_gethdr(pData, (how), (type)))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MCLGET(m, how) m_clget(pData, (m), (how))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MEXTADD(m, buf, size, free, args, flags, type) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m_extadd(pData, (m), (caddr_t)(buf), (size), (free), (args), (flags), (type))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_getm(m, len, how, type) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m_getm2(pData, (m), (len), (how), (type), M_PKTHDR)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Evaluate TRUE if it's safe to write to the mbuf m's data region (this can
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * be both the local data payload, or an external buffer area, depending on
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * whether M_EXT is set).
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (!(((m)->m_flags & M_EXT)) || \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (*((m)->m_ext.ref_cnt) == 1)) ) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* Check if the supplied mbuf has a packet header, or else panic. */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_ASSERTPKTHDR(m) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync KASSERT(m != NULL && m->m_flags & M_PKTHDR, \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync ("%s: no mbuf packet header!", __func__))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Ensure that the supplied mbuf is a valid, non-free mbuf.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * XXX: Broken at the moment. Need some UMA magic to make it work again.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_ASSERTVALID(m) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync KASSERT((((struct mbuf *)m)->m_flags & 0) == 0, \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync ("%s: attempted use of a free mbuf!", __func__))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place an
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * object of the specified size at the end of the mbuf, longword aligned.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_ALIGN(m, len) do { \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync KASSERT(!((m)->m_flags & (M_PKTHDR|M_EXT)), \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync ("%s: M_ALIGN not normal mbuf", __func__)); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync KASSERT((m)->m_data == (m)->m_dat, \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync ("%s: M_ALIGN not a virgin mbuf", __func__)); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync} while (0)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * As above, for mbufs allocated with m_gethdr/MGETHDR or initialized by
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * M_DUP/MOVE_PKTHDR.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MH_ALIGN(m, len) do { \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync KASSERT((m)->m_flags & M_PKTHDR && !((m)->m_flags & M_EXT), \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync ("%s: MH_ALIGN not PKTHDR mbuf", __func__)); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync KASSERT((m)->m_data == (m)->m_pktdat, \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync ("%s: MH_ALIGN not a virgin mbuf", __func__)); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync} while (0)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Compute the amount of space available before the current start of data in
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * an mbuf.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * The M_WRITABLE() is a temporary, conservative safety measure: the burden
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * of checking writability of the mbuf data area rests solely with the caller.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_LEADINGSPACE(m) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync ((m)->m_flags & M_EXT ? \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (m)->m_data - (m)->m_dat)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Compute the amount of space available after the end of data in an mbuf.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * The M_WRITABLE() is a temporary, conservative safety measure: the burden
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * of checking writability of the mbuf data area rests solely with the caller.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_TRAILINGSPACE(m) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync ((m)->m_flags & M_EXT ? \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync - ((m)->m_data + (m)->m_len) : 0) : \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Arrange to prepend space of size plen to mbuf m. If a new mbuf must be
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * allocated, how specifies whether to wait. If the allocation fails, the
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * original mbuf chain is freed and m is set to NULL.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_PREPEND(m, plen, how) do { \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mbuf **_mmp = &(m); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync struct mbuf *_mm = *_mmp; \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int _mplen = (plen); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int __mhow = (how); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync MBUF_CHECKSLEEP(how); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (M_LEADINGSPACE(_mm) >= _mplen) { \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync _mm->m_data -= _mplen; \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync _mm->m_len += _mplen; \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync } else \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync _mm = m_prepend(_mm, _mplen, __mhow); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync if (_mm != NULL && _mm->m_flags & M_PKTHDR) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync _mm->m_pkthdr.len += _mplen; \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *_mmp = _mm; \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync} while (0)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Change mbuf to new type. This is a relatively expensive operation and
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * should be avoided.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MCHTYPE(m, t) m_chtype((m), (t))
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* Length to m_copy to copy all. */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_COPYALL 1000000000
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* Compatibility with 4.3. */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern int max_datalen; /* MHLEN - max_hdr */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern int max_hdr; /* Largest link + protocol header */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern int max_linkhdr; /* Largest link-level header */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern int max_protohdr; /* Largest protocol header */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern struct mbstat mbstat; /* General mbuf stats/infos */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncextern int nmbclusters; /* Maximum number of clusters */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct uio;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_align(struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncint m_apply(struct mbuf *, int, int,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int (*)(void *, void *, u_int), void *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_adj(struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncint m_append(struct mbuf *, int, c_caddr_t);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_defrag(struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_dup(struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_cat(struct mbuf *, struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_collapse(struct mbuf *, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_copyback(struct mbuf *, int, int, c_caddr_t);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_copym(struct mbuf *, int, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_copymdata(struct mbuf *, struct mbuf *,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int, int, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_copypacket(struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_copyup(struct mbuf *n, int len, int dstoff);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_extadd(struct mbuf *, caddr_t, u_int,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync void (*)(void *, void *), void *, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_adj(PNATState, struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncint m_append(PNATState pData, struct mbuf *, int, c_caddr_t);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_defrag(PNATState, struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_dup(PNATState, struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_cat(PNATState, struct mbuf *, struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_collapse(PNATState, struct mbuf *, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_copyback(PNATState, struct mbuf *, int, int, c_caddr_t);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_copym(PNATState, struct mbuf *, int, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_copymdata(PNATState, struct mbuf *, struct mbuf *,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync int, int, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_copypacket(PNATState, struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_copyup(PNATState, struct mbuf *n, int len, int dstoff);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_extadd(PNATState pData, struct mbuf *, caddr_t, u_int,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync void (*)(void *, void *), void *, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_copydata(const struct mbuf *, int, int, caddr_t);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_copy_pkthdr(struct mbuf *, struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_demote(struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_devget(char *, int, int, struct ifnet *,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync void (*)(char *, caddr_t, u_int));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncint m_dup_pkthdr(struct mbuf *, struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncu_int m_fixhdr(struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_fragment(struct mbuf *, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifndef VBOX
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_freem(struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_getm2(struct mbuf *, int, int, short, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_prepend(struct mbuf *, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_pulldown(struct mbuf *, int, int, int *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_pullup(struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncint m_sanity(struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_split(struct mbuf *, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_unshare(struct mbuf *, int how);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#else
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_freem(PNATState pData, struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_getm2(PNATState pData, struct mbuf *, int, int, short, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_prepend(PNATState, struct mbuf *, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_pulldown(PNATState, struct mbuf *, int, int, int *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_pullup(PNATState, struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncint m_sanity(PNATState, struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_split(PNATState, struct mbuf *, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_unshare(PNATState, struct mbuf *, int how);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_getptr(struct mbuf *, int, int *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncu_int m_length(struct mbuf *, struct mbuf **);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_move_pkthdr(struct mbuf *, struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_print(const struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct mbuf *m_uiotombuf(struct uio *, int, int, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*-
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Network packets may have annotations attached by affixing a list of
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * "packet tags" to the pkthdr structure. Packet tags are dynamically
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * allocated semi-opaque data structures that have a fixed header
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * (struct m_tag) that specifies the size of the memory block and a
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * <cookie,type> pair that identifies it. The cookie is a 32-bit unique
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * unsigned value used to identify a module or ABI. By convention this value
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * is chosen as the date+time that the module is created, expressed as the
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * number of seconds since the epoch (e.g., using date -u +'%s'). The type
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * value is an ABI/module-specific value that identifies a particular
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * annotation and is private to the module. For compatibility with systems
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * like OpenBSD that define packet tags w/o an ABI/module cookie, the value
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * PACKET_ABI_COMPAT is used to implement m_tag_get and m_tag_find
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * compatibility shim functions and several tag types are defined below.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Users that do not require compatibility should use a private cookie value
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * so that packet tag-related definitions can be maintained privately.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Note that the packet tag returned by m_tag_alloc has the default memory
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * alignment implemented by malloc. To reference private data one can use a
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * construct like:
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * struct m_tag *mtag = m_tag_alloc(...);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * struct foo *p = (struct foo *)(mtag+1);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * if the alignment of struct m_tag is sufficient for referencing members of
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * struct foo. Otherwise it is necessary to embed struct m_tag within the
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * private data structure to insure proper alignment; e.g.,
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * struct foo {
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * struct m_tag tag;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * ...
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * };
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * struct foo *p = (struct foo *) m_tag_alloc(...);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * struct m_tag *mtag = &p->tag;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Persistent tags stay with an mbuf until the mbuf is reclaimed. Otherwise
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * tags are expected to ``vanish'' when they pass through a network
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * interface. For most interfaces this happens normally as the tags are
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * reclaimed when the mbuf is free'd. However in some special cases
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * reclaiming must be done manually. An example is packets that pass through
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * the loopback interface. Also, one must be careful to do this when
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * ``turning around'' packets (e.g., icmp_reflect).
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * To mark a tag persistent bit-or this flag in when defining the tag id.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * The tag will then be treated as described above.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MTAG_PERSISTENT 0x800
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_NONE 0 /* Nadda */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* Packet tags for use with PACKET_ABI_COMPAT. */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPSEC_IN_DONE 1 /* IPsec applied, in */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPSEC_OUT_DONE 2 /* IPsec applied, out */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPSEC_IN_CRYPTO_DONE 3 /* NIC IPsec crypto done */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED 4 /* NIC IPsec crypto req'ed */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPSEC_IN_COULD_DO_CRYPTO 5 /* NIC notifies IPsec */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPSEC_PENDING_TDB 6 /* Reminder to do IPsec */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_BRIDGE 7 /* Bridge processing done */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_GIF 8 /* GIF processing done */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_GRE 9 /* GRE processing done */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IN_PACKET_CHECKSUM 10 /* NIC checksumming done */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_ENCAP 11 /* Encap. processing */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPSEC_SOCKET 12 /* IPSEC socket ref */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPSEC_HISTORY 13 /* IPSEC history */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPV6_INPUT 14 /* IPV6 input processing */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_DUMMYNET 15 /* dummynet info */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_DIVERT 17 /* divert info */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPFORWARD 18 /* ipforward info */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_MACLABEL (19 | MTAG_PERSISTENT) /* MAC label */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_PF 21 /* PF + ALTQ information */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_RTSOCKFAM 25 /* rtsock sa family */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_IPOPTIONS 27 /* Saved IP options */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define PACKET_TAG_CARP 28 /* CARP info */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#ifdef VBOX
c92314be92f2ca432ac9c08e0a927be9617cbb4dvboxsync# define PACKET_TAG_ALIAS 0xab01
c92314be92f2ca432ac9c08e0a927be9617cbb4dvboxsync# define PACKET_TAG_ETHER 0xab02
c92314be92f2ca432ac9c08e0a927be9617cbb4dvboxsync# define PACKET_SERVICE 0xab03
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* Specific cookies and tags. */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* Packet tag routines. */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct m_tag *m_tag_alloc(u_int32_t, int, int, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_tag_delete(struct mbuf *, struct m_tag *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_tag_delete_chain(struct mbuf *, struct m_tag *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_tag_free_default(struct m_tag *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstruct m_tag *m_tag_copy(struct m_tag *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncint m_tag_copy_chain(struct mbuf *, struct mbuf *, int);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncvoid m_tag_delete_nonpersistent(struct mbuf *);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Initialize the list of tags associated with an mbuf.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_tag_init(struct mbuf *m)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync SLIST_INIT(&m->m_pkthdr.tags);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Set up the contents of a tag. Note that this does not fill in the free
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * method; the caller is expected to do that.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * XXX probably should be called m_tag_init, but that was already taken.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_tag_setup(struct m_tag *t, u_int32_t cookie, int type, int len)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync t->m_tag_id = type;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync t->m_tag_len = len;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync t->m_tag_cookie = cookie;
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Reclaim resources associated with a tag.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_tag_free(struct m_tag *t)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync (*t->m_tag_free)(t);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Return the first tag associated with an mbuf.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct m_tag *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_tag_first(struct mbuf *m)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (SLIST_FIRST(&m->m_pkthdr.tags));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Return the next tag in the list of tags associated with an mbuf.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct m_tag *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_tag_next(struct mbuf *m, struct m_tag *t)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
21f41483611463008ef71e88d2c2b5ece30bc290vboxsync NOREF(m);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (SLIST_NEXT(t, m_tag_link));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Prepend a tag to the list of tags associated with an mbuf.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_tag_prepend(struct mbuf *m, struct m_tag *t)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync SLIST_INSERT_HEAD(&m->m_pkthdr.tags, t, m_tag_link);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/*
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync * Unlink a tag from the list of tags associated with an mbuf.
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline void
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_tag_unlink(struct mbuf *m, struct m_tag *t)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync SLIST_REMOVE(&m->m_pkthdr.tags, t, m_tag, m_tag_link);
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* These are for OpenBSD compatibility. */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define MTAG_ABI_COMPAT 0 /* compatibility ABI */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct m_tag *
46bea716c91426eba7aaa9efaf5e4016b10db3f9vboxsyncm_tag_get(int type, int length, int fWait)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46bea716c91426eba7aaa9efaf5e4016b10db3f9vboxsync return (m_tag_alloc(MTAG_ABI_COMPAT, type, length, fWait));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncstatic __inline struct m_tag *
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsyncm_tag_find(struct mbuf *m, int type, struct m_tag *start)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync{
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync return (SLIST_EMPTY(&m->m_pkthdr.tags) ? (struct m_tag *)NULL :
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync m_tag_locate(m, MTAG_ABI_COMPAT, type, start));
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync}
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* XXX temporary FIB methods probably eventually use tags.*/
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_FIBSHIFT 28
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_FIBMASK 0x0F
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync/* get the fib from an mbuf and if it is not set, return the default */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_GETFIB(_m) \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync ((((_m)->m_flags & M_FIB) >> M_FIBSHIFT) & M_FIBMASK)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#define M_SETFIB(_m, _fib) do { \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync _m->m_flags &= ~M_FIB; \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync _m->m_flags |= (((_fib) << M_FIBSHIFT) & M_FIB); \
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync} while (0)
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif /* _KERNEL */
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync
46192b2e5dd6b322ba3d1aae79e97074d50cdf89vboxsync#endif /* !_SYS_MBUF_H_ */