From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 2DE895A031B for ; Wed, 17 Jul 2024 06:52:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1721191945; bh=FDu8+Sjd4Xv9QHQf6Z4rhpfkybRsYyBQCwJcZuZV3xA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pPWVwpSMHCvS0UL9RIWmA9+vhfnfTLYNHlqUCdpEqLmEePrEaw/nRAxf7Lh/4EY5O q8jBZSmnFt39RZ3nmZWmUVKOAGsp5wXnN9KIC0qX+sgrfNvW3C7t5AN2gNCHGEonPY ZX+OGjVdrvCW4ZpeHU5NTDqkEZenREw4v7+TeEXpO9YnlPPDpe7hiwzForVpTT3A5J EdFLxrxreQbHjJ3+ymHt3N9mJMG4Drq7w9up9NxKszDwHZOdNV43PQBoaxI2zoml1I eZ+w6IDug9+2A7M7X7/L/lkeF5JTLNfSU/6mBT4Js6PYQ6An2aXMIl6U2OIOtz29G1 VpCFwK72pKcGA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WP3T540tlz4x1V; Wed, 17 Jul 2024 14:52:25 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 3/6] flow: Introduce flow_foreach_sidei() macro Date: Wed, 17 Jul 2024 14:52:20 +1000 Message-ID: <20240717045223.2309975-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240717045223.2309975-1-david@gibson.dropbear.id.au> References: <20240717045223.2309975-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: GXGYJADCN6JEWYPPOGGNVEPF4HWWDNOJ X-Message-ID-Hash: GXGYJADCN6JEWYPPOGGNVEPF4HWWDNOJ 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: We have a handful of places where we use a loop to step through each side of a flow or flows, and we're probably going to have mroe in future. Introduce a macro to implement this loop for convenience. Signed-off-by: David Gibson --- flow_table.h | 6 ++++++ tcp_splice.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/flow_table.h b/flow_table.h index 8a5f8f25..4f5d041c 100644 --- a/flow_table.h +++ b/flow_table.h @@ -41,6 +41,12 @@ union flow { extern unsigned flow_first_free; extern union flow flowtab[]; +/** + * flow_foreach_sidei() - 'for' type macro to step through each side of flow + * @sidei_: Takes value INISIDE, then TGTSIDE + */ +#define flow_foreach_sidei(sidei_) \ + for ((sidei_) = INISIDE; (sidei_) < SIDES; (sidei_)++) /** flow_idx() - Index of flow from common structure * @f: Common flow fields pointer diff --git a/tcp_splice.c b/tcp_splice.c index 8bc68a1a..5a9325b1 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -263,7 +263,7 @@ bool tcp_splice_flow_defer(struct tcp_splice_conn *conn) if (!(conn->flags & CLOSING)) return false; - for (sidei = 0; sidei < SIDES; sidei++) { + flow_foreach_sidei(sidei) { /* Flushing might need to block: don't recycle them. */ if (conn->pipe[sidei][0] >= 0) { close(conn->pipe[sidei][0]); @@ -299,7 +299,7 @@ static int tcp_splice_connect_finish(const struct ctx *c, unsigned sidei; int i = 0; - for (sidei = 0; sidei < SIDES; sidei++) { + flow_foreach_sidei(sidei) { for (; i < TCP_SPLICE_PIPE_POOL_SIZE; i++) { if (splice_pipe_pool[i][0] >= 0) { SWAP(conn->pipe[sidei][0], @@ -820,7 +820,7 @@ void tcp_splice_timer(const struct ctx *c, struct tcp_splice_conn *conn) ASSERT(!(conn->flags & CLOSING)); - for (sidei = 0; sidei < SIDES; sidei++) { + flow_foreach_sidei(sidei) { uint8_t set = sidei == 0 ? RCVLOWAT_SET_0 : RCVLOWAT_SET_1; uint8_t act = sidei == 0 ? RCVLOWAT_ACT_0 : RCVLOWAT_ACT_1; -- 2.45.2