ip6_tunnel.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef _NET_IP6_TUNNEL_H
  2. #define _NET_IP6_TUNNEL_H
  3. #include <linux/ipv6.h>
  4. #include <linux/netdevice.h>
  5. #include <linux/if_tunnel.h>
  6. #include <linux/ip6_tunnel.h>
  7. #include <net/ip_tunnels.h>
  8. #include <net/dst_cache.h>
  9. #define IP6TUNNEL_ERR_TIMEO (30*HZ)
  10. /* capable of sending packets */
  11. #define IP6_TNL_F_CAP_XMIT 0x10000
  12. /* capable of receiving packets */
  13. #define IP6_TNL_F_CAP_RCV 0x20000
  14. /* determine capability on a per-packet basis */
  15. #define IP6_TNL_F_CAP_PER_PACKET 0x40000
  16. struct __ip6_tnl_parm {
  17. char name[IFNAMSIZ]; /* name of tunnel device */
  18. int link; /* ifindex of underlying L2 interface */
  19. __u8 proto; /* tunnel protocol */
  20. __u8 encap_limit; /* encapsulation limit for tunnel */
  21. __u8 hop_limit; /* hop limit for tunnel */
  22. __be32 flowinfo; /* traffic class and flowlabel for tunnel */
  23. __u32 flags; /* tunnel flags */
  24. struct in6_addr laddr; /* local tunnel end-point address */
  25. struct in6_addr raddr; /* remote tunnel end-point address */
  26. __be16 i_flags;
  27. __be16 o_flags;
  28. __be32 i_key;
  29. __be32 o_key;
  30. };
  31. /* IPv6 tunnel */
  32. struct ip6_tnl {
  33. struct ip6_tnl __rcu *next; /* next tunnel in list */
  34. struct net_device *dev; /* virtual device associated with tunnel */
  35. struct net *net; /* netns for packet i/o */
  36. struct __ip6_tnl_parm parms; /* tunnel configuration parameters */
  37. struct flowi fl; /* flowi template for xmit */
  38. struct dst_cache dst_cache; /* cached dst */
  39. struct gro_cells gro_cells;
  40. int err_count;
  41. unsigned long err_time;
  42. /* These fields used only by GRE */
  43. __u32 i_seqno; /* The last seen seqno */
  44. __u32 o_seqno; /* The last output seqno */
  45. int hlen; /* tun_hlen + encap_hlen */
  46. int tun_hlen; /* Precalculated header length */
  47. int encap_hlen; /* Encap header length (FOU,GUE) */
  48. struct ip_tunnel_encap encap;
  49. int mlink;
  50. };
  51. struct ip6_tnl_encap_ops {
  52. size_t (*encap_hlen)(struct ip_tunnel_encap *e);
  53. int (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e,
  54. u8 *protocol, struct flowi6 *fl6);
  55. };
  56. extern const struct ip6_tnl_encap_ops __rcu *
  57. ip6tun_encaps[MAX_IPTUN_ENCAP_OPS];
  58. int ip6_tnl_encap_add_ops(const struct ip6_tnl_encap_ops *ops,
  59. unsigned int num);
  60. int ip6_tnl_encap_del_ops(const struct ip6_tnl_encap_ops *ops,
  61. unsigned int num);
  62. int ip6_tnl_encap_setup(struct ip6_tnl *t,
  63. struct ip_tunnel_encap *ipencap);
  64. static inline int ip6_encap_hlen(struct ip_tunnel_encap *e)
  65. {
  66. const struct ip6_tnl_encap_ops *ops;
  67. int hlen = -EINVAL;
  68. if (e->type == TUNNEL_ENCAP_NONE)
  69. return 0;
  70. if (e->type >= MAX_IPTUN_ENCAP_OPS)
  71. return -EINVAL;
  72. rcu_read_lock();
  73. ops = rcu_dereference(ip6tun_encaps[e->type]);
  74. if (likely(ops && ops->encap_hlen))
  75. hlen = ops->encap_hlen(e);
  76. rcu_read_unlock();
  77. return hlen;
  78. }
  79. static inline int ip6_tnl_encap(struct sk_buff *skb, struct ip6_tnl *t,
  80. u8 *protocol, struct flowi6 *fl6)
  81. {
  82. const struct ip6_tnl_encap_ops *ops;
  83. int ret = -EINVAL;
  84. if (t->encap.type == TUNNEL_ENCAP_NONE)
  85. return 0;
  86. if (t->encap.type >= MAX_IPTUN_ENCAP_OPS)
  87. return -EINVAL;
  88. rcu_read_lock();
  89. ops = rcu_dereference(ip6tun_encaps[t->encap.type]);
  90. if (likely(ops && ops->build_header))
  91. ret = ops->build_header(skb, &t->encap, protocol, fl6);
  92. rcu_read_unlock();
  93. return ret;
  94. }
  95. /* Tunnel encapsulation limit destination sub-option */
  96. struct ipv6_tlv_tnl_enc_lim {
  97. __u8 type; /* type-code for option */
  98. __u8 length; /* option length */
  99. __u8 encap_limit; /* tunnel encapsulation limit */
  100. } __packed;
  101. int ip6_tnl_rcv_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
  102. const struct in6_addr *raddr);
  103. int ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
  104. const struct tnl_ptk_info *tpi, struct metadata_dst *tun_dst,
  105. bool log_ecn_error);
  106. int ip6_tnl_xmit_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
  107. const struct in6_addr *raddr);
  108. int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
  109. struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto);
  110. __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw);
  111. __u32 ip6_tnl_get_cap(struct ip6_tnl *t, const struct in6_addr *laddr,
  112. const struct in6_addr *raddr);
  113. struct net *ip6_tnl_get_link_net(const struct net_device *dev);
  114. int ip6_tnl_get_iflink(const struct net_device *dev);
  115. int ip6_tnl_change_mtu(struct net_device *dev, int new_mtu);
  116. #ifdef CONFIG_INET
  117. static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb,
  118. struct net_device *dev)
  119. {
  120. int pkt_len, err;
  121. pkt_len = skb->len - skb_inner_network_offset(skb);
  122. err = ip6_local_out(dev_net(skb_dst(skb)->dev), sk, skb);
  123. if (unlikely(net_xmit_eval(err)))
  124. pkt_len = -1;
  125. iptunnel_xmit_stats(dev, pkt_len);
  126. }
  127. #endif
  128. #endif