From 3a9ec3c5a3799eccb58d268100212fe6172f00dc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 28 Apr 2022 13:56:17 +0200 Subject: [PATCH 1/4] cloud-setup: reorder addresses to honor "primary_ip_address" The order of IPv4 addresses matters, in particular if they are in the same subnet. Kernel will mark all but the first one as "secondary". In NetworkManager's ipv4.addresses, the first address is the primary. It seems that on aliyun cloud, "private-ipv4s" URL may give the addresses in arbitrary order. The primary can be fetched from "primary-ip-address". Fix that by also fetching "primary-ip-address". Then, resort the array so that the primary is the first one in the list. https://bugzilla.redhat.com/show_bug.cgi?id=2079849 (cherry picked from commit 191baf84e215177c66aa23182fcfeae1f66dc271) --- src/nm-cloud-setup/nmcs-provider-aliyun.c | 62 ++++++++++++++++++++++- src/nm-cloud-setup/nmcs-provider.h | 12 +++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/nm-cloud-setup/nmcs-provider-aliyun.c b/src/nm-cloud-setup/nmcs-provider-aliyun.c index 31c9830d2d..9aabca80b3 100644 --- a/src/nm-cloud-setup/nmcs-provider-aliyun.c +++ b/src/nm-cloud-setup/nmcs-provider-aliyun.c @@ -123,6 +123,7 @@ detect(NMCSProvider *provider, GTask *task) typedef enum { GET_CONFIG_FETCH_DONE_TYPE_SUBNET_VPC_CIDR_BLOCK, GET_CONFIG_FETCH_DONE_TYPE_PRIVATE_IPV4S, + GET_CONFIG_FETCH_DONE_TYPE_PRIMARY_IP_ADDRESS, GET_CONFIG_FETCH_DONE_TYPE_NETMASK, GET_CONFIG_FETCH_DONE_TYPE_GATEWAY, } GetConfigFetchDoneType; @@ -177,6 +178,16 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, } break; + case GET_CONFIG_FETCH_DONE_TYPE_PRIMARY_IP_ADDRESS: + + if (nm_utils_parse_inaddr_bin(AF_INET, g_bytes_get_data(response, NULL), NULL, &tmp_addr)) { + nm_assert(config_iface_data->priv.aliyun.primary_ip_address == 0); + nm_assert(!config_iface_data->priv.aliyun.has_primary_ip_address); + config_iface_data->priv.aliyun.primary_ip_address = tmp_addr; + config_iface_data->priv.aliyun.has_primary_ip_address = TRUE; + } + break; + case GET_CONFIG_FETCH_DONE_TYPE_SUBNET_VPC_CIDR_BLOCK: if (nm_utils_parse_inaddr_prefix_bin(AF_INET, @@ -212,6 +223,26 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, break; } + if (!config_iface_data->priv.aliyun.ipv4s_arr_ordered + && config_iface_data->priv.aliyun.has_primary_ip_address + && config_iface_data->ipv4s_len > 0) { + for (i = 0; i < config_iface_data->ipv4s_len; i++) { + if (config_iface_data->ipv4s_arr[i] + != config_iface_data->priv.aliyun.primary_ip_address) + continue; + if (i > 0) { + /* OK, at position [i] we found the primary address. + * Move the elements from [0..(i-1)] to [1..i] and then set [0]. */ + memmove(&config_iface_data->ipv4s_arr[1], + &config_iface_data->ipv4s_arr[0], + i * sizeof(in_addr_t)); + config_iface_data->ipv4s_arr[0] = config_iface_data->priv.aliyun.primary_ip_address; + } + break; + } + config_iface_data->priv.aliyun.ipv4s_arr_ordered = TRUE; + } + out: get_config_data->n_pending--; _nmcs_provider_get_config_task_maybe_return(get_config_data, g_steal_pointer(&error)); @@ -235,6 +266,17 @@ _get_config_fetch_done_cb_private_ipv4s(GObject *source, GAsyncResult *result, g GET_CONFIG_FETCH_DONE_TYPE_PRIVATE_IPV4S); } +static void +_get_config_fetch_done_cb_primary_ip_address(GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + _get_config_fetch_done_cb(NM_HTTP_CLIENT(source), + result, + user_data, + GET_CONFIG_FETCH_DONE_TYPE_PRIMARY_IP_ADDRESS); +} + static void _get_config_fetch_done_cb_netmask(GObject *source, GAsyncResult *result, gpointer user_data) { @@ -297,6 +339,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us gs_free char *uri2 = NULL; gs_free char *uri3 = NULL; gs_free char *uri4 = NULL; + gs_free char *uri5 = NULL; config_iface_data = g_hash_table_lookup(get_config_data->result_dict, v_hwaddr); @@ -361,6 +404,23 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us nm_http_client_poll_get( http_client, (uri3 = _aliyun_uri_interfaces(v_mac_data->path, + NM_STR_HAS_SUFFIX(v_mac_data->path, "/") ? "" : "/", + "primary-ip-address")), + HTTP_TIMEOUT_MS, + 512 * 1024, + 10000, + 1000, + NULL, + get_config_data->intern_cancellable, + NULL, + NULL, + _get_config_fetch_done_cb_primary_ip_address, + nm_utils_user_data_pack(get_config_data, config_iface_data)); + + get_config_data->n_pending++; + nm_http_client_poll_get( + http_client, + (uri4 = _aliyun_uri_interfaces(v_mac_data->path, NM_STR_HAS_SUFFIX(v_mac_data->path, "/") ? "" : "/", "netmask")), HTTP_TIMEOUT_MS, @@ -377,7 +437,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us get_config_data->n_pending++; nm_http_client_poll_get( http_client, - (uri4 = _aliyun_uri_interfaces(v_mac_data->path, + (uri5 = _aliyun_uri_interfaces(v_mac_data->path, NM_STR_HAS_SUFFIX(v_mac_data->path, "/") ? "" : "/", "gateway")), HTTP_TIMEOUT_MS, diff --git a/src/nm-cloud-setup/nmcs-provider.h b/src/nm-cloud-setup/nmcs-provider.h index bce41dcb82..8ec240e5b9 100644 --- a/src/nm-cloud-setup/nmcs-provider.h +++ b/src/nm-cloud-setup/nmcs-provider.h @@ -36,6 +36,18 @@ typedef struct { * nmcs_provider_get_config(). */ bool was_requested : 1; + /* Usually we would want that the parent class NMCSProvider is not aware about + * the implementations. However, it's convenient to track implementation specific data + * here, thus we violate such separation. In practice, all subclasses are known + * at compile time, and it will be simpler this way. */ + struct { + struct { + in_addr_t primary_ip_address; + bool has_primary_ip_address : 1; + bool ipv4s_arr_ordered : 1; + } aliyun; + } priv; + } NMCSProviderGetConfigIfaceData; static inline gboolean From 061c05ca393e847c07707ea22fe892fb08cc48a4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Apr 2022 08:29:59 +0200 Subject: [PATCH 2/4] cloud-setup: track config-task-data in iface-data Let NMCSProviderGetConfigIfaceData.get_config_data have a pointer to the NMCSProviderGetConfigTaskData. This will allow two things: - at several places we pass on `nm_utils_user_data_pack(get_config_data, config_iface_data)` as user data. We can avoid that, by just letting config_iface_data have a pointer to get_config_data. - NMCSProviderGetConfigIfaceData contains a provider specific field "priv". That may also require special initialization or destruction, depending on the type. We thus need access to the provider type, which we have via iface_data->get_config_data->self. Also let NMCSProviderGetConfigTaskData have a pointer "self" to the NMCSProvider. While there was already the "task", which contains the provider as source-object, this is more convenient. (cherry picked from commit 069946cda14b2465d1eb5434402609fcd96f35ba) --- src/nm-cloud-setup/nmcs-provider-aliyun.c | 4 +--- src/nm-cloud-setup/nmcs-provider-azure.c | 4 +--- src/nm-cloud-setup/nmcs-provider-ec2.c | 4 +--- src/nm-cloud-setup/nmcs-provider-gcp.c | 4 +--- src/nm-cloud-setup/nmcs-provider.c | 21 ++++++++++++-------- src/nm-cloud-setup/nmcs-provider.h | 24 +++++++++++++++++------ 6 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/nm-cloud-setup/nmcs-provider-aliyun.c b/src/nm-cloud-setup/nmcs-provider-aliyun.c index 9aabca80b3..02fd7a01aa 100644 --- a/src/nm-cloud-setup/nmcs-provider-aliyun.c +++ b/src/nm-cloud-setup/nmcs-provider-aliyun.c @@ -352,9 +352,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us } config_iface_data = - nmcs_provider_get_config_iface_data_create(get_config_data->result_dict, - FALSE, - v_hwaddr); + nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr); } nm_assert(config_iface_data->iface_idx == -1); diff --git a/src/nm-cloud-setup/nmcs-provider-azure.c b/src/nm-cloud-setup/nmcs-provider-azure.c index 06f23ea73e..9b27af288a 100644 --- a/src/nm-cloud-setup/nmcs-provider-azure.c +++ b/src/nm-cloud-setup/nmcs-provider-azure.c @@ -387,9 +387,7 @@ _get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data) goto out_done; } iface_data->iface_get_config = - nmcs_provider_get_config_iface_data_create(get_config_data->result_dict, - FALSE, - v_hwaddr); + nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr); } else { if (iface_data->iface_get_config->iface_idx >= 0) { _LOGI("interface[%" G_GSSIZE_FORMAT "]: duplicate MAC address %s returned", diff --git a/src/nm-cloud-setup/nmcs-provider-ec2.c b/src/nm-cloud-setup/nmcs-provider-ec2.c index ee4e2a95fa..8362dd7c79 100644 --- a/src/nm-cloud-setup/nmcs-provider-ec2.c +++ b/src/nm-cloud-setup/nmcs-provider-ec2.c @@ -244,9 +244,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us continue; } config_iface_data = - nmcs_provider_get_config_iface_data_create(get_config_data->result_dict, - FALSE, - v_hwaddr); + nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr); } nm_assert(config_iface_data->iface_idx == -1); diff --git a/src/nm-cloud-setup/nmcs-provider-gcp.c b/src/nm-cloud-setup/nmcs-provider-gcp.c index 0df2bdd607..a325f31a17 100644 --- a/src/nm-cloud-setup/nmcs-provider-gcp.c +++ b/src/nm-cloud-setup/nmcs-provider-gcp.c @@ -282,9 +282,7 @@ _get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data) goto out_done; } iface_data->iface_get_config = - nmcs_provider_get_config_iface_data_create(get_config_data->result_dict, - FALSE, - v_hwaddr); + nmcs_provider_get_config_iface_data_create(get_config_data, FALSE, v_hwaddr); is_requested = FALSE; } else { if (iface_data->iface_get_config->iface_idx >= 0) { diff --git a/src/nm-cloud-setup/nmcs-provider.c b/src/nm-cloud-setup/nmcs-provider.c index f14a3d0272..a519ef9b5e 100644 --- a/src/nm-cloud-setup/nmcs-provider.c +++ b/src/nm-cloud-setup/nmcs-provider.c @@ -174,24 +174,27 @@ nmcs_provider_detect_finish(NMCSProvider *self, GAsyncResult *result, GError **e /*****************************************************************************/ NMCSProviderGetConfigIfaceData * -nmcs_provider_get_config_iface_data_create(GHashTable *iface_datas, - gboolean was_requested, - const char *hwaddr) +nmcs_provider_get_config_iface_data_create(NMCSProviderGetConfigTaskData *get_config_data, + gboolean was_requested, + const char *hwaddr) { NMCSProviderGetConfigIfaceData *iface_data; nm_assert(hwaddr); + nm_assert(get_config_data); + nm_assert(NMCS_IS_PROVIDER(get_config_data->self)); iface_data = g_slice_new(NMCSProviderGetConfigIfaceData); *iface_data = (NMCSProviderGetConfigIfaceData){ - .hwaddr = g_strdup(hwaddr), - .iface_idx = -1, - .was_requested = was_requested, + .get_config_data = get_config_data, + .hwaddr = g_strdup(hwaddr), + .iface_idx = -1, + .was_requested = was_requested, }; /* the has does not own the key (iface_datta->hwaddr), the lifetime of the * key is associated with the iface_data instance. */ - g_hash_table_replace(iface_datas, (char *) iface_data->hwaddr, iface_data); + g_hash_table_replace(get_config_data->result_dict, (char *) iface_data->hwaddr, iface_data); return iface_data; } @@ -280,6 +283,8 @@ nmcs_provider_get_config(NMCSProvider *self, get_config_data = g_slice_new(NMCSProviderGetConfigTaskData); *get_config_data = (NMCSProviderGetConfigTaskData){ + /* "self" is kept alive by "task". */ + .self = self, .task = nm_g_task_new(self, cancellable, nmcs_provider_get_config, callback, user_data), .any = any, .result_dict = g_hash_table_new_full(nm_str_hash, g_str_equal, NULL, _iface_data_free), @@ -288,7 +293,7 @@ nmcs_provider_get_config(NMCSProvider *self, nmcs_wait_for_objects_register(get_config_data->task); for (; hwaddrs && hwaddrs[0]; hwaddrs++) - nmcs_provider_get_config_iface_data_create(get_config_data->result_dict, TRUE, hwaddrs[0]); + nmcs_provider_get_config_iface_data_create(get_config_data, TRUE, hwaddrs[0]); if (cancellable) { gulong cancelled_id; diff --git a/src/nm-cloud-setup/nmcs-provider.h b/src/nm-cloud-setup/nmcs-provider.h index 8ec240e5b9..d1ab0a33c2 100644 --- a/src/nm-cloud-setup/nmcs-provider.h +++ b/src/nm-cloud-setup/nmcs-provider.h @@ -9,11 +9,16 @@ /*****************************************************************************/ +struct _NMCSProvider; +struct _NMCSProviderGetConfigTaskData; + typedef struct { /* And it's exactly the same pointer that is also the key for the iface_datas * dictionary. */ const char *hwaddr; + struct _NMCSProviderGetConfigTaskData *get_config_data; + in_addr_t *ipv4s_arr; gsize ipv4s_len; @@ -57,10 +62,6 @@ nmcs_provider_get_config_iface_data_is_valid(const NMCSProviderGetConfigIfaceDat && ((config_data->has_ipv4s && config_data->has_cidr) || config_data->iproutes_len); } -NMCSProviderGetConfigIfaceData *nmcs_provider_get_config_iface_data_create(GHashTable *iface_datas, - gboolean was_requested, - const char *hwaddr); - /*****************************************************************************/ typedef struct { @@ -95,9 +96,11 @@ NM_AUTO_DEFINE_FCN0(NMCSProviderGetConfigResult *, /*****************************************************************************/ -typedef struct { +typedef struct _NMCSProviderGetConfigTaskData { GTask *task; + struct _NMCSProvider *self; + GHashTable *result_dict; /* this cancellable should be used for the provider implementation @@ -117,6 +120,15 @@ typedef struct { bool any : 1; } NMCSProviderGetConfigTaskData; +/*****************************************************************************/ + +NMCSProviderGetConfigIfaceData * +nmcs_provider_get_config_iface_data_create(NMCSProviderGetConfigTaskData *get_config_data, + gboolean was_requested, + const char *hwaddr); + +/*****************************************************************************/ + #define NMCS_TYPE_PROVIDER (nmcs_provider_get_type()) #define NMCS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMCS_TYPE_PROVIDER, NMCSProvider)) #define NMCS_PROVIDER_CLASS(klass) \ @@ -130,7 +142,7 @@ typedef struct { struct _NMCSProviderPrivate; -typedef struct { +typedef struct _NMCSProvider { GObject parent; struct _NMCSProviderPrivate *_priv; } NMCSProvider; From 16ba58cfb1f12026f2c8f85658d60bedb9df7987 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Apr 2022 10:19:54 +0200 Subject: [PATCH 3/4] cloud-setup: use union for NMCSProviderGetConfigIfaceData.priv Use a union, it makes more sense. Note that with union, C's struct initialization might not sufficiently set all fields to the default. In practice yes, but theoretically in C a NULL pointer and floats must not have all zero bits, so the following is not guaranteed to work: struct { int some_field; union { void *v_ptr; int v_int; }; } variable = { .some_field = 24, }; assert(variable.union.v_ptr == 0); assert(variable.union.v_int == 0); When initializing the variable, we should not rely on automatically initialize all union members correctly. It cannot at the same time set NULL pointers and zero integers -- well, on our architectures it probably can, but not as far as guaranteed by C language. We need to know which union field we are going to use and initialize it explicitly. As we know the provider type, we can do that. Also, maybe in the future we need special free/unref calls when destroying the type specific data in NMCSProviderGetConfigIfaceData. As we know the provider, we can. Note that having type specific data in NMCSProviderGetConfigIfaceData.priv is a layering violation. But it is still simpler than implementing type specific handlers (callbacks) or tracking the data somewhere else. After all, we know at compile time all the existing provider types. (cherry picked from commit 1e696c7e93c14bc2ea7bfdcf4a655621ceb4e862) --- src/nm-cloud-setup/nmcs-provider.c | 11 +++++++++++ src/nm-cloud-setup/nmcs-provider.h | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/nm-cloud-setup/nmcs-provider.c b/src/nm-cloud-setup/nmcs-provider.c index a519ef9b5e..fd9a61b813 100644 --- a/src/nm-cloud-setup/nmcs-provider.c +++ b/src/nm-cloud-setup/nmcs-provider.c @@ -192,6 +192,17 @@ nmcs_provider_get_config_iface_data_create(NMCSProviderGetConfigTaskData *get_co .was_requested = was_requested, }; + /* "priv" is a union, and according to C, it might not be properly initialized + * that all union members are set to false/0/NULL/0.0. We need to know which + * union field we are going to use, and that depends on the type of "self". + * Also, knowing the type would allow us to initialize to something other than + * false/0/NULL/0.0. */ + if (G_OBJECT_TYPE(get_config_data->self) == nmcs_provider_aliyun_get_type()) { + iface_data->priv.aliyun = (typeof(iface_data->priv.aliyun)){ + .has_primary_ip_address = FALSE, + }; + } + /* the has does not own the key (iface_datta->hwaddr), the lifetime of the * key is associated with the iface_data instance. */ g_hash_table_replace(get_config_data->result_dict, (char *) iface_data->hwaddr, iface_data); diff --git a/src/nm-cloud-setup/nmcs-provider.h b/src/nm-cloud-setup/nmcs-provider.h index d1ab0a33c2..502f1d0323 100644 --- a/src/nm-cloud-setup/nmcs-provider.h +++ b/src/nm-cloud-setup/nmcs-provider.h @@ -45,7 +45,7 @@ typedef struct { * the implementations. However, it's convenient to track implementation specific data * here, thus we violate such separation. In practice, all subclasses are known * at compile time, and it will be simpler this way. */ - struct { + union { struct { in_addr_t primary_ip_address; bool has_primary_ip_address : 1; @@ -191,4 +191,11 @@ void nmcs_provider_get_config(NMCSProvider *provider, NMCSProviderGetConfigResult * nmcs_provider_get_config_finish(NMCSProvider *provider, GAsyncResult *result, GError **error); +/*****************************************************************************/ + +/* Forward declare the implemented gtype getters so we can use it at a few places without requiring + * to include the full header. The other parts of those headers should not be used aside where they + * are necessary. */ +GType nmcs_provider_aliyun_get_type(void); + #endif /* __NMCS_PROVIDER_H__ */ From a1d9fce14725011a93eb92a87f862d5dd1e0bcb7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 29 Apr 2022 10:34:48 +0200 Subject: [PATCH 4/4] cloud-setup: only pass config-iface-data as user-data for async functions From config_iface_data->get_config_data we have access to the other pointer already. No need to allocate a user data. (cherry picked from commit 7d71aff24770ad8ba6c6bc16a83d4d9e2544bd45) --- src/nm-cloud-setup/nmcs-provider-aliyun.c | 45 +++++++++++------------ src/nm-cloud-setup/nmcs-provider-ec2.c | 29 +++++++-------- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/nm-cloud-setup/nmcs-provider-aliyun.c b/src/nm-cloud-setup/nmcs-provider-aliyun.c index 02fd7a01aa..1a5e5459e4 100644 --- a/src/nm-cloud-setup/nmcs-provider-aliyun.c +++ b/src/nm-cloud-setup/nmcs-provider-aliyun.c @@ -129,24 +129,20 @@ typedef enum { } GetConfigFetchDoneType; static void -_get_config_fetch_done_cb(NMHttpClient *http_client, - GAsyncResult *result, - gpointer user_data, - GetConfigFetchDoneType fetch_type) +_get_config_fetch_done_cb(NMHttpClient *http_client, + GAsyncResult *result, + NMCSProviderGetConfigIfaceData *config_iface_data, + GetConfigFetchDoneType fetch_type) { - NMCSProviderGetConfigTaskData *get_config_data; - gs_unref_bytes GBytes *response = NULL; - gs_free_error GError *error = NULL; - NMCSProviderGetConfigIfaceData *config_iface_data; - in_addr_t tmp_addr; - int tmp_prefix; - in_addr_t netmask_bin; - in_addr_t gateway_bin; - gs_free const char **s_addrs = NULL; - gsize i; - gsize len; - - nm_utils_user_data_unpack(user_data, &get_config_data, &config_iface_data); + gs_unref_bytes GBytes *response = NULL; + gs_free_error GError *error = NULL; + in_addr_t tmp_addr; + int tmp_prefix; + in_addr_t netmask_bin; + in_addr_t gateway_bin; + gs_free const char **s_addrs = NULL; + gsize i; + gsize len; nm_http_client_poll_get_finish(http_client, result, NULL, &response, &error); @@ -244,8 +240,9 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, } out: - get_config_data->n_pending--; - _nmcs_provider_get_config_task_maybe_return(get_config_data, g_steal_pointer(&error)); + config_iface_data->get_config_data->n_pending--; + _nmcs_provider_get_config_task_maybe_return(config_iface_data->get_config_data, + g_steal_pointer(&error)); } static void @@ -379,7 +376,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us NULL, NULL, _get_config_fetch_done_cb_vpc_cidr_block, - nm_utils_user_data_pack(get_config_data, config_iface_data)); + config_iface_data); get_config_data->n_pending++; nm_http_client_poll_get( @@ -396,7 +393,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us NULL, NULL, _get_config_fetch_done_cb_private_ipv4s, - nm_utils_user_data_pack(get_config_data, config_iface_data)); + config_iface_data); get_config_data->n_pending++; nm_http_client_poll_get( @@ -413,7 +410,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us NULL, NULL, _get_config_fetch_done_cb_primary_ip_address, - nm_utils_user_data_pack(get_config_data, config_iface_data)); + config_iface_data); get_config_data->n_pending++; nm_http_client_poll_get( @@ -430,7 +427,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us NULL, NULL, _get_config_fetch_done_cb_netmask, - nm_utils_user_data_pack(get_config_data, config_iface_data)); + config_iface_data); get_config_data->n_pending++; nm_http_client_poll_get( @@ -447,7 +444,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us NULL, NULL, _get_config_fetch_done_cb_gateway, - nm_utils_user_data_pack(get_config_data, config_iface_data)); + config_iface_data); } _nmcs_provider_get_config_task_maybe_return(get_config_data, NULL); diff --git a/src/nm-cloud-setup/nmcs-provider-ec2.c b/src/nm-cloud-setup/nmcs-provider-ec2.c index 8362dd7c79..d6fa03118d 100644 --- a/src/nm-cloud-setup/nmcs-provider-ec2.c +++ b/src/nm-cloud-setup/nmcs-provider-ec2.c @@ -116,19 +116,15 @@ detect(NMCSProvider *provider, GTask *task) /*****************************************************************************/ static void -_get_config_fetch_done_cb(NMHttpClient *http_client, - GAsyncResult *result, - gpointer user_data, - gboolean is_local_ipv4) +_get_config_fetch_done_cb(NMHttpClient *http_client, + GAsyncResult *result, + NMCSProviderGetConfigIfaceData *config_iface_data, + gboolean is_local_ipv4) { - NMCSProviderGetConfigTaskData *get_config_data; - gs_unref_bytes GBytes *response = NULL; - gs_free_error GError *error = NULL; - NMCSProviderGetConfigIfaceData *config_iface_data; - in_addr_t tmp_addr; - int tmp_prefix; - - nm_utils_user_data_unpack(user_data, &get_config_data, &config_iface_data); + gs_unref_bytes GBytes *response = NULL; + gs_free_error GError *error = NULL; + in_addr_t tmp_addr; + int tmp_prefix; nm_http_client_poll_get_finish(http_client, result, NULL, &response, &error); @@ -173,8 +169,9 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, } out: - get_config_data->n_pending--; - _nmcs_provider_get_config_task_maybe_return(get_config_data, g_steal_pointer(&error)); + config_iface_data->get_config_data->n_pending--; + _nmcs_provider_get_config_task_maybe_return(config_iface_data->get_config_data, + g_steal_pointer(&error)); } static void @@ -271,7 +268,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us NULL, NULL, _get_config_fetch_done_cb_subnet_ipv4_cidr_block, - nm_utils_user_data_pack(get_config_data, config_iface_data)); + config_iface_data); get_config_data->n_pending++; nm_http_client_poll_get( @@ -288,7 +285,7 @@ _get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer us NULL, NULL, _get_config_fetch_done_cb_local_ipv4s, - nm_utils_user_data_pack(get_config_data, config_iface_data)); + config_iface_data); } _nmcs_provider_get_config_task_maybe_return(get_config_data, NULL);