]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: dhcp6pd: gracefully handle delegated prefix whose prefixlen is larger than 64
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 4 Dec 2021 21:38:46 +0000 (06:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 7 Dec 2021 09:35:26 +0000 (18:35 +0900)
src/network/networkd-dhcp-prefix-delegation.c

index 0bc922d4000473b25582790df2ff2d3add1c6066..b388a9f882c5fe2cb2be5064a642fb6c484720af 100644 (file)
@@ -667,17 +667,17 @@ static int dhcp6_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *li
 
 static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *addr, uint8_t prefixlen, usec_t lifetime_usec) {
         _cleanup_(route_freep) Route *route = NULL;
-        _cleanup_free_ char *buf = NULL;
         Route *existing;
         int r;
 
         assert(link);
         assert(addr);
 
-        (void) in6_addr_prefix_to_string(addr, prefixlen, &buf);
+        if (prefixlen >= 64) {
+                _cleanup_free_ char *buf = NULL;
 
-        if (prefixlen == 64) {
-                log_link_debug(link, "Not adding a blocking route for DHCPv6 delegated subnet %s since distributed prefix is 64",
+                (void) in6_addr_prefix_to_string(addr, prefixlen, &buf);
+                log_link_debug(link, "Not adding a blocking route for DHCPv6 delegated prefix %s since the prefix has length >= 64.",
                                strna(buf));
                 return 0;
         }
@@ -703,9 +703,13 @@ static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *ad
 
         r = link_request_route(link, TAKE_PTR(route), true, &link->dhcp6_messages,
                                dhcp6_route_handler, NULL);
-        if (r < 0)
+        if (r < 0) {
+                _cleanup_free_ char *buf = NULL;
+
+                (void) in6_addr_prefix_to_string(addr, prefixlen, &buf);
                 return log_link_error_errno(link, r, "Failed to request unreachable route for DHCPv6 delegated subnet %s: %m",
                                             strna(buf));
+        }
 
         return 0;
 }
@@ -743,7 +747,7 @@ static int dhcp6_pd_prefix_add(Link *link, const struct in6_addr *prefix, uint8_
         if (r < 0)
                 return log_link_error_errno(link, r, "Failed to store DHCPv6 PD prefix %s: %m", strna(buf));
 
-        return prefixlen <= 64;
+        return 0;
 }
 
 static int dhcp6_pd_assign_prefixes(Link *link, Link *uplink) {
@@ -826,8 +830,6 @@ int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
                 r = dhcp6_pd_prefix_add(dhcp6_link, &pd_prefix, pd_prefix_len);
                 if (r < 0)
                         return r;
-                if (r == 0)
-                        continue;
 
                 r = dhcp6_request_unreachable_route(dhcp6_link, &pd_prefix, pd_prefix_len, lifetime_valid_usec);
                 if (r < 0)