Statistics
| Branch: | Revision:

root / slirp / mbuf.h @ 0087375e

History | View | Annotate | Download (4.6 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
 * dtom(x) -        convert data pointer within mbuf to mbuf pointer (XXX)
45 f0cbd3ec bellard
 */
46 f0cbd3ec bellard
#define mtod(m,t)        ((t)(m)->m_data)
47 f0cbd3ec bellard
/* #define        dtom(x)                ((struct mbuf *)((int)(x) & ~(M_SIZE-1))) */
48 f0cbd3ec bellard
49 f0cbd3ec bellard
/* XXX About mbufs for slirp:
50 f0cbd3ec bellard
 * Only one mbuf is ever used in a chain, for each "cell" of data.
51 f0cbd3ec bellard
 * m_nextpkt points to the next packet, if fragmented.
52 f0cbd3ec bellard
 * If the data is too large, the M_EXT is used, and a larger block
53 f0cbd3ec bellard
 * is alloced.  Therefore, m_free[m] must check for M_EXT and if set
54 f0cbd3ec bellard
 * free the m_ext.  This is inefficient memory-wise, but who cares.
55 f0cbd3ec bellard
 */
56 f0cbd3ec bellard
57 f0cbd3ec bellard
/* XXX should union some of these! */
58 f0cbd3ec bellard
/* header at beginning of each mbuf: */
59 f0cbd3ec bellard
struct m_hdr {
60 f0cbd3ec bellard
        struct        mbuf *mh_next;                /* Linked list of mbufs */
61 f0cbd3ec bellard
        struct        mbuf *mh_prev;
62 f0cbd3ec bellard
        struct        mbuf *mh_nextpkt;        /* Next packet in queue/record */
63 f0cbd3ec bellard
        struct        mbuf *mh_prevpkt; /* Flags aren't used in the output queue */
64 f0cbd3ec bellard
        int        mh_flags;          /* Misc flags */
65 f0cbd3ec bellard
66 f0cbd3ec bellard
        int        mh_size;                /* Size of data */
67 f0cbd3ec bellard
        struct        socket *mh_so;
68 5fafdf24 ths
69 f0cbd3ec bellard
        caddr_t        mh_data;                /* Location of data */
70 f0cbd3ec bellard
        int        mh_len;                        /* Amount of data in this mbuf */
71 f0cbd3ec bellard
};
72 f0cbd3ec bellard
73 5fafdf24 ths
/*
74 f0cbd3ec bellard
 * How much room is in the mbuf, from m_data to the end of the mbuf
75 f0cbd3ec bellard
 */
76 f0cbd3ec bellard
#define M_ROOM(m) ((m->m_flags & M_EXT)? \
77 f0cbd3ec bellard
                        (((m)->m_ext + (m)->m_size) - (m)->m_data) \
78 f0cbd3ec bellard
                   : \
79 f0cbd3ec bellard
                        (((m)->m_dat + (m)->m_size) - (m)->m_data))
80 f0cbd3ec bellard
81 f0cbd3ec bellard
/*
82 f0cbd3ec bellard
 * How much free room there is
83 f0cbd3ec bellard
 */
84 f0cbd3ec bellard
#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len)
85 f0cbd3ec bellard
#define M_TRAILINGSPACE M_FREEROOM
86 f0cbd3ec bellard
87 f0cbd3ec bellard
struct mbuf {
88 f0cbd3ec bellard
        struct        m_hdr m_hdr;
89 f0cbd3ec bellard
        union M_dat {
90 f0cbd3ec bellard
                char        m_dat_[1]; /* ANSI don't like 0 sized arrays */
91 f0cbd3ec bellard
                char        *m_ext_;
92 f0cbd3ec bellard
        } M_dat;
93 f0cbd3ec bellard
};
94 f0cbd3ec bellard
95 f0cbd3ec bellard
#define m_next                m_hdr.mh_next
96 f0cbd3ec bellard
#define m_prev                m_hdr.mh_prev
97 f0cbd3ec bellard
#define m_nextpkt        m_hdr.mh_nextpkt
98 f0cbd3ec bellard
#define m_prevpkt        m_hdr.mh_prevpkt
99 f0cbd3ec bellard
#define m_flags                m_hdr.mh_flags
100 f0cbd3ec bellard
#define        m_len                m_hdr.mh_len
101 f0cbd3ec bellard
#define        m_data                m_hdr.mh_data
102 f0cbd3ec bellard
#define m_size                m_hdr.mh_size
103 f0cbd3ec bellard
#define m_dat                M_dat.m_dat_
104 f0cbd3ec bellard
#define m_ext                M_dat.m_ext_
105 f0cbd3ec bellard
#define m_so                m_hdr.mh_so
106 f0cbd3ec bellard
107 f0cbd3ec bellard
#define ifq_prev m_prev
108 f0cbd3ec bellard
#define ifq_next m_next
109 f0cbd3ec bellard
#define ifs_prev m_prevpkt
110 f0cbd3ec bellard
#define ifs_next m_nextpkt
111 f0cbd3ec bellard
#define ifq_so m_so
112 f0cbd3ec bellard
113 f0cbd3ec bellard
#define M_EXT                        0x01        /* m_ext points to more (malloced) data */
114 f0cbd3ec bellard
#define M_FREELIST                0x02        /* mbuf is on free list */
115 f0cbd3ec bellard
#define M_USEDLIST                0x04        /* XXX mbuf is on used list (for dtom()) */
116 f0cbd3ec bellard
#define M_DOFREE                0x08        /* when m_free is called on the mbuf, free()
117 f0cbd3ec bellard
                                         * it rather than putting it on the free list */
118 f0cbd3ec bellard
119 f0cbd3ec bellard
/*
120 f0cbd3ec bellard
 * Mbuf statistics. XXX
121 f0cbd3ec bellard
 */
122 f0cbd3ec bellard
123 f0cbd3ec bellard
struct mbstat {
124 f0cbd3ec bellard
        int mbs_alloced;                /* Number of mbufs allocated */
125 5fafdf24 ths
126 f0cbd3ec bellard
};
127 f0cbd3ec bellard
128 f0cbd3ec bellard
extern struct        mbstat mbstat;
129 f0cbd3ec bellard
extern int mbuf_alloced;
130 f0cbd3ec bellard
extern struct mbuf m_freelist, m_usedlist;
131 f0cbd3ec bellard
extern int mbuf_max;
132 f0cbd3ec bellard
133 f0cbd3ec bellard
void m_init _P((void));
134 f0cbd3ec bellard
struct mbuf * m_get _P((void));
135 f0cbd3ec bellard
void m_free _P((struct mbuf *));
136 f0cbd3ec bellard
void m_cat _P((register struct mbuf *, register struct mbuf *));
137 f0cbd3ec bellard
void m_inc _P((struct mbuf *, int));
138 f0cbd3ec bellard
void m_adj _P((struct mbuf *, int));
139 f0cbd3ec bellard
int m_copy _P((struct mbuf *, struct mbuf *, int, int));
140 f0cbd3ec bellard
struct mbuf * dtom _P((void *));
141 f0cbd3ec bellard
142 f0cbd3ec bellard
#endif