diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2023-09-08 11:49:50 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2023-09-08 09:16:13 +0200 |
commit | 60d3915ea3b07ac0a02aaf73dbf3d99547ff33bc (patch) | |
tree | 476002d416b2380258aa80cfc03dd4d37a94d1b6 | |
parent | 5fb376de6ef29e2f21b510aec7cfefeba955e26c (diff) | |
download | passt-60d3915ea3b07ac0a02aaf73dbf3d99547ff33bc.tar passt-60d3915ea3b07ac0a02aaf73dbf3d99547ff33bc.tar.gz passt-60d3915ea3b07ac0a02aaf73dbf3d99547ff33bc.tar.bz2 passt-60d3915ea3b07ac0a02aaf73dbf3d99547ff33bc.tar.lz passt-60d3915ea3b07ac0a02aaf73dbf3d99547ff33bc.tar.xz passt-60d3915ea3b07ac0a02aaf73dbf3d99547ff33bc.tar.zst passt-60d3915ea3b07ac0a02aaf73dbf3d99547ff33bc.zip |
tcp: Return consumed packet count from tcp_data_from_tap()
Currently tcp_data_from_tap() is assumed to consume all packets remaining
in the packet pool it is given. However there are some edge cases where
that's not correct. In preparation for fixing those, change it to return
a count of packets consumed and use that in its caller.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r-- | tcp.c | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -2297,8 +2297,10 @@ err: * @idx: Index of first data packet in pool * * #syscalls sendmsg + * + * Return: count of consumed packets */ -static void tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn, +static int tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn, const struct pool *p, int idx) { int i, iov_i, ack = 0, fin = 0, retr = 0, keep = -1, partial_send = 0; @@ -2310,7 +2312,7 @@ static void tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn, ssize_t n; if (conn->events == CLOSED) - return; + return p->count - idx; ASSERT(conn->events & ESTABLISHED); @@ -2323,19 +2325,19 @@ static void tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn, th = packet_get(p, i, 0, sizeof(*th), &len); if (!th) { tcp_rst(c, conn); - return; + return p->count - idx; } len += sizeof(*th); off = th->doff * 4UL; if (off < sizeof(*th) || off > len) { tcp_rst(c, conn); - return; + return p->count - idx; } if (th->rst) { conn_event(c, conn, CLOSED); - return; + return p->count - idx; } len -= off; @@ -2446,10 +2448,10 @@ eintr: if (errno == EAGAIN || errno == EWOULDBLOCK) { tcp_send_flag(c, conn, ACK_IF_NEEDED); - return; + return p->count - idx; } tcp_rst(c, conn); - return; + return p->count - idx; } if (n < (int)(seq_from_tap - conn->seq_from_tap)) { @@ -2470,7 +2472,7 @@ out: conn->seq_dup_ack_approx = conn->seq_from_tap & 0xff; tcp_send_flag(c, conn, DUP_ACK); } - return; + return p->count - idx; } if (ack && conn->events & TAP_FIN_SENT && @@ -2484,6 +2486,8 @@ out: } else { tcp_send_flag(c, conn, ACK_IF_NEEDED); } + + return p->count - idx; } /** @@ -2540,6 +2544,7 @@ int tcp_tap_handler(struct ctx *c, int af, const void *saddr, const void *daddr, struct tcphdr *th; int ack_due = 0; char *opts; + int count; th = packet_get(p, idx, 0, sizeof(*th), &len); if (!th) @@ -2627,7 +2632,7 @@ int tcp_tap_handler(struct ctx *c, int af, const void *saddr, const void *daddr, } /* Established connections accepting data from tap */ - tcp_data_from_tap(c, conn, p, idx); + count = tcp_data_from_tap(c, conn, p, idx); if (conn->seq_ack_to_tap != conn->seq_from_tap) ack_due = 1; @@ -2641,7 +2646,7 @@ int tcp_tap_handler(struct ctx *c, int af, const void *saddr, const void *daddr, if (ack_due) conn_flag(c, conn, ACK_TO_TAP_DUE); - return p->count - idx; + return count; } /** |