gre.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. static inline struct sk_buff *gre_handle_offloads(struct sk_buff *skb,
  33. bool gre_csum)
  34. {
  35. return iptunnel_handle_offloads(skb, gre_csum, SKB_GSO_GRE);
  36. }
  37. static inline int ip_gre_calc_hlen(__be16 o_flags)
  38. {
  39. int addend = 4;
  40. if (o_flags&TUNNEL_CSUM)
  41. addend += 4;
  42. if (o_flags&TUNNEL_KEY)
  43. addend += 4;
  44. if (o_flags&TUNNEL_SEQ)
  45. addend += 4;
  46. return addend;
  47. }
  48. static inline __be16 gre_flags_to_tnl_flags(__be16 flags)
  49. {
  50. __be16 tflags = 0;
  51. if (flags & GRE_CSUM)
  52. tflags |= TUNNEL_CSUM;
  53. if (flags & GRE_ROUTING)
  54. tflags |= TUNNEL_ROUTING;
  55. if (flags & GRE_KEY)
  56. tflags |= TUNNEL_KEY;
  57. if (flags & GRE_SEQ)
  58. tflags |= TUNNEL_SEQ;
  59. if (flags & GRE_STRICT)
  60. tflags |= TUNNEL_STRICT;
  61. if (flags & GRE_REC)
  62. tflags |= TUNNEL_REC;
  63. if (flags & GRE_VERSION)
  64. tflags |= TUNNEL_VERSION;
  65. return tflags;
  66. }
  67. static inline __be16 tnl_flags_to_gre_flags(__be16 tflags)
  68. {
  69. __be16 flags = 0;
  70. if (tflags & TUNNEL_CSUM)
  71. flags |= GRE_CSUM;
  72. if (tflags & TUNNEL_ROUTING)
  73. flags |= GRE_ROUTING;
  74. if (tflags & TUNNEL_KEY)
  75. flags |= GRE_KEY;
  76. if (tflags & TUNNEL_SEQ)
  77. flags |= GRE_SEQ;
  78. if (tflags & TUNNEL_STRICT)
  79. flags |= GRE_STRICT;
  80. if (tflags & TUNNEL_REC)
  81. flags |= GRE_REC;
  82. if (tflags & TUNNEL_VERSION)
  83. flags |= GRE_VERSION;
  84. return flags;
  85. }
  86. #endif