From owner-freebsd-emulation@FreeBSD.ORG Sat Jan 19 16:26:17 2013 Return-Path: Delivered-To: emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id ABF0D614; Sat, 19 Jan 2013 16:26:17 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 745D02AD; Sat, 19 Jan 2013 16:26:17 +0000 (UTC) Received: from ralph.baldwin.cx (c-68-39-198-164.hsd1.de.comcast.net [68.39.198.164]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id D1A8CB918; Sat, 19 Jan 2013 11:26:16 -0500 (EST) From: John Baldwin To: emulation@freebsd.org Subject: [PATCH] Properly handle Linux TCP socket options Date: Sat, 19 Jan 2013 11:26:13 -0500 User-Agent: KMail/1.13.7 (FreeBSD/9.1-PRERELEASE; KDE/4.8.4; amd64; ; ) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201301191126.13257.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Sat, 19 Jan 2013 11:26:16 -0500 (EST) Cc: net@freebsd.org X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Jan 2013 16:26:17 -0000 The current setsockopt() wrapper for the Linux ABI claims that Linux and FreeBSD use the same values for TCP socket options. This is true for TCP_NODELAY and TCP_MAXSEG but not for any other options. This patch adds a mapping routine for TCP options similar to that used for other socket option levels. I believe this mapping to be correct in terms of which FreeBSD options have the same semantics as Linux options based on comparing code in the two kernels, but I'm not 100% certain about TCP_MD5SIG since the Linux code that it maps to is not as clear (it calls some function pointer and it is not clear if it is accepting a simple boolean value similar to FreeBSD's). Also, almost all of the socket stuff in the linux.h headers appears to be identical and at least some of it are in MI headers in Linux (such as the TCP options). It seems to me that a lot of that should move into linux_socket.h instead. Index: amd64/linux32/linux.h =================================================================== --- amd64/linux32/linux.h (revision 245225) +++ amd64/linux32/linux.h (working copy) @@ -725,6 +725,13 @@ #define LINUX_IP_ADD_MEMBERSHIP 35 #define LINUX_IP_DROP_MEMBERSHIP 36 +#define LINUX_TCP_NODELAY 1 +#define LINUX_TCP_MAXSEG 2 +#define LINUX_TCP_KEEPIDLE 4 +#define LINUX_TCP_KEEPINTVL 5 +#define LINUX_TCP_KEEPCNT 6 +#define LINUX_TCP_MD5SIG 14 + struct l_sockaddr { l_ushort sa_family; char sa_data[14]; Index: compat/linux/linux_socket.c =================================================================== --- compat/linux/linux_socket.c (revision 245225) +++ compat/linux/linux_socket.c (working copy) @@ -56,6 +56,7 @@ #include #include #include +#include #ifdef INET6 #include #include @@ -326,6 +327,27 @@ } static int +linux_to_bsd_tcp_sockopt(int opt) +{ + + switch (opt) { + case LINUX_TCP_NODELAY: + return (TCP_NODELAY); + case LINUX_TCP_MAXSEG: + return (TCP_MAXSEG); + case LINUX_TCP_KEEPIDLE: + return (TCP_KEEPIDLE); + case LINUX_TCP_KEEPINTVL: + return (TCP_KEEPINTVL); + case LINUX_TCP_KEEPCNT: + return (TCP_KEEPCNT); + case LINUX_TCP_MD5SIG: + return (TCP_MD5SIG); + } + return (-1); +} + +static int linux_to_bsd_msg_flags(int flags) { int ret_flags = 0; @@ -1496,8 +1518,7 @@ name = linux_to_bsd_ip_sockopt(args->optname); break; case IPPROTO_TCP: - /* Linux TCP option values match BSD's */ - name = args->optname; + name = linux_to_bsd_tcp_sockopt(args->optname); break; default: name = -1; Index: i386/linux/linux.h =================================================================== --- i386/linux/linux.h (revision 245225) +++ i386/linux/linux.h (working copy) @@ -701,6 +701,13 @@ #define LINUX_IP_ADD_MEMBERSHIP 35 #define LINUX_IP_DROP_MEMBERSHIP 36 +#define LINUX_TCP_NODELAY 1 +#define LINUX_TCP_MAXSEG 2 +#define LINUX_TCP_KEEPIDLE 4 +#define LINUX_TCP_KEEPINTVL 5 +#define LINUX_TCP_KEEPCNT 6 +#define LINUX_TCP_MD5SIG 14 + struct l_sockaddr { l_ushort sa_family; char sa_data[14]; -- John Baldwin