From a9e6aa663e1cf9d155ddfa49a75ac8ecd1982a17 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Thu, 5 Aug 2021 07:44:05 -0400 Subject: [PATCH] aliyun: reuse ipv4 gateway address returned by metadata server The default ipv4 gateway address of the VPC in Aliyun cloud is not the first IP address in the CIDR subnet block, we should instead use the ipv4 gateway address retrieved from the metadata server in `_nmc_mangle_connection()`. https://bugzilla.redhat.com/show_bug.cgi?id=1823315 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/958 Signed-off-by: Wen Liang (cherry picked from commit 778e1f8493babb8e015e5334806de7099c66bafb) (cherry picked from commit 59633dbe117f97f5b453df6a4b1e5a918d2160e8) --- clients/cloud-setup/main.c | 12 +++++++----- clients/cloud-setup/nmcs-provider.h | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/clients/cloud-setup/main.c b/clients/cloud-setup/main.c index 9fa4cd3c84..b2b2eabe76 100644 --- a/clients/cloud-setup/main.c +++ b/clients/cloud-setup/main.c @@ -347,11 +347,13 @@ _nmc_mangle_connection(NMDevice * device, if (entry) g_ptr_array_add(addrs_new, entry); } - - gateway = nm_utils_ip4_address_clear_host_address(config_data->cidr_addr, - config_data->cidr_prefix); - ((guint8 *) &gateway)[3] += 1; - + if (config_data->has_gateway && config_data->gateway) { + gateway = config_data->gateway; + } else { + gateway = nm_utils_ip4_address_clear_host_address(config_data->cidr_addr, + config_data->cidr_prefix); + ((guint8 *) &gateway)[3] += 1; + } rt_metric = 10; rt_table = 30400 + config_data->iface_idx; diff --git a/clients/cloud-setup/nmcs-provider.h b/clients/cloud-setup/nmcs-provider.h index 261f589f2f..3663205964 100644 --- a/clients/cloud-setup/nmcs-provider.h +++ b/clients/cloud-setup/nmcs-provider.h @@ -23,9 +23,11 @@ typedef struct { gssize iface_idx; in_addr_t cidr_addr; + in_addr_t gateway; guint8 cidr_prefix; bool has_ipv4s : 1; bool has_cidr : 1; + bool has_gateway : 1; NMIPRoute **iproutes_arr; gsize iproutes_len;