]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: Add DHCPv6 as a configuration option to radv prefixes
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 4 Jan 2018 13:11:39 +0000 (15:11 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 4 Jan 2018 13:22:43 +0000 (15:22 +0200)
The Network section IPv6PrefixDelegation= option takes two new
configuration values, namely "static" and "dhcpv6" in addition
to boolean yes and no values. Static prefixes in IPv6Prefix
sections are used when IPv6PrefixDelegation= option contains
"static", and DHCPv6 is queried for prefixes when the option
contains "dhcpv6". Both DHCPv6 and static prefixes are used when
the option contains a boolean true value. The default value is
false as before, meaning no prefixes are delegated.

src/network/networkd-link.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.h
src/network/networkd-radv.c
src/network/networkd-radv.h

index 60ac980ad93666617343d61b7160a64f1d94a001..8e1f0fe8196cd4df55f05c24766ae6a7c6f6387d 100644 (file)
@@ -129,7 +129,7 @@ static bool link_radv_enabled(Link *link) {
         if (!link_ipv6ll_enabled(link))
                 return false;
 
-        return link->network->router_prefix_delegation;
+        return (link->network->router_prefix_delegation != RADV_PREFIX_DELEGATION_NONE);
 }
 
 static bool link_lldp_rx_enabled(Link *link) {
index e1990b03024feb0b8998655a0ae8f0ac8af9cea7..816dbaf7096f4d87b97495a3aebb245b3d64fb66 100644 (file)
@@ -156,7 +156,7 @@ BridgeFDB.VLANId,                       config_parse_fdb_vlan_id,
 BridgeVLAN.PVID,                        config_parse_brvlan_pvid,                       0,                             0
 BridgeVLAN.VLAN,                        config_parse_brvlan_vlan,                       0,                             0
 BridgeVLAN.EgressUntagged,              config_parse_brvlan_untagged,                   0,                             0
-Network.IPv6PrefixDelegation,           config_parse_bool,                              0,                             offsetof(Network, router_prefix_delegation)
+Network.IPv6PrefixDelegation,           config_parse_router_prefix_delegation,          0,                             0
 IPv6PrefixDelegation.RouterLifetimeSec, config_parse_sec,                               0,                             offsetof(Network, router_lifetime_usec)
 IPv6PrefixDelegation.Managed,           config_parse_bool,                              0,                             offsetof(Network, router_managed)
 IPv6PrefixDelegation.OtherInformation,  config_parse_bool,                              0,                             offsetof(Network, router_other_information)
index c45f0f72f518af0492d9f4fcafeb59b416c6a4d6..ad56fc5f68054541696c2ebcdc78b656ca1de781 100644 (file)
@@ -86,6 +86,13 @@ typedef struct DUID {
         uint8_t raw_data[MAX_DUID_LEN];
 } DUID;
 
+typedef enum RADVPrefixDelegation {
+        RADV_PREFIX_DELEGATION_NONE,
+        RADV_PREFIX_DELEGATION_STATIC,
+        RADV_PREFIX_DELEGATION_DHCP6,
+        RADV_PREFIX_DELEGATION_BOTH,
+} RADVPrefixDelegation;
+
 typedef struct NetworkConfigSection {
         unsigned line;
         char filename[];
@@ -165,7 +172,7 @@ struct Network {
         bool ipv4ll_route;
 
         /* IPv6 prefix delegation support */
-        bool router_prefix_delegation;
+        RADVPrefixDelegation router_prefix_delegation;
         usec_t router_lifetime_usec;
         uint8_t router_preference;
         bool router_managed;
index c72acc9b8247811dd3f20d2e9a72f2c60556189b..a7e66f575b0401ab11cf9f18d543a42159a7267c 100644 (file)
 #include "sd-radv.h"
 #include "string-util.h"
 
+int config_parse_router_prefix_delegation(const char *unit,
+                                          const char *filename,
+                                          unsigned line,
+                                          const char *section,
+                                          unsigned section_line,
+                                         const char *lvalue,
+                                          int ltype,
+                                          const char *rvalue,
+                                          void *data,
+                                          void *userdata) {
+        Network *network = userdata;
+        int d;
+
+        assert(filename);
+        assert(section);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        if (streq(rvalue, "static"))
+                network->router_prefix_delegation = RADV_PREFIX_DELEGATION_STATIC;
+        else if (streq(rvalue, "dhcpv6"))
+                network->router_prefix_delegation = RADV_PREFIX_DELEGATION_DHCP6;
+        else {
+                d = parse_boolean(rvalue);
+                if (d > 0)
+                        network->router_prefix_delegation = RADV_PREFIX_DELEGATION_BOTH;
+                else
+                        network->router_prefix_delegation = RADV_PREFIX_DELEGATION_NONE;
+
+                if (d < 0)
+                        log_syntax(unit, LOG_ERR, filename, line, -EINVAL, "Router prefix delegation '%s' is invalid, ignoring assignment: %m", rvalue);
+        }
+
+        return 0;
+}
+
 int config_parse_router_preference(const char *unit,
                                    const char *filename,
                                    unsigned line,
@@ -461,10 +498,14 @@ int radv_configure(Link *link) {
                         return r;
         }
 
-        LIST_FOREACH(prefixes, p, link->network->static_prefixes) {
-                r = sd_radv_add_prefix(link->radv, p->radv_prefix);
-                if (r != -EEXIST && r < 0)
-                        return r;
+        if (IN_SET(link->network->router_prefix_delegation,
+                   RADV_PREFIX_DELEGATION_STATIC,
+                   RADV_PREFIX_DELEGATION_BOTH)) {
+                LIST_FOREACH(prefixes, p, link->network->static_prefixes) {
+                        r = sd_radv_add_prefix(link->radv, p->radv_prefix);
+                        if (r != -EEXIST && r < 0)
+                                return r;
+                }
         }
 
         return radv_emit_dns(link);
index a31a9f0e155f3b0a0b0a1f4dfbd21be2d9e0c745..22a169d263752ca2a3a4ac9fb27942db3b3dee69 100644 (file)
@@ -42,6 +42,7 @@ int prefix_new_static(Network *network, const char *filename, unsigned section,
 DEFINE_TRIVIAL_CLEANUP_FUNC(Prefix*, prefix_free);
 #define _cleanup_prefix_free_ _cleanup_(prefix_freep)
 
+int config_parse_router_prefix_delegation(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_router_preference(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_prefix(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_prefix_flags(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);