From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id A0C6A5A026D for ; Mon, 27 Mar 2023 05:56:40 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PlJsJ6zCtz4xDv; Mon, 27 Mar 2023 14:56:36 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1679889396; bh=uk5UY41IsTM5ywBefAPPOWQiDU0zqxThURoLhRIcQ+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mAFgFduynPLA5TrcX0QfONgPNDVTlS74U+th1kkg8Myug1YXeIx1nwG/O5QBD3TCT jAoUONz3WOps4+HHbKB0NpPCbneaN3dNxcijZGMQW2JL+4uPOI5Fcf+OZ5SlaaHFtc RGmftqXtonkNtxejSplApNSiA0jHhciqMH1YFnws= From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 1/2] tcp: Clarify allowed state for tcp_data_from_tap() Date: Mon, 27 Mar 2023 14:56:33 +1100 Message-Id: <20230327035634.1432064-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230327035634.1432064-1-david@gibson.dropbear.id.au> References: <20230327035634.1432064-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: Q5CZSK62TO7KH4X7ZYF2H57CYFXPRN2X X-Message-ID-Hash: Q5CZSK62TO7KH4X7ZYF2H57CYFXPRN2X 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: 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: 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 --- tcp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tcp.c b/tcp.c index f156287..d82c62e 100644 --- a/tcp.c +++ b/tcp.c @@ -2337,6 +2337,11 @@ static void tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn, size_t len; ssize_t n; + if (conn->events == CLOSED) + return; + + ASSERT(conn->events & ESTABLISHED); + for (i = 0, iov_i = 0; i < (int)p->count; i++) { uint32_t seq, seq_offset, ack_seq; struct tcphdr *th; -- 2.39.2