about summary refs log tree commit diff
path: root/src/nm-policy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nm-policy.c')
-rw-r--r--src/nm-policy.c820
1 files changed, 442 insertions, 378 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 68e50a1c..a46b35a2 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -47,10 +47,18 @@
 #include "nm-dhcp4-config.h"
 #include "nm-dhcp6-config.h"
 
+#define _NMLOG_PREFIX_NAME    "policy"
+#define _NMLOG(level, domain, ...) \
+    G_STMT_START { \
+        nm_log ((level), (domain), \
+                "%s" _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
+                _NMLOG_PREFIX_NAME": " \
+                _NM_UTILS_MACRO_REST (__VA_ARGS__)); \
+    } G_STMT_END
+
 typedef struct {
 	NMManager *manager;
 	NMFirewallManager *firewall_manager;
-	guint update_state_id;
 	GSList *pending_activation_checks;
 	GSList *manager_ids;
 	GSList *settings_ids;
@@ -82,16 +90,16 @@ typedef struct {
 
 G_DEFINE_TYPE (NMPolicy, nm_policy, G_TYPE_OBJECT)
 
-enum {
-	PROP_0,
-
+NM_GOBJECT_PROPERTIES_DEFINE (NMPolicy,
+	PROP_MANAGER,
+	PROP_SETTINGS,
 	PROP_DEFAULT_IP4_DEVICE,
 	PROP_DEFAULT_IP6_DEVICE,
 	PROP_ACTIVATING_IP4_DEVICE,
-	PROP_ACTIVATING_IP6_DEVICE
-};
+	PROP_ACTIVATING_IP6_DEVICE,
+);
 
-static void schedule_activate_all (NMPolicy *policy);
+static void schedule_activate_all (NMPolicy *self);
 
 
 static NMDevice *
@@ -118,51 +126,38 @@ get_best_ip6_device (NMPolicy *self, gboolean fully_activated)
 
 #define FALLBACK_HOSTNAME4 "localhost.localdomain"
 
-static gboolean
-set_system_hostname (const char *new_hostname, const char *msg)
+static void
+settings_set_hostname_cb (const char *hostname,
+                          gboolean result,
+                          gpointer user_data)
 {
-	char old_hostname[HOST_NAME_MAX + 1];
-	const char *name;
-	int ret;
+	int ret = 0;
 
-	if (new_hostname)
-		g_warn_if_fail (strlen (new_hostname));
+	if (!result) {
+		ret = sethostname (hostname, strlen (hostname));
+		if (ret != 0) {
+			int errsv = errno;
 
-	old_hostname[HOST_NAME_MAX] = '\0';
-	errno = 0;
-	ret = gethostname (old_hostname, HOST_NAME_MAX);
-	if (ret != 0) {
-		nm_log_warn (LOGD_DNS, "couldn't get the system hostname: (%d) %s",
-		             errno, strerror (errno));
-	} else {
-		/* Don't set the hostname if it isn't actually changing */
-		if (   (new_hostname && !strcmp (old_hostname, new_hostname))
-		       || (!new_hostname && !strcmp (old_hostname, FALLBACK_HOSTNAME4)))
-			return FALSE;
-	}
-
-	name = (new_hostname && strlen (new_hostname)) ? new_hostname : FALLBACK_HOSTNAME4;
-
-	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, errsv, strerror (errsv));
-		if (errsv == EPERM)
-			nm_log_warn (LOGD_DNS, "You should use hostnamed when systemd hardening is in effect!");
+			_LOGW (LOGD_DNS, "couldn't set the system hostname to '%s': (%d) %s",
+			       hostname, errsv, strerror (errsv));
+			if (errsv == EPERM)
+				_LOGW (LOGD_DNS, "you should use hostnamed when systemd hardening is in effect!");
+		}
 	}
 
-	return (ret == 0);
+	if (!ret)
+		nm_dispatcher_call (DISPATCHER_ACTION_HOSTNAME, NULL, NULL, NULL, NULL, NULL, NULL);
 }
 
 static void
-_set_hostname (NMPolicy *policy,
+_set_hostname (NMPolicy *self,
                const char *new_hostname,
                const char *msg)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
+	char old_hostname[HOST_NAME_MAX + 1];
+	const char *name;
+	int ret;
 
 	/* The incoming hostname *can* be NULL, which will get translated to
 	 * 'localhost.localdomain' or such in the hostname policy code, but we
@@ -194,10 +189,41 @@ _set_hostname (NMPolicy *policy,
 	priv->cur_hostname = g_strdup (new_hostname);
 	priv->hostname_changed = TRUE;
 
+	/* Notify the DNS manager of the hostname change so that the domain part, if
+	 * present, can be added to the search list.
+	 */
 	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, NULL);
+	 /* Finally, set kernel hostname */
+
+	if (!priv->cur_hostname)
+		name = FALLBACK_HOSTNAME4;
+	else if (!priv->cur_hostname[0]) {
+		g_warn_if_reached ();
+		name = FALLBACK_HOSTNAME4;
+	} else
+		name = priv->cur_hostname;
+
+	old_hostname[HOST_NAME_MAX] = '\0';
+	errno = 0;
+	ret = gethostname (old_hostname, HOST_NAME_MAX);
+	if (ret != 0) {
+		_LOGW (LOGD_DNS, "couldn't get the system hostname: (%d) %s",
+		       errno, strerror (errno));
+	} else {
+		/* Don't set the hostname if it isn't actually changing */
+		if (nm_streq (name, old_hostname))
+			return;
+	}
+
+	_LOGI (LOGD_DNS, "setting system hostname to '%s' (%s)", name, msg);
+
+	/* Ask NMSettings to update the transient hostname using its
+	 * systemd-hostnamed proxy */
+	nm_settings_set_transient_hostname (priv->settings,
+	                                    name,
+	                                    settings_set_hostname_cb,
+	                                    NULL);
 }
 
 static void
@@ -205,8 +231,8 @@ lookup_callback (GObject *source,
                  GAsyncResult *result,
                  gpointer user_data)
 {
-	NMPolicy *policy = (NMPolicy *) user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = (NMPolicy *) user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	const char *hostname;
 	GError *error = NULL;
 
@@ -218,9 +244,9 @@ lookup_callback (GObject *source,
 	}
 
 	if (hostname)
-		_set_hostname (policy, hostname, "from address lookup");
+		_set_hostname (self, hostname, "from address lookup");
 	else {
-		_set_hostname (policy, NULL, error->message);
+		_set_hostname (self, NULL, error->message);
 		g_error_free (error);
 	}
 
@@ -228,15 +254,15 @@ lookup_callback (GObject *source,
 }
 
 static void
-update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
+update_system_hostname (NMPolicy *self, NMDevice *best4, NMDevice *best6)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	char *configured_hostname = NULL;
 	const char *dhcp_hostname, *p;
 	NMIP4Config *ip4_config;
 	NMIP6Config *ip6_config;
 
-	g_return_if_fail (policy != NULL);
+	g_return_if_fail (self != NULL);
 
 	if (priv->lookup_cancellable) {
 		g_cancellable_cancel (priv->lookup_cancellable);
@@ -255,7 +281,7 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
 	/* Try a persistent hostname first */
 	g_object_get (G_OBJECT (priv->manager), NM_MANAGER_HOSTNAME, &configured_hostname, NULL);
 	if (configured_hostname && nm_utils_is_specific_hostname (configured_hostname)) {
-		_set_hostname (policy, configured_hostname, "from system configuration");
+		_set_hostname (self, configured_hostname, "from system configuration");
 		g_free (configured_hostname);
 		return;
 	}
@@ -263,15 +289,15 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
 
 	/* Try automatically determined hostname from the best device's IP config */
 	if (!best4)
-		best4 = get_best_ip4_device (policy, TRUE);
+		best4 = get_best_ip4_device (self, TRUE);
 	if (!best6)
-		best6 = get_best_ip6_device (policy, TRUE);
+		best6 = get_best_ip6_device (self, TRUE);
 
 	if (!best4 && !best6) {
 		/* No best device; fall back to original hostname or if there wasn't
 		 * one, 'localhost.localdomain'
 		 */
-		_set_hostname (policy, priv->orig_hostname, "no default device");
+		_set_hostname (self, priv->orig_hostname, "no default device");
 		return;
 	}
 
@@ -286,12 +312,12 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
 				/* Sanity check; strip leading spaces */
 				while (*p) {
 					if (!g_ascii_isspace (*p++)) {
-						_set_hostname (policy, p-1, "from DHCPv4");
+						_set_hostname (self, p-1, "from DHCPv4");
 						return;
 					}
 				}
-				nm_log_warn (LOGD_DNS, "DHCPv4-provided hostname '%s' looks invalid; ignoring it",
-				             dhcp_hostname);
+				_LOGW (LOGD_DNS, "DHCPv4-provided hostname '%s' looks invalid; ignoring it",
+				       dhcp_hostname);
 			}
 		}
 	} else if (best6) {
@@ -305,12 +331,12 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
 				/* Sanity check; strip leading spaces */
 				while (*p) {
 					if (!g_ascii_isspace (*p++)) {
-						_set_hostname (policy, p-1, "from DHCPv6");
+						_set_hostname (self, p-1, "from DHCPv6");
 						return;
 					}
 				}
-				nm_log_warn (LOGD_DNS, "DHCPv6-provided hostname '%s' looks invalid; ignoring it",
-				             dhcp_hostname);
+				_LOGW (LOGD_DNS, "DHCPv6-provided hostname '%s' looks invalid; ignoring it",
+				       dhcp_hostname);
 			}
 		}
 	}
