From 94fea0b581ef3b01f78de59faac883ec16bb39b4 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 7 Sep 2015 12:02:54 +0200 Subject: [PATCH] policy: refactor handling of UPDATED signal Obtain a reference to the device in connection_updated() so that it will be easier to call other functions needing it. --- src/nm-policy.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/nm-policy.c b/src/nm-policy.c index b01110bfbb..b22608b530 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1563,26 +1563,19 @@ add_or_change_zone_cb (GError *error, gpointer user_data) } static void -firewall_update_zone (NMPolicy *policy, NMConnection *connection) +firewall_update_zone (NMPolicy *policy, NMConnection *connection, NMDevice *device) { 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 (priv->firewall_manager, - 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)); - } + if ( nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED + && !nm_device_uses_assumed_connection (device)) { + nm_firewall_manager_add_or_change_zone (priv->firewall_manager, + nm_device_get_ip_iface (device), + nm_setting_connection_get_zone (s_con), + FALSE, /* change zone */ + add_or_change_zone_cb, + g_object_ref (device)); } } @@ -1656,8 +1649,22 @@ connection_updated (NMSettings *settings, gpointer user_data) { NMPolicy *policy = (NMPolicy *) user_data; + NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy); + const GSList *iter; + NMDevice *device = NULL; - firewall_update_zone (policy, connection); + /* 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_connection (dev) == connection) { + device = dev; + break; + } + } + + if (device) + firewall_update_zone (policy, connection, device); schedule_activate_all (policy); }