mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
sysctl-util: make sysctl_read_ip_property() a wrapper around sysctl_read()
let's do what we did for sysctl_write()/sysctl_write_ip_property() also for the read paths: i.e. make one a wrapper of the other, and add more careful input validation.
This commit is contained in:
parent
f9755203b9
commit
d1469b7095
@ -118,24 +118,20 @@ int sysctl_read(const char *property, char **ret) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int sysctl_read_ip_property(int af, const char *ifname, const char *property, char **ret) {
|
int sysctl_read_ip_property(int af, const char *ifname, const char *property, char **ret) {
|
||||||
_cleanup_free_ char *value = NULL;
|
|
||||||
const char *p;
|
const char *p;
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(IN_SET(af, AF_INET, AF_INET6));
|
|
||||||
assert(property);
|
assert(property);
|
||||||
|
|
||||||
p = strjoina("/proc/sys/net/ipv", af == AF_INET ? "4" : "6",
|
if (!IN_SET(af, AF_INET, AF_INET6))
|
||||||
ifname ? "/conf/" : "", strempty(ifname),
|
return -EAFNOSUPPORT;
|
||||||
property[0] == '/' ? "" : "/", property);
|
|
||||||
|
|
||||||
r = read_full_virtual_file(p, &value, NULL);
|
if (ifname) {
|
||||||
if (r < 0)
|
if (!ifname_valid_full(ifname, IFNAME_VALID_SPECIAL))
|
||||||
return r;
|
return -EINVAL;
|
||||||
|
|
||||||
truncate_nl(value);
|
p = strjoina("net/", af_to_ipv4_ipv6(af), "/conf/", ifname, "/", property);
|
||||||
if (ret)
|
} else
|
||||||
*ret = TAKE_PTR(value);
|
p = strjoina("net/", af_to_ipv4_ipv6(af), "/", property);
|
||||||
|
|
||||||
return r;
|
return sysctl_read(p, ret);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user