From 93960639e8d99a8aba7975d4eba172c74b26ecc1 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 7 Apr 2025 13:02:50 +0200 Subject: [PATCH] cloud-setup: factor out creation of new connection We're going to create connections on wired devices for OCI VM VNICs, and they're going to also need the same user setting. Factor it out. --- src/nm-cloud-setup/main.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/nm-cloud-setup/main.c b/src/nm-cloud-setup/main.c index fd2fe4ca95..4070a01e79 100644 --- a/src/nm-cloud-setup/main.c +++ b/src/nm-cloud-setup/main.c @@ -691,6 +691,24 @@ try_again: return TRUE; } +static NMConnection * +_new_connection(void) +{ + NMConnection *connection = NULL; + NMSetting *s_user; + + connection = nm_simple_connection_new(); + + s_user = nm_setting_user_new(); + nm_connection_add_setting(connection, s_user); + nm_setting_user_set_data(NM_SETTING_USER(s_user), + "org.freedesktop.NetworkManager.origin", + "nm-cloud-setup", + NULL); + + return connection; +} + static gboolean _config_ethernet(SigTermData *sigterm_data, const NMCSProviderGetConfigIfaceData *config_data, @@ -733,9 +751,8 @@ _oci_new_vlan_dev(SigTermData *sigterm_data, const char *wired_mac_addr = NULL; const NMUtilsNamedValue *map = NULL; const char *ip4_config_method; - NMSetting *s_user; - connection = nm_simple_connection_new(); + connection = _new_connection(); macvlan_name = g_strdup_printf("macvlan%ld", config_data->iface_idx); connection_id = g_strdup_printf("%s%ld", connection_type, config_data->iface_idx); @@ -806,13 +823,6 @@ _oci_new_vlan_dev(SigTermData *sigterm_data, hwaddr, NULL)); - s_user = nm_setting_user_new(); - nm_connection_add_setting(connection, s_user); - nm_setting_user_set_data(NM_SETTING_USER(s_user), - "org.freedesktop.NetworkManager.origin", - "nm-cloud-setup", - NULL); - _nmc_mangle_connection(NULL, connection, result, config_data, NULL, NULL); _LOGD("config device %s: creating %s connection for VLAN %d on %s...",