Skip to content

Commit 3b5bd7d

Browse files
committed
resolved: optionally allow single-label A/AAAA queries
1 parent c2f1e83 commit 3b5bd7d

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

src/resolve/resolved-dns-query.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,12 @@ static int dns_query_add_candidate(DnsQuery *q, DnsScope *s) {
524524
return r;
525525

526526
/* If this a single-label domain on DNS, we might append a suitable search domain first. */
527-
if ((q->flags & SD_RESOLVED_NO_SEARCH) == 0 &&
528-
dns_scope_name_needs_search_domain(s, dns_question_first_name(q->question_idna))) {
529-
/* OK, we need a search domain now. Let's find one for this scope */
527+
if (!FLAGS_SET(q->flags, SD_RESOLVED_NO_SEARCH) &&
528+
dns_scope_name_wants_search_domain(s, dns_question_first_name(q->question_idna))) {
529+
/* OK, we want a search domain now. Let's find one for this scope */
530530

531531
r = dns_query_candidate_next_search_domain(c);
532-
if (r <= 0) /* if there's no search domain, then we won't add any transaction. */
532+
if (r < 0)
533533
return r;
534534
}
535535

src/resolve/resolved-dns-scope.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ DnsScopeMatch dns_scope_good_domain(
619619
manager_is_own_hostname(s->manager, domain) <= 0)) /* never resolve the local hostname via LLMNR */
620620
return DNS_SCOPE_YES_BASE + 1; /* Return +1, as we consider ourselves authoritative
621621
* for single-label names, i.e. one label. This is
622-
* particular relevant as it means a "." route on some
622+
* particularly relevant as it means a "." route on some
623623
* other scope won't pull all traffic away from
624624
* us. (If people actually want to pull traffic away
625625
* from us they should turn off LLMNR on the
@@ -651,20 +651,21 @@ bool dns_scope_good_key(DnsScope *s, const DnsResourceKey *key) {
651651

652652
if (s->protocol == DNS_PROTOCOL_DNS) {
653653

654-
/* On classic DNS, looking up non-address RRs is always
655-
* fine. (Specifically, we want to permit looking up
656-
* DNSKEY and DS records on the root and top-level
657-
* domains.) */
654+
/* On classic DNS, looking up non-address RRs is always fine. (Specifically, we want to
655+
* permit looking up DNSKEY and DS records on the root and top-level domains.) */
658656
if (!dns_resource_key_is_address(key))
659657
return true;
660658

661-
/* However, we refuse to look up A and AAAA RRs on the
662-
* root and single-label domains, under the assumption
663-
* that those should be resolved via LLMNR or search
664-
* path only, and should not be leaked onto the
665-
* internet. */
666-
return !(dns_name_is_single_label(dns_resource_key_name(key)) ||
667-
dns_name_is_root(dns_resource_key_name(key)));
659+
/* Unless explicitly overridden, we refuse to look up A and AAAA RRs on the root and
660+
* single-label domains, under the assumption that those should be resolved via LLMNR or
661+
* search path only, and should not be leaked onto the internet. */
662+
const char* name = dns_resource_key_name(key);
663+
664+
if (!s->manager->resolve_unicast_single_label &&
665+
dns_name_is_single_label(name))
666+
return false;
667+
668+
return !dns_name_is_root(name);
668669
}
669670

670671
/* On mDNS and LLMNR, send A and AAAA queries only on the
@@ -1169,7 +1170,7 @@ DnsSearchDomain *dns_scope_get_search_domains(DnsScope *s) {
11691170
return s->manager->search_domains;
11701171
}
11711172

1172-
bool dns_scope_name_needs_search_domain(DnsScope *s, const char *name) {
1173+
bool dns_scope_name_wants_search_domain(DnsScope *s, const char *name) {
11731174
assert(s);
11741175

11751176
if (s->protocol != DNS_PROTOCOL_DNS)

src/resolve/resolved-dns-scope.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void dns_scope_dump(DnsScope *s, FILE *f);
9999

100100
DnsSearchDomain *dns_scope_get_search_domains(DnsScope *s);
101101

102-
bool dns_scope_name_needs_search_domain(DnsScope *s, const char *name);
102+
bool dns_scope_name_wants_search_domain(DnsScope *s, const char *name);
103103

104104
bool dns_scope_network_good(DnsScope *s);
105105

src/resolve/resolved-gperf.gperf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ struct ConfigPerfItem;
1818
%struct-type
1919
%includes
2020
%%
21-
Resolve.DNS, config_parse_dns_servers, DNS_SERVER_SYSTEM, 0
22-
Resolve.FallbackDNS, config_parse_dns_servers, DNS_SERVER_FALLBACK, 0
23-
Resolve.Domains, config_parse_search_domains, 0, 0
24-
Resolve.LLMNR, config_parse_resolve_support, 0, offsetof(Manager, llmnr_support)
25-
Resolve.MulticastDNS, config_parse_resolve_support, 0, offsetof(Manager, mdns_support)
26-
Resolve.DNSSEC, config_parse_dnssec_mode, 0, offsetof(Manager, dnssec_mode)
27-
Resolve.DNSOverTLS, config_parse_dns_over_tls_mode, 0, offsetof(Manager, dns_over_tls_mode)
28-
Resolve.Cache, config_parse_dns_cache_mode, DNS_CACHE_MODE_YES, offsetof(Manager, enable_cache)
29-
Resolve.DNSStubListener, config_parse_dns_stub_listener_mode, 0, offsetof(Manager, dns_stub_listener_mode)
30-
Resolve.ReadEtcHosts, config_parse_bool, 0, offsetof(Manager, read_etc_hosts)
21+
Resolve.DNS, config_parse_dns_servers, DNS_SERVER_SYSTEM, 0
22+
Resolve.FallbackDNS, config_parse_dns_servers, DNS_SERVER_FALLBACK, 0
23+
Resolve.Domains, config_parse_search_domains, 0, 0
24+
Resolve.LLMNR, config_parse_resolve_support, 0, offsetof(Manager, llmnr_support)
25+
Resolve.MulticastDNS, config_parse_resolve_support, 0, offsetof(Manager, mdns_support)
26+
Resolve.DNSSEC, config_parse_dnssec_mode, 0, offsetof(Manager, dnssec_mode)
27+
Resolve.DNSOverTLS, config_parse_dns_over_tls_mode, 0, offsetof(Manager, dns_over_tls_mode)
28+
Resolve.Cache, config_parse_dns_cache_mode, DNS_CACHE_MODE_YES, offsetof(Manager, enable_cache)
29+
Resolve.DNSStubListener, config_parse_dns_stub_listener_mode, 0, offsetof(Manager, dns_stub_listener_mode)
30+
Resolve.ReadEtcHosts, config_parse_bool, 0, offsetof(Manager, read_etc_hosts)
31+
Resolve.ResolveUnicastSingleLabel, config_parse_bool, 0, offsetof(Manager, resolve_unicast_single_label)

src/resolve/resolved-manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct Manager {
7272

7373
bool need_builtin_fallbacks;
7474
bool read_resolv_conf;
75+
bool resolve_unicast_single_label;
7576

7677
struct stat resolv_conf_stat;
7778

src/resolve/resolved.conf.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
#Cache=yes
2323
#DNSStubListener=yes
2424
#ReadEtcHosts=yes
25+
#ResolveUnicastSingleLabel=no

0 commit comments

Comments
 (0)