summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/systemd.network.xml3
-rw-r--r--src/libsystemd-network/radv-internal.h62
-rw-r--r--src/libsystemd-network/sd-radv.c110
-rw-r--r--src/libsystemd-network/test-ndisc-ra.c8
-rw-r--r--src/network/networkd-network-gperf.gperf2
-rw-r--r--src/network/networkd-network.c3
-rw-r--r--src/network/networkd-radv.c66
-rw-r--r--src/network/networkd-radv.h1
-rw-r--r--src/systemd/sd-radv.h7
9 files changed, 175 insertions, 87 deletions
diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 41a58b36eb..b263220e0c 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -2622,7 +2622,8 @@ Token=prefixstable:2002:da8:1::</programlisting></para>
<term><varname>RouterLifetimeSec=</varname></term>
<listitem><para>Takes a timespan. Configures the IPv6 router lifetime in seconds. When set to
- 0, the host is not acting as a router. Defaults to 30 minutes.</para>
+ 0, the host is not acting as a router. The value must be 0 second, or between 4 seconds and
+ 9000 seconds. Defaults to 1800 seconds (30 minutes).</para>
</listitem>
</varlistentry>
diff --git a/src/libsystemd-network/radv-internal.h b/src/libsystemd-network/radv-internal.h
index ef566ed8ec..260d1a826f 100644
--- a/src/libsystemd-network/radv-internal.h
+++ b/src/libsystemd-network/radv-internal.h
@@ -10,22 +10,54 @@
#include "list.h"
#include "network-common.h"
#include "sparse-endian.h"
-
-assert_cc(SD_RADV_DEFAULT_MIN_TIMEOUT_USEC <= SD_RADV_DEFAULT_MAX_TIMEOUT_USEC);
-
-#define SD_RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC (16*USEC_PER_SEC)
-#define SD_RADV_MAX_INITIAL_RTR_ADVERTISEMENTS 3
-#define SD_RADV_MAX_FINAL_RTR_ADVERTISEMENTS 3
-#define SD_RADV_MIN_DELAY_BETWEEN_RAS 3
-#define SD_RADV_MAX_RA_DELAY_TIME_USEC (500*USEC_PER_MSEC)
-
-#define SD_RADV_OPT_ROUTE_INFORMATION 24
-#define SD_RADV_OPT_RDNSS 25
-#define SD_RADV_OPT_DNSSL 31
+#include "time-util.h"
+
+/* RFC 4861 section 6.2.1.
+ * MaxRtrAdvInterval
+ * The maximum time allowed between sending unsolicited multicast Router Advertisements from the
+ * interface, in seconds. MUST be no less than 4 seconds and no greater than 1800 seconds.
+ * Default: 600 seconds */
+#define RADV_MIN_MAX_TIMEOUT_USEC (4 * USEC_PER_SEC)
+#define RADV_MAX_MAX_TIMEOUT_USEC (1800 * USEC_PER_SEC)
+#define RADV_DEFAULT_MAX_TIMEOUT_USEC (600 * USEC_PER_SEC)
+/* RFC 4861 section 6.2.1.
+ * MinRtrAdvInterval
+ * The minimum time allowed between sending unsolicited multicast Router Advertisements from the
+ * interface, in seconds. MUST be no less than 3 seconds and no greater than .75 * MaxRtrAdvInterval.
+ * Default: 0.33 * MaxRtrAdvInterval If MaxRtrAdvInterval >= 9 seconds; otherwise, the Default is
+ * MaxRtrAdvInterval (Note, this should be a typo. We use 0.75 * MaxRtrAdvInterval). */
+#define RADV_MIN_MIN_TIMEOUT_USEC (3 * USEC_PER_SEC)
+/* RFC 4861 section 6.2.4.
+ * AdvDefaultLifetime
+ * The value to be placed in the Router Lifetime field of Router Advertisements sent from the interface,
+ * in seconds. MUST be either zero or between MaxRtrAdvInterval and 9000 seconds. A value of zero
+ * indicates that the router is not to be used as a default router. These limits may be overridden by
+ * specific documents that describe how IPv6 operates over different link layers. For instance, in a
+ * point-to-point link the peers may have enough information about the number and status of devices at
+ * the other end so that advertisements are needed less frequently.
+ * Default: 3 * MaxRtrAdvInterval */
+#define RADV_MIN_ROUTER_LIFETIME_USEC RADV_MIN_MAX_TIMEOUT_USEC
+#define RADV_MAX_ROUTER_LIFETIME_USEC (9000 * USEC_PER_SEC)
+#define RADV_DEFAULT_ROUTER_LIFETIME_USEC (3 * RADV_DEFAULT_MAX_TIMEOUT_USEC)
+/* RFC 4861 section 10.
+ * MAX_INITIAL_RTR_ADVERT_INTERVAL 16 seconds
+ * MAX_INITIAL_RTR_ADVERTISEMENTS 3 transmissions
+ * MAX_FINAL_RTR_ADVERTISEMENTS 3 transmissions
+ * MIN_DELAY_BETWEEN_RAS 3 seconds
+ * MAX_RA_DELAY_TIME .5 seconds */
+#define RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC (16 * USEC_PER_SEC)
+#define RADV_MAX_INITIAL_RTR_ADVERTISEMENTS 3
+#define RADV_MAX_FINAL_RTR_ADVERTISEMENTS 3
+#define RADV_MIN_DELAY_BETWEEN_RAS 3
+#define RADV_MAX_RA_DELAY_TIME_USEC (500 * USEC_PER_MSEC)
+
+#define RADV_OPT_ROUTE_INFORMATION 24
+#define RADV_OPT_RDNSS 25
+#define RADV_OPT_DNSSL 31
enum RAdvState {
- SD_RADV_STATE_IDLE = 0,
- SD_RADV_STATE_ADVERTISING = 1,
+ RADV_STATE_IDLE = 0,
+ RADV_STATE_ADVERTISING = 1,
};
typedef enum RAdvState RAdvState;
@@ -50,7 +82,7 @@ struct sd_radv {
uint8_t hop_limit;
uint8_t flags;
uint32_t mtu;
- uint16_t lifetime;
+ usec_t lifetime_usec; /* timespan */
int fd;
unsigned ra_sent;
diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c
index 83ef158ebf..00bf7db519 100644
--- a/src/libsystemd-network/sd-radv.c
+++ b/src/libsystemd-network/sd-radv.c
@@ -38,6 +38,7 @@ _public_ int sd_radv_new(sd_radv **ret) {
*ra = (sd_radv) {
.n_ref = 1,
.fd = -1,
+ .lifetime_usec = RADV_DEFAULT_ROUTER_LIFETIME_USEC,
};
*ret = TAKE_PTR(ra);
@@ -81,7 +82,7 @@ _public_ sd_event *sd_radv_get_event(sd_radv *ra) {
_public_ int sd_radv_is_running(sd_radv *ra) {
assert_return(ra, false);
- return ra->state != SD_RADV_STATE_IDLE;
+ return ra->state != RADV_STATE_IDLE;
}
static void radv_reset(sd_radv *ra) {
@@ -128,7 +129,13 @@ static sd_radv *radv_free(sd_radv *ra) {
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv, sd_radv, radv_free);
-static int radv_send(sd_radv *ra, const struct in6_addr *dst, uint32_t router_lifetime) {
+static bool router_lifetime_is_valid(usec_t lifetime_usec) {
+ return lifetime_usec == 0 ||
+ (lifetime_usec >= RADV_MIN_ROUTER_LIFETIME_USEC &&
+ lifetime_usec <= RADV_MAX_ROUTER_LIFETIME_USEC);
+}
+
+static int radv_send(sd_radv *ra, const struct in6_addr *dst, usec_t lifetime_usec) {
sd_radv_route_prefix *rt;
sd_radv_prefix *p;
struct sockaddr_in6 dst_addr = {
@@ -162,6 +169,7 @@ static int radv_send(sd_radv *ra, const struct in6_addr *dst, uint32_t router_li
int r;
assert(ra);
+ assert(router_lifetime_is_valid(lifetime_usec));
r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
@@ -173,7 +181,8 @@ static int radv_send(sd_radv *ra, const struct in6_addr *dst, uint32_t router_li
adv.nd_ra_type = ND_ROUTER_ADVERT;
adv.nd_ra_curhoplimit = ra->hop_limit;
adv.nd_ra_flags_reserved = ra->flags;
- adv.nd_ra_router_lifetime = htobe16(router_lifetime);
+ assert_cc(RADV_MAX_ROUTER_LIFETIME_USEC <= UINT16_MAX * USEC_PER_SEC);
+ adv.nd_ra_router_lifetime = htobe16(DIV_ROUND_UP(lifetime_usec, USEC_PER_SEC));
iov[msg.msg_iovlen++] = IOVEC_MAKE(&adv, sizeof(adv));
/* MAC address is optional, either because the link does not use L2
@@ -274,7 +283,7 @@ static int radv_recv(sd_event_source *s, int fd, uint32_t revents, void *userdat
(void) in_addr_to_string(AF_INET6, (const union in_addr_union*) &src, &addr);
- r = radv_send(ra, &src, ra->lifetime);
+ r = radv_send(ra, &src, ra->lifetime_usec);
if (r < 0)
log_radv_errno(ra, r, "Unable to send solicited Router Advertisement to %s, ignoring: %m", strnull(addr));
else
@@ -283,54 +292,54 @@ static int radv_recv(sd_event_source *s, int fd, uint32_t revents, void *userdat
return 0;
}
-static usec_t radv_compute_timeout(usec_t min, usec_t max) {
- assert_return(min <= max, SD_RADV_DEFAULT_MIN_TIMEOUT_USEC);
-
- /* RFC 4861: min must be no less than 3s, max must be no less than 4s */
- min = MAX(min, 3*USEC_PER_SEC);
- max = MAX(max, 4*USEC_PER_SEC);
-
- return min + (random_u32() % (max - min));
-}
-
static int radv_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
- int r;
+ usec_t min_timeout, max_timeout, time_now, timeout;
sd_radv *ra = userdata;
- usec_t min_timeout = SD_RADV_DEFAULT_MIN_TIMEOUT_USEC;
- usec_t max_timeout = SD_RADV_DEFAULT_MAX_TIMEOUT_USEC;
- usec_t time_now, timeout;
+ int r;
assert(s);
assert(ra);
assert(ra->event);
+ assert(router_lifetime_is_valid(ra->lifetime_usec));
r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now);
if (r < 0)
goto fail;
- r = radv_send(ra, NULL, ra->lifetime);
+ r = radv_send(ra, NULL, ra->lifetime_usec);
if (r < 0)
log_radv_errno(ra, r, "Unable to send Router Advertisement: %m");
/* RFC 4861, Section 6.2.4, sending initial Router Advertisements */
- if (ra->ra_sent < SD_RADV_MAX_INITIAL_RTR_ADVERTISEMENTS) {
- max_timeout = SD_RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC;
- min_timeout = SD_RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC / 3;
- }
+ if (ra->ra_sent < RADV_MAX_INITIAL_RTR_ADVERTISEMENTS)
+ max_timeout = RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC;
+ else
+ max_timeout = RADV_DEFAULT_MAX_TIMEOUT_USEC;
/* RFC 4861, Section 6.2.1, lifetime must be at least MaxRtrAdvInterval,
- so lower the interval here */
- if (ra->lifetime > 0 && (ra->lifetime * USEC_PER_SEC) < max_timeout) {
- max_timeout = ra->lifetime * USEC_PER_SEC;
+ * so lower the interval here */
+ if (ra->lifetime_usec > 0)
+ max_timeout = MIN(max_timeout, ra->lifetime_usec);
+
+ if (max_timeout >= 9 * USEC_PER_SEC)
min_timeout = max_timeout / 3;
- }
+ else
+ min_timeout = max_timeout * 3 / 4;
- timeout = radv_compute_timeout(min_timeout, max_timeout);
+ /* RFC 4861, Section 6.2.1.
+ * MaxRtrAdvInterval MUST be no less than 4 seconds and no greater than 1800 seconds.
+ * MinRtrAdvInterval MUST be no less than 3 seconds and no greater than .75 * MaxRtrAdvInterval. */
+ assert(max_timeout >= RADV_MIN_MAX_TIMEOUT_USEC);
+ assert(max_timeout <= RADV_MAX_MAX_TIMEOUT_USEC);
+ assert(min_timeout >= RADV_MIN_MIN_TIMEOUT_USEC);
+ assert(min_timeout <= max_timeout * 3 / 4);
+
+ timeout = min_timeout + random_u64_range(max_timeout - min_timeout);
log_radv(ra, "Next Router Advertisement in %s", FORMAT_TIMESPAN(timeout, USEC_PER_SEC));
r = event_reset_time(ra->event, &ra->timeout_event_source,
clock_boottime_or_monotonic(),
- time_now + timeout, MSEC_PER_SEC,
+ usec_add(time_now, timeout), MSEC_PER_SEC,
radv_timeout, ra,
ra->event_priority, "radv-timeout", true);
if (r < 0)
@@ -352,7 +361,7 @@ _public_ int sd_radv_stop(sd_radv *ra) {
if (!ra)
return 0;
- if (ra->state == SD_RADV_STATE_IDLE)
+ if (ra->state == RADV_STATE_IDLE)
return 0;
log_radv(ra, "Stopping IPv6 Router Advertisement daemon");
@@ -365,7 +374,7 @@ _public_ int sd_radv_stop(sd_radv *ra) {
radv_reset(ra);
ra->fd = safe_close(ra->fd);
- ra->state = SD_RADV_STATE_IDLE;
+ ra->state = RADV_STATE_IDLE;
return 0;
}
@@ -377,7 +386,7 @@ _public_ int sd_radv_start(sd_radv *ra) {
assert_return(ra->event, -EINVAL);
assert_return(ra->ifindex > 0, -EINVAL);
- if (ra->state != SD_RADV_STATE_IDLE)
+ if (ra->state != RADV_STATE_IDLE)
return 0;
r = event_reset_time(ra->event, &ra->timeout_event_source,
@@ -404,7 +413,7 @@ _public_ int sd_radv_start(sd_radv *ra) {
(void) sd_event_source_set_description(ra->recv_event_source, "radv-receive-message");
- ra->state = SD_RADV_STATE_ADVERTISING;
+ ra->state = RADV_STATE_ADVERTISING;
log_radv(ra, "Started IPv6 Router Advertisement daemon");
@@ -420,7 +429,7 @@ _public_ int sd_radv_set_ifindex(sd_radv *ra, int ifindex) {
assert_return(ra, -EINVAL);
assert_return(ifindex > 0, -EINVAL);
- if (ra->state != SD_RADV_STATE_IDLE)
+ if (ra->state != RADV_STATE_IDLE)
return -EBUSY;
ra->ifindex = ifindex;
@@ -456,7 +465,7 @@ int sd_radv_get_ifname(sd_radv *ra, const char **ret) {
_public_ int sd_radv_set_mac(sd_radv *ra, const struct ether_addr *mac_addr) {
assert_return(ra, -EINVAL);
- if (ra->state != SD_RADV_STATE_IDLE)
+ if (ra->state != RADV_STATE_IDLE)
return -EBUSY;
if (mac_addr)
@@ -479,7 +488,7 @@ _public_ int sd_radv_set_mtu(sd_radv *ra, uint32_t mtu) {
_public_ int sd_radv_set_hop_limit(sd_radv *ra, uint8_t hop_limit) {
assert_return(ra, -EINVAL);
- if (ra->state != SD_RADV_STATE_IDLE)
+ if (ra->state != RADV_STATE_IDLE)
return -EBUSY;
ra->hop_limit = hop_limit;
@@ -487,19 +496,22 @@ _public_ int sd_radv_set_hop_limit(sd_radv *ra, uint8_t hop_limit) {
return 0;
}
-_public_ int sd_radv_set_router_lifetime(sd_radv *ra, uint16_t router_lifetime) {
+_public_ int sd_radv_set_router_lifetime(sd_radv *ra, uint64_t lifetime_usec) {
assert_return(ra, -EINVAL);
- if (ra->state != SD_RADV_STATE_IDLE)
+ if (ra->state != RADV_STATE_IDLE)
return -EBUSY;
+ if (!router_lifetime_is_valid(lifetime_usec))
+ return -EINVAL;
+
/* RFC 4191, Section 2.2, "...If the Router Lifetime is zero, the preference value MUST be set
* to (00) by the sender..." */
- if (router_lifetime == 0 &&
+ if (lifetime_usec == 0 &&
(ra->flags & (0x3 << 3)) != (SD_NDISC_PREFERENCE_MEDIUM << 3))
- return -ETIME;
+ return -EINVAL;
- ra->lifetime = router_lifetime;
+ ra->lifetime_usec = lifetime_usec;
return 0;
}
@@ -507,7 +519,7 @@ _public_ int sd_radv_set_router_lifetime(sd_radv *ra, uint16_t router_lifetime)
_public_ int sd_radv_set_managed_information(sd_radv *ra, int managed) {
assert_return(ra, -EINVAL);
- if (ra->state != SD_RADV_STATE_IDLE)
+ if (ra->state != RADV_STATE_IDLE)
return -EBUSY;
SET_FLAG(ra->flags, ND_RA_FLAG_MANAGED, managed);
@@ -518,7 +530,7 @@ _public_ int sd_radv_set_managed_information(sd_radv *ra, int managed) {
_public_ int sd_radv_set_other_information(sd_radv *ra, int other) {
assert_return(ra, -EINVAL);
- if (ra->state != SD_RADV_STATE_IDLE)
+ if (ra->state != RADV_STATE_IDLE)
return -EBUSY;
SET_FLAG(ra->flags, ND_RA_FLAG_OTHER, other);
@@ -535,7 +547,7 @@ _public_ int sd_radv_set_preference(sd_radv *ra, unsigned preference) {
/* RFC 4191, Section 2.2, "...If the Router Lifetime is zero, the preference value MUST be set
* to (00) by the sender..." */
- if (ra->lifetime == 0 && preference != SD_NDISC_PREFERENCE_MEDIUM)
+ if (ra->lifetime_usec == 0 && preference != SD_NDISC_PREFERENCE_MEDIUM)
return -EINVAL;
ra->flags = (ra->flags & ~(0x3 << 3)) | (preference << 3);
@@ -595,7 +607,7 @@ _public_ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p, int dynamic) {
/* If RAs have already been sent, send an RA immediately to announce the newly-added prefix */
if (ra->ra_sent > 0) {
- r = radv_send(ra, NULL, ra->lifetime);
+ r = radv_send(ra, NULL, ra->lifetime_usec);
if (r < 0)
log_radv_errno(ra, r, "Unable to send Router Advertisement for added prefix: %m");
else
@@ -698,7 +710,7 @@ _public_ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p, int
/* If RAs have already been sent, send an RA immediately to announce the newly-added route prefix */
if (ra->ra_sent > 0) {
- r = radv_send(ra, NULL, ra->lifetime);
+ r = radv_send(ra, NULL, ra->lifetime_usec);
if (r < 0)
log_radv_errno(ra, r, "Unable to send Router Advertisement for added route prefix: %m");
else
@@ -743,7 +755,7 @@ _public_ int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime,
if (!opt_rdnss)
return -ENOMEM;
- opt_rdnss->type = SD_RADV_OPT_RDNSS;
+ opt_rdnss->type = RADV_OPT_RDNSS;
opt_rdnss->length = len / 8;
opt_rdnss->lifetime = htobe32(lifetime);
@@ -779,7 +791,7 @@ _public_ int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime,
if (!opt_dnssl)
return -ENOMEM;
- opt_dnssl->type = SD_RADV_OPT_DNSSL;
+ opt_dnssl->type = RADV_OPT_DNSSL;
opt_dnssl->length = len / 8;
opt_dnssl->lifetime = htobe32(lifetime);
@@ -911,7 +923,7 @@ _public_ int sd_radv_route_prefix_new(sd_radv_route_prefix **ret) {
*p = (sd_radv_route_prefix) {
.n_ref = 1,
- .opt.type = SD_RADV_OPT_ROUTE_INFORMATION,
+ .opt.type = RADV_OPT_ROUTE_INFORMATION,
.opt.length = DIV_ROUND_UP(sizeof(p->opt), 8),
.opt.prefixlen = 64,
diff --git a/src/libsystemd-network/test-ndisc-ra.c b/src/libsystemd-network/test-ndisc-ra.c
index 4713bc99b5..45902862d3 100644
--- a/src/libsystemd-network/test-ndisc-ra.c
+++ b/src/libsystemd-network/test-ndisc-ra.c
@@ -180,7 +180,9 @@ static void test_radv(void) {
assert_se(sd_radv_set_router_lifetime(NULL, 0) < 0);
assert_se(sd_radv_set_router_lifetime(ra, 0) >= 0);
- assert_se(sd_radv_set_router_lifetime(ra, ~0) >= 0);
+ assert_se(sd_radv_set_router_lifetime(ra, USEC_INFINITY) < 0);
+ assert_se(sd_radv_set_router_lifetime(ra, USEC_PER_YEAR) < 0);
+ assert_se(sd_radv_set_router_lifetime(ra, 300 * USEC_PER_SEC) >= 0);
assert_se(sd_radv_set_preference(NULL, 0) < 0);
assert_se(sd_radv_set_preference(ra, SD_NDISC_PREFERENCE_LOW) >= 0);
@@ -189,7 +191,7 @@ static void test_radv(void) {
assert_se(sd_radv_set_preference(ra, ~0) < 0);
assert_se(sd_radv_set_preference(ra, SD_NDISC_PREFERENCE_HIGH) >= 0);
- assert_se(sd_radv_set_router_lifetime(ra, 42000) >= 0);
+ assert_se(sd_radv_set_router_lifetime(ra, 300 * USEC_PER_SEC) >= 0);
assert_se(sd_radv_set_router_lifetime(ra, 0) < 0);
assert_se(sd_radv_set_preference(ra, SD_NDISC_PREFERENCE_MEDIUM) >= 0);
assert_se(sd_radv_set_router_lifetime(ra, 0) >= 0);
@@ -308,7 +310,7 @@ static void test_ra(void) {
assert_se(sd_radv_set_ifindex(ra, 42) >= 0);
assert_se(sd_radv_set_mac(ra, &mac_addr) >= 0);
- assert_se(sd_radv_set_router_lifetime(ra, 180) >= 0);
+ assert_se(sd_radv_set_router_lifetime(ra, 180 * USEC_PER_SEC) >= 0);
assert_se(sd_radv_set_hop_limit(ra, 64) >= 0);
assert_se(sd_radv_set_managed_information(ra, true) >= 0);
assert_se(sd_radv_set_other_information(ra, true) >= 0);
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 6631f5bc3e..595dd36121 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -331,7 +331,7 @@ DHCPv6PrefixDelegation.Assign, config_parse_bool,
DHCPv6PrefixDelegation.ManageTemporaryAddress, config_parse_bool, 0, offsetof(Network, dhcp6_pd_manage_temporary_address)
DHCPv6PrefixDelegation.Token, config_parse_address_generation_type, 0, offsetof(Network, dhcp6_pd_tokens)
DHCPv6PrefixDelegation.RouteMetric, config_parse_uint32, 0, offsetof(Network, dhcp6_pd_route_metric)
-IPv6SendRA.RouterLifetimeSec, config_parse_sec, 0, offsetof(Network, router_lifetime_usec)
+IPv6SendRA.RouterLifetimeSec, config_parse_router_lifetime, 0, offsetof(Network, router_lifetime_usec)
IPv6SendRA.Managed, config_parse_bool, 0, offsetof(Network, router_managed)
IPv6SendRA.OtherInformation, config_parse_bool, 0, offsetof(Network, router_other_information)
IPv6SendRA.RouterPreference, config_parse_router_preference, 0, 0
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 32c03ce47b..d41253c388 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -33,6 +33,7 @@
#include "networkd-sriov.h"
#include "parse-util.h"
#include "path-lookup.h"
+#include "radv-internal.h"
#include "set.h"
#include "socket-util.h"
#include "stat-util.h"
@@ -421,7 +422,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
.dhcp_server_emit_router = true,
.dhcp_server_emit_timezone = true,
- .router_lifetime_usec = 30 * USEC_PER_MINUTE,
+ .router_lifetime_usec = RADV_DEFAULT_ROUTER_LIFETIME_USEC,
.router_dns_lifetime_usec = 7 * USEC_PER_DAY,
.router_emit_dns = true,
.router_emit_domains = true,
diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c
index a290b3730a..08a8bbf8da 100644
--- a/src/network/networkd-radv.c
+++ b/src/network/networkd-radv.c
@@ -17,6 +17,7 @@
#include "networkd-radv.h"
#include "networkd-route.h"
#include "parse-util.h"
+#include "radv-internal.h"
#include "string-util.h"
#include "string-table.h"
#include "strv.h"
@@ -429,7 +430,6 @@ static int radv_find_uplink(Link *link, Link **ret) {
}
static int radv_configure(Link *link) {
- uint16_t router_lifetime;
Link *uplink = NULL;
RoutePrefix *q;
Prefix *p;
@@ -465,19 +465,11 @@ static int radv_configure(Link *link) {
if (r < 0)
return r;
- /* a value of UINT16_MAX represents infinity, 0x0 means this host is not a router */
- if (link->network->router_lifetime_usec == USEC_INFINITY)
- router_lifetime = UINT16_MAX;
- else if (link->network->router_lifetime_usec > (UINT16_MAX - 1) * USEC_PER_SEC)
- router_lifetime = UINT16_MAX - 1;
- else
- router_lifetime = DIV_ROUND_UP(link->network->router_lifetime_usec, USEC_PER_SEC);
-
- r = sd_radv_set_router_lifetime(link->radv, router_lifetime);
+ r = sd_radv_set_router_lifetime(link->radv, link->network->router_lifetime_usec);
if (r < 0)
return r;
- if (router_lifetime > 0) {
+ if (link->network->router_lifetime_usec > 0) {
r = sd_radv_set_preference(link->radv, link->network->router_preference);
if (r < 0)
return r;
@@ -1265,6 +1257,58 @@ int config_parse_router_prefix_delegation(
return 0;
}
+int config_parse_router_lifetime(
+ 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) {
+
+ usec_t usec, *lifetime = data;
+ int r;
+
+ assert(filename);
+ assert(section);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ if (isempty(rvalue)) {
+ *lifetime = RADV_DEFAULT_ROUTER_LIFETIME_USEC;
+ return 0;
+ }
+
+ r = parse_sec(rvalue, &usec);
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Failed to parse router lifetime, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+ if (usec > 0) {
+ if (usec < RADV_MIN_ROUTER_LIFETIME_USEC) {
+ log_syntax(unit, LOG_WARNING, filename, line, 0,
+ "Router lifetime %s is too short, using %s.",
+ FORMAT_TIMESPAN(usec, USEC_PER_SEC),
+ FORMAT_TIMESPAN(RADV_MIN_ROUTER_LIFETIME_USEC, USEC_PER_SEC));
+ usec = RADV_MIN_ROUTER_LIFETIME_USEC;
+ } else if (usec > RADV_MAX_ROUTER_LIFETIME_USEC) {
+ log_syntax(unit, LOG_WARNING, filename, line, 0,
+ "Router lifetime %s is too large, using %s.",
+ FORMAT_TIMESPAN(usec, USEC_PER_SEC),
+ FORMAT_TIMESPAN(RADV_MAX_ROUTER_LIFETIME_USEC, USEC_PER_SEC));
+ usec = RADV_MAX_ROUTER_LIFETIME_USEC;
+ }
+ }
+
+ *lifetime = usec;
+ return 0;
+}
+
int config_parse_router_preference(
const char *unit,
const char *filename,
diff --git a/src/network/networkd-radv.h b/src/network/networkd-radv.h
index 2d69a6fa27..392c00b37d 100644
--- a/src/network/networkd-radv.h
+++ b/src/network/networkd-radv.h
@@ -75,6 +75,7 @@ const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i) _const_;
RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_;
CONFIG_PARSER_PROTOTYPE(config_parse_router_prefix_delegation);
+CONFIG_PARSER_PROTOTYPE(config_parse_router_lifetime);
CONFIG_PARSER_PROTOTYPE(config_parse_router_preference);
CONFIG_PARSER_PROTOTYPE(config_parse_prefix);
CONFIG_PARSER_PROTOTYPE(config_parse_prefix_boolean);
diff --git a/src/systemd/sd-radv.h b/src/systemd/sd-radv.h
index f597c2c33d..820cbd872f 100644
--- a/src/systemd/sd-radv.h
+++ b/src/systemd/sd-radv.h
@@ -30,11 +30,6 @@
_SD_BEGIN_DECLARATIONS;
-#define SD_RADV_DEFAULT_MIN_TIMEOUT_USEC (200*USEC_PER_SEC)
-#define SD_RADV_DEFAULT_MAX_TIMEOUT_USEC (600*USEC_PER_SEC)
-
-#define SD_RADV_DEFAULT_DNS_LIFETIME_USEC (3*SD_RADV_DEFAULT_MAX_TIMEOUT_USEC)
-
typedef struct sd_radv sd_radv;
typedef struct sd_radv_prefix sd_radv_prefix;
typedef struct sd_radv_route_prefix sd_radv_route_prefix;
@@ -58,7 +53,7 @@ int sd_radv_get_ifname(sd_radv *ra, const char **ret);
int sd_radv_set_mac(sd_radv *ra, const struct ether_addr *mac_addr);
int sd_radv_set_mtu(sd_radv *ra, uint32_t mtu);
int sd_radv_set_hop_limit(sd_radv *ra, uint8_t hop_limit);
-int sd_radv_set_router_lifetime(sd_radv *ra, uint16_t router_lifetime);
+int sd_radv_set_router_lifetime(sd_radv *ra, uint64_t lifetime_usec);
int sd_radv_set_managed_information(sd_radv *ra, int managed);
int sd_radv_set_other_information(sd_radv *ra, int other);
int sd_radv_set_preference(sd_radv *ra, unsigned preference);