uipc_syscalls_43.c revision 1.13 1 1.13 jdolecek /* $NetBSD: uipc_syscalls_43.c,v 1.13 2001/06/25 20:46:11 jdolecek Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 1982, 1986, 1989, 1990, 1993
5 1.1 christos * The Regents of the University of California. All rights reserved.
6 1.1 christos *
7 1.1 christos * Redistribution and use in source and binary forms, with or without
8 1.1 christos * modification, are permitted provided that the following conditions
9 1.1 christos * are met:
10 1.1 christos * 1. Redistributions of source code must retain the above copyright
11 1.1 christos * notice, this list of conditions and the following disclaimer.
12 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 christos * notice, this list of conditions and the following disclaimer in the
14 1.1 christos * documentation and/or other materials provided with the distribution.
15 1.1 christos * 3. All advertising materials mentioning features or use of this software
16 1.1 christos * must display the following acknowledgement:
17 1.1 christos * This product includes software developed by the University of
18 1.1 christos * California, Berkeley and its contributors.
19 1.1 christos * 4. Neither the name of the University nor the names of its contributors
20 1.1 christos * may be used to endorse or promote products derived from this software
21 1.1 christos * without specific prior written permission.
22 1.1 christos *
23 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 christos * SUCH DAMAGE.
34 1.1 christos *
35 1.1 christos * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94
36 1.1 christos */
37 1.1 christos
38 1.10 drochner #define COMPAT_OLDSOCK /* used by <sys/socket.h> */
39 1.10 drochner
40 1.1 christos #include <sys/param.h>
41 1.1 christos #include <sys/systm.h>
42 1.1 christos #include <sys/filedesc.h>
43 1.1 christos #include <sys/kernel.h>
44 1.1 christos #include <sys/proc.h>
45 1.1 christos #include <sys/file.h>
46 1.1 christos #include <sys/socket.h>
47 1.1 christos #include <sys/socketvar.h>
48 1.1 christos #include <sys/stat.h>
49 1.1 christos #include <sys/ioctl.h>
50 1.1 christos #include <sys/fcntl.h>
51 1.1 christos #include <sys/malloc.h>
52 1.1 christos #include <sys/syslog.h>
53 1.1 christos #include <sys/unistd.h>
54 1.1 christos #include <sys/resourcevar.h>
55 1.1 christos
56 1.1 christos #include <sys/mount.h>
57 1.1 christos #include <sys/syscallargs.h>
58 1.1 christos
59 1.1 christos int
60 1.3 mycroft compat_43_sys_accept(p, v, retval)
61 1.1 christos struct proc *p;
62 1.2 thorpej void *v;
63 1.2 thorpej register_t *retval;
64 1.2 thorpej {
65 1.3 mycroft struct sys_accept_args /* {
66 1.1 christos syscallarg(int) s;
67 1.1 christos syscallarg(caddr_t) name;
68 1.1 christos syscallarg(int *) anamelen;
69 1.2 thorpej } */ *uap = v;
70 1.1 christos int error;
71 1.1 christos
72 1.3 mycroft if ((error = sys_accept(p, uap, retval)) != 0)
73 1.1 christos return error;
74 1.1 christos
75 1.1 christos if (SCARG(uap, name)) {
76 1.1 christos struct sockaddr sa;
77 1.1 christos
78 1.1 christos if ((error = copyin(SCARG(uap, name), &sa, sizeof(sa))) != 0)
79 1.1 christos return error;
80 1.1 christos
81 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
82 1.1 christos
83 1.1 christos if ((error = copyout(&sa, SCARG(uap, name), sizeof(sa))) != 0)
84 1.1 christos return error;
85 1.1 christos }
86 1.1 christos return 0;
87 1.1 christos }
88 1.1 christos
89 1.1 christos int
90 1.3 mycroft compat_43_sys_getpeername(p, v, retval)
91 1.1 christos struct proc *p;
92 1.2 thorpej void *v;
93 1.2 thorpej register_t *retval;
94 1.2 thorpej {
95 1.3 mycroft struct sys_getpeername_args /* {
96 1.1 christos syscallarg(int) fdes;
97 1.1 christos syscallarg(caddr_t) asa;
98 1.1 christos syscallarg(int *) alen;
99 1.2 thorpej } */ *uap = v;
100 1.1 christos struct sockaddr sa;
101 1.1 christos
102 1.1 christos int error;
103 1.1 christos
104 1.3 mycroft if ((error = sys_getpeername(p, uap, retval)) != 0)
105 1.1 christos return error;
106 1.1 christos
107 1.1 christos if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
108 1.1 christos return error;
109 1.1 christos
110 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
111 1.1 christos
112 1.1 christos if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
113 1.1 christos return error;
114 1.1 christos
115 1.1 christos return 0;
116 1.1 christos }
117 1.1 christos
118 1.1 christos int
119 1.3 mycroft compat_43_sys_getsockname(p, v, retval)
120 1.1 christos struct proc *p;
121 1.2 thorpej void *v;
122 1.2 thorpej register_t *retval;
123 1.2 thorpej {
124 1.3 mycroft struct sys_getsockname_args /* {
125 1.1 christos syscallarg(int) fdes;
126 1.1 christos syscallarg(caddr_t) asa;
127 1.1 christos syscallarg(int *) alen;
128 1.2 thorpej } */ *uap = v;
129 1.1 christos struct sockaddr sa;
130 1.1 christos int error;
131 1.1 christos
132 1.3 mycroft if ((error = sys_getsockname(p, uap, retval)) != 0)
133 1.1 christos return error;
134 1.1 christos
135 1.1 christos if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
136 1.1 christos return error;
137 1.1 christos
138 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
139 1.1 christos
140 1.1 christos if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
141 1.1 christos return error;
142 1.1 christos
143 1.1 christos return 0;
144 1.1 christos }
145 1.1 christos
146 1.1 christos int
147 1.3 mycroft compat_43_sys_recv(p, v, retval)
148 1.1 christos struct proc *p;
149 1.2 thorpej void *v;
150 1.2 thorpej register_t *retval;
151 1.2 thorpej {
152 1.11 augustss struct compat_43_sys_recv_args /* {
153 1.1 christos syscallarg(int) s;
154 1.1 christos syscallarg(caddr_t) buf;
155 1.1 christos syscallarg(int) len;
156 1.1 christos syscallarg(int) flags;
157 1.2 thorpej } */ *uap = v;
158 1.1 christos struct msghdr msg;
159 1.1 christos struct iovec aiov;
160 1.1 christos
161 1.1 christos msg.msg_name = 0;
162 1.1 christos msg.msg_namelen = 0;
163 1.1 christos msg.msg_iov = &aiov;
164 1.1 christos msg.msg_iovlen = 1;
165 1.1 christos aiov.iov_base = SCARG(uap, buf);
166 1.1 christos aiov.iov_len = SCARG(uap, len);
167 1.1 christos msg.msg_control = 0;
168 1.1 christos msg.msg_flags = SCARG(uap, flags);
169 1.13 jdolecek return (recvit(p, SCARG(uap, s), &msg, (caddr_t)0, retval));
170 1.1 christos }
171 1.1 christos
172 1.1 christos int
173 1.3 mycroft compat_43_sys_recvfrom(p, v, retval)
174 1.1 christos struct proc *p;
175 1.2 thorpej void *v;
176 1.2 thorpej register_t *retval;
177 1.2 thorpej {
178 1.3 mycroft struct sys_recvfrom_args /* {
179 1.1 christos syscallarg(int) s;
180 1.1 christos syscallarg(caddr_t) buf;
181 1.1 christos syscallarg(size_t) len;
182 1.1 christos syscallarg(int) flags;
183 1.1 christos syscallarg(caddr_t) from;
184 1.1 christos syscallarg(int *) fromlenaddr;
185 1.2 thorpej } */ *uap = v;
186 1.1 christos
187 1.1 christos SCARG(uap, flags) |= MSG_COMPAT;
188 1.3 mycroft return (sys_recvfrom(p, uap, retval));
189 1.1 christos }
190 1.1 christos
191 1.1 christos /*
192 1.1 christos * Old recvmsg. This code takes advantage of the fact that the old msghdr
193 1.1 christos * overlays the new one, missing only the flags, and with the (old) access
194 1.1 christos * rights where the control fields are now.
195 1.1 christos */
196 1.1 christos int
197 1.3 mycroft compat_43_sys_recvmsg(p, v, retval)
198 1.1 christos struct proc *p;
199 1.2 thorpej void *v;
200 1.2 thorpej register_t *retval;
201 1.2 thorpej {
202 1.11 augustss struct compat_43_sys_recvmsg_args /* {
203 1.1 christos syscallarg(int) s;
204 1.1 christos syscallarg(struct omsghdr *) msg;
205 1.1 christos syscallarg(int) flags;
206 1.2 thorpej } */ *uap = v;
207 1.1 christos struct msghdr msg;
208 1.1 christos struct iovec aiov[UIO_SMALLIOV], *iov;
209 1.1 christos int error;
210 1.1 christos
211 1.5 christos error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg,
212 1.5 christos sizeof (struct omsghdr));
213 1.5 christos if (error)
214 1.1 christos return (error);
215 1.6 kleink if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
216 1.7 kleink if ((u_int)msg.msg_iovlen > IOV_MAX)
217 1.1 christos return (EMSGSIZE);
218 1.1 christos MALLOC(iov, struct iovec *,
219 1.1 christos sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
220 1.1 christos M_WAITOK);
221 1.1 christos } else
222 1.1 christos iov = aiov;
223 1.1 christos msg.msg_flags = SCARG(uap, flags) | MSG_COMPAT;
224 1.5 christos error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
225 1.5 christos (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
226 1.5 christos if (error)
227 1.1 christos goto done;
228 1.1 christos msg.msg_iov = iov;
229 1.1 christos error = recvit(p, SCARG(uap, s), &msg,
230 1.13 jdolecek (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
231 1.1 christos
232 1.1 christos if (msg.msg_controllen && error == 0)
233 1.1 christos error = copyout((caddr_t)&msg.msg_controllen,
234 1.1 christos (caddr_t)&SCARG(uap, msg)->msg_accrightslen, sizeof (int));
235 1.1 christos done:
236 1.1 christos if (iov != aiov)
237 1.1 christos FREE(iov, M_IOV);
238 1.1 christos return (error);
239 1.1 christos }
240 1.1 christos
241 1.1 christos int
242 1.3 mycroft compat_43_sys_send(p, v, retval)
243 1.1 christos struct proc *p;
244 1.2 thorpej void *v;
245 1.2 thorpej register_t *retval;
246 1.2 thorpej {
247 1.11 augustss struct compat_43_sys_send_args /* {
248 1.1 christos syscallarg(int) s;
249 1.1 christos syscallarg(caddr_t) buf;
250 1.1 christos syscallarg(int) len;
251 1.1 christos syscallarg(int) flags;
252 1.2 thorpej } */ *uap = v;
253 1.1 christos struct msghdr msg;
254 1.1 christos struct iovec aiov;
255 1.1 christos
256 1.1 christos msg.msg_name = 0;
257 1.1 christos msg.msg_namelen = 0;
258 1.1 christos msg.msg_iov = &aiov;
259 1.1 christos msg.msg_iovlen = 1;
260 1.1 christos aiov.iov_base = SCARG(uap, buf);
261 1.1 christos aiov.iov_len = SCARG(uap, len);
262 1.1 christos msg.msg_control = 0;
263 1.1 christos msg.msg_flags = 0;
264 1.13 jdolecek return (sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval));
265 1.1 christos }
266 1.1 christos
267 1.1 christos int
268 1.3 mycroft compat_43_sys_sendmsg(p, v, retval)
269 1.1 christos struct proc *p;
270 1.2 thorpej void *v;
271 1.2 thorpej register_t *retval;
272 1.2 thorpej {
273 1.11 augustss struct compat_43_sys_sendmsg_args /* {
274 1.1 christos syscallarg(int) s;
275 1.1 christos syscallarg(caddr_t) msg;
276 1.1 christos syscallarg(int) flags;
277 1.2 thorpej } */ *uap = v;
278 1.1 christos struct msghdr msg;
279 1.1 christos struct iovec aiov[UIO_SMALLIOV], *iov;
280 1.1 christos int error;
281 1.1 christos
282 1.5 christos error = copyin(SCARG(uap, msg), (caddr_t)&msg,
283 1.5 christos sizeof (struct omsghdr));
284 1.5 christos if (error)
285 1.1 christos return (error);
286 1.6 kleink if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
287 1.7 kleink if ((u_int)msg.msg_iovlen > IOV_MAX)
288 1.1 christos return (EMSGSIZE);
289 1.1 christos MALLOC(iov, struct iovec *,
290 1.1 christos sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
291 1.1 christos M_WAITOK);
292 1.1 christos } else
293 1.1 christos iov = aiov;
294 1.5 christos error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
295 1.5 christos (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
296 1.5 christos if (error)
297 1.1 christos goto done;
298 1.1 christos msg.msg_flags = MSG_COMPAT;
299 1.1 christos msg.msg_iov = iov;
300 1.13 jdolecek error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
301 1.1 christos done:
302 1.1 christos if (iov != aiov)
303 1.1 christos FREE(iov, M_IOV);
304 1.1 christos return (error);
305 1.1 christos }
306