|
|
be0c12 |
From c6b2c2fb577d20879b5b4c610c4c29bac259beab Mon Sep 17 00:00:00 2001
|
|
|
be0c12 |
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
|
be0c12 |
Date: Fri, 17 Jul 2020 21:29:13 +0900
|
|
|
be0c12 |
Subject: [PATCH] netlink: introduce rtnl_get/delete_link_alternative_names()
|
|
|
be0c12 |
|
|
|
be0c12 |
(cherry picked from commit 14982526145de84201c7e3b4fc6be6aa5e9a08f7)
|
|
|
be0c12 |
|
|
|
be0c12 |
Related: #2005008
|
|
|
be0c12 |
---
|
|
|
be0c12 |
src/libsystemd/sd-netlink/netlink-util.c | 45 ++++++++++++++++++++++--
|
|
|
be0c12 |
src/libsystemd/sd-netlink/netlink-util.h | 2 ++
|
|
|
be0c12 |
2 files changed, 45 insertions(+), 2 deletions(-)
|
|
|
be0c12 |
|
|
|
be0c12 |
diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c
|
|
|
be0c12 |
index 62fc71a3d8..7f09261981 100644
|
|
|
be0c12 |
--- a/src/libsystemd/sd-netlink/netlink-util.c
|
|
|
be0c12 |
+++ b/src/libsystemd/sd-netlink/netlink-util.c
|
|
|
be0c12 |
@@ -81,12 +81,45 @@ int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias,
|
|
|
be0c12 |
return 0;
|
|
|
be0c12 |
}
|
|
|
be0c12 |
|
|
|
be0c12 |
-int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names) {
|
|
|
be0c12 |
+int rtnl_get_link_alternative_names(sd_netlink **rtnl, int ifindex, char ***ret) {
|
|
|
be0c12 |
+ _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL, *reply = NULL;
|
|
|
be0c12 |
+ _cleanup_strv_free_ char **names = NULL;
|
|
|
be0c12 |
+ int r;
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+ assert(rtnl);
|
|
|
be0c12 |
+ assert(ifindex > 0);
|
|
|
be0c12 |
+ assert(ret);
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+ if (!*rtnl) {
|
|
|
be0c12 |
+ r = sd_netlink_open(rtnl);
|
|
|
be0c12 |
+ if (r < 0)
|
|
|
be0c12 |
+ return r;
|
|
|
be0c12 |
+ }
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+ r = sd_rtnl_message_new_link(*rtnl, &message, RTM_GETLINK, ifindex);
|
|
|
be0c12 |
+ if (r < 0)
|
|
|
be0c12 |
+ return r;
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+ r = sd_netlink_call(*rtnl, message, 0, &reply);
|
|
|
be0c12 |
+ if (r < 0)
|
|
|
be0c12 |
+ return r;
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+ r = sd_netlink_message_read_strv(reply, IFLA_PROP_LIST, IFLA_ALT_IFNAME, &names);
|
|
|
be0c12 |
+ if (r < 0 && r != -ENODATA)
|
|
|
be0c12 |
+ return r;
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+ *ret = TAKE_PTR(names);
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+ return 0;
|
|
|
be0c12 |
+}
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+static int rtnl_update_link_alternative_names(sd_netlink **rtnl, uint16_t nlmsg_type, int ifindex, char * const *alternative_names) {
|
|
|
be0c12 |
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
|
|
|
be0c12 |
int r;
|
|
|
be0c12 |
|
|
|
be0c12 |
assert(rtnl);
|
|
|
be0c12 |
assert(ifindex > 0);
|
|
|
be0c12 |
+ assert(IN_SET(nlmsg_type, RTM_NEWLINKPROP, RTM_DELLINKPROP));
|
|
|
be0c12 |
|
|
|
be0c12 |
if (strv_isempty(alternative_names))
|
|
|
be0c12 |
return 0;
|
|
|
be0c12 |
@@ -97,7 +130,7 @@ int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const
|
|
|
be0c12 |
return r;
|
|
|
be0c12 |
}
|
|
|
be0c12 |
|
|
|
be0c12 |
- r = sd_rtnl_message_new_link(*rtnl, &message, RTM_NEWLINKPROP, ifindex);
|
|
|
be0c12 |
+ r = sd_rtnl_message_new_link(*rtnl, &message, nlmsg_type, ifindex);
|
|
|
be0c12 |
if (r < 0)
|
|
|
be0c12 |
return r;
|
|
|
be0c12 |
|
|
|
be0c12 |
@@ -120,6 +153,14 @@ int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const
|
|
|
be0c12 |
return 0;
|
|
|
be0c12 |
}
|
|
|
be0c12 |
|
|
|
be0c12 |
+int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names) {
|
|
|
be0c12 |
+ return rtnl_update_link_alternative_names(rtnl, RTM_NEWLINKPROP, ifindex, alternative_names);
|
|
|
be0c12 |
+}
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+int rtnl_delete_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names) {
|
|
|
be0c12 |
+ return rtnl_update_link_alternative_names(rtnl, RTM_DELLINKPROP, ifindex, alternative_names);
|
|
|
be0c12 |
+}
|
|
|
be0c12 |
+
|
|
|
be0c12 |
int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name, int *ret) {
|
|
|
be0c12 |
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL, *reply = NULL;
|
|
|
be0c12 |
int r;
|
|
|
be0c12 |
diff --git a/src/libsystemd/sd-netlink/netlink-util.h b/src/libsystemd/sd-netlink/netlink-util.h
|
|
|
be0c12 |
index ea98439fad..4fc31aa274 100644
|
|
|
be0c12 |
--- a/src/libsystemd/sd-netlink/netlink-util.h
|
|
|
be0c12 |
+++ b/src/libsystemd/sd-netlink/netlink-util.h
|
|
|
be0c12 |
@@ -38,7 +38,9 @@ static inline bool rtnl_message_type_is_routing_policy_rule(uint16_t type) {
|
|
|
be0c12 |
|
|
|
be0c12 |
int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name);
|
|
|
be0c12 |
int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, uint32_t mtu);
|
|
|
be0c12 |
+int rtnl_get_link_alternative_names(sd_netlink **rtnl, int ifindex, char ***ret);
|
|
|
be0c12 |
int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names);
|
|
|
be0c12 |
+int rtnl_delete_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names);
|
|
|
be0c12 |
int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name, int *ret);
|
|
|
be0c12 |
|
|
|
be0c12 |
int rtnl_log_parse_error(int r);
|