diff options
author | Thomas Haller <thaller@redhat.com> | 2021-04-20 14:31:58 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-04-20 17:46:05 +0200 |
commit | c9fc3f5b037422e7ead7f5ef1a56fcd2a750d152 (patch) | |
tree | bb2a636868c7c07658a453cb3e6af8817aafc25c | |
parent | 89f326785910ca7a4e6994b9d4052f8ab43fc63e (diff) | |
download | NetworkManager-c9fc3f5b037422e7ead7f5ef1a56fcd2a750d152.tar.gz |
cloud-setup/azure: cleanup constructing URI in _get_config_ips_prefix_list_cb()
-rw-r--r-- | src/nm-cloud-setup/nmcs-provider-azure.c | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/src/nm-cloud-setup/nmcs-provider-azure.c b/src/nm-cloud-setup/nmcs-provider-azure.c index 834db5e52b..b09becb2f6 100644 --- a/src/nm-cloud-setup/nmcs-provider-azure.c +++ b/src/nm-cloud-setup/nmcs-provider-azure.c @@ -207,6 +207,7 @@ _get_config_ips_prefix_list_cb(GObject *source, GAsyncResult *result, gpointer u NMCSProviderGetConfigTaskData *get_config_data; const char * line; gsize line_len; + char iface_idx_str[30]; nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error); @@ -222,12 +223,16 @@ _get_config_ips_prefix_list_cb(GObject *source, GAsyncResult *result, gpointer u /* NMHttpClient guarantees that there is a trailing NUL after the data. */ nm_assert(response_str[response_len] == 0); - nm_assert(!iface_data->iface_get_config->has_ipv4s); nm_assert(!iface_data->iface_get_config->ipv4s_arr); + nm_assert(!iface_data->iface_get_config->has_ipv4s); nm_assert(!iface_data->iface_get_config->has_cidr); + nm_sprintf_buf(iface_idx_str, "%" G_GSSIZE_FORMAT, iface_data->intern_iface_idx); + while (nm_utils_parse_next_line(&response_str, &response_len, &line, &line_len)) { - gint64 ips_prefix_idx; + gint64 ips_prefix_idx; + gs_free char *uri = NULL; + char buf[100]; if (line_len == 0) continue; @@ -242,45 +247,36 @@ _get_config_ips_prefix_list_cb(GObject *source, GAsyncResult *result, gpointer u if (ips_prefix_idx < 0) continue; - { - gs_free const char *uri = NULL; - char buf[100]; - - iface_data->n_iface_data_pending++; - - nm_http_client_poll_get( - NM_HTTP_CLIENT(source), - (uri = _azure_uri_interfaces(nm_sprintf_buf( - buf, - "%" G_GSSIZE_FORMAT "/ipv4/ipAddress/%" G_GINT64_FORMAT "/privateIpAddress", - iface_data->intern_iface_idx, - ips_prefix_idx))), - HTTP_TIMEOUT_MS, - 512 * 1024, - 10000, - 1000, - NM_MAKE_STRV(NM_AZURE_METADATA_HEADER), - get_config_data->intern_cancellable, - NULL, - NULL, - _get_config_fetch_done_cb_private_ipv4s, - iface_data); - } + iface_data->n_iface_data_pending++; + + nm_http_client_poll_get( + NM_HTTP_CLIENT(source), + (uri = _azure_uri_interfaces(iface_idx_str, + "/ipv4/ipAddress/", + nm_sprintf_buf(buf, "%" G_GINT64_FORMAT, ips_prefix_idx), + "/privateIpAddress")), + HTTP_TIMEOUT_MS, + 512 * 1024, + 10000, + 1000, + NM_MAKE_STRV(NM_AZURE_METADATA_HEADER), + get_config_data->intern_cancellable, + NULL, + NULL, + _get_config_fetch_done_cb_private_ipv4s, + iface_data); } iface_data->iface_get_config->ipv4s_len = 0; iface_data->iface_get_config->ipv4s_arr = g_new(in_addr_t, iface_data->n_iface_data_pending); { - gs_free const char *uri = NULL; - char buf[30]; + gs_free char *uri = NULL; iface_data->n_iface_data_pending++; nm_http_client_poll_get( NM_HTTP_CLIENT(source), - (uri = _azure_uri_interfaces( - nm_sprintf_buf(buf, "%" G_GSSIZE_FORMAT, iface_data->intern_iface_idx), - "/ipv4/subnet/0/prefix/")), + (uri = _azure_uri_interfaces(iface_idx_str, "/ipv4/subnet/0/prefix/")), HTTP_TIMEOUT_MS, 512 * 1024, 10000, |