ryantimwilson / rpms / systemd

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