root / slirp / mbuf.h @ bc2c3909
History | View | Annotate | Download (4.9 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 | f0cbd3ec | bellard | * 3. All advertising materials mentioning features or use of this software
|
14 | f0cbd3ec | bellard | * must display the following acknowledgement:
|
15 | f0cbd3ec | bellard | * This product includes software developed by the University of
|
16 | f0cbd3ec | bellard | * California, Berkeley and its contributors.
|
17 | f0cbd3ec | bellard | * 4. Neither the name of the University nor the names of its contributors
|
18 | f0cbd3ec | bellard | * may be used to endorse or promote products derived from this software
|
19 | f0cbd3ec | bellard | * without specific prior written permission.
|
20 | f0cbd3ec | bellard | *
|
21 | f0cbd3ec | bellard | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
22 | f0cbd3ec | bellard | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23 | f0cbd3ec | bellard | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
24 | f0cbd3ec | bellard | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
25 | f0cbd3ec | bellard | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26 | f0cbd3ec | bellard | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
27 | f0cbd3ec | bellard | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
28 | f0cbd3ec | bellard | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29 | f0cbd3ec | bellard | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
30 | f0cbd3ec | bellard | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
31 | f0cbd3ec | bellard | * SUCH DAMAGE.
|
32 | f0cbd3ec | bellard | *
|
33 | f0cbd3ec | bellard | * @(#)mbuf.h 8.3 (Berkeley) 1/21/94
|
34 | f0cbd3ec | bellard | * mbuf.h,v 1.9 1994/11/14 13:54:20 bde Exp
|
35 | f0cbd3ec | bellard | */
|
36 | f0cbd3ec | bellard | |
37 | f0cbd3ec | bellard | #ifndef _MBUF_H_
|
38 | f0cbd3ec | bellard | #define _MBUF_H_
|
39 | f0cbd3ec | bellard | |
40 | f0cbd3ec | bellard | #define m_freem m_free
|
41 | f0cbd3ec | bellard | |
42 | f0cbd3ec | bellard | |
43 | f0cbd3ec | bellard | #define MINCSIZE 4096 /* Amount to increase mbuf if too small */ |
44 | f0cbd3ec | bellard | |
45 | f0cbd3ec | bellard | /*
|
46 | f0cbd3ec | bellard | * Macros for type conversion
|
47 | f0cbd3ec | bellard | * mtod(m,t) - convert mbuf pointer to data pointer of correct type
|
48 | f0cbd3ec | bellard | * dtom(x) - convert data pointer within mbuf to mbuf pointer (XXX)
|
49 | f0cbd3ec | bellard | */
|
50 | f0cbd3ec | bellard | #define mtod(m,t) ((t)(m)->m_data)
|
51 | f0cbd3ec | bellard | /* #define dtom(x) ((struct mbuf *)((int)(x) & ~(M_SIZE-1))) */
|
52 | f0cbd3ec | bellard | |
53 | f0cbd3ec | bellard | /* XXX About mbufs for slirp:
|
54 | f0cbd3ec | bellard | * Only one mbuf is ever used in a chain, for each "cell" of data.
|
55 | f0cbd3ec | bellard | * m_nextpkt points to the next packet, if fragmented.
|
56 | f0cbd3ec | bellard | * If the data is too large, the M_EXT is used, and a larger block
|
57 | f0cbd3ec | bellard | * is alloced. Therefore, m_free[m] must check for M_EXT and if set
|
58 | f0cbd3ec | bellard | * free the m_ext. This is inefficient memory-wise, but who cares.
|
59 | f0cbd3ec | bellard | */
|
60 | f0cbd3ec | bellard | |
61 | f0cbd3ec | bellard | /* XXX should union some of these! */
|
62 | f0cbd3ec | bellard | /* header at beginning of each mbuf: */
|
63 | f0cbd3ec | bellard | struct m_hdr {
|
64 | f0cbd3ec | bellard | struct mbuf *mh_next; /* Linked list of mbufs */ |
65 | f0cbd3ec | bellard | struct mbuf *mh_prev;
|
66 | f0cbd3ec | bellard | struct mbuf *mh_nextpkt; /* Next packet in queue/record */ |
67 | f0cbd3ec | bellard | struct mbuf *mh_prevpkt; /* Flags aren't used in the output queue */ |
68 | f0cbd3ec | bellard | int mh_flags; /* Misc flags */ |
69 | f0cbd3ec | bellard | |
70 | f0cbd3ec | bellard | int mh_size; /* Size of data */ |
71 | f0cbd3ec | bellard | struct socket *mh_so;
|
72 | f0cbd3ec | bellard | |
73 | f0cbd3ec | bellard | caddr_t mh_data; /* Location of data */
|
74 | f0cbd3ec | bellard | int mh_len; /* Amount of data in this mbuf */ |
75 | f0cbd3ec | bellard | }; |
76 | f0cbd3ec | bellard | |
77 | f0cbd3ec | bellard | /*
|
78 | f0cbd3ec | bellard | * How much room is in the mbuf, from m_data to the end of the mbuf
|
79 | f0cbd3ec | bellard | */
|
80 | f0cbd3ec | bellard | #define M_ROOM(m) ((m->m_flags & M_EXT)? \
|
81 | f0cbd3ec | bellard | (((m)->m_ext + (m)->m_size) - (m)->m_data) \ |
82 | f0cbd3ec | bellard | : \ |
83 | f0cbd3ec | bellard | (((m)->m_dat + (m)->m_size) - (m)->m_data)) |
84 | f0cbd3ec | bellard | |
85 | f0cbd3ec | bellard | /*
|
86 | f0cbd3ec | bellard | * How much free room there is
|
87 | f0cbd3ec | bellard | */
|
88 | f0cbd3ec | bellard | #define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len)
|
89 | f0cbd3ec | bellard | #define M_TRAILINGSPACE M_FREEROOM
|
90 | f0cbd3ec | bellard | |
91 | f0cbd3ec | bellard | struct mbuf {
|
92 | f0cbd3ec | bellard | struct m_hdr m_hdr;
|
93 | f0cbd3ec | bellard | union M_dat {
|
94 | f0cbd3ec | bellard | char m_dat_[1]; /* ANSI don't like 0 sized arrays */ |
95 | f0cbd3ec | bellard | char *m_ext_;
|
96 | f0cbd3ec | bellard | } M_dat; |
97 | f0cbd3ec | bellard | }; |
98 | f0cbd3ec | bellard | |
99 | f0cbd3ec | bellard | #define m_next m_hdr.mh_next
|
100 | f0cbd3ec | bellard | #define m_prev m_hdr.mh_prev
|
101 | f0cbd3ec | bellard | #define m_nextpkt m_hdr.mh_nextpkt
|
102 | f0cbd3ec | bellard | #define m_prevpkt m_hdr.mh_prevpkt
|
103 | f0cbd3ec | bellard | #define m_flags m_hdr.mh_flags
|
104 | f0cbd3ec | bellard | #define m_len m_hdr.mh_len
|
105 | f0cbd3ec | bellard | #define m_data m_hdr.mh_data
|
106 | f0cbd3ec | bellard | #define m_size m_hdr.mh_size
|
107 | f0cbd3ec | bellard | #define m_dat M_dat.m_dat_
|
108 | f0cbd3ec | bellard | #define m_ext M_dat.m_ext_
|
109 | f0cbd3ec | bellard | #define m_so m_hdr.mh_so
|
110 | f0cbd3ec | bellard | |
111 | f0cbd3ec | bellard | #define ifq_prev m_prev
|
112 | f0cbd3ec | bellard | #define ifq_next m_next
|
113 | f0cbd3ec | bellard | #define ifs_prev m_prevpkt
|
114 | f0cbd3ec | bellard | #define ifs_next m_nextpkt
|
115 | f0cbd3ec | bellard | #define ifq_so m_so
|
116 | f0cbd3ec | bellard | |
117 | f0cbd3ec | bellard | #define M_EXT 0x01 /* m_ext points to more (malloced) data */ |
118 | f0cbd3ec | bellard | #define M_FREELIST 0x02 /* mbuf is on free list */ |
119 | f0cbd3ec | bellard | #define M_USEDLIST 0x04 /* XXX mbuf is on used list (for dtom()) */ |
120 | f0cbd3ec | bellard | #define M_DOFREE 0x08 /* when m_free is called on the mbuf, free() |
121 | f0cbd3ec | bellard | * it rather than putting it on the free list */
|
122 | f0cbd3ec | bellard | |
123 | f0cbd3ec | bellard | /*
|
124 | f0cbd3ec | bellard | * Mbuf statistics. XXX
|
125 | f0cbd3ec | bellard | */
|
126 | f0cbd3ec | bellard | |
127 | f0cbd3ec | bellard | struct mbstat {
|
128 | f0cbd3ec | bellard | int mbs_alloced; /* Number of mbufs allocated */ |
129 | f0cbd3ec | bellard | |
130 | f0cbd3ec | bellard | }; |
131 | f0cbd3ec | bellard | |
132 | f0cbd3ec | bellard | extern struct mbstat mbstat; |
133 | f0cbd3ec | bellard | extern int mbuf_alloced; |
134 | f0cbd3ec | bellard | extern struct mbuf m_freelist, m_usedlist; |
135 | f0cbd3ec | bellard | extern int mbuf_max; |
136 | f0cbd3ec | bellard | |
137 | f0cbd3ec | bellard | void m_init _P((void)); |
138 | f0cbd3ec | bellard | void msize_init _P((void)); |
139 | f0cbd3ec | bellard | struct mbuf * m_get _P((void)); |
140 | f0cbd3ec | bellard | void m_free _P((struct mbuf *)); |
141 | f0cbd3ec | bellard | void m_cat _P((register struct mbuf *, register struct mbuf *)); |
142 | f0cbd3ec | bellard | void m_inc _P((struct mbuf *, int)); |
143 | f0cbd3ec | bellard | void m_adj _P((struct mbuf *, int)); |
144 | f0cbd3ec | bellard | int m_copy _P((struct mbuf *, struct mbuf *, int, int)); |
145 | f0cbd3ec | bellard | struct mbuf * dtom _P((void *)); |
146 | f0cbd3ec | bellard | |
147 | f0cbd3ec | bellard | #endif |