daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
a8c905
From 8db22aec9bfd140855b64f2879b7ca6d1cba69c6 Mon Sep 17 00:00:00 2001
a8c905
From: Yu Watanabe <watanabe.yu+github@gmail.com>
a8c905
Date: Tue, 17 Dec 2019 18:28:36 +0900
a8c905
Subject: [PATCH] sd-netlink: introduce rtnl_resolve_link_alternative_names()
a8c905
a8c905
(cherry picked from commit b04c5e51da7a61d41d564e73a1e92bd8b29b0223)
a8c905
a8c905
Related: #1850986
a8c905
---
a8c905
 src/libsystemd/sd-netlink/netlink-types.c |  1 +
a8c905
 src/libsystemd/sd-netlink/netlink-util.c  | 29 +++++++++++++++++++++++
a8c905
 src/libsystemd/sd-netlink/netlink-util.h  |  1 +
a8c905
 3 files changed, 31 insertions(+)
a8c905
a8c905
diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c
a8c905
index 47d9c7f1c4..e118a0aa30 100644
a8c905
--- a/src/libsystemd/sd-netlink/netlink-types.c
a8c905
+++ b/src/libsystemd/sd-netlink/netlink-types.c
a8c905
@@ -511,6 +511,7 @@ static const NLType rtnl_link_types[] = {
a8c905
         [IFLA_PHYS_PORT_ID]     = { .type = NETLINK_TYPE_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
a8c905
 */
a8c905
         [IFLA_PROP_LIST]        = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_prop_list_type_system },
a8c905
+        [IFLA_ALT_IFNAME]       = { .type = NETLINK_TYPE_STRING, .size = ALTIFNAMSIZ - 1 },
a8c905
 };
a8c905
 
a8c905
 static const NLTypeSystem rtnl_link_type_system = {
a8c905
diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c
a8c905
index c1c306f121..62fc71a3d8 100644
a8c905
--- a/src/libsystemd/sd-netlink/netlink-util.c
a8c905
+++ b/src/libsystemd/sd-netlink/netlink-util.c
a8c905
@@ -120,6 +120,35 @@ int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const
a8c905
         return 0;
a8c905
 }
a8c905
 
a8c905
+int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name, int *ret) {
a8c905
+        _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL, *reply = NULL;
a8c905
+        int r;
a8c905
+
a8c905
+        assert(rtnl);
a8c905
+        assert(name);
a8c905
+        assert(ret);
a8c905
+
a8c905
+        if (!*rtnl) {
a8c905
+                r = sd_netlink_open(rtnl);
a8c905
+                if (r < 0)
a8c905
+                        return r;
a8c905
+        }
a8c905
+
a8c905
+        r = sd_rtnl_message_new_link(*rtnl, &message, RTM_GETLINK, 0);
a8c905
+        if (r < 0)
a8c905
+                return r;
a8c905
+
a8c905
+        r = sd_netlink_message_append_string(message, IFLA_ALT_IFNAME, name);
a8c905
+        if (r < 0)
a8c905
+                return r;
a8c905
+
a8c905
+        r = sd_netlink_call(*rtnl, message, 0, &reply);
a8c905
+        if (r < 0)
a8c905
+                return r;
a8c905
+
a8c905
+        return sd_rtnl_message_link_get_ifindex(reply, ret);
a8c905
+}
a8c905
+
a8c905
 int rtnl_message_new_synthetic_error(sd_netlink *rtnl, int error, uint32_t serial, sd_netlink_message **ret) {
a8c905
         struct nlmsgerr *err;
a8c905
         int r;
a8c905
diff --git a/src/libsystemd/sd-netlink/netlink-util.h b/src/libsystemd/sd-netlink/netlink-util.h
a8c905
index 92de19c092..ea98439fad 100644
a8c905
--- a/src/libsystemd/sd-netlink/netlink-util.h
a8c905
+++ b/src/libsystemd/sd-netlink/netlink-util.h
a8c905
@@ -39,6 +39,7 @@ static inline bool rtnl_message_type_is_routing_policy_rule(uint16_t type) {
a8c905
 int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name);
a8c905
 int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, uint32_t mtu);
a8c905
 int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names);
a8c905
+int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name, int *ret);
a8c905
 
a8c905
 int rtnl_log_parse_error(int r);
a8c905
 int rtnl_log_create_error(int r);