ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
a8c905
From 817a707daf1e9fa4f20eba04ce1c52af7518e355 Mon Sep 17 00:00:00 2001
a8c905
From: Yu Watanabe <watanabe.yu+github@gmail.com>
a8c905
Date: Fri, 17 Jul 2020 21:36:05 +0900
a8c905
Subject: [PATCH] udev: do not try to reassign alternative names
a8c905
a8c905
Setting alternative names may fail if some of them are already assigned.
a8c905
a8c905
(cherry picked from commit 97fdae33dfe8e7e0a4e5230564f6cdebc4450eec)
a8c905
a8c905
Related: #1850986
a8c905
---
a8c905
 src/udev/net/link-config.c | 12 ++++++++++--
a8c905
 1 file changed, 10 insertions(+), 2 deletions(-)
a8c905
a8c905
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
a8c905
index 8bd374d352..5220f247f0 100644
a8c905
--- a/src/udev/net/link-config.c
a8c905
+++ b/src/udev/net/link-config.c
a8c905
@@ -350,7 +350,7 @@ static int get_mac(struct udev_device *device, bool want_random,
a8c905
 
a8c905
 int link_config_apply(link_config_ctx *ctx, link_config *config,
a8c905
                       struct udev_device *device, const char **name) {
a8c905
-        _cleanup_strv_free_ char **altnames = NULL;
a8c905
+        _cleanup_strv_free_ char **altnames = NULL, **current_altnames = NULL;
a8c905
         bool respect_predictable = false;
a8c905
         struct ether_addr generated_mac;
a8c905
         struct ether_addr *mac = NULL;
a8c905
@@ -514,9 +514,17 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
a8c905
         if (new_name)
a8c905
                 strv_remove(altnames, new_name);
a8c905
         strv_remove(altnames, old_name);
a8c905
+
a8c905
+        r = rtnl_get_link_alternative_names(&ctx->rtnl, ifindex, &current_altnames);
a8c905
+        if (r < 0)
a8c905
+                log_debug_errno(r, "Failed to get alternative names on %s, ignoring: %m", old_name);
a8c905
+
a8c905
+        char **p;
a8c905
+        STRV_FOREACH(p, current_altnames)
a8c905
+                strv_remove(altnames, *p);
a8c905
+
a8c905
         strv_uniq(altnames);
a8c905
         strv_sort(altnames);
a8c905
-
a8c905
         r = rtnl_set_link_alternative_names(&ctx->rtnl, ifindex, altnames);
a8c905
         if (r == -EOPNOTSUPP)
a8c905
                 log_debug_errno(r, "Could not set AlternativeName= or apply AlternativeNamesPolicy= on %s, ignoring: %m", old_name);