diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2016-09-12 18:51:00 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2016-09-12 18:51:00 +0200 |
commit | d65712b92013992e40ec9f02f6d2dc9ae16a6380 (patch) | |
tree | 71f46ddf05cc6b32cdf5e884d0679ab3e1da4df2 | |
parent | b519b96c4e9c4b3c91745a1343b0db0997c03b18 (diff) | |
download | NetworkManager-bg/bgo763937.tar.gz |
wipbg/bgo763937
-rw-r--r-- | libnm-core/nm-connection.c | 10 | ||||
-rw-r--r-- | libnm-core/nm-setting-ip4-config.c | 14 | ||||
-rw-r--r-- | libnm-core/tests/test-general.c | 54 |
3 files changed, 78 insertions, 0 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 57f964095e..b9e9f660e6 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -726,6 +726,7 @@ _normalize_ip_config (NMConnection *self, GHashTable *parameters) NMSettingIPConfig *s_ip4, *s_ip6; NMSetting *setting; gboolean changed = FALSE; + guint num, i; if (parameters) default_ip6_method = g_hash_table_lookup (parameters, NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD); @@ -771,6 +772,15 @@ _normalize_ip_config (NMConnection *self, GHashTable *parameters) g_object_set (s_ip4, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); changed = TRUE; } + + num = nm_setting_ip_config_get_num_addresses (s_ip4); + if ( num > 1 + && nm_streq (nm_setting_ip_config_get_method (s_ip4), + NM_SETTING_IP4_CONFIG_METHOD_SHARED)) { + for (i = num - 1; i > 0; i--) + nm_setting_ip_config_remove_address (s_ip4, 1); + changed = TRUE; + } } if (!s_ip6) { setting = nm_setting_ip6_config_new (); diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index 70fab0e2b1..91a4a3f50c 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -225,6 +225,20 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } + /* Failures from here on are NORMALIZABLE_ERROR... */ + + if ( nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) + && nm_setting_ip_config_get_num_addresses (s_ip) > 1) { + g_set_error (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("multiple addresses are not allowed for '%s=%s'"), + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_SHARED); + g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_ADDRESSES); + return NM_SETTING_VERIFY_NORMALIZABLE_ERROR; + } + /* Failures from here on are NORMALIZABLE... */ if ( !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 6aee25273d..554e6baeed 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -3961,6 +3961,59 @@ test_connection_normalize_may_fail (void) } static void +test_connection_normalize_shared_addresses (void) +{ + gs_unref_object NMConnection *con = NULL; + NMSettingIPConfig *s_ip4, *s_ip6; + NMIPAddress *addr; + gs_free_error GError *error = NULL; + + con = nmtst_create_minimal_connection ("test1", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); + nmtst_assert_connection_verifies_and_normalizable (con); + + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); + g_object_set (G_OBJECT (s_ip4), + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED, + NULL); + + addr = nm_ip_address_new (AF_INET, "1.1.1.1", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); + + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); + g_object_set (s_ip6, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NULL); + + nm_connection_add_setting (con, (NMSetting *) s_ip4); + nm_connection_add_setting (con, (NMSetting *) s_ip6); + + nmtst_assert_connection_verifies_without_normalization (con); + + /* Now we add other addresses and check that they are + * removed during normalization + * */ + addr = nm_ip_address_new (AF_INET, "2.2.2.2", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); + + addr = nm_ip_address_new (AF_INET, "3.3.3.3", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); + + nmtst_assert_connection_verifies_after_normalization (con, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY); + nmtst_connection_normalize (con); + g_assert_cmpuint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1); + addr = nm_setting_ip_config_get_address (s_ip4, 0); + g_assert_cmpstr (nm_ip_address_get_address (addr), ==, "1.1.1.1"); +} + +static void test_setting_ip4_gateway (void) { NMConnection *conn; @@ -5364,6 +5417,7 @@ int main (int argc, char **argv) g_test_add_func ("/core/general/test_connection_normalize_infiniband_mtu", test_connection_normalize_infiniband_mtu); g_test_add_func ("/core/general/test_connection_normalize_gateway_never_default", test_connection_normalize_gateway_never_default); g_test_add_func ("/core/general/test_connection_normalize_may_fail", test_connection_normalize_may_fail); + g_test_add_func ("/core/general/test_connection_normalize_shared_addresses", test_connection_normalize_shared_addresses); g_test_add_func ("/core/general/test_setting_connection_permissions_helpers", test_setting_connection_permissions_helpers); g_test_add_func ("/core/general/test_setting_connection_permissions_property", test_setting_connection_permissions_property); |