]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/ndisc: do not try to set too large value for ICMP ratelimting
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 12 Jan 2024 01:00:31 +0000 (10:00 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 12 Jan 2024 14:38:30 +0000 (14:38 +0000)
Follow-up for 6197db53ba3c61de2268eb723a7a9cd4b3f5f87c.

When we set too large value, the kernel just refuse it. So, this does
not change the net behavior.

Prompted by https://github.com/systemd/systemd/pull/30490#discussion_r1449477125.

src/network/networkd-ndisc.c

index 61dc7acb83f54489efae5f1c581cee527c7226bd..7bb2825b3c2d745171293f91c2855749800467bf 100644 (file)
@@ -358,8 +358,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
 }
 
 static int ndisc_router_process_icmp6_ratelimit(Link *link, sd_ndisc_router *rt) {
-        char buf[DECIMAL_STR_MAX(usec_t)];
-        usec_t icmp6_ratelimit;
+        usec_t icmp6_ratelimit, msec;
         int r;
 
         assert(link);
@@ -375,14 +374,17 @@ static int ndisc_router_process_icmp6_ratelimit(Link *link, sd_ndisc_router *rt)
                 return 0;
         }
 
+        /* We do not allow 0 here. */
         if (!timestamp_is_set(icmp6_ratelimit))
                 return 0;
 
+        msec = DIV_ROUND_UP(icmp6_ratelimit, USEC_PER_MSEC);
+        if (msec <= 0 || msec > INT_MAX)
+                return 0;
+
         /* Limit the maximal rates for sending ICMPv6 packets. 0 to disable any limiting, otherwise the
          * minimal space between responses in milliseconds. Default: 1000. */
-        xsprintf(buf, USEC_FMT, DIV_ROUND_UP(icmp6_ratelimit, USEC_PER_MSEC));
-
-        r = sysctl_write_ip_property(AF_INET6, NULL, "icmp/ratelimit", buf);
+        r = sysctl_write_ip_property_int(AF_INET6, NULL, "icmp/ratelimit", (int) msec);
         if (r < 0)
                 log_link_warning_errno(link, r, "Failed to apply ICMP6 ratelimit, ignoring: %m");