Blame SOURCES/glibc-rh1670041.patch

147e83
commit 08504de71813ddbd447bfbca4a325cbe8ce8bcda
147e83
Author: Florian Weimer <fweimer@redhat.com>
147e83
Date:   Tue Mar 12 11:40:47 2019 +0100
147e83
147e83
    resolv: Enable full ICMP errors for UDP DNS sockets [BZ #24047]
147e83
    
147e83
    The Linux kernel suppresses some ICMP error messages by default for
147e83
    UDP sockets.  This commit enables full ICMP error reporting,
147e83
    hopefully resulting in faster failover to working name servers.
147e83
147e83
diff --git a/resolv/Makefile b/resolv/Makefile
147e83
index 033c3c651f0deb1b..133fe5885c5b65b5 100644
147e83
--- a/resolv/Makefile
147e83
+++ b/resolv/Makefile
147e83
@@ -92,7 +92,7 @@ libresolv-routines := res_comp res_debug \
147e83
 		      res_data res_mkquery res_query res_send		\
147e83
 		      inet_net_ntop inet_net_pton inet_neta base64	\
147e83
 		      ns_parse ns_name ns_netint ns_ttl ns_print	\
147e83
-		      ns_samedomain ns_date \
147e83
+		      ns_samedomain ns_date res_enable_icmp \
147e83
 		      compat-hooks compat-gethnamaddr
147e83
 
147e83
 libanl-routines := gai_cancel gai_error gai_misc gai_notify gai_suspend \
147e83
diff --git a/resolv/res_enable_icmp.c b/resolv/res_enable_icmp.c
147e83
new file mode 100644
147e83
index 0000000000000000..bdc9220f08cef71d
147e83
--- /dev/null
147e83
+++ b/resolv/res_enable_icmp.c
147e83
@@ -0,0 +1,37 @@
147e83
+/* Enable full ICMP errors on a socket.
147e83
+   Copyright (C) 2019 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <errno.h>
147e83
+#include <netinet/in.h>
147e83
+#include <sys/socket.h>
147e83
+
147e83
+int
147e83
+__res_enable_icmp (int family, int fd)
147e83
+{
147e83
+  int one = 1;
147e83
+  switch (family)
147e83
+    {
147e83
+    case AF_INET:
147e83
+      return setsockopt (fd, SOL_IP, IP_RECVERR, &one, sizeof (one));
147e83
+    case AF_INET6:
147e83
+      return setsockopt (fd, SOL_IPV6, IPV6_RECVERR, &one, sizeof (one));
147e83
+    default:
147e83
+      __set_errno (EAFNOSUPPORT);
147e83
+      return -1;
147e83
+    }
147e83
+}
147e83
diff --git a/resolv/res_send.c b/resolv/res_send.c
147e83
index 05c7ba511b0383c1..e57bb12a66b087e4 100644
147e83
--- a/resolv/res_send.c
147e83
+++ b/resolv/res_send.c
147e83
@@ -943,6 +943,18 @@ reopen (res_state statp, int *terrno, int ns)
147e83
 			return (-1);
147e83
 		}
147e83
 
147e83
+		/* Enable full ICMP error reporting for this
147e83
+		   socket.  */
147e83
+		if (__res_enable_icmp (nsap->sa_family,
147e83
+				       EXT (statp).nssocks[ns]) < 0)
147e83
+		  {
147e83
+		    int saved_errno = errno;
147e83
+		    __res_iclose (statp, false);
147e83
+		    __set_errno (saved_errno);
147e83
+		    *terrno = saved_errno;
147e83
+		    return -1;
147e83
+		  }
147e83
+
147e83
 		/*
147e83
 		 * On a 4.3BSD+ machine (client and server,
147e83
 		 * actually), sending to a nameserver datagram
147e83
diff --git a/resolv/resolv-internal.h b/resolv/resolv-internal.h
147e83
index 32dc44777e311849..d73a2c1b944bcbbe 100644
147e83
--- a/resolv/resolv-internal.h
147e83
+++ b/resolv/resolv-internal.h
147e83
@@ -97,4 +97,10 @@ int __res_nopt (struct resolv_context *, int n0,
147e83
 int __inet_pton_length (int af, const char *src, size_t srclen, void *);
147e83
 libc_hidden_proto (__inet_pton_length)
147e83
 
147e83
+/* The Linux kernel does not enable all ICMP messages on a UDP socket
147e83
+   by default.  A call this function enables full error reporting for
147e83
+   the socket FD.  FAMILY must be AF_INET or AF_INET6.  Returns 0 on
147e83
+   success, -1 on failure.  */
147e83
+int __res_enable_icmp (int family, int fd) attribute_hidden;
147e83
+
147e83
 #endif  /* _RESOLV_INTERNAL_H */