Skip to content

Commit 77cd161

Browse files
authored
Merge pull request #2772 from pi-hole/fix/dns_domain_local
home.arpa and internal TLDs may be non-local without revServer
2 parents 04e3332 + b46907a commit 77cd161

1 file changed

Lines changed: 54 additions & 18 deletions

File tree

src/config/dnsmasq_config.c

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,7 @@ bool __attribute__((nonnull(1,3))) write_dnsmasq_config(struct config *conf, boo
488488
fputs("\n", pihole_conf);
489489

490490
// Add upstream DNS servers for reverse lookups
491-
bool domain_revServer = false;
492-
bool domain_homearpa = false;
493-
bool domain_internal = false;
491+
bool revServer_domain = false, revServer_homearpa = false, revServer_internal = false;
494492
const unsigned int revServers = cJSON_GetArraySize(conf->dns.revServers.v.json);
495493
for(unsigned int i = 0; i < revServers; i++)
496494
{
@@ -540,15 +538,15 @@ bool __attribute__((nonnull(1,3))) write_dnsmasq_config(struct config *conf, boo
540538
// Check if the configured domain is the same as the main domain
541539
if(strlen(config.dns.domain.name.v.s) > 0 &&
542540
strcasecmp(domain, config.dns.domain.name.v.s) == 0)
543-
domain_revServer = true;
541+
revServer_domain = true;
544542

545-
// Flag if configured a server for queries for home.arpa domains
543+
// Flag if configured a server for queries for "home.arpa" TLD
546544
if(strcmp(domain, "home.arpa") == 0)
547-
domain_homearpa = true;
545+
revServer_homearpa = true;
548546

549-
// Flag if configured a server for queries for .internal domains
547+
// Flag if configured a server for queries for "internal" TLD
550548
if(strcmp(domain, "internal") == 0)
551-
domain_internal = true;
549+
revServer_internal = true;
552550
}
553551

554552
// Forward unqualified names to the target only when the "never forward
@@ -571,17 +569,55 @@ bool __attribute__((nonnull(1,3))) write_dnsmasq_config(struct config *conf, boo
571569
fputs("local=//\n\n", pihole_conf);
572570
}
573571

574-
// Ensure that home.arpa domains (RFC 8375) are not sent upstream, unless configured by
575-
// user as local domain, with server setting applied above
576-
if (!domain_homearpa)
572+
// Ensure that home.arpa domains (RFC 8375) are not forwarded to
573+
// upstream servers by default. However, we skip adding the protection
574+
// when the user has explicitly configured an exception. The exceptions
575+
// are:
576+
// - a reverse server has been configured for the "home.arpa" TLD, OR
577+
// - the configured DNS domain equals "home.arpa" and that domain is
578+
// explicitly marked non-local.
579+
const bool domain_homearpa = strlen(conf->dns.domain.name.v.s) > 0 &&
580+
strcasecmp(conf->dns.domain.name.v.s, "home.arpa") == 0;
581+
if(revServer_homearpa)
577582
{
578-
fputs("# Do not forward home.arpa domains to upstream servers\n",pihole_conf);
583+
fputs("# A reverse server is configured for \"home.arpa\".\n", pihole_conf);
584+
fputs("# All queries for this domain will be forwarded to this\n", pihole_conf);
585+
fputs("# upstream server\n\n", pihole_conf);
586+
}
587+
else if(domain_homearpa && !config.dns.domain.local.v.b)
588+
{
589+
fputs("# The configured DNS domain is \"home.arpa\" and is explicitly\n", pihole_conf);
590+
fputs("# marked non-local. Pi-hole will be forwarding queries for this\n", pihole_conf);
591+
fputs("# domain to upstream servers.\n\n", pihole_conf);
592+
}
593+
else
594+
{
595+
fputs("# Do not forward .home.arpa domains to upstream servers\n",pihole_conf);
579596
fputs("local=/home.arpa/\n\n",pihole_conf);
580597
}
581598

582-
// Ensure that .internal domains (Internet-Draft draft-davies-internal-tld-03) are not
583-
// sent upstream, unless configured by user as local domain, with server setting applied above
584-
if (!domain_internal)
599+
// Ensure that internal domains (Internet-Draft
600+
// draft-davies-internal-tld-05) are not forwarded to upstream servers
601+
// by default. However, we skip adding the protection when the user has
602+
// explicitly configured an exception. The exceptions are:
603+
// - a reverse server has been configured for the "internal" TLD, OR
604+
// - the configured DNS domain equals "internal" and that domain is
605+
// explicitly marked non-local.
606+
const bool domain_internal = strlen(conf->dns.domain.name.v.s) > 0 &&
607+
strcasecmp(conf->dns.domain.name.v.s, "internal") == 0;
608+
if(revServer_internal)
609+
{
610+
fputs("# A reverse server is configured for \"internal\".\n", pihole_conf);
611+
fputs("# All queries for this domain will be forwarded to this\n", pihole_conf);
612+
fputs("# upstream server\n\n", pihole_conf);
613+
}
614+
else if(domain_internal && !config.dns.domain.local.v.b)
615+
{
616+
fputs("# The configured DNS domain is \"internal\" and is explicitly\n", pihole_conf);
617+
fputs("# marked non-local. Pi-hole will be forwarding queries for this\n", pihole_conf);
618+
fputs("# domain to upstream servers.\n\n", pihole_conf);
619+
}
620+
else
585621
{
586622
fputs("# Do not forward .internal domains to upstream servers\n",pihole_conf);
587623
fputs("local=/internal/\n\n",pihole_conf);
@@ -592,14 +628,14 @@ bool __attribute__((nonnull(1,3))) write_dnsmasq_config(struct config *conf, boo
592628
if(strlen(conf->dns.domain.name.v.s) > 0)
593629
{
594630
fputs("# DNS domain for both the DNS and DHCP server\n", pihole_conf);
595-
if(domain_revServer || !config.dns.domain.local.v.b)
631+
if(revServer_domain || !config.dns.domain.local.v.b)
596632
{
597-
if(domain_revServer)
633+
if(revServer_domain)
598634
{
599635
fputs("# This DNS domain is also used for reverse lookups\n", pihole_conf);
600636
fputs("# It is forwarded to the upstream servers configured above\n", pihole_conf);
601637
}
602-
else if(!config.dns.domain.local.v.b)
638+
else // !config.dns.domain.local.v.b
603639
{
604640
fputs("# This domain is explicitly configured to *not* be local. Ensure\n", pihole_conf);
605641
fputs("# that you have configured at least one upstream server for this\n", pihole_conf);

0 commit comments

Comments
 (0)