datapath: Add support for Linux 3.12
[sliver-openvswitch.git] / datapath / linux / compat / include / net / gre.h
1 #ifndef __LINUX_GRE_WRAPPER_H
2 #define __LINUX_GRE_WRAPPER_H
3
4 #include <linux/skbuff.h>
5 #include <net/ip_tunnels.h>
6
7 #include <linux/version.h>
8 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) || \
9    defined(HAVE_GRE_CISCO_REGISTER)
10 #include_next <net/gre.h>
11 #endif
12
13 #ifndef HAVE_GRE_CISCO_REGISTER
14
15 /* GRE demux not available, implement our own demux. */
16 #define MAX_GRE_PROTO_PRIORITY 255
17
18 struct gre_cisco_protocol {
19         int (*handler)(struct sk_buff *skb, const struct tnl_ptk_info *tpi);
20         u8 priority;
21 };
22
23 #define gre_cisco_register rpl_gre_cisco_register
24 int gre_cisco_register(struct gre_cisco_protocol *proto);
25
26 #define gre_cisco_unregister rpl_gre_cisco_unregister
27 int gre_cisco_unregister(struct gre_cisco_protocol *proto);
28
29 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
30 struct gre_base_hdr {
31         __be16 flags;
32         __be16 protocol;
33 };
34 #define GRE_HEADER_SECTION 4
35
36 static inline __be16 gre_flags_to_tnl_flags(__be16 flags)
37 {
38         __be16 tflags = 0;
39
40         if (flags & GRE_CSUM)
41                 tflags |= TUNNEL_CSUM;
42         if (flags & GRE_ROUTING)
43                 tflags |= TUNNEL_ROUTING;
44         if (flags & GRE_KEY)
45                 tflags |= TUNNEL_KEY;
46         if (flags & GRE_SEQ)
47                 tflags |= TUNNEL_SEQ;
48         if (flags & GRE_STRICT)
49                 tflags |= TUNNEL_STRICT;
50         if (flags & GRE_REC)
51                 tflags |= TUNNEL_REC;
52         if (flags & GRE_VERSION)
53                 tflags |= TUNNEL_VERSION;
54
55         return tflags;
56 }
57
58 static inline __be16 tnl_flags_to_gre_flags(__be16 tflags)
59 {
60         __be16 flags = 0;
61
62         if (tflags & TUNNEL_CSUM)
63                 flags |= GRE_CSUM;
64         if (tflags & TUNNEL_ROUTING)
65                 flags |= GRE_ROUTING;
66         if (tflags & TUNNEL_KEY)
67                 flags |= GRE_KEY;
68         if (tflags & TUNNEL_SEQ)
69                 flags |= GRE_SEQ;
70         if (tflags & TUNNEL_STRICT)
71                 flags |= GRE_STRICT;
72         if (tflags & TUNNEL_REC)
73                 flags |= GRE_REC;
74         if (tflags & TUNNEL_VERSION)
75                 flags |= GRE_VERSION;
76
77         return flags;
78 }
79 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */
80 #endif /* HAVE_GRE_CISCO_REGISTER */
81
82 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,12,0)
83
84 #define gre_build_header rpl_gre_build_header
85 void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
86                       int hdr_len);
87
88 #define gre_handle_offloads rpl_gre_handle_offloads
89 struct sk_buff *gre_handle_offloads(struct sk_buff *skb, bool gre_csum);
90
91 #define ip_gre_calc_hlen rpl_ip_gre_calc_hlen
92 static inline int ip_gre_calc_hlen(__be16 o_flags)
93 {
94         int addend = 4;
95
96         if (o_flags & TUNNEL_CSUM)
97                 addend += 4;
98         if (o_flags & TUNNEL_KEY)
99                 addend += 4;
100         if (o_flags & TUNNEL_SEQ)
101                 addend += 4;
102         return addend;
103 }
104 #endif
105
106 #endif