dhcp: nettools: support option 249 (Microsoft Classless Static Route)

From [1]:

  The length and the data format for the Microsoft Classless Static
  Route Option are exactly the same as those specified for the
  Classless Static Route Option in [RFC3442]; the only difference is
  that Option Code 249 should be used instead of or in addition to
  Option Code 121.

Use routes from option 249 when option 121 is not present, as already
done by the dhclient backend.

[1] https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dhcpe/f9c19c79-1c7f-4746-b555-0c0fc523f3f9

https://bugzilla.redhat.com/show_bug.cgi?id=1959461
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/851
This commit is contained in:
Beniamino Galvani 2021-05-11 19:10:09 +02:00
parent d7594ae9c9
commit e320beb330

View file

@ -342,16 +342,16 @@ lease_parse_routes(NDhcp4ClientLease *lease,
const guint8 *l_data;
gsize l_data_len;
int r;
guint i;
for (i = 0; i < 2; i++) {
const guint8 option_code = (i == 0) ? NM_DHCP_OPTION_DHCP4_CLASSLESS_STATIC_ROUTE
: NM_DHCP_OPTION_DHCP4_PRIVATE_CLASSLESS_STATIC_ROUTE;
if (_client_lease_query(lease, option_code, &l_data, &l_data_len) != 0)
continue;
r = _client_lease_query(lease,
NM_DHCP_OPTION_DHCP4_CLASSLESS_STATIC_ROUTE,
&l_data,
&l_data_len);
if (r == 0) {
nm_str_buf_reset(sbuf);
has_classless = TRUE;
while (lease_option_consume_route(&l_data, &l_data_len, TRUE, &dest, &plen, &gateway)) {
_nm_utils_inet4_ntop(dest, dest_str);
_nm_utils_inet4_ntop(gateway, gateway_str);
@ -359,6 +359,11 @@ lease_parse_routes(NDhcp4ClientLease *lease,
nm_str_buf_append_required_delimiter(sbuf, ' ');
nm_str_buf_append_printf(sbuf, "%s/%d %s", dest_str, (int) plen, gateway_str);
if (has_classless) {
/* Ignore private option if the standard one is present */
continue;
}
if (plen == 0) {
/* if there are multiple default routes, we add them with differing
* metrics. */
@ -384,10 +389,8 @@ lease_parse_routes(NDhcp4ClientLease *lease,
NULL);
}
nm_dhcp_option_add_option(options,
AF_INET,
NM_DHCP_OPTION_DHCP4_CLASSLESS_STATIC_ROUTE,
nm_str_buf_get_str(sbuf));
has_classless = TRUE;
nm_dhcp_option_add_option(options, AF_INET, option_code, nm_str_buf_get_str(sbuf));
}
r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_STATIC_ROUTE, &l_data, &l_data_len);