From bf9fab47adf4860e81f31ade07d75cbe1f0d7d0e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 21 May 2021 12:16:36 +0200 Subject: [PATCH] dhcp/systemd: handle private options 249,252 specially nettools plugin represents the way how to do it, and other plugins should mimic that behavior. The nettools implementation adds private DHCP options as hex, except the options - 249 (Microsoft Classless Static Route) - 252 (Web Proxy Auto Discovery Protocol) Adjust systemd plugin to do the same. For 252, we now parse the "wpad" option differently. The change in behavior is that the property is now no longer exposed as hexstring, but as backslash escaped plain text. For 249, the option is not implemented. But stop adding the option as hex-string too. --- src/core/dhcp/nm-dhcp-systemd.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/core/dhcp/nm-dhcp-systemd.c b/src/core/dhcp/nm-dhcp-systemd.c index e863892585..94cb443d18 100644 --- a/src/core/dhcp/nm-dhcp-systemd.c +++ b/src/core/dhcp/nm-dhcp-systemd.c @@ -429,18 +429,33 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, num = nm_sd_dhcp_lease_get_private_options(lease, &private_options); if (num > 0) { for (i = 0; i < num; i++) { - char *option_string; + guint8 code = private_options[i].code; + const guint8 *l_data = private_options[i].data; + gsize l_data_len = private_options[i].data_len; + char * option_string; - option_string = nm_utils_bin2hexstr_full(private_options[i].data, - private_options[i].data_len, - ':', - FALSE, - NULL); - if (!options) { - g_free(option_string); + if (code == NM_DHCP_OPTION_DHCP4_PRIVATE_PROXY_AUTODISCOVERY) { + if (nm_dhcp_lease_data_parse_cstr(l_data, l_data_len, &l_data_len)) { + nm_dhcp_option_add_option_utf8safe_escape( + options, + AF_INET, + NM_DHCP_OPTION_DHCP4_PRIVATE_PROXY_AUTODISCOVERY, + l_data, + l_data_len); + } continue; } - nm_dhcp_option_take_option(options, AF_INET, private_options[i].code, option_string); + if (code == NM_DHCP_OPTION_DHCP4_PRIVATE_CLASSLESS_STATIC_ROUTE) { + /* nettools and dhclient parse option 249 (Microsoft Classless Static Route) + * as fallback for routes and ignores them from private options. + * + * The systemd plugin does not, and for consistency with nettools we + * also don't expose it as private option either. */ + continue; + } + + option_string = nm_utils_bin2hexstr_full(l_data, l_data_len, ':', FALSE, NULL); + nm_dhcp_option_take_option(options, AF_INET, code, option_string); } } NM_SET_OUT(out_options, g_steal_pointer(&options));