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 62EDC5A0271 for ; Thu, 7 Sep 2023 06:14:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1694060051; bh=J80GV0sGxf3+wDoY4rnOW7+XSad/igLHiiKbVr3jXVM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ohY+J48D+zXoLLufndziCSon64ctv2hUxO87MwyxhS8Pniouc2+O+dENO65H9kgvN KH/RtGx0dkqMPtoBnjy212xEEiveNWkHAEWxNFyM8P1Fbti3hrW455zVvzZFQL4+mG jv+CXc6OWR0ZpzcO1D+9QLj2/9/ClJm9ofBbXvuY= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Rh5Tv3DwWz4xFB; Thu, 7 Sep 2023 14:14:11 +1000 (AEST) Date: Thu, 7 Sep 2023 13:48:03 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2 03/10] flow, tcp: Consolidate flow pointer<->index helpers Message-ID: References: <20230828054146.48673-1-david@gibson.dropbear.id.au> <20230828054146.48673-4-david@gibson.dropbear.id.au> <20230907030121.52763165@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="paV55z8yv4vo9jtE" Content-Disposition: inline In-Reply-To: <20230907030121.52763165@elisabeth> Message-ID-Hash: BSQCSBKBC325OKMJQ6TRZZ55VM6WR7GQ X-Message-ID-Hash: BSQCSBKBC325OKMJQ6TRZZ55VM6WR7GQ 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: 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: --paV55z8yv4vo9jtE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 07, 2023 at 03:01:21AM +0200, Stefano Brivio wrote: > On Mon, 28 Aug 2023 15:41:39 +1000 > David Gibson wrote: >=20 > > 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. > >=20 > > They also define their own CONN() versions, which aren't so easily comb= ined > > since they need to return different types, but we can have them use a > > common helper. > >=20 > > 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(-) > >=20 > > 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[]; > > =20 > > + > > +/** flowk_idx - Index of flow from common structure >=20 > "flowk" Oops, fixed. > > + * @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]; > > =20 > > static unsigned int tcp6_l2_flags_buf_used; > > =20 > > -#define CONN(index) (&flowtab[(index)].tcp) > > -#define CONN_IDX(conn) ((union flow *)(conn) - flowtab) > > +#define CONN(index) (&FLOW(index)->tcp) >=20 > 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? Makes sense to me, done. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --paV55z8yv4vo9jtE Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmT5R+AACgkQzQJF27ox 2GeIwQ/+LnW0WNk32kY+2xawylX4kkk4k0bIyCTaWytHSVGUShEJ0wQxjJX2tq/G Shefek5DiPOJ9UsSZrav0xbESTIs2Fhp/rwKt9reTBvni7ilomUtnRKrJIzhzSFp fE/nkkVqf0C5NbLn7TT/CKEwVQmY9jnR0ceeM5oXX7JypDlgmVKsFfyzAlxxCsa2 ZqW5ePxg1H19byFNQsAJ3BAaVnQ002BfjWJ6qwhlkqCgjZfjsWxZfl4Qa82eVVtG NZNVlzkDvfCFtUmtAmfHhtrDko4Bzdsa9Pap0e7AMP0vIVSetQnvcYKbE3ol1/x2 Wd/rT3Yt1vBwXocLhmlMMiTaqdww8uzvCvy56jZbZuk6Hoh7+lnOBcozblr/QrFf m4AB+UEi1In9aijhEFADS3/p5OaIiU/M8kOA0SccL/rhq/YcyAWhgEibGQJlvGNm VrmwSKwiud7hBbl4moOeAgKnc3N3ViGiVj0I9x7ce6zniXLm1ajNbf0w/ohygVLe +a/N3gHehJwANRjp+DtDy56GsLnL9/ouu4ZfyFlUXmTbcuKmdUwkEvtije6elpuF /uJ0QmXpUYdk4FnKr7u/k2V8uHW0Fx1Fwip6e3PWhhzEs3uGl23Al2cncjizc8u2 3WjS9Z2u0DQBU2ogM2B+e/WKC2+IEJd7Nz6luy4GGhIG2tKWVDo= =kQSX -----END PGP SIGNATURE----- --paV55z8yv4vo9jtE--