Skip to content

Commit 99e015e

Browse files
committed
network: rename settings about DHCPv6 Prefix Delegation
Closes systemd#16602.
1 parent 61c0ef4 commit 99e015e

File tree

9 files changed

+127
-107
lines changed

9 files changed

+127
-107
lines changed

man/systemd.network.xml

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -809,16 +809,6 @@
809809
<literal>false</literal>. See the [IPv6PrefixDelegation] and the [IPv6Prefix] sections for more
810810
configuration options.</para></listitem>
811811
</varlistentry>
812-
<varlistentry>
813-
<term><varname>IPv6PDSubnetId=</varname></term>
814-
<listitem><para>Configure a specific subnet ID on the interface from a (previously) received prefix delegation.
815-
You can either set "auto" (the default) or a specific subnet ID
816-
(as defined in <ulink url="https://tools.ietf.org/html/rfc4291#section-2.5.4">RFC 4291</ulink>, section 2.5.4),
817-
in which case the allowed value is hexadecimal, from 0 to 0x7fffffffffffffff inclusive.
818-
This option is only effective when used together with <varname>IPv6PrefixDelegation=</varname>
819-
and the corresponding configuration on the upstream interface.
820-
</para></listitem>
821-
</varlistentry>
822812
<varlistentry>
823813
<term><varname>IPv6MTUBytes=</varname></term>
824814
<listitem><para>Configures IPv6 maximum transmission unit (MTU).
@@ -1893,25 +1883,6 @@
18931883
</listitem>
18941884
</varlistentry>
18951885

1896-
<varlistentry>
1897-
<term><varname>AssignAcquiredDelegatedPrefixAddress=</varname></term>
1898-
<listitem>
1899-
<para>Takes a boolean. Specifies whether to add an address from the delegated prefixes which are received
1900-
from the WAN interface by the <varname>IPv6PrefixDelegation=</varname>. When true (on LAN interfce), the EUI-64
1901-
algorithm will be used to form an interface identifier from the delegated prefixes. Defaults to true.</para>
1902-
</listitem>
1903-
</varlistentry>
1904-
1905-
<varlistentry>
1906-
<term><varname>AssignAcquiredDelegatedPrefixToken=</varname></term>
1907-
<listitem>
1908-
<para>Specifies an optional address generation mode for <varname>AssignAcquiredDelegatedPrefixAddress=</varname>.
1909-
Takes an IPv6 address. When set, the lower bits of the supplied address are combined with the upper bits of a
1910-
delegatad prefix received from the WAN interface by the <varname>IPv6PrefixDelegation=</varname> prefixes to
1911-
form a complete address.</para>
1912-
</listitem>
1913-
</varlistentry>
1914-
19151886
<varlistentry>
19161887
<term><varname>PrefixDelegationHint=</varname></term>
19171888
<listitem>
@@ -1966,6 +1937,48 @@
19661937
</variablelist>
19671938
</refsect1>
19681939

1940+
<refsect1>
1941+
<title>[DHCPv6PrefixDelegation] Section Options</title>
1942+
<para>The [DHCPv6PrefixDelegation] section configures delegated prefix assigned by DHCPv6 server.
1943+
The settings in this section are used only when <varname>IPv6PrefixDelegation=</varname> setting is
1944+
enabled, or set to <literal>dhcp6</literal>.</para>
1945+
1946+
<variablelist class='network-directives'>
1947+
<varlistentry>
1948+
<term><varname>SubnetId=</varname></term>
1949+
<listitem>
1950+
<para>Configure a specific subnet ID on the interface from a (previously) received prefix
1951+
delegation. You can either set "auto" (the default) or a specific subnet ID (as defined in
1952+
<ulink url="https://tools.ietf.org/html/rfc4291#section-2.5.4">RFC 4291</ulink>, section
1953+
2.5.4), in which case the allowed value is hexadecimal, from 0 to 0x7fffffffffffffff
1954+
inclusive. This option is only effective when used together with
1955+
<varname>IPv6PrefixDelegation=</varname> and the corresponding configuration on the upstream
1956+
interface.</para>
1957+
</listitem>
1958+
</varlistentry>
1959+
1960+
<varlistentry>
1961+
<term><varname>Assign=</varname></term>
1962+
<listitem>
1963+
<para>Takes a boolean. Specifies whether to add an address from the delegated prefixes which
1964+
are received from the WAN interface by the <varname>IPv6PrefixDelegation=</varname>. When
1965+
true (on LAN interfce), the EUI-64 algorithm will be used to form an interface identifier
1966+
from the delegated prefixes. Defaults to true.</para>
1967+
</listitem>
1968+
</varlistentry>
1969+
1970+
<varlistentry>
1971+
<term><varname>Token=</varname></term>
1972+
<listitem>
1973+
<para>Specifies an optional address generation mode for <varname>Assign=</varname>. Takes an
1974+
IPv6 address. When set, the lower bits of the supplied address are combined with the upper
1975+
bits of a delegatad prefix received from the WAN interface by the
1976+
<varname>IPv6PrefixDelegation=</varname> prefixes to form a complete address.</para>
1977+
</listitem>
1978+
</varlistentry>
1979+
</variablelist>
1980+
</refsect1>
1981+
19691982
<refsect1>
19701983
<title>[IPv6AcceptRA] Section Options</title>
19711984
<para>The [IPv6AcceptRA] section configures the IPv6 Router Advertisement (RA) client, if it is enabled

