xref: /openbmc/linux/include/net/dst.h (revision d3aaeb38c40e5a6c08dd31a1b64da65c4352be36)
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>
151da177e4SLinus Torvalds #include <linux/jiffies.h>
161da177e4SLinus Torvalds #include <net/neighbour.h>
171da177e4SLinus Torvalds #include <asm/processor.h>
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #define DST_GC_MIN	(HZ/10)
201da177e4SLinus Torvalds #define DST_GC_INC	(HZ/2)
211da177e4SLinus Torvalds #define DST_GC_MAX	(120*HZ)
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds /* Each dst_entry has reference count and sits in some parent list(s).
241da177e4SLinus Torvalds  * When it is removed from parent list, it is "freed" (dst_free).
251da177e4SLinus Torvalds  * After this it enters dead state (dst->obsolete > 0) and if its refcnt
261da177e4SLinus Torvalds  * is zero, it can be destroyed immediately, otherwise it is added
271da177e4SLinus Torvalds  * to gc list and garbage collector periodically checks the refcnt.
281da177e4SLinus Torvalds  */
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds struct sk_buff;
311da177e4SLinus Torvalds 
32fd2c3ef7SEric Dumazet struct dst_entry {
331e19e02cSEric Dumazet 	struct rcu_head		rcu_head;
341da177e4SLinus Torvalds 	struct dst_entry	*child;
351da177e4SLinus Torvalds 	struct net_device       *dev;
3662fa8a84SDavid S. Miller 	struct  dst_ops	        *ops;
3762fa8a84SDavid S. Miller 	unsigned long		_metrics;
381da177e4SLinus Torvalds 	unsigned long		expires;
39f1dd9c37SZhang Yanmin 	struct dst_entry	*path;
4069cce1d1SDavid S. Miller 	struct neighbour	*_neighbour;
41def8b4faSAlexey Dobriyan #ifdef CONFIG_XFRM
421da177e4SLinus Torvalds 	struct xfrm_state	*xfrm;
435635c10dSEric Dumazet #else
445635c10dSEric Dumazet 	void			*__pad1;
45def8b4faSAlexey Dobriyan #endif
461da177e4SLinus Torvalds 	int			(*input)(struct sk_buff*);
471da177e4SLinus Torvalds 	int			(*output)(struct sk_buff*);
481da177e4SLinus Torvalds 
49f6b72b62SDavid S. Miller 	int			flags;
50f6b72b62SDavid S. Miller #define DST_HOST		0x0001
51f6b72b62SDavid S. Miller #define DST_NOXFRM		0x0002
52f6b72b62SDavid S. Miller #define DST_NOPOLICY		0x0004
53f6b72b62SDavid S. Miller #define DST_NOHASH		0x0008
54f6b72b62SDavid S. Miller #define DST_NOCACHE		0x0010
55f6b72b62SDavid S. Miller #define DST_NOCOUNT		0x0020
56f6b72b62SDavid S. Miller 
5762fa8a84SDavid S. Miller 	short			error;
5862fa8a84SDavid S. Miller 	short			obsolete;
5962fa8a84SDavid S. Miller 	unsigned short		header_len;	/* more space at head required */
6062fa8a84SDavid S. Miller 	unsigned short		trailer_len;	/* space to reserve at tail */
61c7066f70SPatrick McHardy #ifdef CONFIG_IP_ROUTE_CLASSID
62f1dd9c37SZhang Yanmin 	__u32			tclassid;
635635c10dSEric Dumazet #else
645635c10dSEric Dumazet 	__u32			__pad2;
65f1dd9c37SZhang Yanmin #endif
66f1dd9c37SZhang Yanmin 
675635c10dSEric Dumazet 	/*
685635c10dSEric Dumazet 	 * Align __refcnt to a 64 bytes alignment
695635c10dSEric Dumazet 	 * (L1_CACHE_SIZE would be too much)
705635c10dSEric Dumazet 	 */
715635c10dSEric Dumazet #ifdef CONFIG_64BIT
72f6b72b62SDavid S. Miller 	long			__pad_to_align_refcnt[2];
735635c10dSEric Dumazet #endif
74f1dd9c37SZhang Yanmin 	/*
75f1dd9c37SZhang Yanmin 	 * __refcnt wants to be on a different cache line from
76f1dd9c37SZhang Yanmin 	 * input/output/ops or performance tanks badly
77f1dd9c37SZhang Yanmin 	 */
781e19e02cSEric Dumazet 	atomic_t		__refcnt;	/* client references	*/
791e19e02cSEric Dumazet 	int			__use;
80f1dd9c37SZhang Yanmin 	unsigned long		lastuse;
811e19e02cSEric Dumazet 	union {
821e19e02cSEric Dumazet 		struct dst_entry	*next;
831c31720aSEric Dumazet 		struct rtable __rcu	*rt_next;
841e19e02cSEric Dumazet 		struct rt6_info		*rt6_next;
85fc766e4cSEric Dumazet 		struct dn_route __rcu	*dn_next;
861e19e02cSEric Dumazet 	};
871da177e4SLinus Torvalds };
881da177e4SLinus Torvalds 
8969cce1d1SDavid S. Miller static inline struct neighbour *dst_get_neighbour(struct dst_entry *dst)
9069cce1d1SDavid S. Miller {
9169cce1d1SDavid S. Miller 	return dst->_neighbour;
9269cce1d1SDavid S. Miller }
9369cce1d1SDavid S. Miller 
9469cce1d1SDavid S. Miller static inline void dst_set_neighbour(struct dst_entry *dst, struct neighbour *neigh)
9569cce1d1SDavid S. Miller {
9669cce1d1SDavid S. Miller 	dst->_neighbour = neigh;
9769cce1d1SDavid S. Miller }
9869cce1d1SDavid S. Miller 
9962fa8a84SDavid S. Miller extern u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old);
100725d1e1bSDavid S. Miller extern const u32 dst_default_metrics[RTAX_MAX];
10162fa8a84SDavid S. Miller 
10262fa8a84SDavid S. Miller #define DST_METRICS_READ_ONLY	0x1UL
10362fa8a84SDavid S. Miller #define __DST_METRICS_PTR(Y)	\
10462fa8a84SDavid S. Miller 	((u32 *)((Y) & ~DST_METRICS_READ_ONLY))
10562fa8a84SDavid S. Miller #define DST_METRICS_PTR(X)	__DST_METRICS_PTR((X)->_metrics)
10662fa8a84SDavid S. Miller 
10762fa8a84SDavid S. Miller static inline bool dst_metrics_read_only(const struct dst_entry *dst)
10862fa8a84SDavid S. Miller {
10962fa8a84SDavid S. Miller 	return dst->_metrics & DST_METRICS_READ_ONLY;
11062fa8a84SDavid S. Miller }
11162fa8a84SDavid S. Miller 
11262fa8a84SDavid S. Miller extern void __dst_destroy_metrics_generic(struct dst_entry *dst, unsigned long old);
11362fa8a84SDavid S. Miller 
11462fa8a84SDavid S. Miller static inline void dst_destroy_metrics_generic(struct dst_entry *dst)
11562fa8a84SDavid S. Miller {
11662fa8a84SDavid S. Miller 	unsigned long val = dst->_metrics;
11762fa8a84SDavid S. Miller 	if (!(val & DST_METRICS_READ_ONLY))
11862fa8a84SDavid S. Miller 		__dst_destroy_metrics_generic(dst, val);
11962fa8a84SDavid S. Miller }
12062fa8a84SDavid S. Miller 
12162fa8a84SDavid S. Miller static inline u32 *dst_metrics_write_ptr(struct dst_entry *dst)
12262fa8a84SDavid S. Miller {
12362fa8a84SDavid S. Miller 	unsigned long p = dst->_metrics;
12462fa8a84SDavid S. Miller 
1251f37070dSStephen Hemminger 	BUG_ON(!p);
1261f37070dSStephen Hemminger 
12762fa8a84SDavid S. Miller 	if (p & DST_METRICS_READ_ONLY)
12862fa8a84SDavid S. Miller 		return dst->ops->cow_metrics(dst, p);
12962fa8a84SDavid S. Miller 	return __DST_METRICS_PTR(p);
13062fa8a84SDavid S. Miller }
13162fa8a84SDavid S. Miller 
13262fa8a84SDavid S. Miller /* This may only be invoked before the entry has reached global
13362fa8a84SDavid S. Miller  * visibility.
13462fa8a84SDavid S. Miller  */
13562fa8a84SDavid S. Miller static inline void dst_init_metrics(struct dst_entry *dst,
13662fa8a84SDavid S. Miller 				    const u32 *src_metrics,
13762fa8a84SDavid S. Miller 				    bool read_only)
13862fa8a84SDavid S. Miller {
13962fa8a84SDavid S. Miller 	dst->_metrics = ((unsigned long) src_metrics) |
14062fa8a84SDavid S. Miller 		(read_only ? DST_METRICS_READ_ONLY : 0);
14162fa8a84SDavid S. Miller }
14262fa8a84SDavid S. Miller 
14362fa8a84SDavid S. Miller static inline void dst_copy_metrics(struct dst_entry *dest, const struct dst_entry *src)
14462fa8a84SDavid S. Miller {
14562fa8a84SDavid S. Miller 	u32 *dst_metrics = dst_metrics_write_ptr(dest);
14662fa8a84SDavid S. Miller 
14762fa8a84SDavid S. Miller 	if (dst_metrics) {
14862fa8a84SDavid S. Miller 		u32 *src_metrics = DST_METRICS_PTR(src);
14962fa8a84SDavid S. Miller 
15062fa8a84SDavid S. Miller 		memcpy(dst_metrics, src_metrics, RTAX_MAX * sizeof(u32));
15162fa8a84SDavid S. Miller 	}
15262fa8a84SDavid S. Miller }
15362fa8a84SDavid S. Miller 
15462fa8a84SDavid S. Miller static inline u32 *dst_metrics_ptr(struct dst_entry *dst)
15562fa8a84SDavid S. Miller {
15662fa8a84SDavid S. Miller 	return DST_METRICS_PTR(dst);
15762fa8a84SDavid S. Miller }
15862fa8a84SDavid S. Miller 
1591da177e4SLinus Torvalds static inline u32
1605170ae82SDavid S. Miller dst_metric_raw(const struct dst_entry *dst, const int metric)
1611da177e4SLinus Torvalds {
16262fa8a84SDavid S. Miller 	u32 *p = DST_METRICS_PTR(dst);
16362fa8a84SDavid S. Miller 
16462fa8a84SDavid S. Miller 	return p[metric-1];
165defb3519SDavid S. Miller }
166defb3519SDavid S. Miller 
1675170ae82SDavid S. Miller static inline u32
1685170ae82SDavid S. Miller dst_metric(const struct dst_entry *dst, const int metric)
1695170ae82SDavid S. Miller {
1700dbaee3bSDavid S. Miller 	WARN_ON_ONCE(metric == RTAX_HOPLIMIT ||
171d33e4553SDavid S. Miller 		     metric == RTAX_ADVMSS ||
172d33e4553SDavid S. Miller 		     metric == RTAX_MTU);
1735170ae82SDavid S. Miller 	return dst_metric_raw(dst, metric);
1745170ae82SDavid S. Miller }
1755170ae82SDavid S. Miller 
1760dbaee3bSDavid S. Miller static inline u32
1770dbaee3bSDavid S. Miller dst_metric_advmss(const struct dst_entry *dst)
1780dbaee3bSDavid S. Miller {
1790dbaee3bSDavid S. Miller 	u32 advmss = dst_metric_raw(dst, RTAX_ADVMSS);
1800dbaee3bSDavid S. Miller 
1810dbaee3bSDavid S. Miller 	if (!advmss)
1820dbaee3bSDavid S. Miller 		advmss = dst->ops->default_advmss(dst);
1830dbaee3bSDavid S. Miller 
1840dbaee3bSDavid S. Miller 	return advmss;
1850dbaee3bSDavid S. Miller }
1860dbaee3bSDavid S. Miller 
187defb3519SDavid S. Miller static inline void dst_metric_set(struct dst_entry *dst, int metric, u32 val)
188defb3519SDavid S. Miller {
18962fa8a84SDavid S. Miller 	u32 *p = dst_metrics_write_ptr(dst);
190defb3519SDavid S. Miller 
19162fa8a84SDavid S. Miller 	if (p)
19262fa8a84SDavid S. Miller 		p[metric-1] = val;
1931da177e4SLinus Torvalds }
1941da177e4SLinus Torvalds 
1950c3adfb8SGilad Ben-Yossef static inline u32
1960c3adfb8SGilad Ben-Yossef dst_feature(const struct dst_entry *dst, u32 feature)
1970c3adfb8SGilad Ben-Yossef {
198bb5b7c11SDavid S. Miller 	return dst_metric(dst, RTAX_FEATURES) & feature;
1990c3adfb8SGilad Ben-Yossef }
2000c3adfb8SGilad Ben-Yossef 
2011da177e4SLinus Torvalds static inline u32 dst_mtu(const struct dst_entry *dst)
2021da177e4SLinus Torvalds {
203d33e4553SDavid S. Miller 	u32 mtu = dst_metric_raw(dst, RTAX_MTU);
204d33e4553SDavid S. Miller 
205d33e4553SDavid S. Miller 	if (!mtu)
206d33e4553SDavid S. Miller 		mtu = dst->ops->default_mtu(dst);
207d33e4553SDavid S. Miller 
2081da177e4SLinus Torvalds 	return mtu;
2091da177e4SLinus Torvalds }
2101da177e4SLinus Torvalds 
211c1e20f7cSStephen Hemminger /* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */
212c1e20f7cSStephen Hemminger static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metric)
213c1e20f7cSStephen Hemminger {
214c1e20f7cSStephen Hemminger 	return msecs_to_jiffies(dst_metric(dst, metric));
215c1e20f7cSStephen Hemminger }
216c1e20f7cSStephen Hemminger 
217c1e20f7cSStephen Hemminger static inline void set_dst_metric_rtt(struct dst_entry *dst, int metric,
218c1e20f7cSStephen Hemminger 				      unsigned long rtt)
219c1e20f7cSStephen Hemminger {
220defb3519SDavid S. Miller 	dst_metric_set(dst, metric, jiffies_to_msecs(rtt));
221c1e20f7cSStephen Hemminger }
222c1e20f7cSStephen Hemminger 
2231da177e4SLinus Torvalds static inline u32
2241da177e4SLinus Torvalds dst_allfrag(const struct dst_entry *dst)
2251da177e4SLinus Torvalds {
2260c3adfb8SGilad Ben-Yossef 	int ret = dst_feature(dst,  RTAX_FEATURE_ALLFRAG);
2271da177e4SLinus Torvalds 	return ret;
2281da177e4SLinus Torvalds }
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds static inline int
231d33e4553SDavid S. Miller dst_metric_locked(const struct dst_entry *dst, int metric)
2321da177e4SLinus Torvalds {
2331da177e4SLinus Torvalds 	return dst_metric(dst, RTAX_LOCK) & (1<<metric);
2341da177e4SLinus Torvalds }
2351da177e4SLinus Torvalds 
2361da177e4SLinus Torvalds static inline void dst_hold(struct dst_entry * dst)
2371da177e4SLinus Torvalds {
2385635c10dSEric Dumazet 	/*
2395635c10dSEric Dumazet 	 * If your kernel compilation stops here, please check
2405635c10dSEric Dumazet 	 * __pad_to_align_refcnt declaration in struct dst_entry
2415635c10dSEric Dumazet 	 */
2425635c10dSEric Dumazet 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
2431da177e4SLinus Torvalds 	atomic_inc(&dst->__refcnt);
2441da177e4SLinus Torvalds }
2451da177e4SLinus Torvalds 
24603f49f34SPavel Emelyanov static inline void dst_use(struct dst_entry *dst, unsigned long time)
24703f49f34SPavel Emelyanov {
24803f49f34SPavel Emelyanov 	dst_hold(dst);
24903f49f34SPavel Emelyanov 	dst->__use++;
25003f49f34SPavel Emelyanov 	dst->lastuse = time;
25103f49f34SPavel Emelyanov }
25203f49f34SPavel Emelyanov 
2537fee226aSEric Dumazet static inline void dst_use_noref(struct dst_entry *dst, unsigned long time)
2547fee226aSEric Dumazet {
2557fee226aSEric Dumazet 	dst->__use++;
2567fee226aSEric Dumazet 	dst->lastuse = time;
2577fee226aSEric Dumazet }
2587fee226aSEric Dumazet 
2591da177e4SLinus Torvalds static inline
2601da177e4SLinus Torvalds struct dst_entry * dst_clone(struct dst_entry * dst)
2611da177e4SLinus Torvalds {
2621da177e4SLinus Torvalds 	if (dst)
2631da177e4SLinus Torvalds 		atomic_inc(&dst->__refcnt);
2641da177e4SLinus Torvalds 	return dst;
2651da177e4SLinus Torvalds }
2661da177e4SLinus Torvalds 
2678d330868SIlpo Järvinen extern void dst_release(struct dst_entry *dst);
2687fee226aSEric Dumazet 
2697fee226aSEric Dumazet static inline void refdst_drop(unsigned long refdst)
2707fee226aSEric Dumazet {
2717fee226aSEric Dumazet 	if (!(refdst & SKB_DST_NOREF))
2727fee226aSEric Dumazet 		dst_release((struct dst_entry *)(refdst & SKB_DST_PTRMASK));
2737fee226aSEric Dumazet }
2747fee226aSEric Dumazet 
2757fee226aSEric Dumazet /**
2767fee226aSEric Dumazet  * skb_dst_drop - drops skb dst
2777fee226aSEric Dumazet  * @skb: buffer
2787fee226aSEric Dumazet  *
2797fee226aSEric Dumazet  * Drops dst reference count if a reference was taken.
2807fee226aSEric Dumazet  */
281adf30907SEric Dumazet static inline void skb_dst_drop(struct sk_buff *skb)
282adf30907SEric Dumazet {
2837fee226aSEric Dumazet 	if (skb->_skb_refdst) {
2847fee226aSEric Dumazet 		refdst_drop(skb->_skb_refdst);
2857fee226aSEric Dumazet 		skb->_skb_refdst = 0UL;
2867fee226aSEric Dumazet 	}
2877fee226aSEric Dumazet }
2887fee226aSEric Dumazet 
2897fee226aSEric Dumazet static inline void skb_dst_copy(struct sk_buff *nskb, const struct sk_buff *oskb)
2907fee226aSEric Dumazet {
2917fee226aSEric Dumazet 	nskb->_skb_refdst = oskb->_skb_refdst;
2927fee226aSEric Dumazet 	if (!(nskb->_skb_refdst & SKB_DST_NOREF))
2937fee226aSEric Dumazet 		dst_clone(skb_dst(nskb));
2947fee226aSEric Dumazet }
2957fee226aSEric Dumazet 
2967fee226aSEric Dumazet /**
2977fee226aSEric Dumazet  * skb_dst_force - makes sure skb dst is refcounted
2987fee226aSEric Dumazet  * @skb: buffer
2997fee226aSEric Dumazet  *
3007fee226aSEric Dumazet  * If dst is not yet refcounted, let's do it
3017fee226aSEric Dumazet  */
3027fee226aSEric Dumazet static inline void skb_dst_force(struct sk_buff *skb)
3037fee226aSEric Dumazet {
3047fee226aSEric Dumazet 	if (skb_dst_is_noref(skb)) {
3057fee226aSEric Dumazet 		WARN_ON(!rcu_read_lock_held());
3067fee226aSEric Dumazet 		skb->_skb_refdst &= ~SKB_DST_NOREF;
3077fee226aSEric Dumazet 		dst_clone(skb_dst(skb));
3087fee226aSEric Dumazet 	}
309adf30907SEric Dumazet }
3101da177e4SLinus Torvalds 
311d19d56ddSEric Dumazet 
312d19d56ddSEric Dumazet /**
313290b895eSEric Dumazet  *	__skb_tunnel_rx - prepare skb for rx reinsert
314290b895eSEric Dumazet  *	@skb: buffer
315290b895eSEric Dumazet  *	@dev: tunnel device
316290b895eSEric Dumazet  *
317290b895eSEric Dumazet  *	After decapsulation, packet is going to re-enter (netif_rx()) our stack,
318290b895eSEric Dumazet  *	so make some cleanups. (no accounting done)
319290b895eSEric Dumazet  */
320290b895eSEric Dumazet static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
321290b895eSEric Dumazet {
322290b895eSEric Dumazet 	skb->dev = dev;
323290b895eSEric Dumazet 	skb->rxhash = 0;
324290b895eSEric Dumazet 	skb_set_queue_mapping(skb, 0);
325290b895eSEric Dumazet 	skb_dst_drop(skb);
326290b895eSEric Dumazet 	nf_reset(skb);
327290b895eSEric Dumazet }
328290b895eSEric Dumazet 
329290b895eSEric Dumazet /**
330d19d56ddSEric Dumazet  *	skb_tunnel_rx - prepare skb for rx reinsert
331d19d56ddSEric Dumazet  *	@skb: buffer
332d19d56ddSEric Dumazet  *	@dev: tunnel device
333d19d56ddSEric Dumazet  *
334d19d56ddSEric Dumazet  *	After decapsulation, packet is going to re-enter (netif_rx()) our stack,
335d19d56ddSEric Dumazet  *	so make some cleanups, and perform accounting.
336290b895eSEric Dumazet  *	Note: this accounting is not SMP safe.
337d19d56ddSEric Dumazet  */
338d19d56ddSEric Dumazet static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
339d19d56ddSEric Dumazet {
340d19d56ddSEric Dumazet 	/* TODO : stats should be SMP safe */
341d19d56ddSEric Dumazet 	dev->stats.rx_packets++;
342d19d56ddSEric Dumazet 	dev->stats.rx_bytes += skb->len;
343290b895eSEric Dumazet 	__skb_tunnel_rx(skb, dev);
344d19d56ddSEric Dumazet }
345d19d56ddSEric Dumazet 
3461da177e4SLinus Torvalds /* Children define the path of the packet through the
3471da177e4SLinus Torvalds  * Linux networking.  Thus, destinations are stackable.
3481da177e4SLinus Torvalds  */
3491da177e4SLinus Torvalds 
3508764ab2cSSteffen Klassert static inline struct dst_entry *skb_dst_pop(struct sk_buff *skb)
3511da177e4SLinus Torvalds {
352e433430aSSteffen Klassert 	struct dst_entry *child = dst_clone(skb_dst(skb)->child);
3531da177e4SLinus Torvalds 
3548764ab2cSSteffen Klassert 	skb_dst_drop(skb);
3551da177e4SLinus Torvalds 	return child;
3561da177e4SLinus Torvalds }
3571da177e4SLinus Torvalds 
358352e512cSHerbert Xu extern int dst_discard(struct sk_buff *skb);
3595c1e6aa3SDavid S. Miller extern void *dst_alloc(struct dst_ops * ops, struct net_device *dev,
3605c1e6aa3SDavid S. Miller 		       int initial_ref, int initial_obsolete, int flags);
3611da177e4SLinus Torvalds extern void __dst_free(struct dst_entry * dst);
3621da177e4SLinus Torvalds extern struct dst_entry *dst_destroy(struct dst_entry * dst);
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds static inline void dst_free(struct dst_entry * dst)
3651da177e4SLinus Torvalds {
3661da177e4SLinus Torvalds 	if (dst->obsolete > 1)
3671da177e4SLinus Torvalds 		return;
3681da177e4SLinus Torvalds 	if (!atomic_read(&dst->__refcnt)) {
3691da177e4SLinus Torvalds 		dst = dst_destroy(dst);
3701da177e4SLinus Torvalds 		if (!dst)
3711da177e4SLinus Torvalds 			return;
3721da177e4SLinus Torvalds 	}
3731da177e4SLinus Torvalds 	__dst_free(dst);
3741da177e4SLinus Torvalds }
3751da177e4SLinus Torvalds 
3761da177e4SLinus Torvalds static inline void dst_rcu_free(struct rcu_head *head)
3771da177e4SLinus Torvalds {
3781da177e4SLinus Torvalds 	struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head);
3791da177e4SLinus Torvalds 	dst_free(dst);
3801da177e4SLinus Torvalds }
3811da177e4SLinus Torvalds 
3821da177e4SLinus Torvalds static inline void dst_confirm(struct dst_entry *dst)
3831da177e4SLinus Torvalds {
38469cce1d1SDavid S. Miller 	if (dst) {
38569cce1d1SDavid S. Miller 		struct neighbour *n = dst_get_neighbour(dst);
38669cce1d1SDavid S. Miller 		neigh_confirm(n);
38769cce1d1SDavid S. Miller 	}
3881da177e4SLinus Torvalds }
3891da177e4SLinus Torvalds 
390*d3aaeb38SDavid S. Miller static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr)
391*d3aaeb38SDavid S. Miller {
392*d3aaeb38SDavid S. Miller 	return dst->ops->neigh_lookup(dst, daddr);
393*d3aaeb38SDavid S. Miller }
394*d3aaeb38SDavid S. Miller 
3951da177e4SLinus Torvalds static inline void dst_link_failure(struct sk_buff *skb)
3961da177e4SLinus Torvalds {
397adf30907SEric Dumazet 	struct dst_entry *dst = skb_dst(skb);
3981da177e4SLinus Torvalds 	if (dst && dst->ops && dst->ops->link_failure)
3991da177e4SLinus Torvalds 		dst->ops->link_failure(skb);
4001da177e4SLinus Torvalds }
4011da177e4SLinus Torvalds 
4021da177e4SLinus Torvalds static inline void dst_set_expires(struct dst_entry *dst, int timeout)
4031da177e4SLinus Torvalds {
4041da177e4SLinus Torvalds 	unsigned long expires = jiffies + timeout;
4051da177e4SLinus Torvalds 
4061da177e4SLinus Torvalds 	if (expires == 0)
4071da177e4SLinus Torvalds 		expires = 1;
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds 	if (dst->expires == 0 || time_before(expires, dst->expires))
4101da177e4SLinus Torvalds 		dst->expires = expires;
4111da177e4SLinus Torvalds }
4121da177e4SLinus Torvalds 
4131da177e4SLinus Torvalds /* Output packet to network from transport.  */
4141da177e4SLinus Torvalds static inline int dst_output(struct sk_buff *skb)
4151da177e4SLinus Torvalds {
416adf30907SEric Dumazet 	return skb_dst(skb)->output(skb);
4171da177e4SLinus Torvalds }
4181da177e4SLinus Torvalds 
4191da177e4SLinus Torvalds /* Input packet from network to transport.  */
4201da177e4SLinus Torvalds static inline int dst_input(struct sk_buff *skb)
4211da177e4SLinus Torvalds {
422adf30907SEric Dumazet 	return skb_dst(skb)->input(skb);
4231da177e4SLinus Torvalds }
4241da177e4SLinus Torvalds 
4251da177e4SLinus Torvalds static inline struct dst_entry *dst_check(struct dst_entry *dst, u32 cookie)
4261da177e4SLinus Torvalds {
4271da177e4SLinus Torvalds 	if (dst->obsolete)
4281da177e4SLinus Torvalds 		dst = dst->ops->check(dst, cookie);
4291da177e4SLinus Torvalds 	return dst;
4301da177e4SLinus Torvalds }
4311da177e4SLinus Torvalds 
4321da177e4SLinus Torvalds extern void		dst_init(void);
4331da177e4SLinus Torvalds 
434815f4e57SHerbert Xu /* Flags for xfrm_lookup flags argument. */
435815f4e57SHerbert Xu enum {
43680c0bc9eSDavid S. Miller 	XFRM_LOOKUP_ICMP = 1 << 0,
437815f4e57SHerbert Xu };
438815f4e57SHerbert Xu 
4391da177e4SLinus Torvalds struct flowi;
4401da177e4SLinus Torvalds #ifndef CONFIG_XFRM
441452edd59SDavid S. Miller static inline struct dst_entry *xfrm_lookup(struct net *net,
442452edd59SDavid S. Miller 					    struct dst_entry *dst_orig,
443dee9f4bcSDavid S. Miller 					    const struct flowi *fl, struct sock *sk,
444dee9f4bcSDavid S. Miller 					    int flags)
4451da177e4SLinus Torvalds {
446452edd59SDavid S. Miller 	return dst_orig;
4471da177e4SLinus Torvalds }
4481da177e4SLinus Torvalds #else
449452edd59SDavid S. Miller extern struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
450452edd59SDavid S. Miller 				     const struct flowi *fl, struct sock *sk,
451452edd59SDavid S. Miller 				     int flags);
4521da177e4SLinus Torvalds #endif
4531da177e4SLinus Torvalds 
4541da177e4SLinus Torvalds #endif /* _NET_DST_H */
455