Skip to content

Commit

Permalink
Merge branch 'net-add-support-for-ip-generic-checksum-offload-for-gre'
Browse files Browse the repository at this point in the history
Xin Long says:

====================
net: add support for ip generic checksum offload for gre

This patchset it to add ip generic csum processing first in
skb_csum_hwoffload_help() in Patch 1/2 and then add csum
offload support for GRE header in Patch 2/2.
====================

Link: https://lore.kernel.org/r/cover.1611825446.git.lucien.xin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jan 30, 2021
2 parents fd3d375 + efa1a65 commit 2d88296
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
19 changes: 7 additions & 12 deletions include/net/gre.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@ static inline __be16 gre_tnl_flags_to_gre_flags(__be16 tflags)
return flags;
}

static inline __sum16 gre_checksum(struct sk_buff *skb)
{
__wsum csum;

if (skb->ip_summed == CHECKSUM_PARTIAL)
csum = lco_csum(skb);
else
csum = skb_checksum(skb, 0, skb->len, 0);
return csum_fold(csum);
}

static inline void gre_build_header(struct sk_buff *skb, int hdr_len,
__be16 flags, __be16 proto,
__be32 key, __be32 seq)
Expand Down Expand Up @@ -146,7 +135,13 @@ static inline void gre_build_header(struct sk_buff *skb, int hdr_len,
!(skb_shinfo(skb)->gso_type &
(SKB_GSO_GRE | SKB_GSO_GRE_CSUM))) {
*ptr = 0;
*(__sum16 *)ptr = gre_checksum(skb);
if (skb->ip_summed == CHECKSUM_PARTIAL) {
*(__sum16 *)ptr = csum_fold(lco_csum(skb));
} else {
skb->ip_summed = CHECKSUM_PARTIAL;
skb->csum_start = skb_transport_header(skb) - skb->head;
skb->csum_offset = sizeof(*greh);
}
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -3621,7 +3621,18 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,
return !!(features & NETIF_F_SCTP_CRC) ? 0 :
skb_crc32c_csum_help(skb);

return !!(features & NETIF_F_CSUM_MASK) ? 0 : skb_checksum_help(skb);
if (features & NETIF_F_HW_CSUM)
return 0;

if (features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) {
switch (skb->csum_offset) {
case offsetof(struct tcphdr, check):
case offsetof(struct udphdr, check):
return 0;
}
}

return skb_checksum_help(skb);
}
EXPORT_SYMBOL(skb_csum_hwoffload_help);

Expand Down
15 changes: 13 additions & 2 deletions net/ipv4/gre_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
netdev_features_t features)
{
int tnl_hlen = skb_inner_mac_header(skb) - skb_transport_header(skb);
bool need_csum, offload_csum, gso_partial, need_ipsec;
struct sk_buff *segs = ERR_PTR(-EINVAL);
u16 mac_offset = skb->mac_header;
__be16 protocol = skb->protocol;
bool need_csum, gso_partial;
u16 mac_len = skb->mac_len;
int gre_offset, outer_hlen;

Expand Down Expand Up @@ -47,6 +47,11 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
if (need_csum)
features &= ~NETIF_F_SCTP_CRC;

need_ipsec = skb_dst(skb) && dst_xfrm(skb_dst(skb));
/* Try to offload checksum if possible */
offload_csum = !!(need_csum && !need_ipsec &&
(skb->dev->features & NETIF_F_HW_CSUM));

/* segment inner packet. */
segs = skb_mac_gso_segment(skb, features);
if (IS_ERR_OR_NULL(segs)) {
Expand Down Expand Up @@ -100,7 +105,13 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
}

*(pcsum + 1) = 0;
*pcsum = gso_make_checksum(skb, 0);
if (skb->encapsulation || !offload_csum) {
*pcsum = gso_make_checksum(skb, 0);
} else {
skb->ip_summed = CHECKSUM_PARTIAL;
skb->csum_start = skb_transport_header(skb) - skb->head;
skb->csum_offset = sizeof(*greh);
}
} while ((skb = skb->next));
out:
return segs;
Expand Down

0 comments on commit 2d88296

Please sign in to comment.