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=202512 header.b=CvG4azZK; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 390DD5A0626 for ; Mon, 15 Dec 2025 11:08:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1765793302; bh=HQSHWhhxmzic9DrN1cikOzQaWibpN+Zqho+ZQyClbwM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CvG4azZKxIrNVqb1TRyI+jxhovn0HQmoT/Fbb2xh8iM7twUNHSzeIR8oYpaAHxxX/ EfhouEZSvXrTVGAka1upqsXQC9mTYD2THf9ztg4uHHfq+IC5+I+zMuNmCcfJiQO53l XseEKxdnmG9gK5N2WA6GFD+O9u2bm8DDkQkbNCECKkDWJeQZ5+PabkM/7mRRauwO21 FcKzPeEavUIhb2PI3DDBY4Qs8ASdjawODSVIz0mu+ywTjX+qSqZg4kIZyQwctfRDKn tgQTuwuDF3lc4jA9IX5r7hxEC7el/JhtISOIVRt7corjKn1KsibhaPEdLuQ5ZavCIr ZJyaz/anyIM9w== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dVG3V1rKVz4w11; Mon, 15 Dec 2025 21:08:22 +1100 (AEDT) Date: Mon, 15 Dec 2025 20:41:28 +1100 From: David Gibson To: Jon Maloy Subject: Re: [RFC 02/12] ip: Add ip4_default_prefix_len() helper function for class-based prefix Message-ID: References: <20251215015441.887736-1-jmaloy@redhat.com> <20251215015441.887736-3-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="5PkXjdV2v4j87m5u" Content-Disposition: inline In-Reply-To: <20251215015441.887736-3-jmaloy@redhat.com> Message-ID-Hash: 6EZA5VN46FPTTDFHXDQPLTYWTTPSG23Q X-Message-ID-Hash: 6EZA5VN46FPTTDFHXDQPLTYWTTPSG23Q 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: --5PkXjdV2v4j87m5u Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Dec 14, 2025 at 08:54:31PM -0500, Jon Maloy wrote: > We add a helper function to calculate the default IPv4 prefix length > based on address class. This is used to replace the current inline > calculation in conf_ip4(), and is also a preparation for more uses > of this functionality in the coming commits. >=20 > Signed-off-by: Jon Maloy Reviewed-by: David Gibson Not a complaint about this patch, since it's just code motion, but the whole idea of network classes is obsolete these days. I wonder if we should deprecate automatic picking of prefix_len based on class. > --- > conf.c | 15 +++------------ > ip.c | 21 +++++++++++++++++++++ > ip.h | 2 ++ > 3 files changed, 26 insertions(+), 12 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 0e96f36..31acc20 100644 > --- a/conf.c > +++ b/conf.c > @@ -733,18 +733,9 @@ static unsigned int conf_ip4(unsigned int ifi, struc= t ip4_ctx *ip4, > } > =20 > /* Apply default prefix_len to first address if not set */ > - if (!ip4->addrs[0].prefix_len) { > - in_addr_t a =3D ntohl(ip4->addrs[0].addr.s_addr); > - > - if (IN_CLASSA(a)) > - ip4->addrs[0].prefix_len =3D 8; > - else if (IN_CLASSB(a)) > - ip4->addrs[0].prefix_len =3D 16; > - else if (IN_CLASSC(a)) > - ip4->addrs[0].prefix_len =3D 24; > - else > - ip4->addrs[0].prefix_len =3D 32; > - } > + if (!ip4->addrs[0].prefix_len) > + ip4->addrs[0].prefix_len =3D > + ip4_default_prefix_len(&ip4->addrs[0].addr); > =20 > ip4->addr_seen =3D ip4->addrs[0].addr; > =20 > diff --git a/ip.c b/ip.c > index 9a7f4c5..2519c71 100644 > --- a/ip.c > +++ b/ip.c > @@ -13,6 +13,8 @@ > */ > =20 > #include > +#include > + > #include "util.h" > #include "ip.h" > =20 > @@ -67,3 +69,22 @@ found: > *proto =3D nh; > return true; > } > + > +/** > + * ip4_default_prefix_len() - Get default prefix length for IPv4 address > + * @addr: IPv4 address > + * > + * Return: prefix length based on address class (8/16/24), or 32 for oth= er > + */ > +int ip4_default_prefix_len(const struct in_addr *addr) > +{ > + in_addr_t a =3D ntohl(addr->s_addr); > + > + if (IN_CLASSA(a)) > + return 8; > + if (IN_CLASSB(a)) > + return 16; > + if (IN_CLASSC(a)) > + return 24; > + return 32; > +} > diff --git a/ip.h b/ip.h > index 748cb1f..065b78b 100644 > --- a/ip.h > +++ b/ip.h > @@ -139,6 +139,8 @@ static const struct in_addr in4addr_broadcast =3D { 0= xffffffff }; > #define IP4_MAX_ADDRS 8 > #define IP6_MAX_ADDRS 16 > =20 > +int ip4_default_prefix_len(const struct in_addr *addr); > + > /** > * struct ip4_addr_entry - IPv4 address with prefix length > * @addr: IPv4 address > --=20 > 2.51.1 >=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 --5PkXjdV2v4j87m5u Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmk/18cACgkQzQJF27ox 2GfRUhAAlKZk4jUyNk6sPuLEU9IwmKoMpQxbxgl7fPTNkuLsLd0AjFUIEz4s9qNF 7eYt3/zTHsxwx6czXqbN4NX74y3tJ19g02MhtnI7cgyVBoReCbyB/xzg8f1l/faB HVYsLKmRzxsP2khtL0FXAm01/DHZE725HJqArHJ0t15BSs025+XJsGoP0t3/Jj5x CcCeZkk3GScJqnPi9TpTlYiIqwNv8iic1+OxkKd9fzk8TxYd3Lh+w9I5xhdOU1Ez 4wRzdycpXicx2H7wA9BIQ3GrnAphGacOnhH/gENzdgUD0Th5td1IE+6Zc1XSGcTb sA9A1hpW5S1T0RbpKu8etm+U+MoezRzYHYIi0qYQvnBhH7q9J9tFwI4ZbBSRJvGB BSZednz4llPTP5MwjeQt1BT8oUz2ZjAZTmjJUhKSzD7kUMAAdvQ6tf9XBJiowCuN RBkTX2Yjh5ldZytFh8ML4rT7Ns+mqx8hTOUmZvhfa52yigwQHMev0hqaN+76y7Xn B6wj+xdQvtJvvuFvrlkOh4iwpNXdrg4fJe98O+nQVYV6mVd7VjUWBLt60mXeEbNK AOnF4/gWguWtmHc7BATBFt792hFAnL7n5NYWYczzxTNzMxHRmBHasqqhAe2r1CpA NOd7velil1fKdC3dUQlowoSMMhxhd1GxLhKLwY6mclrDqBQcVo4= =kMgC -----END PGP SIGNATURE----- --5PkXjdV2v4j87m5u--