Compare commits

..

5 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek a1b24ee147
Merge pull request #17551 from yuwata/radv-router-lifetime
network: about router lifetime
2020-11-09 21:07:16 +01:00
Yu Watanabe 2075e596cf network: convert router lifetime from usec_t to uint16_t 2020-11-10 00:04:52 +09:00
Yu Watanabe dd1b187075 sd-radv: refuse to set preference except medium when router lifetime is zero 2020-11-10 00:04:52 +09:00
Yu Watanabe ac138551ce sd-radv: router lifetime is uint16_t 2020-11-10 00:04:52 +09:00
Yu Watanabe 71a5db49fd network: make default router lifetime to 30min
Closes #17527.
2020-11-10 00:04:42 +09:00
5 changed files with 25 additions and 17 deletions

View File

@ -2254,9 +2254,8 @@ IPv6Token=prefixstable:2002:da8:1::</programlisting></para>
<varlistentry>
<term><varname>RouterLifetimeSec=</varname></term>
<listitem><para>Takes a timespan. Configures the IPv6 router lifetime in seconds. If set,
this host also announces itself in Router Advertisements as an IPv6
router for the network link. When unset, the host is not acting as a router.</para>
<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>
</listitem>
</varlistentry>

View File

@ -466,14 +466,14 @@ _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, uint32_t router_lifetime) {
_public_ int sd_radv_set_router_lifetime(sd_radv *ra, uint16_t router_lifetime) {
assert_return(ra, -EINVAL);
if (ra->state != SD_RADV_STATE_IDLE)
return -EBUSY;
/* RFC 4191, Section 2.2, "...If the Router Lifetime is zero, the
preference value MUST be set to (00) by the sender..." */
/* 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 &&
(ra->flags & (0x3 << 3)) != (SD_NDISC_PREFERENCE_MEDIUM << 3))
return -ETIME;
@ -506,17 +506,20 @@ _public_ int sd_radv_set_other_information(sd_radv *ra, int other) {
}
_public_ int sd_radv_set_preference(sd_radv *ra, unsigned preference) {
int r = 0;
assert_return(ra, -EINVAL);
assert_return(IN_SET(preference,
SD_NDISC_PREFERENCE_LOW,
SD_NDISC_PREFERENCE_MEDIUM,
SD_NDISC_PREFERENCE_HIGH), -EINVAL);
/* 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)
return -EINVAL;
ra->flags = (ra->flags & ~(0x3 << 3)) | (preference << 3);
return r;
return 0;
}
_public_ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p, int dynamic) {

View File

@ -379,6 +379,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_emit_dns = true,
.router_emit_domains = true,

View File

@ -641,6 +641,7 @@ static bool link_radv_enabled(Link *link) {
}
int radv_configure(Link *link) {
uint16_t router_lifetime;
RoutePrefix *q;
Prefix *p;
int r;
@ -675,16 +676,20 @@ int radv_configure(Link *link) {
if (r < 0)
return r;
/* a value of 0xffffffff represents infinity, 0x0 means this host is
not a router */
r = sd_radv_set_router_lifetime(link->radv,
DIV_ROUND_UP(link->network->router_lifetime_usec, USEC_PER_SEC));
/* 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);
if (r < 0)
return r;
if (link->network->router_lifetime_usec > 0) {
r = sd_radv_set_preference(link->radv,
link->network->router_preference);
if (router_lifetime > 0) {
r = sd_radv_set_preference(link->radv, link->network->router_preference);
if (r < 0)
return r;
}

View File

@ -56,7 +56,7 @@ int sd_radv_set_ifindex(sd_radv *ra, int interface_index);
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, uint32_t router_lifetime);
int sd_radv_set_router_lifetime(sd_radv *ra, uint16_t router_lifetime);
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);