@@ -319,7 +345,7 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
 	 * when NM started up.
 	 */
 	if (priv->orig_hostname) {
-		_set_hostname (policy, priv->orig_hostname, "from system startup");
+		_set_hostname (self, priv->orig_hostname, "from system startup");
 		return;
 	}
 
@@ -345,7 +371,7 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
 		                                                   G_SOCKET_FAMILY_IPV6);
 	} else {
 		/* No valid IP config; fall back to localhost.localdomain */
-		_set_hostname (policy, NULL, "no IP config");
+		_set_hostname (self, NULL, "no IP config");
 		return;
 	}
 
@@ -353,15 +379,15 @@ update_system_hostname (NMPolicy *policy, NMDevice *best4, NMDevice *best6)
 	g_resolver_lookup_by_address_async (priv->resolver,
 	                                    priv->lookup_addr,
 	                                    priv->lookup_cancellable,
-	                                    lookup_callback, policy);
+	                                    lookup_callback, self);
 }
 
 static void
-update_default_ac (NMPolicy *policy,
+update_default_ac (NMPolicy *self,
                    NMActiveConnection *best,
                    void (*set_active_func)(NMActiveConnection*, gboolean))
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	const GSList *connections, *iter;
 
 	/* Clear the 'default[6]' flag on all active connections that aren't the new
@@ -396,14 +422,14 @@ get_best_ip4_config (NMPolicy *self,
 }
 
 static void
-update_ip4_dns (NMPolicy *policy, NMDnsManager *dns_mgr)
+update_ip4_dns (NMPolicy *self, NMDnsManager *dns_mgr)
 {
 	NMIP4Config *ip4_config;
 	const char *ip_iface = NULL;
 	NMVpnConnection *vpn = NULL;
 	NMDnsIPConfigType dns_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE;
 
-	ip4_config = get_best_ip4_config (policy, TRUE, &ip_iface, NULL, NULL, &vpn);
+	ip4_config = get_best_ip4_config (self, TRUE, &ip_iface, NULL, NULL, &vpn);
 	if (ip4_config) {
 		if (vpn)
 			dns_type = NM_DNS_IP_CONFIG_TYPE_VPN;
@@ -416,9 +442,9 @@ update_ip4_dns (NMPolicy *policy, NMDnsManager *dns_mgr)
 }
 
 static void
-update_ip4_routing (NMPolicy *policy, gboolean force_update)
+update_ip4_routing (NMPolicy *self, gboolean force_update)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	NMDevice *best = NULL, *default_device;
 	NMConnection *connection = NULL;
 	NMVpnConnection *vpn = NULL;
@@ -428,13 +454,13 @@ update_ip4_routing (NMPolicy *policy, gboolean force_update)
 	/* Note that we might have an IPv4 VPN tunneled over an IPv6-only device,
 	 * so we can get (vpn != NULL && best == NULL).
 	 */
-	if (!get_best_ip4_config (policy, FALSE, &ip_iface, &best_ac, &best, &vpn)) {
+	if (!get_best_ip4_config (self, FALSE, &ip_iface, &best_ac, &best, &vpn)) {
 		gboolean changed;
 
 		changed = (priv->default_device4 != NULL);
 		priv->default_device4 = NULL;
 		if (changed)
-			g_object_notify (G_OBJECT (policy), NM_POLICY_DEFAULT_IP4_DEVICE);
+			_notify (self, PROP_DEFAULT_IP4_DEVICE);
 
 		return;
 	}
@@ -462,16 +488,16 @@ update_ip4_routing (NMPolicy *policy, gboolean force_update)
 	else
 		default_device = best;
 
-	update_default_ac (policy, best_ac, nm_active_connection_set_default);
+	update_default_ac (self, best_ac, nm_active_connection_set_default);
 
 	if (default_device == priv->default_device4)
 		return;
 
 	priv->default_device4 = default_device;
 	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);
+	_LOGI (LOGD_CORE, "set '%s' (%s) as default for IPv4 routing and DNS",
+	       nm_connection_get_id (connection), ip_iface);
+	_notify (self, PROP_DEFAULT_IP4_DEVICE);
 }
 
 static NMIP6Config *
@@ -491,14 +517,14 @@ get_best_ip6_config (NMPolicy *self,
 }
 
 static void
-update_ip6_dns (NMPolicy *policy, NMDnsManager *dns_mgr)
+update_ip6_dns (NMPolicy *self, NMDnsManager *dns_mgr)
 {
 	NMIP6Config *ip6_config;
 	const char *ip_iface = NULL;
 	NMVpnConnection *vpn = NULL;
 	NMDnsIPConfigType dns_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE;
 
-	ip6_config = get_best_ip6_config (policy, TRUE, &ip_iface, NULL, NULL, &vpn);
+	ip6_config = get_best_ip6_config (self, TRUE, &ip_iface, NULL, NULL, &vpn);
 	if (ip6_config) {
 		if (vpn)
 			dns_type = NM_DNS_IP_CONFIG_TYPE_VPN;
@@ -511,9 +537,9 @@ update_ip6_dns (NMPolicy *policy, NMDnsManager *dns_mgr)
 }
 
 static void
-update_ip6_routing (NMPolicy *policy, gboolean force_update)
+update_ip6_routing (NMPolicy *self, gboolean force_update)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	NMDevice *best = NULL, *default_device6;
 	NMConnection *connection = NULL;
 	NMVpnConnection *vpn = NULL;
@@ -523,13 +549,13 @@ update_ip6_routing (NMPolicy *policy, gboolean force_update)
 	/* Note that we might have an IPv6 VPN tunneled over an IPv4-only device,
 	 * so we can get (vpn != NULL && best == NULL).
 	 */
-	if (!get_best_ip6_config (policy, FALSE, &ip_iface, &best_ac, &best, &vpn)) {
+	if (!get_best_ip6_config (self, FALSE, &ip_iface, &best_ac, &best, &vpn)) {
 		gboolean changed;
 
 		changed = (priv->default_device6 != NULL);
 		priv->default_device6 = NULL;
 		if (changed)
-			g_object_notify (G_OBJECT (policy), NM_POLICY_DEFAULT_IP6_DEVICE);
+			_notify (self, PROP_DEFAULT_IP6_DEVICE);
 
 		return;
 	}
@@ -557,56 +583,56 @@ update_ip6_routing (NMPolicy *policy, gboolean force_update)
 	else
 		default_device6 = best;
 
-	update_default_ac (policy, best_ac, nm_active_connection_set_default6);
+	update_default_ac (self, best_ac, nm_active_connection_set_default6);
 
 	if (default_device6 == priv->default_device6)
 		return;
 
 	priv->default_device6 = default_device6;
 	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);
+	_LOGI (LOGD_CORE, "set '%s' (%s) as default for IPv6 routing and DNS",
+	       nm_connection_get_id (connection), ip_iface);
+	_notify (self, PROP_DEFAULT_IP6_DEVICE);
 }
 
 static void
