daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
a8c905
From c76d050d8d61b4a63d4407bd03bd3f49cd9915ce Mon Sep 17 00:00:00 2001
a8c905
From: Yu Watanabe <watanabe.yu+github@gmail.com>
a8c905
Date: Sun, 15 Dec 2019 22:46:19 +0900
a8c905
Subject: [PATCH] network: make Name= in [Match] support alternative names of
a8c905
 interfaces
a8c905
a8c905
(cherry picked from commit 572b21d96cabd5860b0670e98440b6cb99a4b749
a8c905
src/network bits have been left out.)
a8c905
a8c905
Related: #1850986
a8c905
---
a8c905
 man/systemd.network.xml                   |  7 +++----
a8c905
 src/libsystemd-network/network-internal.c | 20 ++++++++++++++++++--
a8c905
 src/libsystemd-network/network-internal.h |  3 ++-
a8c905
 src/udev/net/link-config.c                |  3 ++-
a8c905
 4 files changed, 25 insertions(+), 8 deletions(-)
a8c905
a8c905
diff --git a/man/systemd.network.xml b/man/systemd.network.xml
a8c905
index fc8e0aea68..8300540096 100644
a8c905
--- a/man/systemd.network.xml
a8c905
+++ b/man/systemd.network.xml
a8c905
@@ -133,10 +133,9 @@
a8c905
         <varlistentry>
a8c905
           <term><varname>Name=</varname></term>
a8c905
           <listitem>
a8c905
-            <para>A whitespace-separated list of shell-style globs
a8c905
-            matching the device name, as exposed by the udev property
a8c905
-            <literal>INTERFACE</literal>. If the list is prefixed
a8c905
-            with a "!", the test is inverted.</para>
a8c905
+            <para>A whitespace-separated list of shell-style globs matching the device name, as exposed
a8c905
+            by the udev property <literal>INTERFACE</literal>, or device's alternative names. If the
a8c905
+            list is prefixed with a "!", the test is inverted.</para>
a8c905
           </listitem>
a8c905
         </varlistentry>
a8c905
         <varlistentry>
a8c905
diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c
a8c905
index 629e858def..a935709cd0 100644
a8c905
--- a/src/libsystemd-network/network-internal.c
a8c905
+++ b/src/libsystemd-network/network-internal.c
a8c905
@@ -92,6 +92,18 @@ static bool net_condition_test_strv(char * const *raw_patterns,
a8c905
         return string && strv_fnmatch(raw_patterns, string, 0);
a8c905
 }
a8c905
 
a8c905
+static bool net_condition_test_ifname(char * const *patterns, const char *ifname, char * const *alternative_names) {
a8c905
+        if (net_condition_test_strv(patterns, ifname))
a8c905
+                return true;
a8c905
+
a8c905
+        char * const *p;
a8c905
+        STRV_FOREACH(p, alternative_names)
a8c905
+                if (net_condition_test_strv(patterns, *p))
a8c905
+                        return true;
a8c905
+
a8c905
+        return false;
a8c905
+}
a8c905
+
a8c905
 bool net_match_config(Set *match_mac,
a8c905
                       char * const *match_paths,
a8c905
                       char * const *match_drivers,
a8c905
@@ -107,7 +119,8 @@ bool net_match_config(Set *match_mac,
a8c905
                       const char *dev_parent_driver,
a8c905
                       const char *dev_driver,
a8c905
                       const char *dev_type,
a8c905
-                      const char *dev_name) {
a8c905
+                      const char *dev_name,
a8c905
+                      char * const *alternative_names) {
a8c905
 
a8c905
         if (match_host && condition_test(match_host) <= 0)
a8c905
                 return false;
a8c905
@@ -124,6 +137,9 @@ bool net_match_config(Set *match_mac,
a8c905
         if (match_arch && condition_test(match_arch) <= 0)
a8c905
                 return false;
a8c905
 
a8c905
+        if (!net_condition_test_ifname(match_names, dev_name, alternative_names))
a8c905
+                return false;
a8c905
+
a8c905
         if (match_mac && dev_mac && !set_contains(match_mac, dev_mac))
a8c905
                 return false;
a8c905
 
a8c905
@@ -214,7 +230,7 @@ int config_parse_match_ifnames(
a8c905
                 if (r == 0)
a8c905
                         break;
a8c905
 
a8c905
-                if (!ifname_valid(word)) {
a8c905
+                if (!ifname_valid_full(word, ltype)) {
a8c905
                         log_syntax(unit, LOG_ERR, filename, line, 0, "Interface name is not valid or too long, ignoring assignment: %s", rvalue);
a8c905
                         return 0;
a8c905
                 }
a8c905
diff --git a/src/libsystemd-network/network-internal.h b/src/libsystemd-network/network-internal.h
a8c905
index 9074758bbb..e1d098f3fe 100644
a8c905
--- a/src/libsystemd-network/network-internal.h
a8c905
+++ b/src/libsystemd-network/network-internal.h
a8c905
@@ -29,7 +29,8 @@ bool net_match_config(Set *match_mac,
a8c905
                       const char *dev_parent_driver,
a8c905
                       const char *dev_driver,
a8c905
                       const char *dev_type,
a8c905
-                      const char *dev_name);
a8c905
+                      const char *dev_name,
a8c905
+                      char * const *alternative_names);
a8c905
 
a8c905
 CONFIG_PARSER_PROTOTYPE(config_parse_net_condition);
a8c905
 CONFIG_PARSER_PROTOTYPE(config_parse_hwaddr);
a8c905
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
a8c905
index d07a1a1874..e5052f8f29 100644
a8c905
--- a/src/udev/net/link-config.c
a8c905
+++ b/src/udev/net/link-config.c
a8c905
@@ -238,7 +238,8 @@ int link_config_get(link_config_ctx *ctx, struct udev_device *device,
a8c905
                                      udev_device_get_driver(udev_device_get_parent(device)),
a8c905
                                      udev_device_get_property_value(device, "ID_NET_DRIVER"),
a8c905
                                      udev_device_get_devtype(device),
a8c905
-                                     udev_device_get_sysname(device))) {
a8c905
+                                     udev_device_get_sysname(device),
a8c905
+                                     NULL)) {
a8c905
                         if (link->match_name) {
a8c905
                                 unsigned char name_assign_type = NET_NAME_UNKNOWN;
a8c905