merge branch 'th/rh979425_set_virtual_iface_name'

https://bugzilla.redhat.com/show_bug.cgi?id=979425
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2014-06-30 18:43:37 +02:00
commit 392d4e4831
20 changed files with 769 additions and 273 deletions

View file

@ -13,6 +13,7 @@ global:
nm_connection_for_each_setting_value;
nm_connection_get_connection_type;
nm_connection_get_id;
nm_connection_get_interface_name;
nm_connection_get_path;
nm_connection_get_setting;
nm_connection_get_setting_802_1x;
@ -52,6 +53,7 @@ global:
nm_connection_need_secrets;
nm_connection_new;
nm_connection_new_from_hash;
nm_connection_normalize;
nm_connection_remove_setting;
nm_connection_replace_settings;
nm_connection_replace_settings_from_connection;

View file

@ -122,6 +122,10 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
static NMSettingVerifyResult _nm_connection_verify (NMConnection *connection, GError **error);
/*************************************************************/
/**
@ -575,6 +579,113 @@ nm_connection_diff (NMConnection *a,
return *out_settings ? FALSE : TRUE;
}
static gboolean
_normalize_virtual_iface_name (NMConnection *self)
{
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (self);
GHashTableIter h_iter;
NMSetting *setting;
NMSettingConnection *s_con;
const char *interface_name;
char *virtual_iface_name = NULL;
gboolean was_modified = FALSE;
const char *prop_name = NULL;
/* search for settings that might need normalization of the interface name. */
g_hash_table_iter_init (&h_iter, priv->settings);
while ( !prop_name
&& g_hash_table_iter_next (&h_iter, NULL, (void **) &setting)) {
if (NM_IS_SETTING_BOND (setting))
prop_name = NM_SETTING_BOND_INTERFACE_NAME;
else if (NM_IS_SETTING_BRIDGE (setting))
prop_name = NM_SETTING_BRIDGE_INTERFACE_NAME;
else if (NM_IS_SETTING_TEAM (setting))
prop_name = NM_SETTING_TEAM_INTERFACE_NAME;
else if (NM_IS_SETTING_VLAN (setting))
prop_name = NM_SETTING_VLAN_INTERFACE_NAME;
}
if (!prop_name)
return FALSE;
s_con = nm_connection_get_setting_connection (self);
g_return_val_if_fail (s_con, FALSE);
interface_name = nm_setting_connection_get_interface_name (s_con);
/* read the potential virtual_iface_name from the setting. */
g_object_get (setting, prop_name, &virtual_iface_name, NULL);
if (g_strcmp0 (interface_name, virtual_iface_name) != 0) {
if (interface_name) {
/* interface_name is set and overwrites the virtual_iface_name. */
g_object_set (setting, prop_name, interface_name, NULL);
} else {
/* interface in NMSettingConnection must be set. */
g_object_set (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, virtual_iface_name, NULL);
}
was_modified = TRUE;
}
g_free (virtual_iface_name);
return was_modified;
}
static gboolean
_normalize_ip_config (NMConnection *self, GHashTable *parameters)
{
NMSettingConnection *s_con = nm_connection_get_setting_connection (self);
const char *default_ip4_method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
const char *default_ip6_method = NULL;
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
NMSetting *setting;
if (parameters)
default_ip6_method = g_hash_table_lookup (parameters, NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD);
if (!default_ip6_method)
default_ip6_method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
s_ip4 = nm_connection_get_setting_ip4_config (self);
s_ip6 = nm_connection_get_setting_ip6_config (self);
if (nm_setting_connection_get_master (s_con)) {
/* Slave connections don't have IP configuration. */
if (s_ip4)
nm_connection_remove_setting (self, NM_TYPE_SETTING_IP4_CONFIG);
if (s_ip6)
nm_connection_remove_setting (self, NM_TYPE_SETTING_IP6_CONFIG);
return s_ip4 || s_ip6;
} 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
* 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 ();
g_object_set (setting,
NM_SETTING_IP4_CONFIG_METHOD, default_ip4_method,
NULL);
nm_connection_add_setting (self, setting);
}
if (!s_ip6) {
setting = nm_setting_ip6_config_new ();
g_object_set (setting,
NM_SETTING_IP6_CONFIG_METHOD, default_ip6_method,
NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
NULL);
nm_connection_add_setting (self, setting);
}
return !s_ip4 || !s_ip6;
}
}
/**
* nm_connection_verify:
* @connection: the #NMConnection to verify
@ -584,7 +695,7 @@ nm_connection_diff (NMConnection *a,
* have allowed values, and some values are dependent on other values. For
* example, if a Wi-Fi connection is security enabled, the #NMSettingWireless
* setting object's 'security' property must contain the setting name of the
* #NMSettingWirelessSecurity object, which must also be present in the
* #NMSettingWirelessSecurity object, which must also be present in the
* connection for the connection to be valid. As another example, the
* #NMSettingWired object's 'mac-address' property must be a validly formatted
* MAC address. The returned #GError contains information about which
@ -594,25 +705,43 @@ nm_connection_diff (NMConnection *a,
**/
gboolean
nm_connection_verify (NMConnection *connection, GError **error)
{
NMSettingVerifyResult result;
result = _nm_connection_verify (connection, error);
/* we treat normalizable connections as valid. */
if (result == NM_SETTING_VERIFY_NORMALIZABLE)
g_clear_error (error);
return result == NM_SETTING_VERIFY_SUCCESS || result == NM_SETTING_VERIFY_NORMALIZABLE;
}
static NMSettingVerifyResult
_nm_connection_verify (NMConnection *connection, GError **error)
{
NMConnectionPrivate *priv;
NMSettingConnection *s_con;
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
GHashTableIter iter;
gpointer value;
GSList *all_settings = NULL;
gboolean success = TRUE;
GSList *all_settings = NULL, *setting_i;
NMSettingVerifyResult success = NM_SETTING_VERIFY_ERROR;
NMSetting *base;
const char *ctype;
GError *normalizable_error = NULL;
NMSettingVerifyResult normalizable_error_type = NM_SETTING_VERIFY_SUCCESS;
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
g_return_val_if_fail (*error == NULL, NM_SETTING_VERIFY_ERROR);
if (!NM_IS_CONNECTION (connection)) {
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_UNKNOWN,
"invalid connection; failed verification");
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NM_SETTING_VERIFY_ERROR);
}
priv = NM_CONNECTION_GET_PRIVATE (connection);
@ -624,22 +753,61 @@ nm_connection_verify (NMConnection *connection, GError **error)
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND,
"connection setting not found");
return FALSE;
goto EXIT;
}
/* Build up the list of settings */
g_hash_table_iter_init (&iter, priv->settings);
while (g_hash_table_iter_next (&iter, NULL, &value))
all_settings = g_slist_append (all_settings, value);
while (g_hash_table_iter_next (&iter, NULL, &value)) {
/* Order NMSettingConnection so that it will be verified first.
* The reason is, that NMSettingConnection:verify() modifies the connection
* by setting NMSettingConnection:interface_name. So we want to call that
* verify() first, because the order can affect the outcome.
* Another reason is, that errors in this setting might be more fundamental
* and should be checked and reported with higher priority.
* Another reason is, that some settings look especially at the
* NMSettingConnection, so they find it first in the all_settings list. */
if (value == s_con)
all_settings = g_slist_append (all_settings, value);
else
all_settings = g_slist_prepend (all_settings, value);
}
all_settings = g_slist_reverse (all_settings);
/* Now, run the verify function of each setting */
g_hash_table_iter_init (&iter, priv->settings);
while (g_hash_table_iter_next (&iter, NULL, &value) && success)
success = nm_setting_verify (NM_SETTING (value), all_settings, error);
g_slist_free (all_settings);
for (setting_i = all_settings; setting_i; setting_i = setting_i->next) {
GError *verify_error = NULL;
NMSettingVerifyResult verify_result;
if (success == FALSE)
return FALSE;
/* verify all settings. We stop if we find the first non-normalizable
* @NM_SETTING_VERIFY_ERROR. If we find normalizable errors we continue
* but remember the error to return it to the user.
* @NM_SETTING_VERIFY_NORMALIZABLE_ERROR has a higher priority then
* @NM_SETTING_VERIFY_NORMALIZABLE, so, if we encounter such an error type,
* we remember it instead (to return it as output).
**/
verify_result = _nm_setting_verify (NM_SETTING (setting_i->data), all_settings, &verify_error);
if (verify_result == NM_SETTING_VERIFY_NORMALIZABLE ||
verify_result == NM_SETTING_VERIFY_NORMALIZABLE_ERROR) {
if ( verify_result == NM_SETTING_VERIFY_NORMALIZABLE_ERROR
&& normalizable_error_type == NM_SETTING_VERIFY_NORMALIZABLE) {
/* NORMALIZABLE_ERROR has higher priority. */
g_clear_error (&normalizable_error);
}
if (!normalizable_error) {
g_propagate_error (&normalizable_error, verify_error);
verify_error = NULL;
normalizable_error_type = verify_result;
}
} 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_clear_error (&verify_error);
}
g_slist_free (all_settings);
/* Now make sure the given 'type' setting can actually be the base setting
* of the connection. Can't have type=ppp for example.
@ -650,7 +818,7 @@ nm_connection_verify (NMConnection *connection, GError **error)
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID,
"connection type missing");
return FALSE;
goto EXIT;
}
base = nm_connection_get_setting_by_name (connection, ctype);
@ -659,7 +827,7 @@ nm_connection_verify (NMConnection *connection, GError **error)
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID,
"base setting GType not found");
return FALSE;
goto EXIT;
}
if (!_nm_setting_is_base_type (base)) {
@ -668,10 +836,116 @@ nm_connection_verify (NMConnection *connection, GError **error)
NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID,
"connection type '%s' is not a base type",
ctype);
return FALSE;
goto EXIT;
}
return TRUE;
s_ip4 = nm_connection_get_setting_ip4_config (connection);
s_ip6 = nm_connection_get_setting_ip6_config (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)) {
g_clear_error (&normalizable_error);
g_set_error (&normalizable_error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_SETTING,
"slave connection cannot have an IP%c setting",
s_ip4 ? '4' : '6');
/* 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)) {
g_set_error (&normalizable_error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_SETTING_NOT_FOUND,
"connection needs an IP%c setting",
!s_ip4 ? '4' : '6');
/* having a master without IP config was not a verify() error, accept
* it for backward compatibility. */
normalizable_error_type = NM_SETTING_VERIFY_NORMALIZABLE;
}
}
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;
EXIT:
g_clear_error (&normalizable_error);
return success;
}
/**
* nm_connection_normalize:
* @connection: the #NMConnection to normalize
* @parameters: (allow-none) (element-type utf8 gpointer): a #GHashTable with
* normalization parameters to allow customization of the normalization by providing
* specific arguments. Unknown arguments will be ignored and the default will be
* used. The keys must be strings, hashed by g_str_hash() and g_str_equal() functions.
* The values are opaque and depend on the parameter name.
* @modified: (out) (allow-none): outputs whether any settings were modified.
* @error: location to store error, or %NULL. Contains the reason,
* why the connection is invalid, if the function returns an error.
*
* Does some basic normalization and fixup of well known inconsistencies
* and deprecated fields. If the connection was modified in any way,
* the output parameter @modified is set %TRUE.
*
* Finally the connection will be verified and %TRUE returns if the connection
* is valid. As this function only performs some specific normalization steps
* it cannot repair all connections. If the connection has errors that
* cannot be normalized, the connection will not be modified.
*
* Returns: %TRUE if the connection is valid, %FALSE if it is not
*
* Since: 1.0
**/
gboolean
nm_connection_normalize (NMConnection *connection,
GHashTable *parameters,
gboolean *modified,
GError **error)
{
NMSettingVerifyResult success;
gboolean was_modified = FALSE;
GError *normalizable_error = NULL;
success = _nm_connection_verify (connection, &normalizable_error);
if (success == NM_SETTING_VERIFY_ERROR ||
success == NM_SETTING_VERIFY_SUCCESS) {
if (normalizable_error)
g_propagate_error (error, normalizable_error);
goto EXIT;
}
g_assert (success == NM_SETTING_VERIFY_NORMALIZABLE || success == NM_SETTING_VERIFY_NORMALIZABLE_ERROR);
g_clear_error (&normalizable_error);
/* Try to perform all kind of normalizations on the settings to fix it.
* We only do this, after verifying that the connection contains no un-normalizable
* errors, because in that case we rather fail without touching the settings. */
was_modified |= _normalize_virtual_iface_name (connection);
was_modified |= _normalize_ip_config (connection, parameters);
/* Verify anew. */
success = _nm_connection_verify (connection, error);
/* we would expect, that after normalization, the connection can be verified. */
g_return_val_if_fail (success == NM_SETTING_VERIFY_SUCCESS, success);
/* we would expect, that the connection was modified during normalization. */
g_return_val_if_fail (was_modified, success);
EXIT:
if (modified)
*modified = was_modified;
return success == NM_SETTING_VERIFY_SUCCESS;
}
/**
@ -1105,6 +1379,33 @@ nm_connection_get_path (NMConnection *connection)
return NM_CONNECTION_GET_PRIVATE (connection)->path;
}
/**
* nm_connection_get_interface_name:
* @connection: The #NMConnection
*
* Returns the interface name as stored in NMSettingConnection:interface_name.
* If the connection contains no NMSettingConnection, it will return %NULL.
*
* For hardware devices and software devices created outside of NetworkManager,
* this name is used to match the device. for software devices created by
* NetworkManager, this is the name of the created interface.
*
* Returns: Name of the kernel interface or %NULL
*
* Since: 1.0
*/
const char *
nm_connection_get_interface_name (NMConnection *connection)
{
NMSettingConnection *s_con;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
s_con = nm_connection_get_setting_connection (connection);
return s_con ? nm_setting_connection_get_interface_name (s_con) : NULL;
}
/**
* nm_connection_get_virtual_iface_name:
* @connection: The #NMConnection

View file

@ -86,6 +86,8 @@ G_BEGIN_DECLS
* #NMSettingWireless.
* @NM_CONNECTION_ERROR_SETTING_NOT_FOUND: the #NMConnection object
* did not contain the specified #NMSetting object
*@NM_CONNECTION_ERROR_INVALID_SETTING: the #NMConnection object contains
* a conflicting setting object
*
* Describes errors that may result from operations involving a #NMConnection.
*
@ -95,9 +97,17 @@ typedef enum
NM_CONNECTION_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND, /*< nick=ConnectionSettingNotFound >*/
NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID, /*< nick=ConnectionTypeInvalid >*/
NM_CONNECTION_ERROR_SETTING_NOT_FOUND /*< nick=SettingNotFound >*/
NM_CONNECTION_ERROR_SETTING_NOT_FOUND, /*< nick=SettingNotFound >*/
NM_CONNECTION_ERROR_INVALID_SETTING, /*< nick=InvalidSetting >*/
} NMConnectionError;
/*
* NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD: overwrite the ip6 method
* when normalizing ip6 configuration. If omited, this defaults to
* @NM_SETTING_IP6_CONFIG_METHOD_AUTO.
*/
#define NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD "ip6-config-method"
#define NM_CONNECTION_ERROR nm_connection_error_quark ()
GQuark nm_connection_error_quark (void);
@ -159,6 +169,11 @@ gboolean nm_connection_diff (NMConnection *a,
GHashTable **out_settings);
gboolean nm_connection_verify (NMConnection *connection, GError **error);
NM_AVAILABLE_IN_1_0
gboolean nm_connection_normalize (NMConnection *connection,
GHashTable *parameters,
gboolean *modified,
GError **error);
const char * nm_connection_need_secrets (NMConnection *connection,
GPtrArray **hints);
@ -181,6 +196,9 @@ const char * nm_connection_get_path (NMConnection *connection);
const char * nm_connection_get_virtual_iface_name (NMConnection *connection);
NM_AVAILABLE_IN_1_0
const char * nm_connection_get_interface_name (NMConnection *connection);
gboolean nm_connection_is_type (NMConnection *connection, const char *type);
void nm_connection_for_each_setting_value (NMConnection *connection,

View file

@ -491,24 +491,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
const char *arp_ip_target = NULL;
const char *primary;
if (!priv->interface_name || !strlen(priv->interface_name)) {
g_set_error_literal (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_INTERFACE_NAME);
return FALSE;
}
if (!nm_utils_iface_valid_name (priv->interface_name)) {
g_set_error_literal (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_INTERFACE_NAME);
return FALSE;
}
g_hash_table_iter_init (&iter, priv->options);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
if (!value[0] || !nm_setting_bond_validate_option (key, value)) {
@ -688,7 +670,13 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
}
return TRUE;
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, FALSE,
NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_INTERFACE_NAME,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
all_settings, error);
}
static const char *

