diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2024-11-25 00:52:57 +0100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-11-27 05:37:28 +0100 |
commit | c0fbc7ef2ae2919bf6162b4149d341f448289836 (patch) | |
tree | 575a722c3f156202a48290961ebe8e8133c336dd | |
parent | 9da2038485c9334d28df34d2ebd5ba04a3c7662d (diff) | |
download | passt-c0fbc7ef2ae2919bf6162b4149d341f448289836.tar passt-c0fbc7ef2ae2919bf6162b4149d341f448289836.tar.gz passt-c0fbc7ef2ae2919bf6162b4149d341f448289836.tar.bz2 passt-c0fbc7ef2ae2919bf6162b4149d341f448289836.tar.lz passt-c0fbc7ef2ae2919bf6162b4149d341f448289836.tar.xz passt-c0fbc7ef2ae2919bf6162b4149d341f448289836.tar.zst passt-c0fbc7ef2ae2919bf6162b4149d341f448289836.zip |
dhcp: Honour broadcast flag (RFC 2131, 4.1)2024_11_27.c0fbc7e
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 <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r-- | dhcp.c | 12 | ||||
-rw-r--r-- | ip.h | 3 |
2 files changed, 13 insertions, 2 deletions
@@ -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 = 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; @@ -400,7 +402,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 = in4addr_broadcast; + else + dst = c->ip4.addr; + + tap_udp4_send(c, c->ip4.our_tap_addr, 67, dst, 68, m, dlen); return 1; } @@ -101,4 +101,7 @@ static const struct in6_addr in6addr_ll_all_nodes = { }, }; +/* IPv4 Limited Broadcast (RFC 919, Section 7), 255.255.255.255 */ +static const struct in_addr in4addr_broadcast = { 0xffffffff }; + #endif /* IP_H */ |