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 <david(a)gibson.dropbear.id.au> --- 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