X Tutup
Skip to content

Commit 84ea567

Browse files
yuwatakeszybz
authored andcommitted
udev,network: warn when .link or .network file has no [Match] section
Closes systemd#12098.
1 parent 2d6888c commit 84ea567

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

man/systemd.link.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@
6060
<refsect1>
6161
<title>[Match] Section Options</title>
6262

63-
<para>A link file is said to match a device if each of the entries in the [Match] section matches, or if
64-
the section is empty. The following keys are accepted:</para>
63+
<para>A link file is said to match a device if all matches specified by the
64+
<literal>[Match]</literal> section are satisfied. When a link file does not contain valid settings
65+
in <literal>[Match]</literal> section, then the file will match all devices and
66+
<command>systemd-udevd</command> warns about that. Hint: to avoid the warning and to make it clear
67+
that all interfaces shall be matched, add the following:
68+
<programlisting>OriginalName=*</programlisting>
69+
The following keys are accepted:</para>
6570

6671
<variablelist class='network-directives'>
6772
<varlistentry>

man/systemd.network.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@
7777
is applied, all later files are ignored, even if they match as
7878
well.</para>
7979

80-
<para>A network file is said to match a device if each of the
81-
entries in the <literal>[Match]</literal> section matches, or if
82-
the section is empty. The following keys are accepted:</para>
80+
<para>A network file is said to match a network interface if all matches specified by the
81+
<literal>[Match]</literal> section are satisfied. When a network file does not contain valid
82+
settings in <literal>[Match]</literal> section, then the file will match all interfaces and
83+
<command>systemd-networkd</command> warns about that. Hint: to avoid the warning and to make it
84+
clear that all interfaces shall be matched, add the following:
85+
<programlisting>Name=*</programlisting>
86+
The following keys are accepted:</para>
8387

8488
<variablelist class='network-directives'>
8589
<varlistentry>

network/99-default.link

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# the Free Software Foundation; either version 2.1 of the License, or
88
# (at your option) any later version.
99

10+
[Match]
11+
OriginalName=*
12+
1013
[Link]
1114
NamePolicy=keep kernel database onboard slot path
1215
MACAddressPolicy=persistent

src/network/networkd-network.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ int network_verify(Network *network) {
172172
assert(network);
173173
assert(network->filename);
174174

175+
if (set_isempty(network->match_mac) && strv_isempty(network->match_path) &&
176+
strv_isempty(network->match_driver) && strv_isempty(network->match_type) &&
177+
strv_isempty(network->match_name) && !network->conditions)
178+
log_warning("%s: No valid settings found in the [Match] section. "
179+
"The file will match all interfaces. "
180+
"If that is intended, please add Name=* in the [Match] section.",
181+
network->filename);
182+
175183
/* skip out early if configuration does not match the environment */
176184
if (!condition_test_list(network->conditions, NULL, NULL, NULL))
177185
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),

src/network/test-networkd-conf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ static void test_config_parse_address_one(const char *rvalue, int family, unsign
173173

174174
assert_se(network = new0(Network, 1));
175175
assert_se(network->filename = strdup("hogehoge.network"));
176+
assert_se(config_parse_ifnames("network", "filename", 1, "section", 1, "Name", 0, "*", &network->match_name, network) == 0);
176177
assert_se(config_parse_address("network", "filename", 1, "section", 1, "Address", 0, rvalue, network, network) == 0);
177178
assert_se(network->n_static_addresses == 1);
178179
assert_se(network_verify(network) >= 0);

src/udev/net/link-config.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ int link_load_one(link_config_ctx *ctx, const char *filename) {
159159
if (link->speed > UINT_MAX)
160160
return -ERANGE;
161161

162+
if (set_isempty(link->match_mac) && strv_isempty(link->match_path) &&
163+
strv_isempty(link->match_driver) && strv_isempty(link->match_type) &&
164+
strv_isempty(link->match_name) && !link->conditions)
165+
log_warning("%s: No valid settings found in the [Match] section. "
166+
"The file will match all interfaces. "
167+
"If that is intended, please add OriginalName=* in the [Match] section.",
168+
filename);
169+
162170
if (!condition_test_list(link->conditions, NULL, NULL, NULL)) {
163171
log_debug("%s: Conditions do not match the system environment, skipping.", filename);
164172
return 0;

0 commit comments

Comments
 (0)
X Tutup