diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-01-28 12:30:25 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-01-28 12:30:25 +0000 |
commit | 4fe834a29f6592cfd3a11a4c231b5c9ca13cb49d (patch) | |
tree | 5598276587352b9d1bf2951c28ec1e4519ea9441 /src/libutil/addr.c | |
parent | 58b5048924664bd913b0b275e61dea9a088b17e7 (diff) | |
download | rspamd-4fe834a29f6592cfd3a11a4c231b5c9ca13cb49d.tar.gz rspamd-4fe834a29f6592cfd3a11a4c231b5c9ca13cb49d.zip |
[Minor] Disable ipv6 check via bind to a random port
Issue: #3221
Diffstat (limited to 'src/libutil/addr.c')
-rw-r--r-- | src/libutil/addr.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 03e7e9918..27e63cd79 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -146,34 +146,39 @@ static void rspamd_ip_check_ipv6 (void) { if (ipv6_status == RSPAMD_IPV6_UNDEFINED) { - gint s, r; - struct sockaddr_in6 sin6; - const struct in6_addr ip6_local = IN6ADDR_LOOPBACK_INIT; + gint s; s = socket (AF_INET6, SOCK_STREAM, 0); + if (s == -1) { ipv6_status = RSPAMD_IPV6_UNSUPPORTED; } else { /* - * Some systems allow ipv6 sockets creating but not binding, - * so here we try to bind to some local address and check, whether it - * is possible + * Try to check /proc if we are on Linux (the common case) */ - memset (&sin6, 0, sizeof (sin6)); - sin6.sin6_family = AF_INET6; - sin6.sin6_port = rspamd_random_uint64_fast () % 40000 + 20000; - sin6.sin6_addr = ip6_local; - - r = bind (s, (struct sockaddr *)&sin6, sizeof (sin6)); - if (r == -1 && errno != EADDRINUSE) { - ipv6_status = RSPAMD_IPV6_UNSUPPORTED; + struct stat st; + + close (s); + + if (stat ("/proc/net/dev", &st) != -1) { + if (stat ("/proc/net/if_inet6", &st) != -1) { + if (st.st_size != 0) { + ipv6_status = RSPAMD_IPV6_SUPPORTED; + } + else { + /* Empty file, no ipv6 configuration at all */ + ipv6_status = RSPAMD_IPV6_UNSUPPORTED; + } + } + else { + ipv6_status = RSPAMD_IPV6_UNSUPPORTED; + } } else { + /* Not a Linux, so we assume it supports ipv6 somehow... */ ipv6_status = RSPAMD_IPV6_SUPPORTED; } - - close (s); } } } |