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 420895A027D for ; Thu, 29 Feb 2024 09:43:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709196173; bh=O+uXaJ87EiPYIZDmWJP/CwY5S9cNvebC3e8Sg0AwKP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XSSN5M8IdFlpYMOkR3/IX45X8MW++dnPk075dnS//fdk6rULKvkPGtAMh5LADi62I wQb49UlapUyVagAJLt8edZGj9gjHvdcGvM4nZZ5VtvILzcqQ2Bl4rk5UYJT99a4G27 JG/Ncul6f7RG2eggNTj+zh0xzcaIVrQEFn8sI0m0Ec58W3M/vTj16ygz7tHbss7fiO ARQy5R+49aTBmR23srKG7wSm5NnAKXmWoFBgusTFJEMeSZJsUhAVaCKpCPLHjKW/KD wJktxKnqsLTdjgjEGxEnGp0dR9ALyzqDIuasYj6P1qnGFBfbPgEUeQ3L17YWXfeP4T juhkRYfxOk0ow== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Tll992Tbhz4wyp; Thu, 29 Feb 2024 19:42:53 +1100 (AEDT) From: David Gibson To: Stefano Brivio , Laurent Vivier , passt-dev@passt.top Subject: [PATCH 6/6] udp: Clean up UDP checksum generation for inbound IPv6 packets Date: Thu, 29 Feb 2024 19:42:50 +1100 Message-ID: <20240229084250.3202450-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240229084250.3202450-1-david@gibson.dropbear.id.au> References: <20240229084250.3202450-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: RWZNI7UOHA3NBGWE2Z5AHREE7D7DBZEW X-Message-ID-Hash: RWZNI7UOHA3NBGWE2Z5AHREE7D7DBZEW 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: David Gibson 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: Currently we open code the calculation of the UDP checksum, which involves temporarily mangling the IPv6 header to match the UDP checksum pseudo-header. It also assumes that the payload is contiguous with the headers, which is true for now, but we want to change in future. We already have a helper which correcly calculates UDP over IPv6 checksums, which doesn't require temporarily modifying the headers and which handles a non-contiguous payload, so use it. It turns out we were already initializing the IPv6 version, nexthdr and hop_limit fields, even though we overwrote them for each packet here, so we can just leave those in place now. Signed-off-by: David Gibson --- udp.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/udp.c b/udp.c index a0080b1a..ee1481f9 100644 --- a/udp.c +++ b/udp.c @@ -676,13 +676,7 @@ static size_t udp_update_hdr6(const struct ctx *c, struct udp6_l2_buf_t *b, b->uh.source = htons(srcport); b->uh.dest = htons(dstport); b->uh.len = b->ip6h.payload_len; - - b->ip6h.hop_limit = IPPROTO_UDP; - b->ip6h.version = b->ip6h.nexthdr = b->uh.check = 0; - b->uh.check = csum(&b->ip6h, ip_len, 0); - b->ip6h.version = 6; - b->ip6h.nexthdr = IPPROTO_UDP; - b->ip6h.hop_limit = 255; + csum_udp6(&b->uh, src, dst, b->data, datalen); return tap_iov_len(c, &b->taph, ip_len); } -- 2.44.0