aboutgitcodebugslistschat
path: root/udp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-09-06 15:17:09 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-09-06 12:53:35 +0200
commitbd99f02a64f46cae44ef13c3cb934b8baa9c1a2c (patch)
treeb3750e7e92a463a4be9f7d0e54c7ff4f62da9a33 /udp.c
parentbd092ca421be8908aadbeb2ecdfb9fede0f67c07 (diff)
downloadpasst-bd99f02a64f46cae44ef13c3cb934b8baa9c1a2c.tar
passt-bd99f02a64f46cae44ef13c3cb934b8baa9c1a2c.tar.gz
passt-bd99f02a64f46cae44ef13c3cb934b8baa9c1a2c.tar.bz2
passt-bd99f02a64f46cae44ef13c3cb934b8baa9c1a2c.tar.lz
passt-bd99f02a64f46cae44ef13c3cb934b8baa9c1a2c.tar.xz
passt-bd99f02a64f46cae44ef13c3cb934b8baa9c1a2c.tar.zst
passt-bd99f02a64f46cae44ef13c3cb934b8baa9c1a2c.zip
udp: Treat errors getting errors as unrecoverable
We can get network errors, usually transient, reported via the socket error queue. However, at least theoretically, we could get errors trying to read the queue itself. Since we have no idea how to clear an error condition in that case, treat it as unrecoverable. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'udp.c')
-rw-r--r--udp.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/udp.c b/udp.c
index 45142cd..85a14de 100644
--- a/udp.c
+++ b/udp.c
@@ -387,11 +387,12 @@ static void udp_tap_prepare(const struct mmsghdr *mmh, unsigned idx,
* udp_sock_recverr() - Receive and clear an error from a socket
* @s: Socket to receive from
*
- * Return: true if errors received and processed, false if no more errors
+ * Return: 1 if error received and processed, 0 if no more errors in queue, < 0
+ * if there was an error reading the queue
*
* #syscalls recvmsg
*/
-static bool udp_sock_recverr(int s)
+static int udp_sock_recverr(int s)
{
const struct sock_extended_err *ee;
const struct cmsghdr *hdr;
@@ -408,14 +409,16 @@ static bool udp_sock_recverr(int s)
rc = recvmsg(s, &mh, MSG_ERRQUEUE);
if (rc < 0) {
- if (errno != EAGAIN && errno != EWOULDBLOCK)
- err_perror("Failed to read error queue");
- return false;
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
+ return 0;
+
+ err_perror("UDP: Failed to read error queue");
+ return -1;
}
if (!(mh.msg_flags & MSG_ERRQUEUE)) {
err("Missing MSG_ERRQUEUE flag reading error queue");
- return false;
+ return -1;
}
hdr = CMSG_FIRSTHDR(&mh);
@@ -424,7 +427,7 @@ static bool udp_sock_recverr(int s)
(hdr->cmsg_level == IPPROTO_IPV6 &&
hdr->cmsg_type == IPV6_RECVERR))) {
err("Unexpected cmsg reading error queue");
- return false;
+ return -1;
}
ee = (const struct sock_extended_err *)CMSG_DATA(hdr);
@@ -433,7 +436,7 @@ static bool udp_sock_recverr(int s)
debug("%s error on UDP socket %i: %s",
str_ee_origin(ee), s, strerror(ee->ee_errno));
- return true;
+ return 1;
}
/**
@@ -447,6 +450,7 @@ static bool udp_sock_recverr(int s)
static int udp_sock_errs(const struct ctx *c, int s, uint32_t events)
{
unsigned n_err = 0;
+ int rc;
ASSERT(!c->no_udp);
@@ -454,8 +458,11 @@ static int udp_sock_errs(const struct ctx *c, int s, uint32_t events)
return 0; /* Nothing to do */
/* Empty the error queue */
- while (udp_sock_recverr(s))
- n_err++;
+ while ((rc = udp_sock_recverr(s)) > 0)
+ n_err += rc;
+
+ if (rc < 0)
+ return -1; /* error reading error, unrecoverable */
return n_err;
}