dryang / rpms / systemd

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