From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v2 6/6] udp: Use existing helper for UDP checksum on inbound IPv6 packets
Date: Wed, 6 Mar 2024 16:34:28 +1100 [thread overview]
Message-ID: <20240306053428.1176129-7-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20240306053428.1176129-1-david@gibson.dropbear.id.au>
Currently we open code the calculation of the UDP checksum in
udp_update_hdr6(). We calling a helper to handle the IPv6 pseudo-header,
and preset the checksum field to 0 so an uninitialised value doesn't get
folded in. We already have a helper to do this: csum_udp6() which we use
in some slow paths. Use it here as well.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
udp.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/udp.c b/udp.c
index fe3a6cd8..45b7cc96 100644
--- a/udp.c
+++ b/udp.c
@@ -671,10 +671,7 @@ static size_t udp_update_hdr6(const struct ctx *c, struct udp6_l2_buf_t *b,
b->uh.source = b->s_in6.sin6_port;
b->uh.dest = htons(dstport);
b->uh.len = b->ip6h.payload_len;
- b->uh.check = 0;
- b->uh.check = csum(&b->uh, payload_len,
- proto_ipv6_header_psum(payload_len, IPPROTO_UDP,
- src, dst));
+ csum_udp6(&b->uh, src, dst, b->data, datalen);
return tap_iov_len(c, &b->taph, payload_len + sizeof(b->ip6h));
}
--
@@ -671,10 +671,7 @@ static size_t udp_update_hdr6(const struct ctx *c, struct udp6_l2_buf_t *b,
b->uh.source = b->s_in6.sin6_port;
b->uh.dest = htons(dstport);
b->uh.len = b->ip6h.payload_len;
- b->uh.check = 0;
- b->uh.check = csum(&b->uh, payload_len,
- proto_ipv6_header_psum(payload_len, IPPROTO_UDP,
- src, dst));
+ csum_udp6(&b->uh, src, dst, b->data, datalen);
return tap_iov_len(c, &b->taph, payload_len + sizeof(b->ip6h));
}
--
2.44.0
next prev parent reply other threads:[~2024-03-06 5:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-06 5:34 [PATCH v2 0/6] udp: Small cleanups David Gibson
2024-03-06 5:34 ` [PATCH v2 1/6] udp: Refactor udp_sock[46]_iov_init() David Gibson
2024-03-06 5:34 ` [PATCH v2 2/6] udp: Consistent port variable names in udp_update_hdr[46] David Gibson
2024-03-06 5:34 ` [PATCH v2 3/6] udp: Pass data length explicitly to to udp_update_hdr[46] David Gibson
2024-03-06 5:34 ` [PATCH v2 4/6] udp: Re-order udp_update_hdr[46] for clarity and brevity David Gibson
2024-03-06 5:34 ` [PATCH v2 5/6] udp: Avoid unnecessary pointer in udp_update_hdr4() David Gibson
2024-03-06 5:34 ` David Gibson [this message]
2024-03-13 14:21 ` [PATCH v2 0/6] udp: Small cleanups Stefano Brivio
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=20240306053428.1176129-7-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--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).