network/route: use sysctl_read_ip_property_int() for reading route/max_size
This commit is contained in:
@@ -16,23 +16,26 @@
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user