linux_socket.c revision 192284
1/*- 2 * Copyright (c) 1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> 30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_socket.c 192284 2009-05-18 04:07:46Z dchagin $"); 31 32/* XXX we use functions that might not exist. */ 33#include "opt_compat.h" 34#include "opt_inet6.h" 35 36#include <sys/param.h> 37#include <sys/proc.h> 38#include <sys/systm.h> 39#include <sys/sysproto.h> 40#include <sys/fcntl.h> 41#include <sys/file.h> 42#include <sys/limits.h> 43#include <sys/lock.h> 44#include <sys/malloc.h> 45#include <sys/mutex.h> 46#include <sys/mbuf.h> 47#include <sys/socket.h> 48#include <sys/socketvar.h> 49#include <sys/syscallsubr.h> 50#include <sys/uio.h> 51#include <sys/syslog.h> 52#include <sys/un.h> 53#include <sys/vimage.h> 54 55#include <net/if.h> 56#include <netinet/in.h> 57#include <netinet/in_systm.h> 58#include <netinet/ip.h> 59#ifdef INET6 60#include <netinet/ip6.h> 61#include <netinet6/ip6_var.h> 62#include <netinet6/in6_var.h> 63#include <netinet6/vinet6.h> 64#endif 65 66#ifdef COMPAT_LINUX32 67#include <machine/../linux32/linux.h> 68#include <machine/../linux32/linux32_proto.h> 69#else 70#include <machine/../linux/linux.h> 71#include <machine/../linux/linux_proto.h> 72#endif 73#include <compat/linux/linux_socket.h> 74#include <compat/linux/linux_util.h> 75 76static int do_sa_get(struct sockaddr **, const struct osockaddr *, int *, 77 struct malloc_type *); 78static int linux_to_bsd_domain(int); 79 80/* 81 * Reads a linux sockaddr and does any necessary translation. 82 * Linux sockaddrs don't have a length field, only a family. 83 */ 84static int 85linux_getsockaddr(struct sockaddr **sap, const struct osockaddr *osa, int len) 86{ 87 int osalen = len; 88 89 return (do_sa_get(sap, osa, &osalen, M_SONAME)); 90} 91 92/* 93 * Copy the osockaddr structure pointed to by osa to kernel, adjust 94 * family and convert to sockaddr. 95 */ 96static int 97do_sa_get(struct sockaddr **sap, const struct osockaddr *osa, int *osalen, 98 struct malloc_type *mtype) 99{ 100 int error=0, bdom; 101 struct sockaddr *sa; 102 struct osockaddr *kosa; 103 int alloclen; 104#ifdef INET6 105 int oldv6size; 106 struct sockaddr_in6 *sin6; 107#endif 108 109 if (*osalen < 2 || *osalen > UCHAR_MAX || !osa) 110 return (EINVAL); 111 112 alloclen = *osalen; 113#ifdef INET6 114 oldv6size = 0; 115 /* 116 * Check for old (pre-RFC2553) sockaddr_in6. We may accept it 117 * if it's a v4-mapped address, so reserve the proper space 118 * for it. 119 */ 120 if (alloclen == sizeof (struct sockaddr_in6) - sizeof (u_int32_t)) { 121 alloclen = sizeof (struct sockaddr_in6); 122 oldv6size = 1; 123 } 124#endif 125 126 kosa = malloc(alloclen, mtype, M_WAITOK); 127 128 if ((error = copyin(osa, kosa, *osalen))) 129 goto out; 130 131 bdom = linux_to_bsd_domain(kosa->sa_family); 132 if (bdom == -1) { 133 error = EINVAL; 134 goto out; 135 } 136 137#ifdef INET6 138 /* 139 * Older Linux IPv6 code uses obsolete RFC2133 struct sockaddr_in6, 140 * which lacks the scope id compared with RFC2553 one. If we detect 141 * the situation, reject the address and write a message to system log. 142 * 143 * Still accept addresses for which the scope id is not used. 144 */ 145 if (oldv6size && bdom == AF_INET6) { 146 sin6 = (struct sockaddr_in6 *)kosa; 147 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr) || 148 (!IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) && 149 !IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr) && 150 !IN6_IS_ADDR_V4COMPAT(&sin6->sin6_addr) && 151 !IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) && 152 !IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))) { 153 sin6->sin6_scope_id = 0; 154 } else { 155 log(LOG_DEBUG, 156 "obsolete pre-RFC2553 sockaddr_in6 rejected\n"); 157 error = EINVAL; 158 goto out; 159 } 160 } else 161#endif 162 if (bdom == AF_INET) 163 alloclen = sizeof(struct sockaddr_in); 164 165 sa = (struct sockaddr *) kosa; 166 sa->sa_family = bdom; 167 sa->sa_len = alloclen; 168 169 *sap = sa; 170 *osalen = alloclen; 171 return (0); 172 173out: 174 free(kosa, mtype); 175 return (error); 176} 177 178static int 179linux_to_bsd_domain(int domain) 180{ 181 182 switch (domain) { 183 case LINUX_AF_UNSPEC: 184 return (AF_UNSPEC); 185 case LINUX_AF_UNIX: 186 return (AF_LOCAL); 187 case LINUX_AF_INET: 188 return (AF_INET); 189 case LINUX_AF_INET6: 190 return (AF_INET6); 191 case LINUX_AF_AX25: 192 return (AF_CCITT); 193 case LINUX_AF_IPX: 194 return (AF_IPX); 195 case LINUX_AF_APPLETALK: 196 return (AF_APPLETALK); 197 } 198 return (-1); 199} 200 201static int 202bsd_to_linux_domain(int domain) 203{ 204 205 switch (domain) { 206 case AF_UNSPEC: 207 return (LINUX_AF_UNSPEC); 208 case AF_LOCAL: 209 return (LINUX_AF_UNIX); 210 case AF_INET: 211 return (LINUX_AF_INET); 212 case AF_INET6: 213 return (LINUX_AF_INET6); 214 case AF_CCITT: 215 return (LINUX_AF_AX25); 216 case AF_IPX: 217 return (LINUX_AF_IPX); 218 case AF_APPLETALK: 219 return (LINUX_AF_APPLETALK); 220 } 221 return (-1); 222} 223 224static int 225linux_to_bsd_sockopt_level(int level) 226{ 227 228 switch (level) { 229 case LINUX_SOL_SOCKET: 230 return (SOL_SOCKET); 231 } 232 return (level); 233} 234 235static int 236bsd_to_linux_sockopt_level(int level) 237{ 238 239 switch (level) { 240 case SOL_SOCKET: 241 return (LINUX_SOL_SOCKET); 242 } 243 return (level); 244} 245 246static int 247linux_to_bsd_ip_sockopt(int opt) 248{ 249 250 switch (opt) { 251 case LINUX_IP_TOS: 252 return (IP_TOS); 253 case LINUX_IP_TTL: 254 return (IP_TTL); 255 case LINUX_IP_OPTIONS: 256 return (IP_OPTIONS); 257 case LINUX_IP_MULTICAST_IF: 258 return (IP_MULTICAST_IF); 259 case LINUX_IP_MULTICAST_TTL: 260 return (IP_MULTICAST_TTL); 261 case LINUX_IP_MULTICAST_LOOP: 262 return (IP_MULTICAST_LOOP); 263 case LINUX_IP_ADD_MEMBERSHIP: 264 return (IP_ADD_MEMBERSHIP); 265 case LINUX_IP_DROP_MEMBERSHIP: 266 return (IP_DROP_MEMBERSHIP); 267 case LINUX_IP_HDRINCL: 268 return (IP_HDRINCL); 269 } 270 return (-1); 271} 272 273static int 274linux_to_bsd_so_sockopt(int opt) 275{ 276 277 switch (opt) { 278 case LINUX_SO_DEBUG: 279 return (SO_DEBUG); 280 case LINUX_SO_REUSEADDR: 281 return (SO_REUSEADDR); 282 case LINUX_SO_TYPE: 283 return (SO_TYPE); 284 case LINUX_SO_ERROR: 285 return (SO_ERROR); 286 case LINUX_SO_DONTROUTE: 287 return (SO_DONTROUTE); 288 case LINUX_SO_BROADCAST: 289 return (SO_BROADCAST); 290 case LINUX_SO_SNDBUF: 291 return (SO_SNDBUF); 292 case LINUX_SO_RCVBUF: 293 return (SO_RCVBUF); 294 case LINUX_SO_KEEPALIVE: 295 return (SO_KEEPALIVE); 296 case LINUX_SO_OOBINLINE: 297 return (SO_OOBINLINE); 298 case LINUX_SO_LINGER: 299 return (SO_LINGER); 300 case LINUX_SO_PEERCRED: 301 return (LOCAL_PEERCRED); 302 case LINUX_SO_RCVLOWAT: 303 return (SO_RCVLOWAT); 304 case LINUX_SO_SNDLOWAT: 305 return (SO_SNDLOWAT); 306 case LINUX_SO_RCVTIMEO: 307 return (SO_RCVTIMEO); 308 case LINUX_SO_SNDTIMEO: 309 return (SO_SNDTIMEO); 310 case LINUX_SO_TIMESTAMP: 311 return (SO_TIMESTAMP); 312 case LINUX_SO_ACCEPTCONN: 313 return (SO_ACCEPTCONN); 314 } 315 return (-1); 316} 317 318static int 319linux_to_bsd_msg_flags(int flags) 320{ 321 int ret_flags = 0; 322 323 if (flags & LINUX_MSG_OOB) 324 ret_flags |= MSG_OOB; 325 if (flags & LINUX_MSG_PEEK) 326 ret_flags |= MSG_PEEK; 327 if (flags & LINUX_MSG_DONTROUTE) 328 ret_flags |= MSG_DONTROUTE; 329 if (flags & LINUX_MSG_CTRUNC) 330 ret_flags |= MSG_CTRUNC; 331 if (flags & LINUX_MSG_TRUNC) 332 ret_flags |= MSG_TRUNC; 333 if (flags & LINUX_MSG_DONTWAIT) 334 ret_flags |= MSG_DONTWAIT; 335 if (flags & LINUX_MSG_EOR) 336 ret_flags |= MSG_EOR; 337 if (flags & LINUX_MSG_WAITALL) 338 ret_flags |= MSG_WAITALL; 339 if (flags & LINUX_MSG_NOSIGNAL) 340 ret_flags |= MSG_NOSIGNAL; 341#if 0 /* not handled */ 342 if (flags & LINUX_MSG_PROXY) 343 ; 344 if (flags & LINUX_MSG_FIN) 345 ; 346 if (flags & LINUX_MSG_SYN) 347 ; 348 if (flags & LINUX_MSG_CONFIRM) 349 ; 350 if (flags & LINUX_MSG_RST) 351 ; 352 if (flags & LINUX_MSG_ERRQUEUE) 353 ; 354#endif 355 return ret_flags; 356} 357 358/* 359* If bsd_to_linux_sockaddr() or linux_to_bsd_sockaddr() faults, then the 360* native syscall will fault. Thus, we don't really need to check the 361* return values for these functions. 362*/ 363 364static int 365bsd_to_linux_sockaddr(struct sockaddr *arg) 366{ 367 struct sockaddr sa; 368 size_t sa_len = sizeof(struct sockaddr); 369 int error; 370 371 if ((error = copyin(arg, &sa, sa_len))) 372 return (error); 373 374 *(u_short *)&sa = sa.sa_family; 375 376 error = copyout(&sa, arg, sa_len); 377 378 return (error); 379} 380 381static int 382linux_to_bsd_sockaddr(struct sockaddr *arg, int len) 383{ 384 struct sockaddr sa; 385 size_t sa_len = sizeof(struct sockaddr); 386 int error; 387 388 if ((error = copyin(arg, &sa, sa_len))) 389 return (error); 390 391 sa.sa_family = *(sa_family_t *)&sa; 392 sa.sa_len = len; 393 394 error = copyout(&sa, arg, sa_len); 395 396 return (error); 397} 398 399 400static int 401linux_sa_put(struct osockaddr *osa) 402{ 403 struct osockaddr sa; 404 int error, bdom; 405 406 /* 407 * Only read/write the osockaddr family part, the rest is 408 * not changed. 409 */ 410 error = copyin(osa, &sa, sizeof(sa.sa_family)); 411 if (error) 412 return (error); 413 414 bdom = bsd_to_linux_domain(sa.sa_family); 415 if (bdom == -1) 416 return (EINVAL); 417 418 sa.sa_family = bdom; 419 error = copyout(&sa, osa, sizeof(sa.sa_family)); 420 if (error) 421 return (error); 422 423 return (0); 424} 425 426static int 427linux_to_bsd_cmsg_type(int cmsg_type) 428{ 429 430 switch (cmsg_type) { 431 case LINUX_SCM_RIGHTS: 432 return (SCM_RIGHTS); 433 } 434 return (-1); 435} 436 437static int 438bsd_to_linux_cmsg_type(int cmsg_type) 439{ 440 441 switch (cmsg_type) { 442 case SCM_RIGHTS: 443 return (LINUX_SCM_RIGHTS); 444 } 445 return (-1); 446} 447 448 449 450static int 451linux_to_bsd_msghdr(struct msghdr *bhdr, const struct l_msghdr *lhdr) 452{ 453 if (lhdr->msg_controllen > INT_MAX) 454 return (ENOBUFS); 455 456 bhdr->msg_name = PTRIN(lhdr->msg_name); 457 bhdr->msg_namelen = lhdr->msg_namelen; 458 bhdr->msg_iov = PTRIN(lhdr->msg_iov); 459 bhdr->msg_iovlen = lhdr->msg_iovlen; 460 bhdr->msg_control = PTRIN(lhdr->msg_control); 461 bhdr->msg_controllen = lhdr->msg_controllen; 462 bhdr->msg_flags = linux_to_bsd_msg_flags(lhdr->msg_flags); 463 return (0); 464} 465 466static int 467bsd_to_linux_msghdr(const struct msghdr *bhdr, struct l_msghdr *lhdr) 468{ 469 lhdr->msg_name = PTROUT(bhdr->msg_name); 470 lhdr->msg_namelen = bhdr->msg_namelen; 471 lhdr->msg_iov = PTROUT(bhdr->msg_iov); 472 lhdr->msg_iovlen = bhdr->msg_iovlen; 473 lhdr->msg_control = PTROUT(bhdr->msg_control); 474 lhdr->msg_controllen = bhdr->msg_controllen; 475 /* msg_flags skipped */ 476 return (0); 477} 478 479static int 480linux_sendit(struct thread *td, int s, struct msghdr *mp, int flags, 481 struct mbuf *control, enum uio_seg segflg) 482{ 483 struct sockaddr *to; 484 int error; 485 486 if (mp->msg_name != NULL) { 487 error = linux_getsockaddr(&to, mp->msg_name, mp->msg_namelen); 488 if (error) 489 return (error); 490 mp->msg_name = to; 491 } else 492 to = NULL; 493 494 error = kern_sendit(td, s, mp, linux_to_bsd_msg_flags(flags), control, 495 segflg); 496 497 if (to) 498 free(to, M_SONAME); 499 return (error); 500} 501 502/* Return 0 if IP_HDRINCL is set for the given socket. */ 503static int 504linux_check_hdrincl(struct thread *td, int s) 505{ 506 int error, optval, size_val; 507 508 size_val = sizeof(optval); 509 error = kern_getsockopt(td, s, IPPROTO_IP, IP_HDRINCL, 510 &optval, UIO_SYSSPACE, &size_val); 511 if (error) 512 return (error); 513 514 return (optval == 0); 515} 516 517struct linux_sendto_args { 518 int s; 519 l_uintptr_t msg; 520 int len; 521 int flags; 522 l_uintptr_t to; 523 int tolen; 524}; 525 526/* 527 * Updated sendto() when IP_HDRINCL is set: 528 * tweak endian-dependent fields in the IP packet. 529 */ 530static int 531linux_sendto_hdrincl(struct thread *td, struct linux_sendto_args *linux_args) 532{ 533/* 534 * linux_ip_copysize defines how many bytes we should copy 535 * from the beginning of the IP packet before we customize it for BSD. 536 * It should include all the fields we modify (ip_len and ip_off). 537 */ 538#define linux_ip_copysize 8 539 540 struct ip *packet; 541 struct msghdr msg; 542 struct iovec aiov[1]; 543 int error; 544 545 /* Check that the packet isn't too big or too small. */ 546 if (linux_args->len < linux_ip_copysize || 547 linux_args->len > IP_MAXPACKET) 548 return (EINVAL); 549 550 packet = (struct ip *)malloc(linux_args->len, M_TEMP, M_WAITOK); 551 552 /* Make kernel copy of the packet to be sent */ 553 if ((error = copyin(PTRIN(linux_args->msg), packet, 554 linux_args->len))) 555 goto goout; 556 557 /* Convert fields from Linux to BSD raw IP socket format */ 558 packet->ip_len = linux_args->len; 559 packet->ip_off = ntohs(packet->ip_off); 560 561 /* Prepare the msghdr and iovec structures describing the new packet */ 562 msg.msg_name = PTRIN(linux_args->to); 563 msg.msg_namelen = linux_args->tolen; 564 msg.msg_iov = aiov; 565 msg.msg_iovlen = 1; 566 msg.msg_control = NULL; 567 msg.msg_flags = 0; 568 aiov[0].iov_base = (char *)packet; 569 aiov[0].iov_len = linux_args->len; 570 error = linux_sendit(td, linux_args->s, &msg, linux_args->flags, 571 NULL, UIO_SYSSPACE); 572goout: 573 free(packet, M_TEMP); 574 return (error); 575} 576 577struct linux_socket_args { 578 int domain; 579 int type; 580 int protocol; 581}; 582 583static int 584linux_socket(struct thread *td, struct linux_socket_args *args) 585{ 586#ifdef INET6 587#ifndef KLD_MODULE 588 INIT_VNET_INET6(curvnet); 589#endif 590#endif 591 struct socket_args /* { 592 int domain; 593 int type; 594 int protocol; 595 } */ bsd_args; 596 int retval_socket, socket_flags; 597 598 bsd_args.protocol = args->protocol; 599 socket_flags = args->type & ~LINUX_SOCK_TYPE_MASK; 600 if (socket_flags & ~(LINUX_SOCK_CLOEXEC | LINUX_SOCK_NONBLOCK)) 601 return (EINVAL); 602 bsd_args.type = args->type & LINUX_SOCK_TYPE_MASK; 603 if (bsd_args.type < 0 || bsd_args.type > LINUX_SOCK_MAX) 604 return (EINVAL); 605 bsd_args.domain = linux_to_bsd_domain(args->domain); 606 if (bsd_args.domain == -1) 607 return (EAFNOSUPPORT); 608 609 retval_socket = socket(td, &bsd_args); 610 if (retval_socket) 611 return (retval_socket); 612 613 if (socket_flags & LINUX_SOCK_NONBLOCK) { 614 retval_socket = kern_fcntl(td, td->td_retval[0], 615 F_SETFL, O_NONBLOCK); 616 if (retval_socket) { 617 (void)kern_close(td, td->td_retval[0]); 618 goto out; 619 } 620 } 621 if (socket_flags & LINUX_SOCK_CLOEXEC) { 622 retval_socket = kern_fcntl(td, td->td_retval[0], 623 F_SETFD, FD_CLOEXEC); 624 if (retval_socket) { 625 (void)kern_close(td, td->td_retval[0]); 626 goto out; 627 } 628 } 629 630 if (bsd_args.type == SOCK_RAW 631 && (bsd_args.protocol == IPPROTO_RAW || bsd_args.protocol == 0) 632 && bsd_args.domain == PF_INET) { 633 /* It's a raw IP socket: set the IP_HDRINCL option. */ 634 int hdrincl; 635 636 hdrincl = 1; 637 /* We ignore any error returned by kern_setsockopt() */ 638 kern_setsockopt(td, td->td_retval[0], IPPROTO_IP, IP_HDRINCL, 639 &hdrincl, UIO_SYSSPACE, sizeof(hdrincl)); 640 } 641#ifdef INET6 642 /* 643 * Linux AF_INET6 socket has IPV6_V6ONLY setsockopt set to 0 by 644 * default and some apps depend on this. So, set V6ONLY to 0 645 * for Linux apps if the sysctl value is set to 1. 646 */ 647 if (bsd_args.domain == PF_INET6 648#ifndef KLD_MODULE 649 /* 650 * XXX: Avoid undefined symbol error with an IPv4 only 651 * kernel. 652 */ 653 && V_ip6_v6only 654#endif 655 ) { 656 int v6only; 657 658 v6only = 0; 659 /* We ignore any error returned by setsockopt() */ 660 kern_setsockopt(td, td->td_retval[0], IPPROTO_IPV6, IPV6_V6ONLY, 661 &v6only, UIO_SYSSPACE, sizeof(v6only)); 662 } 663#endif 664 665out: 666 return (retval_socket); 667} 668 669struct linux_bind_args { 670 int s; 671 l_uintptr_t name; 672 int namelen; 673}; 674 675static int 676linux_bind(struct thread *td, struct linux_bind_args *args) 677{ 678 struct sockaddr *sa; 679 int error; 680 681 error = linux_getsockaddr(&sa, PTRIN(args->name), 682 args->namelen); 683 if (error) 684 return (error); 685 686 error = kern_bind(td, args->s, sa); 687 free(sa, M_SONAME); 688 if (error == EADDRNOTAVAIL && args->namelen != sizeof(struct sockaddr_in)) 689 return (EINVAL); 690 return (error); 691} 692 693struct linux_connect_args { 694 int s; 695 l_uintptr_t name; 696 int namelen; 697}; 698int linux_connect(struct thread *, struct linux_connect_args *); 699 700int 701linux_connect(struct thread *td, struct linux_connect_args *args) 702{ 703 struct socket *so; 704 struct sockaddr *sa; 705 u_int fflag; 706 int error; 707 708 error = linux_getsockaddr(&sa, (struct osockaddr *)PTRIN(args->name), 709 args->namelen); 710 if (error) 711 return (error); 712 713 error = kern_connect(td, args->s, sa); 714 free(sa, M_SONAME); 715 if (error != EISCONN) 716 return (error); 717 718 /* 719 * Linux doesn't return EISCONN the first time it occurs, 720 * when on a non-blocking socket. Instead it returns the 721 * error getsockopt(SOL_SOCKET, SO_ERROR) would return on BSD. 722 * 723 * XXXRW: Instead of using fgetsock(), check that it is a 724 * socket and use the file descriptor reference instead of 725 * creating a new one. 726 */ 727 error = fgetsock(td, args->s, &so, &fflag); 728 if (error == 0) { 729 error = EISCONN; 730 if (fflag & FNONBLOCK) { 731 SOCK_LOCK(so); 732 if (so->so_emuldata == 0) 733 error = so->so_error; 734 so->so_emuldata = (void *)1; 735 SOCK_UNLOCK(so); 736 } 737 fputsock(so); 738 } 739 return (error); 740} 741 742struct linux_listen_args { 743 int s; 744 int backlog; 745}; 746 747static int 748linux_listen(struct thread *td, struct linux_listen_args *args) 749{ 750 struct listen_args /* { 751 int s; 752 int backlog; 753 } */ bsd_args; 754 755 bsd_args.s = args->s; 756 bsd_args.backlog = args->backlog; 757 return (listen(td, &bsd_args)); 758} 759 760struct linux_accept_args { 761 int s; 762 l_uintptr_t addr; 763 l_uintptr_t namelen; 764}; 765 766static int 767linux_accept(struct thread *td, struct linux_accept_args *args) 768{ 769 struct accept_args /* { 770 int s; 771 struct sockaddr * __restrict name; 772 socklen_t * __restrict anamelen; 773 } */ bsd_args; 774 int error, fd; 775 776 bsd_args.s = args->s; 777 /* XXX: */ 778 bsd_args.name = (struct sockaddr * __restrict)PTRIN(args->addr); 779 bsd_args.anamelen = PTRIN(args->namelen);/* XXX */ 780 error = accept(td, &bsd_args); 781 bsd_to_linux_sockaddr((struct sockaddr *)bsd_args.name); 782 if (error) { 783 if (error == EFAULT && args->namelen != sizeof(struct sockaddr_in)) 784 return (EINVAL); 785 return (error); 786 } 787 if (args->addr) { 788 error = linux_sa_put(PTRIN(args->addr)); 789 if (error) { 790 (void)kern_close(td, td->td_retval[0]); 791 return (error); 792 } 793 } 794 795 /* 796 * linux appears not to copy flags from the parent socket to the 797 * accepted one, so we must clear the flags in the new descriptor. 798 * Ignore any errors, because we already have an open fd. 799 */ 800 fd = td->td_retval[0]; 801 (void)kern_fcntl(td, fd, F_SETFL, 0); 802 td->td_retval[0] = fd; 803 return (0); 804} 805 806struct linux_getsockname_args { 807 int s; 808 l_uintptr_t addr; 809 l_uintptr_t namelen; 810}; 811 812static int 813linux_getsockname(struct thread *td, struct linux_getsockname_args *args) 814{ 815 struct getsockname_args /* { 816 int fdes; 817 struct sockaddr * __restrict asa; 818 socklen_t * __restrict alen; 819 } */ bsd_args; 820 int error; 821 822 bsd_args.fdes = args->s; 823 /* XXX: */ 824 bsd_args.asa = (struct sockaddr * __restrict)PTRIN(args->addr); 825 bsd_args.alen = PTRIN(args->namelen); /* XXX */ 826 error = getsockname(td, &bsd_args); 827 bsd_to_linux_sockaddr((struct sockaddr *)bsd_args.asa); 828 if (error) 829 return (error); 830 error = linux_sa_put(PTRIN(args->addr)); 831 if (error) 832 return (error); 833 return (0); 834} 835 836struct linux_getpeername_args { 837 int s; 838 l_uintptr_t addr; 839 l_uintptr_t namelen; 840}; 841 842static int 843linux_getpeername(struct thread *td, struct linux_getpeername_args *args) 844{ 845 struct getpeername_args /* { 846 int fdes; 847 caddr_t asa; 848 int *alen; 849 } */ bsd_args; 850 int error; 851 852 bsd_args.fdes = args->s; 853 bsd_args.asa = (struct sockaddr *)PTRIN(args->addr); 854 bsd_args.alen = (int *)PTRIN(args->namelen); 855 error = getpeername(td, &bsd_args); 856 bsd_to_linux_sockaddr((struct sockaddr *)bsd_args.asa); 857 if (error) 858 return (error); 859 error = linux_sa_put(PTRIN(args->addr)); 860 if (error) 861 return (error); 862 return (0); 863} 864 865struct linux_socketpair_args { 866 int domain; 867 int type; 868 int protocol; 869 l_uintptr_t rsv; 870}; 871 872static int 873linux_socketpair(struct thread *td, struct linux_socketpair_args *args) 874{ 875 struct socketpair_args /* { 876 int domain; 877 int type; 878 int protocol; 879 int *rsv; 880 } */ bsd_args; 881 882 bsd_args.domain = linux_to_bsd_domain(args->domain); 883 if (bsd_args.domain != PF_LOCAL) 884 return (EAFNOSUPPORT); 885 886 bsd_args.type = args->type; 887 if (args->protocol != 0 && args->protocol != PF_UNIX) 888 889 /* 890 * Use of PF_UNIX as protocol argument is not right, 891 * but Linux does it. 892 * Do not map PF_UNIX as its Linux value is identical 893 * to FreeBSD one. 894 */ 895 return (EPROTONOSUPPORT); 896 else 897 bsd_args.protocol = 0; 898 bsd_args.rsv = (int *)PTRIN(args->rsv); 899 return (socketpair(td, &bsd_args)); 900} 901 902struct linux_send_args { 903 int s; 904 l_uintptr_t msg; 905 int len; 906 int flags; 907}; 908 909static int 910linux_send(struct thread *td, struct linux_send_args *args) 911{ 912 struct sendto_args /* { 913 int s; 914 caddr_t buf; 915 int len; 916 int flags; 917 caddr_t to; 918 int tolen; 919 } */ bsd_args; 920 921 bsd_args.s = args->s; 922 bsd_args.buf = (caddr_t)PTRIN(args->msg); 923 bsd_args.len = args->len; 924 bsd_args.flags = args->flags; 925 bsd_args.to = NULL; 926 bsd_args.tolen = 0; 927 return sendto(td, &bsd_args); 928} 929 930struct linux_recv_args { 931 int s; 932 l_uintptr_t msg; 933 int len; 934 int flags; 935}; 936 937static int 938linux_recv(struct thread *td, struct linux_recv_args *args) 939{ 940 struct recvfrom_args /* { 941 int s; 942 caddr_t buf; 943 int len; 944 int flags; 945 struct sockaddr *from; 946 socklen_t fromlenaddr; 947 } */ bsd_args; 948 949 bsd_args.s = args->s; 950 bsd_args.buf = (caddr_t)PTRIN(args->msg); 951 bsd_args.len = args->len; 952 bsd_args.flags = linux_to_bsd_msg_flags(args->flags); 953 bsd_args.from = NULL; 954 bsd_args.fromlenaddr = 0; 955 return (recvfrom(td, &bsd_args)); 956} 957 958static int 959linux_sendto(struct thread *td, struct linux_sendto_args *args) 960{ 961 struct msghdr msg; 962 struct iovec aiov; 963 int error; 964 965 if (linux_check_hdrincl(td, args->s) == 0) 966 /* IP_HDRINCL set, tweak the packet before sending */ 967 return (linux_sendto_hdrincl(td, args)); 968 969 msg.msg_name = PTRIN(args->to); 970 msg.msg_namelen = args->tolen; 971 msg.msg_iov = &aiov; 972 msg.msg_iovlen = 1; 973 msg.msg_control = NULL; 974 msg.msg_flags = 0; 975 aiov.iov_base = PTRIN(args->msg); 976 aiov.iov_len = args->len; 977 error = linux_sendit(td, args->s, &msg, args->flags, NULL, 978 UIO_USERSPACE); 979 return (error); 980} 981 982struct linux_recvfrom_args { 983 int s; 984 l_uintptr_t buf; 985 int len; 986 int flags; 987 l_uintptr_t from; 988 l_uintptr_t fromlen; 989}; 990 991static int 992linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args) 993{ 994 struct recvfrom_args /* { 995 int s; 996 caddr_t buf; 997 size_t len; 998 int flags; 999 struct sockaddr * __restrict from; 1000 socklen_t * __restrict fromlenaddr; 1001 } */ bsd_args; 1002 size_t len; 1003 int error; 1004 1005 if ((error = copyin(PTRIN(args->fromlen), &len, sizeof(size_t)))) 1006 return (error); 1007 1008 bsd_args.s = args->s; 1009 bsd_args.buf = PTRIN(args->buf); 1010 bsd_args.len = args->len; 1011 bsd_args.flags = linux_to_bsd_msg_flags(args->flags); 1012 /* XXX: */ 1013 bsd_args.from = (struct sockaddr * __restrict)PTRIN(args->from); 1014 bsd_args.fromlenaddr = PTRIN(args->fromlen);/* XXX */ 1015 1016 linux_to_bsd_sockaddr((struct sockaddr *)bsd_args.from, len); 1017 error = recvfrom(td, &bsd_args); 1018 bsd_to_linux_sockaddr((struct sockaddr *)bsd_args.from); 1019 1020 if (error) 1021 return (error); 1022 if (args->from) { 1023 error = linux_sa_put((struct osockaddr *) 1024 PTRIN(args->from)); 1025 if (error) 1026 return (error); 1027 } 1028 return (0); 1029} 1030 1031struct linux_sendmsg_args { 1032 int s; 1033 l_uintptr_t msg; 1034 int flags; 1035}; 1036 1037static int 1038linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args) 1039{ 1040 struct cmsghdr *cmsg; 1041 struct mbuf *control; 1042 struct msghdr msg; 1043 struct l_cmsghdr linux_cmsg; 1044 struct l_cmsghdr *ptr_cmsg; 1045 struct l_msghdr linux_msg; 1046 struct iovec *iov; 1047 socklen_t datalen; 1048 void *data; 1049 int error; 1050 1051 error = copyin(PTRIN(args->msg), &linux_msg, sizeof(linux_msg)); 1052 if (error) 1053 return (error); 1054 error = linux_to_bsd_msghdr(&msg, &linux_msg); 1055 if (error) 1056 return (error); 1057 1058 /* 1059 * Some Linux applications (ping) define a non-NULL control data 1060 * pointer, but a msg_controllen of 0, which is not allowed in the 1061 * FreeBSD system call interface. NULL the msg_control pointer in 1062 * order to handle this case. This should be checked, but allows the 1063 * Linux ping to work. 1064 */ 1065 if (msg.msg_control != NULL && msg.msg_controllen == 0) 1066 msg.msg_control = NULL; 1067 1068#ifdef COMPAT_LINUX32 1069 error = linux32_copyiniov(PTRIN(msg.msg_iov), msg.msg_iovlen, 1070 &iov, EMSGSIZE); 1071#else 1072 error = copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE); 1073#endif 1074 if (error) 1075 return (error); 1076 1077 if (msg.msg_control != NULL) { 1078 error = ENOBUFS; 1079 cmsg = malloc(CMSG_HDRSZ, M_TEMP, M_WAITOK | M_ZERO); 1080 control = m_get(M_WAIT, MT_CONTROL); 1081 if (control == NULL) 1082 goto bad; 1083 ptr_cmsg = LINUX_CMSG_FIRSTHDR(&msg); 1084 1085 do { 1086 error = copyin(ptr_cmsg, &linux_cmsg, 1087 sizeof(struct l_cmsghdr)); 1088 if (error) 1089 goto bad; 1090 1091 error = EINVAL; 1092 if (linux_cmsg.cmsg_len < sizeof(struct l_cmsghdr)) 1093 goto bad; 1094 1095 /* 1096 * Now we support only SCM_RIGHTS, so return EINVAL 1097 * in any other cmsg_type 1098 */ 1099 if ((cmsg->cmsg_type = 1100 linux_to_bsd_cmsg_type(linux_cmsg.cmsg_type)) == -1) 1101 goto bad; 1102 cmsg->cmsg_level = 1103 linux_to_bsd_sockopt_level(linux_cmsg.cmsg_level); 1104 1105 datalen = linux_cmsg.cmsg_len - L_CMSG_HDRSZ; 1106 cmsg->cmsg_len = CMSG_LEN(datalen); 1107 data = LINUX_CMSG_DATA(ptr_cmsg); 1108 1109 error = ENOBUFS; 1110 if (!m_append(control, CMSG_HDRSZ, (c_caddr_t) cmsg)) 1111 goto bad; 1112 if (!m_append(control, datalen, (c_caddr_t) data)) 1113 goto bad; 1114 } while ((ptr_cmsg = LINUX_CMSG_NXTHDR(&msg, ptr_cmsg))); 1115 } else { 1116 control = NULL; 1117 cmsg = NULL; 1118 } 1119 1120 msg.msg_iov = iov; 1121 msg.msg_flags = 0; 1122 error = linux_sendit(td, args->s, &msg, args->flags, control, 1123 UIO_USERSPACE); 1124 1125bad: 1126 free(iov, M_IOV); 1127 if (cmsg) 1128 free(cmsg, M_TEMP); 1129 return (error); 1130} 1131 1132struct linux_recvmsg_args { 1133 int s; 1134 l_uintptr_t msg; 1135 int flags; 1136}; 1137 1138static int 1139linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args) 1140{ 1141 struct cmsghdr *cm; 1142 struct msghdr msg; 1143 struct l_cmsghdr *linux_cmsg = NULL; 1144 socklen_t datalen, outlen, clen; 1145 struct l_msghdr linux_msg; 1146 struct iovec *iov, *uiov; 1147 struct mbuf *control = NULL; 1148 struct mbuf **controlp; 1149 caddr_t outbuf; 1150 void *data; 1151 int error, i, fd, fds, *fdp; 1152 1153 error = copyin(PTRIN(args->msg), &linux_msg, sizeof(linux_msg)); 1154 if (error) 1155 return (error); 1156 1157 error = linux_to_bsd_msghdr(&msg, &linux_msg); 1158 if (error) 1159 return (error); 1160 1161#ifdef COMPAT_LINUX32 1162 error = linux32_copyiniov(PTRIN(msg.msg_iov), msg.msg_iovlen, 1163 &iov, EMSGSIZE); 1164#else 1165 error = copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE); 1166#endif 1167 if (error) 1168 return (error); 1169 1170 if (msg.msg_name) { 1171 error = linux_to_bsd_sockaddr((struct sockaddr *)msg.msg_name, 1172 msg.msg_namelen); 1173 if (error) 1174 goto bad; 1175 } 1176 1177 uiov = msg.msg_iov; 1178 msg.msg_iov = iov; 1179 controlp = (msg.msg_control != NULL) ? &control : NULL; 1180 error = kern_recvit(td, args->s, &msg, UIO_USERSPACE, controlp); 1181 msg.msg_iov = uiov; 1182 if (error) 1183 goto bad; 1184 1185 error = bsd_to_linux_msghdr(&msg, &linux_msg); 1186 if (error) 1187 goto bad; 1188 1189 if (linux_msg.msg_name) { 1190 error = bsd_to_linux_sockaddr((struct sockaddr *) 1191 PTRIN(linux_msg.msg_name)); 1192 if (error) 1193 goto bad; 1194 } 1195 if (linux_msg.msg_name && linux_msg.msg_namelen > 2) { 1196 error = linux_sa_put(PTRIN(linux_msg.msg_name)); 1197 if (error) 1198 goto bad; 1199 } 1200 1201 if (control) { 1202 1203 linux_cmsg = malloc(L_CMSG_HDRSZ, M_TEMP, M_WAITOK | M_ZERO); 1204 outbuf = PTRIN(linux_msg.msg_control); 1205 cm = mtod(control, struct cmsghdr *); 1206 outlen = 0; 1207 clen = control->m_len; 1208 1209 while (cm != NULL) { 1210 1211 if ((linux_cmsg->cmsg_type = 1212 bsd_to_linux_cmsg_type(cm->cmsg_type)) == -1) 1213 { 1214 error = EINVAL; 1215 goto bad; 1216 } 1217 data = CMSG_DATA(cm); 1218 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data; 1219 1220 switch (linux_cmsg->cmsg_type) 1221 { 1222 case LINUX_SCM_RIGHTS: 1223 if (outlen + LINUX_CMSG_LEN(datalen) > 1224 linux_msg.msg_controllen) { 1225 if (outlen == 0) { 1226 error = EMSGSIZE; 1227 goto bad; 1228 } else { 1229 linux_msg.msg_flags |= 1230 LINUX_MSG_CTRUNC; 1231 goto out; 1232 } 1233 } 1234 if (args->flags & LINUX_MSG_CMSG_CLOEXEC) { 1235 fds = datalen / sizeof(int); 1236 fdp = data; 1237 for (i = 0; i < fds; i++) { 1238 fd = *fdp++; 1239 (void)kern_fcntl(td, fd, 1240 F_SETFD, FD_CLOEXEC); 1241 } 1242 } 1243 break; 1244 } 1245 1246 linux_cmsg->cmsg_len = LINUX_CMSG_LEN(datalen); 1247 linux_cmsg->cmsg_level = 1248 bsd_to_linux_sockopt_level(cm->cmsg_level); 1249 1250 error = copyout(linux_cmsg, outbuf, L_CMSG_HDRSZ); 1251 if (error) 1252 goto bad; 1253 outbuf += L_CMSG_HDRSZ; 1254 1255 error = copyout(data, outbuf, datalen); 1256 if (error) 1257 goto bad; 1258 1259 outbuf += LINUX_CMSG_ALIGN(datalen); 1260 outlen += LINUX_CMSG_LEN(datalen); 1261 linux_msg.msg_controllen = outlen; 1262 1263 if (CMSG_SPACE(datalen) < clen) { 1264 clen -= CMSG_SPACE(datalen); 1265 cm = (struct cmsghdr *) 1266 ((caddr_t)cm + CMSG_SPACE(datalen)); 1267 } else 1268 cm = NULL; 1269 } 1270 } 1271 1272out: 1273 error = copyout(&linux_msg, PTRIN(args->msg), sizeof(linux_msg)); 1274 1275bad: 1276 free(iov, M_IOV); 1277 if (control != NULL) 1278 m_freem(control); 1279 if (linux_cmsg != NULL) 1280 free(linux_cmsg, M_TEMP); 1281 1282 return (error); 1283} 1284 1285struct linux_shutdown_args { 1286 int s; 1287 int how; 1288}; 1289 1290static int 1291linux_shutdown(struct thread *td, struct linux_shutdown_args *args) 1292{ 1293 struct shutdown_args /* { 1294 int s; 1295 int how; 1296 } */ bsd_args; 1297 1298 bsd_args.s = args->s; 1299 bsd_args.how = args->how; 1300 return (shutdown(td, &bsd_args)); 1301} 1302 1303struct linux_setsockopt_args { 1304 int s; 1305 int level; 1306 int optname; 1307 l_uintptr_t optval; 1308 int optlen; 1309}; 1310 1311static int 1312linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args) 1313{ 1314 struct setsockopt_args /* { 1315 int s; 1316 int level; 1317 int name; 1318 caddr_t val; 1319 int valsize; 1320 } */ bsd_args; 1321 l_timeval linux_tv; 1322 struct timeval tv; 1323 int error, name; 1324 1325 bsd_args.s = args->s; 1326 bsd_args.level = linux_to_bsd_sockopt_level(args->level); 1327 switch (bsd_args.level) { 1328 case SOL_SOCKET: 1329 name = linux_to_bsd_so_sockopt(args->optname); 1330 switch (name) { 1331 case SO_RCVTIMEO: 1332 /* FALLTHROUGH */ 1333 case SO_SNDTIMEO: 1334 error = copyin(PTRIN(args->optval), &linux_tv, 1335 sizeof(linux_tv)); 1336 if (error) 1337 return (error); 1338 tv.tv_sec = linux_tv.tv_sec; 1339 tv.tv_usec = linux_tv.tv_usec; 1340 return (kern_setsockopt(td, args->s, bsd_args.level, 1341 name, &tv, UIO_SYSSPACE, sizeof(tv))); 1342 /* NOTREACHED */ 1343 break; 1344 default: 1345 break; 1346 } 1347 break; 1348 case IPPROTO_IP: 1349 name = linux_to_bsd_ip_sockopt(args->optname); 1350 break; 1351 case IPPROTO_TCP: 1352 /* Linux TCP option values match BSD's */ 1353 name = args->optname; 1354 break; 1355 default: 1356 name = -1; 1357 break; 1358 } 1359 if (name == -1) 1360 return (ENOPROTOOPT); 1361 1362 bsd_args.name = name; 1363 bsd_args.val = PTRIN(args->optval); 1364 bsd_args.valsize = args->optlen; 1365 1366 if (name == IPV6_NEXTHOP) { 1367 linux_to_bsd_sockaddr((struct sockaddr *)bsd_args.val, 1368 bsd_args.valsize); 1369 error = setsockopt(td, &bsd_args); 1370 bsd_to_linux_sockaddr((struct sockaddr *)bsd_args.val); 1371 } else 1372 error = setsockopt(td, &bsd_args); 1373 1374 return (error); 1375} 1376 1377struct linux_getsockopt_args { 1378 int s; 1379 int level; 1380 int optname; 1381 l_uintptr_t optval; 1382 l_uintptr_t optlen; 1383}; 1384 1385static int 1386linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args) 1387{ 1388 struct getsockopt_args /* { 1389 int s; 1390 int level; 1391 int name; 1392 caddr_t val; 1393 int *avalsize; 1394 } */ bsd_args; 1395 l_timeval linux_tv; 1396 struct timeval tv; 1397 socklen_t tv_len, xulen; 1398 struct xucred xu; 1399 struct l_ucred lxu; 1400 int error, name; 1401 1402 bsd_args.s = args->s; 1403 bsd_args.level = linux_to_bsd_sockopt_level(args->level); 1404 switch (bsd_args.level) { 1405 case SOL_SOCKET: 1406 name = linux_to_bsd_so_sockopt(args->optname); 1407 switch (name) { 1408 case SO_RCVTIMEO: 1409 /* FALLTHROUGH */ 1410 case SO_SNDTIMEO: 1411 tv_len = sizeof(tv); 1412 error = kern_getsockopt(td, args->s, bsd_args.level, 1413 name, &tv, UIO_SYSSPACE, &tv_len); 1414 if (error) 1415 return (error); 1416 linux_tv.tv_sec = tv.tv_sec; 1417 linux_tv.tv_usec = tv.tv_usec; 1418 return (copyout(&linux_tv, PTRIN(args->optval), 1419 sizeof(linux_tv))); 1420 /* NOTREACHED */ 1421 break; 1422 case LOCAL_PEERCRED: 1423 if (args->optlen != sizeof(lxu)) 1424 return (EINVAL); 1425 xulen = sizeof(xu); 1426 error = kern_getsockopt(td, args->s, bsd_args.level, 1427 name, &xu, UIO_SYSSPACE, &xulen); 1428 if (error) 1429 return (error); 1430 /* 1431 * XXX Use 0 for pid as the FreeBSD does not cache peer pid. 1432 */ 1433 lxu.pid = 0; 1434 lxu.uid = xu.cr_uid; 1435 lxu.gid = xu.cr_gid; 1436 return (copyout(&lxu, PTRIN(args->optval), sizeof(lxu))); 1437 /* NOTREACHED */ 1438 break; 1439 default: 1440 break; 1441 } 1442 break; 1443 case IPPROTO_IP: 1444 name = linux_to_bsd_ip_sockopt(args->optname); 1445 break; 1446 case IPPROTO_TCP: 1447 /* Linux TCP option values match BSD's */ 1448 name = args->optname; 1449 break; 1450 default: 1451 name = -1; 1452 break; 1453 } 1454 if (name == -1) 1455 return (EINVAL); 1456 1457 bsd_args.name = name; 1458 bsd_args.val = PTRIN(args->optval); 1459 bsd_args.avalsize = PTRIN(args->optlen); 1460 1461 if (name == IPV6_NEXTHOP) { 1462 error = getsockopt(td, &bsd_args); 1463 bsd_to_linux_sockaddr((struct sockaddr *)bsd_args.val); 1464 } else 1465 error = getsockopt(td, &bsd_args); 1466 1467 return (error); 1468} 1469 1470int 1471linux_socketcall(struct thread *td, struct linux_socketcall_args *args) 1472{ 1473 void *arg = (void *)(intptr_t)args->args; 1474 1475 switch (args->what) { 1476 case LINUX_SOCKET: 1477 return (linux_socket(td, arg)); 1478 case LINUX_BIND: 1479 return (linux_bind(td, arg)); 1480 case LINUX_CONNECT: 1481 return (linux_connect(td, arg)); 1482 case LINUX_LISTEN: 1483 return (linux_listen(td, arg)); 1484 case LINUX_ACCEPT: 1485 return (linux_accept(td, arg)); 1486 case LINUX_GETSOCKNAME: 1487 return (linux_getsockname(td, arg)); 1488 case LINUX_GETPEERNAME: 1489 return (linux_getpeername(td, arg)); 1490 case LINUX_SOCKETPAIR: 1491 return (linux_socketpair(td, arg)); 1492 case LINUX_SEND: 1493 return (linux_send(td, arg)); 1494 case LINUX_RECV: 1495 return (linux_recv(td, arg)); 1496 case LINUX_SENDTO: 1497 return (linux_sendto(td, arg)); 1498 case LINUX_RECVFROM: 1499 return (linux_recvfrom(td, arg)); 1500 case LINUX_SHUTDOWN: 1501 return (linux_shutdown(td, arg)); 1502 case LINUX_SETSOCKOPT: 1503 return (linux_setsockopt(td, arg)); 1504 case LINUX_GETSOCKOPT: 1505 return (linux_getsockopt(td, arg)); 1506 case LINUX_SENDMSG: 1507 return (linux_sendmsg(td, arg)); 1508 case LINUX_RECVMSG: 1509 return (linux_recvmsg(td, arg)); 1510 } 1511 1512 uprintf("LINUX: 'socket' typ=%d not implemented\n", args->what); 1513 return (ENOSYS); 1514} 1515