]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/sysctl-util.h
Merge pull request #16112 from poettering/nss-systemd-block-fix
[thirdparty/systemd.git] / src / shared / sysctl-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
88a60da0
KS
2#pragma once
3
3decde02
YW
4#include <stdbool.h>
5#include <stdint.h>
6
7#include "macro.h"
8#include "stdio-util.h"
c16460cf 9#include "string-util.h"
3decde02 10
88a60da0
KS
11char *sysctl_normalize(char *s);
12int sysctl_read(const char *property, char **value);
13int sysctl_write(const char *property, const char *value);
162392b7 14int sysctl_writef(const char *property, const char *format, ...) _printf_(2, 3);
88a60da0 15
a6b3b0aa 16int sysctl_read_ip_property(int af, const char *ifname, const char *property, char **ret);
3decde02
YW
17int sysctl_write_ip_property(int af, const char *ifname, const char *property, const char *value);
18static 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));
20}
21
22#define DEFINE_SYSCTL_WRITE_IP_PROPERTY(name, type, format) \
23 static inline int sysctl_write_ip_property_##name(int af, const char *ifname, const char *property, type value) { \
24 char buf[DECIMAL_STR_MAX(type)]; \
25 xsprintf(buf, format, value); \
26 return sysctl_write_ip_property(af, ifname, property, buf); \
27 }
28
29DEFINE_SYSCTL_WRITE_IP_PROPERTY(int, int, "%i");
30DEFINE_SYSCTL_WRITE_IP_PROPERTY(uint32, uint32_t, "%" PRIu32);