sysctl-util: introduce sysctl_write_ip_property() and friends

This commit is contained in:
Yu Watanabe
2019-02-21 10:38:10 +09:00
parent 56ee4d7001
commit 3decde0226
2 changed files with 37 additions and 0 deletions
+16
View File
@@ -60,6 +60,22 @@ int sysctl_write(const char *property, const char *value) {
return 0;
}
int sysctl_write_ip_property(int af, const char *ifname, const char *property, const char *value) {
const char *p;
assert(IN_SET(af, AF_INET, AF_INET6));
assert(property);
assert(value);
p = strjoina("/proc/sys/net/ipv", af == AF_INET ? "4" : "6",
ifname ? "/conf/" : "", strempty(ifname),
property[0] == '/' ? "" : "/", property);
log_debug("Setting '%s' to '%s'", p, value);
return write_string_file(p, value, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
}
int sysctl_read(const char *property, char **content) {
char *p;