From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id C31565A061D; Mon, 25 Nov 2024 01:04:23 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 3/3] dhcp: Honour broadcast flag (RFC 2131, 4.1) Date: Mon, 25 Nov 2024 01:04:23 +0100 Message-ID: <20241125000423.4131458-4-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241125000423.4131458-1-sbrivio@redhat.com> References: <20241125000423.4131458-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: QR3QAGY63ROOUQWV7PUXKTJGRXGYFAJX X-Message-ID-Hash: QR3QAGY63ROOUQWV7PUXKTJGRXGYFAJX X-MailFrom: sbrivio@passt.top 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 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: 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. Signed-off-by: Stefano Brivio --- dhcp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 = 0, opt_len, opt_off = 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; @@ -398,7 +400,13 @@ int dhcp(const struct ctx *c, const struct pool *p) opt_set_dns_search(c, sizeof(m->o)); dlen = 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 = (struct in_addr){ 0xffffffff }; + else + dst = c->ip4.addr; + + tap_udp4_send(c, c->ip4.our_tap_addr, 67, dst, 68, m, dlen); return 1; } -- 2.43.0