dhcp: merge branch 'bg/nettools-options'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/592
This commit is contained in:
Beniamino Galvani 2020-08-24 16:53:53 +02:00
commit 935e9a4f92
2 changed files with 63 additions and 12 deletions

View file

@ -8,6 +8,12 @@
#include <netinet/in.h>
static inline gboolean
nm_is_ascii (char ch)
{
return ((uint8_t) ch) < 128;
}
/*****************************************************************************/
pid_t nm_utils_gettid (void);

View file

@ -468,9 +468,10 @@ lease_parse_address (NDhcp4ClientLease *lease,
}
static void
lease_parse_domain_name_servers (NDhcp4ClientLease *lease,
NMIP4Config *ip4_config,
GHashTable *options)
lease_parse_address_list (NDhcp4ClientLease *lease,
NMIP4Config *ip4_config,
NMDhcpOptionDhcp4Options option,
GHashTable *options)
{
nm_auto_free_gstring GString *str = NULL;
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
@ -479,7 +480,7 @@ lease_parse_domain_name_servers (NDhcp4ClientLease *lease,
size_t n_data;
int r;
r = n_dhcp4_client_lease_query (lease, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, &data, &n_data);
r = n_dhcp4_client_lease_query (lease, option, &data, &n_data);
if (r)
return;
@ -490,18 +491,30 @@ lease_parse_domain_name_servers (NDhcp4ClientLease *lease,
_nm_utils_inet4_ntop (addr.s_addr, addr_str);
g_string_append (nm_gstring_add_space_delimiter (str), addr_str);
if ( addr.s_addr == 0
|| nm_ip4_addr_is_localhost (addr.s_addr)) {
/* Skip localhost addresses, like also networkd does.
* See https://github.com/systemd/systemd/issues/4524. */
continue;
switch (option) {
case NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER:
if ( addr.s_addr == 0
|| nm_ip4_addr_is_localhost (addr.s_addr)) {
/* Skip localhost addresses, like also networkd does.
* See https://github.com/systemd/systemd/issues/4524. */
continue;
}
nm_ip4_config_add_nameserver (ip4_config, addr.s_addr);
break;
case NM_DHCP_OPTION_DHCP4_NIS_SERVERS:
nm_ip4_config_add_nis_server (ip4_config, addr.s_addr);
break;
case NM_DHCP_OPTION_DHCP4_NETBIOS_NAMESERVER:
nm_ip4_config_add_wins (ip4_config, addr.s_addr);
break;
default:
nm_assert_not_reached ();
}
nm_ip4_config_add_nameserver (ip4_config, addr.s_addr);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER,
option,
str->str);
}
@ -890,6 +903,35 @@ lease_parse_wpad (NDhcp4ClientLease *lease,
wpad);
}
static void
lease_parse_nis_domain (NDhcp4ClientLease *lease,
NMIP4Config *ip4_config,
GHashTable *options)
{
gs_free char *str_free = NULL;
const char *str;
uint8_t *data;
size_t n_data;
guint i;
int r;
r = n_dhcp4_client_lease_query (lease, NM_DHCP_OPTION_DHCP4_NIS_DOMAIN, &data, &n_data);
if (r)
return;
for (i = 0; i < n_data; i++) {
if (!nm_is_ascii ((char) data[i]))
return;
}
str = nm_strndup_a (300, (const char *) data, n_data, &str_free);
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
NM_DHCP_OPTION_DHCP4_NIS_DOMAIN,
str);
nm_ip4_config_set_nis_domain (ip4_config, str);
}
static void
lease_parse_private_options (NDhcp4ClientLease *lease,
GHashTable *options)
@ -942,7 +984,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
return NULL;
lease_parse_routes (lease, ip4_config, options, route_table, route_metric);
lease_parse_domain_name_servers (lease, ip4_config, options);
lease_parse_address_list (lease, ip4_config, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, options);
lease_parse_domainname (lease, ip4_config, options);
lease_parse_search_domains (lease, ip4_config, options);
lease_parse_mtu (lease, ip4_config, options);
@ -952,6 +994,9 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
lease_parse_ntps (lease, options);
lease_parse_root_path (lease, options);
lease_parse_wpad (lease, options);
lease_parse_nis_domain (lease, ip4_config, options);
lease_parse_address_list (lease, ip4_config, NM_DHCP_OPTION_DHCP4_NIS_SERVERS, options);
lease_parse_address_list (lease, ip4_config, NM_DHCP_OPTION_DHCP4_NETBIOS_NAMESERVER, options);
lease_parse_private_options (lease, options);
NM_SET_OUT (out_options, g_steal_pointer (&options));