From 30366e5b3a7676ee685a2a4c7b00d50d28a10a2e Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 19 Sep 2022 15:54:58 +0200 Subject: [PATCH] libnm-core: allow empty slave-type with a NMSettingBondPort It is allowed to have a connection with empty connection.slave-type and a NMSettingBondPort; the property will be set automatically during normalization if a master is set, otherwise the setting will be removed. With this change, it becomes possible to remove a port from a bond from nmcli, turning it into a non-slave connection. Before, this used to fail with: $ nmcli connection add type ethernet ifname test con-name test+ connection.master bond0 connection.slave-type bond $ nmcli connection modify test+ connection.master '' connection.slave-type '' Error: Failed to modify connection 'test+': connection.slave-type: A connection with a 'bond-port' setting must have the slave-type set to 'bond' https://bugzilla.redhat.com/show_bug.cgi?id=2126262 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1382 Fixes: 9958510f2872 ('bond: add support of queue_id of bond port') (cherry picked from commit 23ce9cff99313b9cefb7770262347731161f4539) --- src/libnm-core-impl/nm-setting-bond-port.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-bond-port.c b/src/libnm-core-impl/nm-setting-bond-port.c index 9b41a74f96..7ea82a763e 100644 --- a/src/libnm-core-impl/nm-setting-bond-port.c +++ b/src/libnm-core-impl/nm-setting-bond-port.c @@ -85,13 +85,15 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } slave_type = nm_setting_connection_get_slave_type(s_con); - if (!nm_streq0(slave_type, NM_SETTING_BOND_SETTING_NAME)) { + if (slave_type && !nm_streq(slave_type, NM_SETTING_BOND_SETTING_NAME)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("A connection with a '%s' setting must have the slave-type set to '%s'"), + _("A connection with a '%s' setting must have the slave-type set to '%s'. " + "Instead it is '%s'"), NM_SETTING_BOND_PORT_SETTING_NAME, - NM_SETTING_BOND_SETTING_NAME); + NM_SETTING_BOND_SETTING_NAME, + slave_type); g_prefix_error(error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME,