diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-05-29 03:56:55 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-05-29 06:22:01 +0200 |
commit | 8e5385b485955772133ff7d1b48dcdaa37b11225 (patch) | |
tree | bc27fee6befd8f8243ac0963b34432edd407defc /src/resolve/resolvectl.c | |
parent | util: add assertions (diff) | |
download | systemd-8e5385b485955772133ff7d1b48dcdaa37b11225.tar.xz systemd-8e5385b485955772133ff7d1b48dcdaa37b11225.zip |
resolvectl: use parse_ifindex_or_ifname()
Diffstat (limited to '')
-rw-r--r-- | src/resolve/resolvectl.c | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index 9637e00e60..8e4315d86a 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -76,24 +76,10 @@ typedef enum StatusMode { STATUS_NTA, } StatusMode; -static int parse_ifindex_and_warn(const char *s) { - int ifi; - - assert(s); - - if (parse_ifindex(s, &ifi) < 0) { - ifi = if_nametoindex(s); - if (ifi <= 0) - return log_error_errno(errno, "Unknown interface '%s': %m", s); - } - - return ifi; -} - int ifname_mangle(const char *s) { _cleanup_free_ char *iface = NULL; const char *dot; - int ifi; + int ifi, r; assert(s); @@ -107,16 +93,14 @@ int ifname_mangle(const char *s) { if (!iface) return log_oom(); - if (parse_ifindex(iface, &ifi) < 0) { - ifi = if_nametoindex(iface); - if (ifi <= 0) { - if (errno == ENODEV && arg_ifindex_permissive) { - log_debug("Interface '%s' not found, but -f specified, ignoring.", iface); - return 0; /* done */ - } - - return log_error_errno(errno, "Unknown interface '%s': %m", iface); + r = parse_ifindex_or_ifname(iface, &ifi); + if (r < 0) { + if (r == -ENODEV && arg_ifindex_permissive) { + log_debug("Interface '%s' not found, but -f specified, ignoring.", iface); + return 0; /* done */ } + + return log_error_errno(r, "Unknown interface '%s': %m", iface); } if (arg_ifindex > 0 && arg_ifindex != ifi) @@ -1843,9 +1827,11 @@ static int verb_status(int argc, char **argv, void *userdata) { STRV_FOREACH(ifname, argv + 1) { int ifindex; - ifindex = parse_ifindex_and_warn(*ifname); - if (ifindex < 0) + q = parse_ifindex_or_ifname(*ifname, &ifindex); + if (q < 0) { + log_error_errno(q, "Unknown interface '%s', ignoring: %m", *ifname); continue; + } q = status_ifindex(bus, ifindex, NULL, STATUS_ALL, &empty_line); if (q < 0) |