From c6845f60a062b69d1d4e64db1b6d0f1b6ac75d43 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 19 Oct 2022 11:43:57 +1100 Subject: dhcp: Use tap_udp4_send() helper in dhcp() The IPv4 specific dhcp() manually constructs L2 and IP headers to send its DHCP reply packet, unlike its IPv6 equivalent in dhcpv6.c which uses the tap_udp6_send() helper. Now that we've broaded the parameters to tap_udp4_send() we can use it in dhcp() to avoid some duplicated logic. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- dhcp.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'dhcp.c') diff --git a/dhcp.c b/dhcp.c index 2b3af82..d22698a 100644 --- a/dhcp.c +++ b/dhcp.c @@ -363,22 +363,8 @@ int dhcp(const struct ctx *c, const struct pool *p) if (!c->no_dhcp_dns_search) opt_set_dns_search(c, sizeof(m->o)); - uh->len = htons(len = offsetof(struct msg, o) + fill(m) + sizeof(*uh)); - uh->source = htons(67); - uh->dest = htons(68); - csum_udp4(uh, c->ip4.gw, c->ip4.addr, uh + 1, len - sizeof(*uh)); - - iph->tot_len = htons(len += sizeof(*iph)); - iph->daddr = c->ip4.addr; - iph->saddr = c->ip4.gw; - csum_ip4_header(iph); - - len += sizeof(*eh); - memcpy(eh->h_dest, eh->h_source, ETH_ALEN); - memcpy(eh->h_source, c->mac, ETH_ALEN); - - if (tap_send(c, eh, len) < 0) - perror("DHCP: send"); + len = offsetof(struct msg, o) + fill(m); + tap_udp4_send(c, c->ip4.gw, 67, c->ip4.addr, 68, m, len); return 1; } -- cgit v1.2.3