| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: linux_socket.c,v 1.100 2009/06/11 19:57:58 njoly Exp $ */ | | 1 | /* $NetBSD: linux_socket.c,v 1.101 2009/06/16 15:56:10 njoly Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Frank van der Linden and Eric Haszlakiewicz. | | 8 | * by Frank van der Linden and Eric Haszlakiewicz. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -25,27 +25,27 @@ | | | @@ -25,27 +25,27 @@ |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * Functions in multiarch: | | 33 | * Functions in multiarch: |
34 | * linux_sys_socketcall : linux_socketcall.c | | 34 | * linux_sys_socketcall : linux_socketcall.c |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <sys/cdefs.h> | | 37 | #include <sys/cdefs.h> |
38 | __KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.100 2009/06/11 19:57:58 njoly Exp $"); | | 38 | __KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.101 2009/06/16 15:56:10 njoly Exp $"); |
39 | | | 39 | |
40 | #if defined(_KERNEL_OPT) | | 40 | #if defined(_KERNEL_OPT) |
41 | #include "opt_inet.h" | | 41 | #include "opt_inet.h" |
42 | #endif /* defined(_KERNEL_OPT) */ | | 42 | #endif /* defined(_KERNEL_OPT) */ |
43 | | | 43 | |
44 | #include <sys/param.h> | | 44 | #include <sys/param.h> |
45 | #include <sys/kernel.h> | | 45 | #include <sys/kernel.h> |
46 | #include <sys/systm.h> | | 46 | #include <sys/systm.h> |
47 | #include <sys/buf.h> | | 47 | #include <sys/buf.h> |
48 | #include <sys/malloc.h> | | 48 | #include <sys/malloc.h> |
49 | #include <sys/ioctl.h> | | 49 | #include <sys/ioctl.h> |
50 | #include <sys/tty.h> | | 50 | #include <sys/tty.h> |
51 | #include <sys/file.h> | | 51 | #include <sys/file.h> |
| @@ -531,26 +531,29 @@ linux_sys_sendmsg(struct lwp *l, const s | | | @@ -531,26 +531,29 @@ linux_sys_sendmsg(struct lwp *l, const s |
531 | cidx += cspace; | | 531 | cidx += cspace; |
532 | } while ((l_cc = LINUX_CMSG_NXTHDR(&msg, l_cc)) && resid > 0); | | 532 | } while ((l_cc = LINUX_CMSG_NXTHDR(&msg, l_cc)) && resid > 0); |
533 | | | 533 | |
534 | /* If we allocated a buffer, attach to mbuf */ | | 534 | /* If we allocated a buffer, attach to mbuf */ |
535 | if (cidx > MLEN) { | | 535 | if (cidx > MLEN) { |
536 | MEXTADD(ctl_mbuf, control, clen, M_MBUF, NULL, NULL); | | 536 | MEXTADD(ctl_mbuf, control, clen, M_MBUF, NULL, NULL); |
537 | ctl_mbuf->m_flags |= M_EXT_RW; | | 537 | ctl_mbuf->m_flags |= M_EXT_RW; |
538 | } | | 538 | } |
539 | control = NULL; | | 539 | control = NULL; |
540 | ctl_mbuf->m_len = cidx; | | 540 | ctl_mbuf->m_len = cidx; |
541 | | | 541 | |
542 | msg.msg_control = ctl_mbuf; | | 542 | msg.msg_control = ctl_mbuf; |
543 | msg.msg_flags |= MSG_CONTROLMBUF; | | 543 | msg.msg_flags |= MSG_CONTROLMBUF; |
| | | 544 | |
| | | 545 | ktrkuser("msgcontrol", mtod(ctl_mbuf, void *), |
| | | 546 | msg.msg_controllen); |
544 | } | | 547 | } |
545 | | | 548 | |
546 | error = do_sys_sendmsg(l, SCARG(uap, s), &msg, bflags, retval); | | 549 | error = do_sys_sendmsg(l, SCARG(uap, s), &msg, bflags, retval); |
547 | /* Freed internally */ | | 550 | /* Freed internally */ |
548 | ctl_mbuf = NULL; | | 551 | ctl_mbuf = NULL; |
549 | | | 552 | |
550 | done: | | 553 | done: |
551 | if (ctl_mbuf != NULL) { | | 554 | if (ctl_mbuf != NULL) { |
552 | if (control != NULL && control != mtod(ctl_mbuf, void *)) | | 555 | if (control != NULL && control != mtod(ctl_mbuf, void *)) |
553 | free(control, M_MBUF); | | 556 | free(control, M_MBUF); |
554 | m_free(ctl_mbuf); | | 557 | m_free(ctl_mbuf); |
555 | } | | 558 | } |
556 | return (error); | | 559 | return (error); |
| @@ -591,26 +594,28 @@ linux_copyout_msg_control(struct lwp *l, | | | @@ -591,26 +594,28 @@ linux_copyout_msg_control(struct lwp *l, |
591 | { | | 594 | { |
592 | int dlen, error = 0; | | 595 | int dlen, error = 0; |
593 | struct cmsghdr *cmsg; | | 596 | struct cmsghdr *cmsg; |
594 | struct linux_cmsghdr linux_cmsg; | | 597 | struct linux_cmsghdr linux_cmsg; |
595 | struct mbuf *m; | | 598 | struct mbuf *m; |
596 | char *q, *q_end; | | 599 | char *q, *q_end; |
597 | | | 600 | |
598 | if (mp->msg_controllen <= 0 || control == 0) { | | 601 | if (mp->msg_controllen <= 0 || control == 0) { |
599 | mp->msg_controllen = 0; | | 602 | mp->msg_controllen = 0; |
600 | free_control_mbuf(l, control, control); | | 603 | free_control_mbuf(l, control, control); |
601 | return 0; | | 604 | return 0; |
602 | } | | 605 | } |
603 | | | 606 | |
| | | 607 | ktrkuser("msgcontrol", mtod(control, void *), mp->msg_controllen); |
| | | 608 | |
604 | q = (char *)mp->msg_control; | | 609 | q = (char *)mp->msg_control; |
605 | q_end = q + mp->msg_controllen; | | 610 | q_end = q + mp->msg_controllen; |
606 | | | 611 | |
607 | for (m = control; m != NULL; ) { | | 612 | for (m = control; m != NULL; ) { |
608 | cmsg = mtod(m, struct cmsghdr *); | | 613 | cmsg = mtod(m, struct cmsghdr *); |
609 | | | 614 | |
610 | /* | | 615 | /* |
611 | * Fixup cmsg. We handle two things: | | 616 | * Fixup cmsg. We handle two things: |
612 | * 0. different sizeof cmsg_len. | | 617 | * 0. different sizeof cmsg_len. |
613 | * 1. different values for level/type on some archs | | 618 | * 1. different values for level/type on some archs |
614 | * 2. different alignment of CMSG_DATA on some archs | | 619 | * 2. different alignment of CMSG_DATA on some archs |
615 | */ | | 620 | */ |
616 | linux_cmsg.cmsg_len = cmsg->cmsg_len - LINUX_CMSG_ALIGN_DELTA; | | 621 | linux_cmsg.cmsg_len = cmsg->cmsg_len - LINUX_CMSG_ALIGN_DELTA; |
| @@ -715,28 +720,30 @@ linux_sys_recvmsg(struct lwp *l, const s | | | @@ -715,28 +720,30 @@ linux_sys_recvmsg(struct lwp *l, const s |
715 | error = copyout_sockname(msg.msg_name, &msg.msg_namelen, 0, | | 720 | error = copyout_sockname(msg.msg_name, &msg.msg_namelen, 0, |
716 | from); | | 721 | from); |
717 | } else | | 722 | } else |
718 | msg.msg_namelen = 0; | | 723 | msg.msg_namelen = 0; |
719 | | | 724 | |
720 | if (from != NULL) | | 725 | if (from != NULL) |
721 | m_free(from); | | 726 | m_free(from); |
722 | | | 727 | |
723 | if (error == 0) { | | 728 | if (error == 0) { |
724 | msg.msg_flags = bsd_to_linux_msg_flags(msg.msg_flags); | | 729 | msg.msg_flags = bsd_to_linux_msg_flags(msg.msg_flags); |
725 | if (msg.msg_flags < 0) | | 730 | if (msg.msg_flags < 0) |
726 | /* Some flag unsupported by Linux */ | | 731 | /* Some flag unsupported by Linux */ |
727 | error = EINVAL; | | 732 | error = EINVAL; |
728 | else | | 733 | else { |
| | | 734 | ktrkuser("msghdr", &msg, sizeof(msg)); |
729 | error = copyout(&msg, SCARG(uap, msg), sizeof(msg)); | | 735 | error = copyout(&msg, SCARG(uap, msg), sizeof(msg)); |
| | | 736 | } |
730 | } | | 737 | } |
731 | | | 738 | |
732 | return (error); | | 739 | return (error); |
733 | } | | 740 | } |
734 | | | 741 | |
735 | /* | | 742 | /* |
736 | * Convert socket option level from Linux to NetBSD value. Only SOL_SOCKET | | 743 | * Convert socket option level from Linux to NetBSD value. Only SOL_SOCKET |
737 | * is different, the rest matches IPPROTO_* on both systems. | | 744 | * is different, the rest matches IPPROTO_* on both systems. |
738 | */ | | 745 | */ |
739 | int | | 746 | int |
740 | linux_to_bsd_sopt_level(int llevel) | | 747 | linux_to_bsd_sopt_level(int llevel) |
741 | { | | 748 | { |
742 | | | 749 | |