From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=A2t1Xopp; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 3A4495A004E for ; Mon, 02 Mar 2026 11:29:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1772447360; bh=K/07pwlyA7+UwLhA7jnCE7GnQPw8lp/MtxiGb+2LagY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=A2t1XoppXGadeUpEXfK8JXNBsXJQLfAW53U7APmxjlMuEWnhiirejavzt5BuL0MFU tBnBjBl+44Ow4IQ6ioq3ondvOBeGOvMaPUvxFCXLbqBDGRwztIQc4s1SrPPlsE8DbQ Py1gOSYUaM2yjLViJ8dsK0Q50bnO9/RksLW6oUIxTWt22cC2ulSElxBwrjfEqU/T+n aCHQqLpVjSUUs/TRgprKNouY5DCbCEJIgGDXGgrv7+e+TKMZLUpage99fTnk+TwDTQ ej+V/9SkbzB406eOx8aUnL7CcjWRnahD/Da1M7wDvBV7J6sS5Q0PN5iUcIiTacUT4c jO0qn5sKnWBtQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fPZt84R0Gz4w9Q; Mon, 02 Mar 2026 21:29:20 +1100 (AEDT) Date: Mon, 2 Mar 2026 21:29:16 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v5 02/13] ip: Introduce for_each_addr() macro for address iteration Message-ID: References: <20260222174445.743845-1-jmaloy@redhat.com> <20260222174445.743845-3-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="0fRXhm8JSBlFy2EL" Content-Disposition: inline In-Reply-To: <20260222174445.743845-3-jmaloy@redhat.com> Message-ID-Hash: CPA4MPOWOD352QQET3ALQC5SWU2IJ5HA X-Message-ID-Hash: CPA4MPOWOD352QQET3ALQC5SWU2IJ5HA 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: sbrivio@redhat.com, dgibson@redhat.com, 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: --0fRXhm8JSBlFy2EL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 22, 2026 at 12:44:34PM -0500, Jon Maloy wrote: > Add the for_each_addr() macro to iterate over addresses in the unified > array. The macro supports an address family filter parameter (AF_INET, > AF_INET6, or 0 for all) using a _next_addr_idx() helper function to > skip non-matching entries. >=20 > Signed-off-by: Jon Maloy >=20 > --- > v1: - Broke out as separate commit > - I kept the third argument, despite David's comment, since I still > find it practical. If we want to iterate the list without filter Eh, ok. I'm kind of hoping it will go away eventually, once more of the v4 and v6 paths are unified. > we can just use AF_UNSPEC (=3D=3D 0) > --- > passt.h | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) >=20 > diff --git a/passt.h b/passt.h > index 1aa71f0..bb56998 100644 > --- a/passt.h > +++ b/passt.h > @@ -344,6 +344,40 @@ static inline int inany_prefix4(const struct inany_a= ddr_entry *e) > return e->prefix_len - 96; > } > =20 > +/** > + * _next_addr_idx() - Find next address index matching family filter > + * @c: Pointer to struct ctx > + * @i: Starting index > + * @af: Address family filter: AF_INET, AF_INET6, or 0 for all > + * > + * Return: next matching index, or addr_count if none found > + */ > +static inline int _next_addr_idx(const struct ctx *c, int i, sa_family_t= af) > +{ > + for (; i < c->addr_count; i++) { > + sa_family_t entry_af; > + > + entry_af =3D inany_v4(&c->addrs[i].addr) ? AF_INET : AF_INET6; > + > + if (!af || af =3D=3D entry_af) I'd prefer an explicit (af =3D=3D AF_UNSPEC), rather than subtly relying on AF_UNSPEC having value 0. > + return i; > + } > + return i; > +} > + > +/** > + * for_each_addr() - Iterate over addresses in unified array > + * @e: Pointer variable for current entry (struct inany_addr_entry *) > + * @c: Pointer to struct ctx > + * @af: Address family filter: AF_INET, AF_INET6, or 0 for all > + * > + * Note: @_i is the internal loop counter, uses _next_addr_idx() helper > + */ > +#define for_each_addr(e, c, af) \ > + for (int _i =3D _next_addr_idx((c), 0, (af)); \ Huh. We haven't really used declarations within for previously, but we do require C11 which allows them. There might be some other foreach macros that can be improved by using this. > + _i < (c)->addr_count && ((e) =3D &(c)->addrs[_i], true); \ > + _i =3D _next_addr_idx((c), _i + 1, (af))) > + > void proto_update_l2_buf(const unsigned char *eth_d); > =20 > #endif /* PASST_H */ > --=20 > 2.52.0 >=20 --=20 David Gibson (he or they) | 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 --0fRXhm8JSBlFy2EL Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmlZnsACgkQzQJF27ox 2GfZNw/+PKWpz8XzkhxqgBO9AFfRs5vdsRdFtuAJT+1N1Z1MFlXGGuxDk7p7ZSyo vFrKj00M2ezEF1dIZm6oNo0dhRfmm4Bp+log2cVmF4NDysJ7sLlwv6LxfLYhD2pa GzAsOZLakn8Gmw2c9i4vtFQ5vFmfkVwUyo7CgOMJA6PIcCosQbIEdPAaWiyjpSiE Vyex/iAC4P3m4ex3ifYCmUpi5Aedd6sVBfLqS0av30ktqdG4bJGagnqeeIKtn3QT 5+RbYWgSCCxDbV0h5xfeUwxKyvvEzGopwkSF/y0IEZdP11fCDTMRNBZJSdKwNF4l kWMQpHAL3nXUtj/tx9R/SINpnAIDXzxnDGA59fTOLiXIvnv0VYTOyQKUCZ99al2t guHp/64xJtP5ldK+wr2riKGrUb+qzj+OkTn0v5sSBh+F4egrdGL2ma9FjNwq8tMt FPfr6/t17wdz7YWQvOl095cEwm/KA9KMBuTIH5hIlGCAvJRwBSF3mEdrUSv4vWPQ ib+HGXzX9/+9lXv70kqpIoDIneW9m8vUWPpVWtFR2Fi8l+poj+Svkjylto+Lj3O8 G21XYy+DmrB9bkIGl7BwRmmMqdREFGF4to9y1FC8NQ8N9MbMAoGCGVWsO+FkH9yz /+sbgB2qmkiy0Pb2HX+yoggGrm3B8ylNXdfCrCTG3FQIrQdQcBw= =TE9C -----END PGP SIGNATURE----- --0fRXhm8JSBlFy2EL--