gre.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef __LINUX_GRE_H
  2. #define __LINUX_GRE_H
  3. #include <linux/skbuff.h>
  4. #include <net/ip_tunnels.h>
  5. #define GREPROTO_CISCO 0
  6. #define GREPROTO_PPTP 1
  7. #define GREPROTO_MAX 2
  8. #define GRE_IP_PROTO_MAX 2
  9. struct gre_protocol {
  10. int (*handler)(struct sk_buff *skb);
  11. void (*err_handler)(struct sk_buff *skb, u32 info);
  12. };
  13. struct gre_base_hdr {
  14. __be16 flags;
  15. __be16 protocol;
  16. };
  17. #define GRE_HEADER_SECTION 4
  18. int gre_add_protocol(const struct gre_protocol *proto, u8 version);
  19. int gre_del_protocol(const struct gre_protocol *proto, u8 version);
  20. struct gre_cisco_protocol {
  21. int (*handler)(struct sk_buff *skb, const struct tnl_ptk_info *tpi);
  22. int (*err_handler)(struct sk_buff *skb, u32 info,
  23. const struct tnl_ptk_info *tpi);
  24. u8 priority;
  25. };
  26. int gre_cisco_register(struct gre_cisco_protocol *proto);
  27. int gre_cisco_unregister(struct gre_cisco_protocol *proto);
  28. int gre_offload_init(void);
  29. void gre_offload_exit(void);
  30. void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
  31. int hdr_len);
  32. struct sk_buff *gre_handle_offloads(struct sk_buff *skb, bool gre_csum);
  33. static inline int ip_gre_calc_hlen(__be16 o_flags)
  34. {
  35. int addend = 4;
  36. if (o_flags&TUNNEL_CSUM)
  37. addend += 4;
  38. if (o_flags&TUNNEL_KEY)
  39. addend += 4;
  40. if (o_flags&TUNNEL_SEQ)
  41. addend += 4;
  42. return addend;
  43. }
  44. static inline __be16 gre_flags_to_tnl_flags(__be16 flags)
  45. {
  46. __be16 tflags = 0;
  47. if (flags & GRE_CSUM)
  48. tflags |= TUNNEL_CSUM;
  49. if (flags & GRE_ROUTING)
  50. tflags |= TUNNEL_ROUTING;
  51. if (flags & GRE_KEY)
  52. tflags |= TUNNEL_KEY;
  53. if (flags & GRE_SEQ)
  54. tflags |= TUNNEL_SEQ;
  55. if (flags & GRE_STRICT)
  56. tflags |= TUNNEL_STRICT;
  57. if (flags & GRE_REC)
  58. tflags |= TUNNEL_REC;
  59. if (flags & GRE_VERSION)
  60. tflags |= TUNNEL_VERSION;
  61. return tflags;
  62. }
  63. static inline __be16 tnl_flags_to_gre_flags(__be16 tflags)
  64. {
  65. __be16 flags = 0;
  66. if (tflags & TUNNEL_CSUM)
  67. flags |= GRE_CSUM;
  68. if (tflags & TUNNEL_ROUTING)
  69. flags |= GRE_ROUTING;
  70. if (tflags & TUNNEL_KEY)
  71. flags |= GRE_KEY;
  72. if (tflags & TUNNEL_SEQ)
  73. flags |= GRE_SEQ;
  74. if (tflags & TUNNEL_STRICT)
  75. flags |= GRE_STRICT;
  76. if (tflags & TUNNEL_REC)
  77. flags |= GRE_REC;
  78. if (tflags & TUNNEL_VERSION)
  79. flags |= GRE_VERSION;
  80. return flags;
  81. }
  82. #endif