datapath: Add support for 4.1 kernel.
[cascardo/ovs.git] / datapath / linux / compat / include / net / udp_tunnel.h
1 #ifndef __NET_UDP_TUNNEL_WRAPPER_H
2 #define __NET_UDP_TUNNEL_WRAPPER_H
3
4 #include <linux/version.h>
5 #include <linux/kconfig.h>
6
7 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0)
8 #include_next <net/udp_tunnel.h>
9
10 static inline struct sk_buff *
11 rpl_udp_tunnel_handle_offloads(struct sk_buff *skb, bool udp_csum,
12                                bool is_vxlan)
13 {
14         if (skb_is_gso(skb) && skb_is_encapsulated(skb)) {
15                 kfree_skb(skb);
16                 return ERR_PTR(-ENOSYS);
17         }
18         return udp_tunnel_handle_offloads(skb, udp_csum);
19 }
20 #define udp_tunnel_handle_offloads rpl_udp_tunnel_handle_offloads
21
22 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,1,0)
23 static inline int rpl_udp_tunnel_xmit_skb(struct rtable *rt,
24                                           struct sock *sk, struct sk_buff *skb,
25                                           __be32 src, __be32 dst, __u8 tos, __u8 ttl,
26                                           __be16 df, __be16 src_port, __be16 dst_port,
27                                           bool xnet, bool nocheck)
28 {
29         return udp_tunnel_xmit_skb(rt, skb, src, dst, tos, ttl, df, src_port,
30                                    dst_port, xnet, nocheck);
31 }
32 #define udp_tunnel_xmit_skb rpl_udp_tunnel_xmit_skb
33 #endif
34 #else
35
36 #include <net/ip_tunnels.h>
37 #include <net/udp.h>
38
39 struct udp_port_cfg {
40         u8                      family;
41
42         /* Used only for kernel-created sockets */
43         union {
44                 struct in_addr          local_ip;
45 #if IS_ENABLED(CONFIG_IPV6)
46                 struct in6_addr         local_ip6;
47 #endif
48         };
49
50         union {
51                 struct in_addr          peer_ip;
52 #if IS_ENABLED(CONFIG_IPV6)
53                 struct in6_addr         peer_ip6;
54 #endif
55         };
56
57         __be16                  local_udp_port;
58         __be16                  peer_udp_port;
59         unsigned int            use_udp_checksums:1,
60                                 use_udp6_tx_checksums:1,
61                                 use_udp6_rx_checksums:1;
62 };
63
64 #define udp_sock_create rpl_udp_sock_create
65 int rpl_udp_sock_create(struct net *net, struct udp_port_cfg *cfg,
66                         struct socket **sockp);
67
68 typedef int (*udp_tunnel_encap_rcv_t)(struct sock *sk, struct sk_buff *skb);
69 typedef void (*udp_tunnel_encap_destroy_t)(struct sock *sk);
70
71 struct udp_tunnel_sock_cfg {
72         void *sk_user_data;     /* user data used by encap_rcv call back */
73         /* Used for setting up udp_sock fields, see udp.h for details */
74         __u8  encap_type;
75         udp_tunnel_encap_rcv_t encap_rcv;
76         udp_tunnel_encap_destroy_t encap_destroy;
77 };
78
79 /* Setup the given (UDP) sock to receive UDP encapsulated packets */
80 #define setup_udp_tunnel_sock rpl_setup_udp_tunnel_sock
81 void rpl_setup_udp_tunnel_sock(struct net *net, struct socket *sock,
82                                struct udp_tunnel_sock_cfg *sock_cfg);
83
84 /* Transmit the skb using UDP encapsulation. */
85 #define udp_tunnel_xmit_skb rpl_udp_tunnel_xmit_skb
86 int rpl_udp_tunnel_xmit_skb(struct rtable *rt,
87                             struct sock *sk, struct sk_buff *skb,
88                             __be32 src, __be32 dst, __u8 tos, __u8 ttl,
89                             __be16 df, __be16 src_port, __be16 dst_port,
90                             bool xnet, bool nocheck);
91
92
93 #define udp_tunnel_sock_release rpl_udp_tunnel_sock_release
94 void rpl_udp_tunnel_sock_release(struct socket *sock);
95
96 void ovs_udp_gso(struct sk_buff *skb);
97 void ovs_udp_csum_gso(struct sk_buff *skb);
98
99 static inline struct sk_buff *udp_tunnel_handle_offloads(struct sk_buff *skb,
100                                                          bool udp_csum,
101                                                          bool is_vxlan)
102 {
103         int type = udp_csum ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL;
104         void (*fix_segment)(struct sk_buff *);
105
106         if (!udp_csum)
107                 fix_segment = ovs_udp_gso;
108         else
109                 fix_segment = ovs_udp_csum_gso;
110
111 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0)
112         if (!is_vxlan)
113                 type = 0;
114 #endif
115
116         return ovs_iptunnel_handle_offloads(skb, udp_csum, type, fix_segment);
117 }
118
119 #define udp_tunnel_encap_enable(sock) udp_encap_enable()
120
121 #endif /* Linux version < 4.0 */
122 #endif