summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-12-18 13:54:13 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-01-11 12:06:08 +0100
commit597da51bae9e46a93b310125174d48c9438d3bab (patch)
treedb481a70aa76af1d7b02ed8f8ae5792e883645d8 /src/basic
parent0e05be8405132fb392bc0bd01ea520e58d447467 (diff)
downloadsystemd-597da51bae9e46a93b310125174d48c9438d3bab.tar.gz
tree-wide: make parse_ifindex simply return the index
We don't need a seperate output parameter that is of type int. glibc() says that the type is "unsigned", but the kernel thinks it's "int". And the "alternative names" interface also uses ints. So let's standarize on ints, since it's clearly not realisitic to have interface numbers in the upper half of unsigned int range.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/in-addr-util.c32
-rw-r--r--src/basic/parse-util.c17
-rw-r--r--src/basic/parse-util.h4
3 files changed, 20 insertions, 33 deletions
diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c
index 06b92db579..b6ca27e3e8 100644
--- a/src/basic/in-addr-util.c
+++ b/src/basic/in-addr-util.c
@@ -439,48 +439,38 @@ int in_addr_from_string_auto(const char *s, int *ret_family, union in_addr_union
return -EINVAL;
}
-int in_addr_ifindex_from_string_auto(const char *s, int *family, union in_addr_union *ret, int *ifindex) {
+int in_addr_ifindex_from_string_auto(const char *s, int *family, union in_addr_union *ret_addr, int *ret_ifindex) {
_cleanup_free_ char *buf = NULL;
const char *suffix;
- int r, ifi = 0;
+ int r, ifindex = 0;
assert(s);
assert(family);
- assert(ret);
+ assert(ret_addr);
/* Similar to in_addr_from_string_auto() but also parses an optionally appended IPv6 zone suffix ("scope id")
* if one is found. */
suffix = strchr(s, '%');
if (suffix) {
-
- if (ifindex) {
+ if (ret_ifindex) {
/* If we shall return the interface index, try to parse it */
- r = parse_ifindex(suffix + 1, &ifi);
- if (r < 0) {
- unsigned u;
-
- u = if_nametoindex(suffix + 1);
- if (u <= 0)
- return -errno;
-
- ifi = (int) u;
- }
+ ifindex = parse_ifindex_or_ifname(suffix + 1);
+ if (ifindex < 0)
+ return ifindex;
}
- buf = strndup(s, suffix - s);
+ s = buf = strndup(s, suffix - s);
if (!buf)
return -ENOMEM;
-
- s = buf;
}
- r = in_addr_from_string_auto(s, family, ret);
+ r = in_addr_from_string_auto(s, family, ret_addr);
if (r < 0)
return r;
- if (ifindex)
- *ifindex = ifi;
+ if (ret_ifindex)
+ *ret_ifindex = ifindex;
return r;
}
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
index b81db04989..d3140cc1a4 100644
--- a/src/basic/parse-util.c
+++ b/src/basic/parse-util.c
@@ -79,11 +79,10 @@ int parse_mode(const char *s, mode_t *ret) {
return 0;
}
-int parse_ifindex(const char *s, int *ret) {
+int parse_ifindex(const char *s) {
int ifi, r;
assert(s);
- assert(ret);
r = safe_atoi(s, &ifi);
if (r < 0)
@@ -91,26 +90,24 @@ int parse_ifindex(const char *s, int *ret) {
if (ifi <= 0)
return -EINVAL;
- *ret = ifi;
- return 0;
+ return ifi;
}
-int parse_ifindex_or_ifname(const char *s, int *ret) {
+int parse_ifindex_or_ifname(const char *s) {
int r;
assert(s);
- assert(ret);
- r = parse_ifindex(s, ret);
- if (r >= 0)
+ r = parse_ifindex(s);
+ if (r > 0)
return r;
+ assert(r < 0);
r = (int) if_nametoindex(s);
if (r <= 0)
return -errno;
- *ret = r;
- return 0;
+ return r;
}
int parse_mtu(int family, const char *s, uint32_t *ret) {
diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h
index 3a70b79276..b20f5b52cc 100644
--- a/src/basic/parse-util.h
+++ b/src/basic/parse-util.h
@@ -13,8 +13,8 @@ int parse_boolean(const char *v) _pure_;
int parse_dev(const char *s, dev_t *ret);
int parse_pid(const char *s, pid_t* ret_pid);
int parse_mode(const char *s, mode_t *ret);
-int parse_ifindex(const char *s, int *ret);
-int parse_ifindex_or_ifname(const char *s, int *ret);
+int parse_ifindex(const char *s);
+int parse_ifindex_or_ifname(const char *s);
int parse_mtu(int family, const char *s, uint32_t *ret);
int parse_size(const char *t, uint64_t base, uint64_t *size);