Home | History | Annotate | Line # | Download | only in common
linux_socketcall.c revision 1.17
      1  1.17  christos /*	$NetBSD: linux_socketcall.c,v 1.17 1998/10/03 20:17:43 christos Exp $	*/
      2  1.16       erh 
      3  1.16       erh /*-
      4  1.16       erh  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.16       erh  * All rights reserved.
      6  1.16       erh  *
      7  1.16       erh  * This code is derived from software contributed to The NetBSD Foundation
      8  1.16       erh  * by Eric Haszlakiewicz.
      9  1.16       erh  *
     10  1.16       erh  * Redistribution and use in source and binary forms, with or without
     11  1.16       erh  * modification, are permitted provided that the following conditions
     12  1.16       erh  * are met:
     13  1.16       erh  * 1. Redistributions of source code must retain the above copyright
     14  1.16       erh  *    notice, this list of conditions and the following disclaimer.
     15  1.16       erh  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.16       erh  *    notice, this list of conditions and the following disclaimer in the
     17  1.16       erh  *    documentation and/or other materials provided with the distribution.
     18  1.16       erh  * 3. All advertising materials mentioning features or use of this software
     19  1.16       erh  *    must display the following acknowledgement:
     20  1.16       erh  *	This product includes software developed by the NetBSD
     21  1.16       erh  *	Foundation, Inc. and its contributors.
     22  1.16       erh  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.16       erh  *    contributors may be used to endorse or promote products derived
     24  1.16       erh  *    from this software without specific prior written permission.
     25  1.16       erh  *
     26  1.16       erh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.16       erh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.16       erh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.16       erh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.16       erh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.16       erh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.16       erh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.16       erh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.16       erh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.16       erh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.16       erh  * POSSIBILITY OF SUCH DAMAGE.
     37  1.16       erh  */
     38   1.1      fvdl 
     39   1.1      fvdl /*
     40   1.1      fvdl  * Copyright (c) 1995 Frank van der Linden
     41   1.1      fvdl  * All rights reserved.
     42   1.1      fvdl  *
     43   1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     44   1.1      fvdl  * modification, are permitted provided that the following conditions
     45   1.1      fvdl  * are met:
     46   1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     47   1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     48   1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     50   1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     51   1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     52   1.1      fvdl  *    must display the following acknowledgement:
     53   1.1      fvdl  *      This product includes software developed for the NetBSD Project
     54   1.1      fvdl  *      by Frank van der Linden
     55   1.1      fvdl  * 4. The name of the author may not be used to endorse or promote products
     56   1.1      fvdl  *    derived from this software without specific prior written permission
     57   1.1      fvdl  *
     58   1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59   1.1      fvdl  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60   1.1      fvdl  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61   1.1      fvdl  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     62   1.1      fvdl  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     63   1.1      fvdl  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     64   1.1      fvdl  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     65   1.1      fvdl  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     66   1.1      fvdl  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     67   1.1      fvdl  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68   1.1      fvdl  */
     69   1.1      fvdl 
     70   1.1      fvdl #include <sys/param.h>
     71   1.1      fvdl #include <sys/kernel.h>
     72   1.1      fvdl #include <sys/systm.h>
     73   1.1      fvdl #include <sys/buf.h>
     74   1.1      fvdl #include <sys/malloc.h>
     75   1.1      fvdl #include <sys/ioctl.h>
     76   1.1      fvdl #include <sys/tty.h>
     77   1.1      fvdl #include <sys/file.h>
     78   1.1      fvdl #include <sys/filedesc.h>
     79   1.1      fvdl #include <sys/select.h>
     80   1.1      fvdl #include <sys/socket.h>
     81   1.1      fvdl #include <sys/socketvar.h>
     82   1.1      fvdl #include <net/if.h>
     83   1.1      fvdl #include <netinet/in.h>
     84   1.7   mycroft #include <netinet/tcp.h>
     85   1.1      fvdl #include <sys/mount.h>
     86   1.1      fvdl #include <sys/proc.h>
     87   1.1      fvdl #include <sys/vnode.h>
     88   1.1      fvdl #include <sys/device.h>
     89   1.1      fvdl 
     90   1.1      fvdl #include <sys/syscallargs.h>
     91   1.1      fvdl 
     92  1.17  christos #include <compat/linux/common/linux_types.h>
     93  1.17  christos #include <compat/linux/common/linux_util.h>
     94  1.17  christos #include <compat/linux/common/linux_signal.h>
     95  1.17  christos #include <compat/linux/common/linux_ioctl.h>
     96  1.17  christos #include <compat/linux/common/linux_socket.h>
     97  1.17  christos #include <compat/linux/common/linux_socketcall.h>
     98  1.17  christos #include <compat/linux/common/linux_sockio.h>
     99  1.17  christos 
    100   1.1      fvdl #include <compat/linux/linux_syscallargs.h>
    101   1.1      fvdl 
    102  1.16       erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
    103  1.16       erh /* Not used on: alpha */
    104   1.1      fvdl 
    105   1.1      fvdl /*
    106  1.16       erh  * This file contains the linux_socketcall() multiplexer.  Arguments
    107  1.16       erh  * for the various socket calls are on the user stack. A pointer
    108  1.16       erh  * to them is the only thing that is passed.  We copyin the arguments
    109  1.16       erh  * here so the individual functions can assume they are normal syscalls.
    110  1.16       erh  */
    111  1.16       erh 
    112  1.16       erh /* The sizes of the arguments.  Used for copyin. */
    113  1.16       erh int linux_socketcall_argsize[] = {
    114  1.16       erh 	-1,
    115  1.16       erh 	sizeof(struct linux_sys_socket_args),		/* 1 */
    116  1.16       erh 	sizeof(struct linux_sys_bind_args),
    117  1.16       erh 	sizeof(struct linux_sys_connect_args),
    118  1.16       erh 	sizeof(struct linux_sys_listen_args),
    119  1.16       erh 	sizeof(struct linux_sys_accept_args),		/* 5 */
    120  1.16       erh 	sizeof(struct linux_sys_getsockname_args),
    121  1.16       erh 	sizeof(struct linux_sys_getpeername_args),
    122  1.16       erh 	sizeof(struct linux_sys_socketpair_args),
    123  1.16       erh 	sizeof(struct linux_sys_send_args),
    124  1.16       erh 	sizeof(struct linux_sys_recv_args),		/* 10 */
    125  1.16       erh 	sizeof(struct linux_sys_sendto_args),
    126  1.16       erh 	sizeof(struct linux_sys_recvfrom_args),
    127  1.16       erh 	sizeof(struct linux_sys_shutdown_args),
    128  1.16       erh 	sizeof(struct linux_sys_setsockopt_args),
    129  1.16       erh 	sizeof(struct linux_sys_getsockopt_args),	/* 15 */
    130  1.16       erh 	sizeof(struct linux_sys_sendmsg_args),
    131  1.16       erh 	sizeof(struct linux_sys_recvmsg_args),		/* 17 */
    132  1.16       erh };
    133   1.1      fvdl 
    134   1.1      fvdl /*
    135   1.1      fvdl  * Entry point to all Linux socket calls. Just check which call to
    136   1.1      fvdl  * make and take appropriate action.
    137   1.1      fvdl  */
    138   1.1      fvdl int
    139  1.12   mycroft linux_sys_socketcall(p, v, retval)
    140   1.1      fvdl 	struct proc *p;
    141  1.11   thorpej 	void *v;
    142  1.11   thorpej 	register_t *retval;
    143  1.11   thorpej {
    144  1.12   mycroft 	struct linux_sys_socketcall_args /* {
    145   1.1      fvdl 		syscallarg(int) what;
    146   1.1      fvdl 		syscallarg(void *) args;
    147  1.11   thorpej 	} */ *uap = v;
    148  1.16       erh 	struct linux_socketcall_dummy_args lda;
    149  1.16       erh 	int error;
    150  1.16       erh 
    151  1.16       erh 	if (SCARG(uap, what) > LINUX_MAX_SOCKETCALL)
    152  1.16       erh 		return ENOSYS;
    153  1.16       erh 
    154  1.16       erh 	if ((error = copyin((caddr_t) SCARG(uap, args), (caddr_t) &lda,
    155  1.16       erh 	    linux_socketcall_argsize[SCARG(uap, what)])))
    156  1.16       erh 		return error;
    157  1.11   thorpej 
    158   1.1      fvdl 	switch (SCARG(uap, what)) {
    159   1.1      fvdl 	case LINUX_SYS_socket:
    160  1.16       erh 		return linux_sys_socket(p, (void *)&lda, retval);
    161   1.1      fvdl 	case LINUX_SYS_bind:
    162  1.16       erh 		return sys_bind(p, (void *)&lda, retval);
    163   1.1      fvdl 	case LINUX_SYS_connect:
    164  1.16       erh 		return sys_connect(p, (void *)&lda, retval);
    165   1.1      fvdl 	case LINUX_SYS_listen:
    166  1.16       erh 		return sys_listen(p, (void *)&lda, retval);
    167   1.1      fvdl 	case LINUX_SYS_accept:
    168  1.16       erh 		return compat_43_sys_accept(p, (void *)&lda, retval);
    169   1.1      fvdl 	case LINUX_SYS_getsockname:
    170  1.16       erh 		return compat_43_sys_getsockname(p, (void *)&lda, retval);
    171   1.1      fvdl 	case LINUX_SYS_getpeername:
    172  1.16       erh 		return compat_43_sys_getpeername(p, (void *)&lda, retval);
    173   1.1      fvdl 	case LINUX_SYS_socketpair:
    174  1.16       erh 		return linux_sys_socketpair(p, (void *)&lda, retval);
    175   1.1      fvdl 	case LINUX_SYS_send:
    176  1.16       erh 		return compat_43_sys_send(p, (void *)&lda, retval);
    177   1.1      fvdl 	case LINUX_SYS_recv:
    178  1.16       erh 		return compat_43_sys_recv(p, (void *)&lda, retval);
    179   1.1      fvdl 	case LINUX_SYS_sendto:
    180  1.16       erh 		return linux_sys_sendto(p, (void *)&lda, retval);
    181   1.1      fvdl 	case LINUX_SYS_recvfrom:
    182  1.16       erh 		return linux_sys_recvfrom(p, (void *)&lda, retval);
    183   1.1      fvdl 	case LINUX_SYS_shutdown:
    184  1.16       erh 		return sys_shutdown(p, (void *)&lda, retval);
    185   1.1      fvdl 	case LINUX_SYS_setsockopt:
    186  1.16       erh 		return linux_sys_setsockopt(p, (void *)&lda, retval);
    187   1.1      fvdl 	case LINUX_SYS_getsockopt:
    188  1.16       erh 		return linux_sys_getsockopt(p, (void *)&lda, retval);
    189  1.16       erh 	case LINUX_SYS_sendmsg:
    190  1.16       erh 		return sys_sendmsg(p, (void *)&lda, retval);
    191  1.16       erh 	case LINUX_SYS_recvmsg:
    192  1.16       erh 		return sys_recvmsg(p, (void *)&lda, retval);
    193   1.1      fvdl 	default:
    194   1.1      fvdl 		return ENOSYS;
    195   1.1      fvdl 	}
    196   1.1      fvdl }
    197