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 RESOLVEIPV6 config flag #138

Merged
merged 3 commits into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions FTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ typedef struct {
bool query_display;
bool analyze_AAAA;
int maxDBdays;
bool resolveIPv6;
} ConfigStruct;

// Dynamic structs
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
14 changes: 14 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down