View file

@ -280,25 +280,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
if (!priv->interface_name || !strlen(priv->interface_name)) {
g_set_error_literal (error,
NM_SETTING_BRIDGE_ERROR,
NM_SETTING_BRIDGE_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_BRIDGE_SETTING_NAME, NM_SETTING_BRIDGE_INTERFACE_NAME);
return FALSE;
}
if (!nm_utils_iface_valid_name (priv->interface_name)) {
g_set_error (error,
NM_SETTING_BRIDGE_ERROR,
NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid interface name"),
priv->interface_name);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BRIDGE_SETTING_NAME, NM_SETTING_BRIDGE_INTERFACE_NAME);
return FALSE;
}
if (priv->mac_address && priv->mac_address->len != ETH_ALEN) {
g_set_error_literal (error,
NM_SETTING_BRIDGE_ERROR,
@ -336,7 +317,13 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
error))
return FALSE;
return TRUE;
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, FALSE,
NM_SETTING_BRIDGE_SETTING_NAME, NM_SETTING_BRIDGE_INTERFACE_NAME,
NM_SETTING_BRIDGE_ERROR,
NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY,
NM_SETTING_BRIDGE_ERROR_MISSING_PROPERTY,
all_settings, error);
}
static const char *

View file

@ -796,29 +796,35 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
/* If the connection has a virtual interface name, it must match
* the connection setting's interface name.
/* FIXME: previously, verify() set the NMSettingConnection:interface_name property,
* thus modifying the setting. verify() should not do this, but keep this not to change
* behaviour.
*/
for (iter = all_settings; iter; iter = iter->next) {
const char *virtual_iface;
if (!priv->interface_name) {
for (iter = all_settings; iter; iter = iter->next) {
NMSetting *s_current = iter->data;
char *virtual_iface_name = NULL;
virtual_iface = nm_setting_get_virtual_iface_name (iter->data);
if (virtual_iface) {
if (priv->interface_name) {
if (strcmp (priv->interface_name, virtual_iface) != 0) {
g_set_error (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
_("'%s' doesn't match the virtual interface name '%s'"),
priv->interface_name, virtual_iface);
g_prefix_error (error, "%s.%s: ",
NM_SETTING_CONNECTION_SETTING_NAME,
NM_SETTING_CONNECTION_INTERFACE_NAME);
return FALSE;
if (NM_IS_SETTING_BOND (s_current))
g_object_get (s_current, NM_SETTING_BOND_INTERFACE_NAME, &virtual_iface_name, NULL);
else if (NM_IS_SETTING_BRIDGE (s_current))
g_object_get (s_current, NM_SETTING_BRIDGE_INTERFACE_NAME, &virtual_iface_name, NULL);
else if (NM_IS_SETTING_TEAM (s_current))
g_object_get (s_current, NM_SETTING_TEAM_INTERFACE_NAME, &virtual_iface_name, NULL);
else if (NM_IS_SETTING_VLAN (s_current))
g_object_get (s_current, NM_SETTING_VLAN_INTERFACE_NAME, &virtual_iface_name, NULL);
/* For NMSettingInfiniband, virtual_iface_name has no backing field.
* No need to set the (unset) interface_name to the default value.
**/
if (virtual_iface_name) {
if (nm_utils_iface_valid_name (virtual_iface_name)) {
/* found a new interface name. */
priv->interface_name = virtual_iface_name;
break;
}
} else
priv->interface_name = g_strdup (virtual_iface);
break;
g_free (virtual_iface_name);
}
}
}
@ -861,39 +867,37 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
is_slave = ( !g_strcmp0 (priv->slave_type, NM_SETTING_BOND_SETTING_NAME)
|| !g_strcmp0 (priv->slave_type, NM_SETTING_BRIDGE_SETTING_NAME)
|| !g_strcmp0 (priv->slave_type, NM_SETTING_TEAM_SETTING_NAME));
is_slave = ( priv->slave_type
&& ( !strcmp (priv->slave_type, NM_SETTING_BOND_SETTING_NAME)
|| !strcmp (priv->slave_type, NM_SETTING_BRIDGE_SETTING_NAME)
|| !strcmp (priv->slave_type, NM_SETTING_TEAM_SETTING_NAME)));
if (priv->slave_type && !is_slave) {
g_set_error (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
_("Unknown slave type '%s'"), priv->slave_type);
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_SLAVE_TYPE);
return NM_SETTING_VERIFY_ERROR;
}
/* Bond/bridge/team slaves are not allowed to have any IP configuration. */
if (is_slave) {
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_find_in_list (all_settings, NM_SETTING_IP4_CONFIG_SETTING_NAME));
if (s_ip4) {
if (strcmp (nm_setting_ip4_config_get_method (s_ip4),
NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_IP_CONFIG_NOT_ALLOWED,
_("IPv4 configuration is not allowed for slave"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_SLAVE_TYPE);
return FALSE;
}
if (!priv->master) {
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
_("Slave connections need a valid '" NM_SETTING_CONNECTION_MASTER "' property"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_MASTER);
return NM_SETTING_VERIFY_ERROR;
}
s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_find_in_list (all_settings, NM_SETTING_IP6_CONFIG_SETTING_NAME));
if (s_ip6) {
if (strcmp (nm_setting_ip6_config_get_method (s_ip6),
NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) {
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_IP_CONFIG_NOT_ALLOWED,
_("IPv6 configuration is not allowed for slave"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_SLAVE_TYPE);
return FALSE;
}
} else {
if (priv->master) {
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
_("Cannot set '" NM_SETTING_CONNECTION_MASTER "' without '" NM_SETTING_CONNECTION_SLAVE_TYPE "'"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_SLAVE_TYPE);
return NM_SETTING_VERIFY_ERROR;
}
}
@ -1138,6 +1142,8 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
* set, then the connection can be attached to any interface of the
* appropriate type (subject to restrictions imposed by other settings).
*
* For software devices this specifies the name of the created device.
*
* For connection types where interface names cannot easily be made
* persistent (e.g. mobile broadband or USB Ethernet), this property should
* not be used. Setting this property restricts the interfaces a connection
@ -1171,7 +1177,7 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
/**
* NMSettingConnection:permissions:
*
*
* An array of strings defining what access a given user has to this
* connection. If this is %NULL or empty, all users are allowed to access
* this connection. Otherwise a user is allowed to access this connection

View file

@ -194,6 +194,7 @@ get_virtual_iface_name (NMSetting *setting)
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingConnection *s_con;
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (setting);
if (priv->mac_address && priv->mac_address->len != INFINIBAND_ALEN) {
@ -249,6 +250,45 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
}
s_con = NM_SETTING_CONNECTION (nm_setting_find_in_list (all_settings, NM_SETTING_CONNECTION_SETTING_NAME));
if (s_con) {
const char *interface_name = nm_setting_connection_get_interface_name (s_con);
if (!interface_name)
;
else if (!nm_utils_iface_valid_name (interface_name)) {
/* report the error for NMSettingConnection:interface-name, because
* it's that property that is invalid -- although we currently verify()
* NMSettingInfiniband.
**/
g_set_error (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid interface name"),
interface_name);
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return FALSE;
} else {
if (priv->p_key != -1) {
if (!priv->virtual_iface_name)
priv->virtual_iface_name = g_strdup_printf ("%s.%04x", priv->parent, priv->p_key);
if (strcmp (interface_name, priv->virtual_iface_name) != 0) {
/* We don't support renaming software infiniband devices. Later we might, but
* for now just reject such connections.
**/
g_set_error (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
_("interface name of software infiniband device must be '%s' or unset (instead it is '%s')"),
priv->virtual_iface_name, interface_name);
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return FALSE;
}
}
}
}
return TRUE;
}

View file

@ -30,6 +30,22 @@
NM_SETTING_SECRET_FLAG_NOT_SAVED | \
NM_SETTING_SECRET_FLAG_NOT_REQUIRED)
/**
* NMSettingVerifyResult:
* @NM_SETTING_VERIFY_SUCCESS: the setting verifies successfully
* @NM_SETTING_VERIFY_ERROR: the setting has a serious misconfiguration
* @NM_SETTING_VERIFY_NORMALIZABLE: the setting is valid but has properties
* that should be normalized
* @NM_SETTING_VERIFY_NORMALIZABLE_ERROR: the setting is invalid but the
* errors can be fixed by nm_connection_normalize().
*/
typedef enum {
NM_SETTING_VERIFY_SUCCESS = TRUE,
NM_SETTING_VERIFY_ERROR = FALSE,
NM_SETTING_VERIFY_NORMALIZABLE = 2,
NM_SETTING_VERIFY_NORMALIZABLE_ERROR = 3,
} NMSettingVerifyResult;
void _nm_register_setting (const char *name,
const GType type,
const guint32 priority,
@ -92,5 +108,19 @@ NMSetting *nm_setting_find_in_list (GSList *settings_list, const char *setting_n
const char *nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i);
gboolean nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting, NMIP4Address *address, const char *label);
NMSettingVerifyResult _nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name,
gboolean allow_missing,
const char *setting_name,
const char *setting_property,
GQuark error_quark,
gint e_invalid_property,
gint e_missing_property,
GSList *all_settings,
GError **error);
NMSettingVerifyResult _nm_setting_verify (NMSetting *setting,
GSList *all_settings,
GError **error);
#endif /* NM_SETTING_PRIVATE_H */

