Statistics
| Branch: | Revision:

root / slirp / mbuf.h @ 460fec67

History | View | Annotate | Download (4.3 kB)

1 f0cbd3ec bellard
/*
2 f0cbd3ec bellard
 * Copyright (c) 1982, 1986, 1988, 1993
3 f0cbd3ec bellard
 *        The Regents of the University of California.  All rights reserved.
4 f0cbd3ec bellard
 *
5 f0cbd3ec bellard
 * Redistribution and use in source and binary forms, with or without
6 f0cbd3ec bellard
 * modification, are permitted provided that the following conditions
7 f0cbd3ec bellard
 * are met:
8 f0cbd3ec bellard
 * 1. Redistributions of source code must retain the above copyright
9 f0cbd3ec bellard
 *    notice, this list of conditions and the following disclaimer.
10 f0cbd3ec bellard
 * 2. Redistributions in binary form must reproduce the above copyright
11 f0cbd3ec bellard
 *    notice, this list of conditions and the following disclaimer in the
12 f0cbd3ec bellard
 *    documentation and/or other materials provided with the distribution.
13 2f5f8996 aliguori
 * 3. Neither the name of the University nor the names of its contributors
14 f0cbd3ec bellard
 *    may be used to endorse or promote products derived from this software
15 f0cbd3ec bellard
 *    without specific prior written permission.
16 f0cbd3ec bellard
 *
17 f0cbd3ec bellard
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 f0cbd3ec bellard
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 f0cbd3ec bellard
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 f0cbd3ec bellard
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 f0cbd3ec bellard
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 f0cbd3ec bellard
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 f0cbd3ec bellard
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 f0cbd3ec bellard
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 f0cbd3ec bellard
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 f0cbd3ec bellard
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 f0cbd3ec bellard
 * SUCH DAMAGE.
28 f0cbd3ec bellard
 *
29 f0cbd3ec bellard
 *        @(#)mbuf.h        8.3 (Berkeley) 1/21/94
30 f0cbd3ec bellard
 * mbuf.h,v 1.9 1994/11/14 13:54:20 bde Exp
31 f0cbd3ec bellard
 */
32 f0cbd3ec bellard
33 f0cbd3ec bellard
#ifndef _MBUF_H_
34 f0cbd3ec bellard
#define _MBUF_H_
35 f0cbd3ec bellard
36 f0cbd3ec bellard
#define m_freem m_free
37 f0cbd3ec bellard
38 f0cbd3ec bellard
39 f0cbd3ec bellard
#define MINCSIZE 4096        /* Amount to increase mbuf if too small */
40 f0cbd3ec bellard
41 f0cbd3ec bellard
/*
42 f0cbd3ec bellard
 * Macros for type conversion
43 f0cbd3ec bellard
 * mtod(m,t) -        convert mbuf pointer to data pointer of correct type
44 f0cbd3ec bellard
 */
45 f0cbd3ec bellard
#define mtod(m,t)        ((t)(m)->m_data)
46 f0cbd3ec bellard
47 f0cbd3ec bellard
/* XXX About mbufs for slirp:
48 f0cbd3ec bellard
 * Only one mbuf is ever used in a chain, for each "cell" of data.
49 f0cbd3ec bellard
 * m_nextpkt points to the next packet, if fragmented.
50 f0cbd3ec bellard
 * If the data is too large, the M_EXT is used, and a larger block
51 f0cbd3ec bellard
 * is alloced.  Therefore, m_free[m] must check for M_EXT and if set
52 f0cbd3ec bellard
 * free the m_ext.  This is inefficient memory-wise, but who cares.
53 f0cbd3ec bellard
 */
54 f0cbd3ec bellard
55 f0cbd3ec bellard
/* XXX should union some of these! */
56 f0cbd3ec bellard
/* header at beginning of each mbuf: */
57 f0cbd3ec bellard
struct m_hdr {
58 f0cbd3ec bellard
        struct        mbuf *mh_next;                /* Linked list of mbufs */
59 f0cbd3ec bellard
        struct        mbuf *mh_prev;
60 f0cbd3ec bellard
        struct        mbuf *mh_nextpkt;        /* Next packet in queue/record */
61 f0cbd3ec bellard
        struct        mbuf *mh_prevpkt; /* Flags aren't used in the output queue */
62 f0cbd3ec bellard
        int        mh_flags;          /* Misc flags */
63 f0cbd3ec bellard
64 f0cbd3ec bellard
        int        mh_size;                /* Size of data */
65 f0cbd3ec bellard
        struct        socket *mh_so;
66 5fafdf24 ths
67 f0cbd3ec bellard
        caddr_t        mh_data;                /* Location of data */
68 f0cbd3ec bellard
        int        mh_len;                        /* Amount of data in this mbuf */
69 f0cbd3ec bellard
};
70 f0cbd3ec bellard
71 5fafdf24 ths
/*
72 f0cbd3ec bellard
 * How much room is in the mbuf, from m_data to the end of the mbuf
73 f0cbd3ec bellard
 */
