aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2026-12-03 02:22:24 +0100
committerStefano Brivio <sbrivio@redhat.com>2026-12-03 02:22:24 +0100
commit111029829f8761cd0ccd7c5f8648ad0e9527841b (patch)
treed222584bd48ddb6a9cddaf73129a906fb3392489
parentf8f340650247e97b0633a33cdb08e20f2880b36b (diff)
downloadpasst-111029829f8761cd0ccd7c5f8648ad0e9527841b.tar
passt-111029829f8761cd0ccd7c5f8648ad0e9527841b.tar.gz
passt-111029829f8761cd0ccd7c5f8648ad0e9527841b.tar.bz2
passt-111029829f8761cd0ccd7c5f8648ad0e9527841b.tar.lz
passt-111029829f8761cd0ccd7c5f8648ad0e9527841b.tar.xz
passt-111029829f8761cd0ccd7c5f8648ad0e9527841b.tar.zst
passt-111029829f8761cd0ccd7c5f8648ad0e9527841b.zip
udp: Flush socket errors even after an intervening recvmmsg() clears the code
Gonzalo reports that if a socket error occurs (for example, due to an ICMP message) between udp_sock_errs() and a subsequent recvmmsg() call, coming from udp_sock_recv(), the recvmmsg() call will clear the socket error code, but not the queue. At this point, once we're done handling the socket events, EPOLLERR is still set, so udp_listen_sock_handler(), and, in turn, udp_sock_fwd(), will be called again, but the recvmsg() call in udp_peek_addr() won't report any actual error (rather EAGAIN). As a result, we won't call udp_sock_errs() and leave the error in the queue. This leads to a event processing loop, until a further error is reported. This is a consequence of 04984578b00f ("udp: Deal with errors as we go in udp_sock_fwd()"): earlier, udp_sock_errs() would be called on any EPOLLERR event. But now that we clear errors as we iterate through udp_peek_addr() calls, we don't necessarily do that anymore. This part is still desirable, so, instead of going back to an initial out-of-order call to udp_sock_errs() on EPOLLERR, keep the processing order as it is, but make sure that we'll call udp_sock_errs() at least once per event handling cycle, whenever EPOLLERR was set on the socket. This way, if the error code vanished because of an intervening recvmmsg() call, we will still be able to clear queued errors. Link: https://bugs.passt.top/show_bug.cgi?id=228 Reported-by: Gonzalo Rivas Valenzuela <grv@jessica.cl> Fixes: 04984578b00f ("udp: Deal with errors as we go in udp_sock_fwd()" Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--udp.c28
-rw-r--r--udp_flow.c2
-rw-r--r--udp_internal.h2
3 files changed, 21 insertions, 11 deletions
diff --git a/udp.c b/udp.c
index 7966079..2b0b41f 100644
--- a/udp.c
+++ b/udp.c
@@ -705,13 +705,13 @@ static int udp_sock_errs(const struct ctx *c, int s, flow_sidx_t sidx,
n_err += rc;
if (rc < 0)
- return -1; /* error reading error, unrecoverable */
+ goto fail; /* error reading error, unrecoverable */
errlen = sizeof(err);
if (getsockopt(s, SOL_SOCKET, SO_ERROR, &err, &errlen) < 0 ||
errlen != sizeof(err)) {
flow_perror_ratelimit(uflow, now, "Error reading SO_ERROR");
- return -1; /* error reading error, unrecoverable */
+ goto fail; /* error reading error, unrecoverable */
}
if (err) {
@@ -724,10 +724,16 @@ static int udp_sock_errs(const struct ctx *c, int s, flow_sidx_t sidx,
/* EPOLLERR, but no errors to clear !? */
flow_err_ratelimit(uflow, now,
"EPOLLERR event without reported errors");
- return -1; /* no way to clear, unrecoverable */
+ goto fail; /* no way to clear, unrecoverable */
}
return n_err;
+
+fail:
+ err_ratelimit(now,
+"UDP: Unrecoverable error on listening socket: (%s port %hu)",
+ pif_name(pif), port);
+ return -1;
}
/**
@@ -856,12 +862,13 @@ static void udp_buf_sock_to_tap(const struct ctx *c, int s, int n,
* udp_sock_fwd() - Forward datagrams from a possibly unconnected socket
* @c: Execution context
* @s: Socket to forward from
+ * @errors: There are socket errors (EPOLLERR) to be flushed
* @rule_hint: Forwarding rule to use, or -1 if unknown
* @frompif: Interface to which @s belongs
* @port: Our (local) port number of @s
* @now: Current timestamp
*/
-void udp_sock_fwd(const struct ctx *c, int s, int rule_hint,
+void udp_sock_fwd(const struct ctx *c, int s, bool errors, int rule_hint,
uint8_t frompif, in_port_t port, const struct timespec *now)
{
union sockaddr_inany src;
@@ -876,14 +883,14 @@ void udp_sock_fwd(const struct ctx *c, int s, int rule_hint,
if (rc < 0) {
trace("Error peeking at socket address: %s",
strerror_(-rc));
+
/* Clear errors & carry on */
if (udp_sock_errs(c, s, FLOW_SIDX_NONE,
frompif, port, now) < 0) {
- err_ratelimit(now,
-"UDP: Unrecoverable error on listening socket: (%s port %hu)",
- pif_name(frompif), port);
- /* FIXME: what now? close/re-open socket? */
+ ; /* FIXME: what now? close/re-open socket? */
}
+ errors = false;
+
continue;
}
@@ -918,6 +925,9 @@ void udp_sock_fwd(const struct ctx *c, int s, int rule_hint,
debug_perror("Failed to discard datagram");
}
}
+
+ if (errors)
+ udp_sock_errs(c, s, FLOW_SIDX_NONE, frompif, port, now);
}
/**
@@ -932,7 +942,7 @@ void udp_listen_sock_handler(const struct ctx *c,
const struct timespec *now)
{
if (events & (EPOLLERR | EPOLLIN)) {
- udp_sock_fwd(c, ref.fd, ref.listen.rule,
+ udp_sock_fwd(c, ref.fd, events & EPOLLERR, ref.listen.rule,
ref.listen.pif, ref.listen.port, now);
}
}
diff --git a/udp_flow.c b/udp_flow.c
index 57e159f..0e78fa6 100644
--- a/udp_flow.c
+++ b/udp_flow.c
@@ -393,7 +393,7 @@ static void udp_flush_flow(const struct ctx *c,
{
/* We don't know exactly where the datagrams will come from, but we know
* they'll have an interface and oport matching this flow */
- udp_sock_fwd(c, uflow->s[sidei], -1, uflow->f.pif[sidei],
+ udp_sock_fwd(c, uflow->s[sidei], false, -1, uflow->f.pif[sidei],
uflow->f.side[sidei].oport, now);
}
diff --git a/udp_internal.h b/udp_internal.h
index 361cc74..55dae38 100644
--- a/udp_internal.h
+++ b/udp_internal.h
@@ -33,7 +33,7 @@ size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udphdr *uh,
struct iov_tail *payload,
const struct flowside *toside, size_t dlen,
bool no_udp_csum);
-void udp_sock_fwd(const struct ctx *c, int s, int rule_hint,
+void udp_sock_fwd(const struct ctx *c, int s, bool errors, int rule_hint,
uint8_t frompif, in_port_t port, const struct timespec *now);
#endif /* UDP_INTERNAL_H */