diff options
Diffstat (limited to 'libnm-util/nm-setting-connection.c')
| -rw-r--r-- | libnm-util/nm-setting-connection.c | 312 |
1 files changed, 129 insertions, 183 deletions
diff --git a/libnm-util/nm-setting-connection.c b/libnm-util/nm-setting-connection.c index 56e87a4d..162ae7cb 100644 --- a/libnm-util/nm-setting-connection.c +++ b/libnm-util/nm-setting-connection.c @@ -1,9 +1,6 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ /* - * Dan Williams <dcbw@redhat.com> - * Tambet Ingo <tambet@gmail.com> - * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -19,12 +16,14 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * (C) Copyright 2007 - 2013 Red Hat, Inc. - * (C) Copyright 2007 - 2008 Novell, Inc. + * Copyright 2007 - 2013 Red Hat, Inc. + * Copyright 2007 - 2008 Novell, Inc. */ +#include "config.h" + #include <string.h> -#include <glib/gi18n.h> +#include <glib/gi18n-lib.h> #include "nm-utils.h" #include "nm-dbus-glib-types.h" @@ -459,7 +458,7 @@ nm_setting_connection_remove_permission (NMSettingConnection *setting, * be a username. See #NMSettingConnection:permissions: for more details. * * Returns: %TRUE if the permission was found and removed; %FALSE if it was not. - * + * * Since: 0.9.10 */ gboolean @@ -796,29 +795,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; - - 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 (!priv->interface_name) { + for (iter = all_settings; iter; iter = iter->next) { + NMSetting *s_current = iter->data; + char *virtual_iface_name = NULL; + + 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 +866,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; } } @@ -1103,13 +1106,11 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_ID, - g_param_spec_string (NM_SETTING_CONNECTION_ID, - "ID", - "User-readable connection identifier/name. Must be " - "one or more characters and may change over the lifetime " - "of the connection if the user decides to rename it.", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE)); + g_param_spec_string (NM_SETTING_CONNECTION_ID, "", "", + NULL, + G_PARAM_READWRITE | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:uuid: @@ -1129,20 +1130,11 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_UUID, - g_param_spec_string (NM_SETTING_CONNECTION_UUID, - "UUID", - "Universally unique connection identifier. Must be " - "in the format '2815492f-7e56-435e-b2e9-246bd7cdc664' " - "(ie, contains only hexadecimal characters and '-'). " - "The UUID should be assigned when the connection is " - "created and never changed as long as the connection " - "still applies to the same network. For example, " - "it should not be changed when the user changes the " - "connection's 'id', but should be recreated when the " - "Wi-Fi SSID, mobile broadband network provider, or the " - "connection type changes.", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE)); + g_param_spec_string (NM_SETTING_CONNECTION_UUID, "", "", + NULL, + G_PARAM_READWRITE | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:interface-name: @@ -1151,6 +1143,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 @@ -1161,21 +1155,11 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_INTERFACE_NAME, - g_param_spec_string (NM_SETTING_CONNECTION_INTERFACE_NAME, - "Interface name", - "Interface name this connection is bound to. " - "If not set, then the connection can be attached " - "to any interface of the appropriate type (subject " - "to restrictions imposed by other settings). 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 can " - "be used with, and if interface names change or are " - "reordered the connection may be applied to the wrong " - "interface.", + g_param_spec_string (NM_SETTING_CONNECTION_INTERFACE_NAME, "", "", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE)); + G_PARAM_READWRITE | + NM_SETTING_PARAM_INFERRABLE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:type: @@ -1188,21 +1172,15 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_TYPE, - g_param_spec_string (NM_SETTING_CONNECTION_TYPE, - "Type", - "Base type of the connection. For hardware-dependent " - "connections, should contain the setting name of the " - "hardware-type specific setting (ie, '802-3-ethernet' " - "or '802-11-wireless' or 'bluetooth', etc), and for " - "non-hardware dependent connections like VPN or " - "otherwise, should contain the setting name of that " - "setting type (ie, 'vpn' or 'bridge', etc).", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE)); + g_param_spec_string (NM_SETTING_CONNECTION_TYPE, "", "", + NULL, + G_PARAM_READWRITE | + NM_SETTING_PARAM_INFERRABLE | + G_PARAM_STATIC_STRINGS)); /** * 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 @@ -1217,25 +1195,10 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) */ g_object_class_install_property (object_class, PROP_PERMISSIONS, - _nm_param_spec_specialized (NM_SETTING_CONNECTION_PERMISSIONS, - "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 if and only if they are in this " - "array. Each entry is of the form " - "\"[type]:[id]:[reserved]\", for example: " - "\"user:dcbw:blah\" At this time only the 'user' " - "[type] is allowed. Any other values are ignored and " - "reserved for future use. [id] is the username that " - "this permission refers to, which may not contain the " - "':' character. Any [reserved] information (if " - "present) must be ignored and is reserved for future " - "use. All of [type], [id], and [reserved] must be " - "valid UTF-8.", - DBUS_TYPE_G_LIST_OF_STRING, - G_PARAM_READWRITE)); + _nm_param_spec_specialized (NM_SETTING_CONNECTION_PERMISSIONS, "", "", + DBUS_TYPE_G_LIST_OF_STRING, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:autoconnect: @@ -1247,14 +1210,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_AUTOCONNECT, - g_param_spec_boolean (NM_SETTING_CONNECTION_AUTOCONNECT, - "Autoconnect", - "If TRUE, NetworkManager will activate this connection " - "when its network resources are available. If FALSE, " - "the connection must be manually activated by the user " - "or some other mechanism.", - TRUE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE)); + g_param_spec_boolean (NM_SETTING_CONNECTION_AUTOCONNECT, "", "", + TRUE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:timestamp: @@ -1269,16 +1230,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_TIMESTAMP, - g_param_spec_uint64 (NM_SETTING_CONNECTION_TIMESTAMP, - "Timestamp", - "Timestamp (in seconds since the Unix Epoch) that the " - "connection was last successfully activated. NetworkManager " - "updates the connection timestamp periodically when the " - "connection is active to ensure that an active connection " - "has the latest timestamp. The property is only meant for " - "reading (changes to this property will not be preserved).", + g_param_spec_uint64 (NM_SETTING_CONNECTION_TIMESTAMP, "", "", 0, G_MAXUINT64, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE)); + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:read-only: @@ -1288,15 +1245,13 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) * connection is read-only and cannot be modified. **/ g_object_class_install_property - (object_class, PROP_READ_ONLY, - g_param_spec_boolean (NM_SETTING_CONNECTION_READ_ONLY, - "Read-Only", - "If TRUE, the connection is read-only and cannot be " - "changed by the user or any other mechanism. This is " - "normally set for system connections whose plugin " - "cannot yet write updated connections back out.", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE)); + (object_class, PROP_READ_ONLY, + g_param_spec_boolean (NM_SETTING_CONNECTION_READ_ONLY, "", "", + FALSE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:zone: @@ -1308,16 +1263,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_ZONE, - g_param_spec_string (NM_SETTING_CONNECTION_ZONE, - "Zone", - "The trust level of a the connection." - "Free form case-insensitive string (for example " - "\"Home\", \"Work\", \"Public\"). NULL or " - "unspecified zone means the connection will be " - "placed in the default zone as defined by the " - "firewall.", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE)); + g_param_spec_string (NM_SETTING_CONNECTION_ZONE, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:master: @@ -1326,12 +1277,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_MASTER, - g_param_spec_string (NM_SETTING_CONNECTION_MASTER, - "Master", - "Interface name of the master device or UUID of " - "the master connection", + g_param_spec_string (NM_SETTING_CONNECTION_MASTER, "", "", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE)); + G_PARAM_READWRITE | + NM_SETTING_PARAM_FUZZY_IGNORE | + NM_SETTING_PARAM_INFERRABLE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:slave-type: @@ -1342,13 +1293,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_SLAVE_TYPE, - g_param_spec_string (NM_SETTING_CONNECTION_SLAVE_TYPE, - "Slave-Type", - "Setting name describing the type of slave " - "this connection is (ie, 'bond') or NULL if this " - "connection is not a slave.", + g_param_spec_string (NM_SETTING_CONNECTION_SLAVE_TYPE, "", "", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE)); + G_PARAM_READWRITE | + NM_SETTING_PARAM_FUZZY_IGNORE | + NM_SETTING_PARAM_INFERRABLE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:secondaries: @@ -1361,13 +1311,11 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_SECONDARIES, - _nm_param_spec_specialized (NM_SETTING_CONNECTION_SECONDARIES, - "Secondaries", - "List of connection UUIDs that should be activated " - "when the base connection itself is activated. " - "Currently only VPN connections are supported.", + _nm_param_spec_specialized (NM_SETTING_CONNECTION_SECONDARIES, "", "", DBUS_TYPE_G_LIST_OF_STRING, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE)); + G_PARAM_READWRITE | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); /** * NMSettingConnection:gateway-ping-timeout: @@ -1379,11 +1327,9 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) **/ g_object_class_install_property (object_class, PROP_GATEWAY_PING_TIMEOUT, - g_param_spec_uint (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, - "Gateway Ping Timeout", - "If greater than zero, delay success of IP " - "addressing until either the timeout is reached, or " - "an IP gateway replies to a ping.", + g_param_spec_uint (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, "", "", 0, 30, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); } |