Blame view

include/net/ip_tunnels.h 12.3 KB
c54419321   Pravin B Shelar   GRE: Refactor GRE...
1
2
3
4
5
6
  #ifndef __NET_IP_TUNNELS_H
  #define __NET_IP_TUNNELS_H 1
  
  #include <linux/if_tunnel.h>
  #include <linux/netdevice.h>
  #include <linux/skbuff.h>
7f9562a1f   Jiri Benc   ip_tunnels: recor...
7
  #include <linux/socket.h>
c54419321   Pravin B Shelar   GRE: Refactor GRE...
8
9
  #include <linux/types.h>
  #include <linux/u64_stats_sync.h>
fca5fdf67   Daniel Borkmann   ip_tunnels, bpf: ...
10
  #include <linux/bitops.h>
c54419321   Pravin B Shelar   GRE: Refactor GRE...
11
12
13
  #include <net/dsfield.h>
  #include <net/gro_cells.h>
  #include <net/inet_ecn.h>
563284865   Tom Herbert   net: Changes to i...
14
  #include <net/netns/generic.h>
c54419321   Pravin B Shelar   GRE: Refactor GRE...
15
  #include <net/rtnetlink.h>
3093fbe7f   Thomas Graf   route: Per route ...
16
  #include <net/lwtunnel.h>
e09acddf8   Paolo Abeni   ip_tunnel: replac...
17
  #include <net/dst_cache.h>
c54419321   Pravin B Shelar   GRE: Refactor GRE...
18
19
20
21
22
23
24
25
26
  
  #if IS_ENABLED(CONFIG_IPV6)
  #include <net/ipv6.h>
  #include <net/ip6_fib.h>
  #include <net/ip6_route.h>
  #endif
  
  /* Keep error state on tunnel for 30 sec */
  #define IPTUNNEL_ERR_TIMEO	(30*HZ)
1d8fff907   Thomas Graf   ip_tunnel: Make o...
27
  /* Used to memset ip_tunnel padding. */
376534a3d   Jiri Benc   ip_tunnels: use o...
28
  #define IP_TUNNEL_KEY_SIZE	offsetofend(struct ip_tunnel_key, tp_dst)
1d8fff907   Thomas Graf   ip_tunnel: Make o...
29

c1ea5d672   Jiri Benc   ip_tunnels: add I...
30
31
32
33
34
  /* Used to memset ipv4 address padding. */
  #define IP_TUNNEL_KEY_IPV4_PAD	offsetofend(struct ip_tunnel_key, u.ipv4.dst)
  #define IP_TUNNEL_KEY_IPV4_PAD_LEN				\
  	(FIELD_SIZEOF(struct ip_tunnel_key, u) -		\
  	 FIELD_SIZEOF(struct ip_tunnel_key, u.ipv4))
1d8fff907   Thomas Graf   ip_tunnel: Make o...
35
36
  struct ip_tunnel_key {
  	__be64			tun_id;
c1ea5d672   Jiri Benc   ip_tunnels: add I...
37
38
39
40
41
42
43
44
45
46
  	union {
  		struct {
  			__be32	src;
  			__be32	dst;
  		} ipv4;
  		struct {
  			struct in6_addr src;
  			struct in6_addr dst;
  		} ipv6;
  	} u;
1d8fff907   Thomas Graf   ip_tunnel: Make o...
47
  	__be16			tun_flags;
7c383fb22   Jiri Benc   ip_tunnels: use t...
48
49
  	u8			tos;		/* TOS for IPv4, TC for IPv6 */
  	u8			ttl;		/* TTL for IPv4, HL for IPv6 */
134611446   Daniel Borkmann   ip_tunnel: add su...
50
  	__be32			label;		/* Flow Label for IPv6 */
1d8fff907   Thomas Graf   ip_tunnel: Make o...
51
52
  	__be16			tp_src;
  	__be16			tp_dst;
ac1cf3990   Jiri Benc   ip_tunnels: remov...
53
  };
1d8fff907   Thomas Graf   ip_tunnel: Make o...
54

