mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-20 18:54:09 +08:00
7a7ffbabf9
VM to VM GSO traffic is broken if it goes through VXLAN or GRE tunnel and the physical NIC on the host supports hardware VXLAN/GRE GSO offload (e.g. bnx2x and next-gen mlx4). Two issues - (VXLAN) VM traffic has SKB_GSO_DODGY and SKB_GSO_UDP_TUNNEL with SKB_GSO_TCP/UDP set depending on the inner protocol. GSO header integrity check fails in udp4_ufo_fragment if inner protocol is TCP. Also gso_segs is calculated incorrectly using skb->len that includes tunnel header. Fix: robust check should only be applied to the inner packet. (VXLAN & GRE) Once GSO header integrity check passes, NULL segs is returned and the original skb is sent to hardware. However the tunnel header is already pulled. Fix: tunnel header needs to be restored so that hardware can perform GSO properly on the original packet. Signed-off-by: Wei-Chun Chao <weichunc@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
103 lines
2.5 KiB
C
103 lines
2.5 KiB
C
/*
|
|
* IPV4 GSO/GRO offload support
|
|
* Linux INET implementation
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*
|
|
* UDPv4 GSO support
|
|
*/
|
|
|
|
#include <linux/skbuff.h>
|
|
#include <net/udp.h>
|
|
#include <net/protocol.h>
|
|
|
|
static int udp4_ufo_send_check(struct sk_buff *skb)
|
|
{
|
|
if (!pskb_may_pull(skb, sizeof(struct udphdr)))
|
|
return -EINVAL;
|
|
|
|
if (likely(!skb->encapsulation)) {
|
|
const struct iphdr *iph;
|
|
struct udphdr *uh;
|
|
|
|
iph = ip_hdr(skb);
|
|
uh = udp_hdr(skb);
|
|
|
|
uh->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, skb->len,
|
|
IPPROTO_UDP, 0);
|
|
skb->csum_start = skb_transport_header(skb) - skb->head;
|
|
skb->csum_offset = offsetof(struct udphdr, check);
|
|
skb->ip_summed = CHECKSUM_PARTIAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb,
|
|
netdev_features_t features)
|
|
{
|
|
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
|
unsigned int mss;
|
|
int offset;
|
|
__wsum csum;
|
|
|
|
if (skb->encapsulation &&
|
|
skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL) {
|
|
segs = skb_udp_tunnel_segment(skb, features);
|
|
goto out;
|
|
}
|
|
|
|
mss = skb_shinfo(skb)->gso_size;
|
|
if (unlikely(skb->len <= mss))
|
|
goto out;
|
|
|
|
if (skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) {
|
|
/* Packet is from an untrusted source, reset gso_segs. */
|
|
int type = skb_shinfo(skb)->gso_type;
|
|
|
|
if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY |
|
|
SKB_GSO_UDP_TUNNEL |
|
|
SKB_GSO_IPIP |
|
|
SKB_GSO_GRE | SKB_GSO_MPLS) ||
|
|
!(type & (SKB_GSO_UDP))))
|
|
goto out;
|
|
|
|
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss);
|
|
|
|
segs = NULL;
|
|
goto out;
|
|
}
|
|
|
|
/* Do software UFO. Complete and fill in the UDP checksum as
|
|
* HW cannot do checksum of UDP packets sent as multiple
|
|
* IP fragments.
|
|
*/
|
|
offset = skb_checksum_start_offset(skb);
|
|
csum = skb_checksum(skb, offset, skb->len - offset, 0);
|
|
offset += skb->csum_offset;
|
|
*(__sum16 *)(skb->data + offset) = csum_fold(csum);
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
/* Fragment the skb. IP headers of the fragments are updated in
|
|
* inet_gso_segment()
|
|
*/
|
|
segs = skb_segment(skb, features);
|
|
out:
|
|
return segs;
|
|
}
|
|
|
|
static const struct net_offload udpv4_offload = {
|
|
.callbacks = {
|
|
.gso_send_check = udp4_ufo_send_check,
|
|
.gso_segment = udp4_ufo_fragment,
|
|
},
|
|
};
|
|
|
|
int __init udpv4_offload_init(void)
|
|
{
|
|
return inet_add_offload(&udpv4_offload, IPPROTO_UDP);
|
|
}
|