diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-02-18 13:34:01 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-02-21 10:38:10 +0900 |
commit | 3decde0226f5aabece893a413d9b5fb825da7cb4 (patch) | |
tree | 2b7c17d112fcb4075d0baad374f37e2aa23fefe3 /src/shared/sysctl-util.h | |
parent | 56ee4d7001a162a7a526a10482c3007a7115539f (diff) | |
download | systemd-3decde0226f5aabece893a413d9b5fb825da7cb4.tar.gz |
sysctl-util: introduce sysctl_write_ip_property() and friends
Diffstat (limited to 'src/shared/sysctl-util.h')
-rw-r--r-- | src/shared/sysctl-util.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/shared/sysctl-util.h b/src/shared/sysctl-util.h index fd7c78b2b8..940118c258 100644 --- a/src/shared/sysctl-util.h +++ b/src/shared/sysctl-util.h @@ -1,7 +1,28 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once +#include <stdbool.h> +#include <stdint.h> + +#include "macro.h" +#include "stdio-util.h" +#include "util.h" + char *sysctl_normalize(char *s); int sysctl_read(const char *property, char **value); int sysctl_write(const char *property, const char *value); +int sysctl_write_ip_property(int af, const char *ifname, const char *property, const char *value); +static inline int sysctl_write_ip_property_boolean(int af, const char *ifname, const char *property, bool value) { + return sysctl_write_ip_property(af, ifname, property, one_zero(value)); +} + +#define DEFINE_SYSCTL_WRITE_IP_PROPERTY(name, type, format) \ + static inline int sysctl_write_ip_property_##name(int af, const char *ifname, const char *property, type value) { \ + char buf[DECIMAL_STR_MAX(type)]; \ + xsprintf(buf, format, value); \ + return sysctl_write_ip_property(af, ifname, property, buf); \ + } + +DEFINE_SYSCTL_WRITE_IP_PROPERTY(int, int, "%i"); +DEFINE_SYSCTL_WRITE_IP_PROPERTY(uint32, uint32_t, "%" PRIu32); |