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

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

CVSweb <webmaster@jp.NetBSD.org>