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: 9958510f28 ('bond: add support of queue_id of bond port')
(cherry picked from commit 23ce9cff99)
This commit is contained in:
Beniamino Galvani 2022-09-19 15:54:58 +02:00 committed by Thomas Haller
parent d23c6040f8
commit 30366e5b3a
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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,