src/network/networkd-dhcp6.c

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static int dhcp6_set_pd_address(Link *link,
367367
assert(link->network);
368368
assert(prefix);
369369

370-
if (!link->network->dhcp6_pd_assign_prefix)
370+
if (!link->network->dhcp6_pd_assign)
371371
return 0;
372372

373373
r = address_new(&address);
@@ -376,8 +376,8 @@ static int dhcp6_set_pd_address(Link *link,
376376

377377
address->in_addr = *prefix;
378378

379-
if (!in_addr_is_null(AF_INET6, &link->network->dhcp6_delegation_prefix_token))
380-
memcpy(address->in_addr.in6.s6_addr + 8, link->network->dhcp6_delegation_prefix_token.in6.s6_addr + 8, 8);
379+
if (!in_addr_is_null(AF_INET6, &link->network->dhcp6_pd_token))
380+
memcpy(address->in_addr.in6.s6_addr + 8, link->network->dhcp6_pd_token.in6.s6_addr + 8, 8);
381381
else {
382382
r = generate_ipv6_eui_64_address(link, &address->in_addr.in6);
383383
if (r < 0)
@@ -437,7 +437,7 @@ static bool link_has_preferred_subnet_id(Link *link) {
437437
if (!link->network)
438438
return false;
439439

440-
return link->network->router_prefix_subnet_id >= 0;
440+
return link->network->dhcp6_pd_subnet_id >= 0;
441441
}
442442

443443
static int dhcp6_get_preferred_delegated_prefix(
@@ -461,7 +461,7 @@ static int dhcp6_get_preferred_delegated_prefix(
461461
prefix = *masked_pd_prefix;
462462

463463
if (link_has_preferred_subnet_id(link)) {
464-
uint64_t subnet_id = link->network->router_prefix_subnet_id;
464+
uint64_t subnet_id = link->network->dhcp6_pd_subnet_id;
465465

466466
/* If the link has a preference for a particular subnet id try to allocate that */
467467
if (subnet_id >= n_prefixes)
@@ -1556,7 +1556,18 @@ int config_parse_dhcp6_mud_url(
15561556
return free_and_replace(network->dhcp6_mudurl, unescaped);
15571557
}
15581558

1559-
int config_parse_dhcp6_delegated_prefix_token(
1559+
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode,
1560+
"Failed to parse WithoutRA= setting");
1561+
1562+
static const char* const dhcp6_client_start_mode_table[_DHCP6_CLIENT_START_MODE_MAX] = {
1563+
[DHCP6_CLIENT_START_MODE_NO] = "no",
1564+
[DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST] = "information-request",
1565+
[DHCP6_CLIENT_START_MODE_SOLICIT] = "solicit",
1566+
};
1567+
1568+
DEFINE_STRING_TABLE_LOOKUP(dhcp6_client_start_mode, DHCP6ClientStartMode);
1569+
1570+
int config_parse_dhcp6_pd_subnet_id(
15601571
const char *unit,
15611572
const char *filename,
15621573
unsigned line,
@@ -1568,42 +1579,78 @@ int config_parse_dhcp6_delegated_prefix_token(
15681579
void *data,
15691580
void *userdata) {
15701581

1571-
Network *network = data;
1582+
int64_t *p = data;
1583+
uint64_t t;
15721584
int r;
15731585

15741586
assert(filename);
15751587
assert(lvalue);
15761588
assert(rvalue);
15771589
assert(data);
15781590

1579-
if (isempty(rvalue)) {
1580-
network->dhcp6_delegation_prefix_token = IN_ADDR_NULL;
1591+
if (isempty(rvalue) || streq(rvalue, "auto")) {
1592+
*p = -1;
15811593
return 0;
15821594
}
15831595

1584-
r = in_addr_from_string(AF_INET6, rvalue, &network->dhcp6_delegation_prefix_token);
1596+
r = safe_atoux64(rvalue, &t);
15851597
if (r < 0) {
15861598
log_syntax(unit, LOG_WARNING, filename, line, r,
1587-
"Failed to parse DHCPv6 %s, ignoring: %s", lvalue, rvalue);
1599+
"Failed to parse %s=, ignoring assignment: %s",
1600+
lvalue, rvalue);
15881601
return 0;
15891602
}
1590-
1591-
if (in_addr_is_null(AF_INET6, &network->dhcp6_delegation_prefix_token)) {
1603+
if (t > INT64_MAX) {
15921604
log_syntax(unit, LOG_WARNING, filename, line, 0,
1593-
"DHCPv6 %s cannot be the ANY address, ignoring: %s", lvalue, rvalue);
1605+
"Invalid subnet id '%s', ignoring assignment.",
1606+
rvalue);
15941607
return 0;
15951608
}
15961609

1610+
*p = (int64_t) t;
1611+
15971612
return 0;
15981613
}
15991614

1600-
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode,
1601-
"Failed to parse WithoutRA= setting");
1615+
int config_parse_dhcp6_pd_token(
1616+
const char *unit,
1617+
const char *filename,
1618+
unsigned line,
1619+
const char *section,
1620+
unsigned section_line,
1621+
const char *lvalue,
1622+
int ltype,
1623+
const char *rvalue,
1624+
void *data,
1625+
void *userdata) {
16021626

1603-
static const char* const dhcp6_client_start_mode_table[_DHCP6_CLIENT_START_MODE_MAX] = {
1604-
[DHCP6_CLIENT_START_MODE_NO] = "no",
1605-
[DHCP6_CLIENT_START_MODE_INFORMATION_REQUEST] = "information-request",
1606-
[DHCP6_CLIENT_START_MODE_SOLICIT] = "solicit",
1607-
};
1627+
union in_addr_union *addr = data, tmp;
1628+
int r;
16081629

1609-
DEFINE_STRING_TABLE_LOOKUP(dhcp6_client_start_mode, DHCP6ClientStartMode);
1630+
assert(filename);
1631+
assert(lvalue);
1632+
assert(rvalue);
1633+
assert(data);
1634+
1635+
if (isempty(rvalue)) {
1636+
*addr = IN_ADDR_NULL;
1637+
return 0;
1638+
}
1639+
1640+
r = in_addr_from_string(AF_INET6, rvalue, &tmp);
1641+
if (r < 0) {
1642+
log_syntax(unit, LOG_WARNING, filename, line, r,
1643+
"Failed to parse DHCPv6 Prefix Delegation token, ignoring: %s", rvalue);
1644+
return 0;
1645+
}
1646+
1647+
if (in_addr_is_null(AF_INET6, &tmp)) {
1648+
log_syntax(unit, LOG_WARNING, filename, line, 0,
1649+
"DHCPv6 Prefix Delegation token cannot be the ANY address, ignoring: %s", rvalue);
1650+
return 0;
1651+
}
1652+
1653+
*addr = tmp;
1654+
1655+
return 0;
1656+
}

src/network/networkd-dhcp6.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ int dhcp6_request_prefix_delegation(Link *link);
3434

3535
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_hint);
3636
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_mud_url);
37-
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_delegated_prefix_token);
3837
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_client_start_mode);
38+
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_subnet_id);
39+
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_token);
3940

