]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: support ID_NET_MANAGED_BY udev property
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 31 Oct 2023 09:07:08 +0000 (18:07 +0900)
committerLennart Poettering <lennart@poettering.net>
Wed, 1 Nov 2023 09:14:27 +0000 (10:14 +0100)
If the property is set, networkd manages the interface only when its
value is "io.systemd.Network".

Closes #29768.

man/systemd.network.xml
src/network/networkd-link.c

index 4e360d7a8e81c3143957b90113d6165418180429..b08dfbf1b70432400591677016d765b3c60efac7 100644 (file)
     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:
index 555b19d580b57b27235cf2e4ab7e979655fd9426..2caf4ff24956f6a923eb78801b69eea18dea6651 100644 (file)
@@ -1465,6 +1465,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);
@@ -1499,6 +1500,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);