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=GVzXlhhf; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 6876B5A061A for ; Mon, 25 Nov 2024 02:11:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1732497096; bh=K2Mdg6xnAcojWRqkF5/q8BDRaJBba41VyWOCWYFnYys=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GVzXlhhfsPeEAA9yFkkfvR1UJEEzbKghKUTrkkZRtd/WBAMazcI3TRsoWbO6Rx+/o ENy7Q/5xoZ6JlV3GLJlCJAyiLN9Rm1oZxGGwIpm+gY6NLJughjkzMWWLU/Na+omlvv vy99LYXLrKtlQncvuXSR2HZj8nzEAFZ6VkXk2pAw1wdABY/QIewPtLZhXs3paX53jN CH6L5+uSxx/PdsWvjYSna/wpw1/L98QwDv0w1nSEls564mJ+6hjQ5R/fo66qUWVzhk s6cyHVMggqcWY45XMYuV9ku9nQa9bded5CLpKMGW3z6vk3NAAjDtmmwMBoFg5QuYQg AI+Q9wrPDf5WA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XxSMr1HM3z4xdL; Mon, 25 Nov 2024 12:11:36 +1100 (AEDT) Date: Mon, 25 Nov 2024 12:11:34 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 3/3] dhcp: Honour broadcast flag (RFC 2131, 4.1) Message-ID: References: <20241125000423.4131458-1-sbrivio@redhat.com> <20241125000423.4131458-4-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="+l1gsWOR1bF6ZOm1" Content-Disposition: inline In-Reply-To: <20241125000423.4131458-4-sbrivio@redhat.com> Message-ID-Hash: ZZDATBAHJKS6ZNPXBDZ25J3M2FTZYHY5 X-Message-ID-Hash: ZZDATBAHJKS6ZNPXBDZ25J3M2FTZYHY5 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: --+l1gsWOR1bF6ZOm1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 25, 2024 at 01:04:23AM +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 > --- > dhcp.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index aa0ad96..f1416ee 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -107,6 +107,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; > @@ -280,10 +282,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 > @@ -398,7 +400,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 (struct in_addr){ 0xffffffff }; It would be nice to add a symbolic constant ("in4addr_broadcast"?) to ip.h for this. > + else > + dst =3D c->ip4.addr; > + > + tap_udp4_send(c, c->ip4.our_tap_addr, 67, dst, 68, m, dlen); > =20 > return 1; > } --=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 --+l1gsWOR1bF6ZOm1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmdDzsUACgkQzQJF27ox 2Getcg/+L3u1Dm7tsGETAV8BJcTckiqSL8t/GuacTL2ceO0vr1Le/gLLEmh4h2DB D6hEDXSiuoSYC6U8M2czIRfCjuzhErMQiCfjz06E8m2KeV3OleohMmzmbJnR/NN1 NOVq5+T+V//KA//33VRxdjXfkxhxCYIK9OfQoZ4kLPS2uS4nQA0Wh3xGXhNDyBda MOkATIQqOJ8xfWzzGYUakoEZCpg7Bus/4qYCBKEuBflqE10CBRs+tOyBTXWTkYoR v+kWv5kcjjH6mo+DD4l5LhedjrJ1Q46gOtgxuYLZAsx5QYqTbJIrOPDEQbJcU1Py aStT7DEI1oFtwqqMH7psjMK1zky5GTwEKQaCdLEh5/mmNligUbSowMMhHWSO7WO8 HogYCN4bR28Mi/Db9JpvRGRuNgeyACQaAAbXDCY/Bs+B9E5vtk2rT+pjOVvVNlum sYsznFe8hHHXIvtRfMlGR7CuU2+ugk9TZUI1/p4seitALafNYxinQICkcDaRn3P4 Ar7tMBlyevbPGkYmKxZSYtRtUHQ0vR4K2QAymqtyH6zjk8dS5wAF+HmOJHYpuNQO LYA3/IW+1eJFJ10oAhiNuagpION7UT2/J0DIEgrJzSa7TGgD3cUxqmyNECLPn8Sp xzSgI6GmtEJJnVADwCrlgqOAJLye68ka9LiLGke8llWfzDuJtM4= =naAF -----END PGP SIGNATURE----- --+l1gsWOR1bF6ZOm1--