-update_routing_and_dns (NMPolicy *policy, gboolean force_update)
+update_routing_and_dns (NMPolicy *self, gboolean force_update)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 
 	nm_dns_manager_begin_updates (priv->dns_manager, __func__);
 
-	update_ip4_dns (policy, priv->dns_manager);
-	update_ip6_dns (policy, priv->dns_manager);
+	update_ip4_dns (self, priv->dns_manager);
+	update_ip6_dns (self, priv->dns_manager);
 
-	update_ip4_routing (policy, force_update);
-	update_ip6_routing (policy, force_update);
+	update_ip4_routing (self, force_update);
+	update_ip6_routing (self, force_update);
 
 	/* Update the system hostname */
-	update_system_hostname (policy, priv->default_device4, priv->default_device6);
+	update_system_hostname (self, priv->default_device4, priv->default_device6);
 
 	nm_dns_manager_end_updates (priv->dns_manager, __func__);
 }
 
 static void
-check_activating_devices (NMPolicy *policy)
+check_activating_devices (NMPolicy *self)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
-	GObject *object = G_OBJECT (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
+	GObject *object = G_OBJECT (self);
 	NMDevice *best4, *best6 = NULL;
 
-	best4 = get_best_ip4_device (policy, FALSE);
-	best6 = get_best_ip6_device (policy, FALSE);
+	best4 = get_best_ip4_device (self, FALSE);
+	best6 = get_best_ip6_device (self, FALSE);
 
 	g_object_freeze_notify (object);
 
 	if (best4 != priv->activating_device4) {
 		priv->activating_device4 = best4;
-		g_object_notify (object, NM_POLICY_ACTIVATING_IP4_DEVICE);
+		_notify (self, PROP_ACTIVATING_IP4_DEVICE);
 	}
 	if (best6 != priv->activating_device6) {
 		priv->activating_device6 = best6;
-		g_object_notify (object, NM_POLICY_ACTIVATING_IP6_DEVICE);
+		_notify (self, PROP_ACTIVATING_IP6_DEVICE);
 	}
 
 	g_object_thaw_notify (object);
@@ -629,14 +655,15 @@ activate_data_free (ActivateData *data)
 	if (data->autoactivate_id)
 		g_source_remove (data->autoactivate_id);
 	g_object_unref (data->device);
-	g_free (data);
+
+	g_slice_free (ActivateData, data);
 }
 
 static gboolean
 auto_activate_device (gpointer user_data)
 {
 	ActivateData *data = (ActivateData *) user_data;
-	NMPolicy *policy;
+	NMPolicy *self;
 	NMPolicyPrivate *priv;
 	NMSettingsConnection *best_connection;
 	char *specific_object = NULL;
@@ -645,8 +672,8 @@ auto_activate_device (gpointer user_data)
 	guint i;
 
 	g_assert (data);
-	policy = data->policy;
-	priv = NM_POLICY_GET_PRIVATE (policy);
+	self = data->policy;
+	priv = NM_POLICY_GET_PRIVATE (self);
 
 	data->autoactivate_id = 0;
 
@@ -686,8 +713,8 @@ auto_activate_device (gpointer user_data)
 		GError *error = NULL;
 		NMAuthSubject *subject;
 
-		nm_log_info (LOGD_DEVICE, "Auto-activating connection '%s'.",
-		             nm_settings_connection_get_id (best_connection));
+		_LOGI (LOGD_DEVICE, "auto-activating connection '%s'",
+		       nm_settings_connection_get_id (best_connection));
 		subject = nm_auth_subject_new_internal ();
 		if (!nm_manager_activate_connection (priv->manager,
 		                                     best_connection,
@@ -695,10 +722,10 @@ auto_activate_device (gpointer user_data)
 		                                     data->device,
 		                                     subject,
 		                                     &error)) {
-			nm_log_info (LOGD_DEVICE, "Connection '%s' auto-activation failed: (%d) %s",
-			             nm_settings_connection_get_id (best_connection),
-			             error ? error->code : -1,
-			             error ? error->message : "(none)");
+			_LOGI (LOGD_DEVICE, "connection '%s' auto-activation failed: (%d) %s",
+			       nm_settings_connection_get_id (best_connection),
+			       error->code,
+			       error->message);
 			g_error_free (error);
 		}
 		g_object_unref (subject);
@@ -733,7 +760,7 @@ pending_secondary_data_new (NMDevice *device, GSList *secondaries)
 {
 	PendingSecondaryData *data;
 
-	data = g_malloc0 (sizeof (PendingSecondaryData));
+	data = g_slice_new (PendingSecondaryData);
 	data->device = g_object_ref (device);
 	data->secondaries = secondaries;
 	return data;
@@ -744,16 +771,15 @@ pending_secondary_data_free (PendingSecondaryData *data)
 {
 	g_object_unref (data->device);
 	g_slist_free_full (data->secondaries, g_object_unref);
-	memset (data, 0, sizeof (*data));
-	g_free (data);
+	g_slice_free (PendingSecondaryData, data);
 }
 
 static void
-process_secondaries (NMPolicy *policy,
+process_secondaries (NMPolicy *self,
                      NMActiveConnection *active,
                      gboolean connected)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	GSList *iter, *iter2, *next, *next2;
 
 	/* Loop through devices waiting for secondary connections to activate */
@@ -773,9 +799,9 @@ process_secondaries (NMPolicy *policy,
 				continue;
 
 			if (connected) {
-				nm_log_dbg (LOGD_DEVICE, "Secondary connection '%s' SUCCEEDED; active path '%s'",
-				            nm_active_connection_get_settings_connection_id (active),
-				            nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)));
+				_LOGD (LOGD_DEVICE, "secondary connection '%s' succeeded; active path '%s'",
+				       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);
@@ -789,9 +815,9 @@ process_secondaries (NMPolicy *policy,
 					break;
 				}
 			} else {
-				nm_log_dbg (LOGD_DEVICE, "Secondary connection '%s' FAILED; active path '%s'",
-				            nm_active_connection_get_settings_connection_id (active),
-				            nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)));
+				_LOGD (LOGD_DEVICE, "secondary connection '%s' failed; active path '%s'",
+				       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);
@@ -818,16 +844,16 @@ hostname_changed (NMManager *manager, GParamSpec *pspec, gpointer user_data)
 }
 
 static void
-reset_autoconnect_all (NMPolicy *policy, NMDevice *device)
+reset_autoconnect_all (NMPolicy *self, NMDevice *device)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	GSList *connections, *iter;
 
 	if (device) {
-		nm_log_dbg (LOGD_DEVICE, "Re-enabling autoconnect for all connections on %s",
-		            nm_device_get_iface (device));
+		_LOGD (LOGD_DEVICE, "re-enabling autoconnect for all connections on %s",
+		       nm_device_get_iface (device));
 	} else