46fa062ad   Jiri Benc   ip_tunnels: conve...
55
56
  /* Flags for ip_tunnel_info mode. */
  #define IP_TUNNEL_INFO_TX	0x01	/* represents tx tunnel parameters */
7f9562a1f   Jiri Benc   ip_tunnels: recor...
57
  #define IP_TUNNEL_INFO_IPV6	0x02	/* key contains IPv6 addresses */
ee122c79d   Thomas Graf   vxlan: Flow based...
58

fca5fdf67   Daniel Borkmann   ip_tunnels, bpf: ...
59
60
61
62
  /* Maximum tunnel options length. */
  #define IP_TUNNEL_OPTS_MAX					\
  	GENMASK((FIELD_SIZEOF(struct ip_tunnel_info,		\
  			      options_len) * BITS_PER_BYTE) - 1, 0)
1d8fff907   Thomas Graf   ip_tunnel: Make o...
63
64
  struct ip_tunnel_info {
  	struct ip_tunnel_key	key;
d71785ffc   Paolo Abeni   net: add dst_cach...
65
66
67
  #ifdef CONFIG_DST_CACHE
  	struct dst_cache	dst_cache;
  #endif
1d8fff907   Thomas Graf   ip_tunnel: Make o...
68
  	u8			options_len;
ee122c79d   Thomas Graf   vxlan: Flow based...
69
  	u8			mode;
1d8fff907   Thomas Graf   ip_tunnel: Make o...
70
  };
c54419321   Pravin B Shelar   GRE: Refactor GRE...
71
72
73
74
75
76
77
78
79
  /* 6rd prefix/relay information */
  #ifdef CONFIG_IPV6_SIT_6RD
  struct ip_tunnel_6rd_parm {
  	struct in6_addr		prefix;
  	__be32			relay_prefix;
  	u16			prefixlen;
  	u16			relay_prefixlen;
  };
  #endif
563284865   Tom Herbert   net: Changes to i...
80
  struct ip_tunnel_encap {
6b8847c5a   Jiri Benc   ip_tunnels: use u...
81
82
  	u16			type;
  	u16			flags;
563284865   Tom Herbert   net: Changes to i...
83
84
85
  	__be16			sport;
  	__be16			dport;
  };
c54419321   Pravin B Shelar   GRE: Refactor GRE...
86
87
88
89
90
91
  struct ip_tunnel_prl_entry {
  	struct ip_tunnel_prl_entry __rcu *next;
  	__be32				addr;
  	u16				flags;
  	struct rcu_head			rcu_head;
  };
2e15ea390   Pravin B Shelar   ip_gre: Add suppo...
92
  struct metadata_dst;
c54419321   Pravin B Shelar   GRE: Refactor GRE...
93
94
95
96
  struct ip_tunnel {
  	struct ip_tunnel __rcu	*next;
  	struct hlist_node hash_node;
  	struct net_device	*dev;
5e6700b3b   Nicolas Dichtel   sit: add support ...
97
  	struct net		*net;	/* netns for packet i/o */
c54419321   Pravin B Shelar   GRE: Refactor GRE...
98

c54419321   Pravin B Shelar   GRE: Refactor GRE...
99
100
  	unsigned long	err_time;	/* Time when the last ICMP error
  					 * arrived */
f38ba953b   stephen hemminger   gre: eliminate ho...
101
  	int		err_count;	/* Number of arrived ICMP errors */
c54419321   Pravin B Shelar   GRE: Refactor GRE...
102
103
  
  	/* These four fields used only by GRE */
6b8847c5a   Jiri Benc   ip_tunnels: use u...
104
105
  	u32		i_seqno;	/* The last seen seqno	*/
  	u32		o_seqno;	/* The last output seqno */
563284865   Tom Herbert   net: Changes to i...
106
  	int		tun_hlen;	/* Precalculated header length */
c54419321   Pravin B Shelar   GRE: Refactor GRE...
107

e09acddf8   Paolo Abeni   ip_tunnel: replac...
108
  	struct dst_cache dst_cache;
7d442fab0   Tom Herbert   ipv4: Cache dst i...
109

c54419321   Pravin B Shelar   GRE: Refactor GRE...
110
  	struct ip_tunnel_parm parms;
f38ba953b   stephen hemminger   gre: eliminate ho...
111
  	int		mlink;
563284865   Tom Herbert   net: Changes to i...
112
  	int		encap_hlen;	/* Encap header length (FOU,GUE) */
563284865   Tom Herbert   net: Changes to i...
113
  	int		hlen;		/* tun_hlen + encap_hlen */
f38ba953b   stephen hemminger   gre: eliminate ho...
114
  	struct ip_tunnel_encap encap;
563284865   Tom Herbert   net: Changes to i...
115

c54419321   Pravin B Shelar   GRE: Refactor GRE...
116
117
118
119
120
121
122
123
  	/* for SIT */
  #ifdef CONFIG_IPV6_SIT_6RD
  	struct ip_tunnel_6rd_parm ip6rd;
  #endif
  	struct ip_tunnel_prl_entry __rcu *prl;	/* potential router list */
  	unsigned int		prl_count;	/* # of entries in PRL */
  	int			ip_tnl_net_id;
  	struct gro_cells	gro_cells;
2e15ea390   Pravin B Shelar   ip_gre: Add suppo...
124
  	bool			collect_md;
22a59be8b   Philip Prindeville   net: ipv4: Add ab...
125
  	bool			ignore_df;
c54419321   Pravin B Shelar   GRE: Refactor GRE...
126
  };
