ipip.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef __NET_IPIP_H
  2. #define __NET_IPIP_H 1
  3. #include <linux/if_tunnel.h>
  4. #include <net/gro_cells.h>
  5. #include <net/ip.h>
  6. /* Keep error state on tunnel for 30 sec */
  7. #define IPTUNNEL_ERR_TIMEO (30*HZ)
  8. /* 6rd prefix/relay information */
  9. struct ip_tunnel_6rd_parm {
  10. struct in6_addr prefix;
  11. __be32 relay_prefix;
  12. u16 prefixlen;
  13. u16 relay_prefixlen;
  14. };
  15. struct ip_tunnel {
  16. struct ip_tunnel __rcu *next;
  17. struct net_device *dev;
  18. int err_count; /* Number of arrived ICMP errors */
  19. unsigned long err_time; /* Time when the last ICMP error arrived */
  20. /* These four fields used only by GRE */
  21. __u32 i_seqno; /* The last seen seqno */
  22. __u32 o_seqno; /* The last output seqno */
  23. int hlen; /* Precalculated GRE header length */
  24. int mlink;
  25. struct ip_tunnel_parm parms;
  26. /* for SIT */
  27. #ifdef CONFIG_IPV6_SIT_6RD
  28. struct ip_tunnel_6rd_parm ip6rd;
  29. #endif
  30. struct ip_tunnel_prl_entry __rcu *prl; /* potential router list */
  31. unsigned int prl_count; /* # of entries in PRL */
  32. struct gro_cells gro_cells;
  33. };
  34. struct ip_tunnel_prl_entry {
  35. struct ip_tunnel_prl_entry __rcu *next;
  36. __be32 addr;
  37. u16 flags;
  38. struct rcu_head rcu_head;
  39. };
  40. static inline void iptunnel_xmit(struct sk_buff *skb, struct net_device *dev)
  41. {
  42. int err;
  43. struct iphdr *iph = ip_hdr(skb);
  44. int pkt_len = skb->len - skb_transport_offset(skb);
  45. struct pcpu_tstats *tstats = this_cpu_ptr(dev->tstats);
  46. nf_reset(skb);
  47. skb->ip_summed = CHECKSUM_NONE;
  48. ip_select_ident(iph, skb_dst(skb), NULL);
  49. err = ip_local_out(skb);
  50. if (likely(net_xmit_eval(err) == 0)) {
  51. u64_stats_update_begin(&tstats->syncp);
  52. tstats->tx_bytes += pkt_len;
  53. tstats->tx_packets++;
  54. u64_stats_update_end(&tstats->syncp);
  55. } else {
  56. dev->stats.tx_errors++;
  57. dev->stats.tx_aborted_errors++;
  58. }
  59. }
  60. static inline void tunnel_ip_select_ident(struct sk_buff *skb,
  61. const struct iphdr *old_iph,
  62. struct dst_entry *dst)
  63. {
  64. struct iphdr *iph = ip_hdr(skb);
  65. /* Use inner packet iph-id if possible. */
  66. if (skb->protocol == htons(ETH_P_IP) && old_iph->id)
  67. iph->id = old_iph->id;
  68. else
  69. __ip_select_ident(iph, dst,
  70. (skb_shinfo(skb)->gso_segs ?: 1) - 1);
  71. }
  72. #endif