-		nm_log_dbg (LOGD_DEVICE, "Re-enabling autoconnect for all connections");
+		_LOGD (LOGD_DEVICE, "re-enabling autoconnect for all connections");
 
 	connections = nm_settings_get_connections (priv->settings);
 	for (iter = connections; iter; iter = g_slist_next (iter)) {
@@ -840,12 +866,12 @@ reset_autoconnect_all (NMPolicy *policy, NMDevice *device)
 }
 
 static void
-reset_autoconnect_for_failed_secrets (NMPolicy *policy)
+reset_autoconnect_for_failed_secrets (NMPolicy *self)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	GSList *connections, *iter;
 
-	nm_log_dbg (LOGD_DEVICE, "Re-enabling autoconnect for all connections with failed secrets");
+	_LOGD (LOGD_DEVICE, "re-enabling autoconnect for all connections with failed secrets");
 
 	connections = nm_settings_get_connections (priv->settings);
 	for (iter = connections; iter; iter = g_slist_next (iter)) {
@@ -860,13 +886,13 @@ reset_autoconnect_for_failed_secrets (NMPolicy *policy)
 }
 
 static void
-block_autoconnect_for_device (NMPolicy *policy, NMDevice *device)
+block_autoconnect_for_device (NMPolicy *self, NMDevice *device)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	GSList *connections, *iter;
 
-	nm_log_dbg (LOGD_DEVICE, "Blocking autoconnect for all connections on %s",
-	            nm_device_get_iface (device));
+	_LOGD (LOGD_DEVICE, "blocking autoconnect for all connections on %s",
+	       nm_device_get_iface (device));
 
 	/* NMDevice keeps its own autoconnect-able-ness state; we only need to
 	 * explicitly block connections for software devices, where the NMDevice
@@ -887,7 +913,7 @@ block_autoconnect_for_device (NMPolicy *policy, NMDevice *device)
 static void
 sleeping_changed (NMManager *manager, GParamSpec *pspec, gpointer user_data)
 {
-	NMPolicy *policy = user_data;
+	NMPolicy *self = user_data;
 	gboolean sleeping = FALSE, enabled = FALSE;
 
 	g_object_get (G_OBJECT (manager), NM_MANAGER_SLEEPING, &sleeping, NULL);
@@ -895,13 +921,13 @@ sleeping_changed (NMManager *manager, GParamSpec *pspec, gpointer user_data)
 
 	/* Reset retries on all connections so they'll checked on wakeup */
 	if (sleeping || !enabled)
-		reset_autoconnect_all (policy, NULL);
+		reset_autoconnect_all (self, NULL);
 }
 
 static void
-schedule_activate_check (NMPolicy *policy, NMDevice *device)
+schedule_activate_check (NMPolicy *self, NMDevice *device)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	ActivateData *data;
 	const GSList *active_connections, *iter;
 
@@ -925,17 +951,17 @@ schedule_activate_check (NMPolicy *policy, NMDevice *device)
 
 	nm_device_add_pending_action (device, "autoactivate", TRUE);
 
-	data = g_malloc0 (sizeof (ActivateData));
-	data->policy = policy;
+	data = g_slice_new0 (ActivateData);
+	data->policy = self;
 	data->device = g_object_ref (device);
 	data->autoactivate_id = g_idle_add (auto_activate_device, data);
 	priv->pending_activation_checks = g_slist_append (priv->pending_activation_checks, data);
 }
 
 static void
-clear_pending_activate_check (NMPolicy *policy, NMDevice *device)
+clear_pending_activate_check (NMPolicy *self, NMDevice *device)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	ActivateData *data;
 
 	data = find_pending_activation (priv->pending_activation_checks, device);
@@ -946,8 +972,8 @@ clear_pending_activate_check (NMPolicy *policy, NMDevice *device)
 static gboolean
 reset_connections_retries (gpointer user_data)
 {
-	NMPolicy *policy = (NMPolicy *) user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = (NMPolicy *) user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	GSList *connections, *iter;
 	gint32 con_stamp, min_stamp, now;
 	gboolean changed = FALSE;
@@ -974,21 +1000,21 @@ reset_connections_retries (gpointer user_data)
 
 	/* Schedule the handler again if there are some stamps left */
 	if (min_stamp != 0)
-		priv->reset_retries_id = g_timeout_add_seconds (min_stamp - now, reset_connections_retries, policy);
+		priv->reset_retries_id = g_timeout_add_seconds (min_stamp - now, reset_connections_retries, self);
 
 	/* If anything changed, try to activate the newly re-enabled connections */
 	if (changed)
-		schedule_activate_all (policy);
+		schedule_activate_all (self);
 
 	return FALSE;
 }
 
-static void schedule_activate_all (NMPolicy *policy);
+static void schedule_activate_all (NMPolicy *self);
 
 static void
-activate_slave_connections (NMPolicy *policy, NMDevice *device)
+activate_slave_connections (NMPolicy *self, NMDevice *device)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	const char *master_device, *master_uuid_settings = NULL, *master_uuid_applied = NULL;
 	GSList *connections, *iter;
 	NMActRequest *req;
@@ -1034,15 +1060,15 @@ activate_slave_connections (NMPolicy *policy, NMDevice *device)
 
 	g_slist_free (connections);
 
-	schedule_activate_all (policy);
+	schedule_activate_all (self);
 }
 
 static gboolean
-activate_secondary_connections (NMPolicy *policy,
+activate_secondary_connections (NMPolicy *self,
                                 NMConnection *connection,
                                 NMDevice *device)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	NMSettingConnection *s_con;
 	NMSettingsConnection *settings_con;
 	NMActiveConnection *ac;
@@ -1061,14 +1087,14 @@ activate_secondary_connections (NMPolicy *policy,
 
 		settings_con = nm_settings_get_connection_by_uuid (priv->settings, sec_uuid);
 		if (!settings_con) {
-			nm_log_warn (LOGD_DEVICE, "Secondary connection '%s' auto-activation failed: The connection doesn't exist.",
-			             sec_uuid);
+			_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_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_settings_connection_get_id (settings_con), sec_uuid);
+			_LOGW (LOGD_DEVICE, "secondary connection '%s (%s)' auto-activation failed: The connection is not a VPN.",
+			       nm_settings_connection_get_id (settings_con), sec_uuid);
 			success = FALSE;
 			break;
 		}
@@ -1076,9 +1102,9 @@ activate_secondary_connections (NMPolicy *policy,
 		req = nm_device_get_act_request (device);
 		g_assert (req);
 
-		nm_log_dbg (LOGD_DEVICE, "Activating secondary connection '%s (%s)' for base connection '%s (%s)'",
-		            nm_settings_connection_get_id (settings_con), sec_uuid,
-		            nm_connection_get_id (connection), nm_connection_get_uuid (connection));
+		_LOGD (LOGD_DEVICE, "activating secondary connection '%s (%s)' for base connection '%s (%s)'",
+		       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,
 		                                     settings_con,
 		                                     nm_exported_object_get_path (NM_EXPORTED_OBJECT (req)),
@@ -1088,10 +1114,10 @@ activate_secondary_connections (NMPolicy *policy,
 		if (ac)
 			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_settings_connection_get_id (settings_con), sec_uuid,
-			             error ? error->code : 0,
-			             (error && error->message) ? error->message : "unknown");
+			_LOGW (LOGD_DEVICE, "secondary connection '%s (%s)' auto-activation failed: (%d) %s",
+			       nm_settings_connection_get_id (settings_con), sec_uuid,
+			       error->code,
+			       error->message);
 			g_clear_error (&error);
 			success = FALSE;
 			break;
@@ -1114,8 +1140,8 @@ device_state_changed (NMDevice *device,
                       NMDeviceStateReason reason,
                       gpointer user_data)
 {
-	NMPolicy *policy = (NMPolicy *) user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = (NMPolicy *) user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 
 	NMSettingsConnection *connection = nm_device_get_settings_connection (device);
 
@@ -1135,25 +1161,25 @@ device_state_changed (NMDevice *device,
 			guint32 tries = nm_settings_connection_get_autoconnect_retries (connection);
 
 			if (reason == NM_DEVICE_STATE_REASON_NO_SECRETS) {
-				nm_log_dbg (LOGD_DEVICE, "Connection '%s' now blocked from autoconnect due to no secrets",
-				            nm_settings_connection_get_id (connection));
+				_LOGD (LOGD_DEVICE, "connection '%s' now blocked from autoconnect due to no secrets",
+				       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_settings_connection_get_id (connection), tries);
+				_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left",
+				       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_settings_connection_get_id (connection));
+				_LOGI (LOGD_DEVICE, "disabling autoconnect for connection '%s'.",
+				       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);
 
 					g_warn_if_fail (retry_time != 0);
-					priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_s ()), reset_connections_retries, policy);
+					priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_s ()), reset_connections_retries, self);
 				}
 			}
 			nm_connection_clear_secrets (NM_CONNECTION (connection));