f57966840   Jesse Gross   openvswitch: Add ...
127
128
129
130
131
132
133
134
  #define TUNNEL_CSUM		__cpu_to_be16(0x01)
  #define TUNNEL_ROUTING		__cpu_to_be16(0x02)
  #define TUNNEL_KEY		__cpu_to_be16(0x04)
  #define TUNNEL_SEQ		__cpu_to_be16(0x08)
  #define TUNNEL_STRICT		__cpu_to_be16(0x10)
  #define TUNNEL_REC		__cpu_to_be16(0x20)
  #define TUNNEL_VERSION		__cpu_to_be16(0x40)
  #define TUNNEL_NO_KEY		__cpu_to_be16(0x80)
9a628224a   Pravin B Shelar   ip_tunnel: Add do...
135
  #define TUNNEL_DONT_FRAGMENT    __cpu_to_be16(0x0100)
f57966840   Jesse Gross   openvswitch: Add ...
136
137
  #define TUNNEL_OAM		__cpu_to_be16(0x0200)
  #define TUNNEL_CRIT_OPT		__cpu_to_be16(0x0400)
1dd144cf5   Thomas Graf   openvswitch: Supp...
138
139
  #define TUNNEL_GENEVE_OPT	__cpu_to_be16(0x0800)
  #define TUNNEL_VXLAN_OPT	__cpu_to_be16(0x1000)
db3c6139e   Daniel Borkmann   bpf, vxlan, genev...
140
  #define TUNNEL_NOCACHE		__cpu_to_be16(0x2000)
1dd144cf5   Thomas Graf   openvswitch: Supp...
141
142
  
  #define TUNNEL_OPTIONS_PRESENT	(TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT)
c54419321   Pravin B Shelar   GRE: Refactor GRE...
143
144
145
146
147
148
  
  struct tnl_ptk_info {
  	__be16 flags;
  	__be16 proto;
  	__be32 key;
  	__be32 seq;
9b8c6d7bf   Eric Dumazet   gre: better suppo...
149
  	int hdr_len;
c54419321   Pravin B Shelar   GRE: Refactor GRE...
150
151
152
153
  };
  
  #define PACKET_RCVD	0
  #define PACKET_REJECT	1
125372faa   Jiri Benc   gre: receive also...
154
  #define PACKET_NEXT	2
c54419321   Pravin B Shelar   GRE: Refactor GRE...
155

6261d983f   stephen hemminger   ip_tunnel: embed ...
156
  #define IP_TNL_HASH_BITS   7
