tcp: Clarify allowed state for tcp_data_from_tap()

Comments suggest that this should only be called for an ESTABLISHED
connection.  However, it's non-trivial to ascertain that from the actual
control flow in the caller.  Add an ASSERT() to make it very clear that
this is only called in ESTABLISHED state.

In fact, there were some circumstances where it could be called on a CLOSED
connection.  In a sense that is "established", but with that assert this
does require specific (trivial) handling to avoid a spurious abort().

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2023-03-27 14:56:33 +11:00 committed by Stefano Brivio
parent 1ee2f7cada
commit 085672f77c

5
tcp.c
View file

@ -2337,6 +2337,11 @@ static void tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn,
size_t len; size_t len;
ssize_t n; ssize_t n;
if (conn->events == CLOSED)
return;
ASSERT(conn->events & ESTABLISHED);
for (i = 0, iov_i = 0; i < (int)p->count; i++) { for (i = 0, iov_i = 0; i < (int)p->count; i++) {
uint32_t seq, seq_offset, ack_seq; uint32_t seq, seq_offset, ack_seq;
struct tcphdr *th; struct tcphdr *th;