diff options
author | Susant Sahani <ssahani@vmware.com> | 2020-02-27 13:32:43 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-03-01 00:49:19 +0900 |
commit | bd6379ec57c5a25b1cb4ae61771c8a12179ebd7a (patch) | |
tree | 9f79c8e9562e8906b6704eed5a2c3905cb9aca5f | |
parent | 34332af2bc6f63e5f35c7d71f4bfde993a6bd5f2 (diff) | |
download | systemd-bd6379ec57c5a25b1cb4ae61771c8a12179ebd7a.tar.gz |
network: introduce IPv6 prefix assign
Expose a boolean flag to automatically add an address from the delegated prefix to the interface
-rw-r--r-- | man/systemd.network.xml | 5 | ||||
-rw-r--r-- | src/network/networkd-link.c | 30 | ||||
-rw-r--r-- | src/network/networkd-network-gperf.gperf | 1 | ||||
-rw-r--r-- | src/network/networkd-radv.c | 40 | ||||
-rw-r--r-- | src/network/networkd-radv.h | 3 | ||||
-rw-r--r-- | test/fuzz/fuzz-network-parser/directives.network | 1 |
6 files changed, 80 insertions, 0 deletions
diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 209787bf1b..6c85917881 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -2033,6 +2033,11 @@ to 2592000 seconds (30 days).</para></listitem> </varlistentry> + <varlistentry> + <term><varname>Assign=</varname></term> + <listitem><para>Takes a boolean. When true, adds an address from the prefix. Default to false. + </para></listitem> + </varlistentry> </variablelist> </refsect1> diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 3dca043d99..ca8f9da280 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1222,6 +1222,7 @@ static int link_set_bridge_fdb(Link *link) { static int link_request_set_addresses(Link *link) { AddressLabel *label; Address *ad; + Prefix *p; int r; assert(link); @@ -1257,6 +1258,35 @@ static int link_request_set_addresses(Link *link) { link->address_messages++; } + if (IN_SET(link->network->router_prefix_delegation, + RADV_PREFIX_DELEGATION_STATIC, + RADV_PREFIX_DELEGATION_BOTH)) + LIST_FOREACH(prefixes, p, link->network->static_prefixes) { + _cleanup_(address_freep) Address *address = NULL; + + if (!p->assign) + continue; + + r = address_new(&address); + if (r < 0) + return log_link_error_errno(link, r, "Could not allocate address: %m"); + + r = sd_radv_prefix_get_prefix(p->radv_prefix, &address->in_addr.in6, &address->prefixlen); + if (r < 0) + return r; + + r = generate_ipv6_eui_64_address(link, &address->in_addr.in6); + if (r < 0) + return r; + + address->family = AF_INET6; + r = address_configure(address, link, address_handler, true); + if (r < 0) + return log_link_warning_errno(link, r, "Could not set addresses: %m"); + if (r > 0) + link->address_messages++; + } + LIST_FOREACH(labels, label, link->network->address_labels) { r = address_label_configure(label, link, NULL, false); if (r < 0) diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 134f1535d6..02be2f01aa 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -245,6 +245,7 @@ IPv6Prefix.OnLink, config_parse_prefix_flags, IPv6Prefix.AddressAutoconfiguration, config_parse_prefix_flags, 0, 0 IPv6Prefix.ValidLifetimeSec, config_parse_prefix_lifetime, 0, 0 IPv6Prefix.PreferredLifetimeSec, config_parse_prefix_lifetime, 0, 0 +IPv6Prefix.Assign, config_parse_prefix_assign, 0, 0 IPv6RoutePrefix.Route, config_parse_route_prefix, 0, 0 IPv6RoutePrefix.LifetimeSec, config_parse_route_prefix_lifetime, 0, 0 CAN.BitRate, config_parse_si_uint64, 0, offsetof(Network, can_bitrate) diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c index 620939e251..d9267dd805 100644 --- a/src/network/networkd-radv.c +++ b/src/network/networkd-radv.c @@ -319,6 +319,46 @@ int config_parse_prefix_lifetime(const char *unit, return 0; } +int config_parse_prefix_assign( + 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; + _cleanup_(prefix_free_or_set_invalidp) Prefix *p = NULL; + int r; + + assert(filename); + assert(section); + assert(lvalue); + assert(rvalue); + assert(data); + + r = prefix_new_static(network, filename, section_line, &p); + if (r < 0) + return r; + + r = parse_boolean(rvalue); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse %s=, ignoring assignment: %s", + lvalue, rvalue); + return 0; + } + + p->assign = r; + p = NULL; + + return 0; +} + int config_parse_route_prefix(const char *unit, const char *filename, unsigned line, diff --git a/src/network/networkd-radv.h b/src/network/networkd-radv.h index 21b323e83e..8bf697aff0 100644 --- a/src/network/networkd-radv.h +++ b/src/network/networkd-radv.h @@ -28,6 +28,8 @@ struct Prefix { sd_radv_prefix *radv_prefix; + bool assign; + LIST_FIELDS(Prefix, prefixes); }; @@ -59,6 +61,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_router_preference); CONFIG_PARSER_PROTOTYPE(config_parse_prefix); CONFIG_PARSER_PROTOTYPE(config_parse_prefix_flags); CONFIG_PARSER_PROTOTYPE(config_parse_prefix_lifetime); +CONFIG_PARSER_PROTOTYPE(config_parse_prefix_assign); CONFIG_PARSER_PROTOTYPE(config_parse_radv_dns); CONFIG_PARSER_PROTOTYPE(config_parse_radv_search_domains); CONFIG_PARSER_PROTOTYPE(config_parse_route_prefix); diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network index 2b41239b74..ea872cd7e2 100644 --- a/test/fuzz/fuzz-network-parser/directives.network +++ b/test/fuzz/fuzz-network-parser/directives.network @@ -186,6 +186,7 @@ OnLink= PreferredLifetimeSec= AddressAutoconfiguration= ValidLifetimeSec= +Assign= [IPv6RoutePrefix] Route= LifetimeSec= |