c54419321   Pravin B Shelar   GRE: Refactor GRE...
157
158
159
  #define IP_TNL_HASH_SIZE   (1 << IP_TNL_HASH_BITS)
  
  struct ip_tunnel_net {
c54419321   Pravin B Shelar   GRE: Refactor GRE...
160
  	struct net_device *fb_tunnel_dev;
6261d983f   stephen hemminger   ip_tunnel: embed ...
161
  	struct hlist_head tunnels[IP_TNL_HASH_SIZE];
2e15ea390   Pravin B Shelar   ip_gre: Add suppo...
162
  	struct ip_tunnel __rcu *collect_md_tun;
c54419321   Pravin B Shelar   GRE: Refactor GRE...
163
  };
4c2227984   Pravin B Shelar   ip-tunnel: Use AP...
164
165
  static inline void ip_tunnel_key_init(struct ip_tunnel_key *key,
  				      __be32 saddr, __be32 daddr,
134611446   Daniel Borkmann   ip_tunnel: add su...
166
  				      u8 tos, u8 ttl, __be32 label,
4c2227984   Pravin B Shelar   ip-tunnel: Use AP...
167
168
  				      __be16 tp_src, __be16 tp_dst,
  				      __be64 tun_id, __be16 tun_flags)
1d8fff907   Thomas Graf   ip_tunnel: Make o...
169
  {
4c2227984   Pravin B Shelar   ip-tunnel: Use AP...
170
171
172
173
  	key->tun_id = tun_id;
  	key->u.ipv4.src = saddr;
  	key->u.ipv4.dst = daddr;
  	memset((unsigned char *)key + IP_TUNNEL_KEY_IPV4_PAD,
c1ea5d672   Jiri Benc   ip_tunnels: add I...
174
  	       0, IP_TUNNEL_KEY_IPV4_PAD_LEN);
4c2227984   Pravin B Shelar   ip-tunnel: Use AP...
175
176
  	key->tos = tos;
  	key->ttl = ttl;
134611446   Daniel Borkmann   ip_tunnel: add su...
177
  	key->label = label;
4c2227984   Pravin B Shelar   ip-tunnel: Use AP...
178
  	key->tun_flags = tun_flags;
1d8fff907   Thomas Graf   ip_tunnel: Make o...
179
180
181
182
183
  
  	/* For the tunnel types on the top of IPsec, the tp_src and tp_dst of
  	 * the upper tunnel are used.
  	 * E.g: GRE over IPSEC, the tp_src and tp_port are zero.
  	 */
4c2227984   Pravin B Shelar   ip-tunnel: Use AP...
184
185
  	key->tp_src = tp_src;
  	key->tp_dst = tp_dst;
1d8fff907   Thomas Graf   ip_tunnel: Make o...
186
187
  
  	/* Clear struct padding. */
4c2227984   Pravin B Shelar   ip-tunnel: Use AP...
188
189
190
  	if (sizeof(*key) != IP_TUNNEL_KEY_SIZE)
  		memset((unsigned char *)key + IP_TUNNEL_KEY_SIZE,
  		       0, sizeof(*key) - IP_TUNNEL_KEY_SIZE);
1d8fff907   Thomas Graf   ip_tunnel: Make o...
191
  }
db3c6139e   Daniel Borkmann   bpf, vxlan, genev...
192
193
194
195
196
197
198
199
200
201
202
203
204
  static inline bool
  ip_tunnel_dst_cache_usable(const struct sk_buff *skb,
  			   const struct ip_tunnel_info *info)
  {
  	if (skb->mark)
  		return false;
  	if (!info)
  		return true;
  	if (info->key.tun_flags & TUNNEL_NOCACHE)
  		return false;
  
  	return true;
  }
7f9562a1f   Jiri Benc   ip_tunnels: recor...
205
206
207
208
209
  static inline unsigned short ip_tunnel_info_af(const struct ip_tunnel_info
  					       *tun_info)
  {
  	return tun_info->mode & IP_TUNNEL_INFO_IPV6 ? AF_INET6 : AF_INET;
  }
d817f432c   Amir Vadai   net/ip_tunnels: I...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
  static inline __be64 key32_to_tunnel_id(__be32 key)
  {
  #ifdef __BIG_ENDIAN
  	return (__force __be64)key;
  #else
  	return (__force __be64)((__force u64)key << 32);
  #endif
  }
  
  /* Returns the least-significant 32 bits of a __be64. */
  static inline __be32 tunnel_id_to_key32(__be64 tun_id)
  {
  #ifdef __BIG_ENDIAN
  	return (__force __be32)tun_id;
  #else
  	return (__force __be32)((__force u64)tun_id >> 32);
  #endif
  }
