|
|
698723 |
From c76d050d8d61b4a63d4407bd03bd3f49cd9915ce 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 |
|
|
|
698723 |
Related: #1850986
|
|
|
698723 |
---
|
|
|
698723 |
man/systemd.network.xml | 7 +++----
|
|
|
698723 |
src/libsystemd-network/network-internal.c | 20 ++++++++++++++++++--
|
|
|
698723 |
src/libsystemd-network/network-internal.h | 3 ++-
|
|
|
698723 |
src/udev/net/link-config.c | 3 ++-
|
|
|
698723 |
4 files changed, 25 insertions(+), 8 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);
|
|
|
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 |
|