From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 860CC5A027F for ; Fri, 8 Sep 2023 03:50:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1694137797; bh=Pr6AS9jATAngAUqP/4DIoYDcfSllis5F/c/s7Gm1M8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F7x46KFu2Bk26JWvyDgwQ3dB2Aj+xiGvK08Rbx0dbRE1M11R9tRoO++Y0ooyrC8Q+ 1f28er7UdzDzy1r0f5nfXM14GUHfRd9iXBl4+ovDTwVWiRtLqUtWM0XMLXahP7nSZu RI8giioCXKZ73NT0fxJrKwQyzCsep7qsxc8fSq0w= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RhfF10gQfz4xG4; Fri, 8 Sep 2023 11:49:57 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 5/8] tcp: Return consumed packet count from tcp_data_from_tap() Date: Fri, 8 Sep 2023 11:49:50 +1000 Message-ID: <20230908014953.822952-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230908014953.822952-1-david@gibson.dropbear.id.au> References: <20230908014953.822952-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: L3S5JHDP3EVXIKKIYUWUQZISBOC2QFKA X-Message-ID-Hash: L3S5JHDP3EVXIKKIYUWUQZISBOC2QFKA X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: jlesev@gmail.com, David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- tcp.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tcp.c b/tcp.c index 5592998..34c27f0 100644 --- a/tcp.c +++ b/tcp.c @@ -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; } /** -- 2.41.0