5243b6ac9   Jesse Gross   ip_tunnel: Protec...
228
  #ifdef CONFIG_INET
c54419321   Pravin B Shelar   GRE: Refactor GRE...
229
230
231
  int ip_tunnel_init(struct net_device *dev);
  void ip_tunnel_uninit(struct net_device *dev);
  void  ip_tunnel_dellink(struct net_device *dev, struct list_head *head);
1728d4fab   Nicolas Dichtel   tunnels: advertis...
232
  struct net *ip_tunnel_get_link_net(const struct net_device *dev);
1e99584b9   Nicolas Dichtel   ipip,gre,vti,sit:...
233
  int ip_tunnel_get_iflink(const struct net_device *dev);
d3b6f6141   Eric Dumazet   ip_tunnel: remove...
234
235
  int ip_tunnel_init_net(struct net *net, int ip_tnl_net_id,
  		       struct rtnl_link_ops *ops, char *devname);
c54419321   Pravin B Shelar   GRE: Refactor GRE...
236

6c742e714   Nicolas Dichtel   ipip: add x-netns...
237
  void ip_tunnel_delete_net(struct ip_tunnel_net *itn, struct rtnl_link_ops *ops);
c54419321   Pravin B Shelar   GRE: Refactor GRE...
238
239
  
  void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
bf3d6a8f7   Nicolas Dichtel   iptunnel: specify...
240
  		    const struct iphdr *tnl_params, const u8 protocol);
cfc7381b3   Alexei Starovoitov   ip_tunnel: add co...
241
242
  void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
  		       const u8 proto);
c54419321   Pravin B Shelar   GRE: Refactor GRE...
243
  int ip_tunnel_ioctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd);
7e059158d   David Wragg   vxlan, gre, genev...
244
  int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict);
c54419321   Pravin B Shelar   GRE: Refactor GRE...
245
246
247
248
249
250
251
252
253
254
  int ip_tunnel_change_mtu(struct net_device *dev, int new_mtu);
  
  struct rtnl_link_stats64 *ip_tunnel_get_stats64(struct net_device *dev,
  						struct rtnl_link_stats64 *tot);
  struct ip_tunnel *ip_tunnel_lookup(struct ip_tunnel_net *itn,
  				   int link, __be16 flags,
  				   __be32 remote, __be32 local,
  				   __be32 key);
  
  int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
2e15ea390   Pravin B Shelar   ip_gre: Add suppo...
255
256
  		  const struct tnl_ptk_info *tpi, struct metadata_dst *tun_dst,
  		  bool log_ecn_error);
c54419321   Pravin B Shelar   GRE: Refactor GRE...
257
258
259
260
261
  int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[],
  			 struct ip_tunnel_parm *p);
  int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
  		      struct ip_tunnel_parm *p);
  void ip_tunnel_setup(struct net_device *dev, int net_id);
55c2bc143   Tom Herbert   net: Cleanup enca...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
  
  struct ip_tunnel_encap_ops {
  	size_t (*encap_hlen)(struct ip_tunnel_encap *e);
  	int (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e,
  			    u8 *protocol, struct flowi4 *fl4);
  };
  
  #define MAX_IPTUN_ENCAP_OPS 8
  
  extern const struct ip_tunnel_encap_ops __rcu *
  		iptun_encaps[MAX_IPTUN_ENCAP_OPS];
  
  int ip_tunnel_encap_add_ops(const struct ip_tunnel_encap_ops *op,
  			    unsigned int num);
  int ip_tunnel_encap_del_ops(const struct ip_tunnel_encap_ops *op,
  			    unsigned int num);
563284865   Tom Herbert   net: Changes to i...
278
279
  int ip_tunnel_encap_setup(struct ip_tunnel *t,
  			  struct ip_tunnel_encap *ipencap);
c54419321   Pravin B Shelar   GRE: Refactor GRE...
280

