Skip to content

Commit

Permalink
Merge pull request #2170 from pi-hole/tweak/conn_errors
Browse files Browse the repository at this point in the history
Improve FTL connection error logging
  • Loading branch information
DL6ER authored Jan 31, 2025
2 parents a7e0828 + 3d6bad8 commit 80ef20e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
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 @@ -523,7 +524,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 @@ -2097,7 +2098,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 @@ -2106,7 +2107,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 @@ -2123,10 +2124,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 @@ -2135,7 +2133,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 question 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 @@ -3786,10 +3786,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

0 comments on commit 80ef20e

Please sign in to comment.