ryantimwilson / rpms / systemd

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