diff options
author | Thomas Haller <thaller@redhat.com> | 2017-10-06 13:17:58 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-10-09 22:05:35 +0200 |
commit | 8f1ef161f4dd5ac197b622ac681d55d64c176797 (patch) | |
tree | 7833118bbe210b5687dbdb4da6ef00f7617e5739 /src/nm-ip6-config.c | |
parent | 6a3005ea72ecf9a5df7386c4e106e5816c836980 (diff) | |
download | NetworkManager-8f1ef161f4dd5ac197b622ac681d55d64c176797.tar.gz |
core: refactor parsing resolve.conf
- merge the IPv4 and IPv6 implementations. They are for the most
part identical. Also, they are independent of NMIP4Config/NMIP6Config.
- parse the entire file at once. Don't parse it twice, once for the
name servers and once for the options. This also avoids loading
/etc/resolv.conf twice, as it would be done before.
Diffstat (limited to 'src/nm-ip6-config.c')
-rw-r--r-- | src/nm-ip6-config.c | 85 |
1 files changed, 12 insertions, 73 deletions
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 699c60d3b2..923d2da9bb 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -25,6 +25,7 @@ #include <string.h> #include <arpa/inet.h> +#include <resolv.h> #include "nm-utils/nm-dedup-multi.h" @@ -229,72 +230,6 @@ _notify_routes (NMIP6Config *self) /*****************************************************************************/ -/** - * nm_ip6_config_capture_resolv_conf(): - * @nameservers: array of struct in6_addr - * @rc_contents: the contents of a resolv.conf or %NULL to read /etc/resolv.conf - * - * Reads all resolv.conf IPv6 nameservers and adds them to @nameservers. - * - * Returns: %TRUE if nameservers were added, %FALSE if @nameservers is unchanged - */ -gboolean -nm_ip6_config_capture_resolv_conf (GArray *nameservers, - GPtrArray *dns_options, - const char *rc_contents) -{ - GPtrArray *read_ns, *read_options; - guint i, j; - gboolean changed = FALSE; - - g_return_val_if_fail (nameservers != NULL, FALSE); - - read_ns = nm_utils_read_resolv_conf_nameservers (rc_contents); - if (!read_ns) - return FALSE; - - for (i = 0; i < read_ns->len; i++) { - const char *s = g_ptr_array_index (read_ns, i); - struct in6_addr ns = IN6ADDR_ANY_INIT; - - if (!inet_pton (AF_INET6, s, (void *) &ns) || IN6_IS_ADDR_UNSPECIFIED (&ns)) - continue; - - /* Ignore duplicates */ - for (j = 0; j < nameservers->len; j++) { - struct in6_addr *t = &g_array_index (nameservers, struct in6_addr, j); - - if (IN6_ARE_ADDR_EQUAL (t, &ns)) - break; - } - - if (j == nameservers->len) { - g_array_append_val (nameservers, ns); - changed = TRUE; - } - } - g_ptr_array_unref (read_ns); - - if (dns_options) { - read_options = nm_utils_read_resolv_conf_dns_options (rc_contents); - if (!read_options) - return changed; - - for (i = 0; i < read_options->len; i++) { - const char *s = g_ptr_array_index (read_options, i); - - if (_nm_utils_dns_option_validate (s, NULL, NULL, TRUE, _nm_utils_dns_option_descs) && - _nm_utils_dns_option_find_idx (dns_options, s) < 0) { - g_ptr_array_add (dns_options, g_strdup (s)); - changed = TRUE; - } - } - g_ptr_array_unref (read_options); - } - - return changed; -} - static gint _addresses_sort_cmp_get_prio (const struct in6_addr *addr) { @@ -444,7 +379,6 @@ nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i const NMDedupMultiHeadEntry *head_entry; NMDedupMultiIter iter; const NMPObject *plobj = NULL; - gboolean notify_nameservers = FALSE; gboolean has_addresses = FALSE; nm_assert (ifindex > 0); @@ -512,14 +446,19 @@ nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i /* If the interface has the default route, and has IPv6 addresses, capture * nameservers from /etc/resolv.conf. */ - if (has_addresses && has_gateway && capture_resolv_conf) - notify_nameservers = nm_ip6_config_capture_resolv_conf (priv->nameservers, - priv->dns_options, - NULL); + if (has_addresses && has_gateway && capture_resolv_conf) { + gs_free char *rc_contents = NULL; + + if (g_file_get_contents (_PATH_RESCONF, &rc_contents, NULL, NULL)) { + if (nm_utils_resolve_conf_parse (AF_INET6, + rc_contents, + priv->nameservers, + priv->dns_options)) + _notify (self, PROP_NAMESERVERS); + } + } /* actually, nobody should be connected to the signal, just to be sure, notify */ - if (notify_nameservers) - _notify (self, PROP_NAMESERVERS); _notify_addresses (self); _notify_routes (self); if (!IN6_ARE_ADDR_EQUAL (&priv->gateway, &old_gateway)) |