If udp_sock_recverr() gets an error retrieving the error queue, or
udp_sock_errs() gets an error reading the SO_ERROR sockopt, we log a
message with err_perror(),
That severity is reasonable - this is something going unexpectedly wrong
host side, not merely a connection getting shut down because we hit a
network error. However, the messages can be made more useful by linking
them to the specific flow, and safer by ratelimiting them.
Remove the places where we included the numerical value of the socket fd:
that's rarely useful, especially now that we have the context about the
flow the fd belonged to.
Signed-off-by: David Gibson
---
udp.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/udp.c b/udp.c
index d23163f6..60bcfb89 100644
--- a/udp.c
+++ b/udp.c
@@ -580,10 +580,12 @@ static int udp_sock_recverr(const struct ctx *c, int s, flow_sidx_t sidx,
rc = recvmsg(s, &mh, MSG_ERRQUEUE);
if (rc < 0) {
+ struct udp_flow *uflow = udp_at_sidx(sidx);
+
if (errno == EAGAIN || errno == EWOULDBLOCK)
return 0;
- err_perror("UDP: Failed to read error queue");
+ flow_perror_ratelimit(uflow, now, "Failed to read error queue");
return -1;
}
@@ -693,6 +695,7 @@ static int udp_sock_errs(const struct ctx *c, int s, flow_sidx_t sidx,
uint8_t pif, in_port_t port,
const struct timespec *now)
{
+ struct udp_flow *uflow = udp_at_sidx(sidx);
unsigned n_err = 0;
socklen_t errlen;
int rc, err;
@@ -709,18 +712,20 @@ static int udp_sock_errs(const struct ctx *c, int s, flow_sidx_t sidx,
errlen = sizeof(err);
if (getsockopt(s, SOL_SOCKET, SO_ERROR, &err, &errlen) < 0 ||
errlen != sizeof(err)) {
- err_perror("Error reading SO_ERROR");
+ flow_perror_ratelimit(uflow, now, "Error reading SO_ERROR");
return -1; /* error reading error, unrecoverable */
}
if (err) {
- debug("Unqueued error on UDP socket %i: %s", s, strerror_(err));
+ flow_dbg(uflow, "Unqueued error on UDP socket: %s",
+ strerror_(err));
n_err++;
}
if (!n_err) {
/* EPOLLERR, but no errors to clear !? */
- err("EPOLLERR event without reported errors on socket %i", s);
+ flow_err_ratelimit(uflow, now,
+ "EPOLLERR event without reported errors", s);
return -1; /* no way to clear, unrecoverable */
}
--
2.54.0