From e01e43cd2fa80391c6be70e8bf48eb5228177f11 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 27 Oct 2014 15:44:46 -0500 Subject: [PATCH] dhcp: suppress warning about invalid DNS servers If the DHCP server happens to send "0.0.0.0", which you see with some consumer gear that only has one nameserver set, don't warn because we know it's bogus. Also rename the copy & pasted 'searches' variable to what it's actually used for. --- src/dhcp-manager/nm-dhcp-utils.c | 48 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/dhcp-manager/nm-dhcp-utils.c b/src/dhcp-manager/nm-dhcp-utils.c index 46fa96ecd..13e524aee 100644 --- a/src/dhcp-manager/nm-dhcp-utils.c +++ b/src/dhcp-manager/nm-dhcp-utils.c @@ -488,17 +488,19 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, str = g_hash_table_lookup (options, "domain_name_servers"); if (str) { - char **searches = g_strsplit (str, " ", 0); + char **dns = g_strsplit (str, " ", 0); char **s; - for (s = searches; *s; s++) { + for (s = dns; *s; s++) { if (inet_pton (AF_INET, *s, &tmp_addr) > 0) { - nm_ip4_config_add_nameserver (ip4_config, tmp_addr); - nm_log_info (LOGD_DHCP4, " nameserver '%s'", *s); + if (tmp_addr) { + nm_ip4_config_add_nameserver (ip4_config, tmp_addr); + nm_log_info (LOGD_DHCP4, " nameserver '%s'", *s); + } } else nm_log_warn (LOGD_DHCP4, "ignoring invalid nameserver '%s'", *s); } - g_strfreev (searches); + g_strfreev (dns); } str = g_hash_table_lookup (options, "domain_name"); @@ -519,17 +521,19 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, str = g_hash_table_lookup (options, "netbios_name_servers"); if (str) { - char **searches = g_strsplit (str, " ", 0); + char **nbns = g_strsplit (str, " ", 0); char **s; - for (s = searches; *s; s++) { + for (s = nbns; *s; s++) { if (inet_pton (AF_INET, *s, &tmp_addr) > 0) { - nm_ip4_config_add_wins (ip4_config, tmp_addr); - nm_log_info (LOGD_DHCP4, " wins '%s'", *s); + if (tmp_addr) { + nm_ip4_config_add_wins (ip4_config, tmp_addr); + nm_log_info (LOGD_DHCP4, " wins '%s'", *s); + } } else nm_log_warn (LOGD_DHCP4, "ignoring invalid WINS server '%s'", *s); } - g_strfreev (searches); + g_strfreev (nbns); } str = g_hash_table_lookup (options, "interface_mtu"); @@ -553,17 +557,19 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, str = g_hash_table_lookup (options, "nis_servers"); if (str) { - char **searches = g_strsplit (str, " ", 0); + char **nis = g_strsplit (str, " ", 0); char **s; - for (s = searches; *s; s++) { + for (s = nis; *s; s++) { if (inet_pton (AF_INET, *s, &tmp_addr) > 0) { - nm_ip4_config_add_nis_server (ip4_config, tmp_addr); - nm_log_info (LOGD_DHCP4, " nis '%s'", *s); + if (tmp_addr) { + nm_ip4_config_add_nis_server (ip4_config, tmp_addr); + nm_log_info (LOGD_DHCP4, " nis '%s'", *s); + } } else nm_log_warn (LOGD_DHCP4, "ignoring invalid NIS server '%s'", *s); } - g_strfreev (searches); + g_strfreev (nis); } return ip4_config; @@ -643,17 +649,19 @@ nm_dhcp_utils_ip6_config_from_options (const char *iface, str = g_hash_table_lookup (options, "dhcp6_name_servers"); if (str) { - char **searches = g_strsplit (str, " ", 0); + char **dns = g_strsplit (str, " ", 0); char **s; - for (s = searches; *s; s++) { + for (s = dns; *s; s++) { if (inet_pton (AF_INET6, *s, &tmp_addr) > 0) { - nm_ip6_config_add_nameserver (ip6_config, &tmp_addr); - nm_log_info (LOGD_DHCP6, " nameserver '%s'", *s); + if (!IN6_IS_ADDR_UNSPECIFIED (&tmp_addr)) { + nm_ip6_config_add_nameserver (ip6_config, &tmp_addr); + nm_log_info (LOGD_DHCP6, " nameserver '%s'", *s); + } } else nm_log_warn (LOGD_DHCP6, "ignoring invalid nameserver '%s'", *s); } - g_strfreev (searches); + g_strfreev (dns); } str = g_hash_table_lookup (options, "dhcp6_domain_search");