Home | History | Annotate | Line # | Download | only in common
linux_socketcall.c revision 1.21.2.3
      1  1.21.2.3  jdolecek /*	$NetBSD: linux_socketcall.c,v 1.21.2.3 2002/06/23 17:44:28 jdolecek Exp $	*/
      2      1.16       erh 
      3      1.16       erh /*-
      4      1.18      fvdl  * Copyright (c) 1995, 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.18      fvdl  * by Frank van der Linden and 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.1      fvdl  */
     38  1.21.2.2   thorpej 
     39  1.21.2.2   thorpej #include <sys/cdefs.h>
     40  1.21.2.3  jdolecek __KERNEL_RCSID(0, "$NetBSD: linux_socketcall.c,v 1.21.2.3 2002/06/23 17:44:28 jdolecek Exp $");
     41       1.1      fvdl 
     42       1.1      fvdl #include <sys/param.h>
     43       1.1      fvdl #include <sys/kernel.h>
     44       1.1      fvdl #include <sys/systm.h>
     45       1.1      fvdl #include <sys/buf.h>
     46       1.1      fvdl #include <sys/malloc.h>
     47       1.1      fvdl #include <sys/ioctl.h>
     48       1.1      fvdl #include <sys/tty.h>
     49       1.1      fvdl #include <sys/file.h>
     50       1.1      fvdl #include <sys/filedesc.h>
     51       1.1      fvdl #include <sys/select.h>
     52       1.1      fvdl #include <sys/socket.h>
     53       1.1      fvdl #include <sys/socketvar.h>
     54       1.1      fvdl #include <net/if.h>
     55       1.1      fvdl #include <netinet/in.h>
     56       1.7   mycroft #include <netinet/tcp.h>
     57       1.1      fvdl #include <sys/mount.h>
     58       1.1      fvdl #include <sys/proc.h>
     59       1.1      fvdl #include <sys/vnode.h>
     60       1.1      fvdl #include <sys/device.h>
     61       1.1      fvdl 
     62       1.1      fvdl #include <sys/syscallargs.h>
     63       1.1      fvdl 
     64      1.17  christos #include <compat/linux/common/linux_types.h>
     65      1.17  christos #include <compat/linux/common/linux_util.h>
     66      1.17  christos #include <compat/linux/common/linux_signal.h>
     67      1.17  christos #include <compat/linux/common/linux_ioctl.h>
     68      1.17  christos #include <compat/linux/common/linux_socket.h>
     69      1.17  christos #include <compat/linux/common/linux_socketcall.h>
     70      1.17  christos #include <compat/linux/common/linux_sockio.h>
     71      1.17  christos 
     72       1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     73       1.1      fvdl 
     74  1.21.2.3  jdolecek #undef DPRINTF
     75  1.21.2.3  jdolecek #ifdef DEBUG_LINUX
     76  1.21.2.3  jdolecek #define DPRINTF(a)	uprintf a
     77  1.21.2.3  jdolecek #else
     78  1.21.2.3  jdolecek #define DPRINTF(a)
     79  1.21.2.3  jdolecek #endif
     80  1.21.2.3  jdolecek 
     81      1.16       erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
     82      1.16       erh /* Not used on: alpha */
     83       1.1      fvdl 
     84       1.1      fvdl /*
     85      1.16       erh  * This file contains the linux_socketcall() multiplexer.  Arguments
     86      1.16       erh  * for the various socket calls are on the user stack. A pointer
     87      1.16       erh  * to them is the only thing that is passed.  We copyin the arguments
     88      1.16       erh  * here so the individual functions can assume they are normal syscalls.
     89      1.16       erh  */
     90      1.16       erh 
     91      1.16       erh /* The sizes of the arguments.  Used for copyin. */
     92  1.21.2.3  jdolecek static const struct {
     93  1.21.2.3  jdolecek 	char *name;
     94  1.21.2.3  jdolecek 	int argsize;
     95  1.21.2.3  jdolecek } linux_socketcall[LINUX_MAX_SOCKETCALL+1] = {
     96  1.21.2.3  jdolecek 	{"invalid",	-1},						/* 0 */
     97  1.21.2.3  jdolecek 	{"socket",	sizeof(struct linux_sys_socket_args)},		/* 1 */
     98  1.21.2.3  jdolecek 	{"bind",	sizeof(struct linux_sys_bind_args)},		/* 2 */
     99  1.21.2.3  jdolecek 	{"connect",	sizeof(struct linux_sys_connect_args)},		/* 3 */
    100  1.21.2.3  jdolecek 	{"listen",	sizeof(struct linux_sys_listen_args)},		/* 4 */
    101  1.21.2.3  jdolecek 	{"accept",	sizeof(struct linux_sys_accept_args)},		/* 5 */
    102  1.21.2.3  jdolecek 	{"getsockname",	sizeof(struct linux_sys_getsockname_args)},	/* 6 */
    103  1.21.2.3  jdolecek 	{"getpeername",	sizeof(struct linux_sys_getpeername_args)},	/* 7 */
    104  1.21.2.3  jdolecek 	{"socketpair",	sizeof(struct linux_sys_socketpair_args)},	/* 8 */
    105  1.21.2.3  jdolecek 	{"send",	sizeof(struct linux_sys_send_args)},		/* 9 */
    106  1.21.2.3  jdolecek 	{"recv",	sizeof(struct linux_sys_recv_args)},		/* 10 */
    107  1.21.2.3  jdolecek 	{"sendto",	sizeof(struct linux_sys_sendto_args)},		/* 11 */
    108  1.21.2.3  jdolecek 	{"recvfrom",	sizeof(struct linux_sys_recvfrom_args)},	/* 12 */
    109  1.21.2.3  jdolecek 	{"shutdown",	sizeof(struct linux_sys_shutdown_args)},	/* 13 */
    110  1.21.2.3  jdolecek 	{"setsockopt",	sizeof(struct linux_sys_setsockopt_args)},	/* 14 */
    111  1.21.2.3  jdolecek 	{"getsockopt",	sizeof(struct linux_sys_getsockopt_args)},	/* 15 */
    112  1.21.2.3  jdolecek 	{"sendmsg",	sizeof(struct linux_sys_sendmsg_args)},		/* 16 */
    113  1.21.2.3  jdolecek 	{"recvmsg",	sizeof(struct linux_sys_recvmsg_args)},		/* 17 */
    114      1.16       erh };
    115       1.1      fvdl 
    116       1.1      fvdl /*
    117       1.1      fvdl  * Entry point to all Linux socket calls. Just check which call to
    118       1.1      fvdl  * make and take appropriate action.
    119       1.1      fvdl  */
    120       1.1      fvdl int
    121      1.12   mycroft linux_sys_socketcall(p, v, retval)
    122       1.1      fvdl 	struct proc *p;
    123      1.11   thorpej 	void *v;
    124      1.11   thorpej 	register_t *retval;
    125      1.11   thorpej {
    126      1.12   mycroft 	struct linux_sys_socketcall_args /* {
    127       1.1      fvdl 		syscallarg(int) what;
    128       1.1      fvdl 		syscallarg(void *) args;
    129      1.11   thorpej 	} */ *uap = v;
    130      1.16       erh 	struct linux_socketcall_dummy_args lda;
    131      1.16       erh 	int error;
    132      1.16       erh 
    133      1.20  jdolecek 	if (SCARG(uap, what) < 0 || SCARG(uap, what) > LINUX_MAX_SOCKETCALL)
    134      1.16       erh 		return ENOSYS;
    135      1.16       erh 
    136      1.16       erh 	if ((error = copyin((caddr_t) SCARG(uap, args), (caddr_t) &lda,
    137  1.21.2.3  jdolecek 	    linux_socketcall[SCARG(uap, what)].argsize))) {
    138  1.21.2.3  jdolecek 		DPRINTF(("copyin for %s failed %d\n",
    139  1.21.2.3  jdolecek 		linux_socketcall[SCARG(uap, what)].name, error));
    140      1.16       erh 		return error;
    141  1.21.2.3  jdolecek 	}
    142      1.11   thorpej 
    143       1.1      fvdl 	switch (SCARG(uap, what)) {
    144       1.1      fvdl 	case LINUX_SYS_socket:
    145  1.21.2.3  jdolecek 		error = linux_sys_socket(p, (void *)&lda, retval);
    146  1.21.2.3  jdolecek 		break;
    147       1.1      fvdl 	case LINUX_SYS_bind:
    148  1.21.2.3  jdolecek 		error = linux_sys_bind(p, (void *)&lda, retval);
    149  1.21.2.3  jdolecek 		break;
    150       1.1      fvdl 	case LINUX_SYS_connect:
    151  1.21.2.3  jdolecek 		error = linux_sys_connect(p, (void *)&lda, retval);
    152  1.21.2.3  jdolecek 		break;
    153       1.1      fvdl 	case LINUX_SYS_listen:
    154  1.21.2.3  jdolecek 		error = sys_listen(p, (void *)&lda, retval);
    155  1.21.2.3  jdolecek 		break;
    156       1.1      fvdl 	case LINUX_SYS_accept:
    157  1.21.2.3  jdolecek 		error = linux_sys_accept(p, (void *)&lda, retval);
    158  1.21.2.3  jdolecek 		break;
    159       1.1      fvdl 	case LINUX_SYS_getsockname:
    160  1.21.2.3  jdolecek 		error = linux_sys_getsockname(p, (void *)&lda, retval);
    161  1.21.2.3  jdolecek 		break;
    162       1.1      fvdl 	case LINUX_SYS_getpeername:
    163  1.21.2.3  jdolecek 		error = linux_sys_getpeername(p, (void *)&lda, retval);
    164  1.21.2.3  jdolecek 		break;
    165       1.1      fvdl 	case LINUX_SYS_socketpair:
    166  1.21.2.3  jdolecek 		error = linux_sys_socketpair(p, (void *)&lda, retval);
    167  1.21.2.3  jdolecek 		break;
    168       1.1      fvdl 	case LINUX_SYS_send:
    169  1.21.2.3  jdolecek 		error = linux_sys_send(p, (void *)&lda, retval);
    170  1.21.2.3  jdolecek 		break;
    171       1.1      fvdl 	case LINUX_SYS_recv:
    172  1.21.2.3  jdolecek 		error = linux_sys_recv(p, (void *)&lda, retval);
    173  1.21.2.3  jdolecek 		break;
    174       1.1      fvdl 	case LINUX_SYS_sendto:
    175  1.21.2.3  jdolecek 		error = linux_sys_sendto(p, (void *)&lda, retval);
    176  1.21.2.3  jdolecek 		break;
    177       1.1      fvdl 	case LINUX_SYS_recvfrom:
    178  1.21.2.3  jdolecek 		error = linux_sys_recvfrom(p, (void *)&lda, retval);
    179  1.21.2.3  jdolecek 		break;
    180       1.1      fvdl 	case LINUX_SYS_shutdown:
    181  1.21.2.3  jdolecek 		error = sys_shutdown(p, (void *)&lda, retval);
    182  1.21.2.3  jdolecek 		break;
    183       1.1      fvdl 	case LINUX_SYS_setsockopt:
    184  1.21.2.3  jdolecek 		error = linux_sys_setsockopt(p, (void *)&lda, retval);
    185  1.21.2.3  jdolecek 		break;
    186       1.1      fvdl 	case LINUX_SYS_getsockopt:
    187  1.21.2.3  jdolecek 		error = linux_sys_getsockopt(p, (void *)&lda, retval);
    188  1.21.2.3  jdolecek 		break;
    189      1.16       erh 	case LINUX_SYS_sendmsg:
    190  1.21.2.3  jdolecek 		error = linux_sys_sendmsg(p, (void *)&lda, retval);
    191  1.21.2.3  jdolecek 		break;
    192      1.16       erh 	case LINUX_SYS_recvmsg:
    193  1.21.2.3  jdolecek 		error = linux_sys_recvmsg(p, (void *)&lda, retval);
    194  1.21.2.3  jdolecek 		break;
    195       1.1      fvdl 	default:
    196  1.21.2.3  jdolecek 		error = ENOSYS;
    197  1.21.2.3  jdolecek 		break;
    198       1.1      fvdl 	}
    199  1.21.2.3  jdolecek 
    200  1.21.2.3  jdolecek 	DPRINTF(("sys_%s() = %d\n", linux_socketcall[SCARG(uap, what)].name,
    201  1.21.2.3  jdolecek 	    error));
    202  1.21.2.3  jdolecek 	return error;
    203       1.1      fvdl }
    204