From: Edward Cree <ecree@solarflare.com>
To: David Miller <davem@davemloft.net>
Cc: Tom Herbert <tom@herbertland.com>, netdev <netdev@vger.kernel.org>
Subject: [PATCH net-next 1/2] net: udp: local checksum offload for encapsulation
Date: Thu, 17 Dec 2015 15:29:49 +0000 [thread overview]
Message-ID: <5672D4ED.6080705@solarflare.com> (raw)
In-Reply-To: <5672D466.6050900@solarflare.com>
The arithmetic properties of the ones-complement checksum mean that a
correctly checksummed inner packet, including its checksum, has a ones
complement sum depending only on whatever value was used to initialise
the checksum field before checksumming (in the case of TCP and UDP,
this is the ones complement sum of the pseudo header, complemented).
Consequently, if we are going to offload the inner checksum with
CHECKSUM_PARTIAL, we can compute the outer checksum based only on the
packed data not covered by the inner checksum, and the initial value of
the inner checksum field.
Signed-off-by: Edward Cree <ecree@solarflare.com>
---
net/ipv4/udp.c | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 8841e98..3e63c3d 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -767,13 +767,37 @@ void udp_set_csum(bool nocheck, struct sk_buff *skb,
{
struct udphdr *uh = udp_hdr(skb);
- if (nocheck)
+ if (nocheck) {
uh->check = 0;
- else if (skb_is_gso(skb))
+ } else if (skb_is_gso(skb)) {
uh->check = ~udp_v4_check(len, saddr, daddr, 0);
- else if (skb_dst(skb) && skb_dst(skb)->dev &&
- (skb_dst(skb)->dev->features &
- (NETIF_F_IP_CSUM | NETIF_F_HW_CSUM))) {
+ } else if (skb->ip_summed == CHECKSUM_PARTIAL &&
+ skb_dst(skb) && skb_dst(skb)->dev &&
+ (skb_dst(skb)->dev->features &
+ (NETIF_F_IP_CSUM | NETIF_F_HW_CSUM))) {
+ /* Everything from csum_start onwards will be
+ * checksummed and will thus have a sum of whatever
+ * we previously put in the checksum field (eg. sum
+ * of pseudo-header)
+ */
+ __wsum csum;
+
+ /* Fill in our pseudo-header checksum */
+ uh->check = ~udp_v4_check(len, saddr, daddr, 0);
+ /* Start with complement of inner pseudo-header checksum */
+ csum = ~skb_checksum(skb, skb_checksum_start_offset(skb) + skb->csum_offset,
+ 2, 0);
+ /* Add in checksum of our headers (incl. pseudo-header
+ * checksum filled in above)
+ */
+ csum = skb_checksum(skb, 0, skb_checksum_start_offset(skb), csum);
+ /* The result is the outer checksum */
+ uh->check = csum_fold(csum);
+ if (uh->check == 0)
+ uh->check = CSUM_MANGLED_0;
+ } else if (skb_dst(skb) && skb_dst(skb)->dev &&
+ (skb_dst(skb)->dev->features &
+ (NETIF_F_IP_CSUM | NETIF_F_HW_CSUM))) {
BUG_ON(skb->ip_summed == CHECKSUM_PARTIAL);
--
2.4.3
next prev parent reply other threads:[~2015-12-17 15:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-17 15:27 [PATCH net-next 0/2] Local checksum offload for VXLAN Edward Cree
2015-12-17 15:29 ` Edward Cree [this message]
2015-12-17 15:30 ` [PATCH net-next 2/2] net: vxlan: enable local checksum offload on HW_CSUM devices Edward Cree
2015-12-17 18:06 ` [PATCH net-next 0/2] Local checksum offload for VXLAN Tom Herbert
2015-12-18 10:41 ` Edward Cree
2015-12-18 19:41 ` Tom Herbert
2016-01-06 19:23 ` Edward Cree
2015-12-26 4:41 ` David Miller
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=5672D4ED.6080705@solarflare.com \
--to=ecree@solarflare.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=tom@herbertland.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.