From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 33C265A026F for ; Sat, 13 Jan 2024 23:50:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705186253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PoMfemBnicWpp4npBBkIhIdv5gZxW5QrpyGMSXJou58=; b=WnC88h5x2e8Bupp5RIkbEXWc7sdLuRgKJTfwmYi1hfW7x5vdUoBkpSJes8VLSyBiVhn/Cy 7Jw34rdYCHJ0W1gi82z4cpjmFwp6gOzIQo81TlrJnQZWj8tiJ12/wDQXWQyBQLdy7a/Jc1 H8VdPPDCR6pr/v7mxZ4qm/Vfzgk2QSA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-ADe6KKFbOjyuYMRUMQ3MvA-1; Sat, 13 Jan 2024 17:50:46 -0500 X-MC-Unique: ADe6KKFbOjyuYMRUMQ3MvA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2B0F85A588; Sat, 13 Jan 2024 22:50:45 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF2B6C25AC8; Sat, 13 Jan 2024 22:50:44 +0000 (UTC) Date: Sat, 13 Jan 2024 23:50:40 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v3 01/15] flow: Common data structures for tracking flow addresses Message-ID: <20240113235040.60be469f@elisabeth> In-Reply-To: <20231221070237.1422557-2-david@gibson.dropbear.id.au> References: <20231221070237.1422557-1-david@gibson.dropbear.id.au> <20231221070237.1422557-2-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: QDTQKE5GK5WU3U3TOCNEH7W2PF522S4K X-Message-ID-Hash: QDTQKE5GK5WU3U3TOCNEH7W2PF522S4K X-MailFrom: sbrivio@redhat.com 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: passt-dev@passt.top 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: On Thu, 21 Dec 2023 18:02:23 +1100 David Gibson wrote: > 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"); > + Nits: > +/** flowside_complete - Check if flowside is fully initialized flowside_complete(). By the way, shouldn't we call it something more descriptive such as flowside_is_complete()? It's not obvious this is a check otherwise. > + * @fside: flowside to check * Return: true if pif, addresses and ports are set ...or something of that sort. > + */ > +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; I would align everything after 'return ', that is: return fside->pif != PIF_NONE && !IN6_IS_ADDR_UNSPECIFIED(&fside->faddr) && !IN6_IS_ADDR_UNSPECIFIED(&fside->eaddr) && fside->fport != 0 && fside->eport != 0; mostly for consistency -- not a strong preference. -- Stefano