xref: /openbmc/linux/include/net/dst.h (revision 6f9c961546699ff8bc5e1c1c52200616867ec68a)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * net/dst.h	Protocol independent destination cache definitions.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #ifndef _NET_DST_H
91da177e4SLinus Torvalds #define _NET_DST_H
101da177e4SLinus Torvalds 
1186393e52SAlexey Dobriyan #include <net/dst_ops.h>
1214c85021SArnaldo Carvalho de Melo #include <linux/netdevice.h>
131da177e4SLinus Torvalds #include <linux/rtnetlink.h>
141da177e4SLinus Torvalds #include <linux/rcupdate.h>
15187f1882SPaul Gortmaker #include <linux/bug.h>
161da177e4SLinus Torvalds #include <linux/jiffies.h>
171da177e4SLinus Torvalds #include <net/neighbour.h>
181da177e4SLinus Torvalds #include <asm/processor.h>
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds #define DST_GC_MIN	(HZ/10)
211da177e4SLinus Torvalds #define DST_GC_INC	(HZ/2)
221da177e4SLinus Torvalds #define DST_GC_MAX	(120*HZ)
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds /* Each dst_entry has reference count and sits in some parent list(s).
251da177e4SLinus Torvalds  * When it is removed from parent list, it is "freed" (dst_free).
261da177e4SLinus Torvalds  * After this it enters dead state (dst->obsolete > 0) and if its refcnt
271da177e4SLinus Torvalds  * is zero, it can be destroyed immediately, otherwise it is added
281da177e4SLinus Torvalds  * to gc list and garbage collector periodically checks the refcnt.
291da177e4SLinus Torvalds  */
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds struct sk_buff;
321da177e4SLinus Torvalds 
33fd2c3ef7SEric Dumazet struct dst_entry {
341e19e02cSEric Dumazet 	struct rcu_head		rcu_head;
351da177e4SLinus Torvalds 	struct dst_entry	*child;
361da177e4SLinus Torvalds 	struct net_device       *dev;
3762fa8a84SDavid S. Miller 	struct  dst_ops	        *ops;
3862fa8a84SDavid S. Miller 	unsigned long		_metrics;
391da177e4SLinus Torvalds 	unsigned long           expires;
40f1dd9c37SZhang Yanmin 	struct dst_entry	*path;
41ecd98837SYOSHIFUJI Hideaki / 吉藤英明 	struct dst_entry	*from;
42def8b4faSAlexey Dobriyan #ifdef CONFIG_XFRM
431da177e4SLinus Torvalds 	struct xfrm_state	*xfrm;
445635c10dSEric Dumazet #else
455635c10dSEric Dumazet 	void			*__pad1;
46def8b4faSAlexey Dobriyan #endif
471da177e4SLinus Torvalds 	int			(*input)(struct sk_buff *);
48aad88724SEric Dumazet 	int			(*output)(struct sock *sk, struct sk_buff *skb);
491da177e4SLinus Torvalds 
505110effeSDavid S. Miller 	unsigned short		flags;
51f6b72b62SDavid S. Miller #define DST_HOST		0x0001
52f6b72b62SDavid S. Miller #define DST_NOXFRM		0x0002
53f6b72b62SDavid S. Miller #define DST_NOPOLICY		0x0004
54f6b72b62SDavid S. Miller #define DST_NOHASH		0x0008
55f6b72b62SDavid S. Miller #define DST_NOCACHE		0x0010
56f6b72b62SDavid S. Miller #define DST_NOCOUNT		0x0020
57e90c1483SHannes Frederic Sowa #define DST_FAKE_RTABLE		0x0040
58e90c1483SHannes Frederic Sowa #define DST_XFRM_TUNNEL		0x0080
59e90c1483SHannes Frederic Sowa #define DST_XFRM_QUEUE		0x0100
60f38a9eb1SThomas Graf #define DST_METADATA		0x0200
61f6b72b62SDavid S. Miller 
625110effeSDavid S. Miller 	unsigned short		pending_confirm;
635110effeSDavid S. Miller 
6462fa8a84SDavid S. Miller 	short			error;
65f5b0a874SDavid S. Miller 
66f5b0a874SDavid S. Miller 	/* A non-zero value of dst->obsolete forces by-hand validation
67f5b0a874SDavid S. Miller 	 * of the route entry.  Positive values are set by the generic
68f5b0a874SDavid S. Miller 	 * dst layer to indicate that the entry has been forcefully
69f5b0a874SDavid S. Miller 	 * destroyed.
70f5b0a874SDavid S. Miller 	 *
71f5b0a874SDavid S. Miller 	 * Negative values are used by the implementation layer code to
72f5b0a874SDavid S. Miller 	 * force invocation of the dst_ops->check() method.
73f5b0a874SDavid S. Miller 	 */
7462fa8a84SDavid S. Miller 	short			obsolete;
75f5b0a874SDavid S. Miller #define DST_OBSOLETE_NONE	0
76f5b0a874SDavid S. Miller #define DST_OBSOLETE_DEAD	2
77f5b0a874SDavid S. Miller #define DST_OBSOLETE_FORCE_CHK	-1
78ceb33206SDavid S. Miller #define DST_OBSOLETE_KILL	-2
7962fa8a84SDavid S. Miller 	unsigned short		header_len;	/* more space at head required */
8062fa8a84SDavid S. Miller 	unsigned short		trailer_len;	/* space to reserve at tail */
81c7066f70SPatrick McHardy #ifdef CONFIG_IP_ROUTE_CLASSID
82f1dd9c37SZhang Yanmin 	__u32			tclassid;
835635c10dSEric Dumazet #else
845635c10dSEric Dumazet 	__u32			__pad2;
85f1dd9c37SZhang Yanmin #endif
86f1dd9c37SZhang Yanmin 
87751a587aSJiri Benc #ifdef CONFIG_64BIT
88751a587aSJiri Benc 	struct lwtunnel_state   *lwtstate;
895635c10dSEric Dumazet 	/*
905635c10dSEric Dumazet 	 * Align __refcnt to a 64 bytes alignment
915635c10dSEric Dumazet 	 * (L1_CACHE_SIZE would be too much)
925635c10dSEric Dumazet 	 */
9361adedf3SJiri Benc 	long			__pad_to_align_refcnt[1];
945635c10dSEric Dumazet #endif
95f1dd9c37SZhang Yanmin 	/*
96f1dd9c37SZhang Yanmin 	 * __refcnt wants to be on a different cache line from
97f1dd9c37SZhang Yanmin 	 * input/output/ops or performance tanks badly
98f1dd9c37SZhang Yanmin 	 */
991e19e02cSEric Dumazet 	atomic_t		__refcnt;	/* client references	*/
1001e19e02cSEric Dumazet 	int			__use;
101f1dd9c37SZhang Yanmin 	unsigned long		lastuse;
102751a587aSJiri Benc #ifndef CONFIG_64BIT
103751a587aSJiri Benc 	struct lwtunnel_state   *lwtstate;
104751a587aSJiri Benc #endif
1051e19e02cSEric Dumazet 	union {
1061e19e02cSEric Dumazet 		struct dst_entry	*next;
1071c31720aSEric Dumazet 		struct rtable __rcu	*rt_next;
1081e19e02cSEric Dumazet 		struct rt6_info		*rt6_next;
109fc766e4cSEric Dumazet 		struct dn_route __rcu	*dn_next;
1101e19e02cSEric Dumazet 	};
1111da177e4SLinus Torvalds };
1121da177e4SLinus Torvalds 
113a4023dd0SJoe Perches u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old);
114a37e6e34SEric Dumazet extern const u32 dst_default_metrics[];
11562fa8a84SDavid S. Miller 
11662fa8a84SDavid S. Miller #define DST_METRICS_READ_ONLY		0x1UL
117e5fd387aSMichal Kubeček #define DST_METRICS_FLAGS		0x3UL
11862fa8a84SDavid S. Miller #define __DST_METRICS_PTR(Y)	\
119e5fd387aSMichal Kubeček 	((u32 *)((Y) & ~DST_METRICS_FLAGS))
12062fa8a84SDavid S. Miller #define DST_METRICS_PTR(X)	__DST_METRICS_PTR((X)->_metrics)
12162fa8a84SDavid S. Miller 
12262fa8a84SDavid S. Miller static inline bool dst_metrics_read_only(const struct dst_entry *dst)
12362fa8a84SDavid S. Miller {
12462fa8a84SDavid S. Miller 	return dst->_metrics & DST_METRICS_READ_ONLY;
12562fa8a84SDavid S. Miller }
12662fa8a84SDavid S. Miller 
127a4023dd0SJoe Perches void __dst_destroy_metrics_generic(struct dst_entry *dst, unsigned long old);
12862fa8a84SDavid S. Miller 
12962fa8a84SDavid S. Miller static inline void dst_destroy_metrics_generic(struct dst_entry *dst)
13062fa8a84SDavid S. Miller {
13162fa8a84SDavid S. Miller 	unsigned long val = dst->_metrics;
13262fa8a84SDavid S. Miller 	if (!(val & DST_METRICS_READ_ONLY))
13362fa8a84SDavid S. Miller 		__dst_destroy_metrics_generic(dst, val);
13462fa8a84SDavid S. Miller }
13562fa8a84SDavid S. Miller 
13662fa8a84SDavid S. Miller static inline u32 *dst_metrics_write_ptr(struct dst_entry *dst)
13762fa8a84SDavid S. Miller {
13862fa8a84SDavid S. Miller 	unsigned long p = dst->_metrics;
13962fa8a84SDavid S. Miller 
1401f37070dSStephen Hemminger 	BUG_ON(!p);
1411f37070dSStephen Hemminger 
14262fa8a84SDavid S. Miller 	if (p & DST_METRICS_READ_ONLY)
14362fa8a84SDavid S. Miller 		return dst->ops->cow_metrics(dst, p);
14462fa8a84SDavid S. Miller 	return __DST_METRICS_PTR(p);
14562fa8a84SDavid S. Miller }
14662fa8a84SDavid S. Miller 
14762fa8a84SDavid S. Miller /* This may only be invoked before the entry has reached global
14862fa8a84SDavid S. Miller  * visibility.
14962fa8a84SDavid S. Miller  */
15062fa8a84SDavid S. Miller static inline void dst_init_metrics(struct dst_entry *dst,
15162fa8a84SDavid S. Miller 				    const u32 *src_metrics,
15262fa8a84SDavid S. Miller 				    bool read_only)
15362fa8a84SDavid S. Miller {
15462fa8a84SDavid S. Miller 	dst->_metrics = ((unsigned long) src_metrics) |
15562fa8a84SDavid S. Miller 		(read_only ? DST_METRICS_READ_ONLY : 0);
15662fa8a84SDavid S. Miller }
15762fa8a84SDavid S. Miller 
15862fa8a84SDavid S. Miller static inline void dst_copy_metrics(struct dst_entry *dest, const struct dst_entry *src)
15962fa8a84SDavid S. Miller {
16062fa8a84SDavid S. Miller 	u32 *dst_metrics = dst_metrics_write_ptr(dest);
16162fa8a84SDavid S. Miller 
16262fa8a84SDavid S. Miller 	if (dst_metrics) {
16362fa8a84SDavid S. Miller 		u32 *src_metrics = DST_METRICS_PTR(src);
16462fa8a84SDavid S. Miller 
16562fa8a84SDavid S. Miller 		memcpy(dst_metrics, src_metrics, RTAX_MAX * sizeof(u32));
16662fa8a84SDavid S. Miller 	}
16762fa8a84SDavid S. Miller }
16862fa8a84SDavid S. Miller 
16962fa8a84SDavid S. Miller static inline u32 *dst_metrics_ptr(struct dst_entry *dst)
17062fa8a84SDavid S. Miller {
17162fa8a84SDavid S. Miller 	return DST_METRICS_PTR(dst);
17262fa8a84SDavid S. Miller }
17362fa8a84SDavid S. Miller 
1741da177e4SLinus Torvalds static inline u32
1755170ae82SDavid S. Miller dst_metric_raw(const struct dst_entry *dst, const int metric)
1761da177e4SLinus Torvalds {
17762fa8a84SDavid S. Miller 	u32 *p = DST_METRICS_PTR(dst);
17862fa8a84SDavid S. Miller 
17962fa8a84SDavid S. Miller 	return p[metric-1];
180defb3519SDavid S. Miller }
181defb3519SDavid S. Miller 
1825170ae82SDavid S. Miller static inline u32
1835170ae82SDavid S. Miller dst_metric(const struct dst_entry *dst, const int metric)
1845170ae82SDavid S. Miller {
1850dbaee3bSDavid S. Miller 	WARN_ON_ONCE(metric == RTAX_HOPLIMIT ||
186d33e4553SDavid S. Miller 		     metric == RTAX_ADVMSS ||
187d33e4553SDavid S. Miller 		     metric == RTAX_MTU);
1885170ae82SDavid S. Miller 	return dst_metric_raw(dst, metric);
1895170ae82SDavid S. Miller }
1905170ae82SDavid S. Miller 
1910dbaee3bSDavid S. Miller static inline u32
1920dbaee3bSDavid S. Miller dst_metric_advmss(const struct dst_entry *dst)
1930dbaee3bSDavid S. Miller {
1940dbaee3bSDavid S. Miller 	u32 advmss = dst_metric_raw(dst, RTAX_ADVMSS);
1950dbaee3bSDavid S. Miller 
1960dbaee3bSDavid S. Miller 	if (!advmss)
1970dbaee3bSDavid S. Miller 		advmss = dst->ops->default_advmss(dst);
1980dbaee3bSDavid S. Miller 
1990dbaee3bSDavid S. Miller 	return advmss;
2000dbaee3bSDavid S. Miller }
2010dbaee3bSDavid S. Miller 
202defb3519SDavid S. Miller static inline void dst_metric_set(struct dst_entry *dst, int metric, u32 val)
203defb3519SDavid S. Miller {
20462fa8a84SDavid S. Miller 	u32 *p = dst_metrics_write_ptr(dst);
205defb3519SDavid S. Miller 
20662fa8a84SDavid S. Miller 	if (p)
20762fa8a84SDavid S. Miller 		p[metric-1] = val;
2081da177e4SLinus Torvalds }
2091da177e4SLinus Torvalds 
210c3a8d947SDaniel Borkmann /* Kernel-internal feature bits that are unallocated in user space. */
211c3a8d947SDaniel Borkmann #define DST_FEATURE_ECN_CA	(1 << 31)
212c3a8d947SDaniel Borkmann 
213c3a8d947SDaniel Borkmann #define DST_FEATURE_MASK	(DST_FEATURE_ECN_CA)
214c3a8d947SDaniel Borkmann #define DST_FEATURE_ECN_MASK	(DST_FEATURE_ECN_CA | RTAX_FEATURE_ECN)
215c3a8d947SDaniel Borkmann 
2160c3adfb8SGilad Ben-Yossef static inline u32
2170c3adfb8SGilad Ben-Yossef dst_feature(const struct dst_entry *dst, u32 feature)
2180c3adfb8SGilad Ben-Yossef {
219bb5b7c11SDavid S. Miller 	return dst_metric(dst, RTAX_FEATURES) & feature;
2200c3adfb8SGilad Ben-Yossef }
2210c3adfb8SGilad Ben-Yossef 
2221da177e4SLinus Torvalds static inline u32 dst_mtu(const struct dst_entry *dst)
2231da177e4SLinus Torvalds {
224618f9bc7SSteffen Klassert 	return dst->ops->mtu(dst);
2251da177e4SLinus Torvalds }
2261da177e4SLinus Torvalds 
227c1e20f7cSStephen Hemminger /* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */
228c1e20f7cSStephen Hemminger static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metric)
229c1e20f7cSStephen Hemminger {
230c1e20f7cSStephen Hemminger 	return msecs_to_jiffies(dst_metric(dst, metric));
231c1e20f7cSStephen Hemminger }
232c1e20f7cSStephen Hemminger 
2331da177e4SLinus Torvalds static inline u32
2341da177e4SLinus Torvalds dst_allfrag(const struct dst_entry *dst)
2351da177e4SLinus Torvalds {
2360c3adfb8SGilad Ben-Yossef 	int ret = dst_feature(dst,  RTAX_FEATURE_ALLFRAG);
2371da177e4SLinus Torvalds 	return ret;
2381da177e4SLinus Torvalds }
2391da177e4SLinus Torvalds 
2401da177e4SLinus Torvalds static inline int
241d33e4553SDavid S. Miller dst_metric_locked(const struct dst_entry *dst, int metric)
2421da177e4SLinus Torvalds {
2431da177e4SLinus Torvalds 	return dst_metric(dst, RTAX_LOCK) & (1<<metric);
2441da177e4SLinus Torvalds }
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds static inline void dst_hold(struct dst_entry *dst)
2471da177e4SLinus Torvalds {
2485635c10dSEric Dumazet 	/*
2495635c10dSEric Dumazet 	 * If your kernel compilation stops here, please check
2505635c10dSEric Dumazet 	 * __pad_to_align_refcnt declaration in struct dst_entry
2515635c10dSEric Dumazet 	 */
2525635c10dSEric Dumazet 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
2531da177e4SLinus Torvalds 	atomic_inc(&dst->__refcnt);
2541da177e4SLinus Torvalds }
2551da177e4SLinus Torvalds 
25603f49f34SPavel Emelyanov static inline void dst_use(struct dst_entry *dst, unsigned long time)
25703f49f34SPavel Emelyanov {
25803f49f34SPavel Emelyanov 	dst_hold(dst);
25903f49f34SPavel Emelyanov 	dst->__use++;
26003f49f34SPavel Emelyanov 	dst->lastuse = time;
26103f49f34SPavel Emelyanov }
26203f49f34SPavel Emelyanov 
2637fee226aSEric Dumazet static inline void dst_use_noref(struct dst_entry *dst, unsigned long time)
2647fee226aSEric Dumazet {
2657fee226aSEric Dumazet 	dst->__use++;
2667fee226aSEric Dumazet 	dst->lastuse = time;
2677fee226aSEric Dumazet }
2687fee226aSEric Dumazet 
2697f95e188SEldad Zack static inline struct dst_entry *dst_clone(struct dst_entry *dst)
2701da177e4SLinus Torvalds {
2711da177e4SLinus Torvalds 	if (dst)
2721da177e4SLinus Torvalds 		atomic_inc(&dst->__refcnt);
2731da177e4SLinus Torvalds 	return dst;
2741da177e4SLinus Torvalds }
2751da177e4SLinus Torvalds 
276a4023dd0SJoe Perches void dst_release(struct dst_entry *dst);
2777fee226aSEric Dumazet 
2787fee226aSEric Dumazet static inline void refdst_drop(unsigned long refdst)
2797fee226aSEric Dumazet {
2807fee226aSEric Dumazet 	if (!(refdst & SKB_DST_NOREF))
2817fee226aSEric Dumazet 		dst_release((struct dst_entry *)(refdst & SKB_DST_PTRMASK));
2827fee226aSEric Dumazet }
2837fee226aSEric Dumazet 
2847fee226aSEric Dumazet /**
2857fee226aSEric Dumazet  * skb_dst_drop - drops skb dst
2867fee226aSEric Dumazet  * @skb: buffer
2877fee226aSEric Dumazet  *
2887fee226aSEric Dumazet  * Drops dst reference count if a reference was taken.
2897fee226aSEric Dumazet  */
290adf30907SEric Dumazet static inline void skb_dst_drop(struct sk_buff *skb)
291adf30907SEric Dumazet {
2927fee226aSEric Dumazet 	if (skb->_skb_refdst) {
2937fee226aSEric Dumazet 		refdst_drop(skb->_skb_refdst);
2947fee226aSEric Dumazet 		skb->_skb_refdst = 0UL;
2957fee226aSEric Dumazet 	}
2967fee226aSEric Dumazet }
2977fee226aSEric Dumazet 
298e79e2595SJoe Stringer static inline void __skb_dst_copy(struct sk_buff *nskb, unsigned long refdst)
2997fee226aSEric Dumazet {
300e79e2595SJoe Stringer 	nskb->_skb_refdst = refdst;
3017fee226aSEric Dumazet 	if (!(nskb->_skb_refdst & SKB_DST_NOREF))
3027fee226aSEric Dumazet 		dst_clone(skb_dst(nskb));
3037fee226aSEric Dumazet }
3047fee226aSEric Dumazet 
305e79e2595SJoe Stringer static inline void skb_dst_copy(struct sk_buff *nskb, const struct sk_buff *oskb)
306e79e2595SJoe Stringer {
307e79e2595SJoe Stringer 	__skb_dst_copy(nskb, oskb->_skb_refdst);
308e79e2595SJoe Stringer }
309e79e2595SJoe Stringer 
3107fee226aSEric Dumazet /**
3117fee226aSEric Dumazet  * skb_dst_force - makes sure skb dst is refcounted
3127fee226aSEric Dumazet  * @skb: buffer
3137fee226aSEric Dumazet  *
3147fee226aSEric Dumazet  * If dst is not yet refcounted, let's do it
3157fee226aSEric Dumazet  */
3167fee226aSEric Dumazet static inline void skb_dst_force(struct sk_buff *skb)
3177fee226aSEric Dumazet {
3187fee226aSEric Dumazet 	if (skb_dst_is_noref(skb)) {
3197fee226aSEric Dumazet 		WARN_ON(!rcu_read_lock_held());
3207fee226aSEric Dumazet 		skb->_skb_refdst &= ~SKB_DST_NOREF;
3217fee226aSEric Dumazet 		dst_clone(skb_dst(skb));
3227fee226aSEric Dumazet 	}
323adf30907SEric Dumazet }
3241da177e4SLinus Torvalds 
325d19d56ddSEric Dumazet 
326d19d56ddSEric Dumazet /**
327290b895eSEric Dumazet  *	__skb_tunnel_rx - prepare skb for rx reinsert
328290b895eSEric Dumazet  *	@skb: buffer
329290b895eSEric Dumazet  *	@dev: tunnel device
330ea23192eSNicolas Dichtel  *	@net: netns for packet i/o
331290b895eSEric Dumazet  *
332290b895eSEric Dumazet  *	After decapsulation, packet is going to re-enter (netif_rx()) our stack,
333290b895eSEric Dumazet  *	so make some cleanups. (no accounting done)
334290b895eSEric Dumazet  */
335ea23192eSNicolas Dichtel static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
336ea23192eSNicolas Dichtel 				   struct net *net)
337290b895eSEric Dumazet {
338290b895eSEric Dumazet 	skb->dev = dev;
339bdeab991STom Herbert 
340bdeab991STom Herbert 	/*
3417539fadcSTom Herbert 	 * Clear hash so that we can recalulate the hash for the
342bdeab991STom Herbert 	 * encapsulated packet, unless we have already determine the hash
343bdeab991STom Herbert 	 * over the L4 4-tuple.
344bdeab991STom Herbert 	 */
3457539fadcSTom Herbert 	skb_clear_hash_if_not_l4(skb);
346290b895eSEric Dumazet 	skb_set_queue_mapping(skb, 0);
347ea23192eSNicolas Dichtel 	skb_scrub_packet(skb, !net_eq(net, dev_net(dev)));
348290b895eSEric Dumazet }
349290b895eSEric Dumazet 
350290b895eSEric Dumazet /**
351d19d56ddSEric Dumazet  *	skb_tunnel_rx - prepare skb for rx reinsert
352d19d56ddSEric Dumazet  *	@skb: buffer
353d19d56ddSEric Dumazet  *	@dev: tunnel device
354d19d56ddSEric Dumazet  *
355d19d56ddSEric Dumazet  *	After decapsulation, packet is going to re-enter (netif_rx()) our stack,
356d19d56ddSEric Dumazet  *	so make some cleanups, and perform accounting.
357290b895eSEric Dumazet  *	Note: this accounting is not SMP safe.
358d19d56ddSEric Dumazet  */
359ea23192eSNicolas Dichtel static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
360ea23192eSNicolas Dichtel 				 struct net *net)
361d19d56ddSEric Dumazet {
362d19d56ddSEric Dumazet 	/* TODO : stats should be SMP safe */
363d19d56ddSEric Dumazet 	dev->stats.rx_packets++;
364d19d56ddSEric Dumazet 	dev->stats.rx_bytes += skb->len;
365ea23192eSNicolas Dichtel 	__skb_tunnel_rx(skb, dev, net);
366d19d56ddSEric Dumazet }
367d19d56ddSEric Dumazet 
368aad88724SEric Dumazet int dst_discard_sk(struct sock *sk, struct sk_buff *skb);
369aad88724SEric Dumazet static inline int dst_discard(struct sk_buff *skb)
370aad88724SEric Dumazet {
371aad88724SEric Dumazet 	return dst_discard_sk(skb->sk, skb);
372aad88724SEric Dumazet }
373a4023dd0SJoe Perches void *dst_alloc(struct dst_ops *ops, struct net_device *dev, int initial_ref,
374a4023dd0SJoe Perches 		int initial_obsolete, unsigned short flags);
375f38a9eb1SThomas Graf void dst_init(struct dst_entry *dst, struct dst_ops *ops,
376f38a9eb1SThomas Graf 	      struct net_device *dev, int initial_ref, int initial_obsolete,
377f38a9eb1SThomas Graf 	      unsigned short flags);
378a4023dd0SJoe Perches void __dst_free(struct dst_entry *dst);
379a4023dd0SJoe Perches struct dst_entry *dst_destroy(struct dst_entry *dst);
3801da177e4SLinus Torvalds 
3811da177e4SLinus Torvalds static inline void dst_free(struct dst_entry *dst)
3821da177e4SLinus Torvalds {
383f5b0a874SDavid S. Miller 	if (dst->obsolete > 0)
3841da177e4SLinus Torvalds 		return;
3851da177e4SLinus Torvalds 	if (!atomic_read(&dst->__refcnt)) {
3861da177e4SLinus Torvalds 		dst = dst_destroy(dst);
3871da177e4SLinus Torvalds 		if (!dst)
3881da177e4SLinus Torvalds 			return;
3891da177e4SLinus Torvalds 	}
3901da177e4SLinus Torvalds 	__dst_free(dst);
3911da177e4SLinus Torvalds }
3921da177e4SLinus Torvalds 
3931da177e4SLinus Torvalds static inline void dst_rcu_free(struct rcu_head *head)
3941da177e4SLinus Torvalds {
3951da177e4SLinus Torvalds 	struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head);
3961da177e4SLinus Torvalds 	dst_free(dst);
3971da177e4SLinus Torvalds }
3981da177e4SLinus Torvalds 
3991da177e4SLinus Torvalds static inline void dst_confirm(struct dst_entry *dst)
4001da177e4SLinus Torvalds {
4015110effeSDavid S. Miller 	dst->pending_confirm = 1;
40269cce1d1SDavid S. Miller }
4035110effeSDavid S. Miller 
4045110effeSDavid S. Miller static inline int dst_neigh_output(struct dst_entry *dst, struct neighbour *n,
4055110effeSDavid S. Miller 				   struct sk_buff *skb)
4065110effeSDavid S. Miller {
407425f09abSEric Dumazet 	const struct hh_cache *hh;
4085110effeSDavid S. Miller 
409425f09abSEric Dumazet 	if (dst->pending_confirm) {
410425f09abSEric Dumazet 		unsigned long now = jiffies;
411425f09abSEric Dumazet 
4125110effeSDavid S. Miller 		dst->pending_confirm = 0;
413425f09abSEric Dumazet 		/* avoid dirtying neighbour */
414425f09abSEric Dumazet 		if (n->confirmed != now)
415425f09abSEric Dumazet 			n->confirmed = now;
4165110effeSDavid S. Miller 	}
4175110effeSDavid S. Miller 
4185110effeSDavid S. Miller 	hh = &n->hh;
4195110effeSDavid S. Miller 	if ((n->nud_state & NUD_CONNECTED) && hh->hh_len)
4205110effeSDavid S. Miller 		return neigh_hh_output(hh, skb);
4215110effeSDavid S. Miller 	else
4225110effeSDavid S. Miller 		return n->output(n, skb);
4231da177e4SLinus Torvalds }
4241da177e4SLinus Torvalds 
425d3aaeb38SDavid S. Miller static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr)
426d3aaeb38SDavid S. Miller {
427aaa0c23cSZhouyi Zhou 	struct neighbour *n = dst->ops->neigh_lookup(dst, NULL, daddr);
428aaa0c23cSZhouyi Zhou 	return IS_ERR(n) ? NULL : n;
429f894cbf8SDavid S. Miller }
430f894cbf8SDavid S. Miller 
431f894cbf8SDavid S. Miller static inline struct neighbour *dst_neigh_lookup_skb(const struct dst_entry *dst,
432f894cbf8SDavid S. Miller 						     struct sk_buff *skb)
433f894cbf8SDavid S. Miller {
434aaa0c23cSZhouyi Zhou 	struct neighbour *n =  dst->ops->neigh_lookup(dst, skb, NULL);
435aaa0c23cSZhouyi Zhou 	return IS_ERR(n) ? NULL : n;
436d3aaeb38SDavid S. Miller }
437d3aaeb38SDavid S. Miller 
4381da177e4SLinus Torvalds static inline void dst_link_failure(struct sk_buff *skb)
4391da177e4SLinus Torvalds {
440adf30907SEric Dumazet 	struct dst_entry *dst = skb_dst(skb);
4411da177e4SLinus Torvalds 	if (dst && dst->ops && dst->ops->link_failure)
4421da177e4SLinus Torvalds 		dst->ops->link_failure(skb);
4431da177e4SLinus Torvalds }
4441da177e4SLinus Torvalds 
4451da177e4SLinus Torvalds static inline void dst_set_expires(struct dst_entry *dst, int timeout)
4461da177e4SLinus Torvalds {
4471da177e4SLinus Torvalds 	unsigned long expires = jiffies + timeout;
4481da177e4SLinus Torvalds 
4491da177e4SLinus Torvalds 	if (expires == 0)
4501da177e4SLinus Torvalds 		expires = 1;
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds 	if (dst->expires == 0 || time_before(expires, dst->expires))
4531da177e4SLinus Torvalds 		dst->expires = expires;
4541da177e4SLinus Torvalds }
4551da177e4SLinus Torvalds 
4561da177e4SLinus Torvalds /* Output packet to network from transport.  */
4575a70649eSEric W. Biederman static inline int dst_output(struct sock *sk, struct sk_buff *skb)
458aad88724SEric Dumazet {
459aad88724SEric Dumazet 	return skb_dst(skb)->output(sk, skb);
460aad88724SEric Dumazet }
4610c4b51f0SEric W. Biederman static inline int dst_output_okfn(struct net *net, struct sock *sk, struct sk_buff *skb)
4620c4b51f0SEric W. Biederman {
4630c4b51f0SEric W. Biederman 	return dst_output(sk, skb);
4640c4b51f0SEric W. Biederman }
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds /* Input packet from network to transport.  */
4671da177e4SLinus Torvalds static inline int dst_input(struct sk_buff *skb)
4681da177e4SLinus Torvalds {
469adf30907SEric Dumazet 	return skb_dst(skb)->input(skb);
4701da177e4SLinus Torvalds }
4711da177e4SLinus Torvalds 
4721da177e4SLinus Torvalds static inline struct dst_entry *dst_check(struct dst_entry *dst, u32 cookie)
4731da177e4SLinus Torvalds {
4741da177e4SLinus Torvalds 	if (dst->obsolete)
4751da177e4SLinus Torvalds 		dst = dst->ops->check(dst, cookie);
4761da177e4SLinus Torvalds 	return dst;
4771da177e4SLinus Torvalds }
4781da177e4SLinus Torvalds 
479f38a9eb1SThomas Graf void dst_subsys_init(void);
4801da177e4SLinus Torvalds 
481815f4e57SHerbert Xu /* Flags for xfrm_lookup flags argument. */
482815f4e57SHerbert Xu enum {
48380c0bc9eSDavid S. Miller 	XFRM_LOOKUP_ICMP = 1 << 0,
484b8c203b2SSteffen Klassert 	XFRM_LOOKUP_QUEUE = 1 << 1,
485ac37e251Shuaibin Wang 	XFRM_LOOKUP_KEEP_DST_REF = 1 << 2,
486815f4e57SHerbert Xu };
487815f4e57SHerbert Xu 
4881da177e4SLinus Torvalds struct flowi;
4891da177e4SLinus Torvalds #ifndef CONFIG_XFRM
490452edd59SDavid S. Miller static inline struct dst_entry *xfrm_lookup(struct net *net,
491452edd59SDavid S. Miller 					    struct dst_entry *dst_orig,
492*6f9c9615SEric Dumazet 					    const struct flowi *fl,
493*6f9c9615SEric Dumazet 					    const struct sock *sk,
494dee9f4bcSDavid S. Miller 					    int flags)
4951da177e4SLinus Torvalds {
496452edd59SDavid S. Miller 	return dst_orig;
4971da177e4SLinus Torvalds }
498e87b3998SVlad Yasevich 
499f92ee619SSteffen Klassert static inline struct dst_entry *xfrm_lookup_route(struct net *net,
500f92ee619SSteffen Klassert 						  struct dst_entry *dst_orig,
501f92ee619SSteffen Klassert 						  const struct flowi *fl,
502*6f9c9615SEric Dumazet 						  const struct sock *sk,
503f92ee619SSteffen Klassert 						  int flags)
504f92ee619SSteffen Klassert {
505f92ee619SSteffen Klassert 	return dst_orig;
506f92ee619SSteffen Klassert }
507f92ee619SSteffen Klassert 
508e87b3998SVlad Yasevich static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
509e87b3998SVlad Yasevich {
510e87b3998SVlad Yasevich 	return NULL;
511e87b3998SVlad Yasevich }
512e87b3998SVlad Yasevich 
5131da177e4SLinus Torvalds #else
514a4023dd0SJoe Perches struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
515*6f9c9615SEric Dumazet 			      const struct flowi *fl, const struct sock *sk,
516452edd59SDavid S. Miller 			      int flags);
517e87b3998SVlad Yasevich 
518f92ee619SSteffen Klassert struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
519*6f9c9615SEric Dumazet 				    const struct flowi *fl, const struct sock *sk,
520f92ee619SSteffen Klassert 				    int flags);
521f92ee619SSteffen Klassert 
522e87b3998SVlad Yasevich /* skb attached with this dst needs transformation if dst->xfrm is valid */
523e87b3998SVlad Yasevich static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
524e87b3998SVlad Yasevich {
525e87b3998SVlad Yasevich 	return dst->xfrm;
526e87b3998SVlad Yasevich }
5271da177e4SLinus Torvalds #endif
5281da177e4SLinus Torvalds 
5291da177e4SLinus Torvalds #endif /* _NET_DST_H */
530