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 1D28B5A026D for ; Thu, 21 Dec 2023 08:02:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1703142160; bh=tQ08hWNiHu7lT1oxJ3o8Wcu+4EVVjGZajZDfBcDmma0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GkgnecM8uZ8TEvwQ5uPuvYviG1d7ZeW8kgQaeIjP131aBisoP4uH/xwGbpSKVB/n4 rvwdH+5EiNMQm0JoP7jSYpFm68QBAIIpCmc69eOUsj8QdwzMU4IZNVZLAGTWTgkMxU pM1hymvLTrCaW8BnSqmz7IA+7y+KLbWsNuJyAhcuLQSCBiuTFApYNsl1Sku+caxLaK 5DKZfX7h+UhfTmoUatGE+vYhflbj5nSr91n0QmLra4C+Xnak738a2JsoACW8r72FOT OfFlCyhLzlW9ZYM89O1lq5k+t9dDeMf1+MqgNvHHszeX+/fUZVFc62S+iVeDvdG8oV jbNKa0NisugGg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SwhFr6jk9z4xPQ; Thu, 21 Dec 2023 18:02:40 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v3 01/15] flow: Common data structures for tracking flow addresses Date: Thu, 21 Dec 2023 18:02:23 +1100 Message-ID: <20231221070237.1422557-2-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: BZO6XTLTIHXHW3UEBNJ25CIBYPF6OL6S X-Message-ID-Hash: BZO6XTLTIHXHW3UEBNJ25CIBYPF6OL6S 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: Handling of each protocol needs some degree of tracking of the addresses and ports at the end of each connection or flow. Sometimes that's explicit (as in the guest visible addresses for TCP connections), sometimes implicit (the bound and connected addresses of sockets). To allow more general and robust handling, and more consistency across protocols we want to uniformly track the address and port at each end of the connection. Furthermore, because we allow port remapping, and we sometimes need to apply NAT, the addresses and ports can be different as seen by the guest/namespace and as by the host. Introduce 'struct flowside' to keep track of common information related to one side of each flow. For now that's the addresses, ports and the pif id. Store two of these in the common fields of a flow to track that information for both sides. For now we just introduce the structure and fields themselves, along with a simple helper. Later patches will actually use these to store useful information. Signed-off-by: David Gibson --- flow.h | 33 +++++++++++++++++++++++++++++++++ passt.h | 2 ++ tcp_conn.h | 1 - 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/flow.h b/flow.h index 48a0ab4..e090ba0 100644 --- a/flow.h +++ b/flow.h @@ -27,11 +27,44 @@ extern const char *flow_type_str[]; #define FLOW_TYPE(f) \ ((f)->type < FLOW_NUM_TYPES ? flow_type_str[(f)->type] : "?") +/** + * struct flowside - Common information for one side of a flow + * @eaddr: Endpoint address (remote address from passt's PoV) + * @faddr: Forwarding address (local address from passt's PoV) + * @eport: Endpoint port + * @fport: Forwarding port + * @pif: pif ID on which this side of the flow exists + */ +struct flowside { + union inany_addr faddr; + union inany_addr eaddr; + in_port_t fport; + in_port_t eport; + uint8_t pif; +}; +static_assert(_Alignof(struct flowside) == _Alignof(uint32_t), + "Unexpected alignment for struct flowside"); + +/** flowside_complete - Check if flowside is fully initialized + * @fside: flowside to check + */ +static inline bool flowside_complete(const struct flowside *fside) +{ + return fside->pif != PIF_NONE && + !IN6_IS_ADDR_UNSPECIFIED(&fside->faddr) && + !IN6_IS_ADDR_UNSPECIFIED(&fside->eaddr) && + fside->fport != 0 && fside->eport != 0; +} + +#define SIDES 2 + /** * struct flow_common - Common fields for packet flows + * @side[]: Information for each side of the flow * @type: Type of packet flow */ struct flow_common { + struct flowside side[SIDES]; uint8_t type; }; diff --git a/passt.h b/passt.h index a9e8f15..db0cd10 100644 --- a/passt.h +++ b/passt.h @@ -37,6 +37,8 @@ union epoll_ref; #include "pif.h" #include "packet.h" +#include "siphash.h" +#include "inany.h" #include "flow.h" #include "icmp.h" #include "port_fwd.h" diff --git a/tcp_conn.h b/tcp_conn.h index a5f5cfe..1a4dcf2 100644 --- a/tcp_conn.h +++ b/tcp_conn.h @@ -106,7 +106,6 @@ struct tcp_tap_conn { uint32_t seq_init_from_tap; }; -#define SIDES 2 /** * struct tcp_splice_conn - Descriptor for a spliced TCP connection * @f: Generic flow information -- 2.43.0