dhcp/nettools: accept missing "subnet mask" (option 1) in DHCP lease

Do the same as dhclient plugin in nm_dhcp_utils_ip4_config_from_options().

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1037
This commit is contained in:
Thomas Haller
2022-06-21 10:31:02 +02:00
parent 863b71a8fe
commit 57dfa999f7

View File

@@ -237,20 +237,26 @@ lease_parse_address(NDhcp4ClientLease *lease,
}
r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_SUBNET_MASK, &l_data, &l_data_len);
if (r != 0
|| !nm_dhcp_lease_data_parse_in_addr(l_data,
l_data_len,
&a_netmask,
iface,
NM_DHCP_OPTION_DHCP4_SUBNET_MASK)) {
nm_utils_error_set_literal(error,
NM_UTILS_ERROR_UNKNOWN,
"could not get netmask from lease");
return FALSE;
if (r == N_DHCP4_E_UNSET) {
/* Some DHCP servers may not set the subnet-mask (issue#1037).
* Do the same as the dhclient plugin and use a default. */
a_plen = _nm_utils_ip4_get_default_prefix(a_address.s_addr);
a_netmask = _nm_utils_ip4_prefix_to_netmask(a_plen);
} else {
if (r != 0
|| !nm_dhcp_lease_data_parse_in_addr(l_data,
l_data_len,
&a_netmask,
iface,
NM_DHCP_OPTION_DHCP4_SUBNET_MASK)) {
nm_utils_error_set_literal(error,
NM_UTILS_ERROR_UNKNOWN,
"could not get netmask from lease");
return FALSE;
}
a_plen = _nm_utils_ip4_netmask_to_prefix(a_netmask);
}
a_plen = _nm_utils_ip4_netmask_to_prefix(a_netmask);
nm_dhcp_option_add_option_in_addr(options,
AF_INET,
NM_DHCP_OPTION_DHCP4_NM_IP_ADDRESS,