commit 4fe834a: [Minor] Disable ipv6 check via bind to a random port
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Jan 28 12:35:06 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-01-28 12:30:25 +0000
URL: https://github.com/rspamd/rspamd/commit/4fe834a29f6592cfd3a11a4c231b5c9ca13cb49d (HEAD -> master)
[Minor] Disable ipv6 check via bind to a random port
Issue: #3221
---
src/libutil/addr.c | 37 +++++++++++++++++++++----------------
1 file 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);
}
}
}
More information about the Commits
mailing list