Blame SOURCES/0020-rh1103782-firewall-zone-conflict.patch

708502
From 472dd9aa672de85b49ade5150cbb81497cb8d14d Mon Sep 17 00:00:00 2001
708502
From: Thomas Haller <thaller@redhat.com>
708502
Date: Mon, 2 Jun 2014 12:21:57 +0200
708502
Subject: [PATCH 1/5] firewall: refactor reentrancy for dispose() in
708502
 NMFirewallManager
708502
708502
Signed-off-by: Thomas Haller <thaller@redhat.com>
708502
(cherry picked from commit dde731f0ade88c690b7cf6465c016b9d2343094b)
708502
---
708502
 src/firewall-manager/nm-firewall-manager.c | 17 +++++------------
708502
 1 file changed, 5 insertions(+), 12 deletions(-)
708502
708502
diff --git a/src/firewall-manager/nm-firewall-manager.c b/src/firewall-manager/nm-firewall-manager.c
708502
index 3bf2f24..6d87391 100644
708502
--- a/src/firewall-manager/nm-firewall-manager.c
708502
+++ b/src/firewall-manager/nm-firewall-manager.c
708502
@@ -44,7 +44,6 @@ typedef struct {
708502
 	guint           name_owner_id;
708502
 	DBusGProxy *    proxy;
708502
 	gboolean        running;
708502
-	gboolean        disposed;
708502
 } NMFirewallManagerPrivate;
708502
 
708502
 enum {
708502
@@ -247,7 +246,7 @@ nm_firewall_manager_init (NMFirewallManager * self)
708502
 	NMFirewallManagerPrivate *priv = NM_FIREWALL_MANAGER_GET_PRIVATE (self);
708502
 	DBusGConnection *bus;
708502
 
708502
-	priv->dbus_mgr = nm_dbus_manager_get ();
708502
+	priv->dbus_mgr = g_object_ref (nm_dbus_manager_get ());
708502
 	priv->name_owner_id = g_signal_connect (priv->dbus_mgr,
708502
 	                                        NM_DBUS_MANAGER_NAME_OWNER_CHANGED,
708502
 	                                        G_CALLBACK (name_owner_changed),
708502
@@ -286,20 +285,14 @@ dispose (GObject *object)
708502
 {
708502
 	NMFirewallManagerPrivate *priv = NM_FIREWALL_MANAGER_GET_PRIVATE (object);
708502
 
708502
-	if (priv->disposed)
708502
-		goto out;
708502
-	priv->disposed = TRUE;
708502
-
708502
 	if (priv->dbus_mgr) {
708502
-		if (priv->name_owner_id)
708502
-			g_signal_handler_disconnect (priv->dbus_mgr, priv->name_owner_id);
708502
-		priv->dbus_mgr = NULL;
708502
+		g_signal_handler_disconnect (priv->dbus_mgr, priv->name_owner_id);
708502
+		priv->name_owner_id = 0;
708502
+		g_clear_object (&priv->dbus_mgr);
708502
 	}
708502
 
708502
-	if (priv->proxy)
708502
-		g_object_unref (priv->proxy);
708502
+	g_clear_object (&priv->proxy);
708502
 
708502
-out:
708502
 	/* Chain up to the parent class */
708502
 	G_OBJECT_CLASS (nm_firewall_manager_parent_class)->dispose (object);
708502
 }
708502
-- 
708502
1.9.3
708502
708502
708502
From 3e4ab3a8860d916286ea772e85dfa0432893a6d5 Mon Sep 17 00:00:00 2001
708502
From: Thomas Haller <thaller@redhat.com>
708502
Date: Mon, 2 Jun 2014 15:56:24 +0200
708502
Subject: [PATCH 2/5] firewall: refactor allocation of CBInfo data in
708502
 NMFirewallManager
708502
708502
Signed-off-by: Thomas Haller <thaller@redhat.com>
708502
(cherry picked from commit e3605ab924dd9865ecba9a06de6f5011a9bae3e3)
708502
---
708502
 src/firewall-manager/nm-firewall-manager.c | 21 +++++++++++++++------
708502
 1 file changed, 15 insertions(+), 6 deletions(-)
708502
708502
diff --git a/src/firewall-manager/nm-firewall-manager.c b/src/firewall-manager/nm-firewall-manager.c
708502
index 6d87391..52a5444 100644
708502
--- a/src/firewall-manager/nm-firewall-manager.c
708502
+++ b/src/firewall-manager/nm-firewall-manager.c
708502
@@ -70,6 +70,19 @@ cb_info_free (CBInfo *info)
708502
 	g_free (info);
708502
 }
708502
 
708502
+static CBInfo *
708502
+_cb_info_create (const char *iface, FwAddToZoneFunc callback, gpointer user_data)
708502
+{
708502
+	CBInfo *info;
708502
+
708502
+	info = g_malloc0 (sizeof (CBInfo));
708502
+	info->iface = g_strdup (iface);
708502
+	info->callback = callback;
708502
+	info->user_data = user_data;
708502
+
708502
+	return info;
708502
+}
708502
+
708502
 static void
708502
 add_or_change_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
708502
 {
708502
@@ -113,10 +126,7 @@ nm_firewall_manager_add_or_change_zone (NMFirewallManager *self,
708502
 		return NULL;
708502
 	}
708502
 
708502
-	info = g_malloc0 (sizeof (*info));
708502
-	info->iface = g_strdup (iface);
708502
-	info->callback = callback;
708502
-	info->user_data = user_data;
708502
+	info = _cb_info_create (iface, callback, user_data);
708502
 
708502
 	nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone %s -> %s%s%s", iface, add ? "add" : "change",
708502
 	                           zone?"\"":"", zone ? zone : "default", zone?"\"":"");
708502
@@ -166,8 +176,7 @@ nm_firewall_manager_remove_from_zone (NMFirewallManager *self,
708502
 		return NULL;
708502
 	}
708502
 
708502
-	info = g_malloc0 (sizeof (*info));
708502
-	info->iface = g_strdup (iface);
708502
+	info = _cb_info_create (iface, NULL, NULL);
708502
 
708502
 	nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove -> %s", iface, zone );
708502
 	return dbus_g_proxy_begin_call_with_timeout (priv->proxy,
708502
-- 
708502
1.9.3
708502
708502
708502
From 28732c8a3589395975ec6113f1fe2bb925acf72c Mon Sep 17 00:00:00 2001
708502
From: Thomas Haller <thaller@redhat.com>
708502
Date: Mon, 2 Jun 2014 17:52:33 +0200
708502
Subject: [PATCH 3/5] firewall: extend logging to show id for async dbus calls
708502
 in NMFirewallManager
708502
708502
Signed-off-by: Thomas Haller <thaller@redhat.com>
708502
(cherry picked from commit 3bc38ad531b9976577e543229125d7d8274efe82)
708502
---
708502
 src/firewall-manager/nm-firewall-manager.c | 43 +++++++++++++++++++++++-------
708502
 1 file changed, 33 insertions(+), 10 deletions(-)
708502
708502
diff --git a/src/firewall-manager/nm-firewall-manager.c b/src/firewall-manager/nm-firewall-manager.c
708502
index 52a5444..c99372a 100644
708502
--- a/src/firewall-manager/nm-firewall-manager.c
708502
+++ b/src/firewall-manager/nm-firewall-manager.c
708502
@@ -60,12 +60,18 @@ typedef struct {
708502
 	char *iface;
708502
 	FwAddToZoneFunc callback;
708502
 	gpointer user_data;
708502
+	guint id;
708502
+	gboolean completed;
708502
 } CBInfo;
708502
 
708502
 static void
708502
 cb_info_free (CBInfo *info)
708502
 {
708502
 	g_return_if_fail (info != NULL);
708502
+
708502
+	if (!info->completed)
708502
+		nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone call cancelled [%u]", info->iface, info->id);
708502
+
708502
 	g_free (info->iface);
708502
 	g_free (info);
708502
 }
708502
@@ -73,10 +79,15 @@ cb_info_free (CBInfo *info)
708502
 static CBInfo *
708502
 _cb_info_create (const char *iface, FwAddToZoneFunc callback, gpointer user_data)
708502
 {
708502
+	static guint id;
708502
 	CBInfo *info;
708502
 
708502
-	info = g_malloc0 (sizeof (CBInfo));
708502
+	info = g_malloc (sizeof (CBInfo));
708502
+	if (++id == 0)
708502
+		++id;
708502
+	info->id = id;
708502
 	info->iface = g_strdup (iface);
708502
+	info->completed = FALSE;
708502
 	info->callback = callback;
708502
 	info->user_data = user_data;
708502
 
708502
@@ -95,16 +106,20 @@ add_or_change_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data
708502
 	                            G_TYPE_INVALID)) {
708502
 		g_assert (error);
708502
 		if (g_strcmp0 (error->message, "ZONE_ALREADY_SET") != 0) {
708502
-			nm_log_warn (LOGD_FIREWALL, "(%s) firewall zone add/change failed: (%d) %s",
708502
-			             info->iface, error->code, error->message);
708502
+			nm_log_warn (LOGD_FIREWALL, "(%s) firewall zone add/change failed [%u]: (%d) %s",
708502
+			             info->iface, info->id, error->code, error->message);
708502
 		} else {
708502
-			nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone add/change failed: (%d) %s",
708502
-			            info->iface, error->code, error->message);
708502
+			nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone add/change failed [%u]: (%d) %s",
708502
+			            info->iface, info->id, error->code, error->message);
708502
 		}