@@ -1182,25 +1208,25 @@ device_state_changed (NMDevice *device,
 		if (ip6_config)
 			nm_dns_manager_add_ip6_config (priv->dns_manager, ip_iface, ip6_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
 
-		update_routing_and_dns (policy, FALSE);
+		update_routing_and_dns (self, FALSE);
 
 		nm_dns_manager_end_updates (priv->dns_manager, __func__);
 		break;
 	case NM_DEVICE_STATE_UNMANAGED:
 	case NM_DEVICE_STATE_UNAVAILABLE:
 		if (old_state > NM_DEVICE_STATE_DISCONNECTED)
-			update_routing_and_dns (policy, FALSE);
+			update_routing_and_dns (self, FALSE);
 		break;
 	case NM_DEVICE_STATE_DEACTIVATING:
 		if (reason == NM_DEVICE_STATE_REASON_USER_REQUESTED) {
 			if (!nm_device_get_autoconnect (device)) {
 				/* The device was disconnected; block all connections on it */
-				block_autoconnect_for_device (policy, device);
+				block_autoconnect_for_device (self, device);
 			} else {
 				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_settings_connection_get_id (connection));
+					_LOGD (LOGD_DEVICE, "blocking autoconnect of connection '%s' by user request",
+					       nm_settings_connection_get_id (connection));
 					nm_settings_connection_set_autoconnect_blocked_reason (connection,
 					                                                       NM_DEVICE_STATE_REASON_USER_REQUESTED);
 				}
@@ -1212,19 +1238,19 @@ device_state_changed (NMDevice *device,
 		 * was unplugged and plugged in again, we should try to reconnect.
 		 */
 		if (reason == NM_DEVICE_STATE_REASON_CARRIER && old_state == NM_DEVICE_STATE_UNAVAILABLE)
-			reset_autoconnect_all (policy, device);
+			reset_autoconnect_all (self, device);
 
 		if (old_state > NM_DEVICE_STATE_DISCONNECTED)
-			update_routing_and_dns (policy, FALSE);
+			update_routing_and_dns (self, FALSE);
 
 		/* Device is now available for auto-activation */
-		schedule_activate_check (policy, device);
+		schedule_activate_check (self, device);
 		break;
 
 	case NM_DEVICE_STATE_PREPARE:
 		/* Reset auto-connect retries of all slaves and schedule them for
 		 * activation. */
-		activate_slave_connections (policy, device);
+		activate_slave_connections (self, device);
 		break;
 	case NM_DEVICE_STATE_IP_CONFIG:
 		/* We must have secrets if we got here. */
@@ -1236,10 +1262,10 @@ device_state_changed (NMDevice *device,
 			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 (policy, FALSE);
+			update_routing_and_dns (self, FALSE);
 
 			/* Activate secondary (VPN) connections */
-			if (!activate_secondary_connections (policy, NM_CONNECTION (connection), device))
+			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
@@ -1251,7 +1277,7 @@ device_state_changed (NMDevice *device,
 		break;
 	}
 
-	check_activating_devices (policy);
+	check_activating_devices (self);
 }
 
 static void
@@ -1260,8 +1286,8 @@ device_ip4_config_changed (NMDevice *device,
                            NMIP4Config *old_config,
                            gpointer user_data)
 {
-	NMPolicy *policy = user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	const char *ip_iface = nm_device_get_ip_iface (device);
 
 	nm_dns_manager_begin_updates (priv->dns_manager, __func__);
@@ -1277,8 +1303,8 @@ device_ip4_config_changed (NMDevice *device,
 			if (new_config)
 				nm_dns_manager_add_ip4_config (priv->dns_manager, ip_iface, new_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
 		}
-		update_ip4_dns (policy, priv->dns_manager);
-		update_ip4_routing (policy, TRUE);
+		update_ip4_dns (self, priv->dns_manager);
+		update_ip4_routing (self, TRUE);
 	} else {
 		/* Old configs get removed immediately */
 		if (old_config)
@@ -1294,8 +1320,8 @@ device_ip6_config_changed (NMDevice *device,
                            NMIP6Config *old_config,
                            gpointer user_data)
 {
-	NMPolicy *policy = user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	const char *ip_iface = nm_device_get_ip_iface (device);
 
 	nm_dns_manager_begin_updates (priv->dns_manager, __func__);
@@ -1311,8 +1337,8 @@ device_ip6_config_changed (NMDevice *device,
 			if (new_config)
 				nm_dns_manager_add_ip6_config (priv->dns_manager, ip_iface, new_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
 		}
-		update_ip6_dns (policy, priv->dns_manager);
-		update_ip6_routing (policy, TRUE);
+		update_ip6_dns (self, priv->dns_manager);
+		update_ip6_routing (self, TRUE);
 	} else {
 		/* Old configs get removed immediately */
 		if (old_config)
@@ -1343,21 +1369,21 @@ typedef struct {
 } DeviceSignalId;
 
 static void
-_connect_device_signal (NMPolicy *policy,
+_connect_device_signal (NMPolicy *self,
                         NMDevice *device,
                         const char *name,
                         gpointer callback,
                         gboolean after)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	DeviceSignalId *data;
 
 	data = g_slice_new0 (DeviceSignalId);
 	g_assert (data);
 	if (after)
-		data->id = g_signal_connect_after (device, name, callback, policy);
+		data->id = g_signal_connect_after (device, name, callback, self);
 	else
-		data->id = g_signal_connect (device, name, callback, policy);
+		data->id = g_signal_connect (device, name, callback, self);
 	data->device = device;
 	priv->dev_ids = g_slist_prepend (priv->dev_ids, data);
 }
@@ -1365,25 +1391,25 @@ _connect_device_signal (NMPolicy *policy,
 static void
 device_added (NMManager *manager, NMDevice *device, gpointer user_data)
 {
-	NMPolicy *policy = (NMPolicy *) user_data;
+	NMPolicy *self = (NMPolicy *) user_data;
 
 	/* Connect state-changed with _after, so that the handler is invoked after other handlers. */
-	_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);
-	_connect_device_signal (policy, device, NM_DEVICE_RECHECK_AUTO_ACTIVATE, device_recheck_auto_activate, FALSE);
+	_connect_device_signal (self, device, NM_DEVICE_STATE_CHANGED, device_state_changed, TRUE);
+	_connect_device_signal (self, device, NM_DEVICE_IP4_CONFIG_CHANGED, device_ip4_config_changed, FALSE);
+	_connect_device_signal (self, device, NM_DEVICE_IP6_CONFIG_CHANGED, device_ip6_config_changed, FALSE);
+	_connect_device_signal (self, device, "notify::" NM_DEVICE_AUTOCONNECT, device_autoconnect_changed, FALSE);
+	_connect_device_signal (self, device, NM_DEVICE_RECHECK_AUTO_ACTIVATE, device_recheck_auto_activate, FALSE);
 }
 
 static void
 device_removed (NMManager *manager, NMDevice *device, gpointer user_data)
 {
-	NMPolicy *policy = (NMPolicy *) user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = (NMPolicy *) user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	GSList *iter;
 
 	/* Clear any idle callbacks for this device */
-	clear_pending_activate_check (policy, device);
+	clear_pending_activate_check (self, device);
 
 	/* Clear any signal handlers for this device */
 	iter = priv->dev_ids;
@@ -1407,9 +1433,9 @@ device_removed (NMManager *manager, NMDevice *device, gpointer user_data)
 /**************************************************************************/
 
 static void
-vpn_connection_activated (NMPolicy *policy, NMVpnConnection *vpn)
+vpn_connection_activated (NMPolicy *self, NMVpnConnection *vpn)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	NMIP4Config *ip4_config;
 	NMIP6Config *ip6_config;
 	const char *ip_iface;
@@ -1428,15 +1454,15 @@ vpn_connection_activated (NMPolicy *policy, NMVpnConnection *vpn)
 	if (ip6_config)
 		nm_dns_manager_add_ip6_config (priv->dns_manager, ip_iface, ip6_config, NM_DNS_IP_CONFIG_TYPE_VPN);
 
-	update_routing_and_dns (policy, TRUE);
+	update_routing_and_dns (self, TRUE);
 
 	nm_dns_manager_end_updates (priv->dns_manager, __func__);
 }
 
 static void
-vpn_connection_deactivated (NMPolicy *policy, NMVpnConnection *vpn)
+vpn_connection_deactivated (NMPolicy *self, NMVpnConnection *vpn)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	NMIP4Config *ip4_config;
 	NMIP6Config *ip6_config;
 
@@ -1454,7 +1480,7 @@ vpn_connection_deactivated (NMPolicy *policy, NMVpnConnection *vpn)
 		nm_dns_manager_remove_ip6_config (priv->dns_manager, ip6_config);
 	}
 
-	update_routing_and_dns (policy, TRUE);
+	update_routing_and_dns (self, TRUE);
 
 	nm_dns_manager_end_updates (priv->dns_manager, __func__);
 }
@@ -1464,22 +1490,22 @@ vpn_connection_state_changed (NMVpnConnection *vpn,
                               NMVpnConnectionState new_state,
                               NMVpnConnectionState old_state,
                               NMVpnConnectionStateReason reason,
-                              NMPolicy *policy)
+                              NMPolicy *self)
 {
 	if (new_state == NM_VPN_CONNECTION_STATE_ACTIVATED)
-		vpn_connection_activated (policy, vpn);
+		vpn_connection_activated (self, vpn);
 	else if (new_state >= NM_VPN_CONNECTION_STATE_FAILED) {
 		/* Only clean up IP/DNS if the connection ever got past IP_CONFIG */
 		if (old_state >= NM_VPN_CONNECTION_STATE_IP_CONFIG_GET &&
 		    old_state <= NM_VPN_CONNECTION_STATE_ACTIVATED)
-			vpn_connection_deactivated (policy, vpn);
+			vpn_connection_deactivated (self, vpn);
 	}
 }
 
 static void
-vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *policy)
+vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *self)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	NMActiveConnection *ac = NM_ACTIVE_CONNECTION (vpn);
 	NMSettingsConnection *connection = nm_active_connection_get_settings_connection (ac);
 	GError *error = NULL;
@@ -1491,9 +1517,9 @@ vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *policy)
 	                                     NULL,
 	                                     nm_active_connection_get_subject (ac),
 	                                     &error)) {
-		nm_log_warn (LOGD_DEVICE, "VPN '%s' reconnect failed: %s",
-		             nm_settings_connection_get_id (connection),
-		             error->message ? error->message : "unknown");
+		_LOGW (LOGD_DEVICE, "VPN '%s' reconnect failed: %s",
+		       nm_settings_connection_get_id (connection),
+		       error->message ? error->message : "unknown");
 		g_clear_error (&error);
 	}
 }
