]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/sysctl-util.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include "stdio-util.h"
9 #include "string-util.h"
11 char *sysctl_normalize(char *s
);
12 int sysctl_read(const char *property
, char **value
);
13 int sysctl_write(const char *property
, const char *value
);
14 int sysctl_writef(const char *property
, const char *format
, ...) _printf_(2, 3);
16 int sysctl_read_ip_property(int af
, const char *ifname
, const char *property
, char **ret
);
17 int sysctl_write_ip_property(int af
, const char *ifname
, const char *property
, const char *value
);
18 static inline int sysctl_write_ip_property_boolean(int af
, const char *ifname
, const char *property
, bool value
) {
19 return sysctl_write_ip_property(af
, ifname
, property
, one_zero(value
));
22 int sysctl_write_ip_neighbor_property(int af
, const char *ifname
, const char *property
, const char *value
);
23 static inline int sysctl_write_ip_neighbor_property_uint32(int af
, const char *ifname
, const char *property
, uint32_t value
) {
24 char buf
[DECIMAL_STR_MAX(uint32_t)];
25 xsprintf(buf
, "%u", value
);
26 return sysctl_write_ip_neighbor_property(af
, ifname
, property
, buf
);
29 #define DEFINE_SYSCTL_WRITE_IP_PROPERTY(name, type, format) \
30 static inline int sysctl_write_ip_property_##name(int af, const char *ifname, const char *property, type value) { \
31 char buf[DECIMAL_STR_MAX(type)]; \
32 xsprintf(buf, format, value); \
33 return sysctl_write_ip_property(af, ifname, property, buf); \
36 DEFINE_SYSCTL_WRITE_IP_PROPERTY(int, int, "%i");
37 DEFINE_SYSCTL_WRITE_IP_PROPERTY(uint32
, uint32_t, "%" PRIu32
);