summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Fernandez Mancera <ffmancera@riseup.net>2023-05-29 12:41:16 +0200
committerFernando Fernandez Mancera <ffmancera@riseup.net>2023-06-01 11:59:21 +0200
commit8c14955c1debb123731c7e6b8927a5234e310931 (patch)
tree263adeb627348c7903a88e6ac38a60857efaa79d
parent3707a3df807ca35e05319e1e3473fcb93e7cdc37 (diff)
bridge: remove dead code from commit_option()ff/drop_dead_code_bridge
commit_option() was used in the past to set both bridge and bridge port options using sysfs. Currently it is only used for bridge port options. This patch removes the dead code for bridge options and unify it on commit_port_options(). This is simplifying the work needed to support bridge port option through netlink. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1643
-rw-r--r--src/core/devices/nm-device-bridge.c171
1 files changed, 77 insertions, 94 deletions
diff --git a/src/core/devices/nm-device-bridge.c b/src/core/devices/nm-device-bridge.c
index c07b154979..9a45dbf3fc 100644
--- a/src/core/devices/nm-device-bridge.c
+++ b/src/core/devices/nm-device-bridge.c
@@ -437,96 +437,6 @@ static const Option slave_options[] = {
OPTION(NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, "hairpin_mode", OPTION_TYPE_BOOL(FALSE), ),
{0}};
-static void
-commit_option(NMDevice *device, NMSetting *setting, const Option *option, gboolean slave)
-{
- int ifindex = nm_device_get_ifindex(device);
- nm_auto_unset_gvalue GValue val = G_VALUE_INIT;
- GParamSpec *pspec;
- const char *value;
- char value_buf[100];
-
- if (slave)
- nm_assert(NM_IS_SETTING_BRIDGE_PORT(setting));
- else
- nm_assert(NM_IS_SETTING_BRIDGE(setting));
-
- pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(setting), option->name);
- nm_assert(pspec);
-
- g_value_init(&val, G_PARAM_SPEC_VALUE_TYPE(pspec));
- g_object_get_property((GObject *) setting, option->name, &val);
-
- if (option->to_sysfs) {
- value = option->to_sysfs(&val);
- goto out;
- }
-
- switch (pspec->value_type) {
- case G_TYPE_BOOLEAN:
- value = g_value_get_boolean(&val) ? "1" : "0";
- break;
- case G_TYPE_UINT64:
- case G_TYPE_UINT:
- {
- guint64 uval;
-
- if (pspec->value_type == G_TYPE_UINT64)
- uval = g_value_get_uint64(&val);
- else
- uval = (guint) g_value_get_uint(&val);
-
- /* zero means "unspecified" for some NM properties but isn't in the
- * allowed kernel range, so reset the property to the default value.
- */
- if (option->default_if_zero && uval == 0) {
- if (pspec->value_type == G_TYPE_UINT64)
- uval = NM_G_PARAM_SPEC_GET_DEFAULT_UINT64(pspec);
- else
- uval = NM_G_PARAM_SPEC_GET_DEFAULT_UINT(pspec);
- }
-
- /* Linux kernel bridge interfaces use 'centiseconds' for time-based values.
- * In reality it's not centiseconds, but depends on HZ and USER_HZ, which
- * is almost always works out to be a multiplier of 100, so we can assume
- * centiseconds. See clock_t_to_jiffies().
- */
- if (option->user_hz_compensate)
- uval *= 100;
-
- if (pspec->value_type == G_TYPE_UINT64)
- nm_sprintf_buf(value_buf, "%" G_GUINT64_FORMAT, uval);
- else
- nm_sprintf_buf(value_buf, "%u", (guint) uval);
-
- value = value_buf;
- } break;
- case G_TYPE_STRING:
- value = g_value_get_string(&val);
- break;
- default:
- nm_assert_not_reached();
- value = NULL;
- break;
- }
-
-out:
- if (!value)
- return;
-
- if (slave) {
- nm_platform_sysctl_slave_set_option(nm_device_get_platform(device),
- ifindex,
- option->sysname,
- value);
- } else {
- nm_platform_sysctl_master_set_option(nm_device_get_platform(device),
- ifindex,
- option->sysname,
- value);
- }
-}
-
static const NMPlatformBridgeVlan **
setting_vlans_to_platform(GPtrArray *array)
{
@@ -561,19 +471,92 @@ setting_vlans_to_platform(GPtrArray *array)
}
static void
-commit_slave_options(NMDevice *device, NMSettingBridgePort *setting)
+commit_port_options(NMDevice *device, NMSettingBridgePort *setting)
{
const Option *option;
NMSetting *s;
gs_unref_object NMSetting *s_clear = NULL;
+ int ifindex = nm_device_get_ifindex(device);
if (setting)
s = NM_SETTING(setting);
else
s = s_clear = nm_setting_bridge_port_new();
- for (option = slave_options; option->name; option++)
- commit_option(device, s, option, TRUE);
+ for (option = slave_options; option->name; option++) {
+ nm_auto_unset_gvalue GValue val = G_VALUE_INIT;
+ GParamSpec *pspec;
+ const char *value;
+ char value_buf[100];
+
+ pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(s), option->name);
+ nm_assert(pspec);
+
+ g_value_init(&val, G_PARAM_SPEC_VALUE_TYPE(pspec));
+ g_object_get_property((GObject *) s, option->name, &val);
+
+ if (option->to_sysfs) {
+ value = option->to_sysfs(&val);
+ goto out;
+ }
+
+ switch (pspec->value_type) {
+ case G_TYPE_BOOLEAN:
+ value = g_value_get_boolean(&val) ? "1" : "0";
+ break;
+ case G_TYPE_UINT64:
+ case G_TYPE_UINT:
+ {
+ guint64 uval;
+
+ if (pspec->value_type == G_TYPE_UINT64)
+ uval = g_value_get_uint64(&val);
+ else
+ uval = (guint) g_value_get_uint(&val);
+
+ /* zero means "unspecified" for some NM properties but isn't in the
+ * allowed kernel range, so reset the property to the default value.
+ */
+ if (option->default_if_zero && uval == 0) {
+ if (pspec->value_type == G_TYPE_UINT64)
+ uval = NM_G_PARAM_SPEC_GET_DEFAULT_UINT64(pspec);
+ else
+ uval = NM_G_PARAM_SPEC_GET_DEFAULT_UINT(pspec);
+ }
+
+ /* Linux kernel bridge interfaces use 'centiseconds' for time-based values.
+ * In reality it's not centiseconds, but depends on HZ and USER_HZ, which
+ * is almost always works out to be a multiplier of 100, so we can assume
+ * centiseconds. See clock_t_to_jiffies().
+ */
+ if (option->user_hz_compensate)
+ uval *= 100;
+
+ if (pspec->value_type == G_TYPE_UINT64)
+ nm_sprintf_buf(value_buf, "%" G_GUINT64_FORMAT, uval);
+ else
+ nm_sprintf_buf(value_buf, "%u", (guint) uval);
+
+ value = value_buf;
+ } break;
+ case G_TYPE_STRING:
+ value = g_value_get_string(&val);
+ break;
+ default:
+ nm_assert_not_reached();
+ value = NULL;
+ break;
+ }
+
+out:
+ if (!value)
+ return;
+
+ nm_platform_sysctl_slave_set_option(nm_device_get_platform(device),
+ ifindex,
+ option->sysname,
+ value);
+ }
}
static void
@@ -1042,7 +1025,7 @@ attach_port(NMDevice *device,
return FALSE;
}
- commit_slave_options(port, s_port);
+ commit_port_options(port, s_port);
_LOGI(LOGD_BRIDGE, "attached bridge port %s", nm_device_get_ip_iface(port));
} else {