datapath: Use alternate name for udp_sock_create() backport
[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(3,20,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 #else
23
24 #include <net/ip_tunnels.h>
25 #include <net/udp.h>
26
27 struct udp_port_cfg {
28         u8                      family;
29
30         /* Used only for kernel-created sockets */
31         union {
32                 struct in_addr          local_ip;
33 #if IS_ENABLED(CONFIG_IPV6)
34                 struct in6_addr         local_ip6;
35 #endif
36         };
37
38         union {
39                 struct in_addr          peer_ip;
40 #if IS_ENABLED(CONFIG_IPV6)
41                 struct in6_addr         peer_ip6;
42 #endif
43         };
44
45         __be16                  local_udp_port;
46         __be16                  peer_udp_port;
47         unsigned int            use_udp_checksums:1,
48                                 use_udp6_tx_checksums:1,
49                                 use_udp6_rx_checksums:1;
50 };
51
52 #define udp_sock_create rpl_udp_sock_create
53 int udp_sock_create(struct net *net, struct udp_port_cfg *cfg,
54                     struct socket **sockp);
55
56 typedef int (*udp_tunnel_encap_rcv_t)(struct sock *sk, struct sk_buff *skb);
57 typedef void (*udp_tunnel_encap_destroy_t)(struct sock *sk);
58
59 struct udp_tunnel_sock_cfg {
60         void *sk_user_data;     /* user data used by encap_rcv call back */
61         /* Used for setting up udp_sock fields, see udp.h for details */
62         __u8  encap_type;
63         udp_tunnel_encap_rcv_t encap_rcv;
64         udp_tunnel_encap_destroy_t encap_destroy;
65 };
66
67 /* Setup the given (UDP) sock to receive UDP encapsulated packets */
68 void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
69                            struct udp_tunnel_sock_cfg *sock_cfg);
70
71 /* Transmit the skb using UDP encapsulation. */
72 int udp_tunnel_xmit_skb(struct rtable *rt, struct sk_buff *skb,
73                         __be32 src, __be32 dst, __u8 tos, __u8 ttl,
74                         __be16 df, __be16 src_port, __be16 dst_port,
75                         bool xnet, bool nocheck);
76
77
78 void udp_tunnel_sock_release(struct socket *sock);
79
80 void ovs_udp_gso(struct sk_buff *skb);
81 void ovs_udp_csum_gso(struct sk_buff *skb);
82
83 static inline struct sk_buff *udp_tunnel_handle_offloads(struct sk_buff *skb,
84                                                          bool udp_csum,
85                                                          bool is_vxlan)
86 {
87         int type = udp_csum ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL;
88         void (*fix_segment)(struct sk_buff *);
89
90         if (!udp_csum)
91                 fix_segment = ovs_udp_gso;
92         else
93                 fix_segment = ovs_udp_csum_gso;
94
95 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0)
96         if (!is_vxlan)
97                 type = 0;
98 #endif
99
100         return ovs_iptunnel_handle_offloads(skb, udp_csum, type, fix_segment);
101 }
102
103 #define udp_tunnel_encap_enable(sock) udp_encap_enable()
104
105 #endif /* Linux version < 3.20 */
106 #endif