From e5847f7ae68c34b9f8aeeea3a660ccd85b6837c3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 30 Sep 2017 15:17:13 +0200 Subject: [PATCH] Added RESOLVEIPV6 config flag + extended comments in source Signed-off-by: DL6ER --- FTL.h | 1 + README.md | 1 + config.c | 14 ++++++++++++++ parser.c | 14 ++++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/FTL.h b/FTL.h index f07dbe4a..b4003422 100644 --- a/FTL.h +++ b/FTL.h @@ -120,6 +120,7 @@ typedef struct { bool query_display; bool analyze_AAAA; int maxDBdays; + bool resolveIPv6; } ConfigStruct; // Dynamic structs diff --git a/README.md b/README.md index 6878e22f..0c095bf8 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ Possible settings (**the option shown first is the default**): - `QUERY_DISPLAY=yes|no` (Display all queries? Set to `no` to hide query display) - `AAAA_QUERY_ANALYSIS=yes|no` (Allow `FTL` to analyze AAAA queries from pihole.log?) - `MAXDBDAYS=365` (How long should queries be stored in the database? Setting this to `0` disables the database altogether) +- `RESOLVEIPV6=yes|no` (Should `FTL` try to resolve IPv6 addresses to host names?) ### Implemented keywords (starting with `>`, subject to change): diff --git a/config.c b/config.c index 3df69b15..8df8f1ca 100644 --- a/config.c +++ b/config.c @@ -111,6 +111,20 @@ void read_FTLconf(void) else logg(" MAXDBDAYS: max age for stored queries is %i days", config.maxDBdays); + // RESOLVEIPV6 + // defaults to: Yes + config.resolveIPv6 = true; + buffer = parse_FTLconf(fp, "RESOLVEIPV6"); + if(buffer != NULL) + { + if(strcmp(buffer, "no") == 0) + config.resolveIPv6 = false; + } + if(config.resolveIPv6) + logg(" RESOLVEIPV6: Resolve IPv6 addresses"); + else + logg(" RESOLVEIPV6: Don\'t resolve IPv6 addresses"); + logg("Finished config file parsing"); if(conflinebuffer != NULL) diff --git a/parser.c b/parser.c index bebe5205..bdb35bef 100644 --- a/parser.c +++ b/parser.c @@ -718,15 +718,23 @@ void process_pihole_log(int file) char *resolveHostname(const char *addr) { // Get host name - struct hostent *he; + struct hostent *he = NULL; char *hostname; + bool IPv6 = false; + + // Test if we want to resolve an IPv6 address if(strstr(addr,":") != NULL) + { + IPv6 = true; + } + + if(IPv6 && config.resolveIPv6) // Resolve IPv6 address only if requested { struct in6_addr ipaddr; inet_pton(AF_INET6, addr, &ipaddr); he = gethostbyaddr(&ipaddr, sizeof ipaddr, AF_INET6); } - else + else if(!IPv6) // Always resolve IPv4 addresses { struct in_addr ipaddr; inet_pton(AF_INET, addr, &ipaddr); @@ -735,11 +743,13 @@ char *resolveHostname(const char *addr) if(he == NULL) { + // No hostname found hostname = calloc(1,sizeof(char)); hostname[0] = '\0'; } else { + // Return hostname copied to new memory location hostname = strdup(he->h_name); }