From efbe8025d0127a072e93d0b32bd8d5574690d3ba Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 11 Apr 2018 18:50:36 +0200 Subject: [PATCH 1/3] Implement IGNORE_LOCALHOST config option Signed-off-by: DL6ER --- FTL.h | 1 + config.c | 13 +++++++++++++ database.c | 11 ++++++++++- dnsmasq_interface.c | 10 ++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/FTL.h b/FTL.h index 4bbeabc37..7531291a8 100644 --- a/FTL.h +++ b/FTL.h @@ -131,6 +131,7 @@ typedef struct { int port; int maxlogage; int privacylevel; + bool ignore_localhost; } ConfigStruct; // Dynamic structs diff --git a/config.c b/config.c index 6cf72ad05..dcee354ce 100644 --- a/config.c +++ b/config.c @@ -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 && strcmp(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 diff --git a/database.c b/database.c index 260a3452f..5bbf07e48 100644 --- a/database.c +++ b/database.c @@ -663,7 +663,6 @@ 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) @@ -671,6 +670,16 @@ void read_data_from_DB(void) 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); diff --git a/dnsmasq_interface.c b/dnsmasq_interface.c index ffd1b2b39..8c1ed99ce 100644 --- a/dnsmasq_interface.c +++ b/dnsmasq_interface.c @@ -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) From 0c048b0355e85113ca019144aef437eb757f7eb1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 11 Apr 2018 18:55:58 +0200 Subject: [PATCH 2/3] Add IGNORE_LOCALHOST option to README Signed-off-by: DL6ER --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3c71c9a19..2a01f096e 100644 --- a/README.md +++ b/README.md @@ -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: From 192c9c78446d9ca2b3a4648c64545834c3db9fdd Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 11 Apr 2018 21:59:35 +0100 Subject: [PATCH 3/3] Make config options parsing case-insensitive Signed-off-by: DL6ER --- config.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config.c b/config.c index dcee354ce..94f53dbe1 100644 --- a/config.c +++ b/config.c @@ -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) @@ -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) @@ -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) @@ -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"); @@ -179,7 +179,7 @@ void read_FTLconf(void) config.ignore_localhost = false; buffer = parse_FTLconf(fp, "IGNORE_LOCALHOST"); - if(buffer != NULL && strcmp(buffer, "yes") == 0) + if(buffer != NULL && strcasecmp(buffer, "yes") == 0) config.ignore_localhost = true; if(config.ignore_localhost)