4041
const char* dhcp6_client_start_mode_to_string(DHCP6ClientStartMode i) _const_;
4142
DHCP6ClientStartMode dhcp6_client_start_mode_from_string(const char *s) _pure_;

src/network/networkd-network-gperf.gperf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ DHCPv6.UserClass, config_parse_dhcp_user_class,
213213
DHCPv6.VendorClass, config_parse_dhcp_vendor_class, 0, offsetof(Network, dhcp6_vendor_class)
214214
DHCPv6.SendVendorOption, config_parse_dhcp_send_option, AF_INET6, offsetof(Network, dhcp6_client_send_vendor_options)
215215
DHCPv6.ForceDHCPv6PDOtherInformation, config_parse_bool, 0, offsetof(Network, dhcp6_force_pd_other_information)
216-
DHCPv6.AssignAcquiredDelegatedPrefixAddress, config_parse_bool, 0, offsetof(Network, dhcp6_pd_assign_prefix)
217-
DHCPv6.AssignAcquiredDelegatedPrefixToken, config_parse_dhcp6_delegated_prefix_token, 0, 0
218216
DHCPv6.PrefixDelegationHint, config_parse_dhcp6_pd_hint, 0, 0
219217
DHCPv6.WithoutRA, config_parse_dhcp6_client_start_mode, 0, offsetof(Network, dhcp6_without_ra)
220218
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,
271269
BridgeVLAN.VLAN, config_parse_brvlan_vlan, 0, 0
272270
BridgeVLAN.EgressUntagged, config_parse_brvlan_untagged, 0, 0
273271
Network.IPv6PrefixDelegation, config_parse_router_prefix_delegation, 0, offsetof(Network, router_prefix_delegation)
274-
Network.IPv6PDSubnetId, config_parse_router_prefix_subnet_id, 0, 0
272+
DHCPv6PrefixDelegation.SubnetId, config_parse_dhcp6_pd_subnet_id, 0, offsetof(Network, dhcp6_pd_subnet_id)
273+
DHCPv6PrefixDelegation.Assign, config_parse_bool, 0, offsetof(Network, dhcp6_pd_assign)
274+
DHCPv6PrefixDelegation.Token, config_parse_dhcp6_pd_token, 0, offsetof(Network, dhcp6_pd_token)
275275
IPv6PrefixDelegation.RouterLifetimeSec, config_parse_sec, 0, offsetof(Network, router_lifetime_usec)
276276
IPv6PrefixDelegation.Managed, config_parse_bool, 0, offsetof(Network, router_managed)
277277
IPv6PrefixDelegation.OtherInformation, config_parse_bool, 0, offsetof(Network, router_other_information)

src/network/networkd-network.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
420420
.dhcp6_use_ntp = true,
421421
.dhcp6_use_dns = true,
422422

423-
.dhcp6_pd_assign_prefix = true,
423+
.dhcp6_pd_subnet_id = -1,
424+
.dhcp6_pd_assign = true,
424425

425426
.dhcp_server_emit[SD_DHCP_LEASE_DNS].emit = true,
426427
.dhcp_server_emit[SD_DHCP_LEASE_NTP].emit = true,
@@ -429,7 +430,6 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
429430
.dhcp_server_emit_router = true,
430431
.dhcp_server_emit_timezone = true,
431432

