Print this page
11227 smb code needs smatch fixes
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/smbsrv/mbuf.h
+++ new/usr/src/uts/common/smbsrv/mbuf.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 + * Copyright 2019 Joyent, Inc.
22 23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
23 24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 25 * Use is subject to license terms.
25 26 */
26 27 /*
27 28 * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
28 29 * All rights reserved.
29 30 *
30 31 * Redistribution and use in source and binary forms, with or without
31 32 * modification, are permitted provided that the following conditions
32 33 * are met:
33 34 * 1. Redistributions of source code must retain the above copyright
34 35 * notice, this list of conditions and the following disclaimer.
35 36 * 2. Redistributions in binary form must reproduce the above copyright
36 37 * notice, this list of conditions and the following disclaimer in the
37 38 * documentation and/or other materials provided with the distribution.
38 39 * 3. All advertising materials mentioning features or use of this software
39 40 * must display the following acknowledgement:
40 41 * This product includes software developed by the University of
41 42 * California, Berkeley and its contributors.
42 43 * 4. Neither the name of the University nor the names of its contributors
43 44 * may be used to endorse or promote products derived from this software
44 45 * without specific prior written permission.
45 46 *
46 47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 57 * SUCH DAMAGE.
57 58 *
58 59 */
59 60
60 61 #ifndef _SMBSRV_MBUF_H
61 62 #define _SMBSRV_MBUF_H
62 63
63 64 /*
64 65 * This mbuf simulation should be replaced with (native) mblk_t support.
65 66 */
66 67
67 68 #include <sys/types.h>
68 69 #include <sys/param.h>
69 70 #include <sys/kmem.h>
70 71 #include <smbsrv/string.h>
71 72
72 73 #ifdef __cplusplus
73 74 extern "C" {
74 75 #endif
75 76
76 77 #define MSIZE 256
77 78 #define MCLBYTES 8192
78 79
79 80 /*
80 81 * Mbufs are of a single size, MSIZE (machine/machparam.h), which
81 82 * includes overhead. An mbuf may add a single "mbuf cluster" of size
82 83 * MCLBYTES (also in machine/machparam.h), which has no additional overhead
83 84 * and is used instead of the internal data area; this is done when
84 85 * at least MINCLSIZE of data must be stored.
85 86 */
86 87
87 88 #define MLEN (MSIZE - sizeof (struct m_hdr)) /* normal data len */
88 89 #define MHLEN (MLEN - sizeof (struct pkthdr)) /* data len w/pkthdr */
89 90
90 91 #define MINCLSIZE (MHLEN + MLEN) /* smallest amount to put in cluster */
91 92
92 93 /*
93 94 * Macros for type conversion
94 95 * mtod(m,t) - convert mbuf pointer to data pointer of correct type
95 96 */
96 97 #define mtod(m, t) ((t)((m)->m_data))
97 98
98 99
99 100 /* header at beginning of each mbuf: */
100 101 struct m_hdr {
101 102 struct mbuf *mh_next; /* next buffer in chain */
102 103 struct mbuf *mh_nextpkt; /* next chain in queue/record */
103 104 int mh_len; /* amount of data in this mbuf */
104 105 caddr_t mh_data; /* location of data */
105 106 short mh_type; /* type of data in this mbuf */
106 107 short mh_flags; /* flags; see below */
107 108 };
108 109
109 110 /* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
110 111 struct pkthdr {
111 112 int len; /* total packet length */
112 113 };
113 114
114 115
115 116 /* description of external storage mapped into mbuf, valid if M_EXT set */
116 117 struct m_ext {
117 118 caddr_t ext_buf; /* start of buffer */
118 119 int (*ext_ref)(); /* refcount adjust function */
119 120 uint_t ext_size; /* size of buffer, for ext_free */
120 121 };
121 122
122 123 typedef struct mbuf {
123 124 struct m_hdr m_hdr;
124 125 union {
125 126 struct {
126 127 struct pkthdr MH_pkthdr; /* M_PKTHDR set */
127 128 union {
128 129 struct m_ext MH_ext; /* M_EXT set */
129 130 char MH_databuf[MHLEN];
130 131 } MH_dat;
131 132 } MH;
132 133 char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
133 134 } M_dat;
134 135 } mbuf_t;
135 136
136 137 #define m_next m_hdr.mh_next
137 138 #define m_len m_hdr.mh_len
138 139 #define m_data m_hdr.mh_data
139 140 #define m_type m_hdr.mh_type
140 141 #define m_flags m_hdr.mh_flags
141 142 #define m_nextpkt m_hdr.mh_nextpkt
142 143 #define m_act m_nextpkt
143 144 #define m_pkthdr M_dat.MH.MH_pkthdr
144 145 #define m_ext M_dat.MH.MH_dat.MH_ext
145 146 #define m_pktdat M_dat.MH.MH_dat.MH_databuf
146 147 #define m_dat M_dat.M_databuf
147 148
148 149 /* mbuf flags */
149 150 #define M_EXT 0x0001 /* has associated external storage */
150 151 #define M_PKTHDR 0x0002 /* start of record */
151 152 #define M_EOR 0x0004 /* end of record */
152 153
153 154 /* mbuf pkthdr flags, also in m_flags */
154 155 #define M_BCAST 0x0100 /* send/received as link-level broadcast */
155 156 #define M_MCAST 0x0200 /* send/received as link-level multicast */
156 157
157 158 /* flags copied when copying m_pkthdr */
158 159 #define M_COPYFLAGS (M_PKTHDR|M_EOR|M_BCAST|M_MCAST)
159 160
160 161 /* XXX probably only need MT_DATA */
161 162
162 163 /* mbuf types */
163 164 #define MT_FREE 0 /* should be on free list */
164 165 #define MT_DATA 1 /* dynamic (data) allocation */
165 166 #define MT_HEADER 2 /* packet header */
166 167 #define MT_SOCKET 3 /* socket structure */
167 168 #define MT_PCB 4 /* protocol control block */
168 169 #define MT_RTABLE 5 /* routing tables */
169 170 #define MT_HTABLE 6 /* IMP host tables */
170 171 #define MT_ATABLE 7 /* address resolution tables */
171 172 #define MT_SONAME 8 /* socket name */
172 173 #define MT_SOOPTS 10 /* socket options */
173 174 #define MT_FTABLE 11 /* fragment reassembly header */
174 175 #define MT_RIGHTS 12 /* access rights */
175 176 #define MT_IFADDR 13 /* interface address */
176 177 #define MT_CONTROL 14 /* extra-data protocol message */
177 178 #define MT_OOBDATA 15 /* expedited data */
178 179
179 180 /*
180 181 * flags to malloc: PBSHORTCUT
181 182 */
182 183 #define M_WAITOK 0x0000
183 184 #define M_NOWAIT 0x0001
184 185
185 186 /* flags to m_get/MGET */
186 187 #define M_DONTWAIT M_NOWAIT
187 188 #define M_WAIT M_WAITOK
188 189
189 190
190 191 /*
191 192 * mbuf allocation/deallocation macros:
192 193 *
193 194 * MGET(struct mbuf *m, int how, int type)
194 195 * allocates an mbuf and initializes it to contain internal data.
195 196 *
196 197 * MGETHDR(struct mbuf *m, int how, int type)
197 198 * allocates an mbuf and initializes it to contain a packet header
198 199 * and internal data.
199 200 */
200 201
201 202 #define MGET(m, how, type) { \
202 203 m = smb_mbuf_alloc(); \
203 204 (m)->m_next = (struct mbuf *)NULL; \
204 205 (m)->m_nextpkt = (struct mbuf *)NULL; \
205 206 (m)->m_data = (m)->m_dat; \
206 207 (m)->m_flags = 0; \
207 208 (m)->m_type = (short)(type); \
208 209 }
209 210
210 211 #define MGETHDR(m, how, type) { \
211 212 m = smb_mbuf_alloc(); \
212 213 (m)->m_type = (MT_HEADER); \
213 214 (m)->m_next = (struct mbuf *)NULL; \
214 215 (m)->m_nextpkt = (struct mbuf *)NULL; \
215 216 (m)->m_data = (m)->m_pktdat; \
216 217 (m)->m_flags = M_PKTHDR; \
217 218 }
218 219
219 220 #define MCLGET(m, how) \
220 221 { \
221 222 (m)->m_ext.ext_buf = smb_mbufcl_alloc(); \
222 223 (m)->m_data = (m)->m_ext.ext_buf; \
223 224 (m)->m_flags |= M_EXT; \
224 225 (m)->m_ext.ext_size = MCLBYTES; \
↓ open down ↓ |
193 lines elided |
↑ open up ↑ |
225 226 (m)->m_ext.ext_ref = smb_mbufcl_ref; \
226 227 }
227 228
228 229 /*
229 230 * MFREE(struct mbuf *m, struct mbuf *nn)
230 231 * Free a single mbuf and associated external storage.
231 232 * Place the successor, if any, in nn.
232 233 */
233 234 #define MFREE(m, nn) \
234 235 { \
235 - if ((m)->m_flags & M_EXT) { \
236 - (*((m)->m_ext.ext_ref))((m)->m_ext.ext_buf, \
236 + if ((m)->m_flags & M_EXT) { \
237 + (void) (*((m)->m_ext.ext_ref)) \
238 + ((m)->m_ext.ext_buf, \
237 239 (m)->m_ext.ext_size, -1); \
238 240 (m)->m_ext.ext_buf = 0; \
239 241 } \
240 242 (nn) = (m)->m_next; \
241 243 (m)->m_next = 0; \
242 244 smb_mbuf_free(m); \
243 245 }
244 246
245 247
246 248
247 249 /*
248 250 * As above, for mbufs allocated with m_gethdr/MGETHDR
249 251 * or initialized by M_COPY_PKTHDR.
250 252 */
251 253 #define MH_ALIGN(m, len) \
252 254 { (m)->m_data += (MHLEN - (len)) &~ (sizeof (int32_t) - 1); }
253 255
254 256 #define SMB_MBC_MAGIC 0x4D42435F
255 257 #define SMB_MBC_VALID(p) ASSERT((p)->mbc_magic == SMB_MBC_MAGIC)
256 258
257 259 typedef struct mbuf_chain {
258 260 uint32_t mbc_magic;
259 261 volatile uint32_t flags; /* Various flags */
260 262 struct mbuf_chain *shadow_of; /* I'm shadowing someone */
261 263 mbuf_t *chain; /* Start of chain */
262 264 int32_t max_bytes; /* max # of bytes for chain */
263 265 int32_t chain_offset; /* Current offset into chain */
264 266 } mbuf_chain_t;
265 267
266 268 mbuf_t *smb_mbuf_alloc(void);
267 269 void smb_mbuf_free(mbuf_t *);
268 270
269 271 void *smb_mbufcl_alloc(void);
270 272 void smb_mbufcl_free(void *);
271 273 int smb_mbufcl_ref(void *, uint_t, int);
272 274
273 275 mbuf_t *m_free(mbuf_t *);
274 276 void m_freem(mbuf_t *);
275 277 void smb_mbc_init(void);
276 278 void smb_mbc_fini(void);
277 279 mbuf_chain_t *smb_mbc_alloc(uint32_t);
278 280 void smb_mbc_free(mbuf_chain_t *);
279 281
280 282 #ifdef __cplusplus
281 283 }
282 284 #endif
283 285
284 286 #endif /* _SMBSRV_MBUF_H */
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX