Add BLOCKINGMODE=IP|NXDOMAIN config flag for selecting if FTLDNS should reply with IPv4/IPv6 addresses (need 2 cache slots per domain) or with NXDOMAIN (need 1 cache slot per domain)

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2018-04-22 12:08:44 +02:00
parent d50494b8f4
commit 6d82f29f09
4 changed files with 31 additions and 3 deletions
+2
View File
@@ -132,6 +132,7 @@ typedef struct {
int maxlogage;
int privacylevel;
bool ignore_localhost;
unsigned char blockingmode;
} ConfigStruct;
// Dynamic structs
@@ -212,6 +213,7 @@ enum { QUERY_UNKNOWN, QUERY_GRAVITY, QUERY_FORWARDED, QUERY_CACHE, QUERY_WILDCAR
enum { TYPE_A = 1, TYPE_AAAA, TYPE_ANY, TYPE_SRV, TYPE_SOA, TYPE_PTR, TYPE_TXT, TYPE_MAX };
enum { REPLY_UNKNOWN, REPLY_NODATA, REPLY_NXDOMAIN, REPLY_CNAME, REPLY_IP };
enum { PRIVACY_SHOW_ALL = 0, PRIVACY_HIDE_DOMAINS, PRIVACY_HIDE_DOMAINS_CLIENTS, PRIVACY_MAXIMUM };
enum { MODE_IP, MODE_NX };
// Used to check memory integrity in various structs
#define MAGICBYTE 0x57
+1
View File
@@ -168,6 +168,7 @@ Possible settings (**the option shown first is the default**):
- `FTLPORT=4711` (On which port should FTL be listening?)
- `PRIVACYLEVEL=0` (Which privacy level is used? Can be 0 (permissive) to 3 (very restrictive), see below)
- `IGNORE_LOCALHOST=no|yes` (Should `FTL` ignore queries coming from the local machine?)
- `BLOCKINGMODE=IP|NXDOMAIN` (Should `FTL` reply queries to blocked domains with IPs or NXDOMAIN?)
### Privacy levels
Specifies if we want to anonymize the DNS queries somehow, available options are:
+21
View File
@@ -187,6 +187,27 @@ void read_FTLconf(void)
else
logg(" IGNORE_LOCALHOST: Show queries from localhost");
// BLOCKINGMODE
// defaults to: MODE_IP
config.blockingmode = MODE_IP;
buffer = parse_FTLconf(fp, "BLOCKINGMODE");
if(buffer != NULL)
{
if(strcasecmp(buffer, "NXDOMAIN") == 0)
config.blockingmode = MODE_NX;
}
switch(config.blockingmode)
{
case MODE_NX:
logg(" BLOCKINGMODE: NXDOMAIN for blocked domains");
break;
default:
logg(" BLOCKINGMODE: Pi-hole's IP for blocked domains");
break;
}
logg("Finished config file parsing");
// Release memory
+7 -3
View File
@@ -500,6 +500,8 @@ void FTL_cache(unsigned int flags, char *name, struct all_addr *addr, char *arg,
requesttype = QUERY_GRAVITY;
else if(arg != NULL && strstr(arg, "/black.list") != NULL)
requesttype = QUERY_BLACKLIST;
else if(flags & F_NXDOMAIN)
requesttype = QUERY_GRAVITY;
else // local.list, hostname.list, /etc/hosts and others
requesttype = QUERY_CACHE;
}
@@ -846,20 +848,22 @@ int FTL_listsfile(char* filename, unsigned int index, FILE *f, int cache_size, s
{
strcpy(cache4->name.sname, domain);
cache4->flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4;
if(config.blockingmode == MODE_NX) cache4->flags |= F_NEG | F_NXDOMAIN;
cache4->ttd = daemon->local_ttl;
add_hosts_entry(cache4, &addr4, INADDRSZ, index, rhash, hashsz);
name_count++;
}
// Add IPv6 record
if ((cache6 = malloc(sizeof(struct crec) + strlen(domain)+1-SMALLDNAME)))
// Add IPv6 record only if we respond with an IP address to blocked domains
if (config.blockingmode == MODE_IP && (cache6 = malloc(sizeof(struct crec) + strlen(domain)+1-SMALLDNAME)))
{
strcpy(cache6->name.sname, domain);
cache6->flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV6;
cache6->ttd = daemon->local_ttl;
add_hosts_entry(cache6, &addr6, IN6ADDRSZ, index, rhash, hashsz);
name_count++;
}
added++;
name_count++;
}
// Free allocated memory