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 968C25A026D for ; Thu, 7 Sep 2023 03:01:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694048491; 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=XesoAg4xsXkVOox7tta6TDkcaDtLy1V7wIuwZX+XS/A=; b=PV3C79cKd7lC2drKjjJak8Yua/s3Cmm23KbxvcmqcqnEznS6XCtc48ImJy9GN3NQxG0LQJ RLj0ufjmT9Rke1DXT/nfg3mQu4XWdPKnYr4/KmcJU9+TgdPbSAjkebOilGPieN+arYr+6L nn3SmcAToRgWfV7N2jTjs5HYek/gVaE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-679-_wr7xtMAOQSv1MJNddz-gA-1; Wed, 06 Sep 2023 21:01:30 -0400 X-MC-Unique: _wr7xtMAOQSv1MJNddz-gA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 288AC800CA8; Thu, 7 Sep 2023 01:01:30 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 763FF493110; Thu, 7 Sep 2023 01:01:29 +0000 (UTC) Date: Thu, 7 Sep 2023 03:01:21 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2 03/10] flow, tcp: Consolidate flow pointer<->index helpers Message-ID: <20230907030121.52763165@elisabeth> In-Reply-To: <20230828054146.48673-4-david@gibson.dropbear.id.au> References: <20230828054146.48673-1-david@gibson.dropbear.id.au> <20230828054146.48673-4-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: CS2GHOTJX76D2JN6EINTK4RDNBJHY7N7 X-Message-ID-Hash: CS2GHOTJX76D2JN6EINTK4RDNBJHY7N7 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 Mon, 28 Aug 2023 15:41:39 +1000 David Gibson wrote: > Both tcp.c and tcp_splice.c define CONN_IDX() variants to find the index > of their connection structures in the connection table, now become the > unified flow table. We can easily combine these into a common helper. > While we're there, add some trickery for some additional type safety. > > They also define their own CONN() versions, which aren't so easily combined > since they need to return different types, but we can have them use a > common helper. > > Signed-off-by: David Gibson > --- > flow_table.h | 20 ++++++++++++++++++++ > tcp.c | 49 ++++++++++++++++++++++++------------------------- > tcp_conn.h | 2 +- > tcp_splice.c | 17 ++++++++--------- > 4 files changed, 53 insertions(+), 35 deletions(-) > > diff --git a/flow_table.h b/flow_table.h > index c4c646b..dd4875e 100644 > --- a/flow_table.h > +++ b/flow_table.h > @@ -22,4 +22,24 @@ union flow { > /* Global Flow Table */ > extern union flow flowtab[]; > > + > +/** flowk_idx - Index of flow from common structure "flowk" > + * @f: Common flow fields pointer > + * > + * Return: index of @f in the flow table > + */ > +static inline unsigned flow_idx(const struct flow_common *f) > +{ > + return (union flow *)f - flowtab; > +} > + > +/** FLOW_IDX - Find the index of a flow > + * @f_: Flow pointer, either union flow * or protocol specific > + * > + * Return: index of @f in the flow table > + */ > +#define FLOW_IDX(f_) (flow_idx(&(f_)->f)) > + > +#define FLOW(index) (&flowtab[(index)]) > + > #endif /* FLOW_TABLE_H */ > diff --git a/tcp.c b/tcp.c > index 7994197..7d2e89d 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -561,8 +561,7 @@ tcp6_l2_flags_buf[TCP_FRAMES_MEM]; > > static unsigned int tcp6_l2_flags_buf_used; > > -#define CONN(index) (&flowtab[(index)].tcp) > -#define CONN_IDX(conn) ((union flow *)(conn) - flowtab) > +#define CONN(index) (&FLOW(index)->tcp) Extra parentheses are not needed, but I've been wondering for a bit why you would use "&FLOW" here, as FLOW(x) already resolves to &flowtab[x]... perhaps (&(FLOW(index)->tcp)) is actually easier to read? -- Stefano