Skip to content

bond: fix primary bond option when the link is not present

Bond option netlink support requires primary property to be a ifindex instead of the interface name. This is a workaround for supporting specifying a primary that does not exist yet.

nmcli con add type bond ifname mybond0 bond.options "mode=active-backup,primary=veth1"
Connection 'bond-mybond0' (38100ef9-11e2-4003-aff9-cb2d152ce34f) successfully added.
cat /sys/class/net/mybond0/bonding/primary
ip link add veth1 type veth peer veth1p
ip link set veth1 up
ip link set veth1p up
nmcli con add type ethernet ifname veth1 master mybond0
Connection 'bond-slave-veth1' (24c8f7c4-5a50-4634-aec1-9df0da6d597a) successfully added.
nmcli c up bond-slave-veth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

nmcli c
NAME              UUID                                  TYPE      DEVICE
bond-mybond0      38100ef9-11e2-4003-aff9-cb2d152ce34f  bond      mybond0
bond-slave-veth1  24c8f7c4-5a50-4634-aec1-9df0da6d597a  ethernet  veth1

cat /sys/class/net/mybond0/bonding/primary
veth1

Fixes: e064eb9d ('bond: use netlink to set bond options')

Merge request reports