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

Return DNS port on ">dns-port" telnet command #1264

Merged
merged 2 commits into from
Dec 29, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1473,3 +1473,9 @@ void delete_lease(const char *client_message, const int *sock)
if(config.debug & DEBUG_API)
logg("...done");
}

void getDNSport(const int *sock)
{
// Return DNS port used by FTL
ssend(*sock, "%d\n", config.dns_port);
}
1 change: 1 addition & 0 deletions src/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void getUnknownQueries(const int *sock);

// DNS resolver methods (dnsmasq_interface.c)
void getCacheInformation(const int *sock);
void getDNSport(const int *sock);

// MessagePack serialization helpers
void pack_eom(const int sock);
Expand Down
5 changes: 5 additions & 0 deletions src/api/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ void process_request(const char *client_message, int *sock)
processed = true;
delete_lease(client_message, sock);
}
else if(command(client_message, ">dns-port"))
{
processed = true;
getDNSport(sock);
}

// Test only at the end if we want to quit or kill
// so things can be processed before
Expand Down
7 changes: 7 additions & 0 deletions test/test_suite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
[[ ${lines[6]} == "" ]]
}

@test "DNS server port is reported" {
run bash -c 'echo ">dns-port >quit" | nc -v 127.0.0.1 4711'
printf "%s\n" "${lines[@]}"
[[ ${lines[1]} == "53" ]]
[[ ${lines[2]} == "" ]]
}

@test "Running a second instance is detected and prevented" {
run bash -c 'su pihole -s /bin/sh -c "/home/pihole/pihole-FTL -f"'
printf "%s\n" "${lines[@]}"
Expand Down