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 <liangwen12year@gmail.com>
(cherry picked from commit 778e1f8493)
(cherry picked from commit 59633dbe11)
This commit is contained in:
Wen Liang 2021-08-05 07:44:05 -04:00 committed by Fernando Fernandez Mancera
parent 661da869b3
commit a9e6aa663e
2 changed files with 9 additions and 5 deletions

View file

@ -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;

View file

@ -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;