ip6_tunnel.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #define IP6TUNNEL_ERR_TIMEO (30*HZ)
  8. /* capable of sending packets */
  9. #define IP6_TNL_F_CAP_XMIT 0x10000
  10. /* capable of receiving packets */
  11. #define IP6_TNL_F_CAP_RCV 0x20000
  12. /* determine capability on a per-packet basis */
  13. #define IP6_TNL_F_CAP_PER_PACKET 0x40000
  14. struct __ip6_tnl_parm {
  15. char name[IFNAMSIZ]; /* name of tunnel device */
  16. int link; /* ifindex of underlying L2 interface */
  17. __u8 proto; /* tunnel protocol */
  18. __u8 encap_limit; /* encapsulation limit for tunnel */
  19. __u8 hop_limit; /* hop limit for tunnel */
  20. __be32 flowinfo; /* traffic class and flowlabel for tunnel */
  21. __u32 flags; /* tunnel flags */
  22. struct in6_addr laddr; /* local tunnel end-point address */
  23. struct in6_addr raddr; /* remote tunnel end-point address */
  24. __be16 i_flags;
  25. __be16 o_flags;
  26. __be32 i_key;
  27. __be32 o_key;
  28. };
  29. struct ip6_tnl_dst {
  30. seqlock_t lock;
  31. struct dst_entry __rcu *dst;
  32. u32 cookie;
  33. };
  34. /* IPv6 tunnel */
  35. struct ip6_tnl {
  36. struct ip6_tnl __rcu *next; /* next tunnel in list */
  37. struct net_device *dev; /* virtual device associated with tunnel */
  38. struct net *net; /* netns for packet i/o */
  39. struct __ip6_tnl_parm parms; /* tunnel configuration parameters */
  40. struct flowi fl; /* flowi template for xmit */
  41. struct ip6_tnl_dst __percpu *dst_cache; /* cached dst */
  42. int err_count;
  43. unsigned long err_time;
  44. /* These fields used only by GRE */
  45. __u32 i_seqno; /* The last seen seqno */
  46. __u32 o_seqno; /* The last output seqno */
  47. int hlen; /* Precalculated GRE header length */
  48. int mlink;
  49. };
  50. /* Tunnel encapsulation limit destination sub-option */
  51. struct ipv6_tlv_tnl_enc_lim {
  52. __u8 type; /* type-code for option */
  53. __u8 length; /* option length */
  54. __u8 encap_limit; /* tunnel encapsulation limit */
  55. } __packed;
  56. struct dst_entry *ip6_tnl_dst_get(struct ip6_tnl *t);
  57. int ip6_tnl_dst_init(struct ip6_tnl *t);
  58. void ip6_tnl_dst_destroy(struct ip6_tnl *t);
  59. void ip6_tnl_dst_reset(struct ip6_tnl *t);
  60. void ip6_tnl_dst_set(struct ip6_tnl *t, struct dst_entry *dst);
  61. int ip6_tnl_rcv_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
  62. const struct in6_addr *raddr);
  63. int ip6_tnl_xmit_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
  64. const struct in6_addr *raddr);
  65. __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw);
  66. __u32 ip6_tnl_get_cap(struct ip6_tnl *t, const struct in6_addr *laddr,
  67. const struct in6_addr *raddr);
  68. struct net *ip6_tnl_get_link_net(const struct net_device *dev);
  69. int ip6_tnl_get_iflink(const struct net_device *dev);
  70. static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb,
  71. struct net_device *dev)
  72. {
  73. struct net_device_stats *stats = &dev->stats;
  74. int pkt_len, err;
  75. pkt_len = skb->len - skb_inner_network_offset(skb);
  76. err = ip6_local_out_sk(sk, skb);
  77. if (net_xmit_eval(err) == 0) {
  78. struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
  79. u64_stats_update_begin(&tstats->syncp);
  80. tstats->tx_bytes += pkt_len;
  81. tstats->tx_packets++;
  82. u64_stats_update_end(&tstats->syncp);
  83. } else {
  84. stats->tx_errors++;
  85. stats->tx_aborted_errors++;
  86. }
  87. }
  88. #endif