Blame SOURCES/rh1083196-match-connections-and-s390.patch

708502
From d12b2079bf6508f71a2c6088de1ea1a4d7ae9106 Mon Sep 17 00:00:00 2001
708502
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com>
708502
Date: Wed, 9 Apr 2014 13:48:27 +0200
708502
Subject: [PATCH 1/5] utils: fix check_possible_match() function
708502
MIME-Version: 1.0
708502
Content-Type: text/plain; charset=UTF-8
708502
Content-Transfer-Encoding: 8bit
708502
708502
We can only allow possible match if all the differences are exceptions.
708502
Before, we accepted the connection if an exception was found, but it is wrong
708502
because there may be another difference (that is fatal).
708502
708502
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
708502
---
708502
 src/NetworkManagerUtils.c | 139 ++++++++++++++++++++++++----------------------
708502
 1 file changed, 74 insertions(+), 65 deletions(-)
708502
708502
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
708502
index 17116ee..e0a232e 100644
708502
--- a/src/NetworkManagerUtils.c
708502
+++ b/src/NetworkManagerUtils.c
708502
@@ -649,22 +649,47 @@ nm_utils_read_resolv_conf_nameservers (const char *rc_contents)
708502
 	return nameservers;
708502
 }
708502
 
708502
+static GHashTable *
708502
+check_property_in_hash (GHashTable *hash,
708502
+                        const char *s_name,
708502
+                        const char *p_name)
708502
+{
708502
+	GHashTable *props;
708502
+
708502
+	props = g_hash_table_lookup (hash, s_name);
708502
+	if (   !props
708502
+	    || !g_hash_table_lookup (props, p_name)) {
708502
+		return NULL;
708502
+	}
708502
+	return props;
708502
+}
708502
+
708502
+static void
708502
+remove_from_hash (GHashTable *s_hash,
708502
+                  GHashTable *p_hash,
708502
+                  const char *s_name,
708502
+                  const char *p_name)
708502
+{
708502
+	g_hash_table_remove (p_hash, p_name);
708502
+	if (g_hash_table_size (p_hash) == 0)
708502
+		g_hash_table_remove (s_hash, s_name);
708502
+}
708502
+
708502
 static gboolean
708502
-check_ip6_method_link_local_auto (NMConnection *orig,
708502
-                                  NMConnection *candidate,
708502
-                                  GHashTable *settings)
708502
+check_ip6_method (NMConnection *orig,
708502
+                  NMConnection *candidate,
708502
+                  GHashTable *settings)
708502
 {
708502
 	GHashTable *props;
708502
 	const char *orig_ip6_method, *candidate_ip6_method;
708502
 	NMSettingIP6Config *candidate_ip6;
708502
+	gboolean allow = FALSE;
708502
 
708502
-	props = g_hash_table_lookup (settings, NM_SETTING_IP6_CONFIG_SETTING_NAME);
708502
-	if (   !props
708502
-	    || (g_hash_table_size (props) != 1)
708502
-	    || !g_hash_table_lookup (props, NM_SETTING_IP6_CONFIG_METHOD)) {
708502
-		/* For now 'method' is the only difference we handle here */
708502
-		return FALSE;
708502
-	}
708502
+	props = check_property_in_hash (settings,
708502
+	                                NM_SETTING_IP6_CONFIG_SETTING_NAME,
708502
+	                                NM_SETTING_IP6_CONFIG_METHOD);
708502
+	if (!props)
708502
+		return TRUE;
708502
 
708502
 	/* If the original connection is 'link-local' and the candidate is both 'auto'
708502
 	 * and may-fail=TRUE, then the candidate is OK to use.  may-fail is included
708502
@@ -679,60 +704,41 @@ check_ip6_method_link_local_auto (NMConnection *orig,
708502
 	if (   strcmp (orig_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0
708502
 	    && strcmp (candidate_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0
708502
 	    && (!candidate_ip6 || nm_setting_ip6_config_get_may_fail (candidate_ip6))) {
708502
-		return TRUE;
708502
-	}
708502
-
708502
-	return FALSE;
708502
-}
708502
-
708502
-static gboolean
708502
-check_ip6_method_link_local_ignore (NMConnection *orig,
708502
-                                    NMConnection *candidate,
708502
-                                    GHashTable *settings)
708502
-{
708502
-	GHashTable *props;
708502
-	const char *orig_ip6_method, *candidate_ip6_method;
708502
-
708502
-	props = g_hash_table_lookup (settings, NM_SETTING_IP6_CONFIG_SETTING_NAME);
708502
-	if (   !props
708502
-	    || (g_hash_table_size (props) != 1)
708502
-	    || !g_hash_table_lookup (props, NM_SETTING_IP6_CONFIG_METHOD)) {
708502
-		/* We only handle ipv6 'method' here */
708502
-		return FALSE;
708502
+		allow = TRUE;
708502
 	}
