gre.h 2.2 KB

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