mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 14:00:15 +01:00
proxy: merge branch 'th/proxy-cleanup'
This commit is contained in:
commit
67405bd5bc
12 changed files with 333 additions and 699 deletions
|
|
@ -3482,7 +3482,7 @@ do_device_wifi_hotspot (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
s_proxy = (NMSettingProxy *) nm_setting_proxy_new ();
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_proxy));
|
||||
g_object_set (s_proxy, NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_NONE, NULL);
|
||||
g_object_set (s_proxy, NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE, NULL);
|
||||
|
||||
/* Activate the connection now */
|
||||
nmc->nowait_flag = (nmc->timeout == 0);
|
||||
|
|
|
|||
|
|
@ -2133,18 +2133,18 @@ static gboolean
|
|||
nmc_property_proxy_set_method (NMSetting *setting, const char *prop,
|
||||
const char *val, GError **error)
|
||||
{
|
||||
NMSettingProxyMethod method;
|
||||
int method;
|
||||
gboolean ret;
|
||||
|
||||
ret = nm_utils_enum_from_str (nm_setting_proxy_method_get_type(), val,
|
||||
(int *) &method, NULL);
|
||||
&method, NULL);
|
||||
|
||||
if (!ret) {
|
||||
gs_free const char **values = NULL;
|
||||
gs_free char *values_str = NULL;
|
||||
|
||||
values = nm_utils_enum_get_values (nm_setting_proxy_method_get_type (),
|
||||
NM_SETTING_PROXY_METHOD_AUTO,
|
||||
NM_SETTING_PROXY_METHOD_NONE,
|
||||
G_MAXINT);
|
||||
values_str = g_strjoinv (",", (char **) values);
|
||||
g_set_error (error, 1, 0, _("invalid method '%s', use one of %s"),
|
||||
|
|
@ -2559,7 +2559,7 @@ nmc_setting_custom_init (NMSetting *setting)
|
|||
NULL);
|
||||
} else if (NM_IS_SETTING_PROXY (setting)) {
|
||||
g_object_set (NM_SETTING_PROXY (setting),
|
||||
NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_NONE,
|
||||
NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE,
|
||||
NULL);
|
||||
} else if (NM_IS_SETTING_TUN (setting)) {
|
||||
g_object_set (NM_SETTING_TUN (setting),
|
||||
|
|
|
|||
|
|
@ -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,11 +997,11 @@ _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;
|
||||
NMSettingVerifyResult success = NM_SETTING_VERIFY_ERROR;
|
||||
GError *normalizable_error = NULL;
|
||||
gs_free_error GError *normalizable_error = NULL;
|
||||
NMSettingVerifyResult normalizable_error_type = NM_SETTING_VERIFY_SUCCESS;
|
||||
|
||||
g_return_val_if_fail (NM_IS_CONNECTION (connection), NM_SETTING_VERIFY_ERROR);
|
||||
|
|
@ -1006,7 +1017,7 @@ _nm_connection_verify (NMConnection *connection, GError **error)
|
|||
NM_CONNECTION_ERROR_MISSING_SETTING,
|
||||
_("setting not found"));
|
||||
g_prefix_error (error, "%s: ", NM_SETTING_CONNECTION_SETTING_NAME);
|
||||
goto EXIT;
|
||||
return NM_SETTING_VERIFY_ERROR;
|
||||
}
|
||||
|
||||
/* Build up the list of settings */
|
||||
|
|
@ -1051,8 +1062,8 @@ _nm_connection_verify (NMConnection *connection, GError **error)
|
|||
} else if (verify_result != NM_SETTING_VERIFY_SUCCESS) {
|
||||
g_propagate_error (error, verify_error);
|
||||
g_slist_free (all_settings);
|
||||
g_return_val_if_fail (verify_result == NM_SETTING_VERIFY_ERROR, success);
|
||||
goto EXIT;
|
||||
g_return_val_if_fail (verify_result == NM_SETTING_VERIFY_ERROR, NM_SETTING_VERIFY_ERROR);
|
||||
return NM_SETTING_VERIFY_ERROR;
|
||||
}
|
||||
g_clear_error (&verify_error);
|
||||
}
|
||||
|
|
@ -1060,28 +1071,39 @@ _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 ((normalizable_error_type == NM_SETTING_VERIFY_SUCCESS ||
|
||||
(normalizable_error_type == NM_SETTING_VERIFY_NORMALIZABLE)) && (s_ip4 || s_ip6)) {
|
||||
if ( NM_IN_SET (normalizable_error_type, NM_SETTING_VERIFY_SUCCESS,
|
||||
NM_SETTING_VERIFY_NORMALIZABLE)
|
||||
&& (s_ip4 || s_ip6 || s_proxy)) {
|
||||
g_clear_error (&normalizable_error);
|
||||
g_set_error_literal (&normalizable_error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_SETTING,
|
||||
_("setting not allowed in slave connection"));
|
||||
g_prefix_error (&normalizable_error, "%s: ",
|
||||
s_ip4 ? NM_SETTING_IP4_CONFIG_SETTING_NAME : NM_SETTING_IP6_CONFIG_SETTING_NAME);
|
||||
s_ip4
|
||||
? NM_SETTING_IP4_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 (normalizable_error_type == NM_SETTING_VERIFY_SUCCESS && (!s_ip4 || !s_ip6)) {
|
||||
if ( NM_IN_SET (normalizable_error_type, NM_SETTING_VERIFY_SUCCESS)
|
||||
&& (!s_ip4 || !s_ip6 || !s_proxy)) {
|
||||
g_set_error_literal (&normalizable_error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_MISSING_SETTING,
|
||||
_("setting is required for non-slave connections"));
|
||||
g_prefix_error (&normalizable_error, "%s: ",
|
||||
!s_ip4 ? NM_SETTING_IP4_CONFIG_SETTING_NAME : NM_SETTING_IP6_CONFIG_SETTING_NAME);
|
||||
!s_ip4
|
||||
? NM_SETTING_IP4_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;
|
||||
|
|
@ -1091,13 +1113,10 @@ _nm_connection_verify (NMConnection *connection, GError **error)
|
|||
if (normalizable_error_type != NM_SETTING_VERIFY_SUCCESS) {
|
||||
g_propagate_error (error, normalizable_error);
|
||||
normalizable_error = NULL;
|
||||
success = normalizable_error_type;
|
||||
} else
|
||||
success = NM_SETTING_VERIFY_SUCCESS;
|
||||
return normalizable_error_type;
|
||||
}
|
||||
|
||||
EXIT:
|
||||
g_clear_error (&normalizable_error);
|
||||
return success;
|
||||
return NM_SETTING_VERIFY_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -153,7 +153,19 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
|
|||
NMSettingProxyMethod method;
|
||||
|
||||
method = priv->method;
|
||||
if (method == NM_SETTING_PROXY_METHOD_NONE) {
|
||||
|
||||
if (!NM_IN_SET (method,
|
||||
NM_SETTING_PROXY_METHOD_NONE,
|
||||
NM_SETTING_PROXY_METHOD_AUTO)) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
_("invalid proxy method"));
|
||||
g_prefix_error (error, "%s.%s: ", NM_SETTING_PROXY_SETTING_NAME, NM_SETTING_PROXY_PAC_URL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (method != NM_SETTING_PROXY_METHOD_AUTO) {
|
||||
if (priv->pac_url) {
|
||||
g_set_error (error,
|
||||
NM_CONNECTION_ERROR,
|
||||
|
|
@ -188,9 +200,6 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
|
|||
static void
|
||||
nm_setting_proxy_init (NMSettingProxy *setting)
|
||||
{
|
||||
NMSettingProxyPrivate *priv = NM_SETTING_PROXY_GET_PRIVATE (setting);
|
||||
|
||||
priv->method = NM_SETTING_PROXY_METHOD_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -207,7 +216,7 @@ finalize (GObject *object)
|
|||
|
||||
static void
|
||||
get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMSettingProxy *setting = NM_SETTING_PROXY (object);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,16 +32,16 @@ G_BEGIN_DECLS
|
|||
|
||||
/**
|
||||
* NMSettingProxyMethod:
|
||||
* @NM_SETTING_PROXY_METHOD_AUTO: DHCP obtained Proxy/ Manual override
|
||||
* @NM_SETTING_PROXY_METHOD_NONE: No Proxy for the Connection
|
||||
* @NM_SETTING_PROXY_METHOD_NONE: No Proxy for the Connection
|
||||
* @NM_SETTING_PROXY_METHOD_AUTO: DHCP obtained Proxy/ Manual override
|
||||
*
|
||||
* The Proxy method.
|
||||
*
|
||||
* Since: 1.6
|
||||
*/
|
||||
typedef enum {
|
||||
NM_SETTING_PROXY_METHOD_AUTO = 0,
|
||||
NM_SETTING_PROXY_METHOD_NONE
|
||||
NM_SETTING_PROXY_METHOD_NONE = 0,
|
||||
NM_SETTING_PROXY_METHOD_AUTO = 1,
|
||||
} NMSettingProxyMethod;
|
||||
|
||||
#define NM_TYPE_SETTING_PROXY (nm_setting_proxy_get_type ())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -979,6 +979,10 @@ __define_nmtst_static(02, 1024)
|
|||
__define_nmtst_static(03, 1024)
|
||||
#undef __define_nmtst_static
|
||||
|
||||
#define NMTST_UUID_INIT(uuid) \
|
||||
gs_free char *_nmtst_hidden_##uuid = nm_utils_uuid_generate (); \
|
||||
const char *const uuid = _nmtst_hidden_##uuid
|
||||
|
||||
inline static const char *
|
||||
nmtst_uuid_generate (void)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -922,7 +922,7 @@ make_proxy_setting (shvarFile *ifcfg, GError **error)
|
|||
switch (method) {
|
||||
case NM_SETTING_PROXY_METHOD_AUTO:
|
||||
g_object_set (s_proxy,
|
||||
NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_AUTO,
|
||||
NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_AUTO,
|
||||
NULL);
|
||||
|
||||
value = svGetValue (ifcfg, "PAC_URL", FALSE);
|
||||
|
|
@ -942,16 +942,16 @@ make_proxy_setting (shvarFile *ifcfg, GError **error)
|
|||
break;
|
||||
case NM_SETTING_PROXY_METHOD_NONE:
|
||||
g_object_set (s_proxy,
|
||||
NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_NONE,
|
||||
NM_SETTING_PROXY_METHOD, (int) NM_SETTING_PROXY_METHOD_NONE,
|
||||
NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
value = svGetValue (ifcfg, "BROWSER_ONLY", FALSE);
|
||||
if (value) {
|
||||
if (!g_ascii_strcasecmp (value, "yes")) {
|
||||
if (!g_ascii_strcasecmp (value, "yes"))
|
||||
g_object_set (s_proxy, NM_SETTING_PROXY_BROWSER_ONLY, TRUE, NULL);
|
||||
g_free (value);
|
||||
}
|
||||
g_free (value);
|
||||
}
|
||||
|
||||
return NM_SETTING (s_proxy);
|
||||
|
|
|
|||
|
|
@ -3645,6 +3645,8 @@ test_write_wired_static (void)
|
|||
g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip4), ==, 204);
|
||||
g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip6), ==, 206);
|
||||
|
||||
nm_connection_add_setting (connection, nm_setting_proxy_new ());
|
||||
|
||||
nmtst_assert_connection_equals (connection, FALSE, reread, FALSE);
|
||||
|
||||
route6file = utils_get_route6_path (testfile);
|
||||
|
|
@ -7149,6 +7151,8 @@ test_write_bridge_main (void)
|
|||
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
|
||||
NULL);
|
||||
|
||||
nm_connection_add_setting (connection, nm_setting_proxy_new ());
|
||||
|
||||
nmtst_assert_connection_verifies_without_normalization (connection);
|
||||
|
||||
_writer_new_connection (connection,
|
||||
|
|
@ -7760,6 +7764,8 @@ test_write_bond_main (void)
|
|||
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
|
||||
NULL);
|
||||
|
||||
nm_connection_add_setting (connection, nm_setting_proxy_new ());
|
||||
|
||||
nmtst_assert_connection_verifies_without_normalization (connection);
|
||||
|
||||
_writer_new_connection (connection,
|
||||
|
|
@ -8538,6 +8544,8 @@ test_write_team_master (void)
|
|||
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
||||
NULL);
|
||||
|
||||
nm_connection_add_setting (connection, nm_setting_proxy_new ());
|
||||
|
||||
nmtst_assert_connection_verifies_without_normalization (connection);
|
||||
|
||||
_writer_new_connection (connection,
|
||||
|
|
|
|||
|
|
@ -2030,7 +2030,7 @@ write_proxy_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||
break;
|
||||
case NM_SETTING_PROXY_METHOD_NONE:
|
||||
svSetValue (ifcfg, "PROXY_METHOD", "none", FALSE);
|
||||
/* Write nothing more */
|
||||
break;
|
||||
}
|
||||
|
||||
browser_only = nm_setting_proxy_get_browser_only (s_proxy);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue