mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-01 02:08:02 +02:00
dns: cleanup rebuild_domain_lists() constructing domains list
This commit is contained in:
parent
c3969425ec
commit
103943776c
1 changed files with 49 additions and 29 deletions
|
|
@ -1231,26 +1231,34 @@ get_ip_rdns_domains (NMIPConfig *ip_config)
|
||||||
/* Check if the domain is shadowed by a parent domain with more negative priority */
|
/* Check if the domain is shadowed by a parent domain with more negative priority */
|
||||||
static gboolean
|
static gboolean
|
||||||
domain_is_shadowed (GHashTable *ht,
|
domain_is_shadowed (GHashTable *ht,
|
||||||
const char *domain, int priority,
|
const char *domain,
|
||||||
const char **out_parent, int *out_parent_priority)
|
int priority,
|
||||||
|
const char **out_parent,
|
||||||
|
int *out_parent_priority)
|
||||||
{
|
{
|
||||||
char *parent;
|
char *parent;
|
||||||
int parent_priority;
|
int parent_priority;
|
||||||
|
|
||||||
|
if (!ht)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
nm_assert (!g_hash_table_contains (ht, domain));
|
nm_assert (!g_hash_table_contains (ht, domain));
|
||||||
|
|
||||||
parent_priority = GPOINTER_TO_INT (g_hash_table_lookup (ht, ""));
|
parent_priority = GPOINTER_TO_INT (g_hash_table_lookup (ht, ""));
|
||||||
if (parent_priority < 0 && parent_priority < priority) {
|
if ( parent_priority < 0
|
||||||
|
&& parent_priority < priority) {
|
||||||
*out_parent = "";
|
*out_parent = "";
|
||||||
*out_parent_priority = parent_priority;
|
*out_parent_priority = parent_priority;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
parent = strchr (domain, '.');
|
parent = strchr (domain, '.');
|
||||||
while (parent && parent[1]) {
|
while ( parent
|
||||||
|
&& parent[1]) {
|
||||||
parent++;
|
parent++;
|
||||||
parent_priority = GPOINTER_TO_INT (g_hash_table_lookup (ht, parent));
|
parent_priority = GPOINTER_TO_INT (g_hash_table_lookup (ht, parent));
|
||||||
if (parent_priority < 0 && parent_priority < priority) {
|
if ( parent_priority < 0
|
||||||
|
&& parent_priority < priority) {
|
||||||
*out_parent = parent;
|
*out_parent = parent;
|
||||||
*out_parent_priority = parent_priority;
|
*out_parent_priority = parent_priority;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
@ -1269,8 +1277,6 @@ rebuild_domain_lists (NMDnsManager *self)
|
||||||
gboolean default_route_found = FALSE;
|
gboolean default_route_found = FALSE;
|
||||||
CList *head;
|
CList *head;
|
||||||
|
|
||||||
ht = g_hash_table_new (nm_str_hash, g_str_equal);
|
|
||||||
|
|
||||||
head = _ip_config_lst_head (self);
|
head = _ip_config_lst_head (self);
|
||||||
c_list_for_each_entry (ip_data, head, ip_config_lst) {
|
c_list_for_each_entry (ip_data, head, ip_config_lst) {
|
||||||
NMIPConfig *ip_config = ip_data->ip_config;
|
NMIPConfig *ip_config = ip_data->ip_config;
|
||||||
|
|
@ -1285,55 +1291,66 @@ rebuild_domain_lists (NMDnsManager *self)
|
||||||
|
|
||||||
c_list_for_each_entry (ip_data, head, ip_config_lst) {
|
c_list_for_each_entry (ip_data, head, ip_config_lst) {
|
||||||
NMIPConfig *ip_config = ip_data->ip_config;
|
NMIPConfig *ip_config = ip_data->ip_config;
|
||||||
int priority, old_priority;
|
int priority;
|
||||||
guint i, n, n_domains = 0;
|
|
||||||
const char **domains;
|
const char **domains;
|
||||||
|
guint n_searches;
|
||||||
|
guint n_domains;
|
||||||
|
guint num_dom1;
|
||||||
|
guint num_dom2;
|
||||||
|
guint cap_dom;
|
||||||
|
guint i;
|
||||||
|
|
||||||
if (!nm_ip_config_get_num_nameservers (ip_config))
|
if (!nm_ip_config_get_num_nameservers (ip_config))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
n_domains = nm_ip_config_get_num_searches (ip_config);
|
||||||
|
n_searches = nm_ip_config_get_num_domains (ip_config);
|
||||||
|
|
||||||
priority = nm_ip_config_get_dns_priority (ip_config);
|
priority = nm_ip_config_get_dns_priority (ip_config);
|
||||||
nm_assert (priority != 0);
|
nm_assert (priority != 0);
|
||||||
|
|
||||||
|
cap_dom = 2u + NM_MAX (n_domains, n_searches);
|
||||||
|
|
||||||
g_free (ip_data->domains.search);
|
g_free (ip_data->domains.search);
|
||||||
domains = g_new0 (const char *,
|
domains = g_new (const char *, cap_dom);
|
||||||
2 + NM_MAX (nm_ip_config_get_num_searches (ip_config),
|
|
||||||
nm_ip_config_get_num_domains (ip_config)));
|
|
||||||
ip_data->domains.search = domains;
|
ip_data->domains.search = domains;
|
||||||
|
|
||||||
|
num_dom1 = 0;
|
||||||
|
|
||||||
/* Add wildcard lookup domain to connections with the default route.
|
/* Add wildcard lookup domain to connections with the default route.
|
||||||
* If there is no default route, add the wildcard domain to all non-VPN
|
* If there is no default route, add the wildcard domain to all non-VPN
|
||||||
* connections */
|
* connections */
|
||||||
if (default_route_found) {
|
if (default_route_found) {
|
||||||
if (nm_ip_config_best_default_route_get (ip_config))
|
if (nm_ip_config_best_default_route_get (ip_config))
|
||||||
domains[n_domains++] = "~";
|
domains[num_dom1++] = "~";
|
||||||
} else {
|
} else {
|
||||||
if (ip_data->ip_config_type != NM_DNS_IP_CONFIG_TYPE_VPN)
|
if (ip_data->ip_config_type != NM_DNS_IP_CONFIG_TYPE_VPN)
|
||||||
domains[n_domains++] = "~";
|
domains[num_dom1++] = "~";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* searches are preferred over domains */
|
/* searches are preferred over domains */
|
||||||
n = nm_ip_config_get_num_searches (ip_config);
|
if (n_searches > 0) {
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n_searches; i++)
|
||||||
domains[n_domains++] = nm_ip_config_get_search (ip_config, i);
|
domains[num_dom1++] = nm_ip_config_get_search (ip_config, i);
|
||||||
|
} else {
|
||||||
if (n == 0) {
|
for (i = 0; i < n_domains; i++)
|
||||||
/* If not searches, use any domains */
|
domains[num_dom1++] = nm_ip_config_get_domain (ip_config, i);
|
||||||
n = nm_ip_config_get_num_domains (ip_config);
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
domains[n_domains++] = nm_ip_config_get_domain (ip_config, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = 0;
|
nm_assert (num_dom1 < cap_dom);
|
||||||
for (i = 0; i < n_domains; i++) {
|
|
||||||
|
num_dom2 = 0;
|
||||||
|
for (i = 0; i < num_dom1; i++) {
|
||||||
const char *domain_clean;
|
const char *domain_clean;
|
||||||
const char *parent;
|
const char *parent;
|
||||||
|
int old_priority;
|
||||||
int parent_priority;
|
int parent_priority;
|
||||||
|
|
||||||
domain_clean = nm_utils_parse_dns_domain (domains[i], NULL);
|
domain_clean = nm_utils_parse_dns_domain (domains[i], NULL);
|
||||||
|
|
||||||
/* Remove domains with lower priority */
|
/* Remove domains with lower priority */
|
||||||
old_priority = GPOINTER_TO_INT (g_hash_table_lookup (ht, domain_clean));
|
old_priority = GPOINTER_TO_INT (nm_g_hash_table_lookup (ht, domain_clean));
|
||||||
if (old_priority) {
|
if (old_priority != 0) {
|
||||||
if (old_priority < priority) {
|
if (old_priority < priority) {
|
||||||
_LOGT ("plugin: drop domain '%s' (i=%d, p=%d) because it already exists with p=%d",
|
_LOGT ("plugin: drop domain '%s' (i=%d, p=%d) because it already exists with p=%d",
|
||||||
domains[i], ip_data->data->ifindex,
|
domains[i], ip_data->data->ifindex,
|
||||||
|
|
@ -1349,10 +1366,13 @@ rebuild_domain_lists (NMDnsManager *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOGT ("plugin: add domain '%s' (i=%d, p=%d)", domains[i], ip_data->data->ifindex, priority);
|
_LOGT ("plugin: add domain '%s' (i=%d, p=%d)", domains[i], ip_data->data->ifindex, priority);
|
||||||
|
if (!ht)
|
||||||
|
ht = g_hash_table_new (nm_str_hash, g_str_equal);
|
||||||
g_hash_table_insert (ht, (gpointer) domain_clean, GINT_TO_POINTER (priority));
|
g_hash_table_insert (ht, (gpointer) domain_clean, GINT_TO_POINTER (priority));
|
||||||
domains[n++] = domains[i];
|
domains[num_dom2++] = domains[i];
|
||||||
}
|
}
|
||||||
domains[n] = NULL;
|
nm_assert (num_dom2 < cap_dom);
|
||||||
|
domains[num_dom2] = NULL;
|
||||||
|
|
||||||
g_strfreev (ip_data->domains.reverse);
|
g_strfreev (ip_data->domains.reverse);
|
||||||
ip_data->domains.reverse = get_ip_rdns_domains (ip_config);
|
ip_data->domains.reverse = get_ip_rdns_domains (ip_config);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue