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 086D25A027D for ; Thu, 21 Dec 2023 08:02:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1703142161; bh=fYGNl4BIUU1g6Rf86WRznxjivhKLMvp2vUq9yXDNWE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DfV9bFPPiRsZ82BBdbCbpfBhyePeU7+/PsUlwQrAdrMF1GM/SHe4nDI/FO7VBP7Xf 73IZgNprJgWQPHKUHSURiJxgewOAPDSuWJ7p8IEvU/c72eXQHtQMShZJ4dLiZQyIAz CsgwWYkAj6WmUK2qZoe2BPaw6pdc5adysVt8GmNQBdEZw8iqNJdP/9NbUsqlM2y/as QGzYXyBnituQpBUmLGlYOu3YOpuhoB9CbkYVUCC0OQrJru1W51oQXEaCRDnVOlg1xO DWVa1oT1s0y0nRZYLE5BKMDamw1UblFCAeY7o7rLhT/2ft73aLRxYKZcnl05HMW8XI mwZI+ahxJs/8g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SwhFs0VK0z4xRj; Thu, 21 Dec 2023 18:02:41 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v3 07/15] flow: Add helper to determine a flow's protocol Date: Thu, 21 Dec 2023 18:02:29 +1100 Message-ID: <20231221070237.1422557-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231221070237.1422557-1-david@gibson.dropbear.id.au> References: <20231221070237.1422557-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: WFYTJGFRJIVOECONSSZ2WJ5XWTUSD2N2 X-Message-ID-Hash: WFYTJGFRJIVOECONSSZ2WJ5XWTUSD2N2 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: Each flow already has a type field. This implies the protocol the flow represents, but also has more information: we have two ways to represent TCP flows, "tap" and "spliced". In order to generalise some of the flow mechanics, we'll need to determine a flow's protocol in terms of the IP (L4) protocol number. Introduce a constant table and helper macro to derive this from the flow type. Signed-off-by: David Gibson --- flow.c | 7 +++++++ flow.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/flow.c b/flow.c index 263633e..70036fc 100644 --- a/flow.c +++ b/flow.c @@ -26,6 +26,13 @@ const char *flow_type_str[] = { static_assert(ARRAY_SIZE(flow_type_str) == FLOW_NUM_TYPES, "flow_type_str[] doesn't match enum flow_type"); +const uint8_t flow_proto[] = { + [FLOW_TCP] = IPPROTO_TCP, + [FLOW_TCP_SPLICE] = IPPROTO_TCP, +}; +static_assert(ARRAY_SIZE(flow_proto) == FLOW_NUM_TYPES, + "flow_proto[] doesn't match enum flow_type"); + /* Global Flow Table */ unsigned flow_first_free; union flow flowtab[FLOW_MAX]; diff --git a/flow.h b/flow.h index 72ded54..ab831d1 100644 --- a/flow.h +++ b/flow.h @@ -27,6 +27,10 @@ extern const char *flow_type_str[]; #define FLOW_TYPE(f) \ ((f)->type < FLOW_NUM_TYPES ? flow_type_str[(f)->type] : "?") +extern const uint8_t flow_proto[]; +#define FLOW_PROTO(f) \ + ((f)->type < FLOW_NUM_TYPES ? flow_proto[(f)->type] : 0) + /** * struct flowside - Common information for one side of a flow * @eaddr: Endpoint address (remote address from passt's PoV) -- 2.43.0