network/ndisc: drop onlink prefix when valid lifetime is zero
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 11 Apr 2024 19:38:42 +0000 (04:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 11 Apr 2024 21:12:03 +0000 (06:12 +0900)
Replaces 155d7a2c049cf866a0bfde8de371f09dfb3b6f29.

src/network/networkd-ndisc.c

index 65d2f82286cad7bdbfaa50fcb16137f57fc24981..5d1c895f0d81e70f11585047697ce14d2e93fc2c 100644 (file)
@@ -1224,9 +1224,23 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
         route->pref = preference;
         route->lifetime_usec = lifetime_usec;
 
-        r = ndisc_request_router_route(route, link, rt);
-        if (r < 0)
-                return log_link_warning_errno(link, r, "Could not request prefix route: %m");
+        /* RFC 4861 section 6.3.4:
+         * - If the prefix is not already present in the Prefix List, and the Prefix Information option's
+         *   Valid Lifetime field is non-zero, create a new entry for the prefix and initialize its
+         *   invalidation timer to the Valid Lifetime value in the Prefix Information option.
+         *
+         * - If the prefix is already present in the host's Prefix List as the result of a previously
+         *   received advertisement, reset its invalidation timer to the Valid Lifetime value in the Prefix
+         *   Information option. If the new Lifetime value is zero, time-out the prefix immediately. */
+        if (lifetime_usec == 0) {
+                r = ndisc_remove_route(route, link);
+                if (r < 0)
+                        return log_link_warning_errno(link, r, "Failed to remove prefix route: %m");
+        } else {
+                r = ndisc_request_router_route(route, link, rt);
+                if (r < 0)
+                        return log_link_warning_errno(link, r, "Failed to request prefix route: %m");
+        }
 
         return 0;
 }