mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-20 16:20:05 +01:00
dhcp: fix ignoring addresses with DHCPv6 otherconf (O flag)
With O flag (otherconf mode), don't add the IPv6 addresses to the
collected lease.
An alternative would be to add it initially, but ignore it when
merging the configuration in NML3Cfg. The idea of that would be that if
the mode switches from otherconf to managed, that we already have the
address. However, depending on the mode we already make different DHCPv6
requests (at least for internal client). That means, if the mode changes
we anyway cannot just use the previous lease, because it might not
contain all the information. So it seems better to ignore the address
early.
Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
https://bugzilla.redhat.com/show_bug.cgi?id=2083968
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/ ## 953
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/ ## 1220
This commit is contained in:
parent
f7a7734382
commit
ea891485c7
2 changed files with 42 additions and 33 deletions
|
|
@ -80,14 +80,12 @@ lease_to_ip6_config(NMDedupMultiIndex *multi_idx,
|
||||||
gs_unref_hashtable GHashTable *options = NULL;
|
gs_unref_hashtable GHashTable *options = NULL;
|
||||||
struct in6_addr tmp_addr;
|
struct in6_addr tmp_addr;
|
||||||
const struct in6_addr *dns;
|
const struct in6_addr *dns;
|
||||||
uint32_t lft_pref, lft_valid;
|
|
||||||
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
|
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
|
||||||
char **domains;
|
char **domains;
|
||||||
char **ntp_fqdns;
|
char **ntp_fqdns;
|
||||||
const struct in6_addr *ntp_addrs;
|
const struct in6_addr *ntp_addrs;
|
||||||
const char *s;
|
const char *s;
|
||||||
nm_auto_free_gstring GString *str = NULL;
|
nm_auto_free_gstring GString *str = NULL;
|
||||||
gboolean has_any_addresses = FALSE;
|
|
||||||
int num, i;
|
int num, i;
|
||||||
|
|
||||||
nm_assert(lease);
|
nm_assert(lease);
|
||||||
|
|
@ -96,36 +94,45 @@ lease_to_ip6_config(NMDedupMultiIndex *multi_idx,
|
||||||
|
|
||||||
options = nm_dhcp_option_create_options_dict();
|
options = nm_dhcp_option_create_options_dict();
|
||||||
|
|
||||||
sd_dhcp6_lease_reset_address_iter(lease);
|
if (!info_only) {
|
||||||
nm_gstring_prepare(&str);
|
gboolean has_any_addresses = FALSE;
|
||||||
while (sd_dhcp6_lease_get_address(lease, &tmp_addr, &lft_pref, &lft_valid) >= 0) {
|
uint32_t lft_pref;
|
||||||
const NMPlatformIP6Address address = {
|
uint32_t lft_valid;
|
||||||
.plen = 128,
|
|
||||||
.address = tmp_addr,
|
|
||||||
.timestamp = ts,
|
|
||||||
.lifetime = lft_valid,
|
|
||||||
.preferred = lft_pref,
|
|
||||||
.addr_source = NM_IP_CONFIG_SOURCE_DHCP,
|
|
||||||
};
|
|
||||||
|
|
||||||
nm_l3_config_data_add_address_6(l3cd, &address);
|
sd_dhcp6_lease_reset_address_iter(lease);
|
||||||
|
nm_gstring_prepare(&str);
|
||||||
|
while (sd_dhcp6_lease_get_address(lease, &tmp_addr, &lft_pref, &lft_valid) >= 0) {
|
||||||
|
const NMPlatformIP6Address address = {
|
||||||
|
.plen = 128,
|
||||||
|
.address = tmp_addr,
|
||||||
|
.timestamp = ts,
|
||||||
|
.lifetime = lft_valid,
|
||||||
|
.preferred = lft_pref,
|
||||||
|
.addr_source = NM_IP_CONFIG_SOURCE_DHCP,
|
||||||
|
};
|
||||||
|
|
||||||
_nm_utils_inet6_ntop(&tmp_addr, addr_str);
|
nm_l3_config_data_add_address_6(l3cd, &address);
|
||||||
g_string_append(nm_gstring_add_space_delimiter(str), addr_str);
|
|
||||||
|
|
||||||
has_any_addresses = TRUE;
|
_nm_utils_inet6_ntop(&tmp_addr, addr_str);
|
||||||
}
|
g_string_append(nm_gstring_add_space_delimiter(str), addr_str);
|
||||||
|
|
||||||
if (str->len) {
|
has_any_addresses = TRUE;
|
||||||
nm_dhcp_option_add_option(options, AF_INET6, NM_DHCP_OPTION_DHCP6_NM_IP_ADDRESS, str->str);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!info_only && !has_any_addresses) {
|
if (str->len) {
|
||||||
g_set_error_literal(error,
|
nm_dhcp_option_add_option(options,
|
||||||
NM_MANAGER_ERROR,
|
AF_INET6,
|
||||||
NM_MANAGER_ERROR_FAILED,
|
NM_DHCP_OPTION_DHCP6_NM_IP_ADDRESS,
|
||||||
"no address received in managed mode");
|
str->str);
|
||||||
return NULL;
|
}
|
||||||
|
|
||||||
|
if (!has_any_addresses) {
|
||||||
|
g_set_error_literal(error,
|
||||||
|
NM_MANAGER_ERROR,
|
||||||
|
NM_MANAGER_ERROR_FAILED,
|
||||||
|
"no address received in managed mode");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
num = sd_dhcp6_lease_get_dns(lease, &dns);
|
num = sd_dhcp6_lease_get_dns(lease, &dns);
|
||||||
|
|
|
||||||
|
|
@ -670,8 +670,13 @@ nm_dhcp_utils_ip6_config_from_options(NMDedupMultiIndex *multi_idx,
|
||||||
_LOG2I(LOGD_DHCP6, iface, " preferred_lft %u", address.preferred);
|
_LOG2I(LOGD_DHCP6, iface, " preferred_lft %u", address.preferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
str = g_hash_table_lookup(options, "ip6_address");
|
if (!info_only) {
|
||||||
if (str) {
|
str = g_hash_table_lookup(options, "ip6_address");
|
||||||
|
if (!str) {
|
||||||
|
/* No address in Managed mode is a hard error */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!inet_pton(AF_INET6, str, &tmp_addr)) {
|
if (!inet_pton(AF_INET6, str, &tmp_addr)) {
|
||||||
_LOG2W(LOGD_DHCP6, iface, "(%s): DHCP returned invalid address '%s'", iface, str);
|
_LOG2W(LOGD_DHCP6, iface, "(%s): DHCP returned invalid address '%s'", iface, str);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -681,9 +686,6 @@ nm_dhcp_utils_ip6_config_from_options(NMDedupMultiIndex *multi_idx,
|
||||||
address.addr_source = NM_IP_CONFIG_SOURCE_DHCP;
|
address.addr_source = NM_IP_CONFIG_SOURCE_DHCP;
|
||||||
nm_l3_config_data_add_address_6(l3cd, &address);
|
nm_l3_config_data_add_address_6(l3cd, &address);
|
||||||
_LOG2I(LOGD_DHCP6, iface, " address %s", str);
|
_LOG2I(LOGD_DHCP6, iface, " address %s", str);
|
||||||
} else if (info_only == FALSE) {
|
|
||||||
/* No address in Managed mode is a hard error */
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
str = g_hash_table_lookup(options, "host_name");
|
str = g_hash_table_lookup(options, "host_name");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue