]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/route: use sysctl_read_ip_property_int() for reading route/max_size
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 Oct 2024 21:52:19 +0000 (06:52 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 Oct 2024 21:52:19 +0000 (06:52 +0900)
src/network/networkd-route-util.c

index 9bb1e0f70703ad5b9be09987146df921ce609260..dc9663e24b6a03f4d52b636e37c5a8f498d0a11c 100644 (file)
 #include "strv.h"
 #include "sysctl-util.h"
 
-#define ROUTES_DEFAULT_MAX_PER_FAMILY 4096U
+#define ROUTES_DEFAULT_MAX_PER_FAMILY 4096
 
 unsigned routes_max(void) {
         static thread_local unsigned cached = 0;
-        _cleanup_free_ char *s4 = NULL, *s6 = NULL;
-        unsigned val4 = ROUTES_DEFAULT_MAX_PER_FAMILY, val6 = ROUTES_DEFAULT_MAX_PER_FAMILY;
+        int val4 = ROUTES_DEFAULT_MAX_PER_FAMILY, val6 = ROUTES_DEFAULT_MAX_PER_FAMILY;
 
         if (cached > 0)
                 return cached;
 
-        if (sysctl_read_ip_property(AF_INET, NULL, "route/max_size", &s4) >= 0)
-                if (safe_atou(s4, &val4) >= 0 && val4 == 2147483647U)
+        /* The kernel internally stores these maximum size in int. */
+
+        if (sysctl_read_ip_property_int(AF_INET, /* ifname = */ NULL, "route/max_size", &val4) >= 0)
+                if (val4 == INT_MAX)
                         /* This is the default "no limit" value in the kernel */
                         val4 = ROUTES_DEFAULT_MAX_PER_FAMILY;
 
-        if (sysctl_read_ip_property(AF_INET6, NULL, "route/max_size", &s6) >= 0)
-                (void) safe_atou(s6, &val6);
+        if (sysctl_read_ip_property_int(AF_INET6, /* ifname = */ NULL, "route/max_size", &val6) >= 0)
+                if (val6 == INT_MAX)
+                        /* This is the default "no limit" value in the kernel */
+                        val6 = ROUTES_DEFAULT_MAX_PER_FAMILY;
 
         cached = MAX(ROUTES_DEFAULT_MAX_PER_FAMILY, val4) +
                  MAX(ROUTES_DEFAULT_MAX_PER_FAMILY, val6);