432-
.router_prefix_subnet_id = -1,
433433
.router_emit_dns = true,
434434
.router_emit_domains = true,
435435

src/network/networkd-network.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ struct Network {
184184

185185
/* IPv6 prefix delegation support */
186186
RADVPrefixDelegation router_prefix_delegation;
187-
int64_t router_prefix_subnet_id;
188187
usec_t router_lifetime_usec;
189188
uint8_t router_preference;
190189
bool router_managed;
@@ -198,8 +197,11 @@ struct Network {
198197
bool dhcp6_force_pd_other_information; /* Start DHCPv6 PD also when 'O'
199198
RA flag is set, see RFC 7084,
200199
WPD-4 */
201-
bool dhcp6_pd_assign_prefix;
202-
union in_addr_union dhcp6_delegation_prefix_token;
200+
201+
/* DHCPv6 Prefix Delegation support */
202+
int64_t dhcp6_pd_subnet_id;
203+
bool dhcp6_pd_assign;
204+
union in_addr_union dhcp6_pd_token;
203205

204206
/* Bridge Support */
205207
int use_bpdu;

src/network/networkd-radv.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -866,46 +866,3 @@ int config_parse_router_preference(const char *unit,
866866

867867
return 0;
868868
}
869-
870-
int config_parse_router_prefix_subnet_id(const char *unit,
871-
const char *filename,
872-
unsigned line,
873-
const char *section,
874-
unsigned section_line,
875-
const char *lvalue,
876-
int ltype,
877-
const char *rvalue,
878-
void *data,
879-
void *userdata) {
880-
Network *network = userdata;
881-
uint64_t t;
882-
int r;
883-
884-
assert(filename);
885-
assert(lvalue);
886-
assert(rvalue);
887-
assert(data);
888-
889-
if (isempty(rvalue) || streq(rvalue, "auto")) {
890-
network->router_prefix_subnet_id = -1;
891-
return 0;
892-
}
893-
894-
r = safe_atoux64(rvalue, &t);
895-
if (r < 0) {
896-
log_syntax(unit, LOG_WARNING, filename, line, r,
897-
"Failed to parse %s=, ignoring assignment: %s",
898-
lvalue, rvalue);
899-
return 0;
900-
}
901-
if (t > INT64_MAX) {
902-
log_syntax(unit, LOG_WARNING, filename, line, r,
903-
"Invalid subnet id '%s', ignoring assignment.",
904-
rvalue);
905-
return 0;
906-
}
907-
908-
network->router_prefix_subnet_id = (int64_t)t;
909-
910-
return 0;
911-
}

src/network/networkd-radv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_;
6060

6161
CONFIG_PARSER_PROTOTYPE(config_parse_router_prefix_delegation);
6262
CONFIG_PARSER_PROTOTYPE(config_parse_router_preference);
63-
CONFIG_PARSER_PROTOTYPE(config_parse_router_prefix_subnet_id);
6463
CONFIG_PARSER_PROTOTYPE(config_parse_prefix);
6564
CONFIG_PARSER_PROTOTYPE(config_parse_prefix_flags);
6665
CONFIG_PARSER_PROTOTYPE(config_parse_prefix_lifetime);

test/fuzz/fuzz-network-parser/directives.network

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ SendOption=
130130
RequestOptions=
131131
UserClass=
132132
VendorClass=
133-
AssignAcquiredDelegatedPrefixAddress=
134-
AssignAcquiredDelegatedPrefixToken=
135133
SendVendorOption=
136134
RouteMetric=
135+
[DHCPv6PrefixDelegation]
136+
SubnetId=
137+
Assign=
138+
Token=
137139
[Route]
138140
Destination=
139141
Protocol=
@@ -203,7 +205,6 @@ NTP=
203205
DHCP=
204206
Domains=
205207
IPv6PrefixDelegation=
206-
IPv6PDSubnetId=
207208
VLAN=
208209
DHCPServer=
209210
BindCarrier=

0 commit comments

Comments
 (0)