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