diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2016-01-05 15:52:36 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2016-01-10 23:14:29 +0100 |
commit | a5b6436a901b63fb12d9268c3ae7e472945b8329 (patch) | |
tree | 01c642770772d2ece26c645bb4103f54171de1b2 | |
parent | fa6375cd8b667b9bc6295f3c7a17b7f537714a4e (diff) | |
download | NetworkManager-a5b6436a901b63fb12d9268c3ae7e472945b8329.tar.gz |
device: add possibility to reapply the ipv4 settings
-rw-r--r-- | src/devices/nm-device.c | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 49b3261a57..6099d84333 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -6829,6 +6829,56 @@ _cleanup_ip6_pre (NMDevice *self, CleanupType cleanup_type) addrconf6_cleanup (self); } +static gboolean +reapply_ip4_config (NMDevice *self, + NMConnection *old, + gboolean reconfigure, + GError **error) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMSettingsConnection *connection = nm_device_get_settings_connection (self); + NMSettingIPConfig *s_ip4 = nm_connection_get_setting_ip4_config (NM_CONNECTION (connection)); + NMSettingIPConfig *s_ip4_applied = nm_connection_get_setting_ip4_config (old); + const char *method; + const char *method_applied; + + if (!s_ip4 || !s_ip4_applied || priv->ip4_state == IP_NONE) { + g_set_error_literal (error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, + "No IPv4 configuration to update"); + return FALSE; + } + + if (!reconfigure) + return TRUE; + + method = nm_setting_ip_config_get_method (s_ip4); + method_applied = nm_setting_ip_config_get_method (s_ip4_applied); + + g_clear_object (&priv->con_ip4_config); + priv->con_ip4_config = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); + nm_ip4_config_merge_setting (priv->con_ip4_config, + nm_connection_get_setting_ip4_config (NM_CONNECTION (connection)), + nm_device_get_ip4_route_metric (self)); + + if (strcmp (method, method_applied)) { + _cleanup_ip4_pre (self, CLEANUP_TYPE_DECONFIGURE); + priv->ip4_state = IP_WAIT; + if (!nm_device_activate_stage3_ip4_start (self)) { + g_set_error_literal (error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, + "Failed to apply IPv4 configuration"); + return FALSE; + } + } else { + ip4_config_merge_and_apply (self, NULL, TRUE, NULL); + } + + return TRUE; +} + /* reapply_connection: * @connection: the new connection settings to be applied * @flags: always zero @@ -6852,6 +6902,7 @@ reapply_connection (NMDevice *self, GHashTable *diffs = NULL; GHashTableIter iter; const char *setting; + gboolean success = FALSE; /* No flags supported as of now. */ if (flags != 0) { @@ -6878,18 +6929,23 @@ reapply_connection (NMDevice *self, g_hash_table_iter_init (&iter, diffs); while (g_hash_table_iter_next (&iter, (gpointer *)&setting, NULL)) { - g_set_error (error, - NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, - "Can't reapply changes to '%s' settings", - setting); - return FALSE; + if (strcmp (setting, NM_SETTING_IP4_CONFIG_SETTING_NAME) == 0) { + if (!reapply_ip4_config (self, old, reconfigure, error)) + goto done; + } else { + g_set_error (error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, + "Can't reapply changes to '%s' settings", + setting); + goto done; + } } - if (reconfigure) - nm_connection_replace_settings_from_connection (applied, NM_CONNECTION (connection)); - - return TRUE; + success = TRUE; +done: + g_object_unref (old); + return success; } typedef struct { |