55c2bc143   Tom Herbert   net: Cleanup enca...
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  static inline int ip_encap_hlen(struct ip_tunnel_encap *e)
  {
  	const struct ip_tunnel_encap_ops *ops;
  	int hlen = -EINVAL;
  
  	if (e->type == TUNNEL_ENCAP_NONE)
  		return 0;
  
  	if (e->type >= MAX_IPTUN_ENCAP_OPS)
  		return -EINVAL;
  
  	rcu_read_lock();
  	ops = rcu_dereference(iptun_encaps[e->type]);
  	if (likely(ops && ops->encap_hlen))
  		hlen = ops->encap_hlen(e);
  	rcu_read_unlock();
  
  	return hlen;
  }
  
  static inline int ip_tunnel_encap(struct sk_buff *skb, struct ip_tunnel *t,
  				  u8 *protocol, struct flowi4 *fl4)
  {
  	const struct ip_tunnel_encap_ops *ops;
  	int ret = -EINVAL;
  
  	if (t->encap.type == TUNNEL_ENCAP_NONE)
  		return 0;
  
  	if (t->encap.type >= MAX_IPTUN_ENCAP_OPS)
  		return -EINVAL;
  
  	rcu_read_lock();
  	ops = rcu_dereference(iptun_encaps[t->encap.type]);
  	if (likely(ops && ops->build_header))
  		ret = ops->build_header(skb, &t->encap, protocol, fl4);
  	rcu_read_unlock();
  
  	return ret;
  }
c54419321   Pravin B Shelar   GRE: Refactor GRE...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
  /* Extract dsfield from inner protocol */
  static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph,
  				       const struct sk_buff *skb)
  {
  	if (skb->protocol == htons(ETH_P_IP))
  		return iph->tos;
  	else if (skb->protocol == htons(ETH_P_IPV6))
  		return ipv6_get_dsfield((const struct ipv6hdr *)iph);
  	else
  		return 0;
  }
  
  /* Propogate ECN bits out */
  static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph,
  				     const struct sk_buff *skb)
  {
  	u8 inner = ip_tunnel_get_dsfield(iph, skb);
  
  	return INET_ECN_encapsulate(tos, inner);
  }
a6d5bbf34   Jiri Benc   ip_tunnel: implem...
341
342
343
344
345
346
347
348
  int __iptunnel_pull_header(struct sk_buff *skb, int hdr_len,
  			   __be16 inner_proto, bool raw_proto, bool xnet);
  
  static inline int iptunnel_pull_header(struct sk_buff *skb, int hdr_len,
  				       __be16 inner_proto, bool xnet)
  {
  	return __iptunnel_pull_header(skb, hdr_len, inner_proto, false, xnet);
  }
039f50629   Pravin B Shelar   ip_tunnel: Move s...
349
350
351
  void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
  		   __be32 src, __be32 dst, u8 proto,
  		   u8 tos, u8 ttl, __be16 df, bool xnet);
63d008a4e   Jiri Benc   ipv4: send arp re...
352
353
  struct metadata_dst *iptunnel_metadata_reply(struct metadata_dst *md,
  					     gfp_t flags);
0e6fbc5b6   Pravin B Shelar   ip_tunnels: exten...
354

aed069df0   Alexander Duyck   ip_tunnel_core: i...
355
  int iptunnel_handle_offloads(struct sk_buff *skb, int gso_type_mask);
2d26f0a3c   Eric Dumazet   ipv4: generalize ...
356

a09a4c8dd   Jesse Gross   tunnels: Remove e...
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
  static inline int iptunnel_pull_offloads(struct sk_buff *skb)
  {
  	if (skb_is_gso(skb)) {
  		int err;
  
  		err = skb_unclone(skb, GFP_ATOMIC);
  		if (unlikely(err))
  			return err;
  		skb_shinfo(skb)->gso_type &= ~(NETIF_F_GSO_ENCAP_ALL >>
  					       NETIF_F_GSO_SHIFT);
  	}
  
  	skb->encapsulation = 0;
  	return 0;
  }
039f50629   Pravin B Shelar   ip_tunnel: Move s...
372
  static inline void iptunnel_xmit_stats(struct net_device *dev, int pkt_len)
