aboutgitcodebugslistschat
path: root/udp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-07-17 10:36:02 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-07-17 07:05:15 +0200
commit4e1f850f61caaff0c65ce9d5fc4322a4aea807dc (patch)
treeb0a341a91943b4ffe1794c6df32aa1ad70bc69fb /udp.c
parent272d1d033c640700b21c49335b5b9c9474f52682 (diff)
downloadpasst-4e1f850f61caaff0c65ce9d5fc4322a4aea807dc.tar
passt-4e1f850f61caaff0c65ce9d5fc4322a4aea807dc.tar.gz
passt-4e1f850f61caaff0c65ce9d5fc4322a4aea807dc.tar.bz2
passt-4e1f850f61caaff0c65ce9d5fc4322a4aea807dc.tar.lz
passt-4e1f850f61caaff0c65ce9d5fc4322a4aea807dc.tar.xz
passt-4e1f850f61caaff0c65ce9d5fc4322a4aea807dc.tar.zst
passt-4e1f850f61caaff0c65ce9d5fc4322a4aea807dc.zip
udp, tcp: Tweak handling of no_udp and no_tcp flags
We abort the UDP socket handler if the no_udp flag is set. But if UDP was disabled we should never have had a UDP socket to trigger the handler in the first place. If we somehow did, ignoring it here isn't really going to help because aborting without doing anything is likely to lead to an epoll loop. The same is the case for the TCP socket and timer handlers and the no_tcp flag. Change these checks on the flag to ASSERT()s. Similarly add ASSERT()s to several other entry points to the protocol specific code which should never be called if the protocol is disabled. 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.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/udp.c b/udp.c
index 187483f..fbf3ce7 100644
--- a/udp.c
+++ b/udp.c
@@ -749,7 +749,9 @@ static int udp_sock_recv(const struct ctx *c, int s, uint32_t events,
*/
int n = (c->mode == MODE_PASTA ? 1 : UDP_MAX_FRAMES);
- if (c->no_udp || !(events & EPOLLIN))
+ ASSERT(!c->no_udp);
+
+ if (!(events & EPOLLIN))
return 0;
n = recvmmsg(s, mmh, n, 0, NULL);
@@ -849,10 +851,11 @@ int udp_tap_handler(struct ctx *c, uint8_t pif,
in_port_t src, dst;
socklen_t sl;
- (void)c;
(void)saddr;
(void)pif;
+ ASSERT(!c->no_udp);
+
uh = packet_get(p, idx, 0, sizeof(*uh), NULL);
if (!uh)
return 1;
@@ -1026,6 +1029,8 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
.orig = true, .port = port };
int s, r4 = FD_REF_MAX + 1, r6 = FD_REF_MAX + 1;
+ ASSERT(!c->no_udp);
+
if (ns)
uref.pif = PIF_SPLICE;
else
@@ -1214,6 +1219,8 @@ void udp_timer(struct ctx *c, const struct timespec *now)
unsigned int i;
long *word, tmp;
+ ASSERT(!c->no_udp);
+
if (c->mode == MODE_PASTA) {
if (c->udp.fwd_out.f.mode == FWD_AUTO) {
fwd_scan_ports_udp(&c->udp.fwd_out.f, &c->udp.fwd_in.f,
@@ -1257,6 +1264,8 @@ v6:
*/
int udp_init(struct ctx *c)
{
+ ASSERT(!c->no_udp);
+
udp_iov_init(c);
udp_invert_portmap(&c->udp.fwd_in);