summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Giudici <fgiudici@redhat.com>2019-01-10 09:52:21 +0100
committerFrancesco Giudici <fgiudici@redhat.com>2019-01-10 09:52:21 +0100
commit46726ecdde724b00ec1864979f3fd62e804b819d (patch)
treecd577428efa95ec08217215ffe1d103d30810a29
parenteae86a48237363fdc695f0541ea2d816210ba0df (diff)
parentabc40618f1bab6a347d0ec6abf39a4fb8ed3d563 (diff)
downloadNetworkManager-46726ecdde724b00ec1864979f3fd62e804b819d.tar.gz
merge: branch 'fg/assume_bridge-rh1593939'
Improve assuming bridges on startup. https://bugzilla.redhat.com/show_bug.cgi?id=1593939 https://github.com/NetworkManager/NetworkManager/pull/266
-rw-r--r--libnm-core/nm-core-internal.h5
-rw-r--r--libnm-core/nm-setting-bridge-port.c11
-rw-r--r--src/devices/nm-device-bridge.c101
3 files changed, 84 insertions, 33 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index 1e7ec9bcbc..ae43d27545 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -101,6 +101,11 @@
#define NM_BR_MIN_AGEING_TIME 0
#define NM_BR_MAX_AGEING_TIME 1000000
+#define NM_BR_PORT_MAX_PRIORITY 63
+#define NM_BR_PORT_DEF_PRIORITY 32
+
+#define NM_BR_PORT_MAX_PATH_COST 65535
+
/* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated
* connection can be replaced by a already-defined connection. This flag only
* takes into account properties marked with the %NM_SETTING_PARAM_INFERRABLE
diff --git a/libnm-core/nm-setting-bridge-port.c b/libnm-core/nm-setting-bridge-port.c
index 4104f8c5cc..bc9c3e6fec 100644
--- a/libnm-core/nm-setting-bridge-port.c
+++ b/libnm-core/nm-setting-bridge-port.c
@@ -104,12 +104,6 @@ nm_setting_bridge_port_get_hairpin_mode (NMSettingBridgePort *setting)
/*****************************************************************************/
-#define BR_MAX_PORT_PRIORITY 63
-#define BR_DEF_PRIORITY 32
-
-#define BR_MIN_PATH_COST 1
-#define BR_MAX_PATH_COST 65535
-
static gboolean
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
@@ -238,7 +232,7 @@ nm_setting_bridge_port_class_init (NMSettingBridgePortClass *klass)
g_object_class_install_property
(object_class, PROP_PRIORITY,
g_param_spec_uint (NM_SETTING_BRIDGE_PORT_PRIORITY, "", "",
- 0, BR_MAX_PORT_PRIORITY, BR_DEF_PRIORITY,
+ 0, NM_BR_PORT_MAX_PRIORITY, NM_BR_PORT_DEF_PRIORITY,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
@@ -261,10 +255,9 @@ nm_setting_bridge_port_class_init (NMSettingBridgePortClass *klass)
g_object_class_install_property
(object_class, PROP_PATH_COST,
g_param_spec_uint (NM_SETTING_BRIDGE_PORT_PATH_COST, "", "",
- 0, BR_MAX_PATH_COST, 100,
+ 0, NM_BR_PORT_MAX_PATH_COST, 100,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
- NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index be53f30dc3..4c8921c071 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -168,26 +168,52 @@ complete_connection (NMDevice *device,
typedef struct {
const char *name;
const char *sysname;
- gboolean default_if_zero;
- gboolean user_hz_compensate;
+ uint nm_min;
+ uint nm_max;
+ 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", FALSE, FALSE },
- { NM_SETTING_BRIDGE_PRIORITY, "priority", TRUE, FALSE },
- { NM_SETTING_BRIDGE_FORWARD_DELAY, "forward_delay", TRUE, TRUE },
- { NM_SETTING_BRIDGE_HELLO_TIME, "hello_time", TRUE, TRUE },
- { NM_SETTING_BRIDGE_MAX_AGE, "max_age", TRUE, TRUE },
- { NM_SETTING_BRIDGE_AGEING_TIME, "ageing_time", TRUE, TRUE },
- { NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, "group_fwd_mask", TRUE, FALSE },
- { NM_SETTING_BRIDGE_MULTICAST_SNOOPING, "multicast_snooping", FALSE, FALSE },
+ { NM_SETTING_BRIDGE_STP, "stp_state", /* this must stay as the first item */
+ 0, 1, 1,
+ FALSE, FALSE, FALSE },
+ { NM_SETTING_BRIDGE_PRIORITY, "priority",
+ 0, G_MAXUINT16, 0x8000,
+ TRUE, FALSE, TRUE },
+ { NM_SETTING_BRIDGE_FORWARD_DELAY, "forward_delay",
+ 0, NM_BR_MAX_FORWARD_DELAY, 15,
+ TRUE, TRUE, TRUE},
+ { NM_SETTING_BRIDGE_HELLO_TIME, "hello_time",
+ 0, NM_BR_MAX_HELLO_TIME, 2,
+ TRUE, TRUE, TRUE },
+ { NM_SETTING_BRIDGE_MAX_AGE, "max_age",
+ 0, NM_BR_MAX_MAX_AGE, 20,
+ TRUE, TRUE, TRUE },
+ { NM_SETTING_BRIDGE_AGEING_TIME, "ageing_time",
+ NM_BR_MIN_AGEING_TIME, NM_BR_MAX_AGEING_TIME, 300,
+ TRUE, TRUE, FALSE },
+ { NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, "group_fwd_mask",
+ 0, 0xFFFF, 0,
+ TRUE, FALSE, FALSE },
+ { NM_SETTING_BRIDGE_MULTICAST_SNOOPING, "multicast_snooping",
+ 0, 1, 1,
+ FALSE, FALSE, FALSE },
{ NULL, NULL }
};
static const Option slave_options[] = {
- { NM_SETTING_BRIDGE_PORT_PRIORITY, "priority", TRUE, FALSE },
- { NM_SETTING_BRIDGE_PORT_PATH_COST, "path_cost", TRUE, FALSE },
- { NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, "hairpin_mode", FALSE, FALSE },
+ { NM_SETTING_BRIDGE_PORT_PRIORITY, "priority",
+ 0, NM_BR_PORT_MAX_PRIORITY, NM_BR_PORT_DEF_PRIORITY,
+ TRUE, FALSE },
+ { NM_SETTING_BRIDGE_PORT_PATH_COST, "path_cost",
+ 0, NM_BR_PORT_MAX_PATH_COST, 100,
+ TRUE, FALSE },
+ { NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, "hairpin_mode",
+ 0, 1, 0,
+ FALSE, FALSE },
{ NULL, NULL }
};
@@ -275,23 +301,43 @@ 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);
- int value;
+ uint value;
- if (str) {
- value = strtol (str, NULL, 10);
+ if (!stp_value && option->only_with_stp)
+ continue;
+ if (str) {
/* See comments in set_sysfs_uint() about centiseconds. */
- if (option->user_hz_compensate)
+ if (option->user_hz_compensate) {
+ value = _nm_utils_ascii_str_to_int64 (str, 10,
+ option->nm_min * 100,
+ option->nm_max * 100,
+ option->nm_default * 100);
value /= 100;
-
+ } else {
+ value = _nm_utils_ascii_str_to_int64 (str, 10,
+ option->nm_min,
+ option->nm_max,
+ option->nm_default);
+ }
g_object_set (s_bridge, option->name, value, NULL);
} else
_LOGW (LOGD_BRIDGE, "failed to read bridge setting '%s'", option->sysname);
@@ -322,15 +368,22 @@ master_update_slave_connection (NMDevice *device,
for (option = slave_options; option->name; option++) {
gs_free char *str = nm_platform_sysctl_slave_get_option (nm_device_get_platform (device), ifindex_slave, option->sysname);
- int value;
+ uint value;
if (str) {
- value = strtol (str, NULL, 10);
-
/* See comments in set_sysfs_uint() about centiseconds. */
- if (option->user_hz_compensate)
+ if (option->user_hz_compensate) {
+ value = _nm_utils_ascii_str_to_int64 (str, 10,
+ option->nm_min * 100,
+ option->nm_max * 100,
+ option->nm_default * 100);
value /= 100;
-
+ } else {
+ value = _nm_utils_ascii_str_to_int64 (str, 10,
+ option->nm_min,
+ option->nm_max,
+ option->nm_default);
+ }
g_object_set (s_port, option->name, value, NULL);
} else
_LOGW (LOGD_BRIDGE, "failed to read bridge port setting '%s'", option->sysname);