about summary refs log tree commit diff
path: root/pkgs/os-specific/linux
diff options
context:
space:
mode:
authorWill Dietz <w@wdtz.org>2018-09-24 23:37:44 -0500
committerWill Dietz <w@wdtz.org>2018-09-24 23:59:02 -0500
commitdcd5e4558fb38c202c69f588e3a5fa99c73ea09b (patch)
tree676084cb7f482b5c6c378f3bb2294489a8c42d0a /pkgs/os-specific/linux
parent5c217591fda32180f688207f78caf73daf65b4df (diff)
musl: pick getaddrinfo fix (containers)
Diffstat (limited to 'pkgs/os-specific/linux')
-rw-r--r--pkgs/os-specific/linux/musl/default.nix2
-rw-r--r--pkgs/os-specific/linux/musl/fix-getaddrinfo-regression-with-AI_ADDRCONFIG.patch52
2 files changed, 54 insertions, 0 deletions
diff --git a/pkgs/os-specific/linux/musl/default.nix b/pkgs/os-specific/linux/musl/default.nix
index d2dbfea63ab67..e28b63164862b 100644
--- a/pkgs/os-specific/linux/musl/default.nix
+++ b/pkgs/os-specific/linux/musl/default.nix
@@ -67,6 +67,8 @@ stdenv.mkDerivation rec {
     ./0001-in-pthread_mutex_trylock-EBUSY-out-more-directly-whe.patch
     ./0002-in-pthread_mutex_timedlock-avoid-repeatedly-reading-.patch
     ./0003-fix-namespace-violation-for-c11-mutex-functions.patch
+    # Fix getaddrinfo usage encountered sometimes in containers
+    ./fix-getaddrinfo-regression-with-AI_ADDRCONFIG.patch
     # name_to_handle_at
     ./name-to-handle-at.patch
     ./max-handle-sz-for-name-to-handle-at.patch
diff --git a/pkgs/os-specific/linux/musl/fix-getaddrinfo-regression-with-AI_ADDRCONFIG.patch b/pkgs/os-specific/linux/musl/fix-getaddrinfo-regression-with-AI_ADDRCONFIG.patch
new file mode 100644
index 0000000000000..d603c16f8062c
--- /dev/null
+++ b/pkgs/os-specific/linux/musl/fix-getaddrinfo-regression-with-AI_ADDRCONFIG.patch
@@ -0,0 +1,52 @@
+From f381c118b2d4f7d914481d3cdc830ce41369b002 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Wed, 19 Sep 2018 18:03:22 -0400
+Subject: [PATCH] fix getaddrinfo regression with AI_ADDRCONFIG on some
+ configurations
+
+despite not being documented to do so in the standard or Linux
+documentation, attempts to udp connect to 127.0.0.1 or ::1 generate
+EADDRNOTAVAIL when the loopback device is not configured and there is
+no default route for IPv6. this caused getaddrinfo with AI_ADDRCONFIG
+to fail with EAI_SYSTEM and EADDRNOTAVAIL on some no-IPv6
+configurations, rather than the intended behavior of detecting IPv6 as
+unsuppported and producing IPv4-only results.
+
+previously, only EAFNOSUPPORT was treated as unavailability of the
+address family being probed. instead, treat all errors related to
+inability to get an address or route as conclusive that the family
+being probed is unsupported, and only fail with EAI_SYSTEM on other
+errors.
+
+further improvements may be desirable, such as reporting EAI_AGAIN
+instead of EAI_SYSTEM for errors which are expected to be transient,
+but this patch should suffice to fix the serious regression.
+---
+ src/network/getaddrinfo.c | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c
+index ba26847a..e33bfa28 100644
+--- a/src/network/getaddrinfo.c
++++ b/src/network/getaddrinfo.c
+@@ -76,7 +76,16 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
+ 				close(s);
+ 				if (!r) continue;
+ 			}
+-			if (errno != EAFNOSUPPORT) return EAI_SYSTEM;
++			switch (errno) {
++			case EADDRNOTAVAIL:
++			case EAFNOSUPPORT:
++			case EHOSTUNREACH:
++			case ENETDOWN:
++			case ENETUNREACH:
++				break;
++			default:
++				return EAI_SYSTEM;
++			}
+ 			if (family == tf[i]) return EAI_NONAME;
+ 			family = tf[1-i];
+ 		}
+-- 
+2.19.0
+