aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-01-16 14:15:27 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-02-12 23:42:24 +0100
commit7a8ed9459dfe803c529d61d3741d8d4f8f67ea92 (patch)
tree53b322cc77a651623e9498aecd516993743619a6 /tcp.c
parentcc6d8286d1043d04eb8518e39cebcb9e086dca17 (diff)
downloadpasst-7a8ed9459dfe803c529d61d3741d8d4f8f67ea92.tar
passt-7a8ed9459dfe803c529d61d3741d8d4f8f67ea92.tar.gz
passt-7a8ed9459dfe803c529d61d3741d8d4f8f67ea92.tar.bz2
passt-7a8ed9459dfe803c529d61d3741d8d4f8f67ea92.tar.lz
passt-7a8ed9459dfe803c529d61d3741d8d4f8f67ea92.tar.xz
passt-7a8ed9459dfe803c529d61d3741d8d4f8f67ea92.tar.zst
passt-7a8ed9459dfe803c529d61d3741d8d4f8f67ea92.zip
Make assertions actually useful
There are some places in passt/pasta which #include <assert.h> and make various assertions. If we hit these something has already gone wrong, but they're there so that we a useful message instead of cryptic misbehaviour if assumptions we thought were correct turn out not to be. Except.. the glibc implementation of assert() uses syscalls that aren't in our seccomp filter, so we'll get a SIGSYS before it actually prints the message. Work around this by adding our own ASSERT() implementation using our existing err() function to log the message, and an abort(). The abort() probably also won't work exactly right with seccomp, but once we've printed the message, dying with a SIGSYS works just as well as dying with a SIGABRT. 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.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/tcp.c b/tcp.c
index dfa8b6d..8424d8e 100644
--- a/tcp.c
+++ b/tcp.c
@@ -288,7 +288,6 @@
#include <sys/uio.h>
#include <unistd.h>
#include <time.h>
-#include <assert.h>
#include <linux/tcp.h> /* For struct tcp_info */
@@ -588,7 +587,7 @@ static inline struct tcp_tap_conn *conn_at_idx(int index)
{
if ((index < 0) || (index >= TCP_MAX_CONNS))
return NULL;
- assert(!(CONN(index)->c.spliced));
+ ASSERT(!(CONN(index)->c.spliced));
return CONN(index);
}
@@ -2695,7 +2694,7 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref,
socklen_t sl;
int s;
- assert(ref.r.p.tcp.tcp.listen);
+ ASSERT(ref.r.p.tcp.tcp.listen);
if (c->tcp.conn_count >= TCP_MAX_CONNS)
return;
@@ -2937,7 +2936,7 @@ static void tcp_ns_sock_init4(const struct ctx *c, in_port_t port)
struct in_addr loopback = { htonl(INADDR_LOOPBACK) };
int s;
- assert(c->mode == MODE_PASTA);
+ ASSERT(c->mode == MODE_PASTA);
s = sock_l4(c, AF_INET, IPPROTO_TCP, &loopback, NULL, port, tref.u32);
if (s >= 0)
@@ -2961,7 +2960,7 @@ static void tcp_ns_sock_init6(const struct ctx *c, in_port_t port)
.tcp.index = idx };
int s;
- assert(c->mode == MODE_PASTA);
+ ASSERT(c->mode == MODE_PASTA);
s = sock_l4(c, AF_INET6, IPPROTO_TCP, &in6addr_loopback, NULL, port,
tref.u32);