diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-02-18 07:23:09 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-04-16 04:18:33 +0200 |
commit | 19f3cc86a04ff7870dea3ac97fcbf624db3330fe (patch) | |
tree | 101ce6448c83d535a1d3393646ad9f20bcc57cb1 /src/libsystemd-network | |
parent | Merge pull request #32267 from yuwata/sd-ndisc-router-solicit (diff) | |
download | systemd-19f3cc86a04ff7870dea3ac97fcbf624db3330fe.tar.xz systemd-19f3cc86a04ff7870dea3ac97fcbf624db3330fe.zip |
sd-radv: set only basic information on stop
There are many possible reasons to stop the service;
tentative reboot of the service or the system, the router may be
revoked, and so on.
And, each situations, the availability of the previously announced
options e.g. prefixes, DNSSL and so on is not clear.
So, let's announce only the clear information, that is, the router
lifetime is zero. which indicates that the router will be invalidated
(regardless tentative or not).
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r-- | src/libsystemd-network/sd-radv.c | 26 | ||||
-rw-r--r-- | src/libsystemd-network/test-ndisc-ra.c | 7 |
2 files changed, 31 insertions, 2 deletions
diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c index 79210f9e2c..69ebd94fb1 100644 --- a/src/libsystemd-network/sd-radv.c +++ b/src/libsystemd-network/sd-radv.c @@ -129,6 +129,30 @@ static bool router_lifetime_is_valid(usec_t lifetime_usec) { lifetime_usec <= RADV_MAX_ROUTER_LIFETIME_USEC); } +static int radv_send_router_on_stop(sd_radv *ra) { + static const struct nd_router_advert adv = { + .nd_ra_type = ND_ROUTER_ADVERT, + }; + + _cleanup_set_free_ Set *options = NULL; + usec_t time_now; + int r; + + assert(ra); + + r = sd_event_now(ra->event, CLOCK_BOOTTIME, &time_now); + if (r < 0) + return r; + + if (!ether_addr_is_null(&ra->mac_addr)) { + r = ndisc_option_set_link_layer_address(&options, SD_NDISC_OPTION_SOURCE_LL_ADDRESS, &ra->mac_addr); + if (r < 0) + return r; + } + + return ndisc_send(ra->fd, &IN6_ADDR_ALL_NODES_MULTICAST, &adv.nd_ra_hdr, options, time_now); +} + static int radv_send_router(sd_radv *ra, const struct in6_addr *dst, usec_t lifetime_usec) { assert(ra); assert(router_lifetime_is_valid(lifetime_usec)); @@ -362,7 +386,7 @@ int sd_radv_stop(sd_radv *ra) { /* RFC 4861, Section 6.2.5: * the router SHOULD transmit one or more (but not more than MAX_FINAL_RTR_ADVERTISEMENTS) final * multicast Router Advertisements on the interface with a Router Lifetime field of zero. */ - r = radv_send_router(ra, NULL, 0); + r = radv_send_router_on_stop(ra); if (r < 0) log_radv_errno(ra, r, "Unable to send last Router Advertisement with router lifetime set to zero, ignoring: %m"); diff --git a/src/libsystemd-network/test-ndisc-ra.c b/src/libsystemd-network/test-ndisc-ra.c index c5f10cc795..76f4d7ba3f 100644 --- a/src/libsystemd-network/test-ndisc-ra.c +++ b/src/libsystemd-network/test-ndisc-ra.c @@ -294,8 +294,13 @@ static void verify_message(const uint8_t *buf, size_t len) { /* verify only up to known options, rest is not yet implemented */ for (size_t i = 0, m = MIN(len, sizeof(advertisement)); i < m; i++) { if (test_stopped) + /* on stop, many header fields are zero */ switch (i) { - case 6 ... 7: /* router lifetime must be zero on stop. */ + case 4: /* hop limit */ + case 5: /* flags */ + case 6 ... 7: /* router lifetime */ + case 8 ... 11: /* reachable time */ + case 12 ... 15: /* retrans timer */ assert_se(buf[i] == 0); continue; } |