Blob Blame History Raw
From 959ae54ef220251a4649f7e17f3566d460fe9b11 Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Fri, 16 Sep 2016 05:12:45 +0200
Subject: [PATCH] device: fix crash reapplying connection to slave devices

Slave devices don't have IPv4 and IPv6 configuration and so special
care must be taken when comparing their methods.

https://bugzilla.redhat.com/show_bug.cgi?id=1376446
(cherry picked from commit 8f92ead6e2a9082d5aa4a885680308b4516d70ae)
(cherry picked from commit dbb67694cbc51eb639bd5d7d60d1455e4f5a449a)
---
 src/devices/nm-device.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index d5e1f95..755cd58 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -7780,6 +7780,7 @@ nm_device_reactivate_ip4_config (NMDevice *self,
                                  NMSettingIPConfig *s_ip4_new)
 {
 	NMDevicePrivate *priv;
+	const char *method_old, *method_new;
 
 	g_return_if_fail (NM_IS_DEVICE (self));
 	priv = NM_DEVICE_GET_PRIVATE (self);
@@ -7792,8 +7793,14 @@ nm_device_reactivate_ip4_config (NMDevice *self,
 		                             s_ip4_new,
 		                             nm_device_get_ip4_route_metric (self));
 
-		if (strcmp (nm_setting_ip_config_get_method (s_ip4_new),
-		            nm_setting_ip_config_get_method (s_ip4_old))) {
+		method_old = s_ip4_old ?
+			nm_setting_ip_config_get_method (s_ip4_old) :
+			NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
+		method_new = s_ip4_new ?
+			nm_setting_ip_config_get_method (s_ip4_new) :
+			NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
+
+		if (!nm_streq0 (method_old, method_new)) {
 			_cleanup_ip4_pre (self, CLEANUP_TYPE_DECONFIGURE);
 			priv->ip4_state = IP_WAIT;
 			if (!nm_device_activate_stage3_ip4_start (self))
@@ -7811,6 +7818,7 @@ nm_device_reactivate_ip6_config (NMDevice *self,
                                  NMSettingIPConfig *s_ip6_new)
 {
 	NMDevicePrivate *priv;
+	const char *method_old, *method_new;
 
 	g_return_if_fail (NM_IS_DEVICE (self));
 	priv = NM_DEVICE_GET_PRIVATE (self);
@@ -7823,8 +7831,14 @@ nm_device_reactivate_ip6_config (NMDevice *self,
 		                             s_ip6_new,
 		                             nm_device_get_ip6_route_metric (self));
 
-		if (strcmp (nm_setting_ip_config_get_method (s_ip6_new),
-		            nm_setting_ip_config_get_method (s_ip6_old))) {
+		method_old = s_ip6_old ?
+			nm_setting_ip_config_get_method (s_ip6_old) :
+			NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
+		method_new = s_ip6_new ?
+			nm_setting_ip_config_get_method (s_ip6_new) :
+			NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
+
+		if (!nm_streq0 (method_old, method_new)) {
 			_cleanup_ip6_pre (self, CLEANUP_TYPE_DECONFIGURE);
 			priv->ip6_state = IP_WAIT;
 			if (!nm_device_activate_stage3_ip6_start (self))
-- 
2.7.4