Merge pull request #18896 from poettering/no-localhost-ipv6
if ipv6 is turned off, don't synthesize localhost as ::1 ever
This commit is contained in:
+41
-2
@@ -31,6 +31,7 @@
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "sysctl-util.h"
|
||||
#include "user-util.h"
|
||||
#include "utf8.h"
|
||||
|
||||
@@ -277,10 +278,48 @@ const char* socket_address_get_path(const SocketAddress *a) {
|
||||
}
|
||||
|
||||
bool socket_ipv6_is_supported(void) {
|
||||
if (access("/proc/net/if_inet6", F_OK) != 0)
|
||||
static int cached = -1;
|
||||
|
||||
if (cached < 0) {
|
||||
|
||||
if (access("/proc/net/if_inet6", F_OK) < 0) {
|
||||
|
||||
if (errno != ENOENT) {
|
||||
log_debug_errno(errno, "Unexpected error when checking whether /proc/net/if_inet6 exists: %m");
|
||||
return false;
|
||||
}
|
||||
|
||||
cached = false;
|
||||
} else
|
||||
cached = true;
|
||||
}
|
||||
|
||||
return cached;
|
||||
}
|
||||
|
||||
bool socket_ipv6_is_enabled(void) {
|
||||
_cleanup_free_ char *v;
|
||||
int r;
|
||||
|
||||
/* Much like socket_ipv6_is_supported(), but also checks that the sysctl that disables IPv6 on all
|
||||
* interfaces isn't turned on */
|
||||
|
||||
if (!socket_ipv6_is_supported())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
r = sysctl_read_ip_property(AF_INET6, "all", "disable_ipv6", &v);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Unexpected error reading 'net.ipv6.conf.all.disable_ipv6' sysctl: %m");
|
||||
return true;
|
||||
}
|
||||
|
||||
r = parse_boolean(v);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to pare 'net.ipv6.conf.all.disable_ipv6' sysctl: %m");
|
||||
return true;
|
||||
}
|
||||
|
||||
return !r;
|
||||
}
|
||||
|
||||
bool socket_address_matches_fd(const SocketAddress *a, int fd) {
|
||||
|
||||
Reference in New Issue
Block a user