3c69e38e8f0494137fd3f0a11ec57433978936ab
[cascardo/ovs.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         int (*err_handler)(struct sk_buff *skb, u32 info,
21                            const struct tnl_ptk_info *tpi);
22         u8 priority;
23 };
24
25 #define gre_cisco_register rpl_gre_cisco_register
26 int gre_cisco_register(struct gre_cisco_protocol *proto);
27
28 #define gre_cisco_unregister rpl_gre_cisco_unregister
29 int gre_cisco_unregister(struct gre_cisco_protocol *proto);
30
31 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
32 struct gre_base_hdr {
33         __be16 flags;
34         __be16 protocol;
35 };
36 #define GRE_HEADER_SECTION 4
37
38 static inline __be16 gre_flags_to_tnl_flags(__be16 flags)
39 {
40         __be16 tflags = 0;
41
42         if (flags & GRE_CSUM)
43                 tflags |= TUNNEL_CSUM;
44         if (flags & GRE_ROUTING)
45                 tflags |= TUNNEL_ROUTING;
46         if (flags & GRE_KEY)
47                 tflags |= TUNNEL_KEY;
48         if (flags & GRE_SEQ)
49                 tflags |= TUNNEL_SEQ;
50         if (flags & GRE_STRICT)
51                 tflags |= TUNNEL_STRICT;
52         if (flags & GRE_REC)
53                 tflags |= TUNNEL_REC;
54         if (flags & GRE_VERSION)
55                 tflags |= TUNNEL_VERSION;
56
57         return tflags;
58 }
59
60 static inline __be16 tnl_flags_to_gre_flags(__be16 tflags)
61 {
62         __be16 flags = 0;
63
64         if (tflags & TUNNEL_CSUM)
65                 flags |= GRE_CSUM;
66         if (tflags & TUNNEL_ROUTING)
67                 flags |= GRE_ROUTING;
68         if (tflags & TUNNEL_KEY)
69                 flags |= GRE_KEY;
70         if (tflags & TUNNEL_SEQ)
71                 flags |= GRE_SEQ;
72         if (tflags & TUNNEL_STRICT)
73                 flags |= GRE_STRICT;
74         if (tflags & TUNNEL_REC)
75                 flags |= GRE_REC;
76         if (tflags & TUNNEL_VERSION)
77                 flags |= GRE_VERSION;
78
79         return flags;
80 }
81 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */
82 #endif /* HAVE_GRE_CISCO_REGISTER */
83
84 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,12,0)
85
86 #define gre_build_header rpl_gre_build_header
87 void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
88                       int hdr_len);
89
90 #define gre_handle_offloads rpl_gre_handle_offloads
91 struct sk_buff *gre_handle_offloads(struct sk_buff *skb, bool gre_csum);
92
93 #define ip_gre_calc_hlen rpl_ip_gre_calc_hlen
94 static inline int ip_gre_calc_hlen(__be16 o_flags)
95 {
96         int addend = 4;
97
98         if (o_flags & TUNNEL_CSUM)
99                 addend += 4;
100         if (o_flags & TUNNEL_KEY)
101                 addend += 4;
102         if (o_flags & TUNNEL_SEQ)
103                 addend += 4;
104         return addend;
105 }
106 #else
107 static inline struct sk_buff *rpl_gre_handle_offloads(struct sk_buff *skb,
108                                                   bool gre_csum)
109 {
110         if (skb->encapsulation && skb_is_gso(skb)) {
111                 kfree_skb(skb);
112                 return ERR_PTR(-ENOSYS);
113         }
114         return gre_handle_offloads(skb, gre_csum);
115 }
116 #define gre_handle_offloads rpl_gre_handle_offloads
117 #endif
118
119 #endif