]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: rename settings about DHCPv6 Prefix Delegation 16585/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 28 Jul 2020 20:50:04 +0000 (05:50 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 28 Jul 2020 20:50:08 +0000 (05:50 +0900)
Closes #16602.

man/systemd.network.xml
src/network/networkd-dhcp6.c
src/network/networkd-dhcp6.h
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h
src/network/networkd-radv.c
src/network/networkd-radv.h
test/fuzz/fuzz-network-parser/directives.network

index 0b0c751e91322aea966246f1a0e96efe48da1a28..77986192d4bce846f5bc222f45683e00eeb3c13f 100644 (file)
           <literal>false</literal>. See the [IPv6PrefixDelegation] and the [IPv6Prefix] sections for more
           configuration options.</para></listitem>
         </varlistentry>
-        <varlistentry>
-          <term><varname>IPv6PDSubnetId=</varname></term>
-          <listitem><para>Configure a specific subnet ID on the interface from a (previously) received prefix delegation.
-          You can either set "auto" (the default) or a specific subnet ID
-          (as defined in <ulink url="https://tools.ietf.org/html/rfc4291#section-2.5.4">RFC 4291</ulink>, section 2.5.4),
-          in which case the allowed value is hexadecimal, from 0 to 0x7fffffffffffffff inclusive.
-          This option is only effective when used together with <varname>IPv6PrefixDelegation=</varname>
-          and the corresponding configuration on the upstream interface.
-          </para></listitem>
-        </varlistentry>
         <varlistentry>
           <term><varname>IPv6MTUBytes=</varname></term>
           <listitem><para>Configures IPv6 maximum transmission unit (MTU).
           </listitem>
         </varlistentry>
 
-        <varlistentry>
-          <term><varname>AssignAcquiredDelegatedPrefixAddress=</varname></term>
-          <listitem>
-            <para>Takes a boolean. Specifies whether to add an address from the delegated prefixes which are received
-            from the WAN interface by the <varname>IPv6PrefixDelegation=</varname>. When true (on LAN interfce), the EUI-64
-            algorithm will be used to form an interface identifier from the delegated prefixes. Defaults to true.</para>
-          </listitem>
-        </varlistentry>
-
-        <varlistentry>
-        <term><varname>AssignAcquiredDelegatedPrefixToken=</varname></term>
-          <listitem>
-            <para>Specifies an optional address generation mode for <varname>AssignAcquiredDelegatedPrefixAddress=</varname>.
-            Takes an IPv6 address. When set, the lower bits of the supplied address are combined with the upper bits of a
-            delegatad prefix received from the WAN interface by the <varname>IPv6PrefixDelegation=</varname> prefixes to
-            form a complete address.</para>
-          </listitem>
-        </varlistentry>
-
         <varlistentry>
           <term><varname>PrefixDelegationHint=</varname></term>
           <listitem>
       </variablelist>
   </refsect1>
 
+  <refsect1>
+    <title>[DHCPv6PrefixDelegation] Section Options</title>
+    <para>The [DHCPv6PrefixDelegation] section configures delegated prefix assigned by DHCPv6 server.
+    The settings in this section are used only when <varname>IPv6PrefixDelegation=</varname> setting is
+    enabled, or set to <literal>dhcp6</literal>.</para>
+
+    <variablelist class='network-directives'>
+      <varlistentry>
+        <term><varname>SubnetId=</varname></term>
+        <listitem>
+          <para>Configure a specific subnet ID on the interface from a (previously) received prefix
+          delegation. You can either set "auto" (the default) or a specific subnet ID (as defined in
+          <ulink url="https://tools.ietf.org/html/rfc4291#section-2.5.4">RFC 4291</ulink>, section
+          2.5.4), in which case the allowed value is hexadecimal, from 0 to 0x7fffffffffffffff
+          inclusive. This option is only effective when used together with
+          <varname>IPv6PrefixDelegation=</varname> and the corresponding configuration on the upstream
+          interface.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><varname>Assign=</varname></term>
+        <listitem>
+          <para>Takes a boolean. Specifies whether to add an address from the delegated prefixes which
+          are received from the WAN interface by the <varname>IPv6PrefixDelegation=</varname>. When
+          true (on LAN interfce), the EUI-64 algorithm will be used to form an interface identifier
+          from the delegated prefixes. Defaults to true.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><varname>Token=</varname></term>
+        <listitem>
+          <para>Specifies an optional address generation mode for <varname>Assign=</varname>. Takes an
+          IPv6 address. When set, the lower bits of the supplied address are combined with the upper
+          bits of a delegatad prefix received from the WAN interface by the
+          <varname>IPv6PrefixDelegation=</varname> prefixes to form a complete address.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
   <refsect1>
     <title>[IPv6AcceptRA] Section Options</title>
       <para>The [IPv6AcceptRA] section configures the IPv6 Router Advertisement (RA) client, if it is enabled
index e87d9d1e7c00b6889a1fa1b535fbacd8a38c9244..d671284b001906975a8e0ec4a421217838dd804f 100644 (file)
@@ -367,7 +367,7 @@ static int dhcp6_set_pd_address(Link *link,
         assert(link->network);
         assert(prefix);
 
-        if (!link->network->dhcp6_pd_assign_prefix)
+        if (!link->network->dhcp6_pd_assign)
                 return 0;
 
         r = address_new(&address);
@@ -376,8 +376,8 @@ static int dhcp6_set_pd_address(Link *link,
 
         address->in_addr = *prefix;
 
-        if (!in_addr_is_null(AF_INET6, &link->network->dhcp6_delegation_prefix_token))
-                memcpy(address->in_addr.in6.s6_addr + 8, link->network->dhcp6_delegation_prefix_token.in6.s6_addr + 8, 8);
+        if (!in_addr_is_null(AF_INET6, &link->network->dhcp6_pd_token))
+                memcpy(address->in_addr.in6.s6_addr + 8, link->network->dhcp6_pd_token.in6.s6_addr + 8, 8);
         else {
                 r = generate_ipv6_eui_64_address(link, &address->in_addr.in6);
                 if (r < 0)
@@ -437,7 +437,7 @@ static bool link_has_preferred_subnet_id(Link *link) {
         if (!link->network)
                 return false;
 
-        return link->network->router_prefix_subnet_id >= 0;
+        return link->network->dhcp6_pd_subnet_id >= 0;
 }
 
 static int dhcp6_get_preferred_delegated_prefix(
@@ -461,7 +461,7 @@ static int dhcp6_get_preferred_delegated_prefix(
         prefix = *masked_pd_prefix;
 
         if (link_has_preferred_subnet_id(link)) {
-                uint64_t subnet_id = link->network->router_prefix_subnet_id;
+                uint64_t subnet_id = link->network->dhcp6_pd_subnet_id;
 
                 /* If the link has a preference for a particular subnet id try to allocate that */
                 if (subnet_id >= n_prefixes)
@@ -1556,7 +1556,18 @@ int config_parse_dhcp6_mud_url(
         return free_and_replace(network->dhcp6_mudurl, unescaped);
 }
 
-int config_parse_dhcp6_delegated_prefix_token(
+DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode,
+                         "Failed to parse WithoutRA= setting");
+
+static const char* const dhcp6_client_start_mode_table[_DHCP6_CLIENT_START_MODE_MAX] = {
+        [DHCP6_CLIENT_START_MODE_NO]                  = "no",
+        [DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST] = "information-request",
+        [DHCP6_CLIENT_START_MODE_SOLICIT]             = "solicit",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(dhcp6_client_start_mode, DHCP6ClientStartMode);
+
+int config_parse_dhcp6_pd_subnet_id(
                 const char *unit,
                 const char *filename,
                 unsigned line,
@@ -1568,7 +1579,8 @@ int config_parse_dhcp6_delegated_prefix_token(
                 void *data,
                 void *userdata) {
 
-        Network *network = data;
+        int64_t *p = data;
+        uint64_t t;
         int r;
 
         assert(filename);
@@ -1576,34 +1588,69 @@ int config_parse_dhcp6_delegated_prefix_token(
         assert(rvalue);
         assert(data);
 
-        if (isempty(rvalue)) {
-                network->dhcp6_delegation_prefix_token = IN_ADDR_NULL;
+        if (isempty(rvalue) || streq(rvalue, "auto")) {
+                *p = -1;
                 return 0;
         }
 
-        r = in_addr_from_string(AF_INET6, rvalue, &network->dhcp6_delegation_prefix_token);
+        r = safe_atoux64(rvalue, &t);
         if (r < 0) {
                 log_syntax(unit, LOG_WARNING, filename, line, r,
-                           "Failed to parse DHCPv6 %s, ignoring: %s", lvalue, rvalue);
+                           "Failed to parse %s=, ignoring assignment: %s",
+                           lvalue, rvalue);
                 return 0;
         }
-
-        if (in_addr_is_null(AF_INET6, &network->dhcp6_delegation_prefix_token)) {
+        if (t > INT64_MAX) {
                 log_syntax(unit, LOG_WARNING, filename, line, 0,
-                           "DHCPv6 %s cannot be the ANY address, ignoring: %s", lvalue, rvalue);
+                           "Invalid subnet id '%s', ignoring assignment.",
+                           rvalue);
                 return 0;
         }
 
+        *p = (int64_t) t;
+
         return 0;
 }
 
-DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode,
-                         "Failed to parse WithoutRA= setting");
+int config_parse_dhcp6_pd_token(
+                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) {
 
-static const char* const dhcp6_client_start_mode_table[_DHCP6_CLIENT_START_MODE_MAX] = {
-        [DHCP6_CLIENT_START_MODE_NO]                  = "no",
-        [DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST] = "information-request",
-        [DHCP6_CLIENT_START_MODE_SOLICIT]             = "solicit",
-};
+        union in_addr_union *addr = data, tmp;
+        int r;
 
-DEFINE_STRING_TABLE_LOOKUP(dhcp6_client_start_mode, DHCP6ClientStartMode);
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        if (isempty(rvalue)) {
+                *addr = IN_ADDR_NULL;
+                return 0;
+        }
+
+        r = in_addr_from_string(AF_INET6, rvalue, &tmp);
+        if (r < 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, r,
+                           "Failed to parse DHCPv6 Prefix Delegation token, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        if (in_addr_is_null(AF_INET6, &tmp)) {
+                log_syntax(unit, LOG_WARNING, filename, line, 0,
+                           "DHCPv6 Prefix Delegation token cannot be the ANY address, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        *addr = tmp;
+
+        return 0;
+}
index fa44a2eb5281bbbbf74e95c578fa518a534d01a0..214456096da7f9440a3ade1d2ab64bd37ec34640 100644 (file)
@@ -34,8 +34,9 @@ int dhcp6_request_prefix_delegation(Link *link);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_hint);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_mud_url);
-CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_delegated_prefix_token);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_client_start_mode);
+CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_subnet_id);
+CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_token);
 
 const char* dhcp6_client_start_mode_to_string(DHCP6ClientStartMode i) _const_;
 DHCP6ClientStartMode dhcp6_client_start_mode_from_string(const char *s) _pure_;
index f3c578cbb4c8ca61e2c972ab8036d290643ec524..3f1652b1904ffa622973dd91f29a97701d347880 100644 (file)
@@ -213,8 +213,6 @@ DHCPv6.UserClass,                            config_parse_dhcp_user_class,
 DHCPv6.VendorClass,                          config_parse_dhcp_vendor_class,                           0,                             offsetof(Network, dhcp6_vendor_class)
 DHCPv6.SendVendorOption,                     config_parse_dhcp_send_option,                            AF_INET6,                      offsetof(Network, dhcp6_client_send_vendor_options)
 DHCPv6.ForceDHCPv6PDOtherInformation,        config_parse_bool,                                        0,                             offsetof(Network, dhcp6_force_pd_other_information)
-DHCPv6.AssignAcquiredDelegatedPrefixAddress, config_parse_bool,                                        0,                             offsetof(Network, dhcp6_pd_assign_prefix)
-DHCPv6.AssignAcquiredDelegatedPrefixToken,   config_parse_dhcp6_delegated_prefix_token,                0,                             0
 DHCPv6.PrefixDelegationHint,                 config_parse_dhcp6_pd_hint,                               0,                             0
 DHCPv6.WithoutRA,                            config_parse_dhcp6_client_start_mode,                     0,                             offsetof(Network, dhcp6_without_ra)
 DHCPv6.SendOption,                           config_parse_dhcp_send_option,                            AF_INET6,                      offsetof(Network, dhcp6_client_send_options)
@@ -271,7 +269,9 @@ BridgeVLAN.PVID,                             config_parse_brvlan_pvid,
 BridgeVLAN.VLAN,                             config_parse_brvlan_vlan,                                 0,                             0
 BridgeVLAN.EgressUntagged,                   config_parse_brvlan_untagged,                             0,                             0
 Network.IPv6PrefixDelegation,                config_parse_router_prefix_delegation,                    0,                             offsetof(Network, router_prefix_delegation)
-Network.IPv6PDSubnetId,                      config_parse_router_prefix_subnet_id,                     0,                             0
+DHCPv6PrefixDelegation.SubnetId,             config_parse_dhcp6_pd_subnet_id,                          0,                             offsetof(Network, dhcp6_pd_subnet_id)
+DHCPv6PrefixDelegation.Assign,               config_parse_bool,                                        0,                             offsetof(Network, dhcp6_pd_assign)
+DHCPv6PrefixDelegation.Token,                config_parse_dhcp6_pd_token,                              0,                             offsetof(Network, dhcp6_pd_token)
 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 591d63c6b2c081394bff7c1311535899ba65dd45..694d9b0c3a04217ea2835cc39edb099523eb78a9 100644 (file)
@@ -420,7 +420,8 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
                 .dhcp6_use_ntp = true,
                 .dhcp6_use_dns = true,
 
-                .dhcp6_pd_assign_prefix = true,
+                .dhcp6_pd_subnet_id = -1,
+                .dhcp6_pd_assign = true,
 
                 .dhcp_server_emit[SD_DHCP_LEASE_DNS].emit = true,
                 .dhcp_server_emit[SD_DHCP_LEASE_NTP].emit = true,
@@ -429,7 +430,6 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
                 .dhcp_server_emit_router = true,
                 .dhcp_server_emit_timezone = true,
 
-                .router_prefix_subnet_id = -1,
                 .router_emit_dns = true,
                 .router_emit_domains = true,
 
index 4c3c2bdd74317ef4f9bdee9bb5044c61f84c42d8..5dcb3c548bcc74c8ec59e82f0433c01c84bbc8c0 100644 (file)
@@ -184,7 +184,6 @@ struct Network {
 
         /* IPv6 prefix delegation support */
         RADVPrefixDelegation router_prefix_delegation;
-        int64_t router_prefix_subnet_id;
         usec_t router_lifetime_usec;
         uint8_t router_preference;
         bool router_managed;
@@ -198,8 +197,11 @@ struct Network {
         bool dhcp6_force_pd_other_information; /* Start DHCPv6 PD also when 'O'
                                                   RA flag is set, see RFC 7084,
                                                   WPD-4 */
-        bool dhcp6_pd_assign_prefix;
-        union in_addr_union dhcp6_delegation_prefix_token;
+
+        /* DHCPv6 Prefix Delegation support */
+        int64_t dhcp6_pd_subnet_id;
+        bool dhcp6_pd_assign;
+        union in_addr_union dhcp6_pd_token;
 
         /* Bridge Support */
         int use_bpdu;
index dbc8fd8074928baca8f645e44dd5af8a17666b99..e0c490babab6a1e6798f062d6bf0876912ca9b4c 100644 (file)
@@ -866,46 +866,3 @@ int config_parse_router_preference(const char *unit,
 
         return 0;
 }
-
-int config_parse_router_prefix_subnet_id(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;
-        uint64_t t;
-        int r;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-        assert(data);
-
-        if (isempty(rvalue) || streq(rvalue, "auto")) {
-                network->router_prefix_subnet_id = -1;
-                return 0;
-        }
-
-        r = safe_atoux64(rvalue, &t);
-        if (r < 0) {
-                log_syntax(unit, LOG_WARNING, filename, line, r,
-                           "Failed to parse %s=, ignoring assignment: %s",
-                           lvalue, rvalue);
-                return 0;
-        }
-        if (t > INT64_MAX) {
-                log_syntax(unit, LOG_WARNING, filename, line, r,
-                           "Invalid subnet id '%s', ignoring assignment.",
-                           rvalue);
-                return 0;
-        }
-
-        network->router_prefix_subnet_id = (int64_t)t;
-
-        return 0;
-}
index 73143e74931420b7d94badf41d34852d9e42b22c..496ef97adcf6cca844e2a0b821138d39e78ae243 100644 (file)
@@ -60,7 +60,6 @@ RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_;
 
 CONFIG_PARSER_PROTOTYPE(config_parse_router_prefix_delegation);
 CONFIG_PARSER_PROTOTYPE(config_parse_router_preference);
-CONFIG_PARSER_PROTOTYPE(config_parse_router_prefix_subnet_id);
 CONFIG_PARSER_PROTOTYPE(config_parse_prefix);
 CONFIG_PARSER_PROTOTYPE(config_parse_prefix_flags);
 CONFIG_PARSER_PROTOTYPE(config_parse_prefix_lifetime);
index aa04c1192a3015f0834b3ea5c984b827811489a3..5d804707197f48fd0c47f087c57adde27ea90b9d 100644 (file)
@@ -130,10 +130,12 @@ SendOption=
 RequestOptions=
 UserClass=
 VendorClass=
-AssignAcquiredDelegatedPrefixAddress=
-AssignAcquiredDelegatedPrefixToken=
 SendVendorOption=
 RouteMetric=
+[DHCPv6PrefixDelegation]
+SubnetId=
+Assign=
+Token=
 [Route]
 Destination=
 Protocol=
@@ -203,7 +205,6 @@ NTP=
 DHCP=
 Domains=
 IPv6PrefixDelegation=
-IPv6PDSubnetId=
 VLAN=
 DHCPServer=
 BindCarrier=