@@ -1501,14 +1527,14 @@ vpn_connection_retry_after_failure (NMVpnConnection *vpn, NMPolicy *policy)
 static void
 active_connection_state_changed (NMActiveConnection *active,
                                  GParamSpec *pspec,
-                                 NMPolicy *policy)
+                                 NMPolicy *self)
 {
 	NMActiveConnectionState state = nm_active_connection_get_state (active);
 
 	if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED)
-		process_secondaries (policy, active, TRUE);
+		process_secondaries (self, active, TRUE);
 	else if (state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED)
-		process_secondaries (policy, active, FALSE);
+		process_secondaries (self, active, FALSE);
 }
 
 static void
@@ -1516,20 +1542,20 @@ active_connection_added (NMManager *manager,
                          NMActiveConnection *active,
                          gpointer user_data)
 {
-	NMPolicy *policy = NM_POLICY (user_data);
+	NMPolicy *self = NM_POLICY (user_data);
 
 	if (NM_IS_VPN_CONNECTION (active)) {
 		g_signal_connect (active, NM_VPN_CONNECTION_INTERNAL_STATE_CHANGED,
 		                  G_CALLBACK (vpn_connection_state_changed),
-		                  policy);
+		                  self);
 		g_signal_connect (active, NM_VPN_CONNECTION_INTERNAL_RETRY_AFTER_FAILURE,
 		                  G_CALLBACK (vpn_connection_retry_after_failure),
-		                  policy);
+		                  self);
 	}
 
 	g_signal_connect (active, "notify::" NM_ACTIVE_CONNECTION_STATE,
 	                  G_CALLBACK (active_connection_state_changed),
-	                  policy);
+	                  self);
 }
 
 static void
@@ -1537,29 +1563,29 @@ active_connection_removed (NMManager *manager,
                            NMActiveConnection *active,
                            gpointer user_data)
 {
-	NMPolicy *policy = NM_POLICY (user_data);
+	NMPolicy *self = NM_POLICY (user_data);
 
 	g_signal_handlers_disconnect_by_func (active,
 	                                      vpn_connection_state_changed,
-	                                      policy);
+	                                      self);
 	g_signal_handlers_disconnect_by_func (active,
 	                                      vpn_connection_retry_after_failure,
-	                                      policy);
+	                                      self);
 	g_signal_handlers_disconnect_by_func (active,
 	                                      active_connection_state_changed,
-	                                      policy);
+	                                      self);
 }
 
 /**************************************************************************/
 
 static void
-schedule_activate_all (NMPolicy *policy)
+schedule_activate_all (NMPolicy *self)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	const GSList *iter;
 
 	for (iter = nm_manager_get_devices (priv->manager); iter; iter = g_slist_next (iter))
-		schedule_activate_check (policy, NM_DEVICE (iter->data));
+		schedule_activate_check (self, NM_DEVICE (iter->data));
 }
 
 static void
