settings: make connections always have s_ip4 and s_ip6

Make sure that all connections returned from NMSettings or created via
AddAndActivateConnection have an NMSettingIP4Config and an
NMSettingIP6Config, with non-NULL methods, and get rid of
now-unnecessary checks for those.

Also move the slaves-can't-have-IP-config checks into the
platform-independent code as well. This also gets rid of spurious
"ignoring IP4/IP6 configuration" warnings in ifcfg-rh when reading a
slave ifcfg file.

Partly based on a patch from Pavel.

https://bugzilla.gnome.org/show_bug.cgi?id=708875
This commit is contained in:
Dan Winship
2013-09-26 17:34:23 -04:00
parent 5bcdfd3985
commit 68f12b4e9c
12 changed files with 299 additions and 186 deletions

View File

@@ -298,10 +298,10 @@ nm_utils_get_shared_wifi_permission (NMConnection *connection)
const char *method = NULL;
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
method = nm_setting_ip4_config_get_method (s_ip4);
g_assert (method);
if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0)
if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0)
return NULL; /* Not shared */
s_wifi = nm_connection_get_setting_wireless (connection);
@@ -576,6 +576,72 @@ get_new_connection_name (const GSList *existing,
return cname;
}
void
nm_utils_normalize_connection (NMConnection *connection,
gboolean default_enable_ipv6)
{
NMSettingConnection *s_con = nm_connection_get_setting_connection (connection);
const char *default_ip4_method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
const char *default_ip6_method =
default_enable_ipv6 ? NM_SETTING_IP6_CONFIG_METHOD_AUTO : NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
NMSetting *setting;
const char *method;
s_ip4 = nm_connection_get_setting_ip4_config (connection);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
/* Slave connections don't have IP configuration. */
if (nm_setting_connection_get_master (s_con)) {
default_ip4_method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
default_ip6_method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
if (s_ip4) {
method = nm_setting_ip4_config_get_method (s_ip4);
if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) != 0) {
nm_log_warn (LOGD_SETTINGS, "ignoring IP4 config on slave '%s'",
nm_connection_get_id (connection));
nm_connection_remove_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
s_ip4 = NULL;
}
}
if (s_ip6) {
method = nm_setting_ip6_config_get_method (s_ip6);
if (g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) != 0) {
nm_log_warn (LOGD_SETTINGS, "ignoring IP6 config on slave '%s'",
nm_connection_get_id (connection));
nm_connection_remove_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
s_ip6 = NULL;
}
}
}
/* Ensure all connections have IP4 and IP6 settings objects. If no
* IP6 setting was specified, then assume that means IP6 config is allowed
* to fail. But if no IP4 setting was specified, assume the caller was just
* being lazy.
*/
if (!s_ip4) {
setting = nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, setting);
g_object_set (setting,
NM_SETTING_IP4_CONFIG_METHOD, default_ip4_method,
NULL);
}
if (!s_ip6) {
setting = nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, setting);
g_object_set (setting,
NM_SETTING_IP6_CONFIG_METHOD, default_ip6_method,
NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
NULL);
}
}
void
nm_utils_complete_generic (NMConnection *connection,
const char *ctype,
@@ -585,9 +651,6 @@ nm_utils_complete_generic (NMConnection *connection,
gboolean default_enable_ipv6)
{
NMSettingConnection *s_con;
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
const char *method;
char *id, *uuid;
s_con = nm_connection_get_setting_connection (connection);
@@ -610,31 +673,8 @@ nm_utils_complete_generic (NMConnection *connection,
g_free (id);
}
/* Add an 'auto' IPv4 connection if present */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (!s_ip4) {
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
}
method = nm_setting_ip4_config_get_method (s_ip4);
if (!method) {
g_object_set (G_OBJECT (s_ip4),
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
}
/* Add an 'auto' IPv6 setting if allowed and not preset */
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (!s_ip6 && default_enable_ipv6) {
s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
}
if (s_ip6 && !nm_setting_ip6_config_get_method (s_ip6)) {
g_object_set (G_OBJECT (s_ip6),
NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
NULL);
}
/* Normalize */
nm_utils_normalize_connection (connection, default_enable_ipv6);
}
char *

View File

@@ -82,6 +82,9 @@ gboolean nm_utils_get_proc_sys_net_value_with_bounds (const char *path,
gint32 valid_min,
gint32 valid_max);
void nm_utils_normalize_connection (NMConnection *connection,
gboolean default_enable_ipv6);
void nm_utils_complete_generic (NMConnection *connection,
const char *ctype,
const GSList *existing,

View File

@@ -1316,11 +1316,9 @@ can_auto_connect (NMDevice *dev,
/* Use the connection if it's a shared connection */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4) {
method = nm_setting_ip4_config_get_method (s_ip4);
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
return TRUE;
}
for (ap_iter = priv->ap_list; ap_iter; ap_iter = g_slist_next (ap_iter)) {
NMAccessPoint *ap = NM_AP (ap_iter->data);
@@ -1500,10 +1498,8 @@ scanning_allowed (NMDeviceWifi *self)
/* Don't scan when a shared connection is active; it makes drivers mad */
connection = nm_act_request_get_connection (req);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
ip4_method = nm_setting_ip4_config_get_method (s_ip4);
if (s_ip4 && !strcmp (ip4_method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
if (!strcmp (ip4_method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
return FALSE;
/* Don't scan when the connection is locked to a specifc AP, since
@@ -3140,7 +3136,6 @@ act_stage4_ip4_config_timeout (NMDevice *dev, NMDeviceStateReason *reason)
g_assert (connection);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
may_fail = nm_setting_ip4_config_get_may_fail (s_ip4);
ret = handle_ip_config_timeout (NM_DEVICE_WIFI (dev), connection, may_fail, &chain_up, reason);
@@ -3162,7 +3157,6 @@ act_stage4_ip6_config_timeout (NMDevice *dev, NMDeviceStateReason *reason)
g_assert (connection);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (s_ip6)
may_fail = nm_setting_ip6_config_get_may_fail (s_ip6);
ret = handle_ip_config_timeout (NM_DEVICE_WIFI (dev), connection, may_fail, &chain_up, reason);

View File

@@ -1012,25 +1012,21 @@ nm_device_release_one_slave (NMDevice *dev, NMDevice *slave, gboolean failed)
static gboolean
connection_is_static (NMConnection *connection)
{
NMSettingIP4Config *ip4;
NMSettingIP6Config *ip6;
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
const char *method;
ip4 = nm_connection_get_setting_ip4_config (connection);
if (ip4) {
method = nm_setting_ip4_config_get_method (ip4);
if ( g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) != 0
&& g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) != 0)
s_ip4 = nm_connection_get_setting_ip4_config (connection);
method = nm_setting_ip4_config_get_method (s_ip4);
if ( strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) != 0
&& strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) != 0)
return FALSE;
}
ip6 = nm_connection_get_setting_ip6_config (connection);
if (ip6) {
method = nm_setting_ip6_config_get_method (ip6);
if ( g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) != 0
&& g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) != 0)
s_ip6 = nm_connection_get_setting_ip6_config (connection);
method = nm_setting_ip6_config_get_method (s_ip6);
if ( strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) != 0
&& strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) != 0)
return FALSE;
}
return TRUE;
}
@@ -1931,11 +1927,11 @@ nm_device_ip_config_should_fail (NMDevice *self, gboolean ip6)
/* Fail the connection if the failed IP method is required to complete */
if (ip6) {
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (s_ip6 && !nm_setting_ip6_config_get_may_fail (s_ip6))
if (!nm_setting_ip6_config_get_may_fail (s_ip6))
return TRUE;
} else {
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4 && !nm_setting_ip4_config_get_may_fail (s_ip4))
if (!nm_setting_ip4_config_get_may_fail (s_ip4))
return TRUE;
}
@@ -2188,10 +2184,8 @@ nm_device_handle_autoip4_event (NMDevice *self,
/* Ignore if the connection isn't an AutoIP connection */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
method = nm_setting_ip4_config_get_method (s_ip4);
if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) != 0)
if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) != 0)
return;
iface = nm_device_get_iface (self);
@@ -2705,10 +2699,8 @@ ip4_requires_slaves (NMConnection *connection)
const char *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
method = nm_setting_ip4_config_get_method (s_ip4);
return g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0;
return strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0;
}
static NMActStageReturn
@@ -2729,19 +2721,10 @@ act_stage3_ip4_config_start (NMDevice *self,
connection = nm_device_get_connection (self);
g_assert (connection);
/* If we did not receive IP4 configuration information, default to DHCP.
* Slaves, on the other hand, never have any IP configuration themselves,
* since the master handles all of that.
*/
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (priv->master) /* eg, device is a slave */
method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
else if (s_ip4)
method = nm_setting_ip4_config_get_method (s_ip4);
else
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
if ( g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) != 0
if ( strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) != 0
&& nm_device_is_master (self)
&& nm_device_is_unavailable_because_of_carrier (self)) {
nm_log_info (LOGD_IP4 | LOGD_DEVICE,
@@ -3249,16 +3232,15 @@ ip6_requires_slaves (NMConnection *connection)
const char *method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (s_ip6)
method = nm_setting_ip6_config_get_method (s_ip6);
/* SLAAC, DHCP, and Link-Local depend on connectivity (and thus slaves)
* to complete addressing. SLAAC and DHCP obviously need a peer to
* provide a prefix, while Link-Local must perform DAD on the local link.
*/
return g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0
|| g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0
|| g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0;
return strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0
|| strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0
|| strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0;
}
static NMActStageReturn
@@ -3285,19 +3267,10 @@ act_stage3_ip6_config_start (NMDevice *self,
connection = nm_device_get_connection (self);
g_assert (connection);
/* If we did not receive IP6 configuration information, default to AUTO.
* Slaves, on the other hand, never have any IP configuration themselves,
* since the master handles all of that.
*/
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (priv->master) /* eg, device is a slave */
method = NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
else if (s_ip6)
method = nm_setting_ip6_config_get_method (s_ip6);
else
method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
if ( g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) != 0
if ( strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) != 0
&& nm_device_is_master (self)
&& nm_device_is_unavailable_because_of_carrier (self)) {
nm_log_info (LOGD_IP6 | LOGD_DEVICE,
@@ -3370,7 +3343,7 @@ act_stage3_ip6_config_start (NMDevice *self,
conf_use_tempaddr = ip6_use_tempaddr ();
if (conf_use_tempaddr >= 0)
ip6_privacy = conf_use_tempaddr;
else if (s_ip6)
else
ip6_privacy = nm_setting_ip6_config_get_ip6_privacy (s_ip6);
ip6_privacy = CLAMP (ip6_privacy, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR);
@@ -3917,10 +3890,9 @@ nm_device_activate_ip4_config_commit (gpointer user_data)
/* Start IPv4 sharing if we need it */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
method = nm_setting_ip4_config_get_method (s_ip4);
if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) {
if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) {
if (!start_sharing (self, priv->ip4_config)) {
nm_log_warn (LOGD_SHARING, "Activation (%s) Stage 5 of 5 (IPv4 Commit) start sharing failed.", iface);
nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SHARED_START_FAILED);
@@ -5041,10 +5013,8 @@ dispose (GObject *object)
* to check that.
*/
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
method = nm_setting_ip4_config_get_method (s_ip4);
if ( !method
|| !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)
if ( !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)
|| !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)
|| !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED))
deconfigure = FALSE;
@@ -6444,7 +6414,7 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
FALSE);
g_object_unref (dhcp_mgr);
method = s_ip4 ? nm_setting_ip4_config_get_method (s_ip4) : NM_SETTING_IP4_CONFIG_METHOD_AUTO;
method = nm_setting_ip4_config_get_method (s_ip4);
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
gboolean found = FALSE;
@@ -6485,7 +6455,6 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
/* Everything below for static addressing */
/* Find all IP4 addresses of this connection on the device */
if (s_ip4) {
num = nm_setting_ip4_config_get_num_addresses (s_ip4);
for (i = 0; i < num; i++) {
NMIP4Address *addr = nm_setting_ip4_config_get_address (s_ip4, i);
@@ -6495,7 +6464,6 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
nm_ip4_address_get_prefix (addr)))
return FALSE;
}
}
/* Success; all the connection's static IP addresses are assigned to the device */
return TRUE;

View File

@@ -70,7 +70,6 @@ add_hostname (GString *str, const char *format, const char *hostname)
static void
add_ip4_config (GString *str, NMSettingIP4Config *s_ip4, const char *hostname)
{
if (s_ip4) {
const char *tmp;
tmp = nm_setting_ip4_config_get_dhcp_client_id (s_ip4);
@@ -99,7 +98,6 @@ add_ip4_config (GString *str, NMSettingIP4Config *s_ip4, const char *hostname)
else
g_string_append_printf (str, CLIENTID_FORMAT "\n", tmp);
}
}
add_hostname (str, HOSTNAME4_FORMAT "\n", hostname);
@@ -159,8 +157,7 @@ nm_dhcp_dhclient_create_config (const char *interface,
/* Override config file "dhcp-client-id" and use one from the
* connection.
*/
if ( s_ip4
&& nm_setting_ip4_config_get_dhcp_client_id (s_ip4)
if ( nm_setting_ip4_config_get_dhcp_client_id (s_ip4)
&& !strncmp (p, CLIENTID_TAG, strlen (CLIENTID_TAG)))
continue;

View File

@@ -519,28 +519,21 @@ nm_dhcp_manager_start_ip4 (NMDHCPManager *self,
guint8 *dhcp_anycast_addr)
{
NMDHCPManagerPrivate *priv;
const char *hostname = NULL;
gboolean send_hostname = TRUE;
const char *hostname, *method;
gboolean send_hostname;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
if (s_ip4) {
const char *method = nm_setting_ip4_config_get_method (s_ip4);
if (method) {
/* Method must be 'auto' */
method = nm_setting_ip4_config_get_method (s_ip4);
g_return_val_if_fail (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, NULL);
}
send_hostname = nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4);
if (send_hostname)
hostname = nm_setting_ip4_config_get_dhcp_hostname (s_ip4);
}
if (send_hostname) {
hostname = nm_setting_ip4_config_get_dhcp_hostname (s_ip4);
/* If we're supposed to send the hostname to the DHCP server but
* the user didn't specify one, then use the hostname from the
* hostname provider if there is one, otherwise use the persistent
@@ -553,7 +546,8 @@ nm_dhcp_manager_start_ip4 (NMDHCPManager *self,
!strcmp (hostname, "localhost6.localdomain6")))
hostname = NULL;
}
}
} else
hostname = NULL;
return client_start (self, iface, hwaddr, uuid, FALSE, s_ip4, NULL, timeout, dhcp_anycast_addr, hostname, FALSE);
}
@@ -570,14 +564,13 @@ nm_dhcp_manager_start_ip6 (NMDHCPManager *self,
gboolean info_only)
{
NMDHCPManagerPrivate *priv;
const char *hostname = NULL;
const char *hostname;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
if (s_ip6)
hostname = nm_setting_ip6_config_get_dhcp_hostname (s_ip6);
if (!hostname && priv->hostname_provider) {
hostname = nm_hostname_provider_get_hostname (priv->hostname_provider);

View File

@@ -144,7 +144,7 @@ get_best_ip4_device (NMManager *manager, gboolean fully_activated)
g_assert (connection);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4) {
/* Never set the default route through an IPv4LL-addressed device */
method = nm_setting_ip4_config_get_method (s_ip4);
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
@@ -153,7 +153,6 @@ get_best_ip4_device (NMManager *manager, gboolean fully_activated)
/* 'never-default' devices can't ever be the default */
if (nm_setting_ip4_config_get_never_default (s_ip4))
continue;
}
prio = nm_device_get_priority (dev);
if (prio > 0 && prio < best_prio) {
@@ -223,14 +222,13 @@ get_best_ip6_device (NMManager *manager, gboolean fully_activated)
g_assert (connection);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (s_ip6) {
method = nm_setting_ip6_config_get_method (s_ip6);
if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL))
continue;
if (nm_setting_ip6_config_get_never_default (s_ip6))
continue;
}
prio = nm_device_get_priority (dev);
if (prio > 0 && prio < best_prio) {
@@ -575,7 +573,7 @@ get_best_ip4_config (NMPolicy *policy,
/* Check the user's preference from the NMConnection */
s_ip4 = nm_connection_get_setting_ip4_config (tmp);
if (s_ip4 && nm_setting_ip4_config_get_never_default (s_ip4))
if (nm_setting_ip4_config_get_never_default (s_ip4))
continue;
}
@@ -753,7 +751,7 @@ get_best_ip6_config (NMPolicy *policy,
/* Check the user's preference from the NMConnection */
s_ip6 = nm_connection_get_setting_ip6_config (tmp);
if (s_ip6 && nm_setting_ip6_config_get_never_default (s_ip6))
if (nm_setting_ip6_config_get_never_default (s_ip6))
continue;
}

View File

@@ -68,6 +68,7 @@
#include "nm-settings-utils.h"
#include "nm-connection-provider.h"
#include "nm-config.h"
#include "NetworkManagerUtils.h"
/* LINKER CRACKROCK */
#define EXPORT(sym) void * __export_##sym = &sym;
@@ -800,6 +801,8 @@ claim_connection (NMSettings *self,
return;
}
nm_utils_normalize_connection (NM_CONNECTION (connection), TRUE);
if (!nm_connection_verify (NM_CONNECTION (connection), &error)) {
nm_log_warn (LOGD_SETTINGS, "plugin provided invalid connection: '%s' / '%s' invalid: %d",
g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)),

View File

@@ -25,6 +25,8 @@ libifcfg_rh_io_la_SOURCES = \
utils.h
AM_CPPFLAGS = \
-I$(top_srcdir)/src/ \
-I$(top_srcdir)/src/platform \
-I$(top_srcdir)/src/wifi \
-I$(top_srcdir)/src/settings \
-I$(top_srcdir)/src/posix-signals \

View File

@@ -52,6 +52,7 @@
#include "wifi-utils.h"
#include "nm-posix-signals.h"
#include "NetworkManagerUtils.h"
#include "common.h"
#include "shvar.h"
@@ -4646,10 +4647,6 @@ connection_from_file (const char *filename,
g_object_unref (connection);
connection = NULL;
goto done;
} else if (utils_ignore_ip_config (connection)) {
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: ignoring IP6 configuration");
g_object_unref (s_ip6);
s_ip6 = NULL;
} else {
const char *method;
@@ -4664,11 +4661,7 @@ connection_from_file (const char *filename,
g_object_unref (connection);
connection = NULL;
goto done;
} else if (s_ip4 && utils_ignore_ip_config (connection)) {
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: ignoring IP4 configuration");
g_object_unref (s_ip4);
s_ip4 = NULL;
} else if (s_ip4)
} else
nm_connection_add_setting (connection, s_ip4);
/* There is only one DOMAIN variable and it is read and put to IPv4 config
@@ -4703,6 +4696,8 @@ connection_from_file (const char *filename,
}
g_free (bootproto);
nm_utils_normalize_connection (connection, TRUE);
if (!nm_connection_verify (connection, error)) {
g_object_unref (connection);
connection = NULL;

View File

@@ -13,6 +13,8 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/libnm-util \
-I$(top_builddir)/libnm-util \
-I$(top_srcdir)/libnm-glib \
-I$(top_srcdir)/src/ \
-I$(top_srcdir)/src/platform \
-I$(top_srcdir)/src/settings \
-I$(top_srcdir)/src/wifi \
-I$(top_srcdir)/src/posix-signals \

View File

@@ -47,6 +47,7 @@
#include <nm-setting-vlan.h>
#include "nm-test-helpers.h"
#include "NetworkManagerUtils.h"
#include "common.h"
#include "reader.h"
@@ -6222,6 +6223,9 @@ test_write_wired_static (void)
ASSERT (testfile != NULL,
"wired-static-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -6342,6 +6346,9 @@ test_write_wired_dhcp (void)
ASSERT (testfile != NULL,
"wired-dhcp-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -6466,6 +6473,9 @@ test_write_wired_static_ip6_only (void)
ASSERT (testfile != NULL,
"wired-static-ip6-only-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -6610,6 +6620,9 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
g_assert (success);
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -6765,6 +6778,9 @@ test_read_write_static_routes_legacy (void)
ASSERT (testfile != NULL,
"read-write-static-routes-legacy-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -6937,6 +6953,9 @@ test_write_wired_static_routes (void)
ASSERT (testfile != NULL,
"wired-static-routes-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -7066,6 +7085,9 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void)
ASSERT (testfile != NULL,
"wired-dhcp-8021x-peap-mschapv2write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -7248,6 +7270,9 @@ test_write_wired_8021x_tls (NMSetting8021xCKScheme scheme,
g_assert (success);
g_assert (testfile != NULL);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -7433,6 +7458,9 @@ test_write_wifi_open (void)
ASSERT (testfile != NULL,
"wifi-open-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -7561,6 +7589,9 @@ test_write_wifi_open_hex_ssid (void)
ASSERT (testfile != NULL,
"wifi-open-hex-ssid-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -7689,6 +7720,9 @@ test_write_wifi_wep (void)
ASSERT (testfile != NULL,
"wifi-wep-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -7837,6 +7871,9 @@ test_write_wifi_wep_adhoc (void)
ASSERT (testfile != NULL,
"wifi-wep-adhoc-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -7975,6 +8012,9 @@ test_write_wifi_wep_passphrase (void)
ASSERT (testfile != NULL,
"wifi-wep-passphrase-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -8115,6 +8155,9 @@ test_write_wifi_wep_40_ascii (void)
ASSERT (testfile != NULL,
"wifi-wep-40-ascii-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -8255,6 +8298,9 @@ test_write_wifi_wep_104_ascii (void)
ASSERT (testfile != NULL,
"wifi-wep-104-ascii-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -8392,6 +8438,9 @@ test_write_wifi_leap (void)
ASSERT (testfile != NULL,
"wifi-leap-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -8528,6 +8577,9 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags)
g_assert (success);
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -8681,6 +8733,9 @@ test_write_wifi_wpa_psk (const char *name,
ASSERT (testfile != NULL,
test_name, "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -8829,6 +8884,9 @@ test_write_wifi_wpa_psk_adhoc (void)
ASSERT (testfile != NULL,
"wifi-wpa-psk-adhoc-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -8992,6 +9050,9 @@ test_write_wifi_wpa_eap_tls (void)
ASSERT (testfile != NULL,
"wifi-wpa-eap-tls-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -9173,6 +9234,9 @@ test_write_wifi_wpa_eap_ttls_tls (void)
ASSERT (testfile != NULL,
"wifi-wpa-eap-ttls-tls-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -9326,6 +9390,9 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void)
ASSERT (testfile != NULL,
"wifi-wpa-eap-ttls-mschapv2-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -9467,6 +9534,9 @@ test_write_wifi_wpa_then_open (void)
g_assert (success);
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -9511,6 +9581,9 @@ test_write_wifi_wpa_then_open (void)
g_free (keyfile);
keyfile = NULL;
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read it for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -9660,6 +9733,9 @@ test_write_wifi_wpa_then_wep_with_perms (void)
g_assert (success);
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -9710,6 +9786,9 @@ test_write_wifi_wpa_then_wep_with_perms (void)
g_free (keyfile);
keyfile = NULL;
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read it for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -9852,6 +9931,9 @@ test_write_wifi_dynamic_wep_leap (void)
g_assert (success);
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -10376,6 +10458,9 @@ test_write_wired_qeth_dhcp (void)
ASSERT (testfile != NULL,
"wired-qeth-dhcp-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -10509,6 +10594,9 @@ test_write_wired_ctc_dhcp (void)
svCloseFile (ifcfg);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -10618,6 +10706,9 @@ test_write_permissions (void)
ASSERT (testfile != NULL,
"permissions-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -10745,6 +10836,9 @@ test_write_wifi_wep_agent_keys (void)
g_assert (success);
g_assert (testfile != NULL);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -11138,6 +11232,9 @@ test_write_bridge_main (void)
g_assert (success);
g_assert_cmpstr (testfile, !=, NULL);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -11290,6 +11387,9 @@ test_write_bridge_component (void)
g_assert (success);
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -11622,6 +11722,9 @@ test_write_vlan_only_vlanid (void)
&error);
g_assert (success);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (written,
NULL,
@@ -11728,6 +11831,9 @@ test_write_ethernet_missing_ipv6 (void)
ASSERT (testfile != NULL,
"ethernet-missing-ipv6", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -11916,6 +12022,9 @@ test_write_bond_main (void)
ASSERT (testfile != NULL,
"bond-main-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -12063,6 +12172,9 @@ test_write_bond_slave (void)
ASSERT (testfile != NULL,
"bond-slave-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -12274,6 +12386,9 @@ test_write_infiniband (void)
ASSERT (testfile != NULL,
"infiniband-write", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
@@ -12424,6 +12539,9 @@ test_write_bond_slave_ib (void)
ASSERT (testfile != NULL,
"bond-slave-write-ib", "didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,