Blame SOURCES/0028-rh1264322-update-vlan-mac-address.patch

ab7d06
From 76d8a405e8eda1d6f23dc2146962000e4fba5062 Mon Sep 17 00:00:00 2001
ab7d06
From: Beniamino Galvani <bgalvani@redhat.com>
ab7d06
Date: Tue, 6 Oct 2015 15:21:29 +0200
ab7d06
Subject: [PATCH] device/vlan: update VLAN MAC address when parent's one
ab7d06
 changes
ab7d06
ab7d06
When a VLAN has a bond as parent device the MAC address of the bond
ab7d06
may change when other devices are enslaved and then the VLAN would
ab7d06
have a MAC which is different from parent's one.
ab7d06
ab7d06
Let the VLAN device listen for changes in hw-address property of
ab7d06
parent and update its MAC address accordingly.
ab7d06
ab7d06
https://bugzilla.redhat.com/show_bug.cgi?id=1264322
ab7d06
(cherry picked from commit e6d7fee5a617632acae02e12b1ec6156842df788)
ab7d06
---
ab7d06
 src/devices/nm-device-vlan.c | 40 ++++++++++++++++++++++++++++++++++++----
ab7d06
 1 file changed, 36 insertions(+), 4 deletions(-)
ab7d06
ab7d06
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
ab7d06
index e523e6b..adfcef3 100644
ab7d06
--- a/src/devices/nm-device-vlan.c
ab7d06
+++ b/src/devices/nm-device-vlan.c
ab7d06
@@ -56,6 +56,7 @@ typedef struct {
ab7d06
 
ab7d06
 	NMDevice *parent;
ab7d06
 	guint parent_state_id;
ab7d06
+	guint parent_hwaddr_id;
ab7d06
 	int vlan_id;
ab7d06
 } NMDeviceVlanPrivate;
ab7d06
 
ab7d06
@@ -88,6 +89,36 @@ parent_state_changed (NMDevice *parent,
ab7d06
 }
ab7d06
 
ab7d06
 static void
ab7d06
+parent_hwaddr_changed (NMDevice *parent,
ab7d06
+                       GParamSpec *pspec,
ab7d06
+                       gpointer user_data)
ab7d06
+{
ab7d06
+	NMDeviceVlan *self = NM_DEVICE_VLAN (user_data);
ab7d06
+	NMConnection *connection;
ab7d06
+	NMSettingWired *s_wired;
ab7d06
+	const char *cloned_mac = NULL;
ab7d06
+
ab7d06
+	/* Never touch assumed devices */
ab7d06
+	if (nm_device_uses_assumed_connection (self))
ab7d06
+		return;
ab7d06
+
ab7d06
+	connection = nm_device_get_connection (self);
ab7d06
+	if (!connection)
ab7d06
+		return;
ab7d06
+
ab7d06
+	/* Update the VLAN MAC only if configuration does not specify one */
ab7d06
+	s_wired = nm_connection_get_setting_wired (connection);
ab7d06
+	if (s_wired)
ab7d06
+		cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
ab7d06
+
ab7d06
+	if (!cloned_mac) {
ab7d06
+		_LOGD (LOGD_VLAN, "parent hardware address changed");
ab7d06
+		nm_device_set_hw_addr (self, nm_device_get_hw_address (parent),
ab7d06
+		                       "set", LOGD_VLAN);
ab7d06
+	}
ab7d06
+}
ab7d06
+
ab7d06
+static void
ab7d06
 nm_device_vlan_set_parent (NMDeviceVlan *self, NMDevice *parent, gboolean construct)
ab7d06
 {
ab7d06
 	NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
ab7d06
@@ -96,10 +127,8 @@ nm_device_vlan_set_parent (NMDeviceVlan *self, NMDevice *parent, gboolean constr
ab7d06
 	if (parent == priv->parent)
ab7d06
 		return;
ab7d06
 
ab7d06
-	if (priv->parent_state_id) {
ab7d06
-		g_signal_handler_disconnect (priv->parent, priv->parent_state_id);
ab7d06
-		priv->parent_state_id = 0;
ab7d06
-	}
ab7d06
+	nm_clear_g_signal_handler (priv->parent, &priv->parent_state_id);
ab7d06
+	nm_clear_g_signal_handler (priv->parent, &priv->parent_hwaddr_id);
ab7d06
 	g_clear_object (&priv->parent);
ab7d06
 
ab7d06
 	if (parent) {
ab7d06
@@ -109,6 +138,9 @@ nm_device_vlan_set_parent (NMDeviceVlan *self, NMDevice *parent, gboolean constr
ab7d06
 		                                          G_CALLBACK (parent_state_changed),
ab7d06
 		                                          device);
ab7d06
 
ab7d06
+		priv->parent_hwaddr_id = g_signal_connect (priv->parent, "notify::" NM_DEVICE_HW_ADDRESS,
ab7d06
+		                                           G_CALLBACK (parent_hwaddr_changed), device);
ab7d06
+
ab7d06
 		/* Set parent-dependent unmanaged flag */
ab7d06
 		if (construct) {
ab7d06
 			nm_device_set_initial_unmanaged_flag (device,
ab7d06
-- 
ab7d06
2.4.3
ab7d06