708502
+	} else {
708502
+		nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone add/change succeeded [%u]",
708502
+		            info->iface, info->id);
708502
 	}
708502
 
708502
 	info->callback (error, info->user_data);
708502
 
708502
+	info->completed = TRUE;
708502
 	g_free (zone);
708502
 	g_clear_error (&error);
708502
 }
708502
@@ -128,8 +143,8 @@ nm_firewall_manager_add_or_change_zone (NMFirewallManager *self,
708502
 
708502
 	info = _cb_info_create (iface, callback, user_data);
708502
 
708502
-	nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone %s -> %s%s%s", iface, add ? "add" : "change",
708502
-	                           zone?"\"":"", zone ? zone : "default", zone?"\"":"");
708502
+	nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone %s -> %s%s%s [%u]", iface, add ? "add" : "change",
708502
+	                           zone?"\"":"", zone ? zone : "default", zone?"\"":"", info->id);
708502
 	return dbus_g_proxy_begin_call_with_timeout (priv->proxy,
708502
 	                                             add ? "addInterface" : "changeZone",
708502
 	                                             add_or_change_cb,
708502
@@ -154,11 +169,18 @@ remove_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
708502
 		g_assert (error);
708502
 		/* ignore UNKNOWN_INTERFACE errors */
708502
 		if (error->message && !strstr (error->message, "UNKNOWN_INTERFACE")) {
708502
-			nm_log_warn (LOGD_FIREWALL, "(%s) firewall zone remove failed: (%d) %s",
708502
-			             info->iface, error->code, error->message);
708502
+			nm_log_warn (LOGD_FIREWALL, "(%s) firewall zone remove failed [%u]: (%d) %s",
708502
+			             info->iface, info->id, error->code, error->message);
708502
+		} else {
708502
+			nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove failed [%u]: (%d) %s",
708502
+			            info->iface, info->id, error->code, error->message);
708502
 		}
708502
+	} else {
708502
+		nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove succeeded [%u]",
708502
+		            info->iface, info->id);
708502
 	}
708502
 
708502
+	info->completed = TRUE;
708502
 	g_free (zone);
708502
 	g_clear_error (&error);
708502
 }
708502
@@ -178,7 +200,8 @@ nm_firewall_manager_remove_from_zone (NMFirewallManager *self,
708502
 
708502
 	info = _cb_info_create (iface, NULL, NULL);
708502
 
708502
-	nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove -> %s", iface, zone );
708502
+	nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove -> %s%s%s [%u]", iface,
708502
+	                           zone?"\"":"", zone ? zone : "*", zone?"\"":"", info->id);
708502
 	return dbus_g_proxy_begin_call_with_timeout (priv->proxy,
708502
 	                                             "removeInterface",
708502
 	                                             remove_cb,
708502
-- 
708502
1.9.3
708502
708502
708502
From 342f9f90dbbea28d02dd7a5058c1caea7817142c Mon Sep 17 00:00:00 2001
708502
From: Thomas Haller <thaller@redhat.com>
708502
Date: Mon, 2 Jun 2014 18:11:54 +0200
708502
Subject: [PATCH 4/5] firewall: fix ZONE_CONFLICT when removing interface from
708502
 zone
708502
708502
The firewalld removeInterface call fails with ZONE_CONFLICT when
708502
removing an interface from a wrong zone. This can happen, when the
708502
connection gets modified, while being active (which is related to
708502
bgo#724041).
708502
708502
By not specifying any zone, we remove the interface from the zone
708502
where it currently is added. This behavior was introduced in upstream
708502
firewalld with commit cc3101ab70a3997228be7bc9f45a069c7fccfa36, March 2012,
708502
r0_2_3-1.
708502
This is the behavior we actually want and we don't have to keep proper track
708502
of the current zone.
708502
708502
https://bugzilla.redhat.com/show_bug.cgi?id=1103782
708502
708502
Signed-off-by: Thomas Haller <thaller@redhat.com>
708502
(cherry picked from commit c598336de8d5a257765bf415b87e2bb7a1140b7d)
708502
---
708502
 src/devices/nm-device.c | 4 +---
708502
 1 file changed, 1 insertion(+), 3 deletions(-)
708502
708502
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
708502
index 8399cf6..dd0ea5a 100644
708502
--- a/src/devices/nm-device.c
708502
+++ b/src/devices/nm-device.c
708502
@@ -4912,7 +4912,6 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason)
708502
 	NMDevicePrivate *priv;
708502
 	NMDeviceStateReason ignored = NM_DEVICE_STATE_REASON_NONE;
708502
 	NMConnection *connection = NULL;
708502
-	NMSettingConnection *s_con = NULL;
708502
 	int ifindex;
708502
 
708502
 	g_return_if_fail (NM_IS_DEVICE (self));
708502
@@ -4937,10 +4936,9 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason)
708502
 	if (priv->act_request)
