You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.4 KiB
67 lines
2.4 KiB
From 9b6a3b192ba0f22ce99aa5c48c6c7143d12dddba Mon Sep 17 00:00:00 2001
|
|
From: Nick Rosbrook <nick.rosbrook@canonical.com>
|
|
Date: Wed, 2 Nov 2022 05:36:14 -0400
|
|
Subject: [PATCH] sd-netlink: restore altname on error in rtnl_set_link_name
|
|
|
|
If a current alternative name is to be used to rename a network
|
|
interface, the alternative name must be removed first. If interface
|
|
renaming fails, restore the alternative name that was deleted if
|
|
necessary.
|
|
|
|
(cherry picked from commit 4d600667f8af2985850b03a46357e068d3fb8570)
|
|
|
|
Related: RHEL-5988
|
|
---
|
|
src/libsystemd/sd-netlink/netlink-util.c | 19 ++++++++++++++++---
|
|
1 file changed, 16 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c
|
|
index 6b4c25fe5a..cfcf2578d6 100644
|
|
--- a/src/libsystemd/sd-netlink/netlink-util.c
|
|
+++ b/src/libsystemd/sd-netlink/netlink-util.c
|
|
@@ -14,6 +14,7 @@
|
|
int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name) {
|
|
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
|
|
_cleanup_strv_free_ char **alternative_names = NULL;
|
|
+ bool altname_deleted = false;
|
|
int r;
|
|
|
|
assert(rtnl);
|
|
@@ -33,21 +34,33 @@ int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name) {
|
|
if (r < 0)
|
|
return log_debug_errno(r, "Failed to remove '%s' from alternative names on network interface %i: %m",
|
|
name, ifindex);
|
|
+
|
|
+ altname_deleted = true;
|
|
}
|
|
|
|
r = sd_rtnl_message_new_link(*rtnl, &message, RTM_SETLINK, ifindex);
|
|
if (r < 0)
|
|
- return r;
|
|
+ goto fail;
|
|
|
|
r = sd_netlink_message_append_string(message, IFLA_IFNAME, name);
|
|
if (r < 0)
|
|
- return r;
|
|
+ goto fail;
|
|
|
|
r = sd_netlink_call(*rtnl, message, 0, NULL);
|
|
if (r < 0)
|
|
- return r;
|
|
+ goto fail;
|
|
|
|
return 0;
|
|
+
|
|
+fail:
|
|
+ if (altname_deleted) {
|
|
+ int q = rtnl_set_link_alternative_names(rtnl, ifindex, STRV_MAKE(name));
|
|
+ if (q < 0)
|
|
+ log_debug_errno(q, "Failed to restore '%s' as an alternative name on network interface %i, ignoring: %m",
|
|
+ name, ifindex);
|
|
+ }
|
|
+
|
|
+ return r;
|
|
}
|
|
|
|
int rtnl_set_link_properties(
|