|
12 | 12 | #include <net/udp.h> |
13 | 13 | #include <net/protocol.h> |
14 | 14 | #include <net/inet_common.h> |
| 15 | +#include <net/udp_tunnel.h> |
| 16 | + |
| 17 | +#if IS_ENABLED(CONFIG_NET_UDP_TUNNEL) |
| 18 | +static DEFINE_SPINLOCK(udp_tunnel_gro_lock); |
| 19 | + |
| 20 | +void udp_tunnel_update_gro_lookup(struct net *net, struct sock *sk, bool add) |
| 21 | +{ |
| 22 | + bool is_ipv6 = sk->sk_family == AF_INET6; |
| 23 | + struct udp_sock *tup, *up = udp_sk(sk); |
| 24 | + struct udp_tunnel_gro *udp_tunnel_gro; |
| 25 | + |
| 26 | + spin_lock(&udp_tunnel_gro_lock); |
| 27 | + udp_tunnel_gro = &net->ipv4.udp_tunnel_gro[is_ipv6]; |
| 28 | + if (add) |
| 29 | + hlist_add_head(&up->tunnel_list, &udp_tunnel_gro->list); |
| 30 | + else if (up->tunnel_list.pprev) |
| 31 | + hlist_del_init(&up->tunnel_list); |
| 32 | + |
| 33 | + if (udp_tunnel_gro->list.first && |
| 34 | + !udp_tunnel_gro->list.first->next) { |
| 35 | + tup = hlist_entry(udp_tunnel_gro->list.first, struct udp_sock, |
| 36 | + tunnel_list); |
| 37 | + |
| 38 | + rcu_assign_pointer(udp_tunnel_gro->sk, (struct sock *)tup); |
| 39 | + } else { |
| 40 | + RCU_INIT_POINTER(udp_tunnel_gro->sk, NULL); |
| 41 | + } |
| 42 | + |
| 43 | + spin_unlock(&udp_tunnel_gro_lock); |
| 44 | +} |
| 45 | +EXPORT_SYMBOL_GPL(udp_tunnel_update_gro_lookup); |
| 46 | +#endif |
15 | 47 |
|
16 | 48 | static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, |
17 | 49 | netdev_features_t features, |
@@ -635,8 +667,13 @@ static struct sock *udp4_gro_lookup_skb(struct sk_buff *skb, __be16 sport, |
635 | 667 | { |
636 | 668 | const struct iphdr *iph = skb_gro_network_header(skb); |
637 | 669 | struct net *net = dev_net_rcu(skb->dev); |
| 670 | + struct sock *sk; |
638 | 671 | int iif, sdif; |
639 | 672 |
|
| 673 | + sk = udp_tunnel_sk(net, false); |
| 674 | + if (sk && dport == htons(sk->sk_num)) |
| 675 | + return sk; |
| 676 | + |
640 | 677 | inet_get_iif_sdif(skb, &iif, &sdif); |
641 | 678 |
|
642 | 679 | return __udp4_lib_lookup(net, iph->saddr, sport, |
|
0 commit comments