From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>,
Laurent Vivier <lvivier@redhat.com>,
passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 6/6] udp: Clean up UDP checksum generation for inbound IPv6 packets
Date: Thu, 29 Feb 2024 19:42:50 +1100 [thread overview]
Message-ID: <20240229084250.3202450-7-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20240229084250.3202450-1-david@gibson.dropbear.id.au>
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@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);
}
--
@@ -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
prev parent reply other threads:[~2024-02-29 8:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 8:42 [PATCH 0/6] udp: Small cleanups David Gibson
2024-02-29 8:42 ` [PATCH 1/6] udp: Refactor udp_sock[46]_iov_init() David Gibson
2024-02-29 8:42 ` [PATCH 2/6] udp: Tweak interface to udp_update_hdr[46] David Gibson
2024-02-29 8:42 ` [PATCH 3/6] udp: Clarify setting of addresses inin udp_update_hdr[46]() David Gibson
2024-02-29 8:42 ` [PATCH 4/6] udp: Consistent port variable names in udp_update_hdr[46] David Gibson
2024-02-29 8:42 ` [PATCH 5/6] udp: Avoid unnecessary pointer in udp_update_hdr4() David Gibson
2024-02-29 8:42 ` David Gibson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240229084250.3202450-7-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).