mbuf.h revision eda8b54d9b3e87c1108f18a1df7be9581b28f2e1
9fb5c93ff4449e19077128c07c080acbed35ceeavboxsync/*
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * Copyright (c) 1982, 1986, 1988, 1993
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * The Regents of the University of California. All rights reserved.
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync *
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * Redistribution and use in source and binary forms, with or without
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * modification, are permitted provided that the following conditions
74804912a237136f06d0b49682a119577135902bvboxsync * are met:
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * 1. Redistributions of source code must retain the above copyright
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * notice, this list of conditions and the following disclaimer.
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * 2. Redistributions in binary form must reproduce the above copyright
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * notice, this list of conditions and the following disclaimer in the
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * documentation and/or other materials provided with the distribution.
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * 3. All advertising materials mentioning features or use of this software
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * must display the following acknowledgement:
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * This product includes software developed by the University of
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * California, Berkeley and its contributors.
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * 4. Neither the name of the University nor the names of its contributors
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * may be used to endorse or promote products derived from this software
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * without specific prior written permission.
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync *
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
74804912a237136f06d0b49682a119577135902bvboxsync * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9fb5c93ff4449e19077128c07c080acbed35ceeavboxsync * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * SUCH DAMAGE.
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync *
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * @(#)mbuf.h 8.3 (Berkeley) 1/21/94
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * mbuf.h,v 1.9 1994/11/14 13:54:20 bde Exp
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#ifndef _MBUF_H_
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define _MBUF_H_
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_freem m_free
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define MINCSIZE 4096 /* Amount to increase mbuf if too small */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync/*
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * Macros for type conversion
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * mtod(m,t) - convert mbuf pointer to data pointer of correct type
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * dtom(x) - convert data pointer within mbuf to mbuf pointer (XXX)
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define mtod(m,t) ((t)(m)->m_data)
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync/* #define dtom(x) ((struct mbuf *)((int)(x) & ~(M_SIZE-1))) */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync/* XXX About mbufs for slirp:
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * Only one mbuf is ever used in a chain, for each "cell" of data.
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * m_nextpkt points to the next packet, if fragmented.
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * If the data is too large, the M_EXT is used, and a larger block
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * is alloced. Therefore, m_free[m] must check for M_EXT and if set
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * free the m_ext. This is inefficient memory-wise, but who cares.
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync/* XXX should union some of these! */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync/* header at beginning of each mbuf: */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncstruct m_hdr {
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync struct mbuf *mh_next; /* Linked list of mbufs */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync struct mbuf *mh_prev;
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync struct mbuf *mh_nextpkt; /* Next packet in queue/record */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync struct mbuf *mh_prevpkt; /* Flags aren't used in the output queue */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync int mh_flags; /* Misc flags */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync int mh_size; /* Size of data */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync struct socket *mh_so;
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync caddr_t mh_data; /* Location of data */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync int mh_len; /* Amount of data in this mbuf */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#ifdef VBOX_WITH_BSD_REASS
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync void *header; /*XXX: in real BSD sources this field lays in pkthdr structure*/
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#endif
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync};
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync/*
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * How much room is in the mbuf, from m_data to the end of the mbuf
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define M_ROOM(m) ((m->m_flags & M_EXT)? \
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync (((m)->m_ext + (m)->m_size) - (m)->m_data) \
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync : \
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync (((m)->m_dat + (m)->m_size) - (m)->m_data))
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync/*
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * How much free room there is
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len)
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define M_TRAILINGSPACE M_FREEROOM
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncstruct mbuf {
315ad5b8dea4f6f933a01420cfb1e0fe19183c45vboxsync struct m_hdr m_hdr;
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync union M_dat {
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync char m_dat_[1]; /* ANSI don't like 0 sized arrays */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync char *m_ext_;
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync } M_dat;
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync};
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_next m_hdr.mh_next
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync#define m_prev m_hdr.mh_prev
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_nextpkt m_hdr.mh_nextpkt
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_prevpkt m_hdr.mh_prevpkt
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_flags m_hdr.mh_flags
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_len m_hdr.mh_len
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_data m_hdr.mh_data
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_size m_hdr.mh_size
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_dat M_dat.m_dat_
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_ext M_dat.m_ext_
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define m_so m_hdr.mh_so
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define ifq_prev m_prev
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define ifq_next m_next
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define ifs_prev m_prevpkt
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define ifs_next m_nextpkt
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define ifq_so m_so
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define M_EXT 0x01 /* m_ext points to more (malloced) data */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define M_FREELIST 0x02 /* mbuf is on free list */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define M_USEDLIST 0x04 /* XXX mbuf is on used list (for dtom()) */
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync#define M_DOFREE 0x08 /* when m_free is called on the mbuf, free()
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync * it rather than putting it on the free list */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#ifdef VBOX_WITH_BSD_REASS
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define M_FRAG 0x0800 /* packet is a fragment of a larger packet */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define M_FIRSTFRAG 0x1000 /* paket is first fragment */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#define M_LASTFRAG 0x2000 /* paket is last fragment */
315ad5b8dea4f6f933a01420cfb1e0fe19183c45vboxsync#endif /* VBOX_WITH_BSD_REASS */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync/*
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync * Mbuf statistics. XXX
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync */
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncstruct mbstat {
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync int mbs_alloced; /* Number of mbufs allocated */
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync};
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncextern struct mbstat mbstat;
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncextern int mbuf_alloced;
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncextern struct mbuf m_freelist, m_usedlist;
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncextern int mbuf_max;
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsync
315ad5b8dea4f6f933a01420cfb1e0fe19183c45vboxsyncvoid m_init _P((PNATState));
e9a584ee0777ab2612e206eeec264ccb1a8ce333vboxsyncvoid msize_init _P((PNATState));
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncstruct mbuf * m_get _P((PNATState));
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncvoid m_free _P((PNATState, struct mbuf *));
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncvoid m_cat _P((PNATState, register struct mbuf *, register struct mbuf *));
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncvoid m_inc _P((struct mbuf *, int));
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncvoid m_adj _P((struct mbuf *, int));
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncint m_copy _P((struct mbuf *, struct mbuf *, int, int));
e62cb87bae732e9968199a3ad153cc94004b7182vboxsyncstruct mbuf * dtom _P((PNATState, void *));
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync#endif
e62cb87bae732e9968199a3ad153cc94004b7182vboxsync