device: add possibility to reapply the ipv4 settings

This commit is contained in:
Lubomir Rintel
2016-01-05 15:52:36 +01:00
parent fa6375cd8b
commit a5b6436a90

View File

@@ -6829,6 +6829,56 @@ _cleanup_ip6_pre (NMDevice *self, CleanupType cleanup_type)
addrconf6_cleanup (self); 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: /* reapply_connection:
* @connection: the new connection settings to be applied * @connection: the new connection settings to be applied
* @flags: always zero * @flags: always zero
@@ -6852,6 +6902,7 @@ reapply_connection (NMDevice *self,
GHashTable *diffs = NULL; GHashTable *diffs = NULL;
GHashTableIter iter; GHashTableIter iter;
const char *setting; const char *setting;
gboolean success = FALSE;
/* No flags supported as of now. */ /* No flags supported as of now. */
if (flags != 0) { if (flags != 0) {
@@ -6878,18 +6929,23 @@ reapply_connection (NMDevice *self,
g_hash_table_iter_init (&iter, diffs); g_hash_table_iter_init (&iter, diffs);
while (g_hash_table_iter_next (&iter, (gpointer *)&setting, NULL)) { while (g_hash_table_iter_next (&iter, (gpointer *)&setting, NULL)) {
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, g_set_error (error,
NM_DEVICE_ERROR, NM_DEVICE_ERROR,
NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
"Can't reapply changes to '%s' settings", "Can't reapply changes to '%s' settings",
setting); setting);
return FALSE; goto done;
}
} }
if (reconfigure) success = TRUE;
nm_connection_replace_settings_from_connection (applied, NM_CONNECTION (connection)); done:
g_object_unref (old);
return TRUE; return success;
} }
typedef struct { typedef struct {