diff options
Diffstat (limited to 'src/nm-cloud-setup')
| -rw-r--r-- | src/nm-cloud-setup/main.c | 64 | ||||
| -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, 58 insertions, 23 deletions
diff --git a/src/nm-cloud-setup/main.c b/src/nm-cloud-setup/main.c index 0c452acf..e1cbd1d4 100644 --- a/src/nm-cloud-setup/main.c +++ b/src/nm-cloud-setup/main.c @@ -251,24 +251,38 @@ _get_config(GCancellable *sigterm_cancellable, NMCSProvider *provider, NMClient /*****************************************************************************/ static gboolean -_nmc_skip_connection(NMConnection *connection) +_nmc_skip_connection_by_user_data(NMConnection *connection) { NMSettingUser *s_user; const char *v; - s_user = NM_SETTING_USER(nm_connection_get_setting(connection, NM_TYPE_SETTING_USER)); - if (!s_user) - return FALSE; - #define USER_TAG_SKIP "org.freedesktop.nm-cloud-setup.skip" nm_assert(nm_setting_user_check_key(USER_TAG_SKIP, NULL)); - v = nm_setting_user_get_data(s_user, USER_TAG_SKIP); - return _nm_utils_ascii_str_to_bool(v, FALSE); + s_user = NM_SETTING_USER(nm_connection_get_setting(connection, NM_TYPE_SETTING_USER)); + if (s_user) { + v = nm_setting_user_get_data(s_user, USER_TAG_SKIP); + if (_nm_utils_ascii_str_to_bool(v, FALSE)) + return TRUE; + } + + return FALSE; } static gboolean +_nmc_skip_connection_by_type(NMConnection *connection) +{ + if (!nm_streq0(nm_connection_get_connection_type(connection), NM_SETTING_WIRED_SETTING_NAME)) + return TRUE; + + if (!nm_connection_get_setting_ip4_config(connection)) + return TRUE; + + return FALSE; +} + +static void _nmc_mangle_connection(NMDevice *device, NMConnection *connection, const NMCSProviderGetConfigResult *result, @@ -291,12 +305,8 @@ _nmc_mangle_connection(NMDevice *device, NM_SET_OUT(out_skipped_single_addr, FALSE); NM_SET_OUT(out_changed, FALSE); - if (!nm_streq0(nm_connection_get_connection_type(connection), NM_SETTING_WIRED_SETTING_NAME)) - return FALSE; - s_ip = nm_connection_get_setting_ip4_config(connection); - if (!s_ip) - return FALSE; + nm_assert(NM_IS_SETTING_IP4_CONFIG(s_ip)); if ((ac = nm_device_get_active_connection(device)) && (remote_connection = NM_CONNECTION(nm_active_connection_get_connection(ac)))) @@ -429,7 +439,6 @@ _nmc_mangle_connection(NMDevice *device, rules_new->len); NM_SET_OUT(out_changed, addrs_changed || routes_changed || rules_changed); - return TRUE; } /*****************************************************************************/ @@ -451,6 +460,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); @@ -484,6 +494,8 @@ _config_one(GCancellable *sigterm_cancellable, try_count = 0; try_again: + g_clear_object(&applied_connection); + g_clear_error(&error); applied_connection = nmcs_device_get_applied_connection(device, sigterm_cancellable, @@ -497,23 +509,25 @@ try_again: return any_changes; } - if (_nmc_skip_connection(applied_connection)) { + if (_nmc_skip_connection_by_user_data(applied_connection)) { _LOGD("config device %s: skip applied connection due to user data %s", hwaddr, USER_TAG_SKIP); return any_changes; } - if (!_nmc_mangle_connection(device, - applied_connection, - result, - config_data, - &skipped_single_addr, - &changed)) { + if (_nmc_skip_connection_by_type(applied_connection)) { _LOGD("config device %s: device has no suitable applied connection. Skip", hwaddr); return any_changes; } + _nmc_mangle_connection(device, + applied_connection, + result, + config_data, + &skipped_single_addr, + &changed); + if (!changed) { if (skipped_single_addr) { _LOGD("config device %s: device needs no update to applied connection \"%s\" (%s) " @@ -539,16 +553,22 @@ 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) { _LOGD("config device %s: applied connection changed in the meantime. Retry...", hwaddr); - g_clear_object(&applied_connection); - g_clear_error(&error); try_count++; goto try_again; } diff --git a/src/nm-cloud-setup/nm-cloud-setup-utils.c b/src/nm-cloud-setup/nm-cloud-setup-utils.c index e505f8bd..7cf79592 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 4131abfe..fed0f4b6 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); |