Home | History | Annotate | Line # | Download | only in common
uipc_syscalls_43.c revision 1.37.6.1
      1  1.37.6.1       mjf /*	$NetBSD: uipc_syscalls_43.c,v 1.37.6.1 2008/02/18 21:05:22 mjf 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.37.6.1       mjf __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_43.c,v 1.37.6.1 2008/02/18 21:05:22 mjf 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.29  christos #include <net/if.h>
     59      1.35    martin #include <net/bpf.h>
     60      1.35    martin #include <net/route.h>
     61      1.35    martin #include <netinet/in.h>
     62      1.35    martin #include <netinet/in_systm.h>
     63      1.35    martin #include <netinet/ip.h>
     64      1.35    martin #include <net/if_gre.h>
     65      1.35    martin #include <net/if_atm.h>
     66      1.35    martin #include <net/if_tap.h>
     67  1.37.6.1       mjf #include <net80211/ieee80211_ioctl.h>
     68      1.35    martin #include <netinet6/in6_var.h>
     69      1.35    martin #include <netinet6/nd6.h>
     70      1.24  christos #include <compat/sys/socket.h>
     71      1.29  christos #include <compat/sys/sockio.h>
     72      1.24  christos 
     73      1.15  jdolecek #include <compat/common/compat_util.h>
     74      1.15  jdolecek 
     75      1.15  jdolecek #include <uvm/uvm_extern.h>
     76      1.15  jdolecek 
     77      1.15  jdolecek /*
     78      1.15  jdolecek  * Following 4.3 syscalls were not versioned, even through they should
     79      1.15  jdolecek  * have been:
     80      1.15  jdolecek  * connect(2), bind(2), sendto(2)
     81      1.15  jdolecek  */
     82      1.15  jdolecek 
     83      1.28  christos static int compat_43_sa_put(void *);
     84      1.15  jdolecek 
     85       1.1  christos int
     86      1.19   thorpej compat_43_sys_accept(struct lwp *l, void *v, register_t *retval)
     87       1.2   thorpej {
     88      1.15  jdolecek 	struct compat_43_sys_accept_args /* {
     89       1.1  christos 		syscallarg(int) s;
     90      1.28  christos 		syscallarg(void *) name;
     91       1.1  christos 		syscallarg(int *) anamelen;
     92       1.2   thorpej 	} */ *uap = v;
     93       1.1  christos 	int error;
     94       1.1  christos 
     95      1.19   thorpej 	if ((error = sys_accept(l, v, retval)) != 0)
     96       1.1  christos 		return error;
     97       1.1  christos 
     98      1.15  jdolecek 	if (SCARG(uap, name)
     99      1.15  jdolecek 	    && (error = compat_43_sa_put(SCARG(uap, name))))
    100      1.15  jdolecek 		return (error);
    101       1.1  christos 
    102       1.1  christos 	return 0;
    103       1.1  christos }
    104       1.1  christos 
    105       1.1  christos int
    106      1.19   thorpej compat_43_sys_getpeername(struct lwp *l, void *v, register_t *retval)
    107       1.2   thorpej {
    108      1.15  jdolecek 	struct compat_43_sys_getpeername_args /* {
    109       1.1  christos 		syscallarg(int) fdes;
    110      1.28  christos 		syscallarg(void *) asa;
    111       1.1  christos 		syscallarg(int *) alen;
    112       1.2   thorpej 	} */ *uap = v;
    113       1.1  christos 
    114       1.1  christos 	int error;
    115       1.1  christos 
    116      1.19   thorpej 	if ((error = sys_getpeername(l, v, retval)) != 0)
    117       1.1  christos 		return error;
    118       1.1  christos 
    119      1.15  jdolecek 	if ((error = compat_43_sa_put(SCARG(uap, asa))))
    120      1.15  jdolecek 		return (error);
    121       1.1  christos 
    122       1.1  christos 	return 0;
    123       1.1  christos }
    124       1.1  christos 
    125       1.1  christos int
    126      1.19   thorpej compat_43_sys_getsockname(struct lwp *l, void *v, register_t *retval)
    127       1.2   thorpej {
    128      1.15  jdolecek 	struct compat_43_sys_getsockname_args /* {
    129       1.1  christos 		syscallarg(int) fdes;
    130      1.28  christos 		syscallarg(void *) asa;
    131       1.1  christos 		syscallarg(int *) alen;
    132       1.2   thorpej 	} */ *uap = v;
    133       1.1  christos 	int error;
    134       1.1  christos 
    135      1.19   thorpej 	if ((error = sys_getsockname(l, v, retval)) != 0)
    136       1.1  christos 		return error;
    137       1.1  christos 
    138      1.15  jdolecek 	if ((error = compat_43_sa_put(SCARG(uap, asa))))
    139      1.15  jdolecek 		return (error);
    140       1.1  christos 
    141       1.1  christos 	return 0;
    142       1.1  christos }
    143       1.1  christos 
    144       1.1  christos int
    145      1.19   thorpej compat_43_sys_recv(struct lwp *l, void *v, register_t *retval)
    146       1.2   thorpej {
    147      1.11  augustss 	struct compat_43_sys_recv_args /* {
    148       1.1  christos 		syscallarg(int) s;
    149      1.28  christos 		syscallarg(void *) buf;
    150       1.1  christos 		syscallarg(int) len;
    151       1.1  christos 		syscallarg(int) flags;
    152       1.2   thorpej 	} */ *uap = v;
    153      1.14  jdolecek 	struct sys_recvfrom_args bra;
    154      1.14  jdolecek 
    155      1.14  jdolecek 	SCARG(&bra, s) = SCARG(uap, s);
    156      1.14  jdolecek 	SCARG(&bra, buf) = SCARG(uap, buf);
    157      1.14  jdolecek 	SCARG(&bra, len) = (size_t) SCARG(uap, len);
    158      1.14  jdolecek 	SCARG(&bra, flags) = SCARG(uap, flags);
    159      1.14  jdolecek 	SCARG(&bra, from) = NULL;
    160      1.14  jdolecek 	SCARG(&bra, fromlenaddr) = NULL;
    161       1.1  christos 
    162      1.19   thorpej 	return (sys_recvfrom(l, &bra, retval));
    163       1.1  christos }
    164       1.1  christos 
    165       1.1  christos int
    166      1.19   thorpej compat_43_sys_recvfrom(struct lwp *l, void *v, register_t *retval)
    167       1.2   thorpej {
    168      1.15  jdolecek 	struct compat_43_sys_recvfrom_args /* {
    169       1.1  christos 		syscallarg(int) s;
    170      1.28  christos 		syscallarg(void *) buf;
    171       1.1  christos 		syscallarg(size_t) len;
    172       1.1  christos 		syscallarg(int) flags;
    173      1.28  christos 		syscallarg(void *) from;
    174       1.1  christos 		syscallarg(int *) fromlenaddr;
    175       1.2   thorpej 	} */ *uap = v;
    176      1.15  jdolecek 	int error;
    177      1.15  jdolecek 
    178      1.19   thorpej 	if ((error = sys_recvfrom(l, v, retval)))
    179      1.15  jdolecek 		return (error);
    180      1.15  jdolecek 
    181      1.15  jdolecek 	if (SCARG(uap, from) && (error = compat_43_sa_put(SCARG(uap, from))))
    182      1.15  jdolecek 		return (error);
    183       1.1  christos 
    184      1.15  jdolecek 	return (0);
    185       1.1  christos }
    186       1.1  christos 
    187       1.1  christos /*
    188      1.15  jdolecek  * Old recvmsg. Arrange necessary structures, calls generic code and
    189      1.15  jdolecek  * adjusts results accordingly.
    190       1.1  christos  */
    191       1.1  christos int
    192      1.19   thorpej compat_43_sys_recvmsg(struct lwp *l, void *v, register_t *retval)
    193       1.2   thorpej {
    194      1.11  augustss 	struct compat_43_sys_recvmsg_args /* {
    195       1.1  christos 		syscallarg(int) s;
    196       1.1  christos 		syscallarg(struct omsghdr *) msg;
    197       1.1  christos 		syscallarg(int) flags;
    198       1.2   thorpej 	} */ *uap = v;
    199      1.15  jdolecek 	struct omsghdr omsg;
    200       1.1  christos 	struct msghdr msg;
    201      1.31       dsl 	struct mbuf *from, *control;
    202       1.1  christos 	int error;
    203       1.1  christos 
    204      1.31       dsl 	error = copyin(SCARG(uap, msg), &omsg, sizeof (struct omsghdr));
    205       1.5  christos 	if (error)
    206       1.1  christos 		return (error);
    207      1.23     perry 
    208      1.31       dsl 	if (omsg.msg_accrights == NULL)
    209      1.31       dsl 		omsg.msg_accrightslen = 0;
    210      1.31       dsl 	/* it was this way in 4.4BSD */
    211      1.31       dsl 	if (omsg.msg_accrightslen > MLEN)
    212      1.31       dsl 		return EINVAL;
    213      1.15  jdolecek 
    214      1.15  jdolecek 	msg.msg_name	= omsg.msg_name;
    215      1.15  jdolecek 	msg.msg_namelen = omsg.msg_namelen;
    216      1.15  jdolecek 	msg.msg_iovlen	= omsg.msg_iovlen;
    217      1.31       dsl 	msg.msg_iov	= omsg.msg_iov;
    218      1.31       dsl 	msg.msg_flags	= (SCARG(uap, flags) & MSG_USERFLAGS) | MSG_IOVUSRSPACE;
    219      1.15  jdolecek 
    220      1.31       dsl 	error = do_sys_recvmsg(l, SCARG(uap, s), &msg, &from,
    221      1.31       dsl 	    omsg.msg_accrights != NULL ? &control : NULL, retval);
    222      1.31       dsl 	if (error != 0)
    223      1.31       dsl 		return error;
    224       1.1  christos 
    225      1.15  jdolecek 	/*
    226      1.15  jdolecek 	 * If there is any control information and it's SCM_RIGHTS,
    227      1.15  jdolecek 	 * pass it back to the program.
    228      1.31       dsl 	 * XXX: maybe there can be more than one chunk of control data?
    229      1.15  jdolecek 	 */
    230      1.31       dsl 	if (omsg.msg_accrights && control != NULL) {
    231      1.31       dsl 		struct cmsghdr *cmsg = mtod(control, void *);
    232      1.15  jdolecek 
    233      1.31       dsl 		if (cmsg->cmsg_level == SOL_SOCKET
    234      1.31       dsl 		    && cmsg->cmsg_type == SCM_RIGHTS
    235      1.31       dsl 		    && cmsg->cmsg_len < omsg.msg_accrightslen
    236      1.31       dsl 		    && copyout(CMSG_DATA(cmsg), omsg.msg_accrights,
    237      1.31       dsl 			    cmsg->cmsg_len) == 0) {
    238      1.31       dsl 			omsg.msg_accrightslen = cmsg->cmsg_len;
    239      1.31       dsl 			free_control_mbuf(l, control, control->m_next);
    240      1.31       dsl 		} else {
    241      1.15  jdolecek 			omsg.msg_accrightslen = 0;
    242      1.31       dsl 			free_control_mbuf(l, control, control);
    243      1.15  jdolecek 		}
    244      1.31       dsl 	} else
    245      1.31       dsl 		omsg.msg_accrightslen = 0;
    246      1.23     perry 
    247      1.31       dsl 	if (from != NULL)
    248      1.31       dsl 		/* convert from sockaddr sa_family to osockaddr one here */
    249      1.31       dsl 		mtod(from, struct osockaddr *)->sa_family =
    250      1.31       dsl 				    mtod(from, struct sockaddr *)->sa_family;
    251      1.31       dsl 
    252      1.31       dsl 	error = copyout_sockname(omsg.msg_name, &omsg.msg_namelen, 0, from);
    253      1.31       dsl 	if (from != NULL)
    254      1.31       dsl 		m_free(from);
    255      1.15  jdolecek 
    256      1.31       dsl 	if (error != 0)
    257      1.31       dsl 		 error = copyout(&omsg, SCARG(uap, msg), sizeof(omsg));
    258      1.15  jdolecek 
    259      1.31       dsl 	return error;
    260       1.1  christos }
    261       1.1  christos 
    262       1.1  christos int
    263      1.19   thorpej compat_43_sys_send(struct lwp *l, void *v, register_t *retval)
    264       1.2   thorpej {
    265      1.11  augustss 	struct compat_43_sys_send_args /* {
    266       1.1  christos 		syscallarg(int) s;
    267      1.28  christos 		syscallarg(void *) buf;
    268       1.1  christos 		syscallarg(int) len;
    269       1.1  christos 		syscallarg(int) flags;
    270       1.2   thorpej 	} */ *uap = v;
    271      1.14  jdolecek 	struct sys_sendto_args bsa;
    272      1.14  jdolecek 
    273      1.14  jdolecek 	SCARG(&bsa, s)		= SCARG(uap, s);
    274      1.14  jdolecek 	SCARG(&bsa, buf)	= SCARG(uap, buf);
    275      1.14  jdolecek 	SCARG(&bsa, len)	= SCARG(uap, len);
    276      1.14  jdolecek 	SCARG(&bsa, flags)	= SCARG(uap, flags);
    277      1.14  jdolecek 	SCARG(&bsa, to)		= NULL;
    278      1.14  jdolecek 	SCARG(&bsa, tolen)	= 0;
    279       1.1  christos 
    280      1.19   thorpej 	return (sys_sendto(l, &bsa, retval));
    281       1.1  christos }
    282       1.1  christos 
    283      1.32       dsl int
    284      1.32       dsl compat43_set_accrights(struct msghdr *msg, void *accrights, int accrightslen)
    285      1.32       dsl {
    286      1.32       dsl 	struct cmsghdr *cmsg;
    287      1.32       dsl 	int error;
    288      1.32       dsl 	struct mbuf *ctl;
    289      1.32       dsl 	u_int clen;
    290      1.32       dsl 
    291      1.32       dsl 	if (accrights == NULL || accrightslen == 0) {
    292      1.32       dsl 		msg->msg_control = NULL;
    293      1.32       dsl 		msg->msg_controllen = 0;
    294      1.32       dsl 		return 0;
    295      1.32       dsl 	}
    296      1.32       dsl 
    297      1.32       dsl 	clen = CMSG_SPACE(accrightslen);
    298      1.32       dsl 	/* it was (almost) this way in 4.4BSD */
    299      1.32       dsl 	if (accrightslen < 0 || clen > MLEN)
    300      1.32       dsl 		return EINVAL;
    301      1.32       dsl 
    302      1.32       dsl 	ctl = m_get(M_WAIT, MT_CONTROL);
    303      1.32       dsl 	ctl->m_len = clen;
    304      1.32       dsl 	cmsg = mtod(ctl, void *);
    305      1.32       dsl 	cmsg->cmsg_len		= CMSG_SPACE(accrightslen);
    306      1.32       dsl 	cmsg->cmsg_level	= SOL_SOCKET;
    307      1.32       dsl 	cmsg->cmsg_type 	= SCM_RIGHTS;
    308      1.32       dsl 
    309      1.32       dsl 	error = copyin(accrights, CMSG_DATA(cmsg), accrightslen);
    310      1.32       dsl 	if (error) {
    311      1.32       dsl 		m_free(ctl);
    312      1.32       dsl 		return error;
    313      1.32       dsl 	}
    314      1.32       dsl 
    315      1.32       dsl 	msg->msg_control = ctl;
    316      1.32       dsl 	msg->msg_controllen = clen;
    317      1.32       dsl 	msg->msg_flags |= MSG_CONTROLMBUF;
    318      1.32       dsl 	return 0;
    319      1.32       dsl }
    320      1.32       dsl 
    321      1.15  jdolecek /*
    322      1.15  jdolecek  * Old sendmsg. Arrange necessary structures, call generic code and
    323      1.15  jdolecek  * adjust the results accordingly for old code.
    324      1.15  jdolecek  */
    325       1.1  christos int
    326      1.19   thorpej compat_43_sys_sendmsg(struct lwp *l, void *v, register_t *retval)
    327       1.2   thorpej {
    328      1.11  augustss 	struct compat_43_sys_sendmsg_args /* {
    329       1.1  christos 		syscallarg(int) s;
    330      1.28  christos 		syscallarg(void *) msg;
    331       1.1  christos 		syscallarg(int) flags;
    332       1.2   thorpej 	} */ *uap = v;
    333      1.15  jdolecek 	struct omsghdr omsg;
    334       1.1  christos 	struct msghdr msg;
    335       1.1  christos 	int error;
    336      1.30       dsl 	struct mbuf *nam;
    337      1.30       dsl 	struct osockaddr *osa;
    338      1.30       dsl 	struct sockaddr *sa;
    339       1.1  christos 
    340      1.30       dsl 	error = copyin(SCARG(uap, msg), &omsg, sizeof (struct omsghdr));
    341      1.30       dsl 	if (error != 0)
    342       1.1  christos 		return (error);
    343      1.15  jdolecek 
    344      1.30       dsl 	msg.msg_iovlen = omsg.msg_iovlen;
    345      1.30       dsl 	msg.msg_iov = omsg.msg_iov;
    346      1.15  jdolecek 
    347      1.30       dsl 	error = sockargs(&nam, omsg.msg_name, omsg.msg_namelen, MT_SONAME);
    348      1.30       dsl 	if (error != 0)
    349      1.30       dsl 		return (error);
    350      1.15  jdolecek 
    351      1.30       dsl 	sa = mtod(nam, void *);
    352      1.30       dsl 	osa = mtod(nam, void *);
    353      1.30       dsl 	sa->sa_family = osa->sa_family;
    354      1.30       dsl 	sa->sa_len = omsg.msg_namelen;
    355      1.15  jdolecek 
    356      1.30       dsl 	msg.msg_flags = MSG_IOVUSRSPACE | MSG_NAMEMBUF;
    357      1.15  jdolecek 
    358      1.30       dsl 	msg.msg_name = nam;
    359      1.30       dsl 	msg.msg_namelen = omsg.msg_namelen;
    360      1.32       dsl 	error = compat43_set_accrights(&msg, omsg.msg_accrights,
    361      1.32       dsl 	    omsg.msg_accrightslen);
    362      1.32       dsl 	if (error != 0)
    363      1.32       dsl 		goto bad;
    364      1.15  jdolecek 
    365      1.30       dsl 	return do_sys_sendmsg(l, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
    366      1.30       dsl 
    367      1.30       dsl     bad:
    368      1.30       dsl 	if (nam != NULL)
    369      1.30       dsl 		m_free(nam);
    370      1.30       dsl 
    371       1.1  christos 	return (error);
    372      1.15  jdolecek }
    373      1.15  jdolecek 
    374      1.15  jdolecek static int
    375      1.15  jdolecek compat_43_sa_put(from)
    376      1.28  christos 	void *from;
    377      1.15  jdolecek {
    378      1.15  jdolecek 	struct osockaddr *osa = (struct osockaddr *) from;
    379      1.15  jdolecek 	struct sockaddr sa;
    380      1.15  jdolecek 	struct osockaddr *kosa;
    381      1.15  jdolecek 	int error, len;
    382      1.15  jdolecek 
    383      1.15  jdolecek 	/*
    384      1.15  jdolecek 	 * Only read/write the sockaddr family and length, the rest is
    385      1.15  jdolecek 	 * not changed.
    386      1.15  jdolecek 	 */
    387      1.15  jdolecek 	len = sizeof(sa.sa_len) + sizeof(sa.sa_family);
    388      1.15  jdolecek 
    389      1.28  christos 	error = copyin((void *) osa, (void *) &sa, len);
    390      1.15  jdolecek 	if (error)
    391      1.15  jdolecek 		return (error);
    392      1.15  jdolecek 
    393      1.15  jdolecek 	/* Note: we convert from sockaddr sa_family to osockaddr one here */
    394      1.15  jdolecek 	kosa = (struct osockaddr *) &sa;
    395      1.15  jdolecek 	kosa->sa_family = sa.sa_family;
    396      1.15  jdolecek 	error = copyout(kosa, osa, len);
    397      1.15  jdolecek 	if (error)
    398      1.15  jdolecek 		return (error);
    399      1.15  jdolecek 
    400      1.15  jdolecek 	return (0);
    401       1.1  christos }
    402      1.24  christos 
    403      1.33       skd u_long
    404      1.33       skd compat_cvtcmd(u_long cmd)
    405      1.33       skd {
    406      1.33       skd 	u_long ncmd;
    407      1.33       skd 
    408      1.35    martin 	if (IOCPARM_LEN(cmd) != sizeof(struct oifreq))
    409      1.35    martin 		return cmd;
    410      1.34    martin 
    411      1.35    martin 	ncmd = ((cmd) & ~(IOCPARM_MASK << IOCPARM_SHIFT)) |
    412      1.35    martin 		(sizeof(struct ifreq) << IOCPARM_SHIFT);
    413      1.34    martin 
    414      1.35    martin 	switch (ncmd) {
    415      1.35    martin 	case BIOCGETIF:
    416      1.35    martin 	case BIOCSETIF:
    417      1.35    martin 	case GREDSOCK:
    418      1.35    martin 	case GREGADDRD:
    419      1.35    martin 	case GREGADDRS:
    420      1.35    martin 	case GREGPROTO:
    421      1.35    martin 	case GRESADDRD:
    422      1.35    martin 	case GRESADDRS:
    423      1.35    martin 	case GRESPROTO:
    424      1.35    martin 	case GRESSOCK:
    425  1.37.6.1       mjf #ifdef COMPAT_20
    426  1.37.6.1       mjf 	case OSIOCG80211STATS:
    427  1.37.6.1       mjf 	case OSIOCG80211ZSTATS:
    428  1.37.6.1       mjf #endif /* COMPAT_20 */
    429      1.35    martin 	case SIOCADDMULTI:
    430      1.35    martin 	case SIOCDELMULTI:
    431      1.35    martin 	case SIOCDIFADDR:
    432      1.35    martin 	case SIOCDIFADDR_IN6:
    433      1.35    martin 	case SIOCDIFPHYADDR:
    434      1.35    martin 	case SIOCGDEFIFACE_IN6:
    435  1.37.6.1       mjf 	case SIOCG80211NWID:
    436  1.37.6.1       mjf 	case SIOCG80211STATS:
    437  1.37.6.1       mjf 	case SIOCG80211ZSTATS:
    438      1.35    martin 	case SIOCGIFADDR:
    439      1.35    martin 	case SIOCGIFADDR_IN6:
    440      1.35    martin 	case SIOCGIFAFLAG_IN6:
    441      1.35    martin 	case SIOCGIFALIFETIME_IN6:
    442      1.35    martin 	case SIOCGIFBRDADDR:
    443      1.35    martin 	case SIOCGIFDLT:
    444      1.35    martin 	case SIOCGIFDSTADDR:
    445      1.35    martin 	case SIOCGIFDSTADDR_IN6:
    446      1.35    martin 	case SIOCGIFFLAGS:
    447      1.35    martin 	case SIOCGIFGENERIC:
    448      1.35    martin 	case SIOCGIFMETRIC:
    449      1.35    martin 	case SIOCGIFMTU:
    450      1.35    martin 	case SIOCGIFNETMASK:
    451      1.35    martin 	case SIOCGIFNETMASK_IN6:
    452      1.35    martin 	case SIOCGIFPDSTADDR:
    453      1.35    martin 	case SIOCGIFPDSTADDR_IN6:
    454      1.35    martin 	case SIOCGIFPSRCADDR:
    455      1.35    martin 	case SIOCGIFPSRCADDR_IN6:
    456      1.35    martin 	case SIOCGIFSTAT_ICMP6:
    457      1.35    martin 	case SIOCGIFSTAT_IN6:
    458      1.35    martin 	case SIOCGPVCSIF:
    459      1.35    martin 	case SIOCGVH:
    460      1.35    martin 	case SIOCIFCREATE:
    461      1.35    martin 	case SIOCIFDESTROY:
    462  1.37.6.1       mjf 	case SIOCS80211NWID:
    463      1.35    martin 	case SIOCSDEFIFACE_IN6:
    464      1.35    martin 	case SIOCSIFADDR:
    465      1.35    martin 	case SIOCSIFADDR_IN6:
    466      1.35    martin 	case SIOCSIFBRDADDR:
    467      1.35    martin 	case SIOCSIFDSTADDR:
    468      1.35    martin 	case SIOCSIFDSTADDR_IN6:
    469      1.35    martin 	case SIOCSIFFLAGS:
    470      1.35    martin 	case SIOCSIFGENERIC:
    471      1.35    martin 	case SIOCSIFMEDIA:
    472      1.35    martin 	case SIOCSIFMETRIC:
    473      1.35    martin 	case SIOCSIFMTU:
    474      1.35    martin 	case SIOCSIFNETMASK:
    475      1.35    martin 	case SIOCSIFNETMASK_IN6:
    476      1.35    martin 	case SIOCSNDFLUSH_IN6:
    477      1.35    martin 	case SIOCSPFXFLUSH_IN6:
    478      1.35    martin 	case SIOCSPVCSIF:
    479      1.35    martin 	case SIOCSRTRFLUSH_IN6:
    480      1.35    martin 	case SIOCSVH:
    481      1.35    martin 	case TAPGIFNAME:
    482      1.35    martin 		return ncmd;
    483      1.35    martin 	}
    484      1.35    martin 	return cmd;
    485      1.33       skd }
    486      1.33       skd 
    487      1.24  christos int
    488      1.29  christos compat_ifioctl(struct socket *so, u_long ocmd, u_long cmd, void *data,
    489      1.29  christos     struct lwp *l)
    490      1.24  christos {
    491      1.29  christos 	int error;
    492      1.29  christos 	struct ifreq *ifr = data;
    493      1.24  christos 	struct ifnet *ifp = ifunit(ifr->ifr_name);
    494      1.29  christos 	struct sockaddr *sa;
    495      1.24  christos 
    496      1.24  christos 	if (ifp == NULL)
    497      1.24  christos 		return ENXIO;
    498      1.24  christos 
    499      1.29  christos 	switch (ocmd) {
    500      1.29  christos 	case OSIOCSIFADDR:
    501      1.29  christos 	case OSIOCSIFDSTADDR:
    502      1.29  christos 	case OSIOCSIFBRDADDR:
    503      1.29  christos 	case OSIOCSIFNETMASK:
    504      1.29  christos 		sa = &ifr->ifr_addr;
    505      1.24  christos #if BYTE_ORDER != BIG_ENDIAN
    506      1.29  christos 		if (sa->sa_family == 0 && sa->sa_len < 16) {
    507      1.29  christos 			sa->sa_family = sa->sa_len;
    508      1.29  christos 			sa->sa_len = 16;
    509      1.24  christos 		}
    510      1.24  christos #else
    511      1.29  christos 		if (sa->sa_len == 0)
    512      1.29  christos 			sa->sa_len = 16;
    513      1.24  christos #endif
    514      1.24  christos 		break;
    515      1.24  christos 
    516      1.29  christos 	case OOSIOCGIFADDR:
    517      1.24  christos 		cmd = SIOCGIFADDR;
    518      1.24  christos 		break;
    519      1.24  christos 
    520      1.29  christos 	case OOSIOCGIFDSTADDR:
    521      1.24  christos 		cmd = SIOCGIFDSTADDR;
    522      1.24  christos 		break;
    523      1.24  christos 
    524      1.29  christos 	case OOSIOCGIFBRDADDR:
    525      1.24  christos 		cmd = SIOCGIFBRDADDR;
    526      1.24  christos 		break;
    527      1.24  christos 
    528      1.29  christos 	case OOSIOCGIFNETMASK:
    529      1.24  christos 		cmd = SIOCGIFNETMASK;
    530      1.24  christos 	}
    531      1.24  christos 
    532      1.24  christos 	error = (*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
    533      1.29  christos 	    (struct mbuf *)cmd, (struct mbuf *)ifr, (struct mbuf *)ifp, l);
    534      1.24  christos 
    535      1.24  christos 	switch (ocmd) {
    536      1.29  christos 	case OOSIOCGIFADDR:
    537      1.29  christos 	case OOSIOCGIFDSTADDR:
    538      1.29  christos 	case OOSIOCGIFBRDADDR:
    539      1.29  christos 	case OOSIOCGIFNETMASK:
    540      1.29  christos 		*(u_int16_t *)&ifr->ifr_addr =
    541      1.29  christos 		    ((struct sockaddr *)&ifr->ifr_addr)->sa_family;
    542      1.24  christos 	}
    543      1.24  christos 	return error;
    544      1.24  christos }
    545