diff options
author | Lukas Märdian <slyon@ubuntu.com> | 2021-06-14 17:03:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-14 17:03:40 +0200 |
commit | 44dab84ab91c314504d3a0d2f5db851ec45e6077 (patch) | |
tree | 05832ba5edf8d79ff72a05725ed582093a98f044 /src | |
parent | dafe0a9c30b3a1566ebca3eaed741832a55b3323 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/nm.c | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -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, ","); } } } |