dryang / rpms / systemd

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