core: use nm_connection_get_id() and nm_connection_get_uuid() to simplify code
This commit is contained in:
@@ -738,11 +738,9 @@ get_new_connection_name (const GSList *existing,
|
||||
|
||||
for (iter = existing; iter; iter = g_slist_next (iter)) {
|
||||
NMConnection *candidate = NM_CONNECTION (iter->data);
|
||||
NMSettingConnection *s_con;
|
||||
const char *id;
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
|
||||
id = nm_setting_connection_get_id (s_con);
|
||||
id = nm_connection_get_id (candidate);
|
||||
g_assert (id);
|
||||
names = g_slist_append (names, (gpointer) id);
|
||||
|
||||
|
@@ -1350,7 +1350,6 @@ nm_8021x_stage2_config (NMDeviceEthernet *self, NMDeviceStateReason *reason)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSetting8021x *security;
|
||||
NMSettingConnection *s_connection;
|
||||
const char *setting_name;
|
||||
const char *iface;
|
||||
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
|
||||
@@ -1364,7 +1363,6 @@ nm_8021x_stage2_config (NMDeviceEthernet *self, NMDeviceStateReason *reason)
|
||||
}
|
||||
|
||||
iface = nm_device_get_iface (NM_DEVICE (self));
|
||||
s_connection = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
|
||||
|
||||
/* If we need secrets, get them */
|
||||
setting_name = nm_connection_need_secrets (connection, NULL);
|
||||
@@ -1373,7 +1371,7 @@ nm_8021x_stage2_config (NMDeviceEthernet *self, NMDeviceStateReason *reason)
|
||||
|
||||
nm_log_info (LOGD_DEVICE | LOGD_ETHER,
|
||||
"Activation (%s/wired): connection '%s' has security, but secrets are required.",
|
||||
iface, nm_setting_connection_get_id (s_connection));
|
||||
iface, nm_connection_get_id (connection));
|
||||
|
||||
ret = handle_auth_or_fail (self, req, FALSE);
|
||||
if (ret != NM_ACT_STAGE_RETURN_POSTPONE)
|
||||
@@ -1381,7 +1379,7 @@ nm_8021x_stage2_config (NMDeviceEthernet *self, NMDeviceStateReason *reason)
|
||||
} else {
|
||||
nm_log_info (LOGD_DEVICE | LOGD_ETHER,
|
||||
"Activation (%s/wired): connection '%s' requires no security. No secrets needed.",
|
||||
iface, nm_setting_connection_get_id (s_connection));
|
||||
iface, nm_connection_get_id (connection));
|
||||
|
||||
if (supplicant_interface_init (self))
|
||||
ret = NM_ACT_STAGE_RETURN_POSTPONE;
|
||||
@@ -1799,7 +1797,6 @@ static gboolean
|
||||
ip4_match_config (NMDevice *self, NMConnection *connection)
|
||||
{
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMSettingConnection *s_con;
|
||||
struct nl_handle *nlh = NULL;
|
||||
struct nl_cache *addr_cache = NULL;
|
||||
int i, num;
|
||||
@@ -1811,10 +1808,6 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
|
||||
|
||||
ifindex = nm_device_get_ifindex (self);
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
g_assert (nm_setting_connection_get_uuid (s_con));
|
||||
|
||||
s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
if (!s_ip4)
|
||||
return FALSE;
|
||||
@@ -1833,7 +1826,7 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
|
||||
dhcp_mgr = nm_dhcp_manager_get ();
|
||||
leases = nm_dhcp_manager_get_lease_config (dhcp_mgr,
|
||||
nm_device_get_iface (self),
|
||||
nm_setting_connection_get_uuid (s_con));
|
||||
nm_connection_get_uuid (connection));
|
||||
g_object_unref (dhcp_mgr);
|
||||
|
||||
method = nm_setting_ip4_config_get_method (s_ip4);
|
||||
|
@@ -302,7 +302,6 @@ nm_device_interface_activate (NMDeviceInterface *device,
|
||||
{
|
||||
gboolean success;
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
char *iface;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE_INTERFACE (device), FALSE);
|
||||
@@ -310,12 +309,10 @@ nm_device_interface_activate (NMDeviceInterface *device,
|
||||
|
||||
connection = nm_act_request_get_connection (req);
|
||||
g_assert (connection);
|
||||
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
|
||||
g_assert (s_con);
|
||||
|
||||
iface = nm_device_interface_get_iface (device);
|
||||
nm_log_info (LOGD_DEVICE, "Activation (%s) starting connection '%s'", iface,
|
||||
nm_setting_connection_get_id (s_con));
|
||||
nm_connection_get_id (connection));
|
||||
g_free (iface);
|
||||
|
||||
success = NM_DEVICE_INTERFACE_GET_INTERFACE (device)->activate (device, req, error);
|
||||
|
@@ -3130,7 +3130,6 @@ real_act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason)
|
||||
NMActRequest *req;
|
||||
NMAccessPoint *ap;
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_connection;
|
||||
const char *setting_name;
|
||||
NMSettingWireless *s_wireless;
|
||||
|
||||
@@ -3147,9 +3146,6 @@ real_act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason)
|
||||
connection = nm_act_request_get_connection (req);
|
||||
g_assert (connection);
|
||||
|
||||
s_connection = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_connection);
|
||||
|
||||
s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS);
|
||||
g_assert (s_wireless);
|
||||
|
||||
@@ -3159,7 +3155,7 @@ real_act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason)
|
||||
nm_log_info (LOGD_DEVICE | LOGD_WIFI,
|
||||
"Activation (%s/wireless): access point '%s' has security,"
|
||||
" but secrets are required.",
|
||||
iface, nm_setting_connection_get_id (s_connection));
|
||||
iface, nm_connection_get_id (connection));
|
||||
|
||||
ret = handle_auth_or_fail (self, req, FALSE);
|
||||
if (ret == NM_ACT_STAGE_RETURN_FAILURE)
|
||||
@@ -3172,12 +3168,12 @@ real_act_stage2_config (NMDevice *dev, NMDeviceStateReason *reason)
|
||||
nm_log_info (LOGD_DEVICE | LOGD_WIFI,
|
||||
"Activation (%s/wireless): connection '%s' has security"
|
||||
", and secrets exist. No new secrets needed.",
|
||||
iface, nm_setting_connection_get_id (s_connection));
|
||||
iface, nm_connection_get_id (connection));
|
||||
} else {
|
||||
nm_log_info (LOGD_DEVICE | LOGD_WIFI,
|
||||
"Activation (%s/wireless): connection '%s' requires no "
|
||||
"security. No secrets needed.",
|
||||
iface, nm_setting_connection_get_id (s_connection));
|
||||
iface, nm_connection_get_id (connection));
|
||||
}
|
||||
|
||||
config = build_supplicant_config (self, connection, ap);
|
||||
@@ -3283,16 +3279,12 @@ handle_ip_config_timeout (NMDeviceWifi *self,
|
||||
*/
|
||||
auth_enforced = ap_auth_enforced (connection, ap, &encrypted);
|
||||
if (encrypted && !auth_enforced && !may_fail) {
|
||||
NMSettingConnection *s_con;
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
|
||||
|
||||
/* Activation failed, we must have bad encryption key */
|
||||
nm_log_warn (LOGD_DEVICE | LOGD_WIFI,
|
||||
"Activation (%s/wireless): could not get IP configuration for "
|
||||
"connection '%s'.",
|
||||
nm_device_get_iface (NM_DEVICE (self)),
|
||||
nm_setting_connection_get_id (s_con));
|
||||
nm_connection_get_id (connection));
|
||||
|
||||
ret = handle_auth_or_fail (self, NULL, TRUE);
|
||||
if (ret == NM_ACT_STAGE_RETURN_POSTPONE) {
|
||||
|
@@ -1517,12 +1517,9 @@ dhcp4_start (NMDevice *self,
|
||||
NMDeviceStateReason *reason)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
guint8 *anycast = NULL;
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
|
||||
if (priv->dhcp_anycast_address)
|
||||
@@ -1537,7 +1534,7 @@ dhcp4_start (NMDevice *self,
|
||||
g_warn_if_fail (priv->dhcp4_client == NULL);
|
||||
priv->dhcp4_client = nm_dhcp_manager_start_ip4 (priv->dhcp_manager,
|
||||
nm_device_get_ip_iface (self),
|
||||
nm_setting_connection_get_uuid (s_con),
|
||||
nm_connection_get_uuid (connection),
|
||||
s_ip4,
|
||||
priv->dhcp_timeout,
|
||||
anycast);
|
||||
@@ -1652,8 +1649,6 @@ dhcp6_start (NMDevice *self,
|
||||
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
|
||||
guint8 *anycast = NULL;
|
||||
NMSettingIP6Config *s_ip6;
|
||||
NMSettingConnection *s_con;
|
||||
const char *uuid;
|
||||
const char *ip_iface;
|
||||
const struct in6_addr dest = { { { 0xFF,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } };
|
||||
int err;
|
||||
@@ -1689,16 +1684,12 @@ dhcp6_start (NMDevice *self,
|
||||
priv->ip_iface ? priv->ip_iface : priv->iface, nl_geterror ());
|
||||
}
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
uuid = nm_setting_connection_get_uuid (s_con);
|
||||
|
||||
s_ip6 = (NMSettingIP6Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
|
||||
|
||||
ip_iface = nm_device_get_ip_iface (self);
|
||||
priv->dhcp6_client = nm_dhcp_manager_start_ip6 (priv->dhcp_manager,
|
||||
ip_iface,
|
||||
uuid,
|
||||
nm_connection_get_uuid (connection),
|
||||
s_ip6,
|
||||
priv->dhcp_timeout,
|
||||
anycast,
|
||||
|
@@ -1441,14 +1441,10 @@ add_device (NMManager *self, NMDevice *device)
|
||||
(const GSList *) connections);
|
||||
g_slist_free (connections);
|
||||
|
||||
if (existing) {
|
||||
NMSettingConnection *s_con;
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (existing, NM_TYPE_SETTING_CONNECTION);
|
||||
if (existing)
|
||||
nm_log_dbg (LOGD_DEVICE, "(%s): found existing device connection '%s'",
|
||||
nm_device_get_iface (device),
|
||||
nm_setting_connection_get_id (s_con));
|
||||
}
|
||||
nm_connection_get_id (existing));
|
||||
}
|
||||
|
||||
/* Start the device if it's supposed to be managed */
|
||||
|
@@ -74,19 +74,6 @@ struct NMPolicy {
|
||||
#define RETRIES_TAG "autoconnect-retries"
|
||||
#define RETRIES_DEFAULT 4
|
||||
|
||||
static const char *
|
||||
get_connection_id (NMConnection *connection)
|
||||
{
|
||||
NMSettingConnection *s_con;
|
||||
|
||||
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
||||
g_return_val_if_fail (s_con != NULL, NULL);
|
||||
|
||||
return nm_setting_connection_get_id (s_con);
|
||||
}
|
||||
|
||||
static NMDevice *
|
||||
get_best_ip4_device (NMManager *manager, NMActRequest **out_req)
|
||||
{
|
||||
@@ -760,13 +747,8 @@ auto_activate_device (gpointer user_data)
|
||||
nm_device_get_path (data->device),
|
||||
NULL,
|
||||
&error)) {
|
||||
NMSettingConnection *s_con;
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (best_connection, NM_TYPE_SETTING_CONNECTION));
|
||||
g_assert (s_con);
|
||||
|
||||
nm_log_info (LOGD_DEVICE, "Connection '%s' auto-activation failed: (%d) %s",
|
||||
nm_setting_connection_get_id (s_con), error->code, error->message);
|
||||
nm_connection_get_id (best_connection), error->code, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
@@ -894,7 +876,7 @@ device_state_changed (NMDevice *device,
|
||||
if (connection && IS_ACTIVATING_STATE (old_state)) {
|
||||
g_object_set_data (G_OBJECT (connection), INVALID_TAG, GUINT_TO_POINTER (TRUE));
|
||||
if (get_connection_auto_retries (connection) == 0)
|
||||
nm_log_info (LOGD_DEVICE, "Marking connection '%s' invalid.", get_connection_id (connection));
|
||||
nm_log_info (LOGD_DEVICE, "Marking connection '%s' invalid.", nm_connection_get_id (connection));
|
||||
nm_connection_clear_secrets (connection);
|
||||
}
|
||||
schedule_activate_check (policy, device, 3);
|
||||
@@ -1062,7 +1044,6 @@ connection_updated (NMSettings *settings,
|
||||
static void
|
||||
_deactivate_if_active (NMManager *manager, NMConnection *connection)
|
||||
{
|
||||
NMSettingConnection *s_con;
|
||||
GPtrArray *list;
|
||||
int i;
|
||||
|
||||
@@ -1070,16 +1051,13 @@ _deactivate_if_active (NMManager *manager, NMConnection *connection)
|
||||
if (!list)
|
||||
return;
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
|
||||
g_assert (s_con);
|
||||
|
||||
for (i = 0; i < list->len; i++) {
|
||||
char *path = g_ptr_array_index (list, i);
|
||||
GError *error = NULL;
|
||||
|
||||
if (!nm_manager_deactivate_connection (manager, path, NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, &error)) {
|
||||
nm_log_warn (LOGD_DEVICE, "Connection '%s' disappeared, but error deactivating it: (%d) %s",
|
||||
nm_setting_connection_get_id (s_con), error->code, error->message);
|
||||
nm_connection_get_id (connection), error->code, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
g_free (path);
|
||||
|
@@ -654,7 +654,6 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
|
||||
GError **error)
|
||||
{
|
||||
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
||||
NMSettingConnection *s_con;
|
||||
GHashTable *existing_secrets;
|
||||
guint32 call_id = 0;
|
||||
|
||||
@@ -694,9 +693,8 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
|
||||
if (existing_secrets)
|
||||
g_hash_table_unref (existing_secrets);
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (self), NM_TYPE_SETTING_CONNECTION);
|
||||
nm_log_dbg (LOGD_SETTINGS, "(%s/%s:%u) secrets requested flags 0x%X hint '%s'",
|
||||
nm_setting_connection_get_uuid (s_con),
|
||||
nm_connection_get_uuid (NM_CONNECTION (self)),
|
||||
setting_name,
|
||||
call_id,
|
||||
flags,
|
||||
@@ -710,11 +708,9 @@ nm_settings_connection_cancel_secrets (NMSettingsConnection *self,
|
||||
guint32 call_id)
|
||||
{
|
||||
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
||||
NMSettingConnection *s_con;
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (self), NM_TYPE_SETTING_CONNECTION);
|
||||
nm_log_dbg (LOGD_SETTINGS, "(%s:%u) secrets canceled",
|
||||
nm_setting_connection_get_uuid (s_con),
|
||||
nm_connection_get_uuid (NM_CONNECTION (self)),
|
||||
call_id);
|
||||
|
||||
priv->reqs = g_slist_remove (priv->reqs, GUINT_TO_POINTER (call_id));
|
||||
|
@@ -597,7 +597,6 @@ connection_removed (NMSettingsConnection *obj, gpointer user_data)
|
||||
{
|
||||
GObject *connection = G_OBJECT (obj);
|
||||
guint id;
|
||||
|
||||
g_object_ref (connection);
|
||||
|
||||
/* Disconnect signal handlers, as plugins might still keep references
|
||||
@@ -1289,7 +1288,6 @@ default_wired_try_update (NMDefaultWiredConnection *wired,
|
||||
NMSettings *self)
|
||||
{
|
||||
GError *error = NULL;
|
||||
NMSettingConnection *s_con;
|
||||
const char *id;
|
||||
NMSettingsConnection *added;
|
||||
|
||||
@@ -1297,10 +1295,7 @@ default_wired_try_update (NMDefaultWiredConnection *wired,
|
||||
* persistent storage.
|
||||
*/
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (wired),
|
||||
NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
id = nm_setting_connection_get_id (s_con);
|
||||
id = nm_connection_get_id (NM_CONNECTION (wired));
|
||||
g_assert (id);
|
||||
|
||||
remove_default_wired_connection (self, NM_SETTINGS_CONNECTION (wired), FALSE);
|
||||
@@ -1335,7 +1330,6 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
|
||||
GByteArray *mac = NULL;
|
||||
struct ether_addr tmp;
|
||||
NMDefaultWiredConnection *wired;
|
||||
NMSettingConnection *s_con;
|
||||
gboolean read_only = TRUE;
|
||||
const char *id;
|
||||
|
||||
@@ -1365,10 +1359,7 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
|
||||
if (!wired)
|
||||
goto ignore;
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (wired),
|
||||
NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
id = nm_setting_connection_get_id (s_con);
|
||||
id = nm_connection_get_id (NM_CONNECTION (wired));
|
||||
g_assert (id);
|
||||
|
||||
nm_log_info (LOGD_SETTINGS, "Added default wired connection '%s' for %s",
|
||||
|
@@ -117,7 +117,6 @@ _internal_new_connection (SCPluginIfcfg *self,
|
||||
{
|
||||
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (self);
|
||||
NMIfcfgConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
const char *cid;
|
||||
GError *local = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
@@ -136,9 +135,7 @@ _internal_new_connection (SCPluginIfcfg *self,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
cid = nm_setting_connection_get_id (s_con);
|
||||
cid = nm_connection_get_id (NM_CONNECTION (connection));
|
||||
g_assert (cid);
|
||||
|
||||
g_hash_table_insert (priv->connections,
|
||||
@@ -296,12 +293,9 @@ connection_new_or_changed (SCPluginIfcfg *self,
|
||||
}
|
||||
} else {
|
||||
if (old_unmanaged) { /* now managed */
|
||||
NMSettingConnection *s_con;
|
||||
const char *cid;
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (new), NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
cid = nm_setting_connection_get_id (s_con);
|
||||
cid = nm_connection_get_id (NM_CONNECTION (new));
|
||||
g_assert (cid);
|
||||
|
||||
PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Managing connection '%s' and its "
|
||||
|
@@ -250,18 +250,13 @@ dir_changed (GFileMonitor *monitor,
|
||||
connection = nm_keyfile_connection_new (full_path, NULL, &error);
|
||||
if (connection) {
|
||||
NMKeyfileConnection *found = NULL;
|
||||
NMSettingConnection *s_con;
|
||||
|
||||
/* Connection renames will show up as different files but with
|
||||
* the same UUID. Try to find the original connection.
|
||||
*/
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
|
||||
/* A connection rename is treated just like an update except
|
||||
* A connection rename is treated just like an update except
|
||||
* there's a bit more housekeeping with the hash table.
|
||||
*/
|
||||
found = find_by_uuid (self, nm_setting_connection_get_uuid (s_con));
|
||||
found = find_by_uuid (self, nm_connection_get_uuid (NM_CONNECTION (connection)));
|
||||
if (found) {
|
||||
const char *old_path = nm_keyfile_connection_get_path (connection);
|
||||
|
||||
|
Reference in New Issue
Block a user