mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 10:40:11 +01:00
dns: merge branch 'th/dns-minor-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/809
This commit is contained in:
commit
0d8fe37d64
1 changed files with 45 additions and 45 deletions
|
|
@ -22,6 +22,7 @@
|
|||
#include <libpsl.h>
|
||||
#endif
|
||||
|
||||
#include "libnm-glib-aux/nm-str-buf.h"
|
||||
#include "nm-utils.h"
|
||||
#include "libnm-core-intern/nm-core-internal.h"
|
||||
#include "nm-dns-manager.h"
|
||||
|
|
@ -83,13 +84,13 @@ typedef struct {
|
|||
GHashTable *configs_dict;
|
||||
CList configs_lst_head;
|
||||
|
||||
CList ip_configs_lst_head;
|
||||
CList ip_config_lst_head;
|
||||
GVariant *config_variant;
|
||||
|
||||
NMDnsConfigIPData *best_ip_config_4;
|
||||
NMDnsConfigIPData *best_ip_config_6;
|
||||
|
||||
bool ip_configs_lst_need_sort : 1;
|
||||
bool ip_config_lst_need_sort : 1;
|
||||
|
||||
bool configs_lst_need_sort : 1;
|
||||
|
||||
|
|
@ -266,9 +267,11 @@ _dns_config_ip_data_new(NMDnsConfigData * data,
|
|||
.ip_config_type = ip_config_type,
|
||||
};
|
||||
c_list_link_tail(&data->data_lst_head, &ip_data->data_lst);
|
||||
c_list_link_tail(&NM_DNS_MANAGER_GET_PRIVATE(data->self)->ip_configs_lst_head,
|
||||
c_list_link_tail(&NM_DNS_MANAGER_GET_PRIVATE(data->self)->ip_config_lst_head,
|
||||
&ip_data->ip_config_lst);
|
||||
|
||||
/* We also need to set priv->ip_config_lst_need_sort, but the caller will do that! */
|
||||
|
||||
g_signal_connect(ip_config,
|
||||
NM_IS_IP4_CONFIG(ip_config) ? "notify::" NM_IP4_CONFIG_DNS_PRIORITY
|
||||
: "notify::" NM_IP6_CONFIG_DNS_PRIORITY,
|
||||
|
|
@ -325,7 +328,7 @@ _dns_config_data_free(NMDnsConfigData *data)
|
|||
}
|
||||
|
||||
static int
|
||||
_mgr_get_ip_configs_lst_cmp(const CList *a_lst, const CList *b_lst, const void *user_data)
|
||||
_mgr_get_ip_config_lst_cmp(const CList *a_lst, const CList *b_lst, const void *user_data)
|
||||
{
|
||||
const NMDnsConfigIPData *a = c_list_entry(a_lst, NMDnsConfigIPData, ip_config_lst);
|
||||
const NMDnsConfigIPData *b = c_list_entry(b_lst, NMDnsConfigIPData, ip_config_lst);
|
||||
|
|
@ -341,16 +344,16 @@ _mgr_get_ip_configs_lst_cmp(const CList *a_lst, const CList *b_lst, const void *
|
|||
}
|
||||
|
||||
static CList *
|
||||
_mgr_get_ip_configs_lst_head(NMDnsManager *self)
|
||||
_mgr_get_ip_config_lst_head(NMDnsManager *self)
|
||||
{
|
||||
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self);
|
||||
|
||||
if (G_UNLIKELY(priv->ip_configs_lst_need_sort)) {
|
||||
priv->ip_configs_lst_need_sort = FALSE;
|
||||
c_list_sort(&priv->ip_configs_lst_head, _mgr_get_ip_configs_lst_cmp, NULL);
|
||||
if (G_UNLIKELY(priv->ip_config_lst_need_sort)) {
|
||||
priv->ip_config_lst_need_sort = FALSE;
|
||||
c_list_sort(&priv->ip_config_lst_head, _mgr_get_ip_config_lst_cmp, NULL);
|
||||
}
|
||||
|
||||
return &priv->ip_configs_lst_head;
|
||||
return &priv->ip_config_lst_head;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -1104,7 +1107,7 @@ update_resolv_conf(NMDnsManager * self,
|
|||
}
|
||||
|
||||
static void
|
||||
compute_hash(NMDnsManager *self, const NMGlobalDnsConfig *global, guint8 buffer[HASH_LEN])
|
||||
compute_hash(NMDnsManager *self, const NMGlobalDnsConfig *global, guint8 buffer[static HASH_LEN])
|
||||
{
|
||||
nm_auto_free_checksum GChecksum *sum = NULL;
|
||||
NMDnsConfigIPData * ip_data;
|
||||
|
|
@ -1119,7 +1122,7 @@ compute_hash(NMDnsManager *self, const NMGlobalDnsConfig *global, guint8 buffer[
|
|||
|
||||
/* FIXME(ip-config-checksum): this relies on the fact that an IP
|
||||
* configuration without DNS parameters gives a zero checksum. */
|
||||
head = _mgr_get_ip_configs_lst_head(self);
|
||||
head = _mgr_get_ip_config_lst_head(self);
|
||||
c_list_for_each_entry (ip_data, head, ip_config_lst)
|
||||
nm_ip_config_hash(ip_data->ip_config, sum, TRUE);
|
||||
}
|
||||
|
|
@ -1169,27 +1172,26 @@ merge_global_dns_config(NMResolvConfData *rc, NMGlobalDnsConfig *global_conf)
|
|||
}
|
||||
|
||||
static const char *
|
||||
get_nameserver_list(const NMIPConfig *config, GString **str)
|
||||
get_nameserver_list(const NMIPConfig *config, NMStrBuf *tmp_strbuf)
|
||||
{
|
||||
guint num, i;
|
||||
char buf[NM_UTILS_INET_ADDRSTRLEN];
|
||||
int addr_family;
|
||||
guint num;
|
||||
guint i;
|
||||
|
||||
if (*str)
|
||||
g_string_truncate(*str, 0);
|
||||
else
|
||||
*str = g_string_sized_new(64);
|
||||
nm_str_buf_reset(tmp_strbuf);
|
||||
|
||||
addr_family = nm_ip_config_get_addr_family(config);
|
||||
num = nm_ip_config_get_num_nameservers(config);
|
||||
for (i = 0; i < num; i++) {
|
||||
nm_utils_inet_ntop(addr_family, nm_ip_config_get_nameserver(config, i), buf);
|
||||
if (i > 0)
|
||||
g_string_append_c(*str, ' ');
|
||||
g_string_append(*str, buf);
|
||||
nm_str_buf_append_c(tmp_strbuf, ' ');
|
||||
nm_str_buf_append(tmp_strbuf, buf);
|
||||
}
|
||||
|
||||
return (*str)->str;
|
||||
nm_str_buf_maybe_expand(tmp_strbuf, 1, FALSE);
|
||||
return nm_str_buf_get_str(tmp_strbuf);
|
||||
}
|
||||
|
||||
static char **
|
||||
|
|
@ -1224,13 +1226,14 @@ _collect_resolv_conf_data(NMDnsManager * self,
|
|||
if (global_config)
|
||||
merge_global_dns_config(&rc, global_config);
|
||||
else {
|
||||
nm_auto_free_gstring GString *tmp_gstring = NULL;
|
||||
int prio, first_prio = 0;
|
||||
const NMDnsConfigIPData * ip_data;
|
||||
const CList * head;
|
||||
gboolean is_first = TRUE;
|
||||
nm_auto_str_buf NMStrBuf tmp_strbuf = NM_STR_BUF_INIT(0, FALSE);
|
||||
int prio;
|
||||
int first_prio = 0;
|
||||
const NMDnsConfigIPData *ip_data;
|
||||
const CList * head;
|
||||
gboolean is_first = TRUE;
|
||||
|
||||
head = _mgr_get_ip_configs_lst_head(self);
|
||||
head = _mgr_get_ip_config_lst_head(self);
|
||||
c_list_for_each_entry (ip_data, head, ip_config_lst) {
|
||||
gboolean skip = FALSE;
|
||||
|
||||
|
|
@ -1244,16 +1247,13 @@ _collect_resolv_conf_data(NMDnsManager * self,
|
|||
} else if (first_prio < 0 && first_prio != prio)
|
||||
skip = TRUE;
|
||||
|
||||
if (nm_ip_config_get_num_nameservers(ip_data->ip_config)) {
|
||||
_LOGT(
|
||||
"config: %8d %-7s v%c %-5d %s: %s",
|
||||
prio,
|
||||
_config_type_to_string(ip_data->ip_config_type),
|
||||
nm_utils_addr_family_to_char(nm_ip_config_get_addr_family(ip_data->ip_config)),
|
||||
ip_data->data->ifindex,
|
||||
skip ? "<SKIP>" : "",
|
||||
get_nameserver_list(ip_data->ip_config, &tmp_gstring));
|
||||
}
|
||||
_LOGT("config: %8d %-7s v%c %-5d %s: %s",
|
||||
prio,
|
||||
_config_type_to_string(ip_data->ip_config_type),
|
||||
nm_utils_addr_family_to_char(nm_ip_config_get_addr_family(ip_data->ip_config)),
|
||||
ip_data->data->ifindex,
|
||||
skip ? "<SKIP>" : "",
|
||||
get_nameserver_list(ip_data->ip_config, &tmp_strbuf));
|
||||
|
||||
if (!skip)
|
||||
merge_one_ip_config(&rc, ip_data->data->ifindex, ip_data->ip_config);
|
||||
|
|
@ -1394,7 +1394,7 @@ _mgr_configs_data_construct(NMDnsManager *self)
|
|||
CList * head;
|
||||
int prev_priority = G_MININT;
|
||||
|
||||
head = _mgr_get_ip_configs_lst_head(self);
|
||||
head = _mgr_get_ip_config_lst_head(self);
|
||||
|
||||
#if NM_MORE_ASSERTS
|
||||
/* we call _mgr_configs_data_clear() at the end of update. We
|
||||
|
|
@ -1611,7 +1611,7 @@ _mgr_configs_data_clear(NMDnsManager *self)
|
|||
NMDnsConfigIPData *ip_data;
|
||||
CList * head;
|
||||
|
||||
head = _mgr_get_ip_configs_lst_head(self);
|
||||
head = _mgr_get_ip_config_lst_head(self);
|
||||
c_list_for_each_entry (ip_data, head, ip_config_lst) {
|
||||
nm_clear_g_free(&ip_data->domains.search);
|
||||
nm_clear_pointer(&ip_data->domains.reverse, g_strfreev);
|
||||
|
|
@ -1680,7 +1680,7 @@ update_dns(NMDnsManager *self, gboolean no_caching, GError **error)
|
|||
if (priv->sd_resolve_plugin) {
|
||||
nm_dns_plugin_update(priv->sd_resolve_plugin,
|
||||
global_config,
|
||||
_mgr_get_ip_configs_lst_head(self),
|
||||
_mgr_get_ip_config_lst_head(self),
|
||||
priv->hostname,
|
||||
NULL);
|
||||
}
|
||||
|
|
@ -1702,7 +1702,7 @@ update_dns(NMDnsManager *self, gboolean no_caching, GError **error)
|
|||
_LOGD("update-dns: updating plugin %s", plugin_name);
|
||||
if (!nm_dns_plugin_update(plugin,
|
||||
global_config,
|
||||
_mgr_get_ip_configs_lst_head(self),
|
||||
_mgr_get_ip_config_lst_head(self),
|
||||
priv->hostname,
|
||||
&plugin_error)) {
|
||||
_LOGW("update-dns: plugin %s update failed: %s", plugin_name, plugin_error->message);
|
||||
|
|
@ -1839,7 +1839,7 @@ _ip_config_dns_priority_changed(gpointer config, GParamSpec *pspec, NMDnsConfigI
|
|||
{
|
||||
_ASSERT_dns_config_ip_data(ip_data);
|
||||
|
||||
NM_DNS_MANAGER_GET_PRIVATE(ip_data->data->self)->ip_configs_lst_need_sort = TRUE;
|
||||
NM_DNS_MANAGER_GET_PRIVATE(ip_data->data->self)->ip_config_lst_need_sort = TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
@ -1904,7 +1904,7 @@ nm_dns_manager_set_ip_config(NMDnsManager * self,
|
|||
else
|
||||
ip_data->ip_config_type = ip_config_type;
|
||||
|
||||
priv->ip_configs_lst_need_sort = TRUE;
|
||||
priv->ip_config_lst_need_sort = TRUE;
|
||||
|
||||
p_best = NM_IS_IP4_CONFIG(ip_config) ? &priv->best_ip_config_4 : &priv->best_ip_config_6;
|
||||
|
||||
|
|
@ -2440,7 +2440,7 @@ _get_config_variant(NMDnsManager *self)
|
|||
|
||||
g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
|
||||
|
||||
head = _mgr_get_ip_configs_lst_head(self);
|
||||
head = _mgr_get_ip_config_lst_head(self);
|
||||
c_list_for_each_entry (ip_data, head, ip_config_lst) {
|
||||
const NMIPConfig *ip_config = ip_data->ip_config;
|
||||
GVariantBuilder entry_builder;
|
||||
|
|
@ -2546,7 +2546,7 @@ nm_dns_manager_init(NMDnsManager *self)
|
|||
_LOGT("creating...");
|
||||
|
||||
c_list_init(&priv->configs_lst_head);
|
||||
c_list_init(&priv->ip_configs_lst_head);
|
||||
c_list_init(&priv->ip_config_lst_head);
|
||||
|
||||
priv->config = g_object_ref(nm_config_get());
|
||||
|
||||
|
|
@ -2587,7 +2587,7 @@ dispose(GObject *object)
|
|||
priv->best_ip_config_4 = NULL;
|
||||
priv->best_ip_config_6 = NULL;
|
||||
|
||||
c_list_for_each_entry_safe (ip_data, ip_data_safe, &priv->ip_configs_lst_head, ip_config_lst)
|
||||
c_list_for_each_entry_safe (ip_data, ip_data_safe, &priv->ip_config_lst_head, ip_config_lst)
|
||||
_dns_config_ip_data_free(ip_data);
|
||||
|
||||
nm_clear_pointer(&priv->configs_dict, g_hash_table_destroy);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue