summaryrefslogtreecommitdiff
path: root/libnm-core
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-10-04 16:44:39 +0200
committerThomas Haller <thaller@redhat.com>2016-10-05 14:53:21 +0200
commit8b51e345af65982b03fb0f0e5114e8a7e14a5090 (patch)
treece1ef52d657b22b81001ba1ac1179d2c4d20f91a /libnm-core
parente2c71c82e7e8bc87b3f1c820adacf3595dc18656 (diff)
downloadNetworkManager-8b51e345af65982b03fb0f0e5114e8a7e14a5090.tar.gz
libnm/proxy: add proxy setting for non-slave connection during normalization
And reject slave settings with proxies.
Diffstat (limited to 'libnm-core')
-rw-r--r--libnm-core/nm-connection.c29
-rw-r--r--libnm-core/tests/test-general.c5
-rw-r--r--libnm-core/tests/test-keyfile.c16
3 files changed, 41 insertions, 9 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index f7ebe6418b..d26f57a654 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -724,6 +724,7 @@ _normalize_ip_config (NMConnection *self, GHashTable *parameters)
const char *default_ip4_method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
const char *default_ip6_method = NULL;
NMSettingIPConfig *s_ip4, *s_ip6;
+ NMSettingProxy *s_proxy;
NMSetting *setting;
gboolean changed = FALSE;
guint num, i;
@@ -735,6 +736,7 @@ _normalize_ip_config (NMConnection *self, GHashTable *parameters)
s_ip4 = nm_connection_get_setting_ip4_config (self);
s_ip6 = nm_connection_get_setting_ip6_config (self);
+ s_proxy = nm_connection_get_setting_proxy (self);
if (nm_setting_connection_get_master (s_con)) {
/* Slave connections don't have IP configuration. */
@@ -745,7 +747,10 @@ _normalize_ip_config (NMConnection *self, GHashTable *parameters)
if (s_ip6)
nm_connection_remove_setting (self, NM_TYPE_SETTING_IP6_CONFIG);
- return s_ip4 || s_ip6;
+ if (s_proxy)
+ nm_connection_remove_setting (self, NM_TYPE_SETTING_PROXY);
+
+ return s_ip4 || s_ip6 || s_proxy;
} else {
/* Ensure all non-slave connections have IP4 and IP6 settings objects. If no
* IP6 setting was specified, then assume that means IP6 config is allowed
@@ -822,7 +827,13 @@ _normalize_ip_config (NMConnection *self, GHashTable *parameters)
changed = TRUE;
}
}
- return !s_ip4 || !s_ip6 || changed;
+
+ if (!s_proxy) {
+ setting = nm_setting_proxy_new ();
+ nm_connection_add_setting (self, setting);
+ }
+
+ return !s_ip4 || !s_ip6 || !s_proxy || changed;
}
}
@@ -986,6 +997,7 @@ _nm_connection_verify (NMConnection *connection, GError **error)
NMConnectionPrivate *priv;
NMSettingConnection *s_con;
NMSettingIPConfig *s_ip4, *s_ip6;
+ NMSettingProxy *s_proxy;
GHashTableIter iter;
gpointer value;
GSList *all_settings = NULL, *setting_i;
@@ -1059,11 +1071,12 @@ _nm_connection_verify (NMConnection *connection, GError **error)
s_ip4 = nm_connection_get_setting_ip4_config (connection);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
+ s_proxy = nm_connection_get_setting_proxy (connection);
if (nm_setting_connection_get_master (s_con)) {
if ( NM_IN_SET (normalizable_error_type, NM_SETTING_VERIFY_SUCCESS,
NM_SETTING_VERIFY_NORMALIZABLE)
- && (s_ip4 || s_ip6)) {
+ && (s_ip4 || s_ip6 || s_proxy)) {
g_clear_error (&normalizable_error);
g_set_error_literal (&normalizable_error,
NM_CONNECTION_ERROR,
@@ -1072,13 +1085,15 @@ _nm_connection_verify (NMConnection *connection, GError **error)
g_prefix_error (&normalizable_error, "%s: ",
s_ip4
? NM_SETTING_IP4_CONFIG_SETTING_NAME
- : NM_SETTING_IP6_CONFIG_SETTING_NAME);
+ : (s_ip6
+ ? NM_SETTING_IP6_CONFIG_SETTING_NAME
+ : NM_SETTING_PROXY_SETTING_NAME));
/* having a slave with IP config *was* and is a verify() error. */
normalizable_error_type = NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
}
} else {
if ( NM_IN_SET (normalizable_error_type, NM_SETTING_VERIFY_SUCCESS)
- && (!s_ip4 || !s_ip6)) {
+ && (!s_ip4 || !s_ip6 || !s_proxy)) {
g_set_error_literal (&normalizable_error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_SETTING,
@@ -1086,7 +1101,9 @@ _nm_connection_verify (NMConnection *connection, GError **error)
g_prefix_error (&normalizable_error, "%s: ",
!s_ip4
? NM_SETTING_IP4_CONFIG_SETTING_NAME
- : NM_SETTING_IP6_CONFIG_SETTING_NAME);
+ : (!s_ip6
+ ? NM_SETTING_IP6_CONFIG_SETTING_NAME
+ : NM_SETTING_PROXY_SETTING_NAME));
/* having a master without IP config was not a verify() error, accept
* it for backward compatibility. */
normalizable_error_type = NM_SETTING_VERIFY_NORMALIZABLE;
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
index 52c6f80911..414c6659b3 100644
--- a/libnm-core/tests/test-general.c
+++ b/libnm-core/tests/test-general.c
@@ -3900,6 +3900,7 @@ test_connection_normalize_gateway_never_default (void)
nm_connection_add_setting (con, (NMSetting *) s_ip4);
nm_connection_add_setting (con, (NMSetting *) s_ip6);
+ nm_connection_add_setting (con, nm_setting_proxy_new ());
nmtst_assert_connection_verifies_without_normalization (con);
g_assert_cmpstr ("1.1.1.254", ==, nm_setting_ip_config_get_gateway (s_ip4));
@@ -3942,7 +3943,7 @@ test_connection_normalize_may_fail (void)
nm_connection_add_setting (con, (NMSetting *) s_ip4);
nm_connection_add_setting (con, (NMSetting *) s_ip6);
- nmtst_assert_connection_verifies_without_normalization (con);
+ nmtst_assert_connection_verifies_and_normalizable (con);
/* Now set method=disabled/ignore and check that may-fail becomes TRUE
* after normalization
@@ -3989,7 +3990,7 @@ test_connection_normalize_shared_addresses (void)
nm_connection_add_setting (con, (NMSetting *) s_ip4);
nm_connection_add_setting (con, (NMSetting *) s_ip6);
- nmtst_assert_connection_verifies_without_normalization (con);
+ nmtst_assert_connection_verifies_and_normalizable (con);
/* Now we add other addresses and check that they are
* removed during normalization
diff --git a/libnm-core/tests/test-keyfile.c b/libnm-core/tests/test-keyfile.c
index 84dcffbb9f..9944eb5ef8 100644
--- a/libnm-core/tests/test-keyfile.c
+++ b/libnm-core/tests/test-keyfile.c
@@ -28,6 +28,7 @@
#include "nm-setting-wired.h"
#include "nm-setting-8021x.h"
#include "nm-setting-team.h"
+#include "nm-setting-proxy.h"
#include "nm-utils/nm-test-utils.h"
@@ -115,8 +116,21 @@ _nm_keyfile_read (GKeyFile *keyfile,
if (needs_normalization) {
nmtst_assert_connection_verifies_after_normalization (con, 0, 0);
nmtst_connection_normalize (con);
- } else
+ } else {
+ {
+ NMSettingConnection *s_con;
+
+ /* a non-slave connection must have a proxy setting, but
+ * keyfile reader does not add that (unless a [proxy] section
+ * is present. */
+ s_con = nm_connection_get_setting_connection (con);
+ if ( s_con
+ && !nm_setting_connection_get_master (s_con)
+ && !nm_connection_get_setting_proxy (con))
+ nm_connection_add_setting (con, nm_setting_proxy_new ());
+ }
nmtst_assert_connection_verifies_without_normalization (con);
+ }
return con;
}