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 IGNORE_LOCALHOST config option #254

Merged
merged 3 commits into from Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions FTL.h
Expand Up @@ -131,6 +131,7 @@ typedef struct {
int port;
int maxlogage;
int privacylevel;
bool ignore_localhost;
} ConfigStruct;

// Dynamic structs
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -115,6 +115,7 @@ Possible settings (**the option shown first is the default**):
- `MAXLOGAGE=24.0` (Up to how many hours of queries should be imported from the database and logs? Maximum is 744 (31 days))
- `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?)

### Privacy levels
Specifies if we want to anonymize the DNS queries somehow, available options are:
Expand Down
21 changes: 17 additions & 4 deletions config.c
Expand Up @@ -35,7 +35,7 @@ void read_FTLconf(void)
config.socket_listenlocal = true;
buffer = parse_FTLconf(fp, "SOCKET_LISTENING");

if(buffer != NULL && strcmp(buffer, "all") == 0)
if(buffer != NULL && strcasecmp(buffer, "all") == 0)
config.socket_listenlocal = false;

if(config.socket_listenlocal)
Expand All @@ -48,7 +48,7 @@ void read_FTLconf(void)
config.analyze_AAAA = true;
buffer = parse_FTLconf(fp, "AAAA_QUERY_ANALYSIS");

if(buffer != NULL && strcmp(buffer, "no") == 0)
if(buffer != NULL && strcasecmp(buffer, "no") == 0)
config.analyze_AAAA = false;

if(config.analyze_AAAA)
Expand Down Expand Up @@ -76,7 +76,7 @@ void read_FTLconf(void)
config.resolveIPv6 = true;
buffer = parse_FTLconf(fp, "RESOLVE_IPV6");

if(buffer != NULL && strcmp(buffer, "no") == 0)
if(buffer != NULL && strcasecmp(buffer, "no") == 0)
config.resolveIPv6 = false;

if(config.resolveIPv6)
Expand All @@ -88,7 +88,7 @@ void read_FTLconf(void)
// defaults to: Yes
config.resolveIPv4 = true;
buffer = parse_FTLconf(fp, "RESOLVE_IPV4");
if(buffer != NULL && strcmp(buffer, "no") == 0)
if(buffer != NULL && strcasecmp(buffer, "no") == 0)
config.resolveIPv4 = false;
if(config.resolveIPv4)
logg(" RESOLVE_IPV4: Resolve IPv4 addresses");
Expand Down Expand Up @@ -174,6 +174,19 @@ void read_FTLconf(void)
get_privacy_level(fp);
logg(" PRIVACYLEVEL: Set to %i", config.privacylevel);

// IGNORE_LOCALHOST
// defaults to: No
config.ignore_localhost = false;
buffer = parse_FTLconf(fp, "IGNORE_LOCALHOST");

if(buffer != NULL && strcasecmp(buffer, "yes") == 0)
config.ignore_localhost = true;

if(config.ignore_localhost)
logg(" IGNORE_LOCALHOST: Hide queries from localhost");
else
logg(" IGNORE_LOCALHOST: Show queries from localhost");

logg("Finished config file parsing");

// Release memory
Expand Down
11 changes: 10 additions & 1 deletion database.c
Expand Up @@ -663,14 +663,23 @@ void read_data_from_DB(void)
logg("DB warn: DOMAIN should never be NULL, %i", queryTimeStamp);
continue;
}
int domainID = findDomainID(domain);

const char * client = (const char *)sqlite3_column_text(stmt, 5);
if(client == NULL)
{
logg("DB warn: CLIENT should never be NULL, %i", queryTimeStamp);
continue;
}

// Check if user wants to skip queries coming from localhost
if(config.ignore_localhost &&
(strcmp(client, "127.0.0.1") == 0 || strcmp(client, "::1") == 0))
{
continue;
}

// Obtain IDs only after filtering which queries we want to keep
int domainID = findDomainID(domain);
int clientID = findClientID(client);

const char *forwarddest = (const char *)sqlite3_column_text(stmt, 6);
Expand Down
10 changes: 10 additions & 0 deletions dnsmasq_interface.c
Expand Up @@ -70,6 +70,16 @@ void FTL_new_query(unsigned int flags, char *name, struct all_addr *addr, char *
char *client = strdup(dest);
strtolower(client);

// Check if user wants to skip queries coming from localhost
if(config.ignore_localhost &&
(strcmp(client, "127.0.0.1") == 0 || strcmp(client, "::1") == 0))
{
free(domain);
free(client);
disable_thread_lock();
return;
}

// Check and apply possible privacy level rules
// We do this immediately on the raw data to avoid any possible leaking
if(config.privacylevel >= PRIVACY_HIDE_DOMAINS_CLIENTS)
Expand Down