diff options
| author | Michael Biebl <biebl@debian.org> | 2016-01-20 16:26:51 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2016-01-20 16:26:51 +0100 |
| commit | 494f296a3baab08522617b24b1f126d8f9a17502 (patch) | |
| tree | c8ef32fb0dd1c4ff35a0b38e787abb58692de0cd /src/nm-policy.c | |
| parent | 54f6333410ffd570e62717d9e77c5c987175e397 (diff) | |
Imported Upstream version 1.1.90 upstream/1.1.90
Diffstat (limited to 'src/nm-policy.c')
| -rw-r--r-- | src/nm-policy.c | 213 |
1 files changed, 96 insertions, 117 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c index fc2a9bf7..05f7edf4 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -26,15 +26,13 @@ #include <errno.h> #include <netdb.h> -#include <gio/gio.h> +#include "nm-default.h" #include "nm-policy.h" #include "NetworkManagerUtils.h" #include "nm-activation-request.h" -#include "nm-logging.h" #include "nm-device.h" #include "nm-default-route-manager.h" -#include "nm-dbus-manager.h" #include "nm-setting-ip4-config.h" #include "nm-setting-connection.h" #include "nm-platform.h" @@ -45,7 +43,6 @@ #include "nm-dispatcher.h" #include "nm-utils.h" #include "nm-core-internal.h" -#include "nm-glib-compat.h" #include "nm-manager.h" #include "nm-settings.h" #include "nm-settings-connection.h" @@ -54,6 +51,7 @@ typedef struct { NMManager *manager; + NMFirewallManager *firewall_manager; guint update_state_id; GSList *pending_activation_checks; GSList *manager_ids; @@ -75,7 +73,7 @@ typedef struct { NMDnsManager *dns_manager; gulong config_changed_id; - gint reset_retries_id; /* idle handler for resetting the retries count */ + guint reset_retries_id; /* idle handler for resetting the retries count */ char *orig_hostname; /* hostname at NM start time */ char *cur_hostname; /* hostname we want to assign */ @@ -150,8 +148,12 @@ set_system_hostname (const char *new_hostname, const char *msg) nm_log_info (LOGD_DNS, "Setting system hostname to '%s' (%s)", name, msg); ret = sethostname (name, strlen (name)); if (ret != 0) { + int errsv = errno; + nm_log_warn (LOGD_DNS, "couldn't set the system hostname to '%s': (%d) %s", - name, errno, strerror (errno)); + name, errsv, strerror (errsv)); + if (errsv == EPERM) + nm_log_warn (LOGD_DNS, "You should use hostnamed when systemd hardening is in effect!"); } return (ret == 0); @@ -197,7 +199,7 @@ _set_hostname (NMPolicy *policy, nm_dns_manager_set_hostname (priv->dns_manager, priv->cur_hostname); if (set_system_hostname (priv->cur_hostname, msg)) - nm_dispatcher_call (DISPATCHER_ACTION_HOSTNAME, NULL, NULL, NULL, NULL, NULL); + nm_dispatcher_call (DISPATCHER_ACTION_HOSTNAME, NULL, NULL, NULL, NULL, NULL, NULL); } static void @@ -468,7 +470,7 @@ update_ip4_routing (NMPolicy *policy, gboolean force_update) return; priv->default_device4 = default_device; - connection = nm_active_connection_get_connection (best_ac); + connection = nm_active_connection_get_applied_connection (best_ac); nm_log_info (LOGD_CORE, "Policy set '%s' (%s) as default for IPv4 routing and DNS.", nm_connection_get_id (connection), ip_iface); g_object_notify (G_OBJECT (policy), NM_POLICY_DEFAULT_IP4_DEVICE); @@ -563,7 +565,7 @@ update_ip6_routing (NMPolicy *policy, gboolean force_update) return; priv->default_device6 = default_device6; - connection = nm_active_connection_get_connection (best_ac); + connection = nm_active_connection_get_applied_connection (best_ac); nm_log_info (LOGD_CORE, "Policy set '%s' (%s) as default for IPv6 routing and DNS.", nm_connection_get_id (connection), ip_iface); g_object_notify (G_OBJECT (policy), NM_POLICY_DEFAULT_IP6_DEVICE); @@ -638,7 +640,7 @@ auto_activate_device (gpointer user_data) ActivateData *data = (ActivateData *) user_data; NMPolicy *policy; NMPolicyPrivate *priv; - NMConnection *best_connection; + NMSettingsConnection *best_connection; char *specific_object = NULL; GPtrArray *connections; GSList *connection_list; @@ -676,7 +678,7 @@ auto_activate_device (gpointer user_data) if (!nm_settings_connection_can_autoconnect (candidate)) continue; if (nm_device_can_auto_connect (data->device, (NMConnection *) candidate, &specific_object)) { - best_connection = (NMConnection *) candidate; + best_connection = candidate; break; } } @@ -687,7 +689,7 @@ auto_activate_device (gpointer user_data) NMAuthSubject *subject; nm_log_info (LOGD_DEVICE, "Auto-activating connection '%s'.", - nm_connection_get_id (best_connection)); + nm_settings_connection_get_id (best_connection)); subject = nm_auth_subject_new_internal (); if (!nm_manager_activate_connection (priv->manager, best_connection, @@ -696,7 +698,7 @@ auto_activate_device (gpointer user_data) subject, &error)) { nm_log_info (LOGD_DEVICE, "Connection '%s' auto-activation failed: (%d) %s", - nm_connection_get_id (best_connection), + nm_settings_connection_get_id (best_connection), error ? error->code : -1, error ? error->message : "(none)"); g_error_free (error); @@ -774,8 +776,8 @@ process_secondaries (NMPolicy *policy, if (connected) { nm_log_dbg (LOGD_DEVICE, "Secondary connection '%s' SUCCEEDED; active path '%s'", - nm_active_connection_get_id (active), - nm_active_connection_get_path (active)); + nm_active_connection_get_settings_connection_id (active), + nm_exported_object_get_path (NM_EXPORTED_OBJECT (active))); /* Secondary connection activated */ secondary_data->secondaries = g_slist_remove (secondary_data->secondaries, secondary_active); @@ -790,8 +792,8 @@ process_secondaries (NMPolicy *policy, } } else { nm_log_dbg (LOGD_DEVICE, "Secondary connection '%s' FAILED; active path '%s'", - nm_active_connection_get_id (active), - nm_active_connection_get_path (active)); + nm_active_connection_get_settings_connection_id (active), + nm_exported_object_get_path (NM_EXPORTED_OBJECT (active))); /* Secondary connection failed -> do not watch other connections */ priv->pending_secondaries = g_slist_remove (priv->pending_secondaries, secondary_data); @@ -989,7 +991,7 @@ static void activate_slave_connections (NMPolicy *policy, NMDevice *device) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); - const char *master_device, *master_uuid = NULL; + const char *master_device, *master_uuid_settings = NULL, *master_uuid_applied = NULL; GSList *connections, *iter; NMActRequest *req; @@ -997,8 +999,19 @@ activate_slave_connections (NMPolicy *policy, NMDevice *device) g_assert (master_device); req = nm_device_get_act_request (device); - if (req) - master_uuid = nm_active_connection_get_uuid (NM_ACTIVE_CONNECTION (req)); + if (req) { + NMConnection *con; + + 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; + } + } connections = nm_settings_get_connections (priv->settings); for (iter = connections; iter; iter = g_slist_next (iter)) { @@ -1015,7 +1028,9 @@ activate_slave_connections (NMPolicy *policy, NMDevice *device) if (!slave_master) continue; - if (!g_strcmp0 (slave_master, master_device) || !g_strcmp0 (slave_master, master_uuid)) + if ( !g_strcmp0 (slave_master, master_device) + || !g_strcmp0 (slave_master, master_uuid_applied) + || !g_strcmp0 (slave_master, master_uuid_settings)) nm_settings_connection_reset_autoconnect_retries (NM_SETTINGS_CONNECTION (slave)); } @@ -1055,7 +1070,7 @@ activate_secondary_connections (NMPolicy *policy, } if (!nm_connection_is_type (NM_CONNECTION (settings_con), NM_SETTING_VPN_SETTING_NAME)) { nm_log_warn (LOGD_DEVICE, "Secondary connection '%s (%s)' auto-activation failed: The connection is not a VPN.", - nm_connection_get_id (NM_CONNECTION (settings_con)), sec_uuid); + nm_settings_connection_get_id (settings_con), sec_uuid); success = FALSE; break; } @@ -1064,11 +1079,11 @@ activate_secondary_connections (NMPolicy *policy, g_assert (req); nm_log_dbg (LOGD_DEVICE, "Activating secondary connection '%s (%s)' for base connection '%s (%s)'", - nm_connection_get_id (NM_CONNECTION (settings_con)), 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, - NM_CONNECTION (settings_con), - nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)), + settings_con, + nm_exported_object_get_path (NM_EXPORTED_OBJECT (req)), device, nm_active_connection_get_subject (NM_ACTIVE_CONNECTION (req)), &error); @@ -1076,7 +1091,7 @@ activate_secondary_connections (NMPolicy *policy, secondary_ac_list = g_slist_append (secondary_ac_list, g_object_ref (ac)); else { nm_log_warn (LOGD_DEVICE, "Secondary connection '%s (%s)' auto-activation failed: (%d) %s", - nm_connection_get_id (NM_CONNECTION (settings_con)), sec_uuid, + nm_settings_connection_get_id (settings_con), sec_uuid, error ? error->code : 0, (error && error->message) ? error->message : "unknown"); g_clear_error (&error); @@ -1103,7 +1118,9 @@ device_state_changed (NMDevice *device, { NMPolicy *policy = (NMPolicy *) user_data; NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); - NMSettingsConnection *connection = NM_SETTINGS_CONNECTION (nm_device_get_connection (device)); + + NMSettingsConnection *connection = nm_device_get_settings_connection (device); + const char *ip_iface = nm_device_get_ip_iface (device); NMIP4Config *ip4_config; NMIP6Config *ip6_config; @@ -1121,18 +1138,18 @@ device_state_changed (NMDevice *device, if (reason == NM_DEVICE_STATE_REASON_NO_SECRETS) { nm_log_dbg (LOGD_DEVICE, "Connection '%s' now blocked from autoconnect due to no secrets", - nm_connection_get_id (NM_CONNECTION (connection))); + nm_settings_connection_get_id (connection)); nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_DEVICE_STATE_REASON_NO_SECRETS); } else if (tries > 0) { nm_log_dbg (LOGD_DEVICE, "Connection '%s' failed to autoconnect; %d tries left", - nm_connection_get_id (NM_CONNECTION (connection)), tries); + nm_settings_connection_get_id (connection), tries); nm_settings_connection_set_autoconnect_retries (connection, tries - 1); } if (nm_settings_connection_get_autoconnect_retries (connection) == 0) { nm_log_info (LOGD_DEVICE, "Disabling autoconnect for connection '%s'.", - nm_connection_get_id (NM_CONNECTION (connection))); + nm_settings_connection_get_id (connection)); /* Schedule a handler to reset retries count */ if (!priv->reset_retries_id) { gint32 retry_time = nm_settings_connection_get_autoconnect_retry_time (connection); @@ -1152,6 +1169,7 @@ device_state_changed (NMDevice *device, /* And clear secrets so they will always be requested from the * settings service when the next connection is made. */ + nm_connection_clear_secrets (NM_CONNECTION (connection)); } @@ -1184,7 +1202,7 @@ device_state_changed (NMDevice *device, if (connection) { /* The connection was deactivated, so block just this connection */ nm_log_dbg (LOGD_DEVICE, "Blocking autoconnect of connection '%s' by user request", - nm_connection_get_id (NM_CONNECTION (connection))); + nm_settings_connection_get_id (connection)); nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_DEVICE_STATE_REASON_USER_REQUESTED); } @@ -1352,7 +1370,7 @@ device_added (NMManager *manager, NMDevice *device, gpointer user_data) NMPolicy *policy = (NMPolicy *) user_data; /* Connect state-changed with _after, so that the handler is invoked after other handlers. */ - _connect_device_signal (policy, device, "state-changed", device_state_changed, TRUE); + _connect_device_signal (policy, device, NM_DEVICE_STATE_CHANGED, device_state_changed, TRUE); _connect_device_signal (policy, device, NM_DEVICE_IP4_CONFIG_CHANGED, device_ip4_config_changed, FALSE); _connect_device_signal (policy, device, NM_DEVICE_IP6_CONFIG_CHANGED, device_ip6_config_changed, FALSE); _connect_device_signal (policy, device, "notify::" NM_DEVICE_AUTOCONNECT, device_autoconnect_changed, FALSE); @@ -1465,7 +1483,7 @@ vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *policy) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); NMActiveConnection *ac = NM_ACTIVE_CONNECTION (vpn); - NMConnection *connection = nm_active_connection_get_connection (ac); + NMSettingsConnection *connection = nm_active_connection_get_settings_connection (ac); GError *error = NULL; /* Attempt to reconnect VPN connections that failed after being connected */ @@ -1476,7 +1494,7 @@ vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *policy) nm_active_connection_get_subject (ac), &error)) { nm_log_warn (LOGD_DEVICE, "VPN '%s' reconnect failed: %s", - nm_connection_get_id (connection), + nm_settings_connection_get_id (connection), error->message ? error->message : "unknown"); g_clear_error (&error); } @@ -1557,70 +1575,16 @@ connection_added (NMSettings *settings, } static void -add_or_change_zone_cb (GError *error, gpointer user_data) -{ - NMDevice *device = NM_DEVICE (user_data); - - if (error) { - /* FIXME: what do we do here? */ - } - - g_object_unref (device); -} - -static void -firewall_update_zone (NMPolicy *policy, NMConnection *connection) -{ - NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); - NMSettingConnection *s_con = nm_connection_get_setting_connection (connection); - const GSList *iter; - - /* find dev with passed connection and change zone its interface belongs to */ - for (iter = nm_manager_get_devices (priv->manager); iter; iter = g_slist_next (iter)) { - NMDevice *dev = NM_DEVICE (iter->data); - - if ( (nm_device_get_connection (dev) == connection) - && (nm_device_get_state (dev) == NM_DEVICE_STATE_ACTIVATED) - && !nm_device_uses_assumed_connection (dev)) { - nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (), - nm_device_get_ip_iface (dev), - nm_setting_connection_get_zone (s_con), - FALSE, /* change zone */ - add_or_change_zone_cb, - g_object_ref (dev)); - } - } -} - -static void firewall_started (NMFirewallManager *manager, gpointer user_data) { NMPolicy *policy = (NMPolicy *) user_data; NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); - NMConnection *connection; - NMSettingConnection *s_con; const GSList *iter; /* add interface of each device to correct zone */ - for (iter = nm_manager_get_devices (priv->manager); iter; iter = g_slist_next (iter)) { - NMDevice *dev = NM_DEVICE (iter->data); - - connection = nm_device_get_connection (dev); - if (!connection) - continue; - - s_con = nm_connection_get_setting_connection (connection); - if ( nm_device_get_state (dev) == NM_DEVICE_STATE_ACTIVATED - && !nm_device_uses_assumed_connection (dev)) { - nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (), - nm_device_get_ip_iface (dev), - nm_setting_connection_get_zone (s_con), - FALSE, /* still change zone */ - add_or_change_zone_cb, - g_object_ref (dev)); - } - } + for (iter = nm_manager_get_devices (priv->manager); iter; iter = g_slist_next (iter)) + nm_device_update_firewall_zone (iter->data); } static void @@ -1661,11 +1625,7 @@ connection_updated (NMSettings *settings, NMConnection *connection, gpointer user_data) { - NMPolicy *policy = (NMPolicy *) user_data; - - firewall_update_zone (policy, connection); - - schedule_activate_all (policy); + schedule_activate_all ((NMPolicy *) user_data); } static void @@ -1673,12 +1633,30 @@ connection_updated_by_user (NMSettings *settings, NMSettingsConnection *connection, gpointer user_data) { + NMPolicy *policy = (NMPolicy *) user_data; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); + const GSList *iter; + NMDevice *device = NULL; + + /* find device with given connection */ + for (iter = nm_manager_get_devices (priv->manager); iter; iter = g_slist_next (iter)) { + NMDevice *dev = NM_DEVICE (iter->data); + + if (nm_device_get_settings_connection (dev) == connection) { + device = dev; + break; + } + } + + if (device) + nm_device_reapply_settings_immediately (device); + /* Reset auto retries back to default since connection was updated */ nm_settings_connection_reset_autoconnect_retries (connection); } static void -_deactivate_if_active (NMManager *manager, NMConnection *connection) +_deactivate_if_active (NMManager *manager, NMSettingsConnection *connection) { const GSList *active, *iter; @@ -1688,14 +1666,14 @@ _deactivate_if_active (NMManager *manager, NMConnection *connection) NMActiveConnectionState state = nm_active_connection_get_state (ac); GError *error = NULL; - if (nm_active_connection_get_connection (ac) == connection && + if (nm_active_connection_get_settings_connection (ac) == connection && (state <= NM_ACTIVE_CONNECTION_STATE_ACTIVATED)) { if (!nm_manager_deactivate_connection (manager, - nm_active_connection_get_path (ac), + nm_exported_object_get_path (NM_EXPORTED_OBJECT (ac)), NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, &error)) { nm_log_warn (LOGD_DEVICE, "Connection '%s' disappeared, but error deactivating it: (%d) %s", - nm_connection_get_id (connection), + nm_settings_connection_get_id (connection), error ? error->code : -1, error ? error->message : "(unknown)"); g_clear_error (&error); @@ -1706,7 +1684,7 @@ _deactivate_if_active (NMManager *manager, NMConnection *connection) static void connection_removed (NMSettings *settings, - NMConnection *connection, + NMSettingsConnection *connection, gpointer user_data) { NMPolicy *policy = user_data; @@ -1726,7 +1704,7 @@ connection_visibility_changed (NMSettings *settings, if (nm_settings_connection_is_visible (connection)) schedule_activate_all (policy); else - _deactivate_if_active (priv->manager, NM_CONNECTION (connection)); + _deactivate_if_active (priv->manager, connection); } static void @@ -1748,20 +1726,20 @@ static void _connect_manager_signal (NMPolicy *policy, const char *name, gpointer callback) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); - guint id; + gulong id; id = g_signal_connect (priv->manager, name, callback, policy); - priv->manager_ids = g_slist_prepend (priv->manager_ids, GUINT_TO_POINTER (id)); + priv->manager_ids = g_slist_prepend (priv->manager_ids, (gpointer) id); } static void _connect_settings_signal (NMPolicy *policy, const char *name, gpointer callback) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); - guint id; + gulong id; id = g_signal_connect (priv->settings, name, callback, policy); - priv->settings_ids = g_slist_prepend (priv->settings_ids, GUINT_TO_POINTER (id)); + priv->settings_ids = g_slist_prepend (priv->settings_ids, (gpointer) id); } NMPolicy * @@ -1789,7 +1767,9 @@ nm_policy_new (NMManager *manager, NMSettings *settings) priv->orig_hostname = g_strdup (hostname); } - priv->fw_started_id = g_signal_connect (nm_firewall_manager_get (), "started", + priv->firewall_manager = g_object_ref (nm_firewall_manager_get ()); + + priv->fw_started_id = g_signal_connect (priv->firewall_manager, "started", G_CALLBACK (firewall_started), policy); priv->dns_manager = g_object_ref (nm_dns_manager_get ()); @@ -1799,12 +1779,12 @@ nm_policy_new (NMManager *manager, NMSettings *settings) priv->resolver = g_resolver_get_default (); - _connect_manager_signal (policy, "state-changed", global_state_changed); + _connect_manager_signal (policy, NM_MANAGER_STATE_CHANGED, global_state_changed); _connect_manager_signal (policy, "notify::" NM_MANAGER_HOSTNAME, hostname_changed); _connect_manager_signal (policy, "notify::" NM_MANAGER_SLEEPING, sleeping_changed); _connect_manager_signal (policy, "notify::" NM_MANAGER_NETWORKING_ENABLED, sleeping_changed); - _connect_manager_signal (policy, "device-added", device_added); - _connect_manager_signal (policy, "device-removed", device_removed); + _connect_manager_signal (policy, "internal-device-added", device_added); + _connect_manager_signal (policy, "internal-device-removed", device_removed); _connect_manager_signal (policy, NM_MANAGER_ACTIVE_CONNECTION_ADDED, active_connection_added); _connect_manager_signal (policy, NM_MANAGER_ACTIVE_CONNECTION_REMOVED, active_connection_removed); @@ -1896,9 +1876,11 @@ dispose (GObject *object) g_slist_free_full (priv->pending_secondaries, (GDestroyNotify) pending_secondary_data_free); priv->pending_secondaries = NULL; - if (priv->fw_started_id) { - g_signal_handler_disconnect (nm_firewall_manager_get (), priv->fw_started_id); + if (priv->firewall_manager) { + g_assert (priv->fw_started_id); + g_signal_handler_disconnect (priv->firewall_manager, priv->fw_started_id); priv->fw_started_id = 0; + g_clear_object (&priv->firewall_manager); } if (priv->dns_manager) { @@ -1907,11 +1889,11 @@ dispose (GObject *object) } for (iter = priv->manager_ids; iter; iter = g_slist_next (iter)) - g_signal_handler_disconnect (priv->manager, GPOINTER_TO_UINT (iter->data)); + g_signal_handler_disconnect (priv->manager, (gulong) iter->data); g_clear_pointer (&priv->manager_ids, g_slist_free); for (iter = priv->settings_ids; iter; iter = g_slist_next (iter)) - g_signal_handler_disconnect (priv->settings, GPOINTER_TO_UINT (iter->data)); + g_signal_handler_disconnect (priv->settings, (gulong) iter->data); g_clear_pointer (&priv->settings_ids, g_slist_free); for (iter = priv->dev_ids; iter; iter = g_slist_next (iter)) { @@ -1929,10 +1911,7 @@ dispose (GObject *object) connections = nm_manager_get_active_connections (priv->manager); g_assert (connections == NULL); - if (priv->reset_retries_id) { - g_source_remove (priv->reset_retries_id); - priv->reset_retries_id = 0; - } + nm_clear_g_source (&priv->reset_retries_id); g_clear_pointer (&priv->orig_hostname, g_free); g_clear_pointer (&priv->cur_hostname, g_free); |