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 8FBA35A0281 for ; Thu, 12 Oct 2023 03:51:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1697075480; bh=kWeAQ7mq2iZ+W0dqdaVv7Ia+JR1+BS3vZ4mbpeDOghg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TT958549MZZ3h79vFCfwuf8ni2RC/FTkorYTi6Za6ob58zOlS1eaXLor2bq5vzBHX mQ9+Y4GXY12Kq82yzOPYEAudywP/HKg8MPzBdvgixag+RfuRDw0egVHF8PuJVghV/u JG0thfs5OqqrZG59gJ02bxMpZvFVySPR0gn61toY= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4S5Xfw1Tw4z4xWZ; Thu, 12 Oct 2023 12:51:20 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 10/11] tcp_splice: Exploit side symmetry in tcp_splice_destroy() Date: Thu, 12 Oct 2023 12:51:13 +1100 Message-ID: <20231012015114.2612066-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012015114.2612066-1-david@gibson.dropbear.id.au> References: <20231012015114.2612066-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: EZXJTO4AY6OQFI27WQRWO3CEPUNOROGZ X-Message-ID-Hash: EZXJTO4AY6OQFI27WQRWO3CEPUNOROGZ 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: tcp_splice_destroy() has some close-to-duplicated logic handling closing of the socket and ipies for each side of the connection. We can use a loop across the sides to reduce the duplication. Signed-off-by: David Gibson --- tcp_splice.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/tcp_splice.c b/tcp_splice.c index 99ef8a4..239f6d2 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -258,30 +258,26 @@ void tcp_splice_conn_update(const struct ctx *c, struct tcp_splice_conn *new) void tcp_splice_destroy(struct ctx *c, union tcp_conn *conn_union) { struct tcp_splice_conn *conn = &conn_union->splice; + int side; - if (conn->events & SPLICE_ESTABLISHED) { - /* Flushing might need to block: don't recycle them. */ - if (conn->pipe[0][0] != -1) { - close(conn->pipe[0][0]); - close(conn->pipe[0][1]); - conn->pipe[0][0] = conn->pipe[0][1] = -1; + for (side = 0; side < SIDES; side++) { + if (conn->events & SPLICE_ESTABLISHED) { + /* Flushing might need to block: don't recycle them. */ + if (conn->pipe[side][0] != -1) { + close(conn->pipe[side][0]); + close(conn->pipe[side][1]); + conn->pipe[side][0] = conn->pipe[side][1] = -1; + } } - if (conn->pipe[1][0] != -1) { - close(conn->pipe[1][0]); - close(conn->pipe[1][1]); - conn->pipe[1][0] = conn->pipe[1][1] = -1; + + if (side == 0 || conn->events & SPLICE_CONNECT) { + close(conn->s[side]); + conn->s[side] = -1; } - } - if (conn->events & SPLICE_CONNECT) { - close(conn->s[1]); - conn->s[1] = -1; + conn->read[side] = conn->written[side] = 0; } - close(conn->s[0]); - conn->s[0] = -1; - conn->read[0] = conn->written[0] = conn->read[1] = conn->written[1] = 0; - conn->events = SPLICE_CLOSED; conn->flags = 0; debug("TCP (spliced): index %li, CLOSED", CONN_IDX(conn)); -- 2.41.0