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

Improve FTL connection error logging #2170

Merged
merged 1 commit into from
Jan 31, 2025
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
19 changes: 11 additions & 8 deletions src/dnsmasq/forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ int send_from(int fd, int nowild, char *packet, size_t len,
/* If interface is still in DAD, EINVAL results - ignore that. */
if (errno != EINVAL)
{
const int errnum = errno;
my_syslog(LOG_ERR, _("failed to send packet: %s"), strerror(errno));
/********** Pi-hole modification **********/
FTL_connection_error("failed to send UDP reply", to);
FTL_connection_error("failed to send UDP reply", to, errnum);
/******************************************/
}
#endif
Expand Down Expand Up @@ -516,7 +517,7 @@ static void forward_query(int udpfd, union mysockaddr *udpaddr,
/**** Pi-hole modification ****/
else
{
FTL_connection_error("failed to send UDP request", &srv->addr);
FTL_connection_error("failed to send UDP request", &srv->addr, errno);
}
/******************************/
}
Expand Down Expand Up @@ -2081,7 +2082,7 @@ static ssize_t tcp_talk(int first, int last, int start, unsigned char *packet,
fatal = 1;
/**** Pi-hole modification ****/
if (errno != 0)
FTL_connection_error("failed to send TCP(fast-open) packet", &serv->addr);
FTL_connection_error("failed to send TCP(fast-open) packet", &serv->addr, errno);
/******************************/
#endif

Expand All @@ -2090,7 +2091,7 @@ static ssize_t tcp_talk(int first, int last, int start, unsigned char *packet,
if (fatal || (!data_sent && connect(serv->tcpfd, &serv->addr.sa, sa_len(&serv->addr)) == -1))
{
/**** Pi-hole modification ****/
FTL_connection_error("failed to send TCP(connect) packet", &serv->addr);
FTL_connection_error("failed to send TCP(connect) packet", &serv->addr, errno);
/******************************/
close(serv->tcpfd);
serv->tcpfd = -1;
Expand All @@ -2107,10 +2108,7 @@ static ssize_t tcp_talk(int first, int last, int start, unsigned char *packet,
!read_write(serv->tcpfd, (unsigned char *)length, sizeof (*length), RW_READ_ONCE) ||
!read_write(serv->tcpfd, payload, (rsize = ntohs(*length)), RW_READ_ONCE))
{
/**** Pi-hole modification ****/
FTL_connection_error("failed to send TCP(read_write) packet", &serv->addr);
/******************************/

const int errnum = errno;
close(serv->tcpfd);
serv->tcpfd = -1;
/* We get data then EOF, reopen connection to same server,
Expand All @@ -2119,7 +2117,12 @@ static ssize_t tcp_talk(int first, int last, int start, unsigned char *packet,
if (serv->flags & SERV_GOT_TCP)
goto retry;
else
/**** Pi-hole modification ****/
{
FTL_connection_error("failed to send TCP(read_write) packet", &serv->addr, errnum);
continue;
}
/******************************/
}

/* If the question section of the reply doesn't match the crc we sent, then
Expand Down
5 changes: 2 additions & 3 deletions src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -3737,10 +3737,9 @@ void get_dnsmasq_metrics_obj(cJSON *json)
cJSON_AddNumberToObject(json, get_metric_name(i), daemon->metrics[i]);
}

void FTL_connection_error(const char *reason, const union mysockaddr *addr)
void FTL_connection_error(const char *reason, const union mysockaddr *addr, const int errnum)
{
// Make a private copy of the error
const int errnum = errno;
// Get the error message
const char *error = strerror(errnum);

// Set log priority
Expand Down
2 changes: 1 addition & 1 deletion src/dnsmasq_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void FTL_TCP_worker_terminating(bool finished);

bool FTL_unlink_DHCP_lease(const char *ipaddr, const char **hint);

void FTL_connection_error(const char *reason, const union mysockaddr *addr);
void FTL_connection_error(const char *reason, const union mysockaddr *addr, const int errnum);

bool get_dnsmasq_debug(void) __attribute__ ((pure));

Expand Down
Loading