Statistics
| Branch: | Revision:

root / slirp / mbuf.h @ 19bf7c87

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 MINCSIZE 4096        /* Amount to increase mbuf if too small */
37 f0cbd3ec bellard
38 f0cbd3ec bellard
/*
39 f0cbd3ec bellard
 * Macros for type conversion
40 f0cbd3ec bellard
 * mtod(m,t) -        convert mbuf pointer to data pointer of correct type
41 f0cbd3ec bellard
 */
42 f0cbd3ec bellard
#define mtod(m,t)        ((t)(m)->m_data)
43 f0cbd3ec bellard
44 f0cbd3ec bellard
/* XXX About mbufs for slirp:
45 f0cbd3ec bellard
 * Only one mbuf is ever used in a chain, for each "cell" of data.
46 f0cbd3ec bellard
 * m_nextpkt points to the next packet, if fragmented.
47 f0cbd3ec bellard
 * If the data is too large, the M_EXT is used, and a larger block
48 f0cbd3ec bellard
 * is alloced.  Therefore, m_free[m] must check for M_EXT and if set
49 f0cbd3ec bellard
 * free the m_ext.  This is inefficient memory-wise, but who cares.
50 f0cbd3ec bellard
 */
51 f0cbd3ec bellard
52 f0cbd3ec bellard
/* XXX should union some of these! */
53 f0cbd3ec bellard
/* header at beginning of each mbuf: */
54 f0cbd3ec bellard
struct m_hdr {
55 f0cbd3ec bellard
        struct        mbuf *mh_next;                /* Linked list of mbufs */
56 f0cbd3ec bellard
        struct        mbuf *mh_prev;
57 f0cbd3ec bellard
        struct        mbuf *mh_nextpkt;        /* Next packet in queue/record */
58 f0cbd3ec bellard
        struct        mbuf *mh_prevpkt; /* Flags aren't used in the output queue */
59 f0cbd3ec bellard
        int        mh_flags;          /* Misc flags */
60 f0cbd3ec bellard
61 f0cbd3ec bellard
        int        mh_size;                /* Size of data */
62 f0cbd3ec bellard
        struct        socket *mh_so;
63 5fafdf24 ths
64 f0cbd3ec bellard
        caddr_t        mh_data;                /* Location of data */
65 f0cbd3ec bellard
        int        mh_len;                        /* Amount of data in this mbuf */
66 f0cbd3ec bellard
};
67 f0cbd3ec bellard
68 5fafdf24 ths
/*
69 f0cbd3ec bellard
 * How much room is in the mbuf, from m_data to the end of the mbuf
70 f0cbd3ec bellard
 */
71 f0cbd3ec bellard
#define M_ROOM(m) ((m->m_flags & M_EXT)? \
72 f0cbd3ec bellard
                        (((m)->m_ext + (m)->m_size) - (m)->m_data) \
73 f0cbd3ec bellard
                   : \
74 f0cbd3ec bellard
                        (((m)->m_dat + (m)->m_size) - (m)->m_data))
75 f0cbd3ec bellard
76 f0cbd3ec bellard
/*
77 f0cbd3ec bellard
 * How much free room there is
78 f0cbd3ec bellard
 */
79 f0cbd3ec bellard
#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len)
80 f0cbd3ec bellard
#define M_TRAILINGSPACE M_FREEROOM
81 f0cbd3ec bellard
82 f0cbd3ec bellard
struct mbuf {
83 f0cbd3ec bellard
        struct        m_hdr m_hdr;
84 460fec67 Jan Kiszka
        Slirp *slirp;
85 2b440432 Thomas Huth
        bool        arp_requested;
86 2b440432 Thomas Huth
        uint64_t expiration_date;
87 2b440432 Thomas Huth
        /* start of dynamic buffer area, must be last element */
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 6cb9c6d3 Blue Swirl
void m_init(Slirp *);
119 6cb9c6d3 Blue Swirl
struct mbuf * m_get(Slirp *);
120 6cb9c6d3 Blue Swirl
void m_free(struct mbuf *);
121 6cb9c6d3 Blue Swirl
void m_cat(register struct mbuf *, register struct mbuf *);
122 6cb9c6d3 Blue Swirl
void m_inc(struct mbuf *, int);
123 6cb9c6d3 Blue Swirl
void m_adj(struct mbuf *, int);
124 6cb9c6d3 Blue Swirl
int m_copy(struct mbuf *, struct mbuf *, int, int);
125 6cb9c6d3 Blue Swirl
struct mbuf * dtom(Slirp *, void *);
126 f0cbd3ec bellard
127 f0cbd3ec bellard
#endif