gre.h 2.2 KB

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