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