Compare commits

..

No commits in common. "a1b24ee147454390e9d557a94a848f59ca662c82" and "df80c98cdece42c6b49f4c9adc45017b0b0582c6" have entirely different histories.

5 changed files with 17 additions and 25 deletions

View File

@ -2254,8 +2254,9 @@ IPv6Token=prefixstable:2002:da8:1::</programlisting></para>
<varlistentry> <varlistentry>
<term><varname>RouterLifetimeSec=</varname></term> <term><varname>RouterLifetimeSec=</varname></term>
<listitem><para>Takes a timespan. Configures the IPv6 router lifetime in seconds. When set to <listitem><para>Takes a timespan. Configures the IPv6 router lifetime in seconds. If set,
0, the host is not acting as a router. Defaults to 30 minutes.</para> 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> </listitem>
</varlistentry> </varlistentry>

View File

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

View File

@ -379,7 +379,6 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
.dhcp_server_emit_router = true, .dhcp_server_emit_router = true,
.dhcp_server_emit_timezone = true, .dhcp_server_emit_timezone = true,
.router_lifetime_usec = 30 * USEC_PER_MINUTE,
.router_emit_dns = true, .router_emit_dns = true,
.router_emit_domains = true, .router_emit_domains = true,

View File

@ -641,7 +641,6 @@ static bool link_radv_enabled(Link *link) {
} }
int radv_configure(Link *link) { int radv_configure(Link *link) {
uint16_t router_lifetime;
RoutePrefix *q; RoutePrefix *q;
Prefix *p; Prefix *p;
int r; int r;
@ -676,20 +675,16 @@ int radv_configure(Link *link) {
if (r < 0) if (r < 0)
return r; return r;
/* a value of UINT16_MAX represents infinity, 0x0 means this host is not a router */ /* a value of 0xffffffff represents infinity, 0x0 means this host is
if (link->network->router_lifetime_usec == USEC_INFINITY) not a router */
router_lifetime = UINT16_MAX; r = sd_radv_set_router_lifetime(link->radv,
else if (link->network->router_lifetime_usec > (UINT16_MAX - 1) * USEC_PER_SEC) DIV_ROUND_UP(link->network->router_lifetime_usec, 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) if (r < 0)
return r; return r;
if (router_lifetime > 0) { if (link->network->router_lifetime_usec > 0) {
r = sd_radv_set_preference(link->radv, link->network->router_preference); r = sd_radv_set_preference(link->radv,
link->network->router_preference);
if (r < 0) if (r < 0)
return r; 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_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_mtu(sd_radv *ra, uint32_t mtu);
int sd_radv_set_hop_limit(sd_radv *ra, uint8_t hop_limit); 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, uint32_t router_lifetime);
int sd_radv_set_managed_information(sd_radv *ra, int managed); 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_other_information(sd_radv *ra, int other);
int sd_radv_set_preference(sd_radv *ra, unsigned preference); int sd_radv_set_preference(sd_radv *ra, unsigned preference);