From 4fd90fb6cc098105dcf989ff772c28167874c40e Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Thu, 8 Sep 2022 12:00:45 +0200 Subject: [PATCH] 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. nmcli con add type ethernet ifname veth1 master mybond0 cat /sys/class/net/mybond0/bonding/primary veth1 ``` https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1362 Fixes: e064eb9d1361 ('bond: use netlink to set bond options') --- src/core/devices/nm-device-bond.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c index 558f8f7598..b4e9a4e921 100644 --- a/src/core/devices/nm-device-bond.c +++ b/src/core/devices/nm-device-bond.c @@ -493,6 +493,10 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) if (!nm_device_hw_addr_set_cloned(device, nm_device_get_applied_connection(device), FALSE)) ret = NM_ACT_STAGE_RETURN_FAILURE; } + + /* This is a workaround because netlink do not support ifname as primary */ + set_bond_attr_or_default(device, s_bond, NM_SETTING_BOND_OPTION_PRIMARY); + nm_device_bring_up(device, TRUE, NULL); return ret;