-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve NetworkManager's device management/ignore logic, using udev matching rules (LP: #1951653) #276
Conversation
ab172ec
to
84fdc6f
Compare
1e0b4f7
to
de23de1
Compare
… given in netplan
Also, make sure we clear any runtime state that NetworkManager left in /run/NetworkManager/devices/* as this could overwrite our udev rules.
V2: avoid g_string_replace() which is not available in older verions of GLib (Focal)
de23de1
to
4c16a06
Compare
We have an explicit NM-managed-devices allow-list, now. So we don't need those quirks anymore.
7b5504b
to
dbf7099
Compare
Codecov Report
@@ Coverage Diff @@
## main #276 +/- ##
=======================================
Coverage 99.07% 99.08%
=======================================
Files 61 61
Lines 11194 11226 +32
=======================================
+ Hits 11091 11123 +32
Misses 103 103
Continue to review full report at Codecov.
|
dbf7099
to
f291f83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Only one small optional stylistic nitpick, feel free to merge if you disagree!
Small question though, where does that last commit come from? Has this bug surfaced due to the NM changes?
* Also, mark all devices managed by us explicitly, so it won't get in | ||
* conflict with the system's udev rules that might ignore some devices | ||
* in containers via usr/lib/udev/rules.d/85-nm-unmanaged-devices.rules */ | ||
GList* iter = np_state->netdefs_ordered; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: great work on the whole function body, very readable and well commented despite the complex logic!
* from the "match" stanza (e.g. original_name/mac/drivers) | ||
* This will match the "old" interface (i.e. original MAC and/or | ||
* interface name) if it got changed */ | ||
if (nd->has_match && (nd->match.original_name || nd->match.mac || nd->match.driver)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick (non-blocking): this block could perhaps have been split off into its own function to make it a bit more bitesize ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh.. I was a bit quick with merging and didn't remember this suggestion. It makes sense to encapsulate this into its own function. I will probably work on this in a follow-up commit.
@thom311 is this reasonable? |
yes. lgtm. I am surprised that netplan aims to support a mixed system with networkd and NetworkManager. But sure. |
Thank you for your feedback @thom311! merging.
Yes. A combined setup can lead to funny situations, but we try our best to make it work. |
Yes. That bug surfaced after I implemented the NM changes, seems to be a timing issue that only happened (sometimes) inside our CI. I was not able to reproduce it locally on my machine. |
Description
By default,
systemd-networkd
controls only interfaces that it has explicitly been configured for (via a sd-networkd.network
file); it considers other interfaces as "unmanaged" and ignores them. NetworkManager OTOH tries to claim control of any interface that is UP, which might lead to conflicts if multiple networking daemons are used at the same time.NetworkManager has different ways to control/avoid this behavior:
NM_UNMANAGED=1
udev environment, the weakest condition[keyfile].unmanaged-devices=
setting (affected by some unexpected behavior: LP#1615044)[device].managed=
setting, the strongest condition, overruling all other settings, created a runtime in/run/NetworkManager/devices/*
The stronger rules via NetworkManager.conf are unfortunately a bit limited in their matching logic, as multiple checks can only be ORed (e.g. we cannot check for:
interface-name=wl* AND driver=(virt* OR iwlwifi)
). udev OTOH has a very powerful matching logic (but unfortunately cannot match on the interface type: ethernet/wifi/bridge/...).So we're reimplementing/refactoring the flawed NetworkManager "unmanaged vs managed" logic in netplan, by having an explicit allow-list of interfaces that NM is supposed to control (as some udev rules shipped system-wide would otherwise disable certain interfaces in containers and other special conditions, even if configured via netplan, c.f.
/lib/udev/rules.d/85-nm-unmanaged.rules
) in addition to an explicit deny-list of interfaces to ignore (e.g. because they are to be managed by sd-networkd) as udev rules in/run/udev/rules.d/90-netplan.rules
and keeping the special-case of matching a whole class/type of interfaces (e.g. ethernets/wifis/bridges/...) in/run/NetworkManager/conf.d/netplan.conf
as a NetworkManager.conf[device*].managed=
rule.Furthermore, we're applying this matching logic whenever ANY interface (in netplan YAML) is supposed to be controlled by NetworkManager (that is in contrast to only applying it when NetworkManager is selected as the global renderer).
It is worth mentioning that this "managed vs unmanaged" matching logic is slightly different from netplan's usual matching logic (e.g. for configuring the interfaces), as we might ignore an interface based on it's old AND new/renamed interface name, or it's old and new/changed MAC address, while we cannot do this for the normal netplan matching.
Commits:
Checklist
make check
successfully.make check-coverage
).