ifcfg-rh: read/write multicast-snooping property

This commit is contained in:
Jiří Klimeš 2015-02-20 12:40:36 +01:00
parent 1252386940
commit b9c79de295
4 changed files with 42 additions and 10 deletions

View file

@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2008 - 2014 Red Hat, Inc.
* Copyright 2008 - 2015 Red Hat, Inc.
*/
#include "config.h"
@ -4092,6 +4092,12 @@ handle_bridge_option (NMSetting *setting,
g_object_set (setting, NM_SETTING_BRIDGE_AGEING_TIME, u, NULL);
else
PARSE_WARNING ("invalid ageing_time value '%s'", value);
} else if (!strcmp (key, "multicast_snooping")) {
if (get_uint (value, &u))
g_object_set (setting, NM_SETTING_BRIDGE_MULTICAST_SNOOPING,
(gboolean) u, NULL);
else
PARSE_WARNING ("invalid multicast_snooping value '%s'", value);
} else
PARSE_WARNING ("unhandled bridge option '%s'", key);
}

View file

@ -4,5 +4,5 @@ TYPE=Bridge
BOOTPROTO=dhcp
STP=on
DELAY=2
BRIDGING_OPTS="priority=32744 hello_time=7 max_age=39 ageing_time=235352"
BRIDGING_OPTS="priority=32744 hello_time=7 max_age=39 ageing_time=235352 multicast_snooping=0"
MACADDR=00:16:41:11:22:33

View file

@ -10369,6 +10369,7 @@ test_read_bridge_main (void)
g_assert_cmpuint (nm_setting_bridge_get_hello_time (s_bridge), ==, 7);
g_assert_cmpuint (nm_setting_bridge_get_max_age (s_bridge), ==, 39);
g_assert_cmpuint (nm_setting_bridge_get_ageing_time (s_bridge), ==, 235352);
g_assert (!nm_setting_bridge_get_multicast_snooping (s_bridge));
/* MAC address */
mac = nm_setting_bridge_get_mac_address (s_bridge);

View file

@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2009 - 2014 Red Hat, Inc.
* Copyright 2009 - 2015 Red Hat, Inc.
*/
#include "config.h"
@ -1317,7 +1317,7 @@ write_team_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
}
static guint32
get_setting_default (NMSetting *setting, const char *prop)
get_setting_default_uint (NMSetting *setting, const char *prop)
{
GParamSpec *pspec;
GValue val = G_VALUE_INIT;
@ -1333,12 +1333,30 @@ get_setting_default (NMSetting *setting, const char *prop)
return ret;
}
static gboolean
get_setting_default_boolean (NMSetting *setting, const char *prop)
{
GParamSpec *pspec;
GValue val = G_VALUE_INIT;
gboolean ret = 0;
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), prop);
g_assert (pspec);
g_value_init (&val, pspec->value_type);
g_param_value_set_default (pspec, &val);
g_assert (G_VALUE_HOLDS_BOOLEAN (&val));
ret = g_value_get_boolean (&val);
g_value_unset (&val);
return ret;
}
static gboolean
write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
{
NMSettingBridge *s_bridge;
const char *iface;
guint32 i;
gboolean b;
GString *opts;
const char *mac;
char *s;
@ -1372,7 +1390,7 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error
svSetValue (ifcfg, "STP", "yes", FALSE);
i = nm_setting_bridge_get_forward_delay (s_bridge);
if (i != get_setting_default (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_FORWARD_DELAY)) {
if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_FORWARD_DELAY)) {
s = g_strdup_printf ("%u", i);
svSetValue (ifcfg, "DELAY", s, FALSE);
g_free (s);
@ -1381,14 +1399,14 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error
g_string_append_printf (opts, "priority=%u", nm_setting_bridge_get_priority (s_bridge));
i = nm_setting_bridge_get_hello_time (s_bridge);
if (i != get_setting_default (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_HELLO_TIME)) {
if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_HELLO_TIME)) {
if (opts->len)
g_string_append_c (opts, ' ');
g_string_append_printf (opts, "hello_time=%u", i);
}
i = nm_setting_bridge_get_max_age (s_bridge);
if (i != get_setting_default (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_MAX_AGE)) {
if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_MAX_AGE)) {
if (opts->len)
g_string_append_c (opts, ' ');
g_string_append_printf (opts, "max_age=%u", i);
@ -1396,12 +1414,19 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error
}
i = nm_setting_bridge_get_ageing_time (s_bridge);
if (i != get_setting_default (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_AGEING_TIME)) {
if (i != get_setting_default_uint (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_AGEING_TIME)) {
if (opts->len)
g_string_append_c (opts, ' ');
g_string_append_printf (opts, "ageing_time=%u", i);
}
b = nm_setting_bridge_get_multicast_snooping (s_bridge);
if (b != get_setting_default_boolean (NM_SETTING (s_bridge), NM_SETTING_BRIDGE_MULTICAST_SNOOPING)) {
if (opts->len)
g_string_append_c (opts, ' ');
g_string_append_printf (opts, "multicast_snooping=%u", (guint32) b);
}
if (opts->len)
svSetValue (ifcfg, "BRIDGING_OPTS", opts->str, FALSE);
g_string_free (opts, TRUE);
@ -1428,11 +1453,11 @@ write_bridge_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **
opts = g_string_sized_new (32);
i = nm_setting_bridge_port_get_priority (s_port);
if (i != get_setting_default (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PRIORITY))
if (i != get_setting_default_uint (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PRIORITY))
g_string_append_printf (opts, "priority=%u", i);
i = nm_setting_bridge_port_get_path_cost (s_port);
if (i != get_setting_default (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PATH_COST)) {
if (i != get_setting_default_uint (NM_SETTING (s_port), NM_SETTING_BRIDGE_PORT_PATH_COST)) {
if (opts->len)
g_string_append_c (opts, ' ');
g_string_append_printf (opts, "path_cost=%u", i);