device: when assuming a bridge ignore stp options if stp is disabled

When STP is disabled, the bridge parameters 'priority', 'forward-delay',
'hello-time' and 'max-age' are irrelevant.
We already skip them when loading a connection profile from a ifcfg file.
Do the same when generating a connection from a configured device, in
order to possibly assume the connection.

(cherry picked from commit abc40618f1)
This commit is contained in:
Francesco Giudici 2019-01-03 12:02:41 +01:00
parent 8d0b71fdbc
commit ec0e52cdc8

View file

@ -173,33 +173,34 @@ typedef struct {
uint nm_default;
bool default_if_zero;
bool user_hz_compensate;
bool only_with_stp;
} Option;
static const Option master_options[] = {
{ NM_SETTING_BRIDGE_STP, "stp_state",
{ NM_SETTING_BRIDGE_STP, "stp_state", /* this must stay as the first item */
0, 1, 1,
FALSE, FALSE },
FALSE, FALSE, FALSE },
{ NM_SETTING_BRIDGE_PRIORITY, "priority",
0, G_MAXUINT16, 0x8000,
TRUE, FALSE },
TRUE, FALSE, TRUE },
{ NM_SETTING_BRIDGE_FORWARD_DELAY, "forward_delay",
0, NM_BR_MAX_FORWARD_DELAY, 15,
TRUE, TRUE },
TRUE, TRUE, TRUE},
{ NM_SETTING_BRIDGE_HELLO_TIME, "hello_time",
0, NM_BR_MAX_HELLO_TIME, 2,
TRUE, TRUE },
TRUE, TRUE, TRUE },
{ NM_SETTING_BRIDGE_MAX_AGE, "max_age",
0, NM_BR_MAX_MAX_AGE, 20,
TRUE, TRUE },
TRUE, TRUE, TRUE },
{ NM_SETTING_BRIDGE_AGEING_TIME, "ageing_time",
NM_BR_MIN_AGEING_TIME, NM_BR_MAX_AGEING_TIME, 300,
TRUE, TRUE },
TRUE, TRUE, FALSE },
{ NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, "group_fwd_mask",
0, 0xFFFF, 0,
TRUE, FALSE },
TRUE, FALSE, FALSE },
{ NM_SETTING_BRIDGE_MULTICAST_SNOOPING, "multicast_snooping",
0, 1, 1,
FALSE, FALSE },
FALSE, FALSE, FALSE },
{ NULL, NULL }
};
@ -300,16 +301,29 @@ update_connection (NMDevice *device, NMConnection *connection)
NMSettingBridge *s_bridge = nm_connection_get_setting_bridge (connection);
int ifindex = nm_device_get_ifindex (device);
const Option *option;
gs_free char *stp = NULL;
int stp_value;
if (!s_bridge) {
s_bridge = (NMSettingBridge *) nm_setting_bridge_new ();
nm_connection_add_setting (connection, (NMSetting *) s_bridge);
}
for (option = master_options; option->name; option++) {
option = master_options;
nm_assert (nm_streq (option->sysname, "stp_state"));
stp = nm_platform_sysctl_master_get_option (nm_device_get_platform (device), ifindex, option->sysname);
stp_value = _nm_utils_ascii_str_to_int64 (stp, 10, option->nm_min, option->nm_max, option->nm_default);
g_object_set (s_bridge, option->name, stp_value, NULL);
option++;
for (; option->name; option++) {
gs_free char *str = nm_platform_sysctl_master_get_option (nm_device_get_platform (device), ifindex, option->sysname);
uint value;
if (!stp_value && option->only_with_stp)
continue;
if (str) {
/* See comments in set_sysfs_uint() about centiseconds. */
if (option->user_hz_compensate) {