aboutgitcodebugslistschat
path: root/tcp.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 /tcp.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 'tcp.c')
-rw-r--r--tcp.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/tcp.c b/tcp.c
index e606603..05a430b 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2326,7 +2326,9 @@ void tcp_listen_handler(struct ctx *c, union epoll_ref ref,
union flow *flow;
int s;
- if (c->no_tcp || !(flow = flow_alloc()))
+ ASSERT(!c->no_tcp);
+
+ if (!(flow = flow_alloc()))
return;
s = accept4(ref.fd, &sa.sa, &sl, SOCK_NONBLOCK);
@@ -2379,8 +2381,7 @@ void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
struct itimerspec check_armed = { { 0 }, { 0 } };
struct tcp_tap_conn *conn = CONN(ref.flow);
- if (c->no_tcp)
- return;
+ ASSERT(!c->no_tcp);
/* We don't reset timers on ~ACK_FROM_TAP_DUE, ~ACK_TO_TAP_DUE. If the
* timer is currently armed, this event came from a previous setting,
@@ -2442,6 +2443,7 @@ void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events)
{
struct tcp_tap_conn *conn = CONN(ref.flowside.flow);
+ ASSERT(!c->no_tcp);
ASSERT(conn->f.type == FLOW_TCP);
ASSERT(conn->f.pif[ref.flowside.side] != PIF_TAP);
@@ -2541,6 +2543,8 @@ int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr,
{
int r4 = FD_REF_MAX + 1, r6 = FD_REF_MAX + 1;
+ ASSERT(!c->no_tcp);
+
if (af == AF_UNSPEC && c->ifi4 && c->ifi6)
/* Attempt to get a dual stack socket */
if (tcp_sock_init_af(c, AF_UNSPEC, port, addr, ifname) >= 0)
@@ -2618,6 +2622,8 @@ static void tcp_ns_sock_init6(const struct ctx *c, in_port_t port)
*/
void tcp_ns_sock_init(const struct ctx *c, in_port_t port)
{
+ ASSERT(!c->no_tcp);
+
if (c->ifi4)
tcp_ns_sock_init4(c, port);
if (c->ifi6)
@@ -2706,6 +2712,8 @@ int tcp_init(struct ctx *c)
unsigned int b, optv = 0;
int s;
+ ASSERT(!c->no_tcp);
+
for (b = 0; b < TCP_HASH_TABLE_SIZE; b++)
tc_hash[b] = FLOW_SIDX_NONE;