networkd: Add DHCPv6 as a configuration option to radv prefixes

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.
This commit is contained in:
Patrik Flykt 2018-01-04 15:11:39 +02:00
parent 6e849e95ad
commit 56a23cb40a
5 changed files with 56 additions and 7 deletions

View 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) {

View 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)

View 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;

View File

@ -28,6 +28,43 @@
#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);

View 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);