View file

@ -134,25 +134,13 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (setting);
if (!priv->interface_name || !strlen(priv->interface_name)) {
g_set_error_literal (error,
NM_SETTING_TEAM_ERROR,
NM_SETTING_TEAM_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_TEAM_INTERFACE_NAME);
return FALSE;
}
if (!nm_utils_iface_valid_name (priv->interface_name)) {
g_set_error_literal (error,
NM_SETTING_TEAM_ERROR,
NM_SETTING_TEAM_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_TEAM_INTERFACE_NAME);
return FALSE;
}
return TRUE;
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, FALSE,
NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_TEAM_INTERFACE_NAME,
NM_SETTING_TEAM_ERROR,
NM_SETTING_TEAM_ERROR_INVALID_PROPERTY,
NM_SETTING_TEAM_ERROR_MISSING_PROPERTY,
all_settings, error);
}
static const char *

View file

@ -537,20 +537,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
s_wired = iter->data;
}
/* If interface_name is specified, it must be a valid interface name. We
* don't check that it matches parent and/or id, because we allowing
* renaming vlans to arbitrary names.
*/
if (priv->interface_name && !nm_utils_iface_valid_name (priv->interface_name)) {
g_set_error (error,
NM_SETTING_VLAN_ERROR,
NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid interface name"),
priv->interface_name);
g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_INTERFACE_NAME);
return FALSE;
}
if (priv->parent) {
if (nm_utils_is_uuid (priv->parent)) {
/* If we have an NMSettingConnection:master with slave-type="vlan",
@ -582,7 +568,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
priv->parent);
g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT);
return FALSE;
}
}
} else {
/* If parent is NULL, the parent must be specified via
* NMSettingWired:mac-address.
@ -609,7 +595,17 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
return TRUE;
/* If interface_name is specified, it must be a valid interface name. We
* don't check that it matches parent and/or id, because we allow
* renaming vlans to arbitrary names.
*/
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, TRUE,
NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_INTERFACE_NAME,
NM_SETTING_VLAN_ERROR,
NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
NM_SETTING_VLAN_ERROR_MISSING_PROPERTY,
all_settings, error);
}
static const char *

