diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-12-17 10:28:36 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-12-17 16:05:50 +0100 |
commit | b04c5e51da7a61d41d564e73a1e92bd8b29b0223 (patch) | |
tree | 7bf6b520d6233d8fd60c6333f7a196e05be7f039 /src/libsystemd | |
parent | Merge pull request #14267 from poettering/pkcs11-cryptsetup (diff) | |
download | systemd-b04c5e51da7a61d41d564e73a1e92bd8b29b0223.tar.xz systemd-b04c5e51da7a61d41d564e73a1e92bd8b29b0223.zip |
sd-netlink: introduce rtnl_resolve_link_alternative_names()
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-types.c | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-util.c | 29 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-util.h | 1 |
3 files changed, 31 insertions, 0 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c index bf9f35b88c..6220a8d0b2 100644 --- a/src/libsystemd/sd-netlink/netlink-types.c +++ b/src/libsystemd/sd-netlink/netlink-types.c @@ -593,6 +593,7 @@ static const NLType rtnl_link_types[] = { [IFLA_MIN_MTU] = { .type = NETLINK_TYPE_U32 }, [IFLA_MAX_MTU] = { .type = NETLINK_TYPE_U32 }, [IFLA_PROP_LIST] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_prop_list_type_system }, + [IFLA_ALT_IFNAME] = { .type = NETLINK_TYPE_STRING, .size = ALTIFNAMSIZ - 1 }, }; static const NLTypeSystem rtnl_link_type_system = { diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c index bd9412a63b..80725f6cb4 100644 --- a/src/libsystemd/sd-netlink/netlink-util.c +++ b/src/libsystemd/sd-netlink/netlink-util.c @@ -123,6 +123,35 @@ int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const return 0; } +int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name, int *ret) { + _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL, *reply = NULL; + int r; + + assert(rtnl); + assert(name); + assert(ret); + + if (!*rtnl) { + r = sd_netlink_open(rtnl); + if (r < 0) + return r; + } + + r = sd_rtnl_message_new_link(*rtnl, &message, RTM_GETLINK, 0); + if (r < 0) + return r; + + r = sd_netlink_message_append_string(message, IFLA_ALT_IFNAME, name); + if (r < 0) + return r; + + r = sd_netlink_call(*rtnl, message, 0, &reply); + if (r < 0) + return r; + + return sd_rtnl_message_link_get_ifindex(reply, ret); +} + int rtnl_message_new_synthetic_error(sd_netlink *rtnl, int error, uint32_t serial, sd_netlink_message **ret) { struct nlmsgerr *err; int r; diff --git a/src/libsystemd/sd-netlink/netlink-util.h b/src/libsystemd/sd-netlink/netlink-util.h index 42c8917219..8c43fafec7 100644 --- a/src/libsystemd/sd-netlink/netlink-util.h +++ b/src/libsystemd/sd-netlink/netlink-util.h @@ -50,6 +50,7 @@ static inline bool rtnl_message_type_is_qdisc(uint16_t type) { int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name); int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, uint32_t mtu); int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names); +int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name, int *ret); int rtnl_log_parse_error(int r); int rtnl_log_create_error(int r); |