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=202410 header.b=Z/8htnlg; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 9CE8E5A061D for ; Tue, 26 Nov 2024 02:16:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1732583774; bh=Hkx1xqBHuJbBAQg//SESeCrHDw0BBDGVR97TnGkJp0w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Z/8htnlgnNZcVEH78qjL0Dv8kS5MkRUOJBi1ceeQmCRVl67lCtMrME6B27L/5vfLc sX3G2yU2o77+gwn6dkJcf+PNut8TQOqY3jCsLzc6g/Yt2v6MglIdAee4bME06oL2Aq OdmTF0m4oNX2Bvae226ghJKArguFqI5qx+JNT0HYpLs3W1LuQw5Ut5aSCCund7jdjl YqNURCQdMb1pK1xzje0zSInzenNKubea8zLYGlXDI5MoK6yRBBgRPZTDcf5MjbC06a qdCUZmWamIutnbdx/z5MfArzBMewTYD1EyqVPjVG/zFb+QvBDxH1/a65T4iX4jrkAf 39qtgIR7Ivfgg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Xy4Qk71szz4x3J; Tue, 26 Nov 2024 12:16:14 +1100 (AEDT) Date: Tue, 26 Nov 2024 12:16:11 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v3 3/3] dhcp: Honour broadcast flag (RFC 2131, 4.1) Message-ID: References: <20241125152812.369553-1-sbrivio@redhat.com> <20241125152812.369553-4-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="af/yuzHHYbok9qWM" Content-Disposition: inline In-Reply-To: <20241125152812.369553-4-sbrivio@redhat.com> Message-ID-Hash: RMVQDRSNUDTRLS4WWG5TABD3NTGMGDR7 X-Message-ID-Hash: RMVQDRSNUDTRLS4WWG5TABD3NTGMGDR7 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: --af/yuzHHYbok9qWM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 25, 2024 at 04:28:12PM +0100, Stefano Brivio wrote: > It's widely considered a legacy option nowadays, and I've haven't seen > clients setting it since Windows 95, but it's convenient for a minimal > DHCP client not using raw IP sockets such as what I'm playing with for > muvm. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > dhcp.c | 12 ++++++++++-- > ip.h | 3 +++ > 2 files changed, 13 insertions(+), 2 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index 90bb534..b3688ef 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -112,6 +112,8 @@ struct msg { > uint32_t xid; > uint16_t secs; > uint16_t flags; > +#define FLAG_BROADCAST htons_constant(0x8000) > + > uint32_t ciaddr; > struct in_addr yiaddr; > uint32_t siaddr; > @@ -285,10 +287,10 @@ int dhcp(const struct ctx *c, const struct pool *p) > { > size_t mlen, dlen, offset =3D 0, opt_len, opt_off =3D 0; > char macstr[ETH_ADDRSTRLEN]; > + struct in_addr mask, dst; > const struct ethhdr *eh; > const struct iphdr *iph; > const struct udphdr *uh; > - struct in_addr mask; > unsigned int i; > struct msg *m; > =20 > @@ -400,7 +402,13 @@ int dhcp(const struct ctx *c, const struct pool *p) > opt_set_dns_search(c, sizeof(m->o)); > =20 > dlen =3D offsetof(struct msg, o) + fill(m); > - tap_udp4_send(c, c->ip4.our_tap_addr, 67, c->ip4.addr, 68, m, dlen); > + > + if (m->flags & FLAG_BROADCAST) > + dst =3D in4addr_broadcast; > + else > + dst =3D c->ip4.addr; > + > + tap_udp4_send(c, c->ip4.our_tap_addr, 67, dst, 68, m, dlen); > =20 > return 1; > } > diff --git a/ip.h b/ip.h > index 0742612..1544dbf 100644 > --- a/ip.h > +++ b/ip.h > @@ -101,4 +101,7 @@ static const struct in6_addr in6addr_ll_all_nodes =3D= { > }, > }; > =20 > +/* IPv4 Limited Broadcast (RFC 919, Section 7), 255.255.255.255 */ > +static const struct in_addr in4addr_broadcast =3D { 0xffffffff }; > + > #endif /* IP_H */ --=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 --af/yuzHHYbok9qWM Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmdFIVoACgkQzQJF27ox 2GfmXg/9ETa0Iw3k2aO1t4g1OoWzG/mRLA7gd0NELlx75IEUHMeLVipuEUFKq3N2 +6tm1O0CIKoOcvvOjWQJRHXoJdIyagkHW4S3cupdO0Dd7QQh7Ll35BBwM3Wpro8M u3XDFAtTgvMAzVrTCSXUQAOfaXAlbQj1TyBWl91HvzwTpG2M4s68yiQmwuvmp5Wl 9x5sS0G5AL9HtDTjz5xgefWusk/sq5cDgCqW1jlIRUaGQRJp4i+V+yXYPPdp1lwd L48fKzx4vVrm21UAcsrHmwxCz3L7diUTbuPWeQ3+F+ffb51zqk1DZUBOdEmBfCPJ H2Ppu6j9xXUNrV/6czx26FQItlgTFFXWGKYF+PhKXCD+59N3Fy59S4k+47JUH/Bj tt5p4B24CmexTlYcdCTNFB98SQygkgiPczv556ThjCsWFjoWBac6vlEKVO2y7EJ3 gJphhAc3uLisjsXOXTh69xj1Gvih+GBSkxeaXf5KkpmHnnuMBTxScxOjtMP/7Vym PVJaQsBt+YG4sAHEpHTCEH4u7Tfk1/oVkOpobTskmfrd13CWBWv+exFLyr9dKXTY F10tTwcnwSxUx+TfkZOU7Fp+cUid4kEGtMqb/7HOkJ60AcYtC3tnAytYdrP6y4FR CdJ6Kny+vUBv4PA/mmt3SAuWAw21q10KP6rbiPaJH/MNA+X0EFc= =HUKI -----END PGP SIGNATURE----- --af/yuzHHYbok9qWM--