708502
 		connection = nm_act_request_get_connection (priv->act_request);
708502
 	if (connection) {
708502
-		s_con = nm_connection_get_setting_connection (connection);
708502
 		nm_firewall_manager_remove_from_zone (priv->fw_manager,
708502
 		                                      nm_device_get_ip_iface (self),
708502
-		                                      nm_setting_connection_get_zone (s_con));
708502
+		                                      NULL);
708502
 	}
708502
 
708502
 	ip_check_gw_ping_cleanup (self);
708502
-- 
708502
1.9.3
708502
708502
708502
From cda973fe9c83ea415d3178973ff7826904b2997f Mon Sep 17 00:00:00 2001
708502
From: Thomas Haller <thaller@redhat.com>
708502
Date: Tue, 3 Jun 2014 08:58:20 +0200
708502
Subject: [PATCH 5/5] firewall: fix ZONE_CONFLICT when adding firewall
708502
 interface to zone
708502
708502
Firewalld call addInterface() fails with ZONE_CONFLICT if the interface
708502
is already part of another zone. This complicates the code in NM,
708502
because we would have to keep better track of the zone in which the
708502
interface currently is. Which might be quite difficult because
708502
the zone might be changed from an external program (so we would have
708502
to monitor the firewall configuration and work around potential races).
708502
708502
A better and simpler fix is to simply always use the changeZone() call.
708502
This will do the right thing, regardless if the interface is already part
708502
of a zone or not.
708502
708502
https://bugzilla.redhat.com/show_bug.cgi?id=1103782
708502
708502
Signed-off-by: Thomas Haller <thaller@redhat.com>
708502
(cherry picked from commit c29388bf028d404066e46ea55abc4058abce4078)
708502
---
708502
 src/devices/nm-device.c | 6 +++---
708502
 src/nm-policy.c         | 2 +-
708502
 2 files changed, 4 insertions(+), 4 deletions(-)
708502
708502
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
708502
index dd0ea5a..264d4ab 100644
708502
--- a/src/devices/nm-device.c
708502
+++ b/src/devices/nm-device.c
708502
@@ -4023,7 +4023,7 @@ out:
708502
 
708502
 
708502
 static void
708502
-fw_add_to_zone_cb (GError *error, gpointer user_data)
708502
+fw_change_zone_cb (GError *error, gpointer user_data)
708502
 {
708502
 	NMDevice *self = NM_DEVICE (user_data);
708502
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
708502
@@ -4072,8 +4072,8 @@ nm_device_activate_schedule_stage3_ip_config_start (NMDevice *self)
708502
 	priv->fw_call = nm_firewall_manager_add_or_change_zone (priv->fw_manager,
708502
 	                                                        nm_device_get_ip_iface (self),
708502
 	                                                        zone,
708502
-	                                                        TRUE,
708502
-	                                                        fw_add_to_zone_cb,
708502
+	                                                        FALSE,
708502
+	                                                        fw_change_zone_cb,
708502
 	                                                        self);
708502
 }
708502
 
708502
diff --git a/src/nm-policy.c b/src/nm-policy.c
708502
index b412427..f064fa0 100644
708502
--- a/src/nm-policy.c
708502
+++ b/src/nm-policy.c
708502
@@ -1886,7 +1886,7 @@ firewall_started (NMFirewallManager *manager,
708502
 			nm_firewall_manager_add_or_change_zone (priv->fw_manager,
708502
 			                                        nm_device_get_ip_iface (dev),
708502
 			                                        nm_setting_connection_get_zone (s_con),
708502
-			                                        TRUE, /* add zone */
708502
+			                                        FALSE, /* still change zone */
708502
 			                                        add_or_change_zone_cb,
708502
 			                                        g_object_ref (dev));
708502
 		}
708502
-- 
708502
1.9.3
708502