diff options
author | Antonio Cardace <acardace@redhat.com> | 2020-03-26 12:02:20 +0100 |
---|---|---|
committer | Antonio Cardace <acardace@redhat.com> | 2020-04-06 09:56:11 +0200 |
commit | f5352ff656b888ea7e65c323087806b869b1e153 (patch) | |
tree | 2c0108ce43858827014d90d7fb4d1dd62817e3f8 | |
parent | 93e38cbe56f4af73046863735e7f8c7747145a29 (diff) | |
download | NetworkManager-f5352ff656b888ea7e65c323087806b869b1e153.tar.gz |
nm-setting-bridge: add 'vlan-protocol' bridge option
Also add related unit test.
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
-rw-r--r-- | clients/common/nm-meta-setting-desc.c | 7 | ||||
-rw-r--r-- | clients/common/settings-docs.h.in | 1 | ||||
-rw-r--r-- | libnm-core/nm-setting-bridge.c | 62 | ||||
-rw-r--r-- | libnm-core/nm-setting-bridge.h | 4 | ||||
-rw-r--r-- | libnm-core/tests/test-setting.c | 11 | ||||
-rw-r--r-- | libnm/libnm.ver | 1 | ||||
-rw-r--r-- | src/devices/nm-device-bridge.c | 31 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 1 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 7 |
9 files changed, 125 insertions, 0 deletions
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 30b49b44f5..a46e55510d 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -4911,6 +4911,13 @@ static const NMMetaPropertyInfo *const property_infos_BRIDGE[] = { PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID, .property_type = &_pt_gobject_int, ), + PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLAN_PROTOCOL, + .property_type = &_pt_gobject_string, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( + .values_static = NM_MAKE_STRV ("802.1Q", + "802.1ad"), + ), + ), PROPERTY_INFO_WITH_DESC (NM_SETTING_BRIDGE_VLANS, .property_type = &_pt_objlist, .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( diff --git a/clients/common/settings-docs.h.in b/clients/common/settings-docs.h.in index 4a9ea829e9..8bf37c58aa 100644 --- a/clients/common/settings-docs.h.in +++ b/clients/common/settings-docs.h.in @@ -124,6 +124,7 @@ #define DESCRIBE_DOC_NM_SETTING_BRIDGE_STP N_("Controls whether Spanning Tree Protocol (STP) is enabled for this bridge.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID N_("The default PVID for the ports of the bridge, that is the VLAN id assigned to incoming untagged frames.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_VLAN_FILTERING N_("Control whether VLAN filtering is enabled on the bridge.") +#define DESCRIBE_DOC_NM_SETTING_BRIDGE_VLAN_PROTOCOL N_("If specified, the protocol used for VLAN filtering. Supported values are: '802.1Q', '802.1ad'. If not specified the default value is '802.1Q'.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_VLANS N_("Array of bridge VLAN objects. In addition to the VLANs specified here, the bridge will also have the default-pvid VLAN configured by the bridge.vlan-default-pvid property. In nmcli the VLAN list can be specified with the following syntax: $vid [pvid] [untagged] [, $vid [pvid] [untagged]]... where $vid is either a single id between 1 and 4094 or a range, represented as a couple of ids separated by a dash.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE N_("Enables or disables \"hairpin mode\" for the port, which allows frames to be sent back out through the port the frame was received on.") #define DESCRIBE_DOC_NM_SETTING_BRIDGE_PORT_PATH_COST N_("The Spanning Tree Protocol (STP) port cost for destinations via this port.") diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c index 4190497aae..786c75434d 100644 --- a/libnm-core/nm-setting-bridge.c +++ b/libnm-core/nm-setting-bridge.c @@ -46,6 +46,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMSettingBridge, PROP_MULTICAST_SNOOPING, PROP_VLAN_FILTERING, PROP_VLAN_DEFAULT_PVID, + PROP_VLAN_PROTOCOL, PROP_VLANS, ); @@ -53,6 +54,7 @@ typedef struct { GPtrArray *vlans; char * mac_address; char * group_address; + char * vlan_protocol; guint32 ageing_time; guint16 priority; guint16 forward_delay; @@ -917,6 +919,22 @@ nm_setting_bridge_get_group_address (const NMSettingBridge *setting) return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->group_address; } +/** + * nm_setting_bridge_get_vlan_protocol: + * @setting: the #NMSettingBridge + * + * Returns: the #NMSettingBridge:vlan-protocol property of the setting + * + * Since 1.24 + **/ +const char * +nm_setting_bridge_get_vlan_protocol (const NMSettingBridge *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), NULL); + + return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->vlan_protocol; +} + /*****************************************************************************/ static gboolean @@ -1017,6 +1035,18 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } + if ( priv->vlan_protocol + && !NM_IN_STRSET (priv->vlan_protocol, + "802.1Q", + "802.1ad")) { + g_set_error_literal (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("is not a valid VLAN filtering protocol")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_BRIDGE_SETTING_NAME, NM_SETTING_BRIDGE_VLAN_PROTOCOL); + return FALSE; + } + /* Failures from here on are NORMALIZABLE... */ if (!_nm_utils_bridge_vlan_verify_list (priv->vlans, @@ -1112,6 +1142,9 @@ get_property (GObject *object, guint prop_id, case PROP_VLAN_DEFAULT_PVID: g_value_set_uint (value, priv->vlan_default_pvid); break; + case PROP_VLAN_PROTOCOL: + g_value_set_string (value, priv->vlan_protocol); + break; case PROP_VLANS: g_value_take_boxed (value, _nm_utils_copy_array (priv->vlans, (NMUtilsCopyFunc) nm_bridge_vlan_ref, @@ -1170,6 +1203,10 @@ set_property (GObject *object, guint prop_id, case PROP_VLAN_DEFAULT_PVID: priv->vlan_default_pvid = g_value_get_uint (value); break; + case PROP_VLAN_PROTOCOL: + g_free (priv->vlan_protocol); + priv->vlan_protocol = g_value_dup_string (value); + break; case PROP_VLANS: g_ptr_array_unref (priv->vlans); priv->vlans = _nm_utils_copy_array (g_value_get_boxed (value), @@ -1221,6 +1258,7 @@ finalize (GObject *object) g_free (priv->mac_address); g_free (priv->group_address); + g_free (priv->vlan_protocol); g_ptr_array_unref (priv->vlans); G_OBJECT_CLASS (nm_setting_bridge_parent_class)->finalize (object); @@ -1556,6 +1594,30 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) G_PARAM_STATIC_STRINGS); _nm_properties_override_gobj (properties_override, obj_properties[PROP_GROUP_ADDRESS], &nm_sett_info_propert_type_mac_address); + /** + * NMSettingBridge:vlan-protocol: + * + * If specified, the protocol used for VLAN filtering. + * + * Supported values are: '802.1Q', '802.1ad'. + * If not specified the default value is '802.1Q'. + * + * Since: 1.24 + **/ + /* ---ifcfg-rh--- + * property: vlan-protocol + * variable: BRIDGING_OPTS: vlan_protocol= + * description: VLAN filtering protocol. + * example: BRIDGING_OPTS="vlan_protocol=802.1Q" + * ---end--- + */ + obj_properties[PROP_VLAN_PROTOCOL] = + g_param_spec_string (NM_SETTING_BRIDGE_VLAN_PROTOCOL, "", "", + NULL, + G_PARAM_READWRITE | + NM_SETTING_PARAM_INFERRABLE | + G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_BRIDGE, diff --git a/libnm-core/nm-setting-bridge.h b/libnm-core/nm-setting-bridge.h index e4ff1af6d0..f1076ab443 100644 --- a/libnm-core/nm-setting-bridge.h +++ b/libnm-core/nm-setting-bridge.h @@ -36,6 +36,7 @@ G_BEGIN_DECLS #define NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID "vlan-default-pvid" #define NM_SETTING_BRIDGE_VLANS "vlans" #define NM_SETTING_BRIDGE_GROUP_ADDRESS "group-address" +#define NM_SETTING_BRIDGE_VLAN_PROTOCOL "vlan-protocol" #define NM_BRIDGE_VLAN_VID_MIN 1 #define NM_BRIDGE_VLAN_VID_MAX 4094 @@ -120,6 +121,9 @@ NMBridgeVlan * nm_bridge_vlan_from_str (const char *str, GError **error); NM_AVAILABLE_IN_1_24 const char * nm_setting_bridge_get_group_address (const NMSettingBridge *setting); +NM_AVAILABLE_IN_1_24 +const char * nm_setting_bridge_get_vlan_protocol (const NMSettingBridge *setting); + G_END_DECLS #endif /* __NM_SETTING_BRIDGE_H__ */ diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c index 878c6472af..58e2bd5108 100644 --- a/libnm-core/tests/test-setting.c +++ b/libnm-core/tests/test-setting.c @@ -1966,6 +1966,17 @@ test_bridge_verify (void) "group-address", "01:80:C2:00:00:00"); test_verify_options_bridge (TRUE, "group-address", "01:80:C2:00:00:0A"); + /* vlan-protocol */ + test_verify_options_bridge (FALSE, + "vlan-protocol", "nonsense124"); + test_verify_options_bridge (FALSE, + "vlan-protocol", "802.11"); + test_verify_options_bridge (FALSE, + "vlan-protocol", "802.1Q1"); + test_verify_options_bridge (TRUE, + "vlan-protocol", "802.1Q"); + test_verify_options_bridge (TRUE, + "vlan-protocol", "802.1ad"); } /*****************************************************************************/ diff --git a/libnm/libnm.ver b/libnm/libnm.ver index d93a14c95a..14099ebb5b 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1686,6 +1686,7 @@ global: nm_setting_802_1x_get_phase2_domain_match; nm_setting_bond_get_option_normalized; nm_setting_bridge_get_group_address; + nm_setting_bridge_get_vlan_protocol; nm_setting_vrf_get_table; nm_setting_vrf_get_type; nm_setting_vrf_new; diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index ecac47a2b7..6b666b9551 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -171,6 +171,33 @@ to_sysfs_group_address (GValue *value) return g_value_get_string (value) ?: "01:80:C2:00:00:00"; } +static void +from_sysfs_vlan_protocol (const char *value, GValue *out) +{ + switch (_nm_utils_ascii_str_to_uint64 (value, 16, 0, G_MAXUINT, -1)) { + case ETH_P_8021Q: + /* default value */ + break; + case ETH_P_8021AD: + g_value_set_string (out, "802.1ad"); + break; + } +} + +static const char * +to_sysfs_vlan_protocol (GValue *value) +{ + const char *str = g_value_get_string (value); + + if (nm_streq0 (str, "802.1ad")) { + G_STATIC_ASSERT_EXPR (ETH_P_8021AD == 0x88A8); + return "0x88A8"; + } + + G_STATIC_ASSERT_EXPR (ETH_P_8021Q == 0x8100); + return "0x8100"; +} + /*****************************************************************************/ typedef struct { @@ -223,6 +250,10 @@ static const Option master_options[] = { to_sysfs_group_address, from_sysfs_group_address, 0, 0, 0, FALSE, FALSE, FALSE }, + { NM_SETTING_BRIDGE_VLAN_PROTOCOL, "vlan_protocol", + to_sysfs_vlan_protocol, from_sysfs_vlan_protocol, + 0, 0, 0, + FALSE, FALSE, FALSE }, { NULL, NULL } }; diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 2f8d8afaaf..6076011fe9 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -5162,6 +5162,7 @@ handle_bridge_option (NMSetting *setting, { "default_pvid", NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID, BRIDGE_OPT_TYPE_OPTION }, { "group_address", NM_SETTING_BRIDGE_GROUP_ADDRESS, BRIDGE_OPT_TYPE_OPTION }, { "group_fwd_mask", NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, BRIDGE_OPT_TYPE_OPTION }, + { "vlan_protocol", NM_SETTING_BRIDGE_VLAN_PROTOCOL, BRIDGE_OPT_TYPE_OPTION }, { "priority", NM_SETTING_BRIDGE_PORT_PRIORITY, BRIDGE_OPT_TYPE_PORT_OPTION }, { "path_cost", NM_SETTING_BRIDGE_PORT_PATH_COST, BRIDGE_OPT_TYPE_PORT_OPTION }, { "hairpin_mode", NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, BRIDGE_OPT_TYPE_PORT_OPTION, .extended_bool = TRUE, }, diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index 181e6bbf24..fa947f10ab 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -1522,6 +1522,13 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wire g_string_append_printf (opts, "default_pvid=%u", i); } + s = nm_setting_bridge_get_vlan_protocol (s_bridge); + if (s) { + if (opts->len) + g_string_append_c (opts, ' '); + g_string_append_printf (opts, "vlan_protocol=%s", s); + } + if (opts->len) svSetValueStr (ifcfg, "BRIDGING_OPTS", opts->str); g_string_free (opts, TRUE); |