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 9B6095A026B for ; Thu, 16 Feb 2023 06:43:19 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PHP4K4dnSz4x82; Thu, 16 Feb 2023 16:43:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676526193; bh=vHPIYEc6T+kXKTF5jpv5ZWoFMpY0FIRIAX9h8keF+Bg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HxfL873TQAzcfTSaWUekpA5D5gSwHA8T3cXB/kOkaUGmQ7ZoecY794nsssz5vNO6P M2/4YKqxhs0eS14vxP4djwCEGP9sN+qcLZcIR7GiHFcQVyQ8Nntk3TmoDHfg8HTYat F+zkcwDH00Z+1W3IPZjBGqs+2szD7oIj2e3Hz4b0= Date: Thu, 16 Feb 2023 14:48:24 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] dhcp: Fix netmask calculation for option 1 from prefix length Message-ID: References: <20230216010752.2224192-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="9KK10puI36Ufgb4K" Content-Disposition: inline In-Reply-To: <20230216010752.2224192-1-sbrivio@redhat.com> Message-ID-Hash: JRKBZ2IDYM44Y372LGRDJGHJLEJ4LCRO X-Message-ID-Hash: JRKBZ2IDYM44Y372LGRDJGHJLEJ4LCRO 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, Yalan Zhang X-Mailman-Version: 3.3.3 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: --9KK10puI36Ufgb4K Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 16, 2023 at 02:07:52AM +0100, Stefano Brivio wrote: > Similar to the conf_print() fix from commit 4129764ecaeb ("conf: Fix > mask calculation from prefix_len in conf_print()"): to calculate an > IPv4 netmask from the prefix length, we need to left shift 32 all-one > bits by 32 minus the prefix length -- not by the prefix length > itself. >=20 > Reported-by: Yalan Zhang > Fixes: dd09cceaee21 ("Minor improvements to IPv4 netmask handling") > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > dhcp.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index 6088886..edab780 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -335,7 +335,7 @@ int dhcp(const struct ctx *c, const struct pool *p) > m->chaddr[3], m->chaddr[4], m->chaddr[5]); > =20 > m->yiaddr =3D c->ip4.addr; > - mask.s_addr =3D htonl(0xffffffff << c->ip4.prefix_len); > + mask.s_addr =3D htonl(0xffffffff << (32 - c->ip4.prefix_len)); > memcpy(opts[1].s, &mask, sizeof(mask)); > memcpy(opts[3].s, &c->ip4.gw, sizeof(c->ip4.gw)); > memcpy(opts[54].s, &c->ip4.gw, sizeof(c->ip4.gw)); --=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 --9KK10puI36Ufgb4K Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmPtp4IACgkQzQJF27ox 2GeEDA//bRf/qdyVLTcXdefRhoJMXL9kowUzUDAz4wmMh8faOoE+SUnP2VKh30CJ DrMmO+bRg8ELhOlCyGaXEvdiLQ3RoazcywncisvW0a5XmEjZFVDpdgWhTVpn1eKA wZ84q582H8a4iGqQF8Hj+y4lBN9qpUdYsl0JxH00yRVfPNcdxdxIU9teAIaw+Bmw uxle075q7SgZI4LRKAIIh4wFQg7FWhRlu/tW7uRd1rFn24HCrSKBZrCh73hCAZOA 63BkIAc7/0soND9n9v83pI/EWwIcDR2P5I7gEHhmilUtfFfBFTko81Em7i3haURv jWTaYbzhybh083jofd4aISBcwJjYRRvLq/DX3cXzSrxo6sGamujpAoYnN4/zNFcJ 0yI4Wzmf77ewWgzR0yi43b1gNUWSudP8sl3FJcDJi3uz3Xzdxt8rDDjL2oJ256y3 MXX4LBWuA994hi4UliDv7rutDHRNXX8oOFHas7QiYt0dD0hYeU/YOe26HtTuFcyE 4j5kbJC48P3KMB4QEhaNrB9sqY2GW9mfOv+PDwrc3BaVJg0EuFceGD/g+juRaH/H OzTzvHWzmza+DPtOKEeRf7yiiaLYyxL9ZG1ewAr0ta5ZLxI8EBjgEJdu1uELIvwD txWx/fEJ/Tcw2fTJD9TtjTkmHKU5qkCpi1mqe1ZnkbFZue6ATz8= =A/P5 -----END PGP SIGNATURE----- --9KK10puI36Ufgb4K--