Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for "pi.hole.<local_domain>" and "<hostname>.<local_domain>" #1169

Merged
merged 1 commit into from
Sep 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,32 @@ size_t _FTL_make_answer(struct dns_header *header, char *limit, const size_t len
return p - (unsigned char *)header;
}

static bool is_pihole_domain(const char *domain)
{
static char *pihole_suffix = NULL;
if(!pihole_suffix && daemon->domain_suffix)
{
// Build "pi.hole.<local suffix>" domain
pihole_suffix = calloc(strlen(daemon->domain_suffix) + 9, sizeof(char));
strcpy(pihole_suffix, "pi.hole.");
strcat(pihole_suffix, daemon->domain_suffix);
if(config.debug & DEBUG_QUERIES)
logg("Domain suffix is \"%s\"", daemon->domain_suffix);
}
static char *hostname_suffix = NULL;
if(!hostname_suffix && daemon->domain_suffix)
{
// Build "<hostname>.<local suffix>" domain
hostname_suffix = calloc(strlen(hostname()) + strlen(daemon->domain_suffix) + 2, sizeof(char));
strcpy(hostname_suffix, hostname());
strcat(hostname_suffix, ".");
strcat(hostname_suffix, daemon->domain_suffix);
}
return strcasecmp(domain, "pi.hole") == 0 || strcasecmp(domain, hostname()) == 0 ||
(pihole_suffix && strcasecmp(domain, pihole_suffix) == 0) ||
(hostname_suffix && strcasecmp(domain, hostname_suffix) == 0);
}

bool _FTL_new_query(const unsigned int flags, const char *name,
union mysockaddr *addr, const char *types,
const unsigned short qtype, const int id,
Expand Down Expand Up @@ -436,7 +462,7 @@ bool _FTL_new_query(const unsigned int flags, const char *name,

// If domain is "pi.hole" or the local hostname we skip analyzing this query
// and, instead, immediately reply with the IP address - these queries are not further analyzed
if(strcasecmp(name, "pi.hole") == 0 || strcasecmp(name, hostname()) == 0)
if(is_pihole_domain(name))
{
if(querytype == TYPE_A || querytype == TYPE_AAAA || querytype == TYPE_ANY)
{
Expand Down