blob: fd19625ff99db290fd289b3caf18f32c9b72ffc3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __NET_IPIP_H
2#define __NET_IPIP_H 1
3
4#include <linux/if_tunnel.h>
Eric Dumazet60769a52012-09-27 02:48:50 +00005#include <net/gro_cells.h>
Herbert Xuc439cb22008-01-11 19:14:00 -08006#include <net/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8/* Keep error state on tunnel for 30 sec */
9#define IPTUNNEL_ERR_TIMEO (30*HZ)
10
YOSHIFUJI Hideaki / 吉藤英明fa857af2009-09-22 23:43:14 +000011/* 6rd prefix/relay information */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000012struct ip_tunnel_6rd_parm {
YOSHIFUJI Hideaki / 吉藤英明fa857af2009-09-22 23:43:14 +000013 struct in6_addr prefix;
14 __be32 relay_prefix;
15 u16 prefixlen;
16 u16 relay_prefixlen;
17};
18
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000019struct ip_tunnel {
Eric Dumazet6f0bcf12010-10-24 21:33:16 +000020 struct ip_tunnel __rcu *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 int err_count; /* Number of arrived ICMP errors */
24 unsigned long err_time; /* Time when the last ICMP error arrived */
25
26 /* These four fields used only by GRE */
27 __u32 i_seqno; /* The last seen seqno */
28 __u32 o_seqno; /* The last output seqno */
29 int hlen; /* Precalculated GRE header length */
30 int mlink;
31
32 struct ip_tunnel_parm parms;
YOSHIFUJI Hideaki300aaee2008-03-24 18:28:39 +090033
YOSHIFUJI Hideaki / 吉藤英明fa857af2009-09-22 23:43:14 +000034 /* for SIT */
35#ifdef CONFIG_IPV6_SIT_6RD
36 struct ip_tunnel_6rd_parm ip6rd;
37#endif
Eric Dumazetb33eab02010-10-25 21:01:26 +000038 struct ip_tunnel_prl_entry __rcu *prl; /* potential router list */
YOSHIFUJI Hideaki300aaee2008-03-24 18:28:39 +090039 unsigned int prl_count; /* # of entries in PRL */
Eric Dumazet60769a52012-09-27 02:48:50 +000040
41 struct gro_cells gro_cells;
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -040042};
43
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000044struct ip_tunnel_prl_entry {
Eric Dumazetb33eab02010-10-25 21:01:26 +000045 struct ip_tunnel_prl_entry __rcu *next;
YOSHIFUJI Hideaki300aaee2008-03-24 18:28:39 +090046 __be32 addr;
47 u16 flags;
Eric Dumazetef9a9d12009-10-23 17:51:26 +000048 struct rcu_head rcu_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049};
50
Amerigo Wangaa0010f2012-11-11 21:52:33 +000051static inline void iptunnel_xmit(struct sk_buff *skb, struct net_device *dev)
52{
53 int err;
54 struct iphdr *iph = ip_hdr(skb);
55 int pkt_len = skb->len - skb_transport_offset(skb);
56 struct pcpu_tstats *tstats = this_cpu_ptr(dev->tstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Amerigo Wangaa0010f2012-11-11 21:52:33 +000058 nf_reset(skb);
59 skb->ip_summed = CHECKSUM_NONE;
60 ip_select_ident(iph, skb_dst(skb), NULL);
61
62 err = ip_local_out(skb);
63 if (likely(net_xmit_eval(err) == 0)) {
64 u64_stats_update_begin(&tstats->syncp);
65 tstats->tx_bytes += pkt_len;
66 tstats->tx_packets++;
67 u64_stats_update_end(&tstats->syncp);
68 } else {
69 dev->stats.tx_errors++;
70 dev->stats.tx_aborted_errors++;
71 }
72}
Eric Dumazet290b8952010-09-27 00:33:35 +000073
Pravin B Shelar490ab082013-02-22 07:30:30 +000074static inline void tunnel_ip_select_ident(struct sk_buff *skb,
75 const struct iphdr *old_iph,
76 struct dst_entry *dst)
77{
78 struct iphdr *iph = ip_hdr(skb);
79
80 if (iph->frag_off & htons(IP_DF))
81 iph->id = 0;
82 else {
83 /* Use inner packet iph-id if possible. */
84 if (skb->protocol == htons(ETH_P_IP) && old_iph->id)
85 iph->id = old_iph->id;
86 else
87 __ip_select_ident(iph, dst,
88 (skb_shinfo(skb)->gso_segs ?: 1) - 1);
89 }
90}
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#endif