Annotation of src/sys/compat/linux/common/linux_socket.c, revision 1.45
1.45 ! darrenr 1: /* $NetBSD: linux_socket.c,v 1.44 2003/03/21 21:13:53 dsl 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: */
38:
1.16 erh 39: /*
40: * Functions in multiarch:
41: * linux_sys_socketcall : linux_socketcall.c
1.32 jdolecek 42: *
43: * XXX Note: Linux CMSG_ALIGN() uses (sizeof(long)-1). For architectures
44: * where our CMSG_ALIGN() differs (like powerpc, sparc, sparc64), the passed
45: * control structure would need to be adjusted accordingly in sendmsg() and
46: * recvmsg().
1.16 erh 47: */
1.35 lukem 48:
49: #include <sys/cdefs.h>
1.45 ! darrenr 50: __KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.44 2003/03/21 21:13:53 dsl Exp $");
1.16 erh 51:
1.32 jdolecek 52: #if defined(_KERNEL_OPT)
53: #include "opt_inet.h"
54: #endif
55:
1.1 fvdl 56: #include <sys/param.h>
57: #include <sys/kernel.h>
58: #include <sys/systm.h>
59: #include <sys/buf.h>
60: #include <sys/malloc.h>
61: #include <sys/ioctl.h>
62: #include <sys/tty.h>
63: #include <sys/file.h>
64: #include <sys/filedesc.h>
65: #include <sys/select.h>
66: #include <sys/socket.h>
67: #include <sys/socketvar.h>
68: #include <net/if.h>
1.21 jtk 69: #include <net/if_dl.h>
70: #include <net/if_types.h>
1.1 fvdl 71: #include <netinet/in.h>
1.7 mycroft 72: #include <netinet/tcp.h>
1.1 fvdl 73: #include <sys/mount.h>
74: #include <sys/proc.h>
75: #include <sys/vnode.h>
76: #include <sys/device.h>
1.19 sommerfe 77: #include <sys/protosw.h>
1.32 jdolecek 78: #include <sys/mbuf.h>
79: #include <sys/syslog.h>
1.1 fvdl 80:
1.43 thorpej 81: #include <sys/sa.h>
1.1 fvdl 82: #include <sys/syscallargs.h>
83:
1.42 fvdl 84: #ifdef INET6
85: #include <netinet/ip6.h>
86: #include <netinet6/ip6_var.h>
87: #endif
88:
1.17 christos 89: #include <compat/linux/common/linux_types.h>
90: #include <compat/linux/common/linux_util.h>
91: #include <compat/linux/common/linux_signal.h>
92: #include <compat/linux/common/linux_ioctl.h>
93: #include <compat/linux/common/linux_socket.h>
94: #include <compat/linux/common/linux_socketcall.h>
95: #include <compat/linux/common/linux_sockio.h>
96:
1.1 fvdl 97: #include <compat/linux/linux_syscallargs.h>
1.21 jtk 98:
1.37 christos 99: #ifdef DEBUG_LINUX
100: #define DPRINTF(a) uprintf a
101: #else
102: #define DPRINTF(a)
103: #endif
104:
1.1 fvdl 105: /*
1.16 erh 106: * The calls in this file are entered either via the linux_socketcall()
107: * interface or, on the Alpha, as individual syscalls. The
108: * linux_socketcall function does any massaging of arguments so that all
109: * the calls in here need not think that they are anything other
110: * than a normal syscall.
1.1 fvdl 111: */
1.14 christos 112:
1.32 jdolecek 113: static int linux_to_bsd_domain __P((int));
114: static int bsd_to_linux_domain __P((int));
1.14 christos 115: int linux_to_bsd_sopt_level __P((int));
116: int linux_to_bsd_so_sockopt __P((int));
117: int linux_to_bsd_ip_sockopt __P((int));
118: int linux_to_bsd_tcp_sockopt __P((int));
119: int linux_to_bsd_udp_sockopt __P((int));
1.45 ! darrenr 120: int linux_getifhwaddr __P((struct lwp *, register_t *, u_int, void *));
1.36 christos 121: static int linux_sa_get __P((struct proc *, caddr_t *sgp, struct sockaddr **sap,
1.34 fvdl 122: const struct osockaddr *osa, int *osalen));
1.32 jdolecek 123: static int linux_sa_put __P((struct osockaddr *osa));
124:
125: static const int linux_to_bsd_domain_[LINUX_AF_MAX] = {
126: AF_UNSPEC,
127: AF_UNIX,
128: AF_INET,
129: AF_CCITT, /* LINUX_AF_AX25 */
130: AF_IPX,
131: AF_APPLETALK,
132: -1, /* LINUX_AF_NETROM */
133: -1, /* LINUX_AF_BRIDGE */
134: -1, /* LINUX_AF_ATMPVC */
135: AF_CCITT, /* LINUX_AF_X25 */
136: AF_INET6,
137: -1, /* LINUX_AF_ROSE */
138: AF_DECnet,
139: -1, /* LINUX_AF_NETBEUI */
140: -1, /* LINUX_AF_SECURITY */
141: pseudo_AF_KEY,
142: AF_ROUTE, /* LINUX_AF_NETLINK */
143: -1, /* LINUX_AF_PACKET */
144: -1, /* LINUX_AF_ASH */
145: -1, /* LINUX_AF_ECONET */
146: -1, /* LINUX_AF_ATMSVC */
147: AF_SNA,
148: /* rest up to LINUX_AF_MAX-1 is not allocated */
149: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
150: };
151:
152: static const int bsd_to_linux_domain_[AF_MAX] = {
153: LINUX_AF_UNSPEC,
154: LINUX_AF_UNIX,
155: LINUX_AF_INET,
156: -1, /* AF_IMPLINK */
157: -1, /* AF_PUP */
158: -1, /* AF_CHAOS */
159: -1, /* AF_NS */
160: -1, /* AF_ISO */
161: -1, /* AF_ECMA */
162: -1, /* AF_DATAKIT */
163: LINUX_AF_AX25, /* AF_CCITT */
164: LINUX_AF_SNA,
165: LINUX_AF_DECnet,
166: -1, /* AF_DLI */
167: -1, /* AF_LAT */
168: -1, /* AF_HYLINK */
169: LINUX_AF_APPLETALK,
170: LINUX_AF_NETLINK,
171: -1, /* AF_LINK */
172: -1, /* AF_XTP */
173: -1, /* AF_COIP */
174: -1, /* AF_CNT */
175: -1, /* pseudo_AF_RTIP */
176: LINUX_AF_IPX,
177: LINUX_AF_INET6,
178: -1, /* pseudo_AF_PIP */
179: -1, /* AF_ISDN */
180: -1, /* AF_NATM */
181: -1, /* AF_ARP */
182: LINUX_pseudo_AF_KEY,
183: -1, /* pseudo_AF_HDRCMPLT */
184: };
1.1 fvdl 185:
186: /*
187: * Convert between Linux and BSD socket domain values
188: */
1.32 jdolecek 189: static int
1.1 fvdl 190: linux_to_bsd_domain(ldom)
191: int ldom;
192: {
1.32 jdolecek 193: if (ldom < 0 || ldom >= LINUX_AF_MAX)
194: return (-1);
195:
196: return linux_to_bsd_domain_[ldom];
197: }
198:
199: /*
200: * Convert between BSD and Linux socket domain values
201: */
202: static int
203: bsd_to_linux_domain(bdom)
204: int bdom;
205: {
206: if (bdom < 0 || bdom >= AF_MAX)
207: return (-1);
1.12 mycroft 208:
1.32 jdolecek 209: return bsd_to_linux_domain_[bdom];
1.1 fvdl 210: }
211:
1.2 mycroft 212: int
1.43 thorpej 213: linux_sys_socket(l, v, retval)
214: struct lwp *l;
1.16 erh 215: void *v;
216: register_t *retval;
217: {
218: struct linux_sys_socket_args /* {
1.1 fvdl 219: syscallarg(int) domain;
220: syscallarg(int) type;
221: syscallarg(int) protocol;
1.16 erh 222: } */ *uap = v;
1.12 mycroft 223: struct sys_socket_args bsa;
1.42 fvdl 224: int error;
1.1 fvdl 225:
1.16 erh 226: SCARG(&bsa, protocol) = SCARG(uap, protocol);
227: SCARG(&bsa, type) = SCARG(uap, type);
228: SCARG(&bsa, domain) = linux_to_bsd_domain(SCARG(uap, domain));
1.1 fvdl 229: if (SCARG(&bsa, domain) == -1)
230: return EINVAL;
1.43 thorpej 231: error = sys_socket(l, &bsa, retval);
1.41 itojun 232:
233: #ifdef INET6
234: /*
1.42 fvdl 235: * Linux AF_INET6 socket has IPV6_V6ONLY setsockopt set to 0 by
236: * default and some apps depend on this. So, set V6ONLY to 0
237: * for Linux apps if the sysctl value is set to 1.
1.41 itojun 238: */
1.42 fvdl 239: if (!error && ip6_v6only && SCARG(&bsa, domain) == PF_INET6) {
1.43 thorpej 240: struct proc *p = l->l_proc;
1.42 fvdl 241: struct file *fp;
242:
243: if (getsock(p->p_fd, *retval, &fp) == 0) {
244: struct mbuf *m;
245:
246: m = m_get(M_WAIT, MT_SOOPTS);
247: m->m_len = sizeof(int);
248: *mtod(m, int *) = 0;
249:
250: /* ignore error */
251: (void) sosetopt((struct socket *)fp->f_data,
252: IPPROTO_IPV6, IPV6_V6ONLY, m);
253:
1.45 ! darrenr 254: FILE_UNUSE(fp, l);
1.41 itojun 255: }
256: }
257: #endif
258:
1.42 fvdl 259: return (error);
1.1 fvdl 260: }
261:
1.2 mycroft 262: int
1.43 thorpej 263: linux_sys_socketpair(l, v, retval)
264: struct lwp *l;
1.16 erh 265: void *v;
1.1 fvdl 266: register_t *retval;
267: {
1.16 erh 268: struct linux_sys_socketpair_args /* {
1.1 fvdl 269: syscallarg(int) domain;
270: syscallarg(int) type;
271: syscallarg(int) protocol;
272: syscallarg(int *) rsv;
1.16 erh 273: } */ *uap = v;
1.12 mycroft 274: struct sys_socketpair_args bsa;
1.1 fvdl 275:
1.16 erh 276: SCARG(&bsa, domain) = linux_to_bsd_domain(SCARG(uap, domain));
1.1 fvdl 277: if (SCARG(&bsa, domain) == -1)
278: return EINVAL;
1.16 erh 279: SCARG(&bsa, type) = SCARG(uap, type);
280: SCARG(&bsa, protocol) = SCARG(uap, protocol);
281: SCARG(&bsa, rsv) = SCARG(uap, rsv);
1.1 fvdl 282:
1.43 thorpej 283: return sys_socketpair(l, &bsa, retval);
1.1 fvdl 284: }
285:
1.2 mycroft 286: int
1.43 thorpej 287: linux_sys_sendto(l, v, retval)
288: struct lwp *l;
1.16 erh 289: void *v;
1.1 fvdl 290: register_t *retval;
291: {
1.16 erh 292: struct linux_sys_sendto_args /* {
1.32 jdolecek 293: syscallarg(int) s;
294: syscallarg(void *) msg;
295: syscallarg(int) len;
296: syscallarg(int) flags;
297: syscallarg(struct osockaddr *) to;
298: syscallarg(int) tolen;
1.16 erh 299: } */ *uap = v;
1.43 thorpej 300: struct proc *p = l->l_proc;
1.12 mycroft 301: struct sys_sendto_args bsa;
1.34 fvdl 302: int tolen;
1.1 fvdl 303:
1.16 erh 304: SCARG(&bsa, s) = SCARG(uap, s);
305: SCARG(&bsa, buf) = SCARG(uap, msg);
1.32 jdolecek 306: SCARG(&bsa, len) = (size_t) SCARG(uap, len);
1.16 erh 307: SCARG(&bsa, flags) = SCARG(uap, flags);
1.34 fvdl 308: tolen = SCARG(uap, tolen);
1.32 jdolecek 309: if (SCARG(uap, to)) {
310: struct sockaddr *sa;
311: int error;
1.36 christos 312: caddr_t sg = stackgap_init(p, 0);
1.32 jdolecek 313:
1.36 christos 314: if ((error = linux_sa_get(p, &sg, &sa, SCARG(uap, to), &tolen)))
1.32 jdolecek 315: return (error);
316:
317: SCARG(&bsa, to) = sa;
318: } else
319: SCARG(&bsa, to) = NULL;
1.34 fvdl 320: SCARG(&bsa, tolen) = tolen;
1.1 fvdl 321:
1.43 thorpej 322: return (sys_sendto(l, &bsa, retval));
1.32 jdolecek 323: }
324:
325: int
1.43 thorpej 326: linux_sys_sendmsg(l, v, retval)
327: struct lwp *l;
1.32 jdolecek 328: void *v;
329: register_t *retval;
330: {
331: struct linux_sys_sendmsg_args /* {
332: syscallarg(int) s;
333: syscallarg(struct msghdr *) msg;
334: syscallarg(u_int) flags;
335: } */ *uap = v;
1.43 thorpej 336: struct proc *p = l->l_proc;
1.32 jdolecek 337: struct msghdr msg;
338: int error;
339: struct sys_sendmsg_args bsa;
340: struct msghdr *nmsg = NULL;
341:
342: error = copyin(SCARG(uap, msg), (caddr_t)&msg, sizeof(msg));
343: if (error)
344: return (error);
345:
346: if (msg.msg_name) {
347: struct sockaddr *sa;
1.36 christos 348: caddr_t sg = stackgap_init(p, 0);
1.32 jdolecek 349:
1.36 christos 350: nmsg = (struct msghdr *) stackgap_alloc(p, &sg,
1.32 jdolecek 351: sizeof(struct msghdr));
352: if (!nmsg)
353: return (ENOMEM);
354:
1.36 christos 355: error = linux_sa_get(p, &sg, &sa,
1.34 fvdl 356: (struct osockaddr *) msg.msg_name, &msg.msg_namelen);
1.32 jdolecek 357: if (error)
358: return (error);
359:
360: msg.msg_name = (struct sockaddr *) sa;
361: if ((error = copyout(&msg, nmsg, sizeof(struct msghdr))))
362: return (error);
363: }
364:
365: /*
366: * XXX handle different alignment of cmsg data on architectures where
367: * the Linux alignment is different (powerpc, sparc, sparc64).
368: */
369:
370: SCARG(&bsa, s) = SCARG(uap, s);
371: SCARG(&bsa, msg) = nmsg;
372: SCARG(&bsa, flags) = SCARG(uap, flags);
373:
1.43 thorpej 374: if ((error = sys_sendmsg(l, &bsa, retval)))
1.32 jdolecek 375: return (error);
376:
377: return (0);
1.1 fvdl 378: }
379:
1.32 jdolecek 380:
1.2 mycroft 381: int
1.43 thorpej 382: linux_sys_recvfrom(l, v, retval)
383: struct lwp *l;
1.16 erh 384: void *v;
385: register_t *retval;
386: {
387: struct linux_sys_recvfrom_args /* {
1.1 fvdl 388: syscallarg(int) s;
389: syscallarg(void *) buf;
390: syscallarg(int) len;
391: syscallarg(int) flags;
1.32 jdolecek 392: syscallarg(struct osockaddr *) from;
393: syscallarg(int *) fromlenaddr;
1.16 erh 394: } */ *uap = v;
1.32 jdolecek 395: int error;
396: struct sys_recvfrom_args bra;
1.1 fvdl 397:
1.16 erh 398: SCARG(&bra, s) = SCARG(uap, s);
399: SCARG(&bra, buf) = SCARG(uap, buf);
400: SCARG(&bra, len) = SCARG(uap, len);
401: SCARG(&bra, flags) = SCARG(uap, flags);
1.32 jdolecek 402: SCARG(&bra, from) = (struct sockaddr *) SCARG(uap, from);
403: SCARG(&bra, fromlenaddr) = SCARG(uap, fromlenaddr);
1.1 fvdl 404:
1.43 thorpej 405: if ((error = sys_recvfrom(l, &bra, retval)))
1.32 jdolecek 406: return (error);
407:
408: if (SCARG(uap, from) && (error = linux_sa_put(SCARG(uap, from))))
409: return (error);
410:
411: return (0);
412: }
413:
414: int
1.43 thorpej 415: linux_sys_recvmsg(l, v, retval)
416: struct lwp *l;
1.32 jdolecek 417: void *v;
418: register_t *retval;
419: {
420: struct linux_sys_recvmsg_args /* {
421: syscallarg(int) s;
422: syscallarg(struct msghdr *) msg;
423: syscallarg(u_int) flags;
424: } */ *uap = v;
425: struct msghdr msg;
426: int error;
427:
1.43 thorpej 428: if ((error = sys_recvmsg(l, v, retval)))
1.32 jdolecek 429: return (error);
430:
431: error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg,
432: sizeof(msg));
433:
434: if (!error && msg.msg_name && msg.msg_namelen > 2)
435: error = linux_sa_put(msg.msg_name);
436:
437: /*
438: * XXX handle different alignment of cmsg data on architectures where
439: * the Linux alignment is different (powerpc, sparc, sparc64).
440: */
441:
442: return (error);
1.1 fvdl 443: }
444:
445: /*
446: * Convert socket option level from Linux to NetBSD value. Only SOL_SOCKET
447: * is different, the rest matches IPPROTO_* on both systems.
448: */
1.2 mycroft 449: int
1.1 fvdl 450: linux_to_bsd_sopt_level(llevel)
451: int llevel;
452: {
1.12 mycroft 453:
1.1 fvdl 454: switch (llevel) {
455: case LINUX_SOL_SOCKET:
456: return SOL_SOCKET;
1.3 mycroft 457: case LINUX_SOL_IP:
458: return IPPROTO_IP;
459: case LINUX_SOL_TCP:
460: return IPPROTO_TCP;
461: case LINUX_SOL_UDP:
462: return IPPROTO_UDP;
1.1 fvdl 463: default:
464: return -1;
465: }
466: }
467:
468: /*
469: * Convert Linux socket level socket option numbers to NetBSD values.
470: */
1.2 mycroft 471: int
1.1 fvdl 472: linux_to_bsd_so_sockopt(lopt)
473: int lopt;
474: {
1.12 mycroft 475:
1.1 fvdl 476: switch (lopt) {
477: case LINUX_SO_DEBUG:
478: return SO_DEBUG;
479: case LINUX_SO_REUSEADDR:
1.39 jschauma 480: /*
481: * Linux does not implement SO_REUSEPORT, but allows reuse of a
482: * host:port pair through SO_REUSEADDR even if the address is not a
483: * multicast-address. Effectively, this means that we should use
484: * SO_REUSEPORT to allow Linux applications to not exit with
485: * EADDRINUSE
486: */
487: return SO_REUSEPORT;
1.1 fvdl 488: case LINUX_SO_TYPE:
489: return SO_TYPE;
490: case LINUX_SO_ERROR:
491: return SO_ERROR;
492: case LINUX_SO_DONTROUTE:
493: return SO_DONTROUTE;
494: case LINUX_SO_BROADCAST:
495: return SO_BROADCAST;
496: case LINUX_SO_SNDBUF:
497: return SO_SNDBUF;
498: case LINUX_SO_RCVBUF:
499: return SO_RCVBUF;
500: case LINUX_SO_KEEPALIVE:
501: return SO_KEEPALIVE;
502: case LINUX_SO_OOBINLINE:
503: return SO_OOBINLINE;
504: case LINUX_SO_LINGER:
505: return SO_LINGER;
506: case LINUX_SO_PRIORITY:
507: case LINUX_SO_NO_CHECK:
508: default:
509: return -1;
510: }
511: }
512:
513: /*
1.3 mycroft 514: * Convert Linux IP level socket option number to NetBSD values.
515: */
516: int
517: linux_to_bsd_ip_sockopt(lopt)
518: int lopt;
519: {
1.12 mycroft 520:
1.3 mycroft 521: switch (lopt) {
522: case LINUX_IP_TOS:
523: return IP_TOS;
524: case LINUX_IP_TTL:
525: return IP_TTL;
526: case LINUX_IP_MULTICAST_TTL:
527: return IP_MULTICAST_TTL;
528: case LINUX_IP_MULTICAST_LOOP:
529: return IP_MULTICAST_LOOP;
530: case LINUX_IP_MULTICAST_IF:
531: return IP_MULTICAST_IF;
532: case LINUX_IP_ADD_MEMBERSHIP:
533: return IP_ADD_MEMBERSHIP;
534: case LINUX_IP_DROP_MEMBERSHIP:
535: return IP_DROP_MEMBERSHIP;
536: default:
537: return -1;
538: }
539: }
540:
541: /*
542: * Convert Linux TCP level socket option number to NetBSD values.
543: */
544: int
545: linux_to_bsd_tcp_sockopt(lopt)
546: int lopt;
547: {
1.12 mycroft 548:
1.3 mycroft 549: switch (lopt) {
1.6 mycroft 550: case LINUX_TCP_NODELAY:
551: return TCP_NODELAY;
552: case LINUX_TCP_MAXSEG:
553: return TCP_MAXSEG;
1.3 mycroft 554: default:
1.6 mycroft 555: return -1;
1.3 mycroft 556: }
557: }
558:
559: /*
560: * Convert Linux UDP level socket option number to NetBSD values.
561: */
562: int
563: linux_to_bsd_udp_sockopt(lopt)
564: int lopt;
565: {
1.12 mycroft 566:
1.3 mycroft 567: switch (lopt) {
568: default:
1.6 mycroft 569: return -1;
1.3 mycroft 570: }
571: }
572:
573: /*
1.5 mycroft 574: * Another reasonably straightforward function: setsockopt(2).
1.1 fvdl 575: * The level and option numbers are converted; the values passed
576: * are not (yet) converted, the ones currently implemented don't
577: * need conversion, as they are the same on both systems.
578: */
1.2 mycroft 579: int
1.43 thorpej 580: linux_sys_setsockopt(l, v, retval)
581: struct lwp *l;
1.16 erh 582: void *v;
583: register_t *retval;
584: {
585: struct linux_sys_setsockopt_args /* {
1.1 fvdl 586: syscallarg(int) s;
587: syscallarg(int) level;
588: syscallarg(int) optname;
589: syscallarg(void *) optval;
590: syscallarg(int) optlen;
1.16 erh 591: } */ *uap = v;
1.12 mycroft 592: struct sys_setsockopt_args bsa;
1.16 erh 593: int name;
1.1 fvdl 594:
1.16 erh 595: SCARG(&bsa, s) = SCARG(uap, s);
596: SCARG(&bsa, level) = linux_to_bsd_sopt_level(SCARG(uap, level));
597: SCARG(&bsa, val) = SCARG(uap, optval);
598: SCARG(&bsa, valsize) = SCARG(uap, optlen);
1.1 fvdl 599:
600: switch (SCARG(&bsa, level)) {
1.40 itojun 601: case SOL_SOCKET:
602: name = linux_to_bsd_so_sockopt(SCARG(uap, optname));
603: break;
604: case IPPROTO_IP:
605: name = linux_to_bsd_ip_sockopt(SCARG(uap, optname));
606: break;
607: case IPPROTO_TCP:
608: name = linux_to_bsd_tcp_sockopt(SCARG(uap, optname));
609: break;
610: case IPPROTO_UDP:
611: name = linux_to_bsd_udp_sockopt(SCARG(uap, optname));
612: break;
613: default:
614: return EINVAL;
1.1 fvdl 615: }
616:
617: if (name == -1)
618: return EINVAL;
619: SCARG(&bsa, name) = name;
620:
1.43 thorpej 621: return sys_setsockopt(l, &bsa, retval);
1.1 fvdl 622: }
623:
624: /*
625: * getsockopt(2) is very much the same as setsockopt(2) (see above)
626: */
1.2 mycroft 627: int
1.43 thorpej 628: linux_sys_getsockopt(l, v, retval)
629: struct lwp *l;
1.16 erh 630: void *v;
631: register_t *retval;
632: {
633: struct linux_sys_getsockopt_args /* {
1.1 fvdl 634: syscallarg(int) s;
635: syscallarg(int) level;
636: syscallarg(int) optname;
637: syscallarg(void *) optval;
1.16 erh 638: syscallarg(int *) optlen;
639: } */ *uap = v;
1.12 mycroft 640: struct sys_getsockopt_args bga;
1.16 erh 641: int name;
1.1 fvdl 642:
1.16 erh 643: SCARG(&bga, s) = SCARG(uap, s);
644: SCARG(&bga, level) = linux_to_bsd_sopt_level(SCARG(uap, level));
645: SCARG(&bga, val) = SCARG(uap, optval);
646: SCARG(&bga, avalsize) = SCARG(uap, optlen);
1.1 fvdl 647:
648: switch (SCARG(&bga, level)) {
1.40 itojun 649: case SOL_SOCKET:
650: name = linux_to_bsd_so_sockopt(SCARG(uap, optname));
651: break;
652: case IPPROTO_IP:
653: name = linux_to_bsd_ip_sockopt(SCARG(uap, optname));
654: break;
655: case IPPROTO_TCP:
656: name = linux_to_bsd_tcp_sockopt(SCARG(uap, optname));
657: break;
658: case IPPROTO_UDP:
659: name = linux_to_bsd_udp_sockopt(SCARG(uap, optname));
660: break;
661: default:
662: return EINVAL;
1.1 fvdl 663: }
664:
665: if (name == -1)
666: return EINVAL;
1.5 mycroft 667: SCARG(&bga, name) = name;
1.1 fvdl 668:
1.43 thorpej 669: return sys_getsockopt(l, &bga, retval);
1.13 mycroft 670: }
671:
1.21 jtk 672: #define IF_NAME_LEN 16
673:
674: int
1.45 ! darrenr 675: linux_getifhwaddr(l, retval, fd, data)
! 676: struct lwp *l;
1.21 jtk 677: register_t *retval;
678: u_int fd;
679: void *data;
680: {
681: /* Not the full structure, just enough to map what we do here */
682: struct linux_ifreq {
683: char if_name[IF_NAME_LEN];
684: struct osockaddr hwaddr;
685: } lreq;
1.45 ! darrenr 686: struct proc *p = l->l_proc;
1.21 jtk 687: struct filedesc *fdp;
688: struct file *fp;
689: struct ifaddr *ifa;
690: struct ifnet *ifp;
691: struct sockaddr_dl *sadl;
692: int error, found;
693: int index, ifnum;
694:
695: /*
696: * We can't emulate this ioctl by calling sys_ioctl() to run
697: * SIOCGIFCONF, because the user buffer is not of the right
698: * type to take those results. We can't use kernel buffers to
699: * receive the results, as the implementation of sys_ioctl()
700: * and ifconf() [which implements SIOCGIFCONF] use
701: * copyin()/copyout() which will fail on kernel addresses.
702: *
703: * So, we must duplicate code from sys_ioctl() and ifconf(). Ugh.
704: */
705:
706: fdp = p->p_fd;
1.30 thorpej 707: if ((fp = fd_getfile(fdp, fd)) == NULL)
1.21 jtk 708: return (EBADF);
709:
710: FILE_USE(fp);
711: if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
712: error = EBADF;
713: goto out;
714: }
715:
716: error = copyin(data, (caddr_t)&lreq, sizeof(lreq));
717: if (error)
718: goto out;
719: lreq.if_name[IF_NAME_LEN-1] = '\0'; /* just in case */
720:
721: /*
1.22 jdolecek 722: * Try real interface name first, then fake "ethX"
1.21 jtk 723: */
1.22 jdolecek 724: for (ifp = ifnet.tqh_first, found = 0;
725: ifp != 0 && !found;
726: ifp = ifp->if_list.tqe_next) {
727: if (strcmp(lreq.if_name, ifp->if_xname))
728: /* not this interface */
729: continue;
730: found=1;
731: if ((ifa = ifp->if_addrlist.tqh_first) != 0) {
732: for (; ifa != 0; ifa = ifa->ifa_list.tqe_next) {
733: sadl = (struct sockaddr_dl *)ifa->ifa_addr;
734: /* only return ethernet addresses */
735: /* XXX what about FDDI, etc. ? */
736: if (sadl->sdl_family != AF_LINK ||
737: sadl->sdl_type != IFT_ETHER)
738: continue;
739: memcpy((caddr_t)&lreq.hwaddr.sa_data,
740: LLADDR(sadl),
741: MIN(sadl->sdl_alen,
742: sizeof(lreq.hwaddr.sa_data)));
743: lreq.hwaddr.sa_family =
744: sadl->sdl_family;
745: error = copyout((caddr_t)&lreq, data,
746: sizeof(lreq));
747: goto out;
748: }
749: } else {
750: error = ENODEV;
751: goto out;
752: }
753: }
754:
1.31 jdolecek 755: if (strncmp(lreq.if_name, "eth", 3) == 0) {
1.21 jtk 756: for (ifnum = 0, index = 3;
757: lreq.if_name[index] != '\0' && index < IF_NAME_LEN;
758: index++) {
759: ifnum *= 10;
760: ifnum += lreq.if_name[index] - '0';
761: }
762:
763: error = EINVAL; /* in case we don't find one */
764: for (ifp = ifnet.tqh_first, found = 0;
765: ifp != 0 && !found;
766: ifp = ifp->if_list.tqe_next) {
767: memcpy(lreq.if_name, ifp->if_xname,
768: MIN(IF_NAME_LEN, IFNAMSIZ));
769: if ((ifa = ifp->if_addrlist.tqh_first) == 0)
770: /* no addresses on this interface */
771: continue;
772: else
773: for (; ifa != 0; ifa = ifa->ifa_list.tqe_next) {
774: sadl = (struct sockaddr_dl *)ifa->ifa_addr;
775: /* only return ethernet addresses */
776: /* XXX what about FDDI, etc. ? */
777: if (sadl->sdl_family != AF_LINK ||
778: sadl->sdl_type != IFT_ETHER)
779: continue;
780: if (ifnum--)
781: /* not the reqested iface */
782: continue;
783: memcpy((caddr_t)&lreq.hwaddr.sa_data,
784: LLADDR(sadl),
785: MIN(sadl->sdl_alen,
786: sizeof(lreq.hwaddr.sa_data)));
787: lreq.hwaddr.sa_family =
788: sadl->sdl_family;
789: error = copyout((caddr_t)&lreq, data,
790: sizeof(lreq));
791: found = 1;
792: break;
793: }
794: }
1.22 jdolecek 795: } else {
796: /* unknown interface, not even an "eth*" name */
797: error = ENODEV;
798: }
1.21 jtk 799:
800: out:
1.45 ! darrenr 801: FILE_UNUSE(fp, l);
1.21 jtk 802: return error;
803: }
1.24 thorpej 804: #undef IF_NAME_LEN
1.21 jtk 805:
1.13 mycroft 806: int
1.45 ! darrenr 807: linux_ioctl_socket(l, uap, retval)
! 808: struct lwp *l;
1.23 augustss 809: struct linux_sys_ioctl_args /* {
1.13 mycroft 810: syscallarg(int) fd;
811: syscallarg(u_long) com;
812: syscallarg(caddr_t) data;
813: } */ *uap;
814: register_t *retval;
815: {
1.45 ! darrenr 816: struct proc *p = l->l_proc;
1.13 mycroft 817: u_long com;
1.25 fvdl 818: int error = 0, isdev = 0, dosys = 1;
1.13 mycroft 819: struct sys_ioctl_args ia;
1.25 fvdl 820: struct file *fp;
821: struct filedesc *fdp;
822: struct vnode *vp;
1.45 ! darrenr 823: int (*ioctlf)(struct file *, u_long, void *, struct lwp *);
1.25 fvdl 824: struct ioctl_pt pt;
825:
826: fdp = p->p_fd;
1.30 thorpej 827: if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
1.25 fvdl 828: return (EBADF);
829:
830: FILE_USE(fp);
831:
832: if (fp->f_type == DTYPE_VNODE) {
833: vp = (struct vnode *)fp->f_data;
834: isdev = vp->v_type == VCHR;
835: }
836:
837: /*
838: * Don't try to interpret socket ioctl calls that are done
839: * on a device filedescriptor, just pass them through, to
840: * emulate Linux behaviour. Use PTIOCLINUX so that the
841: * device will only handle these if it's prepared to do
842: * so, to avoid unexpected things from happening.
843: */
844: if (isdev) {
1.26 fvdl 845: dosys = 0;
1.25 fvdl 846: ioctlf = fp->f_ops->fo_ioctl;
847: pt.com = SCARG(uap, com);
848: pt.data = SCARG(uap, data);
1.45 ! darrenr 849: error = ioctlf(fp, PTIOCLINUX, (caddr_t)&pt, l);
1.27 fvdl 850: /*
851: * XXX hack: if the function returns EJUSTRETURN,
852: * it has stuffed a sysctl return value in pt.data.
853: */
854: if (error == EJUSTRETURN) {
855: retval[0] = (register_t)pt.data;
856: error = 0;
857: }
1.25 fvdl 858: goto out;
859: }
1.13 mycroft 860:
861: com = SCARG(uap, com);
862: retval[0] = 0;
863:
864: switch (com) {
865: case LINUX_SIOCGIFCONF:
866: SCARG(&ia, com) = OSIOCGIFCONF;
867: break;
868: case LINUX_SIOCGIFFLAGS:
869: SCARG(&ia, com) = SIOCGIFFLAGS;
870: break;
1.25 fvdl 871: case LINUX_SIOCSIFFLAGS:
872: SCARG(&ia, com) = SIOCSIFFLAGS;
873: break;
1.13 mycroft 874: case LINUX_SIOCGIFADDR:
875: SCARG(&ia, com) = OSIOCGIFADDR;
876: break;
877: case LINUX_SIOCGIFDSTADDR:
878: SCARG(&ia, com) = OSIOCGIFDSTADDR;
879: break;
880: case LINUX_SIOCGIFBRDADDR:
881: SCARG(&ia, com) = OSIOCGIFBRDADDR;
882: break;
883: case LINUX_SIOCGIFNETMASK:
884: SCARG(&ia, com) = OSIOCGIFNETMASK;
885: break;
886: case LINUX_SIOCADDMULTI:
887: SCARG(&ia, com) = SIOCADDMULTI;
888: break;
889: case LINUX_SIOCDELMULTI:
890: SCARG(&ia, com) = SIOCDELMULTI;
891: break;
1.21 jtk 892: case LINUX_SIOCGIFHWADDR:
1.45 ! darrenr 893: error = linux_getifhwaddr(l, retval, SCARG(uap, fd),
1.21 jtk 894: SCARG(uap, data));
1.29 fvdl 895: dosys = 0;
1.25 fvdl 896: break;
1.13 mycroft 897: default:
1.25 fvdl 898: error = EINVAL;
899: }
900:
901: out:
1.45 ! darrenr 902: FILE_UNUSE(fp, l);
1.25 fvdl 903:
904: if (error ==0 && dosys) {
905: SCARG(&ia, fd) = SCARG(uap, fd);
906: SCARG(&ia, data) = SCARG(uap, data);
1.43 thorpej 907: /* XXX NJWLWP */
908: error = sys_ioctl(curlwp, &ia, retval);
1.13 mycroft 909: }
910:
1.25 fvdl 911: return error;
1.1 fvdl 912: }
1.19 sommerfe 913:
914: int
1.43 thorpej 915: linux_sys_connect(l, v, retval)
916: struct lwp *l;
1.19 sommerfe 917: void *v;
918: register_t *retval;
919: {
1.32 jdolecek 920: struct linux_sys_connect_args /* {
1.19 sommerfe 921: syscallarg(int) s;
922: syscallarg(const struct sockaddr *) name;
1.32 jdolecek 923: syscallarg(int) namelen;
1.19 sommerfe 924: } */ *uap = v;
1.43 thorpej 925: struct proc *p = l->l_proc;
1.32 jdolecek 926: int error;
927: struct sockaddr *sa;
928: struct sys_connect_args bca;
1.36 christos 929: caddr_t sg = stackgap_init(p, 0);
1.34 fvdl 930: int namlen;
1.32 jdolecek 931:
1.34 fvdl 932: namlen = SCARG(uap, namelen);
1.36 christos 933: error = linux_sa_get(p, &sg, &sa, SCARG(uap, name), &namlen);
1.32 jdolecek 934: if (error)
935: return (error);
1.19 sommerfe 936:
1.32 jdolecek 937: SCARG(&bca, s) = SCARG(uap, s);
938: SCARG(&bca, name) = sa;
1.34 fvdl 939: SCARG(&bca, namelen) = (unsigned int) namlen;
1.32 jdolecek 940:
1.43 thorpej 941: error = sys_connect(l, &bca, retval);
1.19 sommerfe 942:
943: if (error == EISCONN) {
944: struct file *fp;
1.23 augustss 945: struct socket *so;
1.19 sommerfe 946: int s, state, prflags;
947:
1.20 thorpej 948: /* getsock() will use the descriptor for us */
949: if (getsock(p->p_fd, SCARG(uap, s), &fp) != 0)
1.19 sommerfe 950: return EISCONN;
951:
952: s = splsoftnet();
953: so = (struct socket *)fp->f_data;
954: state = so->so_state;
955: prflags = so->so_proto->pr_flags;
956: splx(s);
1.45 ! darrenr 957: FILE_UNUSE(fp, l);
1.19 sommerfe 958: /*
959: * We should only let this call succeed once per
960: * non-blocking connect; however we don't have
961: * a convenient place to keep that state..
962: */
963: if ((state & SS_NBIO) && (state & SS_ISCONNECTED) &&
964: (prflags & PR_CONNREQUIRED))
965: return 0;
966: }
967:
1.32 jdolecek 968: return (error);
969: }
970:
971: int
1.43 thorpej 972: linux_sys_bind(l, v, retval)
973: struct lwp *l;
1.32 jdolecek 974: void *v;
975: register_t *retval;
976: {
977: struct linux_sys_bind_args /* {
978: syscallarg(int) s;
979: syscallarg(const struct osockaddr *) name;
980: syscallarg(int) namelen;
981: } */ *uap = v;
1.43 thorpej 982: struct proc *p = l->l_proc;
1.34 fvdl 983: int error, namlen;
1.32 jdolecek 984: struct sys_bind_args bsa;
985:
1.34 fvdl 986: namlen = SCARG(uap, namelen);
1.32 jdolecek 987: SCARG(&bsa, s) = SCARG(uap, s);
988: if (SCARG(uap, name)) {
989: struct sockaddr *sa;
1.36 christos 990: caddr_t sg = stackgap_init(p, 0);
1.32 jdolecek 991:
1.36 christos 992: error = linux_sa_get(p, &sg, &sa, SCARG(uap, name), &namlen);
1.32 jdolecek 993: if (error)
994: return (error);
995:
996: SCARG(&bsa, name) = sa;
997: } else
998: SCARG(&bsa, name) = NULL;
1.34 fvdl 999: SCARG(&bsa, namelen) = namlen;
1.32 jdolecek 1000:
1.43 thorpej 1001: return (sys_bind(l, &bsa, retval));
1.32 jdolecek 1002: }
1003:
1004: int
1.43 thorpej 1005: linux_sys_getsockname(l, v, retval)
1006: struct lwp *l;
1.32 jdolecek 1007: void *v;
1008: register_t *retval;
1009: {
1010: struct linux_sys_getsockname_args /* {
1011: syscallarg(int) fdes;
1012: syscallarg(caddr_t) asa;
1013: syscallarg(int *) alen;
1014: } */ *uap = v;
1015: int error;
1016:
1.43 thorpej 1017: if ((error = sys_getsockname(l, uap, retval)) != 0)
1.32 jdolecek 1018: return (error);
1019:
1020: if ((error = linux_sa_put((struct osockaddr *)SCARG(uap, asa))))
1021: return (error);
1022:
1023: return (0);
1024: }
1025:
1026: int
1.43 thorpej 1027: linux_sys_getpeername(l, v, retval)
1028: struct lwp *l;
1.32 jdolecek 1029: void *v;
1030: register_t *retval;
1031: {
1032: struct sys_getpeername_args /* {
1033: syscallarg(int) fdes;
1034: syscallarg(caddr_t) asa;
1035: syscallarg(int *) alen;
1036: } */ *uap = v;
1037: int error;
1038:
1.43 thorpej 1039: if ((error = sys_getpeername(l, uap, retval)) != 0)
1.32 jdolecek 1040: return (error);
1041:
1042: if ((error = linux_sa_put((struct osockaddr *)SCARG(uap, asa))))
1043: return (error);
1044:
1045: return (0);
1046: }
1047:
1048: /*
1049: * Copy the osockaddr structure pointed to by osa to kernel, adjust
1050: * family and convert to sockaddr, allocate stackgap and put the
1051: * the converted structure there, address on stackgap returned in sap.
1052: */
1053: static int
1.36 christos 1054: linux_sa_get(p, sgp, sap, osa, osalen)
1055: struct proc *p;
1.32 jdolecek 1056: caddr_t *sgp;
1057: struct sockaddr **sap;
1.33 jdolecek 1058: const struct osockaddr *osa;
1.34 fvdl 1059: int *osalen;
1.32 jdolecek 1060: {
1061: int error=0, bdom;
1062: struct sockaddr *sa, *usa;
1063: struct osockaddr *kosa = (struct osockaddr *) &sa;
1.34 fvdl 1064: int alloclen;
1065: #ifdef INET6
1066: int oldv6size;
1067: struct sockaddr_in6 *sin6;
1068: #endif
1.32 jdolecek 1069:
1.37 christos 1070: if (*osalen < 2 || *osalen > UCHAR_MAX || !osa) {
1071: DPRINTF(("bad osa=%p osalen=%d\n", osa, *osalen));
1.32 jdolecek 1072: return (EINVAL);
1.37 christos 1073: }
1.32 jdolecek 1074:
1.34 fvdl 1075: alloclen = *osalen;
1076: #ifdef INET6
1077: oldv6size = 0;
1078: /*
1079: * Check for old (pre-RFC2553) sockaddr_in6. We may accept it
1080: * if it's a v4-mapped address, so reserve the proper space
1081: * for it.
1082: */
1083: if (alloclen == sizeof (struct sockaddr_in6) - sizeof (u_int32_t)) {
1084: alloclen = sizeof (struct sockaddr_in6);
1085: oldv6size = 1;
1086: }
1087: #endif
1.32 jdolecek 1088:
1.34 fvdl 1089: kosa = (struct osockaddr *) malloc(alloclen, M_TEMP, M_WAITOK);
1090:
1.37 christos 1091: if ((error = copyin(osa, (caddr_t) kosa, *osalen))) {
1092: DPRINTF(("error copying osa %d\n", error));
1.32 jdolecek 1093: goto out;
1.37 christos 1094: }
1.32 jdolecek 1095:
1096: bdom = linux_to_bsd_domain(kosa->sa_family);
1097: if (bdom == -1) {
1.37 christos 1098: DPRINTF(("bad linux family=%d\n", kosa->sa_family));
1.32 jdolecek 1099: error = EINVAL;
1100: goto out;
1101: }
1102:
1103: #ifdef INET6
1104: /*
1105: * Older Linux IPv6 code uses obsolete RFC2133 struct sockaddr_in6,
1106: * which lacks the scope id compared with RFC2553 one. If we detect
1107: * the situation, reject the address and write a message to system log.
1.34 fvdl 1108: *
1109: * Still accept addresses for which the scope id is not used.
1.32 jdolecek 1110: */
1.34 fvdl 1111: if (oldv6size && bdom == AF_INET6) {
1112: sin6 = (struct sockaddr_in6 *)kosa;
1113: if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr) ||
1114: (!IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) &&
1115: !IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr) &&
1116: !IN6_IS_ADDR_V4COMPAT(&sin6->sin6_addr) &&
1117: !IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) &&
1118: !IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))) {
1119: sin6->sin6_scope_id = 0;
1120: } else {
1121: struct proc *p = curproc; /* XXX */
1122: int uid = p->p_cred && p->p_ucred ?
1123: p->p_ucred->cr_uid : -1;
1124:
1125: log(LOG_DEBUG,
1126: "pid %d (%s), uid %d: obsolete pre-RFC2553 "
1127: "sockaddr_in6 rejected",
1128: p->p_pid, p->p_comm, uid);
1129: error = EINVAL;
1130: goto out;
1131: }
1.38 christos 1132: } else
1133: #endif
1134: if (bdom == AF_INET) {
1.37 christos 1135: alloclen = sizeof(struct sockaddr_in);
1.32 jdolecek 1136: }
1137:
1138: sa = (struct sockaddr *) kosa;
1139: sa->sa_family = bdom;
1.34 fvdl 1140: sa->sa_len = alloclen;
1.37 christos 1141: #ifdef DEBUG_LINUX
1142: DPRINTF(("family %d, len = %d [ ", sa->sa_family, sa->sa_len));
1143: for (bdom = 0; bdom < sizeof(sa->sa_data); bdom++)
1144: DPRINTF(("%02x ", sa->sa_data[bdom]));
1145: DPRINTF(("\n"));
1146: #endif
1.32 jdolecek 1147:
1.36 christos 1148: usa = (struct sockaddr *) stackgap_alloc(p, sgp, alloclen);
1.32 jdolecek 1149: if (!usa) {
1150: error = ENOMEM;
1151: goto out;
1152: }
1153:
1.37 christos 1154: if ((error = copyout(sa, usa, alloclen))) {
1155: DPRINTF(("error copying out socket %d\n", error));
1.32 jdolecek 1156: goto out;
1.37 christos 1157: }
1.32 jdolecek 1158:
1159: *sap = usa;
1160:
1161: out:
1.34 fvdl 1162: *osalen = alloclen;
1.32 jdolecek 1163: free(kosa, M_TEMP);
1164: return (error);
1165: }
1166:
1167: static int
1168: linux_sa_put(osa)
1169: struct osockaddr *osa;
1170: {
1171: struct sockaddr sa;
1172: struct osockaddr *kosa;
1173: int error, bdom, len;
1174:
1175: /*
1176: * Only read/write the sockaddr family and length part, the rest is
1177: * not changed.
1178: */
1179: len = sizeof(sa.sa_len) + sizeof(sa.sa_family);
1180:
1181: error = copyin((caddr_t) osa, (caddr_t) &sa, len);
1182: if (error)
1183: return (error);
1184:
1185: bdom = bsd_to_linux_domain(sa.sa_family);
1186: if (bdom == -1)
1187: return (EINVAL);
1188:
1189: /* Note: we convert from sockaddr to osockaddr here, too */
1190: kosa = (struct osockaddr *) &sa;
1191: kosa->sa_family = bdom;
1192: error = copyout(kosa, osa, len);
1193: if (error)
1194: return (error);
1195:
1196: return (0);
1197: }
1198:
1199: int
1.43 thorpej 1200: linux_sys_recv(l, v, retval)
1201: struct lwp *l;
1.32 jdolecek 1202: void *v;
1203: register_t *retval;
1204: {
1205: struct linux_sys_recv_args /* {
1206: syscallarg(int) s;
1207: syscallarg(void *) buf;
1208: syscallarg(int) len;
1209: syscallarg(int) flags;
1210: } */ *uap = v;
1211: struct sys_recvfrom_args bra;
1212:
1213:
1214: SCARG(&bra, s) = SCARG(uap, s);
1215: SCARG(&bra, buf) = SCARG(uap, buf);
1216: SCARG(&bra, len) = (size_t) SCARG(uap, len);
1217: SCARG(&bra, flags) = SCARG(uap, flags);
1218: SCARG(&bra, from) = NULL;
1219: SCARG(&bra, fromlenaddr) = NULL;
1220:
1.43 thorpej 1221: return (sys_recvfrom(l, &bra, retval));
1.32 jdolecek 1222: }
1223:
1224: int
1.43 thorpej 1225: linux_sys_send(l, v, retval)
1226: struct lwp *l;
1.32 jdolecek 1227: void *v;
1228: register_t *retval;
1229: {
1230: struct linux_sys_send_args /* {
1231: syscallarg(int) s;
1232: syscallarg(caddr_t) buf;
1233: syscallarg(int) len;
1234: syscallarg(int) flags;
1235: } */ *uap = v;
1236: struct sys_sendto_args bsa;
1237:
1238: SCARG(&bsa, s) = SCARG(uap, s);
1239: SCARG(&bsa, buf) = SCARG(uap, buf);
1240: SCARG(&bsa, len) = SCARG(uap, len);
1241: SCARG(&bsa, flags) = SCARG(uap, flags);
1242: SCARG(&bsa, to) = NULL;
1243: SCARG(&bsa, tolen) = 0;
1244:
1.43 thorpej 1245: return (sys_sendto(l, &bsa, retval));
1.32 jdolecek 1246: }
1247:
1248: int
1.43 thorpej 1249: linux_sys_accept(l, v, retval)
1250: struct lwp *l;
1.32 jdolecek 1251: void *v;
1252: register_t *retval;
1253: {
1254: struct linux_sys_accept_args /* {
1255: syscallarg(int) s;
1256: syscallarg(struct osockaddr *) name;
1257: syscallarg(int *) anamelen;
1258: } */ *uap = v;
1259: int error;
1260: struct sys_accept_args baa;
1261:
1262: SCARG(&baa, s) = SCARG(uap, s);
1263: SCARG(&baa, name) = (struct sockaddr *) SCARG(uap, name);
1264: SCARG(&baa, anamelen) = (unsigned int *) SCARG(uap, anamelen);
1265:
1.43 thorpej 1266: if ((error = sys_accept(l, &baa, retval)))
1.32 jdolecek 1267: return (error);
1268:
1269: if (SCARG(uap, name) && (error = linux_sa_put(SCARG(uap, name))))
1270: return (error);
1271:
1272: return (0);
1.19 sommerfe 1273: }
CVSweb <webmaster@jp.NetBSD.org>