2013-06-20 17:11:43 -07:00
|
|
|
#ifndef __LINUX_GRE_WRAPPER_H
|
|
|
|
#define __LINUX_GRE_WRAPPER_H
|
|
|
|
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <net/ip_tunnels.h>
|
|
|
|
|
2014-02-07 10:46:53 -08:00
|
|
|
#include <linux/version.h>
|
2013-12-22 19:43:58 -08:00
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) || \
|
|
|
|
defined(HAVE_GRE_CISCO_REGISTER)
|
2013-06-20 17:11:43 -07:00
|
|
|
#include_next <net/gre.h>
|
2013-12-22 19:43:58 -08:00
|
|
|
#endif
|
2013-06-20 17:11:43 -07:00
|
|
|
|
2013-12-22 19:43:58 -08:00
|
|
|
#ifndef HAVE_GRE_CISCO_REGISTER
|
2013-06-20 17:11:43 -07:00
|
|
|
|
2013-12-22 19:43:58 -08:00
|
|
|
/* GRE demux not available, implement our own demux. */
|
|
|
|
#define MAX_GRE_PROTO_PRIORITY 255
|
2013-06-20 17:11:43 -07:00
|
|
|
|
2013-12-22 19:43:58 -08:00
|
|
|
struct gre_cisco_protocol {
|
|
|
|
int (*handler)(struct sk_buff *skb, const struct tnl_ptk_info *tpi);
|
2014-04-05 16:17:35 -07:00
|
|
|
int (*err_handler)(struct sk_buff *skb, u32 info,
|
|
|
|
const struct tnl_ptk_info *tpi);
|
2013-12-22 19:43:58 -08:00
|
|
|
u8 priority;
|
2013-06-20 17:11:43 -07:00
|
|
|
};
|
|
|
|
|
2013-12-22 19:43:58 -08:00
|
|
|
#define gre_cisco_register rpl_gre_cisco_register
|
2015-04-20 18:19:53 -07:00
|
|
|
int rpl_gre_cisco_register(struct gre_cisco_protocol *proto);
|
2013-06-20 17:11:43 -07:00
|
|
|
|
2013-12-22 19:43:58 -08:00
|
|
|
#define gre_cisco_unregister rpl_gre_cisco_unregister
|
2015-04-20 18:19:53 -07:00
|
|
|
int rpl_gre_cisco_unregister(struct gre_cisco_protocol *proto);
|
2013-06-20 17:11:43 -07:00
|
|
|
|
2013-08-02 11:38:51 -07:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
|
2013-06-20 17:11:43 -07:00
|
|
|
struct gre_base_hdr {
|
|
|
|
__be16 flags;
|
|
|
|
__be16 protocol;
|
|
|
|
};
|
|
|
|
#define GRE_HEADER_SECTION 4
|
|
|
|
|
|
|
|
static inline __be16 gre_flags_to_tnl_flags(__be16 flags)
|
|
|
|
{
|
|
|
|
__be16 tflags = 0;
|
|
|
|
|
|
|
|
if (flags & GRE_CSUM)
|
|
|
|
tflags |= TUNNEL_CSUM;
|
|
|
|
if (flags & GRE_ROUTING)
|
|
|
|
tflags |= TUNNEL_ROUTING;
|
|
|
|
if (flags & GRE_KEY)
|
|
|
|
tflags |= TUNNEL_KEY;
|
|
|
|
if (flags & GRE_SEQ)
|
|
|
|
tflags |= TUNNEL_SEQ;
|
|
|
|
if (flags & GRE_STRICT)
|
|
|
|
tflags |= TUNNEL_STRICT;
|
|
|
|
if (flags & GRE_REC)
|
|
|
|
tflags |= TUNNEL_REC;
|
|
|
|
if (flags & GRE_VERSION)
|
|
|
|
tflags |= TUNNEL_VERSION;
|
|
|
|
|
|
|
|
return tflags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline __be16 tnl_flags_to_gre_flags(__be16 tflags)
|
|
|
|
{
|
|
|
|
__be16 flags = 0;
|
|
|
|
|
|
|
|
if (tflags & TUNNEL_CSUM)
|
|
|
|
flags |= GRE_CSUM;
|
|
|
|
if (tflags & TUNNEL_ROUTING)
|
|
|
|
flags |= GRE_ROUTING;
|
|
|
|
if (tflags & TUNNEL_KEY)
|
|
|
|
flags |= GRE_KEY;
|
|
|
|
if (tflags & TUNNEL_SEQ)
|
|
|
|
flags |= GRE_SEQ;
|
|
|
|
if (tflags & TUNNEL_STRICT)
|
|
|
|
flags |= GRE_STRICT;
|
|
|
|
if (tflags & TUNNEL_REC)
|
|
|
|
flags |= GRE_REC;
|
|
|
|
if (tflags & TUNNEL_VERSION)
|
|
|
|
flags |= GRE_VERSION;
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
2013-08-02 11:38:51 -07:00
|
|
|
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */
|
2013-12-22 19:43:58 -08:00
|
|
|
#endif /* HAVE_GRE_CISCO_REGISTER */
|
2013-11-20 09:50:14 -08:00
|
|
|
|
2015-02-18 14:27:17 -08:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,12,0)
|
2014-02-07 10:46:53 -08:00
|
|
|
|
2013-08-02 11:38:51 -07:00
|
|
|
#define gre_build_header rpl_gre_build_header
|
2015-04-20 18:19:53 -07:00
|
|
|
void rpl_gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
|
|
|
|
int hdr_len);
|
2013-08-02 11:38:51 -07:00
|
|
|
|
|
|
|
#define gre_handle_offloads rpl_gre_handle_offloads
|
2015-04-20 18:19:53 -07:00
|
|
|
struct sk_buff *rpl_gre_handle_offloads(struct sk_buff *skb, bool gre_csum);
|
2013-08-02 11:38:51 -07:00
|
|
|
|
2013-10-14 15:26:40 -07:00
|
|
|
#define ip_gre_calc_hlen rpl_ip_gre_calc_hlen
|
2013-08-02 11:38:51 -07:00
|
|
|
static inline int ip_gre_calc_hlen(__be16 o_flags)
|
|
|
|
{
|
|
|
|
int addend = 4;
|
|
|
|
|
|
|
|
if (o_flags & TUNNEL_CSUM)
|
|
|
|
addend += 4;
|
|
|
|
if (o_flags & TUNNEL_KEY)
|
|
|
|
addend += 4;
|
|
|
|
if (o_flags & TUNNEL_SEQ)
|
|
|
|
addend += 4;
|
|
|
|
return addend;
|
|
|
|
}
|
2014-07-03 11:38:29 -07:00
|
|
|
#else
|
2014-12-19 05:15:16 -08:00
|
|
|
|
2014-07-03 11:38:29 -07:00
|
|
|
static inline struct sk_buff *rpl_gre_handle_offloads(struct sk_buff *skb,
|
|
|
|
bool gre_csum)
|
|
|
|
{
|
2014-12-19 05:15:16 -08:00
|
|
|
if (skb_is_gso(skb) && skb_is_encapsulated(skb)) {
|
2014-07-03 11:38:29 -07:00
|
|
|
kfree_skb(skb);
|
|
|
|
return ERR_PTR(-ENOSYS);
|
|
|
|
}
|
|
|
|
return gre_handle_offloads(skb, gre_csum);
|
|
|
|
}
|
|
|
|
#define gre_handle_offloads rpl_gre_handle_offloads
|
2014-02-07 10:46:53 -08:00
|
|
|
#endif
|
2013-08-02 11:38:51 -07:00
|
|
|
|
2013-06-20 17:11:43 -07:00
|
|
|
#endif
|