]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-address.c
network: ignore requested ipv6 addresses when ipv6 is disabled by sysctl
[thirdparty/systemd.git] / src / network / networkd-address.c
index 1a9ba4223cd93b187ea196674afe8f092737c426..7fe99bc4853216b1329db4a9f25ac01d1223d78d 100644 (file)
@@ -5,6 +5,7 @@
 #include "alloc-util.h"
 #include "conf-parser.h"
 #include "firewall-util.h"
+#include "memory-util.h"
 #include "missing_network.h"
 #include "netlink-util.h"
 #include "networkd-address.h"
@@ -15,7 +16,6 @@
 #include "string-util.h"
 #include "strv.h"
 #include "utf8.h"
-#include "util.h"
 
 #define ADDRESSES_PER_LINK_MAX 2048U
 #define STATIC_ADDRESSES_PER_NETWORK_MAX 1024U
@@ -490,7 +490,7 @@ int address_remove(
 }
 
 static int address_acquire(Link *link, Address *original, Address **ret) {
-        union in_addr_union in_addr = {};
+        union in_addr_union in_addr = IN_ADDR_NULL;
         struct in_addr broadcast = {};
         _cleanup_(address_freep) Address *na = NULL;
         int r;
@@ -566,6 +566,11 @@ int address_configure(
         assert(link->manager->rtnl);
         assert(callback);
 
+        if (address->family == AF_INET6 && manager_sysctl_ipv6_enabled(link->manager) == 0) {
+                log_link_warning(link, "An IPv6 address is requested, but IPv6 is disabled by sysctl, ignoring.");
+                return 0;
+        }
+
         /* If this is a new address, then refuse adding more than the limit */
         if (address_get(link, address->family, &address->in_addr, address->prefixlen, NULL) <= 0 &&
             set_size(link->addresses) >= ADDRESSES_PER_LINK_MAX)
@@ -665,7 +670,7 @@ int address_configure(
                 return log_link_error_errno(link, r, "Could not add address: %m");
         }
 
-        return 0;
+        return 1;
 }
 
 int config_parse_broadcast(
@@ -787,7 +792,7 @@ int config_parse_address(const char *unit,
         else
                 n->in_addr_peer = buffer;
 
-        if (n->family == AF_INET && n->broadcast.s_addr == 0)
+        if (n->family == AF_INET && n->broadcast.s_addr == 0 && n->prefixlen <= 30)
                 n->broadcast.s_addr = n->in_addr.in.s_addr | htonl(0xfffffffflu >> n->prefixlen);
 
         n = NULL;