ip6_tunnel.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. bool collect_md;
  23. __be32 flowinfo; /* traffic class and flowlabel for tunnel */
  24. __u32 flags; /* tunnel flags */
  25. struct in6_addr laddr; /* local tunnel end-point address */
  26. struct in6_addr raddr; /* remote tunnel end-point address */
  27. __be16 i_flags;
  28. __be16 o_flags;
  29. __be32 i_key;
  30. __be32 o_key;
  31. };
  32. /* IPv6 tunnel */
  33. struct ip6_tnl {
  34. struct ip6_tnl __rcu *next; /* next tunnel in list */
  35. struct net_device *dev; /* virtual device associated with tunnel */
  36. struct net *net; /* netns for packet i/o */
  37. struct __ip6_tnl_parm parms; /* tunnel configuration parameters */
  38. struct flowi fl; /* flowi template for xmit */
  39. struct dst_cache dst_cache; /* cached dst */
  40. struct gro_cells gro_cells;
  41. int err_count;
  42. unsigned long err_time;
  43. /* These fields used only by GRE */
  44. __u32 i_seqno; /* The last seen seqno */
  45. __u32 o_seqno; /* The last output seqno */
  46. int hlen; /* tun_hlen + encap_hlen */
  47. int tun_hlen; /* Precalculated header length */
  48. int encap_hlen; /* Encap header length (FOU,GUE) */
  49. struct ip_tunnel_encap encap;
  50. int mlink;
  51. };
  52. struct ip6_tnl_encap_ops {
  53. size_t (*encap_hlen)(struct ip_tunnel_encap *e);
  54. int (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e,
  55. u8 *protocol, struct flowi6 *fl6);
  56. };
  57. #ifdef CONFIG_INET
  58. extern const struct ip6_tnl_encap_ops __rcu *
  59. ip6tun_encaps[MAX_IPTUN_ENCAP_OPS];
  60. int ip6_tnl_encap_add_ops(const struct ip6_tnl_encap_ops *ops,
  61. unsigned int num);
  62. int ip6_tnl_encap_del_ops(const struct ip6_tnl_encap_ops *ops,
  63. unsigned int num);
  64. int ip6_tnl_encap_setup(struct ip6_tnl *t,
  65. struct ip_tunnel_encap *ipencap);
  66. static inline int ip6_encap_hlen(struct ip_tunnel_encap *e)
  67. {
  68. const struct ip6_tnl_encap_ops *ops;
  69. int hlen = -EINVAL;
  70. if (e->type == TUNNEL_ENCAP_NONE)
  71. return 0;
  72. if (e->type >= MAX_IPTUN_ENCAP_OPS)
  73. return -EINVAL;
  74. rcu_read_lock();
  75. ops = rcu_dereference(ip6tun_encaps[e->type]);
  76. if (likely(ops && ops->encap_hlen))
  77. hlen = ops->encap_hlen(e);
  78. rcu_read_unlock();
  79. return hlen;
  80. }
  81. static inline int ip6_tnl_encap(struct sk_buff *skb, struct ip6_tnl *t,
  82. u8 *protocol, struct flowi6 *fl6)
  83. {
  84. const struct ip6_tnl_encap_ops *ops;
  85. int ret = -EINVAL;
  86. if (t->encap.type == TUNNEL_ENCAP_NONE)
  87. return 0;
  88. if (t->encap.type >= MAX_IPTUN_ENCAP_OPS)
  89. return -EINVAL;
  90. rcu_read_lock();
  91. ops = rcu_dereference(ip6tun_encaps[t->encap.type]);
  92. if (likely(ops && ops->build_header))
  93. ret = ops->build_header(skb, &t->encap, protocol, fl6);
  94. rcu_read_unlock();
  95. return ret;
  96. }
  97. /* Tunnel encapsulation limit destination sub-option */
  98. struct ipv6_tlv_tnl_enc_lim {
  99. __u8 type; /* type-code for option */
  100. __u8 length; /* option length */
  101. __u8 encap_limit; /* tunnel encapsulation limit */
  102. } __packed;
  103. int ip6_tnl_rcv_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
  104. const struct in6_addr *raddr);
  105. int ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
  106. const struct tnl_ptk_info *tpi, struct metadata_dst *tun_dst,
  107. bool log_ecn_error);
  108. int ip6_tnl_xmit_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
  109. const struct in6_addr *raddr);
  110. int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
  111. struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto);
  112. __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw);
  113. __u32 ip6_tnl_get_cap(struct ip6_tnl *t, const struct in6_addr *laddr,
  114. const struct in6_addr *raddr);
  115. struct net *ip6_tnl_get_link_net(const struct net_device *dev);
  116. int ip6_tnl_get_iflink(const struct net_device *dev);
  117. int ip6_tnl_change_mtu(struct net_device *dev, int new_mtu);
  118. static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb,
  119. struct net_device *dev)
  120. {
  121. int pkt_len, err;
  122. memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
  123. pkt_len = skb->len - skb_inner_network_offset(skb);
  124. err = ip6_local_out(dev_net(skb_dst(skb)->dev), sk, skb);
  125. if (dev) {
  126. if (unlikely(net_xmit_eval(err)))
  127. pkt_len = -1;
  128. iptunnel_xmit_stats(dev, pkt_len);
  129. }
  130. }
  131. #endif
  132. #endif