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=R6yOkH2L; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id A1ECA5A0653 for ; Wed, 04 Feb 2026 15:47:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1770216470; bh=gw9U4+pms2odjQQN6s3f7gdp1UJ/nXK9vBc9JvP8TOA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=R6yOkH2Loga+m2WhHO0QrXHboxi12l7vDSv6pju3NsjcBXw2/S/+5vGaYdb0ifzmW xjbLe4GmJghj77k6aFVbNkj7aqRpZo64x8fa8+ybIx1F8x8wiBHvSDThyEF2t3sI6w vDo/QbW+78NlWKm5CzoXGZg58KF+b+2K+iuFvBZJEUMEg+dlyeJz/XLDzypidOE/Mz M2yn+mYCstpjYnxxoM9wYRnXByHlfB/Gz2ikUNmQdb02r1bDvsgvUPFFfwufRB4bjm NejEZYoOM90Bd1zQ9qMVbmnjjLIPBoFObycJkUfp6Z0NfSF6XJ80Z0/pjbcA56bOVJ 2uilqCtAppPQQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4f5jrQ6N7Dz4wpf; Thu, 05 Feb 2026 01:47:50 +1100 (AEDT) Date: Wed, 4 Feb 2026 22:52:14 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v3 02/11] ip: Add IN4_MASK() macro for IPv4 netmask calculation Message-ID: References: <20260130214447.2540791-1-jmaloy@redhat.com> <20260130214447.2540791-3-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Vm3lzyjWxWWUDd4E" Content-Disposition: inline In-Reply-To: <20260130214447.2540791-3-jmaloy@redhat.com> Message-ID-Hash: 3WXGSNBMKISKFFTHGFLPSCU2BWO6X7P2 X-Message-ID-Hash: 3WXGSNBMKISKFFTHGFLPSCU2BWO6X7P2 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: --Vm3lzyjWxWWUDd4E Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 30, 2026 at 04:44:38PM -0500, Jon Maloy wrote: > Add a convenience macro to compute an IPv4 netmask from a prefix length. > This simplifies netmask calculations throughout the codebase. >=20 > Signed-off-by: Jon Maloy Reviewed-by: David Gibson > --- > conf.c | 2 +- > dhcp.c | 2 +- > ip.h | 2 ++ > 3 files changed, 4 insertions(+), 2 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 98d5d17..5188c02 100644 > --- a/conf.c > +++ b/conf.c > @@ -1147,7 +1147,7 @@ static void conf_print(const struct ctx *c) > if (!c->no_dhcp) { > uint32_t mask; > =20 > - mask =3D htonl(0xffffffff << (32 - c->ip4.prefix_len)); > + mask =3D IN4_MASK(c->ip4.prefix_len); > =20 > info("DHCP:"); > info(" assign: %s", > diff --git a/dhcp.c b/dhcp.c > index 6b9c2e3..c552f01 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -404,7 +404,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > =20 > info(" from %s", eth_ntop(m->chaddr, macstr, sizeof(macstr))); > =20 > - mask.s_addr =3D htonl(0xffffffff << (32 - c->ip4.prefix_len)); > + mask.s_addr =3D IN4_MASK(c->ip4.prefix_len); > memcpy(opts[1].s, &mask, sizeof(mask)); > memcpy(opts[3].s, &c->ip4.guest_gw, sizeof(c->ip4.guest_gw)); > memcpy(opts[54].s, &c->ip4.our_tap_addr, sizeof(c->ip4.our_tap_addr)); > diff --git a/ip.h b/ip.h > index bd28640..c829d84 100644 > --- a/ip.h > +++ b/ip.h > @@ -17,6 +17,8 @@ > (ntohl(((struct in_addr *)(a))->s_addr) >> IN_CLASSA_NSHIFT =3D=3D IN_L= OOPBACKNET) > #define IN4_IS_ADDR_MULTICAST(a) \ > (IN_MULTICAST(ntohl(((struct in_addr *)(a))->s_addr))) > +#define IN4_MASK(prefix_len) \ > + (htonl(0xffffffff << (128 - (prefix_len)))) > #define IN4_ARE_ADDR_EQUAL(a, b) \ > (((struct in_addr *)(a))->s_addr =3D=3D ((struct in_addr *)b)->s_addr) > #define IN4ADDR_LOOPBACK_INIT \ > --=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 --Vm3lzyjWxWWUDd4E Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmDQPcACgkQzQJF27ox 2GcFVg//Sf76JzvhiPG6sMXoIJ01AvttsdDtHxWWqkGRVJckBQ6XFh4HpU+z9Fjt q6z4olcbL+JBlqjKq60U2eOVq4zYJr0v61au/yEF71VqgKq94p0nYcURBf5Ev2HU ABTReQsfHloU1YuAvvSWiEXNFDTZyFMVBjoA0qOfCIWNTBqno5PN4VZeKyOE7qw7 hUxPAVAbVSZJ+1NNOVjSbh6OioVWyX210Bl91rTjmhmnlApKsJbL1EEuBID1VI56 qpwaEBb0NxQdOcxMYEzEO0QPuxbrIBe/UHxTFibSuvIxKL79FS7iXCBVsOa6TPXU dn2ORfQmcUV6CzyUFtcTi4DmMeHWcDhDNb5yg3MgSOwqRaY/Ji3gXazmOAkdmbTR k6WzTSqrpiP6q+8mLR0/zlBoy81s/MHGAsbF9ztqfYZk23ohfZcFA3S4FnycC+3W 2oIsuXSgUUYOZdEOl0TZ+siJeFfvv17Hl0lrQU4mZJQ/JZJr9v6i2hE78Q8F25UV rev/XQXsgaVGqG98v30yOtOlHN1xzWsVItQ/2XwkKbFUsU4JqlOAO7uGn/ThK39v UlO3hyjlhb/OofR6hmaidfStJqjBaqwJ7IbF0+q3lCcB7C+JolnMIgy6PZkXJMIf psZNvICJu6qiwD8nNrQPfd0mevCUZcozshg5b4o8CYLo3zNI7P0= =MstN -----END PGP SIGNATURE----- --Vm3lzyjWxWWUDd4E--