From 44dab84ab91c314504d3a0d2f5db851ec45e6077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=A4rdian?= Date: Mon, 14 Jun 2021 17:03:40 +0200 Subject: Fix NM unmanaged-devices (changes behavior) (#201) nm: fix ignoring of multiple match conditions (like interface-name: AND mac:, instead of defaulting to MAC if available) Some interfaces (e.g. bond members) might change their MAC and be picked up ny NM, interfering the tests, cf. test_bond_mac/Networkd COMMITS: * nm: ignore interfaces by name and MAC, if both are given Some interfaces, matched by MAC, could change their MAC address after assignment (e.g. a bond member), thus NM would not ignore this interface anymore, even if it is also matched by interface-name. --- src/nm.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/nm.c b/src/nm.c index 08f12ad..2deaa29 100644 --- a/src/nm.c +++ b/src/nm.c @@ -41,18 +41,22 @@ static void g_string_append_netdef_match(GString* s, const NetplanNetDefinition* def) { g_assert(!def->match.driver || def->set_name); - if (def->match.mac) { - g_string_append_printf(s, "mac:%s", def->match.mac); - } else if (def->match.original_name || def->set_name || def->type >= NETPLAN_DEF_TYPE_VIRTUAL) { - /* we always have the renamed name here */ - g_string_append_printf(s, "interface-name:%s", - (def->type >= NETPLAN_DEF_TYPE_VIRTUAL) ? def->id - : (def->set_name ?: def->match.original_name)); + if (def->match.mac || def->match.original_name || def->set_name || def->type >= NETPLAN_DEF_TYPE_VIRTUAL) { + if (def->match.mac) { + g_string_append_printf(s, "mac:%s,", def->match.mac); + } + /* MAC could change, e.g. for bond slaves. Ignore by interface-name as well */ + if (def->match.original_name || def->set_name || def->type >= NETPLAN_DEF_TYPE_VIRTUAL) { + /* we always have the renamed name here */ + g_string_append_printf(s, "interface-name:%s,", + (def->type >= NETPLAN_DEF_TYPE_VIRTUAL) ? def->id + : (def->set_name ?: def->match.original_name)); + } } else { /* no matches → match all devices of that type */ switch (def->type) { case NETPLAN_DEF_TYPE_ETHERNET: - g_string_append(s, "type:ethernet"); + g_string_append(s, "type:ethernet,"); break; /* This cannot be reached with just NM and networkd backends, as * networkd does not support wifi and thus we'll never blacklist a @@ -940,13 +944,13 @@ nd_append_non_nm_ids(gpointer data, gpointer str) if (nd->backend != NETPLAN_BACKEND_NM) { if (nd->match.driver) { + /* TODO: NetworkManager supports (non-globbing) "driver:..." matching nowadays */ /* NM cannot match on drivers, so ignore these via udev rules */ if (!udev_rules) udev_rules = g_string_new(NULL); g_string_append_printf(udev_rules, "ACTION==\"add|change\", SUBSYSTEM==\"net\", ENV{ID_NET_DRIVER}==\"%s\", ENV{NM_UNMANAGED}=\"1\"\n", nd->match.driver); } else { g_string_append_netdef_match((GString*) str, nd); - g_string_append((GString*) str, ","); } } } -- cgit v1.2.3