Commit 4bcb877d authored by Tom Herbert's avatar Tom Herbert Committed by David S. Miller

udp: Offload outer UDP tunnel csum if available

In __skb_udp_tunnel_segment if outer UDP checksums are enabled and
ip_summed is not already CHECKSUM_PARTIAL, set up checksum offload
if device features allow it.
Signed-off-by: default avatarTom Herbert <therbert@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 63487bab
...@@ -29,7 +29,7 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, ...@@ -29,7 +29,7 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
netdev_features_t features, netdev_features_t features,
struct sk_buff *(*gso_inner_segment)(struct sk_buff *skb, struct sk_buff *(*gso_inner_segment)(struct sk_buff *skb,
netdev_features_t features), netdev_features_t features),
__be16 new_protocol) __be16 new_protocol, bool is_ipv6)
{ {
struct sk_buff *segs = ERR_PTR(-EINVAL); struct sk_buff *segs = ERR_PTR(-EINVAL);
u16 mac_offset = skb->mac_header; u16 mac_offset = skb->mac_header;
...@@ -39,7 +39,9 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, ...@@ -39,7 +39,9 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
netdev_features_t enc_features; netdev_features_t enc_features;
int udp_offset, outer_hlen; int udp_offset, outer_hlen;
unsigned int oldlen; unsigned int oldlen;
bool need_csum; bool need_csum = !!(skb_shinfo(skb)->gso_type &
SKB_GSO_UDP_TUNNEL_CSUM);
bool offload_csum = false, dont_encap = need_csum;
oldlen = (u16)~skb->len; oldlen = (u16)~skb->len;
...@@ -52,10 +54,12 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, ...@@ -52,10 +54,12 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
skb_set_network_header(skb, skb_inner_network_offset(skb)); skb_set_network_header(skb, skb_inner_network_offset(skb));
skb->mac_len = skb_inner_network_offset(skb); skb->mac_len = skb_inner_network_offset(skb);
skb->protocol = new_protocol; skb->protocol = new_protocol;
skb->encap_hdr_csum = need_csum;
need_csum = !!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL_CSUM); /* Try to offload checksum if possible */
if (need_csum) offload_csum = !!(need_csum &&
skb->encap_hdr_csum = 1; (skb->dev->features &
(is_ipv6 ? NETIF_F_V6_CSUM : NETIF_F_V4_CSUM)));
/* segment inner packet. */ /* segment inner packet. */
enc_features = skb->dev->hw_enc_features & features; enc_features = skb->dev->hw_enc_features & features;
...@@ -72,11 +76,21 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, ...@@ -72,11 +76,21 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
do { do {
struct udphdr *uh; struct udphdr *uh;
int len; int len;
__be32 delta;
if (dont_encap) {
skb->encapsulation = 0;
skb->ip_summed = CHECKSUM_NONE;
} else {
/* Only set up inner headers if we might be offloading
* inner checksum.
*/
skb_reset_inner_headers(skb); skb_reset_inner_headers(skb);
skb->encapsulation = 1; skb->encapsulation = 1;
}
skb->mac_len = mac_len; skb->mac_len = mac_len;
skb->protocol = protocol;
skb_push(skb, outer_hlen); skb_push(skb, outer_hlen);
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
...@@ -86,19 +100,25 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, ...@@ -86,19 +100,25 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb,
uh = udp_hdr(skb); uh = udp_hdr(skb);
uh->len = htons(len); uh->len = htons(len);
if (need_csum) { if (!need_csum)
__be32 delta = htonl(oldlen + len); continue;
delta = htonl(oldlen + len);
uh->check = ~csum_fold((__force __wsum) uh->check = ~csum_fold((__force __wsum)
((__force u32)uh->check + ((__force u32)uh->check +
(__force u32)delta)); (__force u32)delta));
if (offload_csum) {
skb->ip_summed = CHECKSUM_PARTIAL;
skb->csum_start = skb_transport_header(skb) - skb->head;
skb->csum_offset = offsetof(struct udphdr, check);
} else {
uh->check = gso_make_checksum(skb, ~uh->check); uh->check = gso_make_checksum(skb, ~uh->check);
if (uh->check == 0) if (uh->check == 0)
uh->check = CSUM_MANGLED_0; uh->check = CSUM_MANGLED_0;
} }
skb->protocol = protocol;
} while ((skb = skb->next)); } while ((skb = skb->next));
out: out:
return segs; return segs;
...@@ -134,7 +154,7 @@ struct sk_buff *skb_udp_tunnel_segment(struct sk_buff *skb, ...@@ -134,7 +154,7 @@ struct sk_buff *skb_udp_tunnel_segment(struct sk_buff *skb,
} }
segs = __skb_udp_tunnel_segment(skb, features, gso_inner_segment, segs = __skb_udp_tunnel_segment(skb, features, gso_inner_segment,
protocol); protocol, is_ipv6);
out_unlock: out_unlock:
rcu_read_unlock(); rcu_read_unlock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment