diff options
Diffstat (limited to 'src/nm-policy.c')
| -rw-r--r-- | src/nm-policy.c | 417 |
1 files changed, 188 insertions, 229 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c index 7f8c665c..125f2704 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -56,10 +56,10 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMPolicy, PROP_MANAGER, PROP_SETTINGS, - PROP_DEFAULT_IP4_AC, - PROP_DEFAULT_IP6_AC, - PROP_ACTIVATING_IP4_AC, - PROP_ACTIVATING_IP6_AC, + PROP_DEFAULT_IP4_DEVICE, + PROP_DEFAULT_IP6_DEVICE, + PROP_ACTIVATING_IP4_DEVICE, + PROP_ACTIVATING_IP6_DEVICE, ); typedef struct { @@ -79,8 +79,8 @@ typedef struct { NMHostnameManager *hostname_manager; - NMActiveConnection *default_ac4, *activating_ac4; - NMActiveConnection *default_ac6, *activating_ac6; + NMDevice *default_device4, *activating_device4; + NMDevice *default_device6, *activating_device6; struct { GInetAddress *addr; @@ -146,7 +146,6 @@ _PRIV_TO_SELF (NMPolicyPrivate *priv) static void schedule_activate_all (NMPolicy *self); static void schedule_activate_check (NMPolicy *self, NMDevice *device); -static NMDevice *get_default_device (NMPolicy *self, int addr_family); /*****************************************************************************/ @@ -368,56 +367,43 @@ device_ip6_subnet_needed (NMDevice *device, _LOGD (LOGD_IP6, "ipv6-pd: %s needs a subnet", nm_device_get_iface (device)); - if (!priv->default_ac6) { + if (!priv->default_device6) { /* We request the prefixes when the default IPv6 device is set. */ _LOGI (LOGD_IP6, "ipv6-pd: no device to obtain a subnet to share on %s from", nm_device_get_iface (device)); return; } - ip6_subnet_from_device (self, get_default_device (self, AF_INET6), device); - nm_device_copy_ip6_dns_config (device, get_default_device (self, AF_INET6)); + ip6_subnet_from_device (self, priv->default_device6, device); + nm_device_copy_ip6_dns_config (device, priv->default_device6); } /*****************************************************************************/ static NMDevice * -get_default_device (NMPolicy *self, int addr_family) -{ - NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - NMActiveConnection *ac; - - nm_assert_addr_family (addr_family); - - ac = (addr_family == AF_INET) ? priv->default_ac4 : priv->default_ac6; - - return ac ? nm_active_connection_get_device (ac) : NULL; -} - -static NMActiveConnection * -get_best_active_connection (NMPolicy *self, - int addr_family, - gboolean fully_activated) +get_best_ip_device (NMPolicy *self, + int addr_family, + gboolean fully_activated) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); const CList *tmp_lst; NMDevice *device; + NMDevice *best_device; + NMDevice *prev_device; guint32 best_metric = G_MAXUINT32; gboolean best_is_fully_activated = FALSE; - NMActiveConnection *best_ac, *prev_ac; nm_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6)); - /* we prefer the current AC in case of identical metric. - * Hence, try that one first. */ - prev_ac = addr_family == AF_INET - ? (fully_activated ? priv->default_ac4 : priv->activating_ac4) - : (fully_activated ? priv->default_ac6 : priv->activating_ac6); - best_ac = NULL; + /* we prefer the current device in case of identical metric. + * Hence, try that one first.*/ + best_device = NULL; + prev_device = addr_family == AF_INET + ? (fully_activated ? priv->default_device4 : priv->activating_device4) + : (fully_activated ? priv->default_device6 : priv->activating_device6); nm_manager_for_each_device (priv->manager, device, tmp_lst) { NMDeviceState state; const NMPObject *r; - NMActiveConnection *ac; NMConnection *connection; guint32 metric; gboolean is_fully_activated; @@ -449,29 +435,26 @@ get_best_active_connection (NMPolicy *self, } else continue; - ac = (NMActiveConnection *) nm_device_get_act_request (device); - nm_assert (ac); - - if ( !best_ac + if ( !best_device || (!best_is_fully_activated && is_fully_activated) || ( metric < best_metric - || (metric == best_metric && ac == prev_ac))) { - best_ac = ac; + || (metric == best_metric && device == prev_device))) { + best_device = device; best_metric = metric; best_is_fully_activated = is_fully_activated; } } if ( !fully_activated - && best_ac + && best_device && best_is_fully_activated) { - /* There's a best activating AC only if the best device + /* There's only a best activating device if the best device * among all activating and already-activated devices is a * still-activating one. */ return NULL; } - return best_ac; + return best_device; } static gboolean @@ -685,7 +668,6 @@ update_system_hostname (NMPolicy *self, const char *msg) gboolean external_hostname = FALSE; const NMPlatformIP4Address *addr4; const NMPlatformIP6Address *addr6; - NMDevice *device; g_return_if_fail (self != NULL); @@ -738,11 +720,11 @@ update_system_hostname (NMPolicy *self, const char *msg) return; } - if (priv->default_ac4) { + if (priv->default_device4) { NMDhcp4Config *dhcp4_config; /* Grab a hostname out of the device's DHCP4 config */ - dhcp4_config = nm_device_get_dhcp4_config (get_default_device (self, AF_INET)); + dhcp4_config = nm_device_get_dhcp4_config (priv->default_device4); if (dhcp4_config) { dhcp_hostname = nm_dhcp4_config_get_option (dhcp4_config, "host_name"); if (dhcp_hostname && dhcp_hostname[0]) { @@ -758,11 +740,11 @@ update_system_hostname (NMPolicy *self, const char *msg) } } - if (priv->default_ac6) { + if (priv->default_device6) { NMDhcp6Config *dhcp6_config; /* Grab a hostname out of the device's DHCP6 config */ - dhcp6_config = nm_device_get_dhcp6_config (get_default_device (self, AF_INET6)); + dhcp6_config = nm_device_get_dhcp6_config (priv->default_device6); if (dhcp6_config) { dhcp_hostname = nm_dhcp6_config_get_option (dhcp6_config, "host_name"); if (dhcp_hostname && dhcp_hostname[0]) { @@ -797,7 +779,7 @@ update_system_hostname (NMPolicy *self, const char *msg) priv->dhcp_hostname = FALSE; - if (!priv->default_ac4 && !priv->default_ac6) { + if (!priv->default_device4 && !priv->default_device6) { /* No best device; fall back to the last hostname set externally * to NM or if there wasn't one, 'localhost.localdomain' */ @@ -816,11 +798,8 @@ update_system_hostname (NMPolicy *self, const char *msg) /* No configured hostname, no automatically determined hostname, and no * bootup hostname. Start reverse DNS of the current IPv4 or IPv6 address. */ - device = get_default_device (self, AF_INET); - ip4_config = device ? nm_device_get_ip4_config (device) : NULL; - - device = get_default_device (self, AF_INET6); - ip6_config = device ? nm_device_get_ip6_config (device) : NULL; + ip4_config = priv->default_device4 ? nm_device_get_ip4_config (priv->default_device4) : NULL; + ip6_config = priv->default_device6 ? nm_device_get_ip6_config (priv->default_device6) : NULL; if ( ip4_config && (addr4 = nm_ip4_config_get_first_address (ip4_config))) { @@ -873,19 +852,16 @@ get_best_ip_config (NMPolicy *self, NMVpnConnection **out_vpn) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - gpointer conf, best_conf = NULL; + NMDevice *device; + gpointer conf; const CList *tmp_list; NMActiveConnection *ac; - guint64 best_metric = G_MAXUINT64; - NMVpnConnection *best_vpn = NULL; nm_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6)); nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) { NMVpnConnection *candidate; NMVpnConnectionState vpn_state; - const NMPObject *obj; - guint32 metric; if (!NM_IS_VPN_CONNECTION (ac)) continue; @@ -903,45 +879,40 @@ get_best_ip_config (NMPolicy *self, if (!conf) continue; - if (addr_family == AF_INET) - obj = nm_ip4_config_best_default_route_get (conf); - else - obj = nm_ip6_config_best_default_route_get (conf); - if (!obj) - continue; - - metric = NMP_OBJECT_CAST_IPX_ROUTE (obj)->rx.metric; - if (metric <= best_metric) { - best_metric = metric; - best_conf = conf; - best_vpn = candidate; + if (addr_family == AF_INET) { + if (!nm_ip4_config_best_default_route_get (conf)) + continue; + } else { + if (!nm_ip6_config_best_default_route_get (conf)) + continue; } - } - if (best_metric != G_MAXUINT64) { + /* FIXME: in case of multiple VPN candidates, choose the one with the + * best metric. */ NM_SET_OUT (out_device, NULL); - NM_SET_OUT (out_vpn, best_vpn); - NM_SET_OUT (out_ac, NM_ACTIVE_CONNECTION (best_vpn)); - NM_SET_OUT (out_ip_iface, nm_vpn_connection_get_ip_iface (best_vpn, TRUE)); - return best_conf; + NM_SET_OUT (out_vpn, candidate); + NM_SET_OUT (out_ac, ac); + NM_SET_OUT (out_ip_iface, nm_vpn_connection_get_ip_iface (candidate, TRUE)); + return conf; } - ac = get_best_active_connection (self, addr_family, TRUE); - if (ac) { - NMDevice *device = nm_active_connection_get_device (ac); - - nm_assert (device); + device = get_best_ip_device (self, addr_family, TRUE); + if (device) { + NMActRequest *req; if (addr_family == AF_INET) conf = nm_device_get_ip4_config (device); else conf = nm_device_get_ip6_config (device); + req = nm_device_get_act_request (device); - NM_SET_OUT (out_device, device); - NM_SET_OUT (out_vpn, NULL); - NM_SET_OUT (out_ac, ac); - NM_SET_OUT (out_ip_iface, nm_device_get_ip_iface (device)); - return conf; + if (conf && req) { + NM_SET_OUT (out_device, device); + NM_SET_OUT (out_vpn, NULL); + NM_SET_OUT (out_ac, NM_ACTIVE_CONNECTION (req)); + NM_SET_OUT (out_ip_iface, nm_device_get_ip_iface (device)); + return conf; + } } NM_SET_OUT (out_device, NULL); @@ -966,17 +937,17 @@ update_ip4_routing (NMPolicy *self, gboolean force_update) * so we can get (vpn != NULL && best == NULL). */ if (!get_best_ip_config (self, AF_INET, &ip_iface, &best_ac, &best, &vpn)) { - if (nm_clear_g_object (&priv->default_ac4)) { - _LOGt (LOGD_DNS, "set-default-ac-4: %p", NULL); - _notify (self, PROP_DEFAULT_IP4_AC); + if (nm_clear_g_object (&priv->default_device4)) { + _LOGt (LOGD_DNS, "set-default-device-4: %p", NULL); + _notify (self, PROP_DEFAULT_IP4_DEVICE); } return; } g_assert ((best || vpn) && best_ac); if ( !force_update - && best_ac - && best_ac == priv->default_ac4) + && best + && best == priv->default_device4) return; if (best) { @@ -988,16 +959,19 @@ update_ip4_routing (NMPolicy *self, gboolean force_update) } } + if (vpn) + best = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn)); + update_default_ac (self, AF_INET, best_ac); - if (!nm_g_object_ref_set (&priv->default_ac4, best_ac)) + if (!nm_g_object_ref_set (&priv->default_device4, best)) return; - _LOGt (LOGD_DNS, "set-default-ac-4: %p", priv->default_ac4); + _LOGt (LOGD_DNS, "set-default-device-4: %p", priv->default_device4); _LOGI (LOGD_CORE, "set '%s' (%s) as default for IPv4 routing and DNS", nm_connection_get_id (nm_active_connection_get_applied_connection (best_ac)), ip_iface); - _notify (self, PROP_DEFAULT_IP4_AC); + _notify (self, PROP_DEFAULT_IP4_DEVICE); } static void @@ -1011,7 +985,7 @@ update_ip6_dns_delegation (NMPolicy *self) nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) { device = nm_active_connection_get_device (ac); if (device && nm_device_needs_ip6_subnet (device)) - nm_device_copy_ip6_dns_config (device, get_default_device (self, AF_INET6)); + nm_device_copy_ip6_dns_config (device, priv->default_device6); } } @@ -1027,7 +1001,7 @@ update_ip6_prefix_delegation (NMPolicy *self) nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) { device = nm_active_connection_get_device (ac); if (device && nm_device_needs_ip6_subnet (device)) - ip6_subnet_from_device (self, get_default_device (self, AF_INET6), device); + ip6_subnet_from_device (self, priv->default_device6, device); } } @@ -1046,17 +1020,17 @@ update_ip6_routing (NMPolicy *self, gboolean force_update) * so we can get (vpn != NULL && best == NULL). */ if (!get_best_ip_config (self, AF_INET6, &ip_iface, &best_ac, &best, &vpn)) { - if (nm_clear_g_object (&priv->default_ac6)) { - _LOGt (LOGD_DNS, "set-default-ac-6: %p", NULL); - _notify (self, PROP_DEFAULT_IP6_AC); + if (nm_clear_g_object (&priv->default_device6)) { + _LOGt (LOGD_DNS, "set-default-device-6: %p", NULL); + _notify (self, PROP_DEFAULT_IP6_DEVICE); } return; } g_assert ((best || vpn) && best_ac); if ( !force_update - && best_ac - && best_ac == priv->default_ac6) + && best + && best == priv->default_device6) return; if (best) { @@ -1068,18 +1042,21 @@ update_ip6_routing (NMPolicy *self, gboolean force_update) } } + if (vpn) + best = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn)); + update_default_ac (self, AF_INET6, best_ac); - if (!nm_g_object_ref_set (&priv->default_ac6, best_ac)) + if (!nm_g_object_ref_set (&priv->default_device6, best)) return; - _LOGt (LOGD_DNS, "set-default-ac-6: %p", priv->default_ac6); + _LOGt (LOGD_DNS, "set-default-device-6: %p", priv->default_device6); update_ip6_prefix_delegation (self); _LOGI (LOGD_CORE, "set '%s' (%s) as default for IPv6 routing and DNS", nm_connection_get_id (nm_active_connection_get_applied_connection (best_ac)), ip_iface); - _notify (self, PROP_DEFAULT_IP6_AC); + _notify (self, PROP_DEFAULT_IP6_DEVICE); } static void @@ -1127,23 +1104,23 @@ update_routing_and_dns (NMPolicy *self, gboolean force_update) } static void -check_activating_active_connections (NMPolicy *self) +check_activating_devices (NMPolicy *self) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - NMActiveConnection *best4, *best6 = NULL; + NMDevice *best4, *best6 = NULL; - best4 = get_best_active_connection (self, AF_INET, FALSE); - best6 = get_best_active_connection (self, AF_INET6, FALSE); + best4 = get_best_ip_device (self, AF_INET, FALSE); + best6 = get_best_ip_device (self, AF_INET6, FALSE); g_object_freeze_notify (G_OBJECT (self)); - if (nm_g_object_ref_set (&priv->activating_ac4, best4)) { - _LOGt (LOGD_DNS, "set-activating-ac-4: %p", priv->activating_ac4); - _notify (self, PROP_ACTIVATING_IP4_AC); + if (nm_g_object_ref_set (&priv->activating_device4, best4)) { + _LOGt (LOGD_DNS, "set-activating-device-4: %p", priv->activating_device4); + _notify (self, PROP_ACTIVATING_IP4_DEVICE); } - if (nm_g_object_ref_set (&priv->activating_ac6, best6)) { - _LOGt (LOGD_DNS, "set-activating-ac-6: %p", priv->activating_ac6); - _notify (self, PROP_ACTIVATING_IP6_AC); + if (nm_g_object_ref_set (&priv->activating_device6, best6)) { + _LOGt (LOGD_DNS, "set-activating-device-6: %p", priv->activating_device6); + _notify (self, PROP_ACTIVATING_IP6_DEVICE); } g_object_thaw_notify (G_OBJECT (self)); @@ -1235,33 +1212,30 @@ auto_activate_device (NMPolicy *self, if (!nm_device_autoconnect_allowed (device)) return; - connections = nm_manager_get_activatable_connections (priv->manager, TRUE, TRUE, &len); + connections = nm_manager_get_activatable_connections (priv->manager, &len, TRUE); if (!connections[0]) return; /* Find the first connection that should be auto-activated */ best_connection = NULL; for (i = 0; i < len; i++) { - NMSettingsConnection *candidate = connections[i]; - NMConnection *cand_conn; + NMSettingsConnection *candidate = NM_SETTINGS_CONNECTION (connections[i]); NMSettingConnection *s_con; const char *permission; if (nm_settings_connection_autoconnect_is_blocked (candidate)) continue; - cand_conn = nm_settings_connection_get_connection (candidate); - - s_con = nm_connection_get_setting_connection (cand_conn); + s_con = nm_connection_get_setting_connection (NM_CONNECTION (candidate)); if (!nm_setting_connection_get_autoconnect (s_con)) continue; - permission = nm_utils_get_shared_wifi_permission (cand_conn); + permission = nm_utils_get_shared_wifi_permission (NM_CONNECTION (candidate)); if ( permission && !nm_settings_connection_check_permission (candidate, permission)) continue; - if (nm_device_can_auto_connect (device, candidate, &specific_object)) { + if (nm_device_can_auto_connect (device, (NMConnection *) candidate, &specific_object)) { best_connection = candidate; break; } @@ -1444,36 +1418,34 @@ reset_autoconnect_all (NMPolicy *self, connections = nm_settings_get_connections (priv->settings, NULL); for (i = 0; connections[i]; i++) { - NMSettingsConnection *sett_conn = connections[i]; + NMSettingsConnection *connection = connections[i]; if ( device - && !nm_device_check_connection_compatible (device, - nm_settings_connection_get_connection (sett_conn), - NULL)) + && !nm_device_check_connection_compatible (device, NM_CONNECTION (connection))) continue; if (only_no_secrets) { /* we only reset the no-secrets blocked flag. */ - if (nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, + if (nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS, FALSE)) { /* maybe the connection is still blocked afterwards for other reasons * and in the larger picture nothing changed. But it's too complicated * to find out exactly. Just assume, something changed to be sure. */ - if (!nm_settings_connection_autoconnect_is_blocked (sett_conn)) + if (!nm_settings_connection_autoconnect_is_blocked (connection)) changed = TRUE; } } else { /* we reset the tries-count and any blocked-reason */ - if (nm_settings_connection_autoconnect_retries_get (sett_conn) == 0) + if (nm_settings_connection_autoconnect_retries_get (connection) == 0) changed = TRUE; - nm_settings_connection_autoconnect_retries_reset (sett_conn); + nm_settings_connection_autoconnect_retries_reset (connection); - if (nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, + if (nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL & ~NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST, FALSE)) { - if (!nm_settings_connection_autoconnect_is_blocked (sett_conn)) + if (!nm_settings_connection_autoconnect_is_blocked (connection)) changed = TRUE; } } @@ -1594,9 +1566,7 @@ static void activate_slave_connections (NMPolicy *self, NMDevice *device) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - const char *master_device; - const char *master_uuid_settings = NULL; - const char *master_uuid_applied = NULL; + const char *master_device, *master_uuid_settings = NULL, *master_uuid_applied = NULL; guint i; NMActRequest *req; gboolean internal_activation = FALSE; @@ -1608,18 +1578,16 @@ activate_slave_connections (NMPolicy *self, NMDevice *device) req = nm_device_get_act_request (device); if (req) { - NMConnection *connection; - NMSettingsConnection *sett_conn; + NMConnection *con; NMAuthSubject *subject; - connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (req)); - if (connection) - master_uuid_applied = nm_connection_get_uuid (connection); - - sett_conn = nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (req)); - if (sett_conn) { - master_uuid_settings = nm_settings_connection_get_uuid (sett_conn); - if (nm_streq0 (master_uuid_settings, master_uuid_applied)) + con = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (req)); + if (con) + master_uuid_applied = nm_connection_get_uuid (con); + con = NM_CONNECTION (nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (req))); + if (con) { + master_uuid_settings = nm_connection_get_uuid (con); + if (!g_strcmp0 (master_uuid_settings, master_uuid_applied)) master_uuid_settings = NULL; } @@ -1630,11 +1598,11 @@ activate_slave_connections (NMPolicy *self, NMDevice *device) changed = FALSE; connections = nm_settings_get_connections (priv->settings, NULL); for (i = 0; connections[i]; i++) { - NMSettingsConnection *sett_conn = connections[i]; + NMSettingsConnection *connection = connections[i]; NMSettingConnection *s_slave_con; const char *slave_master; - s_slave_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (sett_conn)); + s_slave_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); slave_master = nm_setting_connection_get_master (s_slave_con); if (!slave_master) continue; @@ -1644,14 +1612,14 @@ activate_slave_connections (NMPolicy *self, NMDevice *device) continue; if (!internal_activation) { - if (nm_settings_connection_autoconnect_retries_get (sett_conn) == 0) + if (nm_settings_connection_autoconnect_retries_get (connection) == 0) changed = TRUE; - nm_settings_connection_autoconnect_retries_reset (sett_conn); + nm_settings_connection_autoconnect_retries_reset (connection); } - if (nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, + if (nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED, FALSE)) { - if (!nm_settings_connection_autoconnect_is_blocked (sett_conn)) + if (!nm_settings_connection_autoconnect_is_blocked (connection)) changed = TRUE; } } @@ -1667,6 +1635,7 @@ activate_secondary_connections (NMPolicy *self, { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); NMSettingConnection *s_con; + NMSettingsConnection *settings_con; NMActiveConnection *ac; PendingSecondaryData *secondary_data; GSList *secondary_ac_list = NULL; @@ -1675,25 +1644,22 @@ activate_secondary_connections (NMPolicy *self, gboolean success = TRUE; s_con = nm_connection_get_setting_connection (connection); - nm_assert (s_con); + g_assert (s_con); for (i = 0; i < nm_setting_connection_get_num_secondaries (s_con); i++) { - NMSettingsConnection *sett_conn; const char *sec_uuid = nm_setting_connection_get_secondary (s_con, i); NMActRequest *req; - sett_conn = nm_settings_get_connection_by_uuid (priv->settings, sec_uuid); - if (!sett_conn) { + settings_con = nm_settings_get_connection_by_uuid (priv->settings, sec_uuid); + if (!settings_con) { _LOGW (LOGD_DEVICE, "secondary connection '%s' auto-activation failed: The connection doesn't exist.", sec_uuid); success = FALSE; break; } - - if (!nm_connection_is_type (nm_settings_connection_get_connection (sett_conn), - NM_SETTING_VPN_SETTING_NAME)) { + if (!nm_connection_is_type (NM_CONNECTION (settings_con), NM_SETTING_VPN_SETTING_NAME)) { _LOGW (LOGD_DEVICE, "secondary connection '%s (%s)' auto-activation failed: The connection is not a VPN.", - nm_settings_connection_get_id (sett_conn), sec_uuid); + nm_settings_connection_get_id (settings_con), sec_uuid); success = FALSE; break; } @@ -1702,10 +1668,10 @@ activate_secondary_connections (NMPolicy *self, g_assert (req); _LOGD (LOGD_DEVICE, "activating secondary connection '%s (%s)' for base connection '%s (%s)'", - nm_settings_connection_get_id (sett_conn), sec_uuid, + nm_settings_connection_get_id (settings_con), sec_uuid, nm_connection_get_id (connection), nm_connection_get_uuid (connection)); ac = nm_manager_activate_connection (priv->manager, - sett_conn, + settings_con, NULL, nm_dbus_object_get_path (NM_DBUS_OBJECT (req)), device, @@ -1717,7 +1683,7 @@ activate_secondary_connections (NMPolicy *self, secondary_ac_list = g_slist_append (secondary_ac_list, g_object_ref (ac)); else { _LOGW (LOGD_DEVICE, "secondary connection '%s (%s)' auto-activation failed: (%d) %s", - nm_settings_connection_get_id (sett_conn), sec_uuid, + nm_settings_connection_get_id (settings_con), sec_uuid, error->code, error->message); g_clear_error (&error); @@ -1745,7 +1711,7 @@ device_state_changed (NMDevice *device, NMPolicyPrivate *priv = user_data; NMPolicy *self = _PRIV_TO_SELF (priv); NMActiveConnection *ac; - NMSettingsConnection *sett_conn = nm_device_get_settings_connection (device); + NMSettingsConnection *connection = nm_device_get_settings_connection (device); NMIP4Config *ip4_config; NMIP6Config *ip6_config; NMSettingConnection *s_con = NULL; @@ -1763,8 +1729,8 @@ device_state_changed (NMDevice *device, /* Block autoconnect of the just-failed connection for situations * where a retry attempt would just fail again. */ - if (sett_conn) { - nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, + if (connection) { + nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED, TRUE); } @@ -1778,7 +1744,7 @@ device_state_changed (NMDevice *device, /* Mark the connection invalid if it failed during activation so that * it doesn't get automatically chosen over and over and over again. */ - if ( sett_conn + if ( connection && old_state >= NM_DEVICE_STATE_PREPARE && old_state <= NM_DEVICE_STATE_ACTIVATED) { gboolean block_no_secrets = FALSE; @@ -1799,7 +1765,7 @@ device_state_changed (NMDevice *device, * That can happen when nm_settings_connection_get_secrets() fails early without actually * consulting any agents. */ - con_v = nm_settings_connection_get_last_secret_agent_version_id (sett_conn); + con_v = nm_settings_connection_get_last_secret_agent_version_id (connection); if ( con_v == 0 || con_v == nm_agent_manager_get_agent_version_id (priv->agent_mgr)) block_no_secrets = TRUE; @@ -1807,35 +1773,33 @@ device_state_changed (NMDevice *device, if (block_no_secrets) { _LOGD (LOGD_DEVICE, "connection '%s' now blocked from autoconnect due to no secrets", - nm_settings_connection_get_id (sett_conn)); - nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS, TRUE); + nm_settings_connection_get_id (connection)); + nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS, TRUE); } else { - tries = nm_settings_connection_autoconnect_retries_get (sett_conn); + tries = nm_settings_connection_autoconnect_retries_get (connection); if (tries > 0) { _LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left", - nm_settings_connection_get_id (sett_conn), tries - 1); - _connection_autoconnect_retries_set (self, sett_conn, tries - 1); + nm_settings_connection_get_id (connection), tries - 1); + _connection_autoconnect_retries_set (self, connection, tries - 1); } else if (tries != 0) { _LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; infinite tries left", - nm_settings_connection_get_id (sett_conn)); + nm_settings_connection_get_id (connection)); } } - /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */ - nm_connection_clear_secrets (nm_settings_connection_get_connection (sett_conn)); + nm_connection_clear_secrets (NM_CONNECTION (connection)); } break; case NM_DEVICE_STATE_ACTIVATED: - if (sett_conn) { + if (connection) { /* Reset auto retries back to default since connection was successful */ - nm_settings_connection_autoconnect_retries_reset (sett_conn); + nm_settings_connection_autoconnect_retries_reset (connection); /* And clear secrets so they will always be requested from the * settings service when the next connection is made. */ - /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */ - nm_connection_clear_secrets (nm_settings_connection_get_connection (sett_conn)); + nm_connection_clear_secrets (NM_CONNECTION (connection)); } /* Add device's new IPv4 and IPv6 configs to DNS */ @@ -1859,7 +1823,7 @@ device_state_changed (NMDevice *device, update_routing_and_dns (self, FALSE); break; case NM_DEVICE_STATE_DEACTIVATING: - if (sett_conn) { + if (connection) { NMSettingsAutoconnectBlockedReason blocked_reason = NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE; switch (nm_device_state_reason_check (reason)) { @@ -1874,10 +1838,10 @@ device_state_changed (NMDevice *device, } if (blocked_reason != NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE) { _LOGD (LOGD_DEVICE, "blocking autoconnect of connection '%s': %s", - nm_settings_connection_get_id (sett_conn), + nm_settings_connection_get_id (connection), NM_UTILS_LOOKUP_STR (nm_device_state_reason_to_str, nm_device_state_reason_check (reason))); - nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, blocked_reason, TRUE); + nm_settings_connection_autoconnect_blocked_reason_set (connection, blocked_reason, TRUE); } } ip6_remove_device_prefix_delegations (self, device); @@ -1913,25 +1877,20 @@ device_state_changed (NMDevice *device, break; case NM_DEVICE_STATE_IP_CONFIG: /* We must have secrets if we got here. */ - if (sett_conn) - nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL, FALSE); + if (connection) + nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL, FALSE); break; case NM_DEVICE_STATE_SECONDARIES: - if (sett_conn) - s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (sett_conn)); - if ( s_con - && nm_setting_connection_get_num_secondaries (s_con) > 0) { + if (connection) + s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); + if (s_con && nm_setting_connection_get_num_secondaries (s_con) > 0) { /* Make routes and DNS up-to-date before activating dependent connections */ update_routing_and_dns (self, FALSE); /* Activate secondary (VPN) connections */ - if (!activate_secondary_connections (self, - nm_settings_connection_get_connection (sett_conn), - device)) { - nm_device_queue_state (device, - NM_DEVICE_STATE_FAILED, + if (!activate_secondary_connections (self, NM_CONNECTION (connection), device)) + nm_device_queue_state (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED); - } } else nm_device_queue_state (device, NM_DEVICE_STATE_ACTIVATED, NM_DEVICE_STATE_REASON_NONE); @@ -1941,7 +1900,7 @@ device_state_changed (NMDevice *device, break; } - check_activating_active_connections (self); + check_activating_devices (self); } static void @@ -2423,28 +2382,28 @@ secret_agent_registered (NMSettings *settings, schedule_activate_all (self); } -NMActiveConnection * -nm_policy_get_default_ip4_ac (NMPolicy *self) +NMDevice * +nm_policy_get_default_ip4_device (NMPolicy *self) { - return NM_POLICY_GET_PRIVATE (self)->default_ac4; + return NM_POLICY_GET_PRIVATE (self)->default_device4; } -NMActiveConnection * -nm_policy_get_default_ip6_ac (NMPolicy *self) +NMDevice * +nm_policy_get_default_ip6_device (NMPolicy *self) { - return NM_POLICY_GET_PRIVATE (self)->default_ac6; + return NM_POLICY_GET_PRIVATE (self)->default_device6; } -NMActiveConnection * -nm_policy_get_activating_ip4_ac (NMPolicy *self) +NMDevice * +nm_policy_get_activating_ip4_device (NMPolicy *self) { - return NM_POLICY_GET_PRIVATE (self)->activating_ac4; + return NM_POLICY_GET_PRIVATE (self)->activating_device4; } -NMActiveConnection * -nm_policy_get_activating_ip6_ac (NMPolicy *self) +NMDevice * +nm_policy_get_activating_ip6_device (NMPolicy *self) { - return NM_POLICY_GET_PRIVATE (self)->activating_ac6; + return NM_POLICY_GET_PRIVATE (self)->activating_device6; } /*****************************************************************************/ @@ -2466,17 +2425,17 @@ get_property (GObject *object, guint prop_id, NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); switch (prop_id) { - case PROP_DEFAULT_IP4_AC: - g_value_set_object (value, priv->default_ac4); + case PROP_DEFAULT_IP4_DEVICE: + g_value_set_object (value, priv->default_device4); break; - case PROP_DEFAULT_IP6_AC: - g_value_set_object (value, priv->default_ac6); + case PROP_DEFAULT_IP6_DEVICE: + g_value_set_object (value, priv->default_device6); break; - case PROP_ACTIVATING_IP4_AC: - g_value_set_object (value, priv->activating_ac4); + case PROP_ACTIVATING_IP4_DEVICE: + g_value_set_object (value, priv->activating_device4); break; - case PROP_ACTIVATING_IP6_AC: - g_value_set_object (value, priv->activating_ac6); + case PROP_ACTIVATING_IP6_DEVICE: + g_value_set_object (value, priv->activating_device6); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -2617,10 +2576,10 @@ dispose (GObject *object) g_clear_object (&priv->lookup.addr); g_clear_object (&priv->lookup.resolver); - nm_clear_g_object (&priv->default_ac4); - nm_clear_g_object (&priv->default_ac6); - nm_clear_g_object (&priv->activating_ac4); - nm_clear_g_object (&priv->activating_ac6); + nm_clear_g_object (&priv->default_device4); + nm_clear_g_object (&priv->default_device6); + nm_clear_g_object (&priv->activating_device4); + nm_clear_g_object (&priv->activating_device6); g_clear_pointer (&priv->pending_active_connections, g_hash_table_unref); c_list_for_each_entry_safe (data, data_safe, &priv->pending_activation_checks, pending_lst) @@ -2726,23 +2685,23 @@ nm_policy_class_init (NMPolicyClass *policy_class) G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_DEFAULT_IP4_AC] = - g_param_spec_object (NM_POLICY_DEFAULT_IP4_AC, "", "", - NM_TYPE_ACTIVE_CONNECTION, + obj_properties[PROP_DEFAULT_IP4_DEVICE] = + g_param_spec_object (NM_POLICY_DEFAULT_IP4_DEVICE, "", "", + NM_TYPE_DEVICE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_DEFAULT_IP6_AC] = - g_param_spec_object (NM_POLICY_DEFAULT_IP6_AC, "", "", + obj_properties[PROP_DEFAULT_IP6_DEVICE] = + g_param_spec_object (NM_POLICY_DEFAULT_IP6_DEVICE, "", "", NM_TYPE_DEVICE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ACTIVATING_IP4_AC] = - g_param_spec_object (NM_POLICY_ACTIVATING_IP4_AC, "", "", + obj_properties[PROP_ACTIVATING_IP4_DEVICE] = + g_param_spec_object (NM_POLICY_ACTIVATING_IP4_DEVICE, "", "", NM_TYPE_DEVICE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_ACTIVATING_IP6_AC] = - g_param_spec_object (NM_POLICY_ACTIVATING_IP6_AC, "", "", + obj_properties[PROP_ACTIVATING_IP6_DEVICE] = + g_param_spec_object (NM_POLICY_ACTIVATING_IP6_DEVICE, "", "", NM_TYPE_DEVICE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); |