diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-01-11 11:21:01 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-01-12 11:24:35 +0100 |
commit | d308bb99d20b45fed1923ed6b893a59dbac02eca (patch) | |
tree | 085a0d8b68470695146ee584bd60b402c34cd4d8 /src/shared/socket-netlink.c | |
parent | fc2ea97ad03baaa480253034b2f709e82bbc0fe1 (diff) | |
download | systemd-d308bb99d20b45fed1923ed6b893a59dbac02eca.tar.gz |
Resolve alternative ifnames wherever we would resolve an interface name
To keep the names manageable, "ifname_or_ifindex" is replaced by "interface".
Diffstat (limited to 'src/shared/socket-netlink.c')
-rw-r--r-- | src/shared/socket-netlink.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/shared/socket-netlink.c b/src/shared/socket-netlink.c index 3fb7356317..5177137b99 100644 --- a/src/shared/socket-netlink.c +++ b/src/shared/socket-netlink.c @@ -30,6 +30,30 @@ int resolve_ifname(sd_netlink **rtnl, const char *name) { return rtnl_resolve_link_alternative_name(rtnl, name); } +int resolve_interface(sd_netlink **rtnl, const char *name) { + int r; + + /* Like resolve_ifname, but resolves interface numbers too. */ + + assert(name); + + r = parse_ifindex(name); + if (r > 0) + return r; + assert(r < 0); + + return resolve_ifname(rtnl, name); +} + +int resolve_interface_or_warn(sd_netlink **rtnl, const char *name) { + int r; + + r = resolve_interface(rtnl, name); + if (r < 0) + return log_error_errno(r, "Failed to resolve interface \"%s\": %m", name); + return r; +} + int socket_address_parse(SocketAddress *a, const char *s) { _cleanup_free_ char *n = NULL; char *e; @@ -318,7 +342,7 @@ int in_addr_ifindex_from_string_auto(const char *s, int *family, union in_addr_u if (suffix) { if (ret_ifindex) { /* If we shall return the interface index, try to parse it */ - ifindex = parse_ifindex_or_ifname(suffix + 1); + ifindex = resolve_interface(NULL, suffix + 1); if (ifindex < 0) return ifindex; } |