From 209b2e53d17a18a674a1835d07cbfb2451cfd619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 1 Jul 2019 16:16:40 +0200 Subject: [PATCH 1/2] Remove SO_BSDCOMPAT usage, it's ignore since Linux 2.4 The SO_BSDCOMPAT socket option is no-op since Linux 2.4, see the manpage: SO_BSDCOMPAT Enable BSD bug-to-bug compatibility. This is used by the UDP protocol module in Linux 2.0 and 2.2. If enabled, ICMP errors received for a UDP socket will not be passed to the user program. In later kernel versions, support for this option has been phased out: Linux 2.4 silently ignores it, and Linux 2.6 generates a kernel warning (printk()) if a program uses this option. Linux 2.0 also enabled BSD bug-to-bug compatibility options (random header changing, skipping of the broadcast flag) for raw sockets with this option, but that was removed in Linux 2.2. --- lib/isc/unix/socket.c | 59 +------------------------------------------ 1 file changed, 1 insertion(+), 58 deletions(-) diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 6eda418b9f..d2b8b77156 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -77,10 +77,6 @@ #include "errno2result.h" -#if defined(SO_BSDCOMPAT) && defined(__linux__) -#include -#endif - #ifdef ENABLE_TCP_FASTOPEN #include #endif @@ -2054,44 +2050,6 @@ set_sndbuf(void) { } #endif -#ifdef SO_BSDCOMPAT -/* - * This really should not be necessary to do. Having to workout - * which kernel version we are on at run time so that we don't cause - * the kernel to issue a warning about us using a deprecated socket option. - * Such warnings should *never* be on by default in production kernels. - * - * We can't do this a build time because executables are moved between - * machines and hence kernels. - * - * We can't just not set SO_BSDCOMAT because some kernels require it. - */ - -static isc_once_t bsdcompat_once = ISC_ONCE_INIT; -bool bsdcompat = true; - -static void -clear_bsdcompat(void) { -#ifdef __linux__ - struct utsname buf; - char *endp; - long int major; - long int minor; - - uname(&buf); /* Can only fail if buf is bad in Linux. */ - - /* Paranoia in parsing can be increased, but we trust uname(). */ - major = strtol(buf.release, &endp, 10); - if (*endp == '.') { - minor = strtol(endp+1, &endp, 10); - if ((major > 2) || ((major == 2) && (minor >= 4))) { - bsdcompat = false; - } - } -#endif /* __linux __ */ -} -#endif - static void use_min_mtu(isc__socket_t *sock) { #if !defined(IPV6_USE_MIN_MTU) && !defined(IPV6_MTU) @@ -2134,7 +2092,7 @@ opensocket(isc__socketmgr_t *manager, isc__socket_t *sock, char strbuf[ISC_STRERRORSIZE]; const char *err = "socket"; int tries = 0; -#if defined(USE_CMSG) || defined(SO_BSDCOMPAT) || defined(SO_NOSIGPIPE) +#if defined(USE_CMSG) || defined(SO_NOSIGPIPE) int on = 1; #endif #if defined(SO_RCVBUF) || defined(SO_SNDBUF) @@ -2282,21 +2240,6 @@ opensocket(isc__socketmgr_t *manager, isc__socket_t *sock, return (result); } -#ifdef SO_BSDCOMPAT - RUNTIME_CHECK(isc_once_do(&bsdcompat_once, - clear_bsdcompat) == ISC_R_SUCCESS); - if (sock->type != isc_sockettype_unix && bsdcompat && - setsockopt(sock->fd, SOL_SOCKET, SO_BSDCOMPAT, - (void *)&on, sizeof(on)) < 0) { - strerror_r(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, - "setsockopt(%d, SO_BSDCOMPAT) failed: %s", - sock->fd, - strbuf); - /* Press on... */ - } -#endif - #ifdef SO_NOSIGPIPE if (setsockopt(sock->fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on)) < 0) { From 9dd11ee258fb2cba4e3784869f8286a5b27d0b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 1 Jul 2019 16:19:01 +0200 Subject: [PATCH 2/2] Add CHANGES note: 5261. [cleanup] Remove SO_BSDCOMPAT socket option usage. --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index 7b11710c31..0ab20f6845 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +5261. [cleanup] Remove SO_BSDCOMPAT socket option usage. + 5260. [bug] dnstap-read was producing malformed output for large packets. [GL #1093]