View file

@ -24,6 +24,7 @@
*/
#include <string.h>
#include <glib/gi18n.h>
#include "nm-setting.h"
#include "nm-setting-private.h"
@ -517,13 +518,24 @@ nm_setting_get_name (NMSetting *setting)
gboolean
nm_setting_verify (NMSetting *setting, GSList *all_settings, GError **error)
{
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
g_return_val_if_fail (!error || *error == NULL, FALSE);
NMSettingVerifyResult result = _nm_setting_verify (setting, all_settings, error);
if (result == NM_SETTING_VERIFY_NORMALIZABLE)
g_clear_error (error);
return result == NM_SETTING_VERIFY_SUCCESS || result == NM_SETTING_VERIFY_NORMALIZABLE;
}
NMSettingVerifyResult
_nm_setting_verify (NMSetting *setting, GSList *all_settings, GError **error)
{
g_return_val_if_fail (NM_IS_SETTING (setting), NM_SETTING_VERIFY_ERROR);
g_return_val_if_fail (!error || *error == NULL, NM_SETTING_VERIFY_ERROR);
if (NM_SETTING_GET_CLASS (setting)->verify)
return NM_SETTING_GET_CLASS (setting)->verify (setting, all_settings, error);
return TRUE;
return NM_SETTING_VERIFY_SUCCESS;
}
static gboolean
@ -1259,6 +1271,87 @@ nm_setting_get_virtual_iface_name (NMSetting *setting)
return NULL;
}
NMSettingVerifyResult
_nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name,
gboolean allow_missing,
const char *setting_name,
const char *setting_property,
GQuark error_quark,
gint e_invalid_property,
gint e_missing_property,
GSList *all_settings,
GError **error)
{
NMSettingConnection *s_con;
const char *con_name;
s_con = NM_SETTING_CONNECTION (nm_setting_find_in_list (all_settings, NM_SETTING_CONNECTION_SETTING_NAME));
con_name = s_con ? nm_setting_connection_get_interface_name (s_con) : NULL;
if (!interface_name && !con_name) {
if (allow_missing)
return NM_SETTING_VERIFY_SUCCESS;
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return NM_SETTING_VERIFY_ERROR;
}
if (!con_name && !nm_utils_iface_valid_name (interface_name)) {
/* the interface_name is invalid, we cannot normalize it. Only do this if !con_name,
* because if con_name is set, it can overwrite interface_name. */
g_set_error_literal (error,
error_quark,
e_invalid_property,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", setting_name, setting_property);
return NM_SETTING_VERIFY_ERROR;
}
if (!con_name) {
/* NMSettingConnection has interface not set, it should be normalized to interface_name */
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return NM_SETTING_VERIFY_NORMALIZABLE;
}
if (!nm_utils_iface_valid_name (con_name)) {
/* NMSettingConnection:interface_name is invalid, we cannot normalize it. */
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return NM_SETTING_VERIFY_ERROR;
}
if (!interface_name) {
/* Normalize by setting NMSettingConnection:interface_name. */
g_set_error_literal (error,
error_quark,
e_missing_property,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", setting_name, setting_property);
return NM_SETTING_VERIFY_NORMALIZABLE;
}
if (strcmp (con_name, interface_name) != 0) {
/* con_name and interface_name are different. It can be normalized by setting interface_name
* to con_name. */
g_set_error_literal (error,
error_quark,
e_missing_property,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", setting_name, setting_property);
/* we would like to make this a NORMALIZEABLE_ERROR, but that might
* break older connections. */
return NM_SETTING_VERIFY_NORMALIZABLE;
}
return NM_SETTING_VERIFY_SUCCESS;
}
/*****************************************************************************/
static void

View file

@ -173,7 +173,7 @@ typedef struct {
GObjectClass parent;
/* Virtual functions */
gboolean (*verify) (NMSetting *setting,
gint (*verify) (NMSetting *setting,
GSList *all_settings,
GError **error);

View file

@ -2484,6 +2484,119 @@ test_setting_old_uuid (void)
g_assert (success == TRUE);
}
/*
* nm_connection_verify() modifies the connection by setting
* the interface-name property to the virtual_iface_name of
* the type specific settings.
*
* It would be preferable of verify() not to touch the connection,
* but as it is now, stick with it and test it.
**/
static void
test_connection_verify_sets_interface_name (void)
{
NMConnection *con;
NMSettingConnection *s_con;
NMSettingBond *s_bond;
GError *error = NULL;
gboolean success;
s_con = (NMSettingConnection *) nm_setting_connection_new ();
g_object_set (G_OBJECT (s_con),
NM_SETTING_CONNECTION_ID, "test1",
NM_SETTING_CONNECTION_UUID, "22001632-bbb4-4616-b277-363dce3dfb5b",
NM_SETTING_CONNECTION_TYPE, NM_SETTING_BOND_SETTING_NAME,
NULL);
s_bond = (NMSettingBond *) nm_setting_bond_new ();
g_object_set (G_OBJECT (s_bond),
NM_SETTING_BOND_INTERFACE_NAME, "bond-x",
NULL);
con = nm_connection_new ();
nm_connection_add_setting (con, NM_SETTING (s_con));
nm_connection_add_setting (con, NM_SETTING (s_bond));
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, NULL);
/* for backward compatiblity, normalizes the interface name */
success = nm_connection_verify (con, &error);
g_assert (success && !error);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, "bond-x");
g_object_unref (con);
}
/*
* Test normalization of interface-name
**/
static void
test_connection_normalize_virtual_iface_name (void)
{
NMConnection *con;
NMSettingConnection *s_con;
NMSettingVlan *s_vlan;
NMSetting *setting;
GError *error = NULL;
gboolean success;
const char *IFACE_NAME = "iface";
const char *IFACE_VIRT = "iface-X";
gboolean modified = FALSE;
con = nm_connection_new ();
setting = nm_setting_ip4_config_new ();
g_object_set (setting,
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
nm_connection_add_setting (con, setting);
setting = nm_setting_ip6_config_new ();
g_object_set (setting,
NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
NULL);
nm_connection_add_setting (con, setting);
s_con = (NMSettingConnection *) nm_setting_connection_new ();
g_object_set (G_OBJECT (s_con),
NM_SETTING_CONNECTION_ID, "test1",
NM_SETTING_CONNECTION_UUID, "22001632-bbb4-4616-b277-363dce3dfb5b",
NM_SETTING_CONNECTION_TYPE, NM_SETTING_VLAN_SETTING_NAME,
NM_SETTING_CONNECTION_INTERFACE_NAME, IFACE_NAME,
NULL);
s_vlan = (NMSettingVlan *) nm_setting_vlan_new ();
g_object_set (G_OBJECT (s_vlan),
NM_SETTING_VLAN_INTERFACE_NAME, IFACE_VIRT,
NM_SETTING_VLAN_PARENT, "eth0",
NULL);
nm_connection_add_setting (con, NM_SETTING (s_con));
nm_connection_add_setting (con, NM_SETTING (s_vlan));
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_VIRT);
/* for backward compatiblity, normalizes the interface name */
success = nm_connection_verify (con, &error);
g_assert (success && !error);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_VIRT);
success = nm_connection_normalize (con, NULL, &modified, &error);
g_assert (success && !error);
g_assert (modified);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_NAME);
success = nm_connection_verify (con, &error);
g_assert (success && !error);
g_object_unref (con);
}
NMTST_DEFINE ();
int main (int argc, char **argv)
@ -2521,6 +2634,8 @@ int main (int argc, char **argv)
test_connection_replace_settings ();
test_connection_replace_settings_from_connection ();
test_connection_new_from_hash ();
test_connection_verify_sets_interface_name ();
test_connection_normalize_virtual_iface_name ();
test_setting_connection_permissions_helpers ();
test_setting_connection_permissions_property ();

