From 059d7b6eae827e73c73633bcc40fe74f3696f3f6 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 18 Dec 2021 07:52:30 +0900 Subject: [PATCH] sd-radv: send RA when prefix is updated --- src/libsystemd-network/sd-radv.c | 50 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c index f8ffb6358f5..a305171902c 100644 --- a/src/libsystemd-network/sd-radv.c +++ b/src/libsystemd-network/sd-radv.c @@ -617,7 +617,8 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { strna(addr_p), FORMAT_TIMESPAN(p->lifetime_preferred_usec, USEC_PER_SEC), FORMAT_TIMESPAN(p->lifetime_valid_usec, USEC_PER_SEC)); - return 0; + + goto announce; } _cleanup_free_ char *addr_cur = NULL; @@ -631,19 +632,21 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { LIST_APPEND(prefix, ra->prefixes, p); ra->n_prefixes++; - if (ra->state == RADV_STATE_IDLE) { - log_radv(ra, "Added prefix %s", strna(addr_p)); + log_radv(ra, "Added prefix %s", strna(addr_p)); + + if (ra->state == RADV_STATE_IDLE) + return 0; + +announce: + if (ra->ra_sent == 0) return 0; - } /* 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_usec); - if (r < 0) - log_radv_errno(ra, r, "Unable to send Router Advertisement for added prefix: %m"); - else - log_radv(ra, "Sent Router Advertisement for added prefix"); - } + 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 + log_radv(ra, "Sent Router Advertisement for added/updated prefix"); return 0; } @@ -709,7 +712,8 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { log_radv(ra, "Updated/replaced IPv6 route prefix %s (lifetime: %s)", strna(addr_p), FORMAT_TIMESPAN(p->lifetime_usec, USEC_PER_SEC)); - return 0; + + goto announce; } _cleanup_free_ char *addr_cur = NULL; @@ -723,19 +727,21 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { LIST_APPEND(prefix, ra->route_prefixes, p); ra->n_route_prefixes++; - if (ra->state == RADV_STATE_IDLE) { - log_radv(ra, "Added route prefix %s", strna(addr_p)); + log_radv(ra, "Added route prefix %s", strna(addr_p)); + + if (ra->state == RADV_STATE_IDLE) + return 0; + +announce: + if (ra->ra_sent == 0) return 0; - } /* 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_usec); - if (r < 0) - log_radv_errno(ra, r, "Unable to send Router Advertisement for added route prefix: %m"); - else - log_radv(ra, "Sent Router Advertisement for added route prefix"); - } + 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 + log_radv(ra, "Sent Router Advertisement for added route prefix"); return 0; }