@@ -1567,17 +1593,17 @@ connection_added (NMSettings *settings,
                   NMSettingsConnection *connection,
                   gpointer user_data)
 {
-	NMPolicy *policy = NM_POLICY (user_data);
+	NMPolicy *self = NM_POLICY (user_data);
 
-	schedule_activate_all (policy);
+	schedule_activate_all (self);
 }
 
 static void
 firewall_started (NMFirewallManager *manager,
                   gpointer user_data)
 {
-	NMPolicy *policy = (NMPolicy *) user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = (NMPolicy *) user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	const GSList *iter;
 
 	/* add interface of each device to correct zone */
@@ -1588,8 +1614,8 @@ firewall_started (NMFirewallManager *manager,
 static void
 dns_config_changed (NMDnsManager *dns_manager, gpointer user_data)
 {
-	NMPolicy *policy = (NMPolicy *) user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = (NMPolicy *) user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 
 	/* Restart a thread for reverse-DNS lookup after we are signalled that
 	 * DNS changed. Because the result from a previous run may not be right
@@ -1606,15 +1632,15 @@ dns_config_changed (NMDnsManager *dns_manager, gpointer user_data)
 	if (priv->lookup_addr) {
 		char *str = NULL;
 
-		nm_log_dbg (LOGD_DNS, "restarting reverse-lookup thread for address %s",
-		            (str = g_inet_address_to_string (priv->lookup_addr)));
+		_LOGD (LOGD_DNS, "restarting reverse-lookup thread for address %s",
+		       (str = g_inet_address_to_string (priv->lookup_addr)));
 		g_free (str);
 
 		priv->lookup_cancellable = g_cancellable_new ();
 		g_resolver_lookup_by_address_async (priv->resolver,
 		                                    priv->lookup_addr,
 		                                    priv->lookup_cancellable,
-		                                    lookup_callback, policy);
+		                                    lookup_callback, self);
 	}
 }
 
@@ -1631,8 +1657,8 @@ connection_updated_by_user (NMSettings *settings,
                             NMSettingsConnection *connection,
                             gpointer user_data)
 {
-	NMPolicy *policy = (NMPolicy *) user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = (NMPolicy *) user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	const GSList *iter;
 	NMDevice *device = NULL;
 
@@ -1670,10 +1696,10 @@ _deactivate_if_active (NMManager *manager, NMSettingsConnection *connection)
 			                                       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_settings_connection_get_id (connection),
-					         error ? error->code : -1,
-					         error ? error->message : "(unknown)");
+				_LOGW (LOGD_DEVICE, "connection '%s' disappeared, but error deactivating it: (%d) %s",
+				       nm_settings_connection_get_id (connection),
+				       error ? error->code : -1,
+				       error ? error->message : "(unknown)");
 				g_clear_error (&error);
 			}
 		}
@@ -1685,8 +1711,8 @@ connection_removed (NMSettings *settings,
                     NMSettingsConnection *connection,
                     gpointer user_data)
 {
-	NMPolicy *policy = user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 
 	_deactivate_if_active (priv->manager, connection);
 }
@@ -1696,11 +1722,11 @@ connection_visibility_changed (NMSettings *settings,
                                NMSettingsConnection *connection,
                                gpointer user_data)
 {
-	NMPolicy *policy = user_data;
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = user_data;
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 
 	if (nm_settings_connection_is_visible (connection))
-		schedule_activate_all (policy);
+		schedule_activate_all (self);
 	else
 		_deactivate_if_active (priv->manager, connection);
 }
@@ -1710,52 +1736,125 @@ secret_agent_registered (NMSettings *settings,
                          NMSecretAgent *agent,
                          gpointer user_data)
 {
-	NMPolicy *policy = NM_POLICY (user_data);
+	NMPolicy *self = NM_POLICY (user_data);
 
 	/* The registered secret agent may provide some missing secrets. Thus we
 	 * reset retries count here and schedule activation, so that the
 	 * connections failed due to missing secrets may re-try auto-connection.
 	 */
-	reset_autoconnect_for_failed_secrets (policy);
-	schedule_activate_all (policy);
+	reset_autoconnect_for_failed_secrets (self);
+	schedule_activate_all (self);
 }
 
+NMDevice *
+nm_policy_get_default_ip4_device (NMPolicy *self)
+{
+	return NM_POLICY_GET_PRIVATE (self)->default_device4;
+}
+
+NMDevice *
+nm_policy_get_default_ip6_device (NMPolicy *self)
+{
+	return NM_POLICY_GET_PRIVATE (self)->default_device6;
+}
+
+NMDevice *
+nm_policy_get_activating_ip4_device (NMPolicy *self)
+{
+	return NM_POLICY_GET_PRIVATE (self)->activating_device4;
+}
+
+NMDevice *
+nm_policy_get_activating_ip6_device (NMPolicy *self)
+{
+	return NM_POLICY_GET_PRIVATE (self)->activating_device6;
+}
+
+/*****************************************************************************/
+
 static void
-_connect_manager_signal (NMPolicy *policy, const char *name, gpointer callback)
+get_property (GObject *object, guint prop_id,
+              GValue *value, GParamSpec *pspec)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = NM_POLICY (object);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
+
+	switch (prop_id) {
+	case PROP_DEFAULT_IP4_DEVICE:
+		g_value_set_object (value, priv->default_device4);
+		break;
+	case PROP_DEFAULT_IP6_DEVICE:
+		g_value_set_object (value, priv->default_device6);
+		break;
+	case PROP_ACTIVATING_IP4_DEVICE:
+		g_value_set_object (value, priv->activating_device4);
+		break;
+	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);
+		break;
+	}
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+              const GValue *value, GParamSpec *pspec)
+{
+	NMPolicy *self = NM_POLICY (object);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
+
+	switch (prop_id) {
+	case PROP_MANAGER:
+		/* construct-only */
+		priv->manager = g_value_get_object (value);
+		g_return_if_fail (NM_IS_MANAGER (priv->manager));
+		break;
+	case PROP_SETTINGS:
+		/* construct-only */
+		priv->settings = g_value_dup_object (value);
+		g_return_if_fail (NM_IS_SETTINGS (priv->settings));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+/*****************************************************************************/
+
+static void
+_connect_manager_signal (NMPolicy *self, const char *name, gpointer callback)
+{
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	gulong id;
 
-	id = g_signal_connect (priv->manager, name, callback, policy);
+	id = g_signal_connect (priv->manager, name, callback, self);
 	priv->manager_ids = g_slist_prepend (priv->manager_ids, (gpointer) id);
 }
 
 static void
-_connect_settings_signal (NMPolicy *policy, const char *name, gpointer callback)
+_connect_settings_signal (NMPolicy *self, const char *name, gpointer callback)
 {
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	gulong id;
 
-	id = g_signal_connect (priv->settings, name, callback, policy);
+	id = g_signal_connect (priv->settings, name, callback, self);
 	priv->settings_ids = g_slist_prepend (priv->settings_ids, (gpointer) id);
 }
 
-NMPolicy *
-nm_policy_new (NMManager *manager, NMSettings *settings)
+static void
+nm_policy_init (NMPolicy *self)
 {
-	NMPolicy *policy;
-	NMPolicyPrivate *priv;
-	static gboolean initialized = FALSE;
-	char hostname[HOST_NAME_MAX + 2];
-
-	g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
-	g_return_val_if_fail (initialized == FALSE, NULL);
+}
 
-	policy = g_object_new (NM_TYPE_POLICY, NULL);
-	priv = NM_POLICY_GET_PRIVATE (policy);
-	priv->manager = manager;
-	priv->settings = g_object_ref (settings);
-	priv->update_state_id = 0;
+static void
+constructed (GObject *object)
+{
+	NMPolicy *self = NM_POLICY (object);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
+	char hostname[HOST_NAME_MAX + 2];
 
 	/* Grab hostname on startup and use that if nothing provides one */
 	memset (hostname, 0, sizeof (hostname));
@@ -1768,103 +1867,56 @@ nm_policy_new (NMManager *manager, NMSettings *settings)
 	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);
+	                                        G_CALLBACK (firewall_started), self);
 
 	priv->dns_manager = g_object_ref (nm_dns_manager_get ());
 	nm_dns_manager_set_initial_hostname (priv->dns_manager, priv->orig_hostname);
 	priv->config_changed_id = g_signal_connect (priv->dns_manager, "config-changed",
-	                                            G_CALLBACK (dns_config_changed), policy);
+	                                            G_CALLBACK (dns_config_changed), self);
 
 	priv->resolver = g_resolver_get_default ();
 