View file

@ -14,6 +14,7 @@ libnm-util/crypto.c
libnm-util/crypto_gnutls.c
libnm-util/crypto_nss.c
libnm-util/nm-connection.c
libnm-util/nm-setting.c
libnm-util/nm-setting-8021x.c
libnm-util/nm-setting-adsl.c
libnm-util/nm-setting-bluetooth.c

View file

@ -453,70 +453,6 @@ 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);
if (nm_setting_connection_get_master (s_con)) {
/* Slave connections don't have IP configuration. */
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;
}
} 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
* 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);
}
}
}
const char *
nm_utils_get_ip_config_method (NMConnection *connection,
GType ip_setting_type)
@ -570,6 +506,10 @@ nm_utils_complete_generic (NMConnection *connection,
{
NMSettingConnection *s_con;
char *id, *uuid;
GHashTable *parameters = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (parameters, NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD,
default_enable_ipv6 ? NM_SETTING_IP6_CONFIG_METHOD_AUTO : NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
s_con = nm_connection_get_setting_connection (connection);
if (!s_con) {
@ -592,7 +532,9 @@ nm_utils_complete_generic (NMConnection *connection,
}
/* Normalize */
nm_utils_normalize_connection (connection, default_enable_ipv6);
nm_connection_normalize (connection, parameters, NULL, NULL);
g_hash_table_destroy (parameters);
}
char *

View file

@ -93,8 +93,6 @@ void value_hash_add_object_property (GHashTable *hash,
const char *prop,
GType val_type);
void nm_utils_normalize_connection (NMConnection *connection,
gboolean default_enable_ipv6);
const char *nm_utils_get_ip_config_method (NMConnection *connection,
GType ip_setting_type);

View file

@ -445,8 +445,7 @@ nm_settings_connection_replace_settings (NMSettingsConnection *self,
priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
nm_utils_normalize_connection (new_connection, TRUE);
if (!nm_connection_verify (new_connection, error))
if (!nm_connection_normalize (new_connection, NULL, NULL, error))
return FALSE;
/* Do nothing if there's nothing to update */

View file

@ -831,9 +831,7 @@ claim_connection (NMSettings *self,
return;
}
nm_utils_normalize_connection (NM_CONNECTION (connection), TRUE);
if (!nm_connection_verify (NM_CONNECTION (connection), &error)) {
if (!nm_connection_normalize (NM_CONNECTION (connection), NULL, NULL, &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)),
error->message, error->code);

View file

@ -5245,9 +5245,7 @@ connection_from_file (const char *filename,
}
g_free (bootproto);
nm_utils_normalize_connection (connection, TRUE);
if (!nm_connection_verify (connection, error)) {
if (!nm_connection_normalize (connection, NULL, NULL, error)) {
g_object_unref (connection);
connection = NULL;
}

View file

@ -2786,7 +2786,7 @@ test_read_write_802_1X_subj_matches (void)
g_assert (success);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
@ -6136,7 +6136,7 @@ test_write_wifi_hidden (void)
svCloseFile (f);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL,
@ -6834,7 +6834,7 @@ test_write_wired_static (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -6957,7 +6957,7 @@ test_write_wired_dhcp (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -7011,7 +7011,7 @@ test_write_wired_dhcp_plus_ip (void)
g_assert (success);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (written, NULL, TYPE_ETHERNET, NULL, NULL,
@ -7071,7 +7071,7 @@ test_read_write_wired_dhcp_send_hostname (void)
g_assert (success);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (written, NULL, TYPE_ETHERNET, NULL, NULL,
@ -7196,7 +7196,7 @@ test_write_wired_static_ip6_only (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -7343,7 +7343,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -7501,7 +7501,7 @@ test_read_write_static_routes_legacy (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -7676,7 +7676,7 @@ test_write_wired_static_routes (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -7808,7 +7808,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -7993,7 +7993,7 @@ test_write_wired_8021x_tls (NMSetting8021xCKScheme scheme,
g_assert (testfile != NULL);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -8408,7 +8408,7 @@ test_write_gateway (void)
svCloseFile (f);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL,
@ -8529,7 +8529,7 @@ test_write_wifi_open (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -8661,7 +8661,7 @@ test_write_wifi_open_hex_ssid (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -8792,7 +8792,7 @@ test_write_wifi_wep (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -8943,7 +8943,7 @@ test_write_wifi_wep_adhoc (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -9084,7 +9084,7 @@ test_write_wifi_wep_passphrase (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -9227,7 +9227,7 @@ test_write_wifi_wep_40_ascii (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -9370,7 +9370,7 @@ test_write_wifi_wep_104_ascii (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -9510,7 +9510,7 @@ test_write_wifi_leap (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -9649,7 +9649,7 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags)
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -9805,7 +9805,7 @@ test_write_wifi_wpa_psk (const char *name,
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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -9956,7 +9956,7 @@ test_write_wifi_wpa_psk_adhoc (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -10122,7 +10122,7 @@ test_write_wifi_wpa_eap_tls (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -10306,7 +10306,7 @@ test_write_wifi_wpa_eap_ttls_tls (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -10462,7 +10462,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -10606,7 +10606,7 @@ test_write_wifi_wpa_then_open (void)
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -10653,7 +10653,7 @@ test_write_wifi_wpa_then_open (void)
keyfile = NULL;
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read it for comparison */
reread = connection_from_file (testfile,
@ -10805,7 +10805,7 @@ test_write_wifi_wpa_then_wep_with_perms (void)
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -10858,7 +10858,7 @@ test_write_wifi_wpa_then_wep_with_perms (void)
keyfile = NULL;
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read it for comparison */
reread = connection_from_file (testfile,
@ -11003,7 +11003,7 @@ test_write_wifi_dynamic_wep_leap (void)
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -11537,7 +11537,7 @@ test_write_wired_qeth_dhcp (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -11674,7 +11674,7 @@ test_write_wired_ctc_dhcp (void)
svCloseFile (ifcfg);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -11786,7 +11786,7 @@ test_write_permissions (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -11916,7 +11916,7 @@ test_write_wifi_wep_agent_keys (void)
g_assert (testfile != NULL);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -12325,7 +12325,7 @@ test_write_bridge_main (void)
g_assert_cmpstr (testfile, !=, NULL);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -12480,7 +12480,7 @@ test_write_bridge_component (void)
g_assert (testfile);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -12815,7 +12815,7 @@ test_write_vlan_only_vlanid (void)
g_assert (success);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (written,
@ -12924,7 +12924,7 @@ test_write_ethernet_missing_ipv6 (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -13115,7 +13115,7 @@ test_write_bond_main (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -13162,8 +13162,6 @@ test_read_bond_slave (void)
gboolean ignore_error = FALSE;
GError *error = NULL;
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
"*ignoring IP4 config on slave*");
connection = connection_from_file (TEST_IFCFG_BOND_SLAVE,
NULL,
TYPE_ETHERNET,
@ -13269,7 +13267,7 @@ test_write_bond_slave (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -13483,7 +13481,7 @@ test_write_infiniband (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -13530,8 +13528,6 @@ test_read_bond_slave_ib (void)
gboolean ignore_error = FALSE;
GError *error = NULL;
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING,
"*ignoring IP4 config on slave*");
connection = connection_from_file (TEST_IFCFG_BOND_SLAVE_IB,
NULL,
NULL,
@ -13640,7 +13636,7 @@ test_write_bond_slave_ib (void)
"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);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
@ -14215,7 +14211,7 @@ test_write_team_master (void)
svCloseFile (f);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL,
@ -14338,7 +14334,7 @@ test_write_team_port (void)
svCloseFile (f);
/* reread will be normalized, so we must normalize connection too. */
nm_utils_normalize_connection (connection, TRUE);
nm_connection_normalize (connection, NULL, NULL, NULL);
/* re-read the connection for comparison */
reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL,