diff options
author | Thomas Haller <thaller@redhat.com> | 2022-12-06 19:30:02 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-12-19 15:46:48 +0100 |
commit | 37dc0a9c2f83851e50ed8787da9606c22906add0 (patch) | |
tree | 797e97728c8b022c06626f71e138916ce88f069a | |
parent | 5f8bfb82b75347a8b6a56d8d7e1c90f5b7efd7f3 (diff) |
nm-cloud-setup: set preserve-external-ip flag during reapply
Externally added IP addresses/routes should be preserved by
nm-cloud-setup. This allows other tools to also configure the interface
and the Reapply() call from nm-cloud-setup would not interfere
with those tools.
https://bugzilla.redhat.com/show_bug.cgi?id=2132754
(cherry picked from commit 29b0420be72fa4ae6878f6dd82d34c245a538351)
-rw-r--r-- | src/nm-cloud-setup/main.c | 9 | ||||
-rw-r--r-- | src/nm-cloud-setup/nm-cloud-setup-utils.c | 16 | ||||
-rw-r--r-- | src/nm-cloud-setup/nm-cloud-setup-utils.h | 1 |
3 files changed, 25 insertions, 1 deletions
diff --git a/src/nm-cloud-setup/main.c b/src/nm-cloud-setup/main.c index 0c452acfe3..5329d06b57 100644 --- a/src/nm-cloud-setup/main.c +++ b/src/nm-cloud-setup/main.c @@ -451,6 +451,7 @@ _config_one(GCancellable *sigterm_cancellable, gboolean version_id_changed; guint try_count; gboolean any_changes = FALSE; + gboolean maybe_no_preserved_external_ip; g_main_context_iteration(NULL, FALSE); @@ -539,10 +540,18 @@ try_again: /* we are about to call Reapply(). Even if that fails, it counts as if we changed something. */ any_changes = TRUE; + /* "preserve-external-ip" flag was only introduced in 1.41.6 and 1.40.9. + * We have no convenient way to check the daemon version (short of parsing the "Version" + * string). Hence, we don't know it. Take into account, that the daemon that we + * talk to might not support the flag yet. This is to support backward compatibility + * during package upgrade. */ + maybe_no_preserved_external_ip = TRUE; + if (!nmcs_device_reapply(device, sigterm_cancellable, applied_connection, applied_version_id, + maybe_no_preserved_external_ip, &version_id_changed, &error)) { if (version_id_changed && try_count < 5) { diff --git a/src/nm-cloud-setup/nm-cloud-setup-utils.c b/src/nm-cloud-setup/nm-cloud-setup-utils.c index e505f8bd03..7cf7959241 100644 --- a/src/nm-cloud-setup/nm-cloud-setup-utils.c +++ b/src/nm-cloud-setup/nm-cloud-setup-utils.c @@ -822,6 +822,7 @@ nmcs_device_reapply(NMDevice *device, GCancellable *sigterm_cancellable, NMConnection *connection, guint64 version_id, + gboolean maybe_no_preserved_external_ip, gboolean *out_version_id_changed, GError **error) { @@ -829,11 +830,13 @@ nmcs_device_reapply(NMDevice *device, DeviceReapplyData data = { .main_loop = main_loop, }; + NMDeviceReapplyFlags reapply_flags = NM_DEVICE_REAPPLY_FLAGS_PRESERVE_EXTERNAL_IP; +again: nm_device_reapply_async(device, connection, version_id, - 0, + reapply_flags, sigterm_cancellable, _nmcs_device_reapply_cb, &data); @@ -841,6 +844,17 @@ nmcs_device_reapply(NMDevice *device, g_main_loop_run(main_loop); if (data.error) { + if (maybe_no_preserved_external_ip + && reapply_flags == NM_DEVICE_REAPPLY_FLAGS_PRESERVE_EXTERNAL_IP + && nm_g_error_matches(data.error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED)) { + /* Hm? Maybe we running against an older version of NetworkManager that + * doesn't support "preserve-external-ip" flags? Retry without the flag. + * + * Note that recent version would reject invalid flags with NM_DEVICE_ERROR_INVALID_ARGUMENT, + * but we want to detect old daemon versions here. */ + reapply_flags = NM_DEVICE_REAPPLY_FLAGS_NONE; + goto again; + } NM_SET_OUT( out_version_id_changed, g_error_matches(data.error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_VERSION_ID_MISMATCH)); diff --git a/src/nm-cloud-setup/nm-cloud-setup-utils.h b/src/nm-cloud-setup/nm-cloud-setup-utils.h index 4131abfe7c..fed0f4b6ed 100644 --- a/src/nm-cloud-setup/nm-cloud-setup-utils.h +++ b/src/nm-cloud-setup/nm-cloud-setup-utils.h @@ -136,6 +136,7 @@ gboolean nmcs_device_reapply(NMDevice *device, GCancellable *sigterm_cancellable, NMConnection *connection, guint64 version_id, + gboolean maybe_no_preserved_external_ip, gboolean *out_version_id_changed, GError **error); |