summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-netlink
diff options
context:
space:
mode:
authorNick Rosbrook <nick.rosbrook@canonical.com>2022-11-02 10:36:14 +0100
committerNick Rosbrook <nick.rosbrook@canonical.com>2022-12-15 15:35:26 +0100
commit4d600667f8af2985850b03a46357e068d3fb8570 (patch)
treede915f001f91fb246131ff04cb2fed73da28b5b0 /src/libsystemd/sd-netlink
parentsd-netlink: do not swap old name and alternative name (diff)
downloadsystemd-4d600667f8af2985850b03a46357e068d3fb8570.tar.xz
systemd-4d600667f8af2985850b03a46357e068d3fb8570.zip
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.
Diffstat (limited to '')
-rw-r--r--src/libsystemd/sd-netlink/netlink-util.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c
index a53ffb2616..af601bd347 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(