c54419321   Pravin B Shelar   GRE: Refactor GRE...
373
  {
039f50629   Pravin B Shelar   ip_tunnel: Move s...
374
375
  	if (pkt_len > 0) {
  		struct pcpu_sw_netstats *tstats = get_cpu_ptr(dev->tstats);
c54419321   Pravin B Shelar   GRE: Refactor GRE...
376

c54419321   Pravin B Shelar   GRE: Refactor GRE...
377
  		u64_stats_update_begin(&tstats->syncp);
039f50629   Pravin B Shelar   ip_tunnel: Move s...
378
  		tstats->tx_bytes += pkt_len;
c54419321   Pravin B Shelar   GRE: Refactor GRE...
379
380
  		tstats->tx_packets++;
  		u64_stats_update_end(&tstats->syncp);
b4fe85f9c   Jason A. Donenfeld   ip_tunnel: disabl...
381
  		put_cpu_ptr(tstats);
c54419321   Pravin B Shelar   GRE: Refactor GRE...
382
  	} else {
039f50629   Pravin B Shelar   ip_tunnel: Move s...
383
384
385
386
387
388
389
390
  		struct net_device_stats *err_stats = &dev->stats;
  
  		if (pkt_len < 0) {
  			err_stats->tx_errors++;
  			err_stats->tx_aborted_errors++;
  		} else {
  			err_stats->tx_dropped++;
  		}
c54419321   Pravin B Shelar   GRE: Refactor GRE...
391
392
  	}
  }
5243b6ac9   Jesse Gross   ip_tunnel: Protec...
393

4c2227984   Pravin B Shelar   ip-tunnel: Use AP...
394
  static inline void *ip_tunnel_info_opts(struct ip_tunnel_info *info)
ee122c79d   Thomas Graf   vxlan: Flow based...
395
396
397
  {
  	return info + 1;
  }
4c2227984   Pravin B Shelar   ip-tunnel: Use AP...
398
399
400
401
402
403
404
405
406
407
408
409
  static inline void ip_tunnel_info_opts_get(void *to,
  					   const struct ip_tunnel_info *info)
  {
  	memcpy(to, info + 1, info->options_len);
  }
  
  static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
  					   const void *from, int len)
  {
  	memcpy(ip_tunnel_info_opts(info), from, len);
  	info->options_len = len;
  }
3093fbe7f   Thomas Graf   route: Per route ...
410
411
412
413
  static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
  {
  	return (struct ip_tunnel_info *)lwtstate->data;
  }
e7030878f   Thomas Graf   fib: Add fib rule...
414
415
416
417
418
419
420
  extern struct static_key ip_tunnel_metadata_cnt;
  
  /* Returns > 0 if metadata should be collected */
  static inline int ip_tunnel_collect_metadata(void)
  {
  	return static_key_false(&ip_tunnel_metadata_cnt);
  }
045a0fa0c   Thomas Graf   ip_tunnel: Call i...
421
  void __init ip_tunnel_core_init(void);
e7030878f   Thomas Graf   fib: Add fib rule...
422
423
  void ip_tunnel_need_metadata(void);
  void ip_tunnel_unneed_metadata(void);
052831879   Thomas Graf   ip_tunnel: Provid...
424
425
426
427
428
429
430
431
432
433
434
435
436
437
  #else /* CONFIG_INET */
  
  static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
  {
  	return NULL;
  }
  
  static inline void ip_tunnel_need_metadata(void)
  {
  }
  
  static inline void ip_tunnel_unneed_metadata(void)
  {
  }
e28e87ed4   Daniel Borkmann   ip_tunnel, bpf: i...
438
439
440
441
442
443
444
445
446
447
  static inline void ip_tunnel_info_opts_get(void *to,
  					   const struct ip_tunnel_info *info)
  {
  }
  
  static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
  					   const void *from, int len)
  {
  	info->options_len = 0;
  }
5243b6ac9   Jesse Gross   ip_tunnel: Protec...
448
  #endif /* CONFIG_INET */
c54419321   Pravin B Shelar   GRE: Refactor GRE...
449
  #endif /* __NET_IP_TUNNELS_H */