[PATCH 2/3] device: commit IP config after determining if there are changes



Reorder the code so that it is possible to pass has_changes as a
parameter to nm_ip[64]_config_commit().

Also, ensure that the IP config is exported to D-Bus after it is
successfully committed, even if old_config is not NULL (because
the previous attempt to commit it may have failed).

Signed-off-by: David Ward <david ward ll mit edu>
---
 src/devices/nm-device.c | 94 +++++++++++++++++++++++--------------------------
 1 file changed, 44 insertions(+), 50 deletions(-)

diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index f0ef657..24ad35f 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -6113,53 +6113,50 @@ nm_device_set_ip4_config (NMDevice *self,
 
        old_config = priv->ip4_config;
 
-       /* Always commit to nm-platform to update lifetimes */
-       if (commit && new_config) {
-               gboolean assumed = nm_device_uses_assumed_connection (self);
-
-               nm_device_set_mtu (self, nm_ip4_config_get_mtu (new_config));
-
-               /* for assumed devices we set the device_route_metric to the default which will
-                * stop nm_platform_ip4_address_sync() to replace the device routes. */
-               success = nm_ip4_config_commit (new_config, ip_ifindex,
-                                               assumed ? NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE : 
default_route_metric);
-               if (!success)
-                       reason_local = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
-       }
-
        if (new_config) {
                if (old_config) {
                        /* has_changes is set only on relevant changes, because when the configuration 
changes,
                         * this causes a re-read and reset. This should only happen for relevant changes */
                        nm_ip4_config_replace (old_config, new_config, &has_changes);
-                       if (has_changes) {
-                               _LOGD (LOGD_IP4, "update IP4Config instance (%s)",
-                                      nm_ip4_config_get_dbus_path (old_config));
-                       }
                } else {
                        has_changes = TRUE;
                        priv->ip4_config = g_object_ref (new_config);
-
-                       if (success && !nm_ip4_config_get_dbus_path (new_config)) {
-                               /* Export over D-Bus */
-                               nm_ip4_config_export (new_config);
-                       }
-
-                       _LOGD (LOGD_IP4, "set IP4Config instance (%s)",
-                              nm_ip4_config_get_dbus_path (new_config));
                }
        } else if (old_config) {
                has_changes = TRUE;
                priv->ip4_config = NULL;
-               _LOGD (LOGD_IP4, "clear IP4Config instance (%s)",
-                      nm_ip4_config_get_dbus_path (old_config));
                /* Device config is invalid if combined config is invalid */
                g_clear_object (&priv->dev_ip4_config);
        }
 
+       /* Always commit to nm-platform to update lifetimes */
+       if (commit && new_config) {
+               gboolean assumed = nm_device_uses_assumed_connection (self);
+
+               nm_device_set_mtu (self, nm_ip4_config_get_mtu (new_config));
+
+               /* for assumed devices we set the device_route_metric to the default which will
+                * stop nm_platform_ip4_address_sync() to replace the device routes. */
+               success = nm_ip4_config_commit (new_config, ip_ifindex,
+                                               assumed ? NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE : 
default_route_metric);
+               if (!success)
+                       reason_local = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
+       }
+
+       if (success && priv->ip4_config)
+               nm_ip4_config_export (priv->ip4_config);
+
        nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), self);
 
        if (has_changes) {
+               if (priv->ip4_config) {
+                       _LOGD (LOGD_IP4, "set IP4Config instance (%s)",
+                              nm_ip4_config_get_dbus_path (priv->ip4_config));
+               } else {
+                       _LOGD (LOGD_IP4, "clear IP4Config instance (%s)",
+                              nm_ip4_config_get_dbus_path (old_config));
+               }
+
                _update_ip4_address (self);
 
                if (old_config != priv->ip4_config)
@@ -6251,45 +6248,42 @@ nm_device_set_ip6_config (NMDevice *self,
 
        old_config = priv->ip6_config;
 
-       /* Always commit to nm-platform to update lifetimes */
-       if (commit && new_config) {
-               nm_device_ipv6_set_mtu (self, priv->ip6_mtu);
-               success = nm_ip6_config_commit (new_config, ip_ifindex);
-               if (!success)
-                       reason_local = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
-       }
-
        if (new_config) {
                if (old_config) {
                        /* has_changes is set only on relevant changes, because when the configuration 
changes,
                         * this causes a re-read and reset. This should only happen for relevant changes */
                        nm_ip6_config_replace (old_config, new_config, &has_changes);
-                       if (has_changes) {
-                               _LOGD (LOGD_IP6, "update IP6Config instance (%s)",
-                                      nm_ip6_config_get_dbus_path (old_config));
-                       }
                } else {
                        has_changes = TRUE;
                        priv->ip6_config = g_object_ref (new_config);
-
-                       if (success && !nm_ip6_config_get_dbus_path (new_config)) {
-                               /* Export over D-Bus */
-                               nm_ip6_config_export (new_config);
-                       }
-
-                       _LOGD (LOGD_IP6, "set IP6Config instance (%s)",
-                              nm_ip6_config_get_dbus_path (new_config));
                }
        } else if (old_config) {
                has_changes = TRUE;
                priv->ip6_config = NULL;
-               _LOGD (LOGD_IP6, "clear IP6Config instance (%s)",
-                      nm_ip6_config_get_dbus_path (old_config));
        }
 
+       /* Always commit to nm-platform to update lifetimes */
+       if (commit && new_config) {
+               nm_device_ipv6_set_mtu (self, priv->ip6_mtu);
+               success = nm_ip6_config_commit (new_config, ip_ifindex);
+               if (!success)
+                       reason_local = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
+       }
+
+       if (success && priv->ip6_config)
+               nm_ip6_config_export (priv->ip6_config);
+
        nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self);
 
        if (has_changes) {
+               if (priv->ip6_config) {
+                       _LOGD (LOGD_IP6, "set IP6Config instance (%s)",
+                              nm_ip6_config_get_dbus_path (priv->ip6_config));
+               } else {
+                       _LOGD (LOGD_IP6, "clear IP6Config instance (%s)",
+                              nm_ip6_config_get_dbus_path (old_config));
+               }
+
                if (old_config != priv->ip6_config)
                        g_object_notify (G_OBJECT (self), NM_DEVICE_IP6_CONFIG);
                g_signal_emit (self, signals[IP6_CONFIG_CHANGED], 0, priv->ip6_config, old_config);
-- 
1.8.3.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]