uipc_syscalls_43.c revision 1.28.2.4 1 1.28.2.4 ad /* $NetBSD: uipc_syscalls_43.c,v 1.28.2.4 2007/10/09 13:44:03 ad Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 1982, 1986, 1989, 1990, 1993
5 1.1 christos * The Regents of the University of California. All rights reserved.
6 1.1 christos *
7 1.1 christos * Redistribution and use in source and binary forms, with or without
8 1.1 christos * modification, are permitted provided that the following conditions
9 1.1 christos * are met:
10 1.1 christos * 1. Redistributions of source code must retain the above copyright
11 1.1 christos * notice, this list of conditions and the following disclaimer.
12 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 christos * notice, this list of conditions and the following disclaimer in the
14 1.1 christos * documentation and/or other materials provided with the distribution.
15 1.22 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 christos * may be used to endorse or promote products derived from this software
17 1.1 christos * without specific prior written permission.
18 1.1 christos *
19 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 christos * SUCH DAMAGE.
30 1.1 christos *
31 1.1 christos * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94
32 1.1 christos */
33 1.17 lukem
34 1.17 lukem #include <sys/cdefs.h>
35 1.28.2.4 ad __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_43.c,v 1.28.2.4 2007/10/09 13:44:03 ad Exp $");
36 1.1 christos
37 1.1 christos #include <sys/param.h>
38 1.1 christos #include <sys/systm.h>
39 1.1 christos #include <sys/filedesc.h>
40 1.1 christos #include <sys/kernel.h>
41 1.1 christos #include <sys/proc.h>
42 1.1 christos #include <sys/file.h>
43 1.1 christos #include <sys/socket.h>
44 1.1 christos #include <sys/socketvar.h>
45 1.1 christos #include <sys/stat.h>
46 1.1 christos #include <sys/ioctl.h>
47 1.1 christos #include <sys/fcntl.h>
48 1.1 christos #include <sys/malloc.h>
49 1.1 christos #include <sys/syslog.h>
50 1.1 christos #include <sys/unistd.h>
51 1.1 christos #include <sys/resourcevar.h>
52 1.15 jdolecek #include <sys/mbuf.h> /* for MLEN */
53 1.24 christos #include <sys/protosw.h>
54 1.1 christos
55 1.1 christos #include <sys/mount.h>
56 1.1 christos #include <sys/syscallargs.h>
57 1.1 christos
58 1.24 christos #include <net/if.h>
59 1.28.2.4 ad #include <net/bpf.h>
60 1.28.2.4 ad #include <net/route.h>
61 1.28.2.4 ad #include <netinet/in.h>
62 1.28.2.4 ad #include <netinet/in_systm.h>
63 1.28.2.4 ad #include <netinet/ip.h>
64 1.28.2.4 ad #include <net/if_gre.h>
65 1.28.2.4 ad #include <net/if_atm.h>
66 1.28.2.4 ad #include <net/if_tap.h>
67 1.28.2.4 ad #include <netinet6/in6_var.h>
68 1.28.2.4 ad #include <netinet6/nd6.h>
69 1.28.2.1 ad #include <compat/sys/socket.h>
70 1.28.2.1 ad #include <compat/sys/sockio.h>
71 1.24 christos
72 1.15 jdolecek #include <compat/common/compat_util.h>
73 1.15 jdolecek
74 1.15 jdolecek #include <uvm/uvm_extern.h>
75 1.15 jdolecek
76 1.15 jdolecek /*
77 1.15 jdolecek * Following 4.3 syscalls were not versioned, even through they should
78 1.15 jdolecek * have been:
79 1.15 jdolecek * connect(2), bind(2), sendto(2)
80 1.15 jdolecek */
81 1.15 jdolecek
82 1.28 christos static int compat_43_sa_put(void *);
83 1.15 jdolecek
84 1.1 christos int
85 1.19 thorpej compat_43_sys_accept(struct lwp *l, void *v, register_t *retval)
86 1.2 thorpej {
87 1.15 jdolecek struct compat_43_sys_accept_args /* {
88 1.1 christos syscallarg(int) s;
89 1.28 christos syscallarg(void *) name;
90 1.1 christos syscallarg(int *) anamelen;
91 1.2 thorpej } */ *uap = v;
92 1.1 christos int error;
93 1.1 christos
94 1.19 thorpej if ((error = sys_accept(l, v, retval)) != 0)
95 1.1 christos return error;
96 1.1 christos
97 1.15 jdolecek if (SCARG(uap, name)
98 1.15 jdolecek && (error = compat_43_sa_put(SCARG(uap, name))))
99 1.15 jdolecek return (error);
100 1.1 christos
101 1.1 christos return 0;
102 1.1 christos }
103 1.1 christos
104 1.1 christos int
105 1.19 thorpej compat_43_sys_getpeername(struct lwp *l, void *v, register_t *retval)
106 1.2 thorpej {
107 1.15 jdolecek struct compat_43_sys_getpeername_args /* {
108 1.1 christos syscallarg(int) fdes;
109 1.28 christos syscallarg(void *) asa;
110 1.1 christos syscallarg(int *) alen;
111 1.2 thorpej } */ *uap = v;
112 1.1 christos
113 1.1 christos int error;
114 1.1 christos
115 1.19 thorpej if ((error = sys_getpeername(l, v, retval)) != 0)
116 1.1 christos return error;
117 1.1 christos
118 1.15 jdolecek if ((error = compat_43_sa_put(SCARG(uap, asa))))
119 1.15 jdolecek return (error);
120 1.1 christos
121 1.1 christos return 0;
122 1.1 christos }
123 1.1 christos
124 1.1 christos int
125 1.19 thorpej compat_43_sys_getsockname(struct lwp *l, void *v, register_t *retval)
126 1.2 thorpej {
127 1.15 jdolecek struct compat_43_sys_getsockname_args /* {
128 1.1 christos syscallarg(int) fdes;
129 1.28 christos syscallarg(void *) asa;
130 1.1 christos syscallarg(int *) alen;
131 1.2 thorpej } */ *uap = v;
132 1.1 christos int error;
133 1.1 christos
134 1.19 thorpej if ((error = sys_getsockname(l, v, retval)) != 0)
135 1.1 christos return error;
136 1.1 christos
137 1.15 jdolecek if ((error = compat_43_sa_put(SCARG(uap, asa))))
138 1.15 jdolecek return (error);
139 1.1 christos
140 1.1 christos return 0;
141 1.1 christos }
142 1.1 christos
143 1.1 christos int
144 1.19 thorpej compat_43_sys_recv(struct lwp *l, void *v, register_t *retval)
145 1.2 thorpej {
146 1.11 augustss struct compat_43_sys_recv_args /* {
147 1.1 christos syscallarg(int) s;
148 1.28 christos syscallarg(void *) buf;
149 1.1 christos syscallarg(int) len;
150 1.1 christos syscallarg(int) flags;
151 1.2 thorpej } */ *uap = v;
152 1.14 jdolecek struct sys_recvfrom_args bra;
153 1.14 jdolecek
154 1.14 jdolecek SCARG(&bra, s) = SCARG(uap, s);
155 1.14 jdolecek SCARG(&bra, buf) = SCARG(uap, buf);
156 1.14 jdolecek SCARG(&bra, len) = (size_t) SCARG(uap, len);
157 1.14 jdolecek SCARG(&bra, flags) = SCARG(uap, flags);
158 1.14 jdolecek SCARG(&bra, from) = NULL;
159 1.14 jdolecek SCARG(&bra, fromlenaddr) = NULL;
160 1.1 christos
161 1.19 thorpej return (sys_recvfrom(l, &bra, retval));
162 1.1 christos }
163 1.1 christos
164 1.1 christos int
165 1.19 thorpej compat_43_sys_recvfrom(struct lwp *l, void *v, register_t *retval)
166 1.2 thorpej {
167 1.15 jdolecek struct compat_43_sys_recvfrom_args /* {
168 1.1 christos syscallarg(int) s;
169 1.28 christos syscallarg(void *) buf;
170 1.1 christos syscallarg(size_t) len;
171 1.1 christos syscallarg(int) flags;
172 1.28 christos syscallarg(void *) from;
173 1.1 christos syscallarg(int *) fromlenaddr;
174 1.2 thorpej } */ *uap = v;
175 1.15 jdolecek int error;
176 1.15 jdolecek
177 1.19 thorpej if ((error = sys_recvfrom(l, v, retval)))
178 1.15 jdolecek return (error);
179 1.15 jdolecek
180 1.15 jdolecek if (SCARG(uap, from) && (error = compat_43_sa_put(SCARG(uap, from))))
181 1.15 jdolecek return (error);
182 1.1 christos
183 1.15 jdolecek return (0);
184 1.1 christos }
185 1.1 christos
186 1.1 christos /*
187 1.15 jdolecek * Old recvmsg. Arrange necessary structures, calls generic code and
188 1.15 jdolecek * adjusts results accordingly.
189 1.1 christos */
190 1.1 christos int
191 1.19 thorpej compat_43_sys_recvmsg(struct lwp *l, void *v, register_t *retval)
192 1.2 thorpej {
193 1.11 augustss struct compat_43_sys_recvmsg_args /* {
194 1.1 christos syscallarg(int) s;
195 1.1 christos syscallarg(struct omsghdr *) msg;
196 1.1 christos syscallarg(int) flags;
197 1.2 thorpej } */ *uap = v;
198 1.15 jdolecek struct omsghdr omsg;
199 1.1 christos struct msghdr msg;
200 1.28.2.2 ad struct mbuf *from, *control;
201 1.1 christos int error;
202 1.1 christos
203 1.28.2.2 ad error = copyin(SCARG(uap, msg), &omsg, sizeof (struct omsghdr));
204 1.5 christos if (error)
205 1.1 christos return (error);
206 1.23 perry
207 1.28.2.2 ad if (omsg.msg_accrights == NULL)
208 1.28.2.2 ad omsg.msg_accrightslen = 0;
209 1.28.2.2 ad /* it was this way in 4.4BSD */
210 1.28.2.2 ad if (omsg.msg_accrightslen > MLEN)
211 1.28.2.2 ad return EINVAL;
212 1.15 jdolecek
213 1.15 jdolecek msg.msg_name = omsg.msg_name;
214 1.15 jdolecek msg.msg_namelen = omsg.msg_namelen;
215 1.15 jdolecek msg.msg_iovlen = omsg.msg_iovlen;
216 1.28.2.2 ad msg.msg_iov = omsg.msg_iov;
217 1.28.2.2 ad msg.msg_flags = (SCARG(uap, flags) & MSG_USERFLAGS) | MSG_IOVUSRSPACE;
218 1.15 jdolecek
219 1.28.2.2 ad error = do_sys_recvmsg(l, SCARG(uap, s), &msg, &from,
220 1.28.2.2 ad omsg.msg_accrights != NULL ? &control : NULL, retval);
221 1.28.2.2 ad if (error != 0)
222 1.28.2.2 ad return error;
223 1.1 christos
224 1.15 jdolecek /*
225 1.15 jdolecek * If there is any control information and it's SCM_RIGHTS,
226 1.15 jdolecek * pass it back to the program.
227 1.28.2.2 ad * XXX: maybe there can be more than one chunk of control data?
228 1.15 jdolecek */
229 1.28.2.2 ad if (omsg.msg_accrights && control != NULL) {
230 1.28.2.2 ad struct cmsghdr *cmsg = mtod(control, void *);
231 1.23 perry
232 1.28.2.2 ad if (cmsg->cmsg_level == SOL_SOCKET
233 1.28.2.2 ad && cmsg->cmsg_type == SCM_RIGHTS
234 1.28.2.2 ad && cmsg->cmsg_len < omsg.msg_accrightslen
235 1.28.2.2 ad && copyout(CMSG_DATA(cmsg), omsg.msg_accrights,
236 1.28.2.2 ad cmsg->cmsg_len) == 0) {
237 1.28.2.2 ad omsg.msg_accrightslen = cmsg->cmsg_len;
238 1.28.2.2 ad free_control_mbuf(l, control, control->m_next);
239 1.28.2.2 ad } else {
240 1.15 jdolecek omsg.msg_accrightslen = 0;
241 1.28.2.2 ad free_control_mbuf(l, control, control);
242 1.15 jdolecek }
243 1.28.2.2 ad } else
244 1.28.2.2 ad omsg.msg_accrightslen = 0;
245 1.23 perry
246 1.28.2.2 ad if (from != NULL)
247 1.28.2.2 ad /* convert from sockaddr sa_family to osockaddr one here */
248 1.28.2.2 ad mtod(from, struct osockaddr *)->sa_family =
249 1.28.2.2 ad mtod(from, struct sockaddr *)->sa_family;
250 1.28.2.2 ad
251 1.28.2.2 ad error = copyout_sockname(omsg.msg_name, &omsg.msg_namelen, 0, from);
252 1.28.2.2 ad if (from != NULL)
253 1.28.2.2 ad m_free(from);
254 1.15 jdolecek
255 1.28.2.2 ad if (error != 0)
256 1.28.2.2 ad error = copyout(&omsg, SCARG(uap, msg), sizeof(omsg));
257 1.15 jdolecek
258 1.28.2.2 ad return error;
259 1.1 christos }
260 1.1 christos
261 1.1 christos int
262 1.19 thorpej compat_43_sys_send(struct lwp *l, void *v, register_t *retval)
263 1.2 thorpej {
264 1.11 augustss struct compat_43_sys_send_args /* {
265 1.1 christos syscallarg(int) s;
266 1.28 christos syscallarg(void *) buf;
267 1.1 christos syscallarg(int) len;
268 1.1 christos syscallarg(int) flags;
269 1.2 thorpej } */ *uap = v;
270 1.14 jdolecek struct sys_sendto_args bsa;
271 1.14 jdolecek
272 1.14 jdolecek SCARG(&bsa, s) = SCARG(uap, s);
273 1.14 jdolecek SCARG(&bsa, buf) = SCARG(uap, buf);
274 1.14 jdolecek SCARG(&bsa, len) = SCARG(uap, len);
275 1.14 jdolecek SCARG(&bsa, flags) = SCARG(uap, flags);
276 1.14 jdolecek SCARG(&bsa, to) = NULL;
277 1.14 jdolecek SCARG(&bsa, tolen) = 0;
278 1.1 christos
279 1.19 thorpej return (sys_sendto(l, &bsa, retval));
280 1.1 christos }
281 1.1 christos
282 1.28.2.2 ad int
283 1.28.2.2 ad compat43_set_accrights(struct msghdr *msg, void *accrights, int accrightslen)
284 1.28.2.2 ad {
285 1.28.2.2 ad struct cmsghdr *cmsg;
286 1.28.2.2 ad int error;
287 1.28.2.2 ad struct mbuf *ctl;
288 1.28.2.2 ad u_int clen;
289 1.28.2.2 ad
290 1.28.2.2 ad if (accrights == NULL || accrightslen == 0) {
291 1.28.2.2 ad msg->msg_control = NULL;
292 1.28.2.2 ad msg->msg_controllen = 0;
293 1.28.2.2 ad return 0;
294 1.28.2.2 ad }
295 1.28.2.2 ad
296 1.28.2.2 ad clen = CMSG_SPACE(accrightslen);
297 1.28.2.2 ad /* it was (almost) this way in 4.4BSD */
298 1.28.2.2 ad if (accrightslen < 0 || clen > MLEN)
299 1.28.2.2 ad return EINVAL;
300 1.28.2.2 ad
301 1.28.2.2 ad ctl = m_get(M_WAIT, MT_CONTROL);
302 1.28.2.2 ad ctl->m_len = clen;
303 1.28.2.2 ad cmsg = mtod(ctl, void *);
304 1.28.2.2 ad cmsg->cmsg_len = CMSG_SPACE(accrightslen);
305 1.28.2.2 ad cmsg->cmsg_level = SOL_SOCKET;
306 1.28.2.2 ad cmsg->cmsg_type = SCM_RIGHTS;
307 1.28.2.2 ad
308 1.28.2.2 ad error = copyin(accrights, CMSG_DATA(cmsg), accrightslen);
309 1.28.2.2 ad if (error) {
310 1.28.2.2 ad m_free(ctl);
311 1.28.2.2 ad return error;
312 1.28.2.2 ad }
313 1.28.2.2 ad
314 1.28.2.2 ad msg->msg_control = ctl;
315 1.28.2.2 ad msg->msg_controllen = clen;
316 1.28.2.2 ad msg->msg_flags |= MSG_CONTROLMBUF;
317 1.28.2.2 ad return 0;
318 1.28.2.2 ad }
319 1.28.2.2 ad
320 1.15 jdolecek /*
321 1.15 jdolecek * Old sendmsg. Arrange necessary structures, call generic code and
322 1.15 jdolecek * adjust the results accordingly for old code.
323 1.15 jdolecek */
324 1.1 christos int
325 1.19 thorpej compat_43_sys_sendmsg(struct lwp *l, void *v, register_t *retval)
326 1.2 thorpej {
327 1.11 augustss struct compat_43_sys_sendmsg_args /* {
328 1.1 christos syscallarg(int) s;
329 1.28 christos syscallarg(void *) msg;
330 1.1 christos syscallarg(int) flags;
331 1.2 thorpej } */ *uap = v;
332 1.15 jdolecek struct omsghdr omsg;
333 1.1 christos struct msghdr msg;
334 1.1 christos int error;
335 1.28.2.1 ad struct mbuf *nam;
336 1.28.2.1 ad struct osockaddr *osa;
337 1.28.2.1 ad struct sockaddr *sa;
338 1.1 christos
339 1.28.2.1 ad error = copyin(SCARG(uap, msg), &omsg, sizeof (struct omsghdr));
340 1.28.2.1 ad if (error != 0)
341 1.1 christos return (error);
342 1.15 jdolecek
343 1.28.2.1 ad msg.msg_iovlen = omsg.msg_iovlen;
344 1.28.2.1 ad msg.msg_iov = omsg.msg_iov;
345 1.15 jdolecek
346 1.28.2.1 ad error = sockargs(&nam, omsg.msg_name, omsg.msg_namelen, MT_SONAME);
347 1.28.2.1 ad if (error != 0)
348 1.28.2.1 ad return (error);
349 1.15 jdolecek
350 1.28.2.1 ad sa = mtod(nam, void *);
351 1.28.2.1 ad osa = mtod(nam, void *);
352 1.28.2.1 ad sa->sa_family = osa->sa_family;
353 1.28.2.1 ad sa->sa_len = omsg.msg_namelen;
354 1.15 jdolecek
355 1.28.2.1 ad msg.msg_flags = MSG_IOVUSRSPACE | MSG_NAMEMBUF;
356 1.23 perry
357 1.28.2.1 ad msg.msg_name = nam;
358 1.28.2.1 ad msg.msg_namelen = omsg.msg_namelen;
359 1.28.2.2 ad error = compat43_set_accrights(&msg, omsg.msg_accrights,
360 1.28.2.2 ad omsg.msg_accrightslen);
361 1.28.2.2 ad if (error != 0)
362 1.28.2.2 ad goto bad;
363 1.15 jdolecek
364 1.28.2.1 ad return do_sys_sendmsg(l, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
365 1.28.2.1 ad
366 1.28.2.1 ad bad:
367 1.28.2.1 ad if (nam != NULL)
368 1.28.2.1 ad m_free(nam);
369 1.28.2.1 ad
370 1.1 christos return (error);
371 1.15 jdolecek }
372 1.15 jdolecek
373 1.15 jdolecek static int
374 1.15 jdolecek compat_43_sa_put(from)
375 1.28 christos void *from;
376 1.15 jdolecek {
377 1.15 jdolecek struct osockaddr *osa = (struct osockaddr *) from;
378 1.15 jdolecek struct sockaddr sa;
379 1.15 jdolecek struct osockaddr *kosa;
380 1.15 jdolecek int error, len;
381 1.15 jdolecek
382 1.15 jdolecek /*
383 1.15 jdolecek * Only read/write the sockaddr family and length, the rest is
384 1.15 jdolecek * not changed.
385 1.15 jdolecek */
386 1.15 jdolecek len = sizeof(sa.sa_len) + sizeof(sa.sa_family);
387 1.15 jdolecek
388 1.28 christos error = copyin((void *) osa, (void *) &sa, len);
389 1.15 jdolecek if (error)
390 1.15 jdolecek return (error);
391 1.15 jdolecek
392 1.15 jdolecek /* Note: we convert from sockaddr sa_family to osockaddr one here */
393 1.15 jdolecek kosa = (struct osockaddr *) &sa;
394 1.15 jdolecek kosa->sa_family = sa.sa_family;
395 1.15 jdolecek error = copyout(kosa, osa, len);
396 1.15 jdolecek if (error)
397 1.15 jdolecek return (error);
398 1.15 jdolecek
399 1.15 jdolecek return (0);
400 1.1 christos }
401 1.24 christos
402 1.28.2.3 ad u_long
403 1.28.2.3 ad compat_cvtcmd(u_long cmd)
404 1.28.2.3 ad {
405 1.28.2.3 ad u_long ncmd;
406 1.28.2.3 ad
407 1.28.2.4 ad if (IOCPARM_LEN(cmd) != sizeof(struct oifreq))
408 1.28.2.4 ad return cmd;
409 1.28.2.4 ad
410 1.28.2.4 ad ncmd = ((cmd) & ~(IOCPARM_MASK << IOCPARM_SHIFT)) |
411 1.28.2.4 ad (sizeof(struct ifreq) << IOCPARM_SHIFT);
412 1.28.2.4 ad
413 1.28.2.4 ad switch (ncmd) {
414 1.28.2.4 ad case BIOCGETIF:
415 1.28.2.4 ad case BIOCSETIF:
416 1.28.2.4 ad case GREDSOCK:
417 1.28.2.4 ad case GREGADDRD:
418 1.28.2.4 ad case GREGADDRS:
419 1.28.2.4 ad case GREGPROTO:
420 1.28.2.4 ad case GRESADDRD:
421 1.28.2.4 ad case GRESADDRS:
422 1.28.2.4 ad case GRESPROTO:
423 1.28.2.4 ad case GRESSOCK:
424 1.28.2.4 ad case SIOCADDMULTI:
425 1.28.2.4 ad case SIOCDELMULTI:
426 1.28.2.4 ad case SIOCDIFADDR:
427 1.28.2.4 ad case SIOCDIFADDR_IN6:
428 1.28.2.4 ad case SIOCDIFPHYADDR:
429 1.28.2.4 ad case SIOCGDEFIFACE_IN6:
430 1.28.2.4 ad case SIOCGIFADDR:
431 1.28.2.4 ad case SIOCGIFADDR_IN6:
432 1.28.2.4 ad case SIOCGIFAFLAG_IN6:
433 1.28.2.4 ad case SIOCGIFALIFETIME_IN6:
434 1.28.2.4 ad case SIOCGIFBRDADDR:
435 1.28.2.4 ad case SIOCGIFDLT:
436 1.28.2.4 ad case SIOCGIFDSTADDR:
437 1.28.2.4 ad case SIOCGIFDSTADDR_IN6:
438 1.28.2.4 ad case SIOCGIFFLAGS:
439 1.28.2.4 ad case SIOCGIFGENERIC:
440 1.28.2.4 ad case SIOCGIFMETRIC:
441 1.28.2.4 ad case SIOCGIFMTU:
442 1.28.2.4 ad case SIOCGIFNETMASK:
443 1.28.2.4 ad case SIOCGIFNETMASK_IN6:
444 1.28.2.4 ad case SIOCGIFPDSTADDR:
445 1.28.2.4 ad case SIOCGIFPDSTADDR_IN6:
446 1.28.2.4 ad case SIOCGIFPSRCADDR:
447 1.28.2.4 ad case SIOCGIFPSRCADDR_IN6:
448 1.28.2.4 ad case SIOCGIFSTAT_ICMP6:
449 1.28.2.4 ad case SIOCGIFSTAT_IN6:
450 1.28.2.4 ad case SIOCGPVCSIF:
451 1.28.2.4 ad case SIOCGVH:
452 1.28.2.4 ad case SIOCIFCREATE:
453 1.28.2.4 ad case SIOCIFDESTROY:
454 1.28.2.4 ad case SIOCSDEFIFACE_IN6:
455 1.28.2.4 ad case SIOCSIFADDR:
456 1.28.2.4 ad case SIOCSIFADDR_IN6:
457 1.28.2.4 ad case SIOCSIFBRDADDR:
458 1.28.2.4 ad case SIOCSIFDSTADDR:
459 1.28.2.4 ad case SIOCSIFDSTADDR_IN6:
460 1.28.2.4 ad case SIOCSIFFLAGS:
461 1.28.2.4 ad case SIOCSIFGENERIC:
462 1.28.2.4 ad case SIOCSIFMEDIA:
463 1.28.2.4 ad case SIOCSIFMETRIC:
464 1.28.2.4 ad case SIOCSIFMTU:
465 1.28.2.4 ad case SIOCSIFNETMASK:
466 1.28.2.4 ad case SIOCSIFNETMASK_IN6:
467 1.28.2.4 ad case SIOCSNDFLUSH_IN6:
468 1.28.2.4 ad case SIOCSPFXFLUSH_IN6:
469 1.28.2.4 ad case SIOCSPVCSIF:
470 1.28.2.4 ad case SIOCSRTRFLUSH_IN6:
471 1.28.2.4 ad case SIOCSVH:
472 1.28.2.4 ad case TAPGIFNAME:
473 1.28.2.4 ad return ncmd;
474 1.28.2.3 ad }
475 1.28.2.4 ad return cmd;
476 1.28.2.3 ad }
477 1.28.2.3 ad
478 1.24 christos int
479 1.28.2.1 ad compat_ifioctl(struct socket *so, u_long ocmd, u_long cmd, void *data,
480 1.28.2.1 ad struct lwp *l)
481 1.24 christos {
482 1.28.2.1 ad int error;
483 1.28.2.1 ad struct ifreq *ifr = data;
484 1.24 christos struct ifnet *ifp = ifunit(ifr->ifr_name);
485 1.28.2.1 ad struct sockaddr *sa;
486 1.24 christos
487 1.24 christos if (ifp == NULL)
488 1.24 christos return ENXIO;
489 1.24 christos
490 1.28.2.1 ad switch (ocmd) {
491 1.28.2.1 ad case OSIOCSIFADDR:
492 1.28.2.1 ad case OSIOCSIFDSTADDR:
493 1.28.2.1 ad case OSIOCSIFBRDADDR:
494 1.28.2.1 ad case OSIOCSIFNETMASK:
495 1.28.2.1 ad sa = &ifr->ifr_addr;
496 1.24 christos #if BYTE_ORDER != BIG_ENDIAN
497 1.28.2.1 ad if (sa->sa_family == 0 && sa->sa_len < 16) {
498 1.28.2.1 ad sa->sa_family = sa->sa_len;
499 1.28.2.1 ad sa->sa_len = 16;
500 1.24 christos }
501 1.24 christos #else
502 1.28.2.1 ad if (sa->sa_len == 0)
503 1.28.2.1 ad sa->sa_len = 16;
504 1.24 christos #endif
505 1.24 christos break;
506 1.24 christos
507 1.28.2.1 ad case OOSIOCGIFADDR:
508 1.24 christos cmd = SIOCGIFADDR;
509 1.24 christos break;
510 1.24 christos
511 1.28.2.1 ad case OOSIOCGIFDSTADDR:
512 1.24 christos cmd = SIOCGIFDSTADDR;
513 1.24 christos break;
514 1.24 christos
515 1.28.2.1 ad case OOSIOCGIFBRDADDR:
516 1.24 christos cmd = SIOCGIFBRDADDR;
517 1.24 christos break;
518 1.24 christos
519 1.28.2.1 ad case OOSIOCGIFNETMASK:
520 1.24 christos cmd = SIOCGIFNETMASK;
521 1.24 christos }
522 1.24 christos
523 1.24 christos error = (*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
524 1.28.2.1 ad (struct mbuf *)cmd, (struct mbuf *)ifr, (struct mbuf *)ifp, l);
525 1.24 christos
526 1.24 christos switch (ocmd) {
527 1.28.2.1 ad case OOSIOCGIFADDR:
528 1.28.2.1 ad case OOSIOCGIFDSTADDR:
529 1.28.2.1 ad case OOSIOCGIFBRDADDR:
530 1.28.2.1 ad case OOSIOCGIFNETMASK:
531 1.28.2.1 ad *(u_int16_t *)&ifr->ifr_addr =
532 1.28.2.1 ad ((struct sockaddr *)&ifr->ifr_addr)->sa_family;
533 1.24 christos }
534 1.24 christos return error;
535 1.24 christos }
536