-	_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, "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);
-
-	_connect_settings_signal (policy, NM_SETTINGS_SIGNAL_CONNECTION_ADDED, connection_added);
-	_connect_settings_signal (policy, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, connection_updated);
-	_connect_settings_signal (policy, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED_BY_USER, connection_updated_by_user);
-	_connect_settings_signal (policy, NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, connection_removed);
-	_connect_settings_signal (policy, NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED,
+	_connect_manager_signal (self, NM_MANAGER_STATE_CHANGED, global_state_changed);
+	_connect_manager_signal (self, "notify::" NM_MANAGER_HOSTNAME, hostname_changed);
+	_connect_manager_signal (self, "notify::" NM_MANAGER_SLEEPING, sleeping_changed);
+	_connect_manager_signal (self, "notify::" NM_MANAGER_NETWORKING_ENABLED, sleeping_changed);
+	_connect_manager_signal (self, "internal-device-added", device_added);
+	_connect_manager_signal (self, "internal-device-removed", device_removed);
+	_connect_manager_signal (self, NM_MANAGER_ACTIVE_CONNECTION_ADDED, active_connection_added);
+	_connect_manager_signal (self, NM_MANAGER_ACTIVE_CONNECTION_REMOVED, active_connection_removed);
+
+	_connect_settings_signal (self, NM_SETTINGS_SIGNAL_CONNECTION_ADDED, connection_added);
+	_connect_settings_signal (self, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, connection_updated);
+	_connect_settings_signal (self, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED_BY_USER, connection_updated_by_user);
+	_connect_settings_signal (self, NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, connection_removed);
+	_connect_settings_signal (self, NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED,
 	                          connection_visibility_changed);
-	_connect_settings_signal (policy, NM_SETTINGS_SIGNAL_AGENT_REGISTERED, secret_agent_registered);
+	_connect_settings_signal (self, NM_SETTINGS_SIGNAL_AGENT_REGISTERED, secret_agent_registered);
 
-	initialized = TRUE;
-	return policy;
+	G_OBJECT_CLASS (nm_policy_parent_class)->constructed (object);
 }
 
-NMDevice *
-nm_policy_get_default_ip4_device (NMPolicy *policy)
-{
-	return NM_POLICY_GET_PRIVATE (policy)->default_device4;
-}
-
-NMDevice *
-nm_policy_get_default_ip6_device (NMPolicy *policy)
-{
-	return NM_POLICY_GET_PRIVATE (policy)->default_device6;
-}
-
-NMDevice *
-nm_policy_get_activating_ip4_device (NMPolicy *policy)
-{
-	return NM_POLICY_GET_PRIVATE (policy)->activating_device4;
-}
-
-NMDevice *
-nm_policy_get_activating_ip6_device (NMPolicy *policy)
-{
-	return NM_POLICY_GET_PRIVATE (policy)->activating_device6;
-}
-
-static void
-nm_policy_init (NMPolicy *policy)
-{
-}
-
-static void
-get_property (GObject *object, guint prop_id,
-              GValue *value, GParamSpec *pspec)
+NMPolicy *
+nm_policy_new (NMManager *manager, NMSettings *settings)
 {
-	NMPolicy *policy = NM_POLICY (object);
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
+	g_return_val_if_fail (NM_IS_SETTINGS (settings), NULL);
 
-	switch (prop_id) {
-	case PROP_DEFAULT_IP4_DEVICE:
-		g_value_set_object (value, priv->default_device4);
-		break;
-	case PROP_DEFAULT_IP6_DEVICE:
-		g_value_set_object (value, priv->default_device6);
-		break;
-	case PROP_ACTIVATING_IP4_DEVICE:
-		g_value_set_object (value, priv->activating_device4);
-		break;
-	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);
-		break;
-	}
+	return g_object_new (NM_TYPE_POLICY,
+	                     NM_POLICY_MANAGER, manager,
+	                     NM_POLICY_SETTINGS, settings,
+	                     NULL);
 }
 
 static void
 dispose (GObject *object)
 {
-	NMPolicy *policy = NM_POLICY (object);
-	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+	NMPolicy *self = NM_POLICY (object);
+	NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
 	const GSList *connections, *iter;
 
-	/* Tell any existing hostname lookup thread to die. */
-	if (priv->lookup_cancellable) {
-		g_cancellable_cancel (priv->lookup_cancellable);
-		g_clear_object (&priv->lookup_cancellable);
-	}
+	nm_clear_g_cancellable (&priv->lookup_cancellable);
+
 	g_clear_object (&priv->lookup_addr);
 	g_clear_object (&priv->resolver);
 
@@ -1876,13 +1928,12 @@ dispose (GObject *object)
 
 	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;
+		nm_clear_g_signal_handler (priv->firewall_manager, &priv->fw_started_id);
 		g_clear_object (&priv->firewall_manager);
 	}
 
 	if (priv->dns_manager) {
-		g_signal_handler_disconnect (priv->dns_manager, priv->config_changed_id);
+		nm_clear_g_signal_handler (priv->dns_manager, &priv->config_changed_id);
 		g_clear_object (&priv->dns_manager);
 	}
 
@@ -1916,6 +1967,8 @@ dispose (GObject *object)
 
 	g_clear_object (&priv->settings);
 
+	nm_assert (NM_IS_MANAGER (priv->manager));
+
 	G_OBJECT_CLASS (nm_policy_parent_class)->dispose (object);
 }
 
@@ -1927,30 +1980,41 @@ nm_policy_class_init (NMPolicyClass *policy_class)
 	g_type_class_add_private (policy_class, sizeof (NMPolicyPrivate));
 
 	object_class->get_property = get_property;
+	object_class->set_property = set_property;
+	object_class->constructed = constructed;
 	object_class->dispose = dispose;
 
-	g_object_class_install_property
-		(object_class, PROP_DEFAULT_IP4_DEVICE,
-		 g_param_spec_object (NM_POLICY_DEFAULT_IP4_DEVICE, "", "",
-		                      NM_TYPE_DEVICE,
-		                      G_PARAM_READABLE |
-		                      G_PARAM_STATIC_STRINGS));
-	g_object_class_install_property
-		(object_class, PROP_DEFAULT_IP6_DEVICE,
-		 g_param_spec_object (NM_POLICY_DEFAULT_IP6_DEVICE, "", "",
-		                      NM_TYPE_DEVICE,
-		                      G_PARAM_READABLE |
-		                      G_PARAM_STATIC_STRINGS));
-	g_object_class_install_property
-		(object_class, PROP_ACTIVATING_IP4_DEVICE,
-		 g_param_spec_object (NM_POLICY_ACTIVATING_IP4_DEVICE, "", "",
-		                      NM_TYPE_DEVICE,
-		                      G_PARAM_READABLE |
-		                      G_PARAM_STATIC_STRINGS));
-	g_object_class_install_property
-		(object_class, PROP_ACTIVATING_IP6_DEVICE,
-		 g_param_spec_object (NM_POLICY_ACTIVATING_IP6_DEVICE, "", "",
-		                      NM_TYPE_DEVICE,
-		                      G_PARAM_READABLE |
-		                      G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_MANAGER] =
+	    g_param_spec_object (NM_POLICY_MANAGER, "", "",
+	                         NM_TYPE_MANAGER,
+	                         G_PARAM_WRITABLE |
+	                         G_PARAM_CONSTRUCT_ONLY |
+	                         G_PARAM_STATIC_STRINGS);
+	obj_properties[PROP_SETTINGS] =
+	    g_param_spec_object (NM_POLICY_SETTINGS, "", "",
+	                         NM_TYPE_SETTINGS,
+	                         G_PARAM_WRITABLE |
+	                         G_PARAM_CONSTRUCT_ONLY |
+	                         G_PARAM_STATIC_STRINGS);
+	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_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_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_DEVICE] =
+	    g_param_spec_object (NM_POLICY_ACTIVATING_IP6_DEVICE, "", "",
+	                         NM_TYPE_DEVICE,
+	                         G_PARAM_READABLE |
+	                         G_PARAM_STATIC_STRINGS);
+	g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
 }