From e519e20ae16e24438c0be0d3bc6eed953a55d9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 4 Feb 2020 08:30:40 +0100 Subject: [PATCH 1/2] test-network: do not fail if lo has a .network file Fixes #9895. --- src/network/test-network.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/network/test-network.c b/src/network/test-network.c index 7c37563ac2..b29523b318 100644 --- a/src/network/test-network.c +++ b/src/network/test-network.c @@ -122,11 +122,18 @@ static int test_load_config(Manager *manager) { static void test_network_get(Manager *manager, sd_device *loopback) { Network *network; const struct ether_addr mac = ETHER_ADDR_NULL; + int r; - /* let's assume that the test machine does not have a .network file - that applies to the loopback device... */ - assert_se(network_get(manager, loopback, "lo", NULL, &mac, &mac, 0, NULL, NULL, &network) == -ENOENT); - assert_se(!network); + /* Let's hope that the test machine does not have a .network file that applies to loopback deviceā€¦ + * But it is still possible, so let's allow that case too. */ + r = network_get(manager, loopback, "lo", NULL, &mac, &mac, 0, NULL, NULL, &network); + if (r == -ENOENT) + /* The expected case */ + assert_se(!network); + else if (r >= 0) + assert_se(network); + else + assert_not_reached("bad error!"); } static void test_address_equality(void) { From dade7349174765a702ab5cb9e27608ca966c3673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 4 Feb 2020 08:42:50 +0100 Subject: [PATCH 2/2] network,udev: refuse .link and .network settings with no matches Two releases ago we started warning about this, and I think it is now to turn this into a hard error. People get bitten by this every once in a while, and there doesn't see to be any legitimate use case where the same .link or .network files should be applied to _all_ interfaces, since in particular that configuration would apply both to lo and any other interfaces. And if for whatever reason that is actually desired, OriginalName=* or Name=* can be easily added to silence the warning and achieve the effect. (The case described in #12098 is particularly nasty: 'echo -n >foo.network' creates a mask file, 'echo >foo.network' creates a "match all" file.) Fixes #717, #12098 for realz now. --- src/network/networkd-network.c | 8 ++++---- src/udev/net/link-config.c | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 4fd48be52a..ed59584fd1 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -164,10 +164,10 @@ int network_verify(Network *network) { strv_isempty(network->match_path) && strv_isempty(network->match_driver) && strv_isempty(network->match_type) && strv_isempty(network->match_name) && strv_isempty(network->match_property) && strv_isempty(network->match_ssid) && !network->conditions) - log_warning("%s: No valid settings found in the [Match] section. " - "The file will match all interfaces. " - "If that is intended, please add Name=* in the [Match] section.", - network->filename); + return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), + "%s: No valid settings found in the [Match] section, ignoring file. " + "To match all interfaces, add Name=* in the [Match] section.", + network->filename); /* skip out early if configuration does not match the environment */ if (!condition_test_list(network->conditions, NULL, NULL, NULL)) diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 4a44edfc01..dfe9b9f313 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -165,11 +165,12 @@ int link_load_one(link_config_ctx *ctx, const char *filename) { if (set_isempty(link->match_mac) && set_isempty(link->match_permanent_mac) && strv_isempty(link->match_path) && strv_isempty(link->match_driver) && strv_isempty(link->match_type) && - strv_isempty(link->match_name) && strv_isempty(link->match_property) && !link->conditions) - log_warning("%s: No valid settings found in the [Match] section. " - "The file will match all interfaces. " - "If that is intended, please add OriginalName=* in the [Match] section.", + strv_isempty(link->match_name) && strv_isempty(link->match_property) && !link->conditions) { + log_warning("%s: No valid settings found in the [Match] section, ignoring file. " + "To match all interfaces, add OriginalName=* in the [Match] section.", filename); + return 0; + } if (!condition_test_list(link->conditions, NULL, NULL, NULL)) { log_debug("%s: Conditions do not match the system environment, skipping.", filename);