summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2020-08-24 16:53:53 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2020-08-24 16:53:53 +0200
commit935e9a4f926aa1872f03281f0aa5f4edcab6eaba (patch)
treeb063f4d57c8d4ddcf1bc04c9a306ff4edf8a7782
parent94ded0c5b2472693190c5d6da77d3c811bdbd63b (diff)
parent01a1eaf02f66b6de74f531b55433500ec8b0f4b8 (diff)
downloadNetworkManager-935e9a4f926aa1872f03281f0aa5f4edcab6eaba.tar.gz
dhcp: merge branch 'bg/nettools-options'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/592
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h6
-rw-r--r--src/dhcp/nm-dhcp-nettools.c69
2 files changed, 63 insertions, 12 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 7efb8aed52..a097a690c8 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -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);
diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c
index 8d7d021710..2ceed09537 100644
--- a/src/dhcp/nm-dhcp-nettools.c
+++ b/src/dhcp/nm-dhcp-nettools.c
@@ -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);
}
@@ -891,6 +904,35 @@ lease_parse_wpad (NDhcp4ClientLease *lease,
}
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));