PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/include/net/ip6_tunnel.h

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