]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: Fix set bond device MAC address failed
authorJian Zhang <zhangjian.3032@bytedance.com>
Fri, 2 Dec 2022 12:08:38 +0000 (20:08 +0800)
committerJian Zhang <zhangjian.3032@bytedance.com>
Mon, 5 Dec 2022 11:48:45 +0000 (19:48 +0800)
Issue:
When device is in bond mode and booting up, there is a probability of
set bond MAC address failed due to `Device or resource busy` error.

In systemd-networkd, set MAC address steps are:
1. Try to set MAC address to device.
2. If failed with `Device or resource busy`, then `Down` the device.
3. Try to set MAC address to device again.

Currently, Even down the bond device, the bond device is still return
`Device or resource busy` error. So the MAC address set failed.

The root cause is that this not enough to down the bond device. We need
to down all the slaves of the bond device.
About this descprition, we could use those commands to check:
```shell
We have two network devices: eth0, bond1, eth0 is slave of bond1.
They are all up.

1. Down bond1, and set MAC address to bond1.
~# ip link set bond1 down
~# ip link set bond1 address 00:11:22:33:44:55
ip: SIOCSIFHWADDR: Device or resource busy

2. Down eth0, and set MAC address to bond1.
~# ip link set eth0 down
~# ip link set bond1 address 00:11:22:33:44:55
Set okay.
```

Fix:
When setting the mac for the second time, if the device kind is bond,
then we need to down the slave devices of bond device.

Tested: Verified in a long time test( reboot cycles ).

Fixes: #25627
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
src/network/networkd-setlink.c
src/network/networkd-setlink.h

index b6aaa1e9dbc4e345da32888ba23fedd75fc1e20a..541c4b8a728feba7f4fc080d19dd33b9ac922d4d 100644 (file)
@@ -502,6 +502,14 @@ static int link_is_ready_to_set_link(Link *link, Request *req) {
                         r = link_down_now(link);
                         if (r < 0)
                                 return r;
+
+                        /* If the kind of the link is "bond", we need
+                         * set the slave link down as well. */
+                        if (streq_ptr(link->kind, "bond")) {
+                                r = link_down_slave_links(link);
+                                if (r < 0)
+                                        return r;
+                        }
                 }
                 break;
 
@@ -1226,6 +1234,21 @@ int link_down_now(Link *link) {
         return 0;
 }
 
+int link_down_slave_links(Link *link) {
+        Link *slave;
+        int r;
+
+        assert(link);
+
+        SET_FOREACH(slave, link->slaves) {
+                r = link_down_now(slave);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
 static int link_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
         int r;
 
index 7e5ba32ef1c4846a60594cd566071d14fa2de884..841e5eeb9c4142fd7b6e4ac3ed73ee4fe18de059 100644 (file)
@@ -25,4 +25,5 @@ int link_request_to_activate(Link *link);
 int link_request_to_bring_up_or_down(Link *link, bool up);
 
 int link_down_now(Link *link);
+int link_down_slave_links(Link *link);
 int link_remove(Link *link);