From 90dca9e0c9bb28c5cdce09a7fe0bebc263943c02 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 24 Jun 2016 09:19:42 +0200 Subject: [PATCH] dns: log DNS servers at TRACE level Be more verbose at TRACE level and log the DNS servers associated to configurations. This will help to debug issues like [0]. [0] https://bugzilla.redhat.com/show_bug.cgi?id=1348887 (cherry picked from commit a5d1db08f8a6d422d6dcb382fb0ca93f018299a9) --- shared/nm-macros-internal.h | 8 ++++++ src/dns-manager/nm-dns-manager.c | 46 +++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h index ffa3ace086..fe27b761a0 100644 --- a/shared/nm-macros-internal.h +++ b/shared/nm-macros-internal.h @@ -46,6 +46,14 @@ _nm_auto_unset_gvalue_impl (GValue *v) } #define nm_auto_unset_gvalue nm_auto(_nm_auto_unset_gvalue_impl) +static inline void +_nm_auto_free_gstring_impl (GString **str) +{ + if (*str) + g_string_free (*str, TRUE); +} +#define nm_auto_free_gstring nm_auto(_nm_auto_free_gstring_impl) + /********************************************************/ /* http://stackoverflow.com/a/11172679 */ diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c index 6c29bd390f..3efd5ac1a8 100644 --- a/src/dns-manager/nm-dns-manager.c +++ b/src/dns-manager/nm-dns-manager.c @@ -940,6 +940,44 @@ merge_global_dns_config (NMResolvConfData *rc, NMGlobalDnsConfig *global_conf) return TRUE; } +static const char * +get_nameserver_list (void *config, GString **str) +{ + NMIP4Config *ip4; + NMIP6Config *ip6; + guint num, i; + + nm_assert (str); + + if (*str) + g_string_truncate (*str, 0); + else + *str = g_string_sized_new (64); + + if (NM_IS_IP4_CONFIG (config)) { + ip4 = (NMIP4Config *) config; + num = nm_ip4_config_get_num_nameservers (ip4); + for (i = 0; i < num; i++) { + g_string_append (*str, + nm_utils_inet4_ntop (nm_ip4_config_get_nameserver (ip4, i), + NULL)); + g_string_append_c (*str, ' '); + } + } else if (NM_IS_IP6_CONFIG (config)) { + ip6 = (NMIP6Config *) config; + num = nm_ip6_config_get_num_nameservers (ip6); + for (i = 0; i < num; i++) { + g_string_append (*str, + nm_utils_inet6_ntop (nm_ip6_config_get_nameserver (ip6, i), + NULL)); + g_string_append_c (*str, ' '); + } + } else + g_return_val_if_reached (NULL); + + return (*str)->str; +} + static gboolean update_dns (NMDnsManager *self, gboolean no_caching, @@ -959,6 +997,7 @@ update_dns (NMDnsManager *self, NMConfigData *data; NMGlobalDnsConfig *global_config; gs_free NMDnsIPConfigData **plugin_confs = NULL; + nm_auto_free_gstring GString *tmp_gstring = NULL; g_return_val_if_fail (!error || !*error, FALSE); @@ -1015,12 +1054,13 @@ update_dns (NMDnsManager *self, prev_prio = prio; - _LOGT ("config: %8d %-7s v%c %-16s %s", + _LOGT ("config: %8d %-7s v%c %-16s %s: %s", prio, _config_type_to_string (current->type), - v4 ? '4' : '6', + v4 ? '4' : '6', current->iface, - skip ? "" : ""); + skip ? "" : "", + get_nameserver_list (current->config, &tmp_gstring)); if (!skip) { merge_one_ip_config_data (self, &rc, current);