]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: optionally bring up interface before joining bridge 34438/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 15 Sep 2024 17:36:13 +0000 (02:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 11 Dec 2024 02:23:48 +0000 (11:23 +0900)
Closes #34247.

rules.d/81-net-bridge.rules [new file with mode: 0644]
rules.d/meson.build
src/network/networkd-setlink.c

diff --git a/rules.d/81-net-bridge.rules b/rules.d/81-net-bridge.rules
new file mode 100644 (file)
index 0000000..defb31f
--- /dev/null
@@ -0,0 +1,16 @@
+# do not edit this file, it will be overwritten on update
+
+ACTION=="remove", GOTO="net_bridge_end"
+SUBSYSTEM!="net", GOTO="net_bridge_end"
+
+# Some devices require the port to be up before joining the bridge.
+# In such cases, set ID_NET_BRING_UP_BEFORE_JOINING_BRIDGE to "1".
+
+# Texas Instruments Ethernet device with switchdev mode:
+# https://docs.kernel.org/networking/device_drivers/ethernet/ti/am65_nuss_cpsw_switchdev.html#enabling-switch
+ENV{ID_NET_DRIVER}=="am65-cpsw-nuss", SUBSYSTEMS=="platform", DRIVERS=="am65-cpsw-nuss", \
+  PROGRAM="/usr/sbin/devlink dev param show platform/%b name switch_mode", \
+  RESULT=="*cmode runtime value true*", \
+  ENV{ID_NET_BRING_UP_BEFORE_JOINING_BRIDGE}="1"
+
+LABEL="net_bridge_end"
index 3040fae8a43f94d4c784f575d7cc7f6d8352a333..61165fd86f49af5332d7ecdab85342a594282d23 100644 (file)
@@ -29,6 +29,7 @@ rules = [
                '75-probe_mtd.rules',
                '78-sound-card.rules',
                '80-net-setup-link.rules',
+               '81-net-bridge.rules',
                '81-net-dhcp.rules',
                '90-iocost.rules',
               )],
index 8ef523dfdcf1b823f9002a47d7e21c1a828a5949..467fadb3eab1b5dbe618c4e81f1369221bb8ed37 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/if_bridge.h>
 #include <linux/ipv6.h>
 
+#include "device-private.h"
 #include "missing_network.h"
 #include "netif-util.h"
 #include "netlink-util.h"
@@ -581,6 +582,25 @@ static int link_is_ready_to_set_link(Link *link, Request *req) {
                                 return r;
                 }
 
+                if (link->network->bridge && !FLAGS_SET(link->flags, IFF_UP) && link->dev) {
+                        /* Some devices require the port to be up before joining the bridge.
+                         *
+                         * E.g. Texas Instruments SoC Ethernet running in switch mode:
+                         * https://docs.kernel.org/networking/device_drivers/ethernet/ti/am65_nuss_cpsw_switchdev.html#enabling-switch
+                         * > Port’s netdev devices have to be in UP before joining to the bridge to avoid
+                         * > overwriting of bridge configuration as CPSW switch driver completely reloads its
+                         * > configuration when first port changes its state to UP. */
+
+                        r = device_get_property_bool(link->dev, "ID_NET_BRING_UP_BEFORE_JOINING_BRIDGE");
+                        if (r < 0 && r != -ENOENT)
+                                log_link_warning_errno(link, r, "Failed to get or parse ID_NET_BRING_UP_BEFORE_JOINING_BRIDGE property, ignoring: %m");
+                        else if (r > 0) {
+                                r = link_up_now(link);
+                                if (r < 0)
+                                        return r;
+                        }
+                }
+
                 req->userdata = UINT32_TO_PTR(m);
                 break;
         }