Annotation of src/sys/compat/linux/common/linux_socketcall.c, revision 1.26

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

CVSweb <webmaster@jp.NetBSD.org>