From cf213216fd968b9b2de59bd012d1a7f536908b21 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Feb 2017 15:24:58 +0100 Subject: [PATCH] libnm-core: add ethernet setting for vlan connection A "vlan" setting can optionally have an ethernet setting. However, ifcfg-rh reader always adds such a setting, because well... Anyway, the result is that writing a VLAN setting without ethernet section will yield a different result on re-read. Let's have normalization add the ethernet setting, so that two we consistently have it present. --- libnm-core/nm-connection.c | 15 ++++++++++++++- libnm-core/nm-setting-vlan.c | 14 +++++++++++++- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 4 +--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index ce6f405c35..08edec70c8 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -986,6 +986,18 @@ _normalize_team_port_config (NMConnection *self, GHashTable *parameters) return FALSE; } +static gboolean +_normalize_required_settings (NMConnection *self, GHashTable *parameters) +{ + if (nm_connection_get_setting_vlan (self)) { + if (!nm_connection_get_setting_wired (self)) { + nm_connection_add_setting (self, nm_setting_wired_new ()); + return TRUE; + } + } + return FALSE; +} + /** * nm_connection_verify: * @connection: the #NMConnection to verify @@ -1233,8 +1245,9 @@ nm_connection_normalize (NMConnection *connection, was_modified |= _normalize_connection_uuid (connection); was_modified |= _normalize_connection_type (connection); was_modified |= _normalize_connection_slave_type (connection); - was_modified |= _normalize_ethernet_link_neg (connection); + was_modified |= _normalize_required_settings (connection, parameters); was_modified |= _normalize_ip_config (connection, parameters); + was_modified |= _normalize_ethernet_link_neg (connection); was_modified |= _normalize_infiniband_mtu (connection, parameters); was_modified |= _normalize_bond_mode (connection, parameters); was_modified |= _normalize_wireless_mac_address_randomization (connection, parameters); diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c index 6126478479..bbda72d7bb 100644 --- a/libnm-core/nm-setting-vlan.c +++ b/libnm-core/nm-setting-vlan.c @@ -600,7 +600,7 @@ nm_setting_vlan_init (NMSettingVlan *setting) { } -static gboolean +static int verify (NMSetting *setting, NMConnection *connection, GError **error) { NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting); @@ -681,6 +681,18 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } + if (connection && !s_wired) { + /* technically, a VLAN setting does not require an ethernet setting. However, + * the ifcfg-rh reader always adds a ethernet setting when reading a vlan setting. + * Thus, in order to be consistent, always add one via normalization. */ + g_set_error_literal (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_SETTING_NOT_FOUND, + _("vlan setting should have a ethernet setting as well")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_FLAGS); + return NM_SETTING_VERIFY_NORMALIZABLE; + } + return TRUE; } diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index b98ac9dd88..824fa1aca3 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -8403,8 +8403,6 @@ test_team_reread_slave (void) "permissions=\n" "slave-type=team\n" "\n" - "[ethernet]\n" - "\n" "[vlan]\n" "egress-priority-map=\n" "flags=1\n" @@ -8427,7 +8425,7 @@ test_team_reread_slave (void) NM_SETTING_VLAN_PARENT, "enp31s0f1", NULL); nm_connection_add_setting (connection_2, nm_setting_team_port_new ()); - nm_connection_add_setting (connection_2, nm_setting_wired_new ()); + nmtst_connection_normalize (connection_2); nmtst_assert_connection_equals (connection_1, FALSE, connection_2, FALSE);