network: check whether ipv6 is enabled in sysctl
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 18 Feb 2019 06:00:15 +0000 (15:00 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 21 Feb 2019 01:55:13 +0000 (10:55 +0900)
Currently, the value is read only once.

Fixes #11711.

src/network/networkd-link.c
src/network/networkd-manager.c
src/network/networkd-manager.h

index 4bfa610..8bca042 100644 (file)
@@ -74,6 +74,9 @@ static bool link_dhcp6_enabled(Link *link) {
         if (link->network->bond)
                 return false;
 
+        if (manager_sysctl_ipv6_enabled(link->manager) == 0)
+                return false;
+
         return link->network->dhcp & ADDRESS_FAMILY_IPV6;
 }
 
@@ -143,6 +146,9 @@ static bool link_ipv6ll_enabled(Link *link) {
         if (link->network->bond)
                 return false;
 
+        if (manager_sysctl_ipv6_enabled(link->manager) == 0)
+                return false;
+
         return link->network->link_local & ADDRESS_FAMILY_IPV6;
 }
 
@@ -155,6 +161,9 @@ static bool link_ipv6_enabled(Link *link) {
         if (link->network->bridge || link->network->bond)
                 return false;
 
+        if (manager_sysctl_ipv6_enabled(link->manager) == 0)
+                return false;
+
         /* DHCPv6 client will not be started if no IPv6 link-local address is configured. */
         return link_ipv6ll_enabled(link) || network_has_static_ipv6_addresses(link->network);
 }
@@ -234,6 +243,9 @@ static bool link_ipv6_forward_enabled(Link *link) {
         if (link->network->ip_forward == _ADDRESS_FAMILY_BOOLEAN_INVALID)
                 return false;
 
+        if (manager_sysctl_ipv6_enabled(link->manager) == 0)
+                return false;
+
         return link->network->ip_forward & ADDRESS_FAMILY_IPV6;
 }
 
index b7e15a5..edb5801 100644 (file)
@@ -24,6 +24,7 @@
 #include "path-util.h"
 #include "set.h"
 #include "strv.h"
+#include "sysctl-util.h"
 #include "tmpfile-util.h"
 #include "virt.h"
 
@@ -1379,6 +1380,8 @@ int manager_new(Manager **ret) {
         if (!m->state_file)
                 return -ENOMEM;
 
+        m->sysctl_ipv6_enabled = -1;
+
         r = sd_event_default(&m->event);
         if (r < 0)
                 return r;
@@ -1877,3 +1880,18 @@ int manager_request_product_uuid(Manager *m, Link *link) {
 
         return 0;
 }
+
+int manager_sysctl_ipv6_enabled(Manager *manager) {
+        _cleanup_free_ char *value = NULL;
+        int r;
+
+        if (manager->sysctl_ipv6_enabled >= 0)
+                return manager->sysctl_ipv6_enabled;
+
+        r = sysctl_read_ip_property(AF_INET6, "all", "disable_ipv6", &value);
+        if (r < 0)
+                return log_warning_errno(r, "Failed to read net.ipv6.conf.all.disable_ipv6 sysctl property: %m");
+
+        manager->sysctl_ipv6_enabled = value[0] == '0';
+        return manager->sysctl_ipv6_enabled;
+}
index 33f80bf..35ab6be 100644 (file)
@@ -56,6 +56,8 @@ struct Manager {
         Set *rules;
         Set *rules_foreign;
         Set *rules_saved;
+
+        int sysctl_ipv6_enabled;
 };
 
 extern const sd_bus_vtable manager_vtable[];
@@ -93,4 +95,6 @@ Link *manager_dhcp6_prefix_get(Manager *m, struct in6_addr *addr);
 int manager_dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link);
 int manager_dhcp6_prefix_remove_all(Manager *m, Link *link);
 
+int manager_sysctl_ipv6_enabled(Manager *manager);
+
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);