Home | History | Annotate | Line # | Download | only in common
uipc_syscalls_43.c revision 1.25.20.2
      1  1.25.20.2        ad /*	$NetBSD: uipc_syscalls_43.c,v 1.25.20.2 2007/02/01 08:48:13 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.25.20.2        ad __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_43.c,v 1.25.20.2 2007/02/01 08:48:13 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 <compat/sys/socket.h>
     59       1.24  christos #include <net/if.h>
     60       1.24  christos 
     61       1.15  jdolecek #include <compat/common/compat_util.h>
     62       1.15  jdolecek 
     63       1.15  jdolecek #include <uvm/uvm_extern.h>
     64       1.15  jdolecek 
     65       1.15  jdolecek /*
     66       1.15  jdolecek  * Following 4.3 syscalls were not versioned, even through they should
     67       1.15  jdolecek  * have been:
     68       1.15  jdolecek  * connect(2), bind(2), sendto(2)
     69       1.15  jdolecek  */
     70       1.15  jdolecek 
     71       1.15  jdolecek static int compat_43_sa_put(caddr_t);
     72       1.15  jdolecek 
     73        1.1  christos int
     74       1.19   thorpej compat_43_sys_accept(struct lwp *l, void *v, register_t *retval)
     75        1.2   thorpej {
     76       1.15  jdolecek 	struct compat_43_sys_accept_args /* {
     77        1.1  christos 		syscallarg(int) s;
     78        1.1  christos 		syscallarg(caddr_t) name;
     79        1.1  christos 		syscallarg(int *) anamelen;
     80        1.2   thorpej 	} */ *uap = v;
     81        1.1  christos 	int error;
     82        1.1  christos 
     83       1.19   thorpej 	if ((error = sys_accept(l, v, retval)) != 0)
     84        1.1  christos 		return error;
     85        1.1  christos 
     86       1.15  jdolecek 	if (SCARG(uap, name)
     87       1.15  jdolecek 	    && (error = compat_43_sa_put(SCARG(uap, name))))
     88       1.15  jdolecek 		return (error);
     89        1.1  christos 
     90        1.1  christos 	return 0;
     91        1.1  christos }
     92        1.1  christos 
     93        1.1  christos int
     94       1.19   thorpej compat_43_sys_getpeername(struct lwp *l, void *v, register_t *retval)
     95        1.2   thorpej {
     96       1.15  jdolecek 	struct compat_43_sys_getpeername_args /* {
     97        1.1  christos 		syscallarg(int) fdes;
     98        1.1  christos 		syscallarg(caddr_t) asa;
     99        1.1  christos 		syscallarg(int *) alen;
    100        1.2   thorpej 	} */ *uap = v;
    101        1.1  christos 
    102        1.1  christos 	int error;
    103        1.1  christos 
    104       1.19   thorpej 	if ((error = sys_getpeername(l, v, retval)) != 0)
    105        1.1  christos 		return error;
    106        1.1  christos 
    107       1.15  jdolecek 	if ((error = compat_43_sa_put(SCARG(uap, asa))))
    108       1.15  jdolecek 		return (error);
    109        1.1  christos 
    110        1.1  christos 	return 0;
    111        1.1  christos }
    112        1.1  christos 
    113        1.1  christos int
    114       1.19   thorpej compat_43_sys_getsockname(struct lwp *l, void *v, register_t *retval)
    115        1.2   thorpej {
    116       1.15  jdolecek 	struct compat_43_sys_getsockname_args /* {
    117        1.1  christos 		syscallarg(int) fdes;
    118        1.1  christos 		syscallarg(caddr_t) asa;
    119        1.1  christos 		syscallarg(int *) alen;
    120        1.2   thorpej 	} */ *uap = v;
    121        1.1  christos 	int error;
    122        1.1  christos 
    123       1.19   thorpej 	if ((error = sys_getsockname(l, v, retval)) != 0)
    124        1.1  christos 		return error;
    125        1.1  christos 
    126       1.15  jdolecek 	if ((error = compat_43_sa_put(SCARG(uap, asa))))
    127       1.15  jdolecek 		return (error);
    128        1.1  christos 
    129        1.1  christos 	return 0;
    130        1.1  christos }
    131        1.1  christos 
    132        1.1  christos int
    133       1.19   thorpej compat_43_sys_recv(struct lwp *l, void *v, register_t *retval)
    134        1.2   thorpej {
    135       1.11  augustss 	struct compat_43_sys_recv_args /* {
    136        1.1  christos 		syscallarg(int) s;
    137        1.1  christos 		syscallarg(caddr_t) buf;
    138        1.1  christos 		syscallarg(int) len;
    139        1.1  christos 		syscallarg(int) flags;
    140        1.2   thorpej 	} */ *uap = v;
    141       1.14  jdolecek 	struct sys_recvfrom_args bra;
    142       1.14  jdolecek 
    143       1.14  jdolecek 	SCARG(&bra, s) = SCARG(uap, s);
    144       1.14  jdolecek 	SCARG(&bra, buf) = SCARG(uap, buf);
    145       1.14  jdolecek 	SCARG(&bra, len) = (size_t) SCARG(uap, len);
    146       1.14  jdolecek 	SCARG(&bra, flags) = SCARG(uap, flags);
    147       1.14  jdolecek 	SCARG(&bra, from) = NULL;
    148       1.14  jdolecek 	SCARG(&bra, fromlenaddr) = NULL;
    149        1.1  christos 
    150       1.19   thorpej 	return (sys_recvfrom(l, &bra, retval));
    151        1.1  christos }
    152        1.1  christos 
    153        1.1  christos int
    154       1.19   thorpej compat_43_sys_recvfrom(struct lwp *l, void *v, register_t *retval)
    155        1.2   thorpej {
    156       1.15  jdolecek 	struct compat_43_sys_recvfrom_args /* {
    157        1.1  christos 		syscallarg(int) s;
    158        1.1  christos 		syscallarg(caddr_t) buf;
    159        1.1  christos 		syscallarg(size_t) len;
    160        1.1  christos 		syscallarg(int) flags;
    161        1.1  christos 		syscallarg(caddr_t) from;
    162        1.1  christos 		syscallarg(int *) fromlenaddr;
    163        1.2   thorpej 	} */ *uap = v;
    164       1.15  jdolecek 	int error;
    165       1.15  jdolecek 
    166       1.19   thorpej 	if ((error = sys_recvfrom(l, v, retval)))
    167       1.15  jdolecek 		return (error);
    168       1.15  jdolecek 
    169       1.15  jdolecek 	if (SCARG(uap, from) && (error = compat_43_sa_put(SCARG(uap, from))))
    170       1.15  jdolecek 		return (error);
    171        1.1  christos 
    172       1.15  jdolecek 	return (0);
    173        1.1  christos }
    174        1.1  christos 
    175        1.1  christos /*
    176       1.15  jdolecek  * Old recvmsg. Arrange necessary structures, calls generic code and
    177       1.15  jdolecek  * adjusts results accordingly.
    178        1.1  christos  */
    179        1.1  christos int
    180       1.19   thorpej compat_43_sys_recvmsg(struct lwp *l, void *v, register_t *retval)
    181        1.2   thorpej {
    182       1.11  augustss 	struct compat_43_sys_recvmsg_args /* {
    183        1.1  christos 		syscallarg(int) s;
    184        1.1  christos 		syscallarg(struct omsghdr *) msg;
    185        1.1  christos 		syscallarg(int) flags;
    186        1.2   thorpej 	} */ *uap = v;
    187       1.19   thorpej 	struct proc *p = l->l_proc;
    188       1.15  jdolecek 	struct omsghdr omsg;
    189        1.1  christos 	struct msghdr msg;
    190        1.1  christos 	struct iovec aiov[UIO_SMALLIOV], *iov;
    191        1.1  christos 	int error;
    192        1.1  christos 
    193       1.15  jdolecek 	error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&omsg,
    194        1.5  christos 	    sizeof (struct omsghdr));
    195        1.5  christos 	if (error)
    196        1.1  christos 		return (error);
    197       1.15  jdolecek 	if ((u_int)omsg.msg_iovlen > UIO_SMALLIOV) {
    198       1.15  jdolecek 		if ((u_int)omsg.msg_iovlen > IOV_MAX)
    199        1.1  christos 			return (EMSGSIZE);
    200       1.15  jdolecek 		iov = malloc(sizeof(struct iovec) * omsg.msg_iovlen,
    201       1.15  jdolecek 		    M_IOV, M_WAITOK);
    202        1.1  christos 	} else
    203        1.1  christos 		iov = aiov;
    204       1.23     perry 
    205       1.15  jdolecek 	error = copyin((caddr_t)omsg.msg_iov, (caddr_t)iov,
    206       1.15  jdolecek 	    (unsigned)(omsg.msg_iovlen * sizeof (struct iovec)));
    207        1.5  christos 	if (error)
    208        1.1  christos 		goto done;
    209       1.15  jdolecek 
    210       1.15  jdolecek 	msg.msg_name	= omsg.msg_name;
    211       1.15  jdolecek 	msg.msg_namelen = omsg.msg_namelen;
    212       1.15  jdolecek 	msg.msg_iovlen	= omsg.msg_iovlen;
    213       1.15  jdolecek 	msg.msg_iov	= iov;
    214       1.15  jdolecek 	msg.msg_flags	= SCARG(uap, flags);
    215       1.15  jdolecek 
    216       1.15  jdolecek 	/*
    217       1.15  jdolecek 	 * If caller passes accrights, arrange things for generic code to
    218       1.15  jdolecek 	 * DTRT.
    219       1.15  jdolecek 	 */
    220       1.15  jdolecek 	if (omsg.msg_accrights && omsg.msg_accrightslen) {
    221       1.18  christos 		caddr_t sg = stackgap_init(p, 0);
    222       1.15  jdolecek 		struct cmsg *ucmsg;
    223       1.15  jdolecek 
    224       1.15  jdolecek 		/* it was this way in 4.4BSD */
    225       1.15  jdolecek 		if ((u_int) omsg.msg_accrightslen > MLEN)
    226       1.15  jdolecek 			return (EINVAL);
    227       1.15  jdolecek 
    228       1.18  christos 		ucmsg = stackgap_alloc(p, &sg, CMSG_SPACE(omsg.msg_accrightslen));
    229       1.15  jdolecek 		if (ucmsg == NULL)
    230       1.16  jdolecek 			return (EMSGSIZE);
    231       1.15  jdolecek 
    232       1.15  jdolecek 		msg.msg_control = ucmsg;
    233       1.15  jdolecek 		msg.msg_controllen = CMSG_SPACE(omsg.msg_accrightslen);
    234       1.15  jdolecek 	} else {
    235       1.15  jdolecek 		msg.msg_control = NULL;
    236       1.15  jdolecek 		msg.msg_controllen = 0;
    237       1.15  jdolecek 	}
    238       1.15  jdolecek 
    239       1.25  christos 	error = recvit(l, SCARG(uap, s), &msg,
    240       1.13  jdolecek 	    (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
    241        1.1  christos 
    242       1.15  jdolecek 	/*
    243       1.15  jdolecek 	 * If there is any control information and it's SCM_RIGHTS,
    244       1.15  jdolecek 	 * pass it back to the program.
    245       1.15  jdolecek 	 */
    246       1.15  jdolecek 	if (!error && omsg.msg_accrights && msg.msg_controllen > 0) {
    247       1.15  jdolecek 		struct cmsghdr *cmsg;
    248       1.15  jdolecek 
    249       1.16  jdolecek 		/* safe - msg.msg_controllen set by kernel */
    250       1.15  jdolecek 		cmsg = (struct cmsghdr *) malloc(msg.msg_controllen,
    251       1.15  jdolecek 		    M_TEMP, M_WAITOK);
    252       1.23     perry 
    253       1.15  jdolecek 		error = copyin(msg.msg_control, cmsg, msg.msg_controllen);
    254       1.15  jdolecek 		if (error) {
    255       1.15  jdolecek 			free(cmsg, M_TEMP);
    256       1.15  jdolecek 			return (error);
    257       1.15  jdolecek 		}
    258       1.15  jdolecek 
    259       1.15  jdolecek 		if (cmsg->cmsg_level != SOL_SOCKET
    260       1.15  jdolecek 		    || cmsg->cmsg_type != SCM_RIGHTS
    261       1.15  jdolecek 		    || copyout(CMSG_DATA(cmsg), omsg.msg_accrights,
    262       1.15  jdolecek 			    cmsg->cmsg_len)) {
    263       1.15  jdolecek 			omsg.msg_accrightslen = 0;
    264       1.15  jdolecek 		}
    265       1.23     perry 
    266       1.15  jdolecek 		free(cmsg, M_TEMP);
    267       1.15  jdolecek 
    268       1.15  jdolecek 		if (!error) {
    269       1.15  jdolecek 			error = copyout(&cmsg->cmsg_len,
    270       1.15  jdolecek 			    &SCARG(uap, msg)->msg_accrightslen, sizeof(int));
    271       1.15  jdolecek 		}
    272       1.15  jdolecek 	}
    273       1.15  jdolecek 
    274       1.15  jdolecek 	if (!error && omsg.msg_name) {
    275       1.15  jdolecek 		int namelen;
    276       1.15  jdolecek 
    277       1.15  jdolecek 		if ((error = copyin(&SCARG(uap, msg)->msg_namelen, &namelen, sizeof(int)) == 0)
    278       1.15  jdolecek 		    && namelen > 0)
    279       1.15  jdolecek 			error = compat_43_sa_put(omsg.msg_name);
    280       1.15  jdolecek 	}
    281       1.15  jdolecek 
    282        1.1  christos done:
    283        1.1  christos 	if (iov != aiov)
    284       1.15  jdolecek 		free(iov, M_IOV);
    285        1.1  christos 	return (error);
    286        1.1  christos }
    287        1.1  christos 
    288        1.1  christos int
    289       1.19   thorpej compat_43_sys_send(struct lwp *l, void *v, register_t *retval)
    290        1.2   thorpej {
    291       1.11  augustss 	struct compat_43_sys_send_args /* {
    292        1.1  christos 		syscallarg(int) s;
    293        1.1  christos 		syscallarg(caddr_t) buf;
    294        1.1  christos 		syscallarg(int) len;
    295        1.1  christos 		syscallarg(int) flags;
    296        1.2   thorpej 	} */ *uap = v;
    297       1.14  jdolecek 	struct sys_sendto_args bsa;
    298       1.14  jdolecek 
    299       1.14  jdolecek 	SCARG(&bsa, s)		= SCARG(uap, s);
    300       1.14  jdolecek 	SCARG(&bsa, buf)	= SCARG(uap, buf);
    301       1.14  jdolecek 	SCARG(&bsa, len)	= SCARG(uap, len);
    302       1.14  jdolecek 	SCARG(&bsa, flags)	= SCARG(uap, flags);
    303       1.14  jdolecek 	SCARG(&bsa, to)		= NULL;
    304       1.14  jdolecek 	SCARG(&bsa, tolen)	= 0;
    305        1.1  christos 
    306       1.19   thorpej 	return (sys_sendto(l, &bsa, retval));
    307        1.1  christos }
    308        1.1  christos 
    309       1.15  jdolecek /*
    310       1.15  jdolecek  * Old sendmsg. Arrange necessary structures, call generic code and
    311       1.15  jdolecek  * adjust the results accordingly for old code.
    312       1.15  jdolecek  */
    313        1.1  christos int
    314       1.19   thorpej compat_43_sys_sendmsg(struct lwp *l, void *v, register_t *retval)
    315        1.2   thorpej {
    316       1.11  augustss 	struct compat_43_sys_sendmsg_args /* {
    317        1.1  christos 		syscallarg(int) s;
    318        1.1  christos 		syscallarg(caddr_t) msg;
    319        1.1  christos 		syscallarg(int) flags;
    320        1.2   thorpej 	} */ *uap = v;
    321       1.19   thorpej 	struct proc *p = l->l_proc;
    322       1.15  jdolecek 	struct omsghdr omsg;
    323        1.1  christos 	struct msghdr msg;
    324        1.1  christos 	struct iovec aiov[UIO_SMALLIOV], *iov;
    325        1.1  christos 	int error;
    326       1.18  christos 	caddr_t sg = stackgap_init(p, 0);
    327        1.1  christos 
    328       1.15  jdolecek 	error = copyin(SCARG(uap, msg), (caddr_t)&omsg,
    329        1.5  christos 	    sizeof (struct omsghdr));
    330        1.5  christos 	if (error)
    331        1.1  christos 		return (error);
    332       1.15  jdolecek 	if ((u_int)omsg.msg_iovlen > UIO_SMALLIOV) {
    333       1.15  jdolecek 		if ((u_int)omsg.msg_iovlen > IOV_MAX)
    334        1.1  christos 			return (EMSGSIZE);
    335       1.15  jdolecek 		iov = malloc(sizeof(struct iovec) * omsg.msg_iovlen,
    336       1.15  jdolecek 		    M_IOV, M_WAITOK);
    337        1.1  christos 	} else
    338        1.1  christos 		iov = aiov;
    339       1.15  jdolecek 	error = copyin((caddr_t)omsg.msg_iov, (caddr_t)iov,
    340       1.15  jdolecek 	    (unsigned)(omsg.msg_iovlen * sizeof (struct iovec)));
    341        1.5  christos 	if (error)
    342        1.1  christos 		goto done;
    343       1.15  jdolecek 
    344       1.15  jdolecek 	if (omsg.msg_name) {
    345       1.15  jdolecek 		struct osockaddr *osa;
    346       1.15  jdolecek 		struct sockaddr *sa, *usa;
    347       1.15  jdolecek 
    348       1.15  jdolecek 		if ((u_int) omsg.msg_namelen > UCHAR_MAX)
    349       1.15  jdolecek 			return (EINVAL);
    350       1.15  jdolecek 
    351       1.15  jdolecek 		osa = malloc(omsg.msg_namelen, M_TEMP, M_WAITOK);
    352       1.15  jdolecek 
    353       1.15  jdolecek 		if ((error = copyin(omsg.msg_name, osa, omsg.msg_namelen))) {
    354       1.15  jdolecek 			free(osa, M_TEMP);
    355       1.15  jdolecek 			return (error);
    356       1.15  jdolecek 		}
    357       1.15  jdolecek 
    358       1.15  jdolecek 		sa = (struct sockaddr *) osa;
    359       1.15  jdolecek 		sa->sa_family = osa->sa_family;
    360       1.15  jdolecek 		sa->sa_len = omsg.msg_namelen;
    361       1.15  jdolecek 
    362       1.18  christos 		usa = stackgap_alloc(p, &sg, omsg.msg_namelen);
    363       1.15  jdolecek 		if (!usa) {
    364       1.15  jdolecek 			free(osa, M_TEMP);
    365       1.15  jdolecek 			return (ENOMEM);
    366       1.15  jdolecek 		}
    367       1.15  jdolecek 
    368       1.15  jdolecek 		(void) copyout(sa, usa, omsg.msg_namelen);
    369       1.15  jdolecek 		free(osa, M_TEMP);
    370       1.23     perry 
    371       1.15  jdolecek 		msg.msg_name = usa;
    372       1.15  jdolecek 		msg.msg_namelen = omsg.msg_namelen;
    373       1.15  jdolecek 	} else {
    374       1.15  jdolecek 		msg.msg_name = NULL;
    375       1.15  jdolecek 		msg.msg_namelen = 0;
    376       1.15  jdolecek 	}
    377       1.15  jdolecek 	msg.msg_iovlen	= omsg.msg_iovlen;
    378       1.15  jdolecek 	msg.msg_iov	= iov;
    379       1.15  jdolecek 	msg.msg_flags	= 0;
    380       1.15  jdolecek 
    381       1.15  jdolecek 	if (omsg.msg_accrights && omsg.msg_accrightslen != 0) {
    382       1.15  jdolecek 		struct cmsghdr *cmsg, *ucmsg;
    383       1.15  jdolecek 
    384       1.15  jdolecek 		/* it was this way in 4.4BSD */
    385       1.15  jdolecek 		if ((u_int) omsg.msg_accrightslen > MLEN)
    386       1.15  jdolecek 			return (EINVAL);
    387       1.15  jdolecek 
    388       1.15  jdolecek 		cmsg = malloc(CMSG_SPACE(omsg.msg_accrightslen), M_TEMP,
    389       1.23     perry 		    M_WAITOK);
    390       1.15  jdolecek 		cmsg->cmsg_len		= CMSG_SPACE(omsg.msg_accrightslen);
    391       1.15  jdolecek 		cmsg->cmsg_level	= SOL_SOCKET;
    392       1.15  jdolecek 		cmsg->cmsg_type 	= SCM_RIGHTS;
    393       1.15  jdolecek 
    394       1.15  jdolecek 		error = copyin(omsg.msg_accrights, CMSG_DATA(cmsg),
    395       1.15  jdolecek 		    omsg.msg_accrightslen);
    396       1.15  jdolecek 		if (error) {
    397       1.15  jdolecek 			free(cmsg, M_TEMP);
    398       1.15  jdolecek 			return (error);
    399       1.15  jdolecek 		}
    400       1.23     perry 
    401       1.18  christos 		ucmsg = stackgap_alloc(p, &sg, CMSG_SPACE(omsg.msg_accrightslen));
    402       1.15  jdolecek 		if (!ucmsg) {
    403       1.15  jdolecek 			free(cmsg, M_TEMP);
    404       1.16  jdolecek 			return (EMSGSIZE);
    405       1.15  jdolecek 		}
    406       1.15  jdolecek 
    407       1.15  jdolecek 		(void) copyout(cmsg, ucmsg, CMSG_SPACE(omsg.msg_accrightslen));
    408       1.15  jdolecek 		free(cmsg, M_TEMP);
    409       1.15  jdolecek 
    410       1.15  jdolecek 		msg.msg_control = ucmsg;
    411       1.15  jdolecek 		msg.msg_controllen = CMSG_SPACE(omsg.msg_accrightslen);
    412       1.15  jdolecek 	} else {
    413       1.15  jdolecek 		msg.msg_control = NULL;
    414       1.15  jdolecek 		msg.msg_controllen = 0;
    415       1.15  jdolecek 	}
    416       1.15  jdolecek 
    417       1.25  christos 	error = sendit(l, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
    418        1.1  christos done:
    419        1.1  christos 	if (iov != aiov)
    420        1.1  christos 		FREE(iov, M_IOV);
    421        1.1  christos 	return (error);
    422       1.15  jdolecek }
    423       1.15  jdolecek 
    424       1.15  jdolecek static int
    425       1.15  jdolecek compat_43_sa_put(from)
    426       1.15  jdolecek 	caddr_t from;
    427       1.15  jdolecek {
    428       1.15  jdolecek 	struct osockaddr *osa = (struct osockaddr *) from;
    429       1.15  jdolecek 	struct sockaddr sa;
    430       1.15  jdolecek 	struct osockaddr *kosa;
    431       1.15  jdolecek 	int error, len;
    432       1.15  jdolecek 
    433       1.15  jdolecek 	/*
    434       1.15  jdolecek 	 * Only read/write the sockaddr family and length, the rest is
    435       1.15  jdolecek 	 * not changed.
    436       1.15  jdolecek 	 */
    437       1.15  jdolecek 	len = sizeof(sa.sa_len) + sizeof(sa.sa_family);
    438       1.15  jdolecek 
    439       1.15  jdolecek 	error = copyin((caddr_t) osa, (caddr_t) &sa, len);
    440       1.15  jdolecek 	if (error)
    441       1.15  jdolecek 		return (error);
    442       1.15  jdolecek 
    443       1.15  jdolecek 	/* Note: we convert from sockaddr sa_family to osockaddr one here */
    444       1.15  jdolecek 	kosa = (struct osockaddr *) &sa;
    445       1.15  jdolecek 	kosa->sa_family = sa.sa_family;
    446       1.15  jdolecek 	error = copyout(kosa, osa, len);
    447       1.15  jdolecek 	if (error)
    448       1.15  jdolecek 		return (error);
    449       1.15  jdolecek 
    450       1.15  jdolecek 	return (0);
    451        1.1  christos }
    452       1.24  christos 
    453       1.24  christos int
    454       1.25  christos compat_ifioctl(struct socket *so, u_long cmd, caddr_t data, struct lwp *l)
    455       1.24  christos {
    456       1.24  christos 	int error, ocmd = cmd;
    457       1.24  christos 	struct ifreq *ifr = (struct ifreq *)data;
    458       1.24  christos 	struct ifnet *ifp = ifunit(ifr->ifr_name);
    459       1.24  christos 
    460       1.24  christos 	if (ifp == NULL)
    461       1.24  christos 		return ENXIO;
    462       1.24  christos 
    463       1.24  christos 	switch (cmd) {
    464       1.24  christos 	case SIOCSIFADDR:
    465       1.24  christos 	case SIOCSIFDSTADDR:
    466       1.24  christos 	case SIOCSIFBRDADDR:
    467       1.24  christos 	case SIOCSIFNETMASK:
    468       1.24  christos #if BYTE_ORDER != BIG_ENDIAN
    469       1.24  christos 		if (ifr->ifr_addr.sa_family == 0 &&
    470       1.24  christos 		    ifr->ifr_addr.sa_len < 16) {
    471       1.24  christos 			ifr->ifr_addr.sa_family = ifr->ifr_addr.sa_len;
    472       1.24  christos 			ifr->ifr_addr.sa_len = 16;
    473       1.24  christos 		}
    474       1.24  christos #else
    475       1.24  christos 		if (ifr->ifr_addr.sa_len == 0)
    476       1.24  christos 			ifr->ifr_addr.sa_len = 16;
    477       1.24  christos #endif
    478       1.24  christos 		break;
    479       1.24  christos 
    480       1.24  christos 	case OSIOCGIFADDR:
    481       1.24  christos 		cmd = SIOCGIFADDR;
    482       1.24  christos 		break;
    483       1.24  christos 
    484       1.24  christos 	case OSIOCGIFDSTADDR:
    485       1.24  christos 		cmd = SIOCGIFDSTADDR;
    486       1.24  christos 		break;
    487       1.24  christos 
    488       1.24  christos 	case OSIOCGIFBRDADDR:
    489       1.24  christos 		cmd = SIOCGIFBRDADDR;
    490       1.24  christos 		break;
    491       1.24  christos 
    492       1.24  christos 	case OSIOCGIFNETMASK:
    493       1.24  christos 		cmd = SIOCGIFNETMASK;
    494       1.24  christos 	}
    495       1.24  christos 
    496       1.24  christos 	error = (*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
    497       1.25  christos 	    (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)ifp, l);
    498       1.24  christos 
    499       1.24  christos 	switch (ocmd) {
    500       1.24  christos 	case OSIOCGIFADDR:
    501       1.24  christos 	case OSIOCGIFDSTADDR:
    502       1.24  christos 	case OSIOCGIFBRDADDR:
    503       1.24  christos 	case OSIOCGIFNETMASK:
    504       1.24  christos 		*(u_int16_t *)&ifr->ifr_addr = ifr->ifr_addr.sa_family;
    505       1.24  christos 	}
    506       1.24  christos 	return error;
    507       1.24  christos }
    508