summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-radv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/networkd-radv.c')
-rw-r--r--src/network/networkd-radv.c169
1 files changed, 53 insertions, 116 deletions
diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c
index 5115646e7d..8cff0237a9 100644
--- a/src/network/networkd-radv.c
+++ b/src/network/networkd-radv.c
@@ -277,83 +277,6 @@ int link_reconfigure_radv_address(Address *address, Link *link) {
return 0;
}
-static int radv_set_prefix(Link *link, Prefix *prefix) {
- _cleanup_(sd_radv_prefix_unrefp) sd_radv_prefix *p = NULL;
- int r;
-
- assert(link);
- assert(link->radv);
- assert(prefix);
-
- r = sd_radv_prefix_new(&p);
- if (r < 0)
- return r;
-
- r = sd_radv_prefix_set_prefix(p, &prefix->prefix.address, prefix->prefix.prefixlen);
- if (r < 0)
- return r;
-
- r = sd_radv_prefix_set_preferred_lifetime(p, prefix->prefix.preferred_lifetime, prefix->prefix.preferred_until);
- if (r < 0)
- return r;
-
- r = sd_radv_prefix_set_valid_lifetime(p, prefix->prefix.valid_lifetime, prefix->prefix.valid_until);
- if (r < 0)
- return r;
-
- r = sd_radv_prefix_set_onlink(p, FLAGS_SET(prefix->prefix.flags, ND_OPT_PI_FLAG_ONLINK));
- if (r < 0)
- return r;
-
- r = sd_radv_prefix_set_address_autoconfiguration(p, FLAGS_SET(prefix->prefix.flags, ND_OPT_PI_FLAG_AUTO));
- if (r < 0)
- return r;
-
- return sd_radv_add_prefix(link->radv, p);
-}
-
-static int radv_set_route_prefix(Link *link, RoutePrefix *prefix) {
- _cleanup_(sd_radv_route_prefix_unrefp) sd_radv_route_prefix *p = NULL;
- int r;
-
- assert(link);
- assert(link->radv);
- assert(prefix);
-
- r = sd_radv_route_prefix_new(&p);
- if (r < 0)
- return r;
-
- r = sd_radv_route_prefix_set_prefix(p, &prefix->route.address, prefix->route.prefixlen);
- if (r < 0)
- return r;
-
- r = sd_radv_route_prefix_set_lifetime(p, prefix->route.lifetime, prefix->route.valid_until);
- if (r < 0)
- return r;
-
- return sd_radv_add_route_prefix(link->radv, p);
-}
-
-static int radv_set_pref64_prefix(Link *link, Prefix64 *prefix) {
- _cleanup_(sd_radv_pref64_prefix_unrefp) sd_radv_pref64_prefix *p = NULL;
- int r;
-
- assert(link);
- assert(link->radv);
- assert(prefix);
-
- r = sd_radv_pref64_prefix_new(&p);
- if (r < 0)
- return r;
-
- r = sd_radv_pref64_prefix_set_prefix(p, &prefix->prefix64.prefix, prefix->prefix64.prefixlen, prefix->prefix64.lifetime);
- if (r < 0)
- return r;
-
- return sd_radv_add_pref64_prefix(link->radv, p);
-}
-
static int network_get_ipv6_dns(Network *network, struct in6_addr **ret_addresses, size_t *ret_size) {
_cleanup_free_ struct in6_addr *addresses = NULL;
size_t n_addresses = 0;
@@ -430,9 +353,12 @@ static int radv_set_dns(Link *link, Link *uplink) {
return 0;
set_dns:
- return sd_radv_set_rdnss(link->radv,
- link->network->router_dns_lifetime_usec,
- dns, n_dns);
+ return sd_radv_add_rdnss(
+ link->radv,
+ n_dns,
+ dns,
+ link->network->router_dns_lifetime_usec,
+ /* valid_until = */ USEC_INFINITY);
}
static int radv_set_domains(Link *link, Link *uplink) {
@@ -466,9 +392,11 @@ set_domains:
if (!s)
return log_oom();
- return sd_radv_set_dnssl(link->radv,
- link->network->router_dns_lifetime_usec,
- s);
+ return sd_radv_add_dnssl(
+ link->radv,
+ s,
+ link->network->router_dns_lifetime_usec,
+ /* valid_until = */ USEC_INFINITY);
}
@@ -556,21 +484,40 @@ static int radv_configure(Link *link) {
Prefix *p;
HASHMAP_FOREACH(p, link->network->prefixes_by_section) {
- r = radv_set_prefix(link, p);
+ r = sd_radv_add_prefix(
+ link->radv,
+ &p->prefix.address,
+ p->prefix.prefixlen,
+ p->prefix.flags,
+ p->prefix.valid_lifetime,
+ p->prefix.preferred_lifetime,
+ p->prefix.valid_until,
+ p->prefix.preferred_until);
if (r < 0 && r != -EEXIST)
return r;
}
RoutePrefix *q;
HASHMAP_FOREACH(q, link->network->route_prefixes_by_section) {
- r = radv_set_route_prefix(link, q);
+ r = sd_radv_add_route(
+ link->radv,
+ &q->route.address,
+ q->route.prefixlen,
+ q->route.preference,
+ q->route.lifetime,
+ q->route.valid_until);
if (r < 0 && r != -EEXIST)
return r;
}
Prefix64 *n;
HASHMAP_FOREACH(n, link->network->pref64_prefixes_by_section) {
- r = radv_set_pref64_prefix(link, n);
+ r = sd_radv_add_prefix64(
+ link->radv,
+ &n->prefix64.prefix,
+ n->prefix64.prefixlen,
+ n->prefix64.lifetime,
+ n->prefix64.valid_until);
if (r < 0 && r != -EEXIST)
return r;
}
@@ -585,17 +532,15 @@ static int radv_configure(Link *link) {
if (r < 0)
return log_link_debug_errno(link, r, "Could not set RA Domains: %m");
- r = sd_radv_set_home_agent_information(link->radv, link->network->router_home_agent_information);
- if (r < 0)
- return r;
-
- r = sd_radv_set_home_agent_preference(link->radv, link->network->router_home_agent_preference);
- if (r < 0)
- return r;
-
- r = sd_radv_set_home_agent_lifetime(link->radv, link->network->home_agent_lifetime_usec);
- if (r < 0)
- return r;
+ if (link->network->router_home_agent_information) {
+ r = sd_radv_set_home_agent(
+ link->radv,
+ link->network->router_home_agent_preference,
+ link->network->home_agent_lifetime_usec,
+ /* valid_until = */ USEC_INFINITY);
+ if (r < 0)
+ return r;
+ }
return 0;
}
@@ -739,31 +684,23 @@ int radv_add_prefix(
usec_t lifetime_preferred_usec,
usec_t lifetime_valid_usec) {
- _cleanup_(sd_radv_prefix_unrefp) sd_radv_prefix *p = NULL;
int r;
assert(link);
+ assert(prefix);
if (!link->radv)
return 0;
- r = sd_radv_prefix_new(&p);
- if (r < 0)
- return r;
-
- r = sd_radv_prefix_set_prefix(p, prefix, prefix_len);
- if (r < 0)
- return r;
-
- r = sd_radv_prefix_set_preferred_lifetime(p, RADV_DEFAULT_PREFERRED_LIFETIME_USEC, lifetime_preferred_usec);
- if (r < 0)
- return r;
-
- r = sd_radv_prefix_set_valid_lifetime(p, RADV_DEFAULT_VALID_LIFETIME_USEC, lifetime_valid_usec);
- if (r < 0)
- return r;
-
- r = sd_radv_add_prefix(link->radv, p);
+ r = sd_radv_add_prefix(
+ link->radv,
+ prefix,
+ prefix_len,
+ ND_OPT_PI_FLAG_ONLINK | ND_OPT_PI_FLAG_AUTO,
+ RADV_DEFAULT_VALID_LIFETIME_USEC,
+ RADV_DEFAULT_PREFERRED_LIFETIME_USEC,
+ lifetime_valid_usec,
+ lifetime_preferred_usec);
if (r == -EEXIST)
return 0;
if (r < 0)
@@ -1435,7 +1372,7 @@ int config_parse_router_prefix_delegation(
}
/* When IPv6SendRA= is enabled, only static prefixes are sent by default, and users
- * need to explicitly enable DHCPv6PrefixDelegation=. */
+ * need to explicitly enable DHCPPrefixDelegation=. */
*ra = r ? RADV_PREFIX_DELEGATION_STATIC : RADV_PREFIX_DELEGATION_NONE;
return 0;
}