dcavalca / rpms / systemd

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