74 f0cbd3ec bellard
#define M_ROOM(m) ((m->m_flags & M_EXT)? \
75 f0cbd3ec bellard
                        (((m)->m_ext + (m)->m_size) - (m)->m_data) \
76 f0cbd3ec bellard
                   : \
77 f0cbd3ec bellard
                        (((m)->m_dat + (m)->m_size) - (m)->m_data))
78 f0cbd3ec bellard
79 f0cbd3ec bellard
/*
80 f0cbd3ec bellard
 * How much free room there is
81 f0cbd3ec bellard
 */
82 f0cbd3ec bellard
#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len)
83 f0cbd3ec bellard
#define M_TRAILINGSPACE M_FREEROOM
84 f0cbd3ec bellard
85 f0cbd3ec bellard
struct mbuf {
86 f0cbd3ec bellard
        struct        m_hdr m_hdr;
87 460fec67 Jan Kiszka
        Slirp *slirp;
88 f0cbd3ec bellard
        union M_dat {
89 f0cbd3ec bellard
                char        m_dat_[1]; /* ANSI don't like 0 sized arrays */
90 f0cbd3ec bellard
                char        *m_ext_;
91 f0cbd3ec bellard
        } M_dat;
92 f0cbd3ec bellard
};
93 f0cbd3ec bellard
94 f0cbd3ec bellard
#define m_next                m_hdr.mh_next
95 f0cbd3ec bellard
#define m_prev                m_hdr.mh_prev
96 f0cbd3ec bellard
#define m_nextpkt        m_hdr.mh_nextpkt
97 f0cbd3ec bellard
#define m_prevpkt        m_hdr.mh_prevpkt
98 f0cbd3ec bellard
#define m_flags                m_hdr.mh_flags
99 f0cbd3ec bellard
#define        m_len                m_hdr.mh_len
100 f0cbd3ec bellard
#define        m_data                m_hdr.mh_data
101 f0cbd3ec bellard
#define m_size                m_hdr.mh_size
102 f0cbd3ec bellard
#define m_dat                M_dat.m_dat_
103 f0cbd3ec bellard
#define m_ext                M_dat.m_ext_
104 f0cbd3ec bellard
#define m_so                m_hdr.mh_so
105 f0cbd3ec bellard
106 f0cbd3ec bellard
#define ifq_prev m_prev
107 f0cbd3ec bellard
#define ifq_next m_next
108 f0cbd3ec bellard
#define ifs_prev m_prevpkt
109 f0cbd3ec bellard
#define ifs_next m_nextpkt
110 f0cbd3ec bellard
#define ifq_so m_so
111 f0cbd3ec bellard
112 f0cbd3ec bellard
#define M_EXT                        0x01        /* m_ext points to more (malloced) data */
113 f0cbd3ec bellard
#define M_FREELIST                0x02        /* mbuf is on free list */
114 f0cbd3ec bellard
#define M_USEDLIST                0x04        /* XXX mbuf is on used list (for dtom()) */
115 f0cbd3ec bellard
#define M_DOFREE                0x08        /* when m_free is called on the mbuf, free()
116 f0cbd3ec bellard
                                         * it rather than putting it on the free list */
117 f0cbd3ec bellard
118 460fec67 Jan Kiszka
void m_init _P((Slirp *));
119 460fec67 Jan Kiszka
struct mbuf * m_get _P((Slirp *));
120 f0cbd3ec bellard
void m_free _P((struct mbuf *));
121 f0cbd3ec bellard
void m_cat _P((register struct mbuf *, register struct mbuf *));
122 f0cbd3ec bellard
void m_inc _P((struct mbuf *, int));
123 f0cbd3ec bellard
void m_adj _P((struct mbuf *, int));
124 f0cbd3ec bellard
int m_copy _P((struct mbuf *, struct mbuf *, int, int));
125 460fec67 Jan Kiszka
struct mbuf * dtom _P((Slirp *, void *));
126 f0cbd3ec bellard
127 f0cbd3ec bellard
#endif