Skip to content

Commit

Permalink
network: support ID_NET_MANAGED_BY udev property
Browse files Browse the repository at this point in the history
If the property is set, networkd manages the interface only when its
value is "io.systemd.Network".

Closes systemd#29768.
  • Loading branch information
yuwata authored and ssahani committed Nov 23, 2023
1 parent 883fa5c commit 46d81c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions man/systemd.network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
configured. The first (in alphanumeric order) of the network files that matches a given interface
is applied, all later files are ignored, even if they match as well.</para>

<para>Note that any network interfaces that have the <varname>ID_NET_MANAGED_BY=</varname> udev property
set will never be matched by any .network files – unless the property's value is the string
<literal>io.systemd.Network</literal> – even if the [Match] section would otherwise match. This may be
used to exclude specific network interfaces from <command>systemd-networkd</command>'s management, while
keeping the [Match] section generic. The <varname>ID_NET_MANAGED_BY=</varname> poperty thus declares
intended <emphasis>ownership</emphasis> of the device, and permits ensuring that concurrent network
management implementations do not compete for management of specific devices.</para>

<para>A network file is said to match a network interface if all matches specified by the [Match]
section are satisfied. When a network file does not contain valid settings in [Match] section, then
the file will match all interfaces and <command>systemd-networkd</command> warns about that. Hint:
Expand Down
10 changes: 10 additions & 0 deletions src/network/networkd-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,7 @@ static int link_check_initialized(Link *link) {

int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t action) {
int r, ifindex;
const char *s;
Link *link;

assert(m);
Expand Down Expand Up @@ -1507,6 +1508,15 @@ int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t
return 0;
}

r = sd_device_get_property_value(device, "ID_NET_MANAGED_BY", &s);
if (r < 0 && r != -ENOENT)
log_device_debug_errno(device, r, "Failed to get ID_NET_MANAGED_BY udev property, ignoring: %m");
if (r >= 0 && !streq(s, "io.systemd.Network")) {
log_device_debug(device, "Interface is requested to be managed by '%s', not managing the interface.", s);
link_set_state(link, LINK_STATE_UNMANAGED);
return 0;
}

r = link_initialized(link, device);
if (r < 0)
link_enter_failed(link);
Expand Down

0 comments on commit 46d81c0

Please sign in to comment.