From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 0A66B5A0269 for ; Wed, 19 Oct 2022 02:44:08 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4MsX6S1vv8z4xH3; Wed, 19 Oct 2022 11:44:00 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1666140240; bh=jkHN/8eRU2mGy8+f9ERFnictRXw2Pac5dSYPZdaugJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RMuTaAc6deJCCT0HYayBZLYvM3tT+3Eyr18/k29t2pg1JKXC3gk94ulI530P8ycRq Z/M//ppirKUgWFPPi9Re7nx/v+Retg8koAUidwC+0Pso4wr1emqwCCQoT+WziG4Y4Q w8DerozHzIoKAAFQf6Z+VJJksMuhuqdSH9UakQZ8= From: David Gibson To: Stefano Brivio Subject: [PATCH v2 14/14] dhcp: Use tap_udp4_send() helper in dhcp() Date: Wed, 19 Oct 2022 11:43:57 +1100 Message-Id: <20221019004357.1454325-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221019004357.1454325-1-david@gibson.dropbear.id.au> References: <20221019004357.1454325-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: M7KGPFVUNJJREJSUUDJ4PMOT27OD2U4F X-Message-ID-Hash: M7KGPFVUNJJREJSUUDJ4PMOT27OD2U4F 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, David Gibson X-Mailman-Version: 3.3.3 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: 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 --- dhcp.c | 18 ++---------------- tap.c | 1 - 2 files changed, 2 insertions(+), 17 deletions(-) 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; } diff --git a/tap.c b/tap.c index d250a0b..3f78c99 100644 --- a/tap.c +++ b/tap.c @@ -170,7 +170,6 @@ static void *tap_push_ip4h(char *buf, in_addr_t src, in_addr_t dst, * @in: UDP payload contents (not including UDP header) * @len: UDP payload length (not including UDP header) */ -/* cppcheck-suppress unusedFunction */ void tap_udp4_send(const struct ctx *c, in_addr_t src, in_port_t sport, in_addr_t dst, in_port_t dport, const void *in, size_t len) -- 2.37.3