708502
 
708502
 	/* If the original connection method is 'link-local' and the candidate method
708502
 	 * is 'ignore' we can take the connection, because NM didn't simply take care
708502
 	 * of IPv6.
708502
 	 */
708502
-	orig_ip6_method = nm_utils_get_ip_config_method (orig, NM_TYPE_SETTING_IP6_CONFIG);
708502
-	candidate_ip6_method = nm_utils_get_ip_config_method (candidate, NM_TYPE_SETTING_IP6_CONFIG);
708502
-
708502
 	if (   strcmp (orig_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0
708502
 	    && strcmp (candidate_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) {
708502
-		return TRUE;
708502
+		allow = TRUE;
708502
 	}
708502
 
708502
-	return FALSE;
708502
+	if (allow) {
708502
+		remove_from_hash (settings, props,
708502
+		                  NM_SETTING_IP6_CONFIG_SETTING_NAME,
708502
+		                  NM_SETTING_IP6_CONFIG_METHOD);
708502
+	}
708502
+	return allow;
708502
 }
708502
 
708502
 static gboolean
708502
-check_ip4_method_disabled_auto (NMConnection *orig,
708502
-                                NMConnection *candidate,
708502
-                                GHashTable *settings,
708502
-                                gboolean device_has_carrier)
708502
+check_ip4_method (NMConnection *orig,
708502
+                  NMConnection *candidate,
708502
+                  GHashTable *settings,
708502
+                  gboolean device_has_carrier)
708502
 {
708502
 	GHashTable *props;
708502
 	const char *orig_ip4_method, *candidate_ip4_method;
708502
 	NMSettingIP4Config *candidate_ip4;
708502
 
708502
-	props = g_hash_table_lookup (settings, NM_SETTING_IP4_CONFIG_SETTING_NAME);
708502
-	if (   !props
708502
-	    || (g_hash_table_size (props) != 1)
708502
-	    || !g_hash_table_lookup (props, NM_SETTING_IP4_CONFIG_METHOD)) {
708502
-		/* For now 'method' is the only difference we handle here */
708502
-		return FALSE;
708502
-	}
708502
+	props = check_property_in_hash (settings,
708502
+	                                NM_SETTING_IP4_CONFIG_SETTING_NAME,
708502
+	                                NM_SETTING_IP4_CONFIG_METHOD);
708502
+	if (!props)
708502
+		return TRUE;
708502
 
708502
 	/* If the original connection is 'disabled' (device had no IP addresses)
708502
 	 * but it has no carrier, that most likely means that IP addressing could
708502
@@ -747,9 +753,11 @@ check_ip4_method_disabled_auto (NMConnection *orig,
708502
 	    && strcmp (candidate_ip4_method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0
708502
 	    && (!candidate_ip4 || nm_setting_ip4_config_get_may_fail (candidate_ip4))
708502
 	    && (device_has_carrier == FALSE)) {
708502
+		remove_from_hash (settings, props,
708502
+		                  NM_SETTING_IP4_CONFIG_SETTING_NAME,
708502
+		                  NM_SETTING_IP4_CONFIG_METHOD);
708502
 		return TRUE;
708502
 	}
708502
-
708502
 	return FALSE;
708502
 }
708502
 
708502
@@ -762,13 +770,11 @@ check_connection_interface_name (NMConnection *orig,
708502
 	const char *orig_ifname, *cand_ifname;
708502
 	NMSettingConnection *s_con_orig, *s_con_cand;
708502
 
708502
-	props = g_hash_table_lookup (settings, NM_SETTING_CONNECTION_SETTING_NAME);
708502
-	if (   !props
708502
-	    || (g_hash_table_size (props) != 1)
708502
-	    || !g_hash_table_lookup (props, NM_SETTING_CONNECTION_INTERFACE_NAME)) {
708502
-		/* We only handle 'interface-name' here. */
708502
-		return FALSE;
708502
-	}
708502
+	props = check_property_in_hash (settings,
708502
+	                                NM_SETTING_CONNECTION_SETTING_NAME,
708502
+	                                NM_SETTING_CONNECTION_INTERFACE_NAME);
708502
+	if (!props)
708502
+		return TRUE;
708502
 
708502
 	/* If one of the interface name is NULL, we accept that connection */
708502
 	s_con_orig = nm_connection_get_setting_connection (orig);
708502
@@ -776,9 +782,12 @@ check_connection_interface_name (NMConnection *orig,
708502
 	orig_ifname = nm_setting_connection_get_interface_name (s_con_orig);
708502
 	cand_ifname = nm_setting_connection_get_interface_name (s_con_cand);
708502
 
708502
-	if (!orig_ifname || !cand_ifname)
708502
+	if (!orig_ifname || !cand_ifname) {
708502
+		remove_from_hash (settings, props,
708502
+		                  NM_SETTING_CONNECTION_SETTING_NAME,
708502
+		                  NM_SETTING_CONNECTION_INTERFACE_NAME);
708502
 		return TRUE;
708502
-
708502
+	}
708502
 	return FALSE;
708502
 }
708502
 
708502
@@ -790,19 +799,19 @@ check_possible_match (NMConnection *orig,
708502
 {
708502
 	g_return_val_if_fail (settings != NULL, NULL);
708502
 
708502
-	if (check_ip6_method_link_local_auto (orig, candidate, settings))
708502
-		return candidate;
708502
+	if (!check_ip6_method (orig, candidate, settings))
708502
+		return NULL;
708502
 
708502
-	if (check_ip6_method_link_local_ignore (orig, candidate, settings))
708502
-		return candidate;
708502
+	if (!check_ip4_method (orig, candidate, settings, device_has_carrier))
708502
+		return NULL;
708502
 
708502
-	if (check_ip4_method_disabled_auto (orig, candidate, settings, device_has_carrier))
708502
-		return candidate;
708502
+	if (!check_connection_interface_name (orig, candidate, settings))
708502
+		return NULL;
708502
 
708502
-	if (check_connection_interface_name (orig, candidate, settings))
708502
+	if (g_hash_table_size (settings) == 0)
708502
 		return candidate;
708502
-
708502
-	return NULL;
708502
+	else
708502
+		return NULL;
708502
 }
708502
 
708502
 /**
708502
-- 
708502
1.7.11.7
708502
708502
708502
From 1301995202308842c572b2f543f95b37142926d0 Mon Sep 17 00:00:00 2001
708502
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com>
708502
Date: Mon, 7 Apr 2014 15:25:09 +0200
708502
Subject: [PATCH 2/5] device: add s390 values to connection in
708502
 update_connection() (rh #1083196)
708502
MIME-Version: 1.0
708502
Content-Type: text/plain; charset=UTF-8
708502
Content-Transfer-Encoding: 8bit
708502
708502
708502
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
708502
---
708502
 src/devices/nm-device-ethernet.c | 110 +++++++++++++++++++++++++++------------
708502
 1 file changed, 78 insertions(+), 32 deletions(-)
708502
708502
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
708502
index e6f091d..920d255 100644
708502
--- a/src/devices/nm-device-ethernet.c
708502
+++ b/src/devices/nm-device-ethernet.c
708502
@@ -15,7 +15,7 @@
708502
  * with this program; if not, write to the Free Software Foundation, Inc.,
708502
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
708502
  *
708502
- * Copyright (C) 2005 - 2013 Red Hat, Inc.
708502
+ * Copyright (C) 2005 - 2014 Red Hat, Inc.
708502
  * Copyright (C) 2006 - 2008 Novell, Inc.
708502
  */
708502
 
708502
@@ -114,6 +114,8 @@ typedef struct {
708502
 	char *              subchan2;
708502
 	char *              subchan3;
708502
 	char *              subchannels; /* Composite used for checking unmanaged specs */
708502
+	char *              s390_nettype;
708502
+	GHashTable *        s390_options;
708502
 
708502
 	/* PPPoE */
708502
 	NMPPPManager *ppp_manager;
708502
@@ -145,6 +147,25 @@ nm_ethernet_error_quark (void)
708502
 	return quark;
708502
 }
708502
 
708502
+static char *
708502
+get_link_basename (const char *parent_path, const char *name, GError **error)
708502
+{
708502
+	char buf[128];
708502
+	char *path;
708502
+	char *result = NULL;
708502
+
708502
+	path = g_strdup_printf ("%s/%s", parent_path, name);
708502
+
708502
+	memset (buf, 0, sizeof (buf));
708502
+	errno = 0;
708502
+	if (readlink (path, &buf[0], sizeof (buf) - 1) >= 0)
708502
+		result = g_path_get_basename (buf);
708502
+	else
708502
+		g_set_error (error, 0, 1, "failed to read link '%s': %d", path, errno);
708502
+	g_free (path);
708502
+	return result;
708502
+}
708502
+
708502
 static void
708502
 _update_s390_subchannels (NMDeviceEthernet *self)
708502
 {
708502
@@ -192,34 +213,33 @@ _update_s390_subchannels (NMDeviceEthernet *self)
708502
 		goto out;
708502
 	}
708502
 
708502
-	/* FIXME: we probably care about ordering here to ensure that we map
708502
-	 * cdev0 -> subchan1, cdev1 -> subchan2, etc.
708502
-	 */
708502
 	while ((item = g_dir_read_name (dir))) {
708502
-		char buf[50];
708502
-		char *cdev_path;
708502
-
708502
-		if (strncmp (item, "cdev", 4))
708502
-			continue;  /* Not a subchannel link */
708502
-
708502
-		cdev_path = g_strdup_printf ("%s/%s", parent_path, item);
708502
-
708502
-		memset (buf, 0, sizeof (buf));
708502
-		errno = 0;
708502
-		if (readlink (cdev_path, &buf[0], sizeof (buf) - 1) >= 0) {
708502
-			if (!priv->subchan1)
708502
-				priv->subchan1 = g_path_get_basename (buf);
708502
-			else if (!priv->subchan2)
708502
-				priv->subchan2 = g_path_get_basename (buf);
708502
-			else if (!priv->subchan3)
708502
-				priv->subchan3 = g_path_get_basename (buf);
708502
-		} else {
708502
-			nm_log_warn (LOGD_DEVICE | LOGD_HW,
708502
-			             "(%s): failed to read cdev link '%s': %d",
708502
-			             iface, cdev_path, errno);
708502
+		if (!strcmp (item, "cdev0")) {
708502
+			priv->subchan1 = get_link_basename (parent_path, "cdev0", &error);
708502
+		} else if (!strcmp (item, "cdev1")) {
708502
+			priv->subchan2 = get_link_basename (parent_path, "cdev1", &error);
708502
+		} else if (!strcmp (item, "cdev2")) {
708502
+			priv->subchan3 = get_link_basename (parent_path, "cdev2", &error);
708502
+		} else if (!strcmp (item, "driver")) {
708502
+			priv->s390_nettype = get_link_basename (parent_path, "driver", &error);
708502
+		} else if (   !strcmp (item, "layer2")
708502
+		           || !strcmp (item, "portname")
708502
+		           || !strcmp (item, "portno")) {
708502
+			char *path, *value;
708502
+			path = g_strdup_printf ("%s/%s", parent_path, item);
708502
+			value = nm_platform_sysctl_get (path);
708502
+			if (value && *value)
708502
+				g_hash_table_insert (priv->s390_options, g_strdup (item), g_strdup (value));
708502
+			else
708502
+				nm_log_warn (LOGD_DEVICE | LOGD_HW, "(%s): error reading %s", iface, path);
708502
+			g_free (path);
708502
+			g_free (value);
708502
 		}
708502
-		g_free (cdev_path);
708502
-	};
708502
+		if (error) {
708502
+			nm_log_warn (LOGD_DEVICE | LOGD_HW, "(%s): %s", iface, error->message);
708502
+			g_clear_error (&error);
708502
+		}
708502
+	}
708502
 
708502
 	g_dir_close (dir);
708502
 
708502
@@ -250,8 +270,8 @@ out:
708502
 
708502
 static GObject*
708502
 constructor (GType type,
708502
-			 guint n_construct_params,
708502
-			 GObjectConstructParam *construct_params)
708502
+             guint n_construct_params,
708502
+             GObjectConstructParam *construct_params)
708502
 {
708502
 	GObject *object;
708502
 	NMDevice *self;
708502
@@ -268,8 +288,8 @@ constructor (GType type,
708502
 		          || nm_platform_link_get_type (ifindex) == NM_LINK_TYPE_VETH);
708502
 
708502
 		nm_log_dbg (LOGD_HW | LOGD_ETHER, "(%s): kernel ifindex %d",
708502
-			        nm_device_get_iface (NM_DEVICE (self)),
708502
-			        nm_device_get_ifindex (NM_DEVICE (self)));
708502
+		            nm_device_get_iface (NM_DEVICE (self)),
708502
+		            nm_device_get_ifindex (NM_DEVICE (self)));
708502
 
708502
 		/* s390 stuff */
708502
 		_update_s390_subchannels (NM_DEVICE_ETHERNET (self));
708502
@@ -305,8 +325,10 @@ device_state_changed (NMDevice *device,
708502
 }
708502
 
708502
 static void
708502
-nm_device_ethernet_init (NMDeviceEthernet * self)
708502
+nm_device_ethernet_init (NMDeviceEthernet *self)
708502
 {
708502
+	NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
708502
+	priv->s390_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
708502
 }
708502
 
708502
 NMDevice *
708502
@@ -1543,6 +1565,8 @@ update_connection (NMDevice *device, NMConnection *connection)
708502
 	static const guint8 null_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
708502
 	const char *mac_prop = NM_SETTING_WIRED_MAC_ADDRESS;
708502
 	GByteArray *array;
708502
+	GHashTableIter iter;
708502
+	gpointer key, value;
708502
 
708502
 	if (!s_wired) {
708502
 		s_wired = (NMSettingWired *) nm_setting_wired_new ();
708502
@@ -1571,6 +1595,26 @@ update_connection (NMDevice *device, NMConnection *connection)
708502
 	}
708502
 
708502
 	/* We don't set the MTU as we don't know whether it was set explicitly */
708502
+
708502
+	/* s390 */
708502
+	if (priv->subchannels) {
708502
+		GPtrArray *subchan_arr = g_ptr_array_sized_new (3);
708502
+		if (priv->subchan1)
708502
+			 g_ptr_array_add (subchan_arr, priv->subchan1);
708502
+		if (priv->subchan2)
708502
+			 g_ptr_array_add (subchan_arr, priv->subchan2);
708502
+		if (priv->subchan3)
708502
+			 g_ptr_array_add (subchan_arr, priv->subchan3);
708502
+		g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, subchan_arr, NULL);
708502
+		g_ptr_array_free (subchan_arr, TRUE);
708502
+	}
708502
+	if (priv->s390_nettype)
708502
+		g_object_set (s_wired, NM_SETTING_WIRED_S390_NETTYPE, priv->s390_nettype, NULL);
708502
+	g_hash_table_iter_init (&iter, priv->s390_options);
708502
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
708502
+		nm_setting_wired_add_s390_option (s_wired, (const char *) key, (const char *) value);
708502
+	}
708502
+
708502
 }
708502
 
708502
 static void
708502
@@ -1638,6 +1682,8 @@ dispose (GObject *object)
708502
 	g_free (priv->subchan2);
708502
 	g_free (priv->subchan3);
708502
 	g_free (priv->subchannels);
708502
+	g_free (priv->s390_nettype);
708502
+	g_hash_table_destroy (priv->s390_options);
708502
 
708502
 	if (priv->pppoe_wait_id) {
708502
 		g_source_remove (priv->pppoe_wait_id);
708502
-- 
708502
1.7.11.7
708502
708502
708502
From 7251e4ea22f0a281da87e0d1c28c3405bf75068a Mon Sep 17 00:00:00 2001
708502
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com>
708502
Date: Tue, 8 Apr 2014 10:49:16 +0200
708502
Subject: [PATCH 3/5] utils: allow matching connections with no MAC (missing
708502
 HWADDR) (rh #1083196)
708502
MIME-Version: 1.0
708502
Content-Type: text/plain; charset=UTF-8
708502
Content-Transfer-Encoding: 8bit
708502
708502
708502
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
708502
---
708502
 src/NetworkManagerUtils.c | 33 +++++++++++++++++++++++++++++++++
708502
 1 file changed, 33 insertions(+)
708502
708502
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
708502
index e0a232e..52b7c43 100644
708502
--- a/src/NetworkManagerUtils.c
708502
+++ b/src/NetworkManagerUtils.c
708502
@@ -791,6 +791,36 @@ check_connection_interface_name (NMConnection *orig,
708502
 	return FALSE;
708502
 }
708502
 
708502
+static gboolean
708502
+check_connection_mac_address (NMConnection *orig,
708502
+                              NMConnection *candidate,
708502
+                              GHashTable *settings)
708502
+{
708502
+	GHashTable *props;
708502
+	const GByteArray *orig_mac, *cand_mac;
708502
+	NMSettingWired *s_wired_orig, *s_wired_cand;
708502
+
708502
+	props = check_property_in_hash (settings,
708502
+	                                NM_SETTING_WIRED_SETTING_NAME,
708502
+	                                NM_SETTING_WIRED_MAC_ADDRESS);
708502
+	if (!props)
708502
+		return TRUE;
708502
+
708502
+	/* If one of the MAC addresses is NULL, we accept that connection */
708502
+	s_wired_orig = nm_connection_get_setting_wired (orig);
708502
+	s_wired_cand = nm_connection_get_setting_wired (candidate);
708502
+	orig_mac = nm_setting_wired_get_mac_address (s_wired_orig);
708502
+	cand_mac = nm_setting_wired_get_mac_address (s_wired_cand);
708502
+
708502
+	if (!orig_mac || !cand_mac) {
708502
+		remove_from_hash (settings, props,
708502
+		                  NM_SETTING_WIRED_SETTING_NAME,
708502
+		                  NM_SETTING_WIRED_MAC_ADDRESS);
708502
+		return TRUE;
708502
+	}
708502
+	return FALSE;
708502
+}
708502
+
708502
 static NMConnection *
708502
 check_possible_match (NMConnection *orig,
708502
                       NMConnection *candidate,
708502
@@ -808,6 +838,9 @@ check_possible_match (NMConnection *orig,
708502
 	if (!check_connection_interface_name (orig, candidate, settings))
708502
 		return NULL;
708502
 
708502
+	if (!check_connection_mac_address (orig, candidate, settings))
708502
+		return NULL;
708502
+
708502
 	if (g_hash_table_size (settings) == 0)
708502
 		return candidate;
708502
 	else
708502
-- 
708502
1.7.11.7
708502
708502
708502
From ff2b655691af48cf73d7780fdd662cd861c365c7 Mon Sep 17 00:00:00 2001
708502
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com>
708502
Date: Tue, 8 Apr 2014 10:39:31 +0200
708502
Subject: [PATCH 4/5] tests: improve tests for nm_utils_match_connection()
708502
 function
708502
MIME-Version: 1.0
708502
Content-Type: text/plain; charset=UTF-8
708502
Content-Transfer-Encoding: 8bit
708502
708502
nm_utils_match_connection() is the main function used to match connections
708502
when assuming connections on startup.
708502
708502
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
708502
---
708502
 src/tests/test-general.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++
708502
 1 file changed, 113 insertions(+)
708502
708502
diff --git a/src/tests/test-general.c b/src/tests/test-general.c
708502
index ecbda9a..207191f 100644
708502
--- a/src/tests/test-general.c
708502
+++ b/src/tests/test-general.c
708502
@@ -21,6 +21,7 @@
708502
 #include <glib.h>
708502
 #include <string.h>
708502
 #include <errno.h>
708502
+#include <netinet/ether.h>
708502
 
708502
 #include "NetworkManagerUtils.h"
708502
 #include "nm-utils.h"
708502
@@ -440,6 +441,116 @@ test_connection_match_interface_name (void)
708502
 	g_object_unref (copy);
708502
 }
708502
 
708502
+static void
708502
+test_connection_match_wired (void)
708502
+{
708502
+	NMConnection *orig, *copy, *matched;
708502
+	GSList *connections = NULL;
708502
+	NMSettingWired *s_wired;
708502
+	GPtrArray *subchan_arr = g_ptr_array_sized_new (3);
708502
+	GByteArray *mac;
708502
+
708502
+	g_ptr_array_add (subchan_arr, "0.0.8000");
708502
+	g_ptr_array_add (subchan_arr, "0.0.8001");
708502
+	g_ptr_array_add (subchan_arr, "0.0.8002");
708502
+
708502
+	orig = _match_connection_new ();
708502
+	copy = nm_connection_duplicate (orig);
708502
+	connections = g_slist_append (connections, copy);
708502
+
708502
+	mac = nm_utils_hwaddr_atoba ("52:54:00:ab:db:23", ARPHRD_ETHER);
708502
+	s_wired = nm_connection_get_setting_wired (orig);
708502
+	g_assert (s_wired);
708502
+	g_object_set (G_OBJECT (s_wired),
708502
+	              NM_SETTING_WIRED_PORT, "tp",           /* port is not compared */
708502
+	              NM_SETTING_WIRED_MAC_ADDRESS, mac,     /* we allow MAC address just in one connection */
708502
+	              NM_SETTING_WIRED_S390_SUBCHANNELS, subchan_arr,
708502
+	              NM_SETTING_WIRED_S390_NETTYPE, "qeth",
708502
+	              NULL);
708502
+	g_byte_array_free (mac, TRUE);
708502
+
708502
+	s_wired = nm_connection_get_setting_wired (copy);
708502
+	g_assert (s_wired);
708502
+	g_object_set (G_OBJECT (s_wired),
708502
+	              NM_SETTING_WIRED_S390_SUBCHANNELS, subchan_arr,
708502
+	              NM_SETTING_WIRED_S390_NETTYPE, "qeth",
708502
+	              NULL);
708502
+
708502
+	matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
708502
+	g_assert (matched == copy);
708502
+
708502
+	g_slist_free (connections);
708502
+	g_ptr_array_free (subchan_arr, TRUE);
708502
+	g_object_unref (orig);
708502
+	g_object_unref (copy);
708502
+}
708502
+
708502
+static void
708502
+test_connection_no_match_ip4_addr (void)
708502
+{
708502
+	NMConnection *orig, *copy, *matched;
708502
+	GSList *connections = NULL;
708502
+	NMSettingIP4Config *s_ip4;
708502
+	NMSettingIP6Config *s_ip6;
708502
+	NMIP4Address *nm_addr;
708502
+	guint32 addr, gw;
708502
+
708502
+	orig = _match_connection_new ();
708502
+	copy = nm_connection_duplicate (orig);
708502
+	connections = g_slist_append (connections, copy);
708502
+
708502
+	/* Check that if we have two differences, ipv6.method (exception we allow) and
708502
+	 * ipv4.addresses (which is fatal), we don't match the connections.
708502
+	 */
708502
+	s_ip6 = nm_connection_get_setting_ip6_config (orig);
708502
+	g_assert (s_ip6);
708502
+	g_object_set (G_OBJECT (s_ip6),
708502
+	              NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
708502
+	              NULL);
708502
+
708502
+	s_ip6 = nm_connection_get_setting_ip6_config (copy);
708502
+	g_assert (s_ip6);
708502
+	g_object_set (G_OBJECT (s_ip6),
708502
+	              NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
708502
+	              NULL);
708502
+
708502
+
708502
+	s_ip4 = nm_connection_get_setting_ip4_config (orig);
708502
+	g_assert (s_ip4);
708502
+	g_object_set (G_OBJECT (s_ip4),
708502
+	              NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
708502
+	              NULL);
708502
+	nm_addr = nm_ip4_address_new ();
708502
+	inet_pton (AF_INET, "1.1.1.4", &addr);
708502
+	inet_pton (AF_INET, "1.1.1.254", &gw;;
708502
+	nm_ip4_address_set_address (nm_addr, addr);
708502
+	nm_ip4_address_set_prefix (nm_addr, 24);
708502
+	nm_ip4_address_set_gateway (nm_addr, gw);
708502
+	nm_setting_ip4_config_add_address (s_ip4, nm_addr);
708502
+	nm_ip4_address_unref (nm_addr);
708502
+
708502
+	s_ip4 = nm_connection_get_setting_ip4_config (copy);
708502
+	g_assert (s_ip4);
708502
+	g_object_set (G_OBJECT (s_ip4),
708502
+	              NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
708502
+	              NULL);
708502
+	nm_addr = nm_ip4_address_new ();
708502
+	inet_pton (AF_INET, "2.2.2.4", &addr);
708502
+	inet_pton (AF_INET, "2.2.2.254", &gw;;
708502
+	nm_ip4_address_set_address (nm_addr, addr);
708502
+	nm_ip4_address_set_prefix (nm_addr, 24);
708502
+	nm_ip4_address_set_gateway (nm_addr, gw);
708502
+	nm_setting_ip4_config_add_address (s_ip4, nm_addr);
708502
+	nm_ip4_address_unref (nm_addr);
708502
+
708502
+	matched = nm_utils_match_connection (connections, orig, TRUE, NULL, NULL);
708502
+	g_assert (matched != copy);
708502
+
708502
+	g_slist_free (connections);
708502
+	g_object_unref (orig);
708502
+	g_object_unref (copy);
708502
+}
708502
+
708502
 /*******************************************/
708502
 
708502
 int
708502
@@ -457,6 +568,8 @@ main (int argc, char **argv)
708502
 	g_test_add_func ("/general/connection-match/ip6-method-ignore", test_connection_match_ip6_method_ignore);
708502
 	g_test_add_func ("/general/connection-match/ip4-method", test_connection_match_ip4_method);
708502
 	g_test_add_func ("/general/connection-match/con-interface-name", test_connection_match_interface_name);
708502
+	g_test_add_func ("/general/connection-match/wired", test_connection_match_wired);
708502
+	g_test_add_func ("/general/connection-match/no-match-ip4-addr", test_connection_no_match_ip4_addr);
708502
 
708502
 	return g_test_run ();
708502
 }
708502
-- 
708502
1.7.11.7
708502
708502
708502
From 59c0b7258c3bb7bc818b979eb2aeaf9bb9700e29 Mon Sep 17 00:00:00 2001
708502
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com>
708502
Date: Mon, 7 Apr 2014 15:34:10 +0200
708502
Subject: [PATCH 5/5] device-ethernet: add finalize() method
708502
MIME-Version: 1.0
708502
Content-Type: text/plain; charset=UTF-8
708502
Content-Transfer-Encoding: 8bit
708502
708502
708502
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
708502
---
708502
 src/devices/nm-device-ethernet.c | 26 ++++++++++++++++++--------
708502
 1 file changed, 18 insertions(+), 8 deletions(-)
708502
708502
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
708502
index 920d255..79e9086 100644
708502
--- a/src/devices/nm-device-ethernet.c
708502
+++ b/src/devices/nm-device-ethernet.c
708502
@@ -1677,14 +1677,6 @@ dispose (GObject *object)
708502
 	NMDeviceEthernet *self = NM_DEVICE_ETHERNET (object);
708502
 	NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
708502
 
708502
-	g_clear_object (&priv->supplicant.mgr);
708502
-	g_free (priv->subchan1);
708502
-	g_free (priv->subchan2);
708502
-	g_free (priv->subchan3);
708502
-	g_free (priv->subchannels);
708502
-	g_free (priv->s390_nettype);
708502
-	g_hash_table_destroy (priv->s390_options);
708502
-
708502
 	if (priv->pppoe_wait_id) {
708502
 		g_source_remove (priv->pppoe_wait_id);
708502
 		priv->pppoe_wait_id = 0;
708502
@@ -1697,6 +1689,23 @@ dispose (GObject *object)
708502
 }
708502
 
708502
 static void
708502
+finalize (GObject *object)
708502
+{
708502
+	NMDeviceEthernet *self = NM_DEVICE_ETHERNET (object);
708502
+	NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
708502
+
708502
+	g_clear_object (&priv->supplicant.mgr);
708502
+	g_free (priv->subchan1);
708502
+	g_free (priv->subchan2);
708502
+	g_free (priv->subchan3);
708502
+	g_free (priv->subchannels);
708502
+	g_free (priv->s390_nettype);
708502
+	g_hash_table_destroy (priv->s390_options);
708502
+
708502
+	G_OBJECT_CLASS (nm_device_ethernet_parent_class)->finalize (object);
708502
+}
708502
+
708502
+static void
708502
 get_property (GObject *object, guint prop_id,
708502
               GValue *value, GParamSpec *pspec)
708502
 {
708502
@@ -1740,6 +1749,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
708502
 	/* virtual methods */
708502
 	object_class->constructor = constructor;
708502
 	object_class->dispose = dispose;
708502
+	object_class->finalize = finalize;
708502
 	object_class->get_property = get_property;
708502
 	object_class->set_property = set_property;
708502
 
708502
-- 
708502
1.7.11.7
708502
708502
From 981e33b83b57377d04fa6caa50a4434c59fb9285 Mon Sep 17 00:00:00 2001
708502
From: Thomas Haller <thaller@redhat.com>
708502
Date: Fri, 11 Apr 2014 12:46:53 +0200
708502
Subject: [PATCH] core: replace readlink() by glib equivalent in
708502
 NMDeviceEthernet
708502
MIME-Version: 1.0
708502
Content-Type: text/plain; charset=UTF-8
708502
Content-Transfer-Encoding: 8bit
708502
708502
Makes the function working for link destinations longer then 127 bytes and
708502
fixes a potential bug that the result of readlink() was not zero
708502
terminated for long paths.
708502
708502
Probably this would be no problem, but better be save.
708502
708502
Related: https://bugzilla.redhat.com/attachment.cgi?id=885371
708502
708502
Signed-off-by: Thomas Haller <thaller@redhat.com>
708502
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
708502
---
708502
 src/devices/nm-device-ethernet.c | 15 ++++++---------
708502
 1 file changed, 6 insertions(+), 9 deletions(-)
708502
708502
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
708502
index 79e9086..e9937e4 100644
708502
--- a/src/devices/nm-device-ethernet.c
708502
+++ b/src/devices/nm-device-ethernet.c
708502
@@ -150,18 +150,15 @@ nm_ethernet_error_quark (void)
708502
 static char *
708502
 get_link_basename (const char *parent_path, const char *name, GError **error)
708502
 {
708502
-	char buf[128];
708502
-	char *path;
708502
+	char *link_dest, *path;
708502
 	char *result = NULL;
708502
 
708502
 	path = g_strdup_printf ("%s/%s", parent_path, name);
708502
-
708502
-	memset (buf, 0, sizeof (buf));
708502
-	errno = 0;
708502
-	if (readlink (path, &buf[0], sizeof (buf) - 1) >= 0)
708502
-		result = g_path_get_basename (buf);
708502
-	else
708502
-		g_set_error (error, 0, 1, "failed to read link '%s': %d", path, errno);
708502
+	link_dest = g_file_read_link (path, error);
708502
+	if (link_dest) {
708502
+		result = g_path_get_basename (link_dest);
708502
+		g_free (link_dest);
708502
+	}
708502
 	g_free (path);
708502
 	return result;
708502
 }
708502
-- 
708502
1.7.11.7
708502