xref: /openbmc/linux/include/net/dst.h (revision 6585d7dc491d9d5e323ed52ee32ad071e04c9dfa)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * net/dst.h	Protocol independent destination cache definitions.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds 
91da177e4SLinus Torvalds #ifndef _NET_DST_H
101da177e4SLinus Torvalds #define _NET_DST_H
111da177e4SLinus Torvalds 
1286393e52SAlexey Dobriyan #include <net/dst_ops.h>
1314c85021SArnaldo Carvalho de Melo #include <linux/netdevice.h>
141da177e4SLinus Torvalds #include <linux/rtnetlink.h>
151da177e4SLinus Torvalds #include <linux/rcupdate.h>
16187f1882SPaul Gortmaker #include <linux/bug.h>
171da177e4SLinus Torvalds #include <linux/jiffies.h>
189620fef2SEric Dumazet #include <linux/refcount.h>
191da177e4SLinus Torvalds #include <net/neighbour.h>
201da177e4SLinus Torvalds #include <asm/processor.h>
21e43b2190SBrian Vazquez #include <linux/indirect_call_wrapper.h>
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds struct sk_buff;
241da177e4SLinus Torvalds 
25fd2c3ef7SEric Dumazet struct dst_entry {
2666727145SAlexey Dobriyan 	struct net_device       *dev;
2762fa8a84SDavid S. Miller 	struct  dst_ops	        *ops;
2862fa8a84SDavid S. Miller 	unsigned long		_metrics;
291da177e4SLinus Torvalds 	unsigned long           expires;
30def8b4faSAlexey Dobriyan #ifdef CONFIG_XFRM
311da177e4SLinus Torvalds 	struct xfrm_state	*xfrm;
325635c10dSEric Dumazet #else
335635c10dSEric Dumazet 	void			*__pad1;
34def8b4faSAlexey Dobriyan #endif
351da177e4SLinus Torvalds 	int			(*input)(struct sk_buff *);
36ede2059dSEric W. Biederman 	int			(*output)(struct net *net, struct sock *sk, struct sk_buff *skb);
371da177e4SLinus Torvalds 
385110effeSDavid S. Miller 	unsigned short		flags;
39f6b72b62SDavid S. Miller #define DST_NOXFRM		0x0002
40f6b72b62SDavid S. Miller #define DST_NOPOLICY		0x0004
411eb04e7cSWei Wang #define DST_NOCOUNT		0x0008
421eb04e7cSWei Wang #define DST_FAKE_RTABLE		0x0010
431eb04e7cSWei Wang #define DST_XFRM_TUNNEL		0x0020
441eb04e7cSWei Wang #define DST_XFRM_QUEUE		0x0040
451eb04e7cSWei Wang #define DST_METADATA		0x0080
46f6b72b62SDavid S. Miller 
47f5b0a874SDavid S. Miller 	/* A non-zero value of dst->obsolete forces by-hand validation
48f5b0a874SDavid S. Miller 	 * of the route entry.  Positive values are set by the generic
49f5b0a874SDavid S. Miller 	 * dst layer to indicate that the entry has been forcefully
50f5b0a874SDavid S. Miller 	 * destroyed.
51f5b0a874SDavid S. Miller 	 *
52f5b0a874SDavid S. Miller 	 * Negative values are used by the implementation layer code to
53f5b0a874SDavid S. Miller 	 * force invocation of the dst_ops->check() method.
54f5b0a874SDavid S. Miller 	 */
5562fa8a84SDavid S. Miller 	short			obsolete;
56f5b0a874SDavid S. Miller #define DST_OBSOLETE_NONE	0
57f5b0a874SDavid S. Miller #define DST_OBSOLETE_DEAD	2
58f5b0a874SDavid S. Miller #define DST_OBSOLETE_FORCE_CHK	-1
59ceb33206SDavid S. Miller #define DST_OBSOLETE_KILL	-2
6062fa8a84SDavid S. Miller 	unsigned short		header_len;	/* more space at head required */
6162fa8a84SDavid S. Miller 	unsigned short		trailer_len;	/* space to reserve at tail */
6251ce8bd4SJulian Anastasov 
63f1dd9c37SZhang Yanmin 	/*
64f1dd9c37SZhang Yanmin 	 * __refcnt wants to be on a different cache line from
65f1dd9c37SZhang Yanmin 	 * input/output/ops or performance tanks badly
66f1dd9c37SZhang Yanmin 	 */
678b207e73SDavid Miller #ifdef CONFIG_64BIT
688b207e73SDavid Miller 	atomic_t		__refcnt;	/* 64-bit offset 64 */
698b207e73SDavid Miller #endif
701e19e02cSEric Dumazet 	int			__use;
71f1dd9c37SZhang Yanmin 	unsigned long		lastuse;
72751a587aSJiri Benc 	struct lwtunnel_state   *lwtstate;
738b207e73SDavid Miller 	struct rcu_head		rcu_head;
748b207e73SDavid Miller 	short			error;
758b207e73SDavid Miller 	short			__pad;
768b207e73SDavid Miller 	__u32			tclassid;
778b207e73SDavid Miller #ifndef CONFIG_64BIT
788b207e73SDavid Miller 	atomic_t		__refcnt;	/* 32-bit offset 64 */
798b207e73SDavid Miller #endif
801da177e4SLinus Torvalds };
811da177e4SLinus Torvalds 
823fb07dafSEric Dumazet struct dst_metrics {
833fb07dafSEric Dumazet 	u32		metrics[RTAX_MAX];
849620fef2SEric Dumazet 	refcount_t	refcnt;
85258a980dSGeert Uytterhoeven } __aligned(4);		/* Low pointer bits contain DST_METRICS_FLAGS */
863fb07dafSEric Dumazet extern const struct dst_metrics dst_default_metrics;
873fb07dafSEric Dumazet 
88a4023dd0SJoe Perches u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old);
8962fa8a84SDavid S. Miller 
9062fa8a84SDavid S. Miller #define DST_METRICS_READ_ONLY		0x1UL
913fb07dafSEric Dumazet #define DST_METRICS_REFCOUNTED		0x2UL
92e5fd387aSMichal Kubeček #define DST_METRICS_FLAGS		0x3UL
9362fa8a84SDavid S. Miller #define __DST_METRICS_PTR(Y)	\
94e5fd387aSMichal Kubeček 	((u32 *)((Y) & ~DST_METRICS_FLAGS))
9562fa8a84SDavid S. Miller #define DST_METRICS_PTR(X)	__DST_METRICS_PTR((X)->_metrics)
9662fa8a84SDavid S. Miller 
9762fa8a84SDavid S. Miller static inline bool dst_metrics_read_only(const struct dst_entry *dst)
9862fa8a84SDavid S. Miller {
9962fa8a84SDavid S. Miller 	return dst->_metrics & DST_METRICS_READ_ONLY;
10062fa8a84SDavid S. Miller }
10162fa8a84SDavid S. Miller 
102a4023dd0SJoe Perches void __dst_destroy_metrics_generic(struct dst_entry *dst, unsigned long old);
10362fa8a84SDavid S. Miller 
10462fa8a84SDavid S. Miller static inline void dst_destroy_metrics_generic(struct dst_entry *dst)
10562fa8a84SDavid S. Miller {
10662fa8a84SDavid S. Miller 	unsigned long val = dst->_metrics;
10762fa8a84SDavid S. Miller 	if (!(val & DST_METRICS_READ_ONLY))
10862fa8a84SDavid S. Miller 		__dst_destroy_metrics_generic(dst, val);
10962fa8a84SDavid S. Miller }
11062fa8a84SDavid S. Miller 
11162fa8a84SDavid S. Miller static inline u32 *dst_metrics_write_ptr(struct dst_entry *dst)
11262fa8a84SDavid S. Miller {
11362fa8a84SDavid S. Miller 	unsigned long p = dst->_metrics;
11462fa8a84SDavid S. Miller 
1151f37070dSStephen Hemminger 	BUG_ON(!p);
1161f37070dSStephen Hemminger 
11762fa8a84SDavid S. Miller 	if (p & DST_METRICS_READ_ONLY)
11862fa8a84SDavid S. Miller 		return dst->ops->cow_metrics(dst, p);
11962fa8a84SDavid S. Miller 	return __DST_METRICS_PTR(p);
12062fa8a84SDavid S. Miller }
12162fa8a84SDavid S. Miller 
12262fa8a84SDavid S. Miller /* This may only be invoked before the entry has reached global
12362fa8a84SDavid S. Miller  * visibility.
12462fa8a84SDavid S. Miller  */
12562fa8a84SDavid S. Miller static inline void dst_init_metrics(struct dst_entry *dst,
12662fa8a84SDavid S. Miller 				    const u32 *src_metrics,
12762fa8a84SDavid S. Miller 				    bool read_only)
12862fa8a84SDavid S. Miller {
12962fa8a84SDavid S. Miller 	dst->_metrics = ((unsigned long) src_metrics) |
13062fa8a84SDavid S. Miller 		(read_only ? DST_METRICS_READ_ONLY : 0);
13162fa8a84SDavid S. Miller }
13262fa8a84SDavid S. Miller 
13362fa8a84SDavid S. Miller static inline void dst_copy_metrics(struct dst_entry *dest, const struct dst_entry *src)
13462fa8a84SDavid S. Miller {
13562fa8a84SDavid S. Miller 	u32 *dst_metrics = dst_metrics_write_ptr(dest);
13662fa8a84SDavid S. Miller 
13762fa8a84SDavid S. Miller 	if (dst_metrics) {
13862fa8a84SDavid S. Miller 		u32 *src_metrics = DST_METRICS_PTR(src);
13962fa8a84SDavid S. Miller 
14062fa8a84SDavid S. Miller 		memcpy(dst_metrics, src_metrics, RTAX_MAX * sizeof(u32));
14162fa8a84SDavid S. Miller 	}
14262fa8a84SDavid S. Miller }
14362fa8a84SDavid S. Miller 
14462fa8a84SDavid S. Miller static inline u32 *dst_metrics_ptr(struct dst_entry *dst)
14562fa8a84SDavid S. Miller {
14662fa8a84SDavid S. Miller 	return DST_METRICS_PTR(dst);
14762fa8a84SDavid S. Miller }
14862fa8a84SDavid S. Miller 
1491da177e4SLinus Torvalds static inline u32
1505170ae82SDavid S. Miller dst_metric_raw(const struct dst_entry *dst, const int metric)
1511da177e4SLinus Torvalds {
15262fa8a84SDavid S. Miller 	u32 *p = DST_METRICS_PTR(dst);
15362fa8a84SDavid S. Miller 
15462fa8a84SDavid S. Miller 	return p[metric-1];
155defb3519SDavid S. Miller }
156defb3519SDavid S. Miller 
1575170ae82SDavid S. Miller static inline u32
1585170ae82SDavid S. Miller dst_metric(const struct dst_entry *dst, const int metric)
1595170ae82SDavid S. Miller {
1600dbaee3bSDavid S. Miller 	WARN_ON_ONCE(metric == RTAX_HOPLIMIT ||
161d33e4553SDavid S. Miller 		     metric == RTAX_ADVMSS ||
162d33e4553SDavid S. Miller 		     metric == RTAX_MTU);
1635170ae82SDavid S. Miller 	return dst_metric_raw(dst, metric);
1645170ae82SDavid S. Miller }
1655170ae82SDavid S. Miller 
1660dbaee3bSDavid S. Miller static inline u32
1670dbaee3bSDavid S. Miller dst_metric_advmss(const struct dst_entry *dst)
1680dbaee3bSDavid S. Miller {
1690dbaee3bSDavid S. Miller 	u32 advmss = dst_metric_raw(dst, RTAX_ADVMSS);
1700dbaee3bSDavid S. Miller 
1710dbaee3bSDavid S. Miller 	if (!advmss)
1720dbaee3bSDavid S. Miller 		advmss = dst->ops->default_advmss(dst);
1730dbaee3bSDavid S. Miller 
1740dbaee3bSDavid S. Miller 	return advmss;
1750dbaee3bSDavid S. Miller }
1760dbaee3bSDavid S. Miller 
177defb3519SDavid S. Miller static inline void dst_metric_set(struct dst_entry *dst, int metric, u32 val)
178defb3519SDavid S. Miller {
17962fa8a84SDavid S. Miller 	u32 *p = dst_metrics_write_ptr(dst);
180defb3519SDavid S. Miller 
18162fa8a84SDavid S. Miller 	if (p)
18262fa8a84SDavid S. Miller 		p[metric-1] = val;
1831da177e4SLinus Torvalds }
1841da177e4SLinus Torvalds 
185c3a8d947SDaniel Borkmann /* Kernel-internal feature bits that are unallocated in user space. */
18640f6a2cbSVandana BN #define DST_FEATURE_ECN_CA	(1U << 31)
187c3a8d947SDaniel Borkmann 
188c3a8d947SDaniel Borkmann #define DST_FEATURE_MASK	(DST_FEATURE_ECN_CA)
189c3a8d947SDaniel Borkmann #define DST_FEATURE_ECN_MASK	(DST_FEATURE_ECN_CA | RTAX_FEATURE_ECN)
190c3a8d947SDaniel Borkmann 
1910c3adfb8SGilad Ben-Yossef static inline u32
1920c3adfb8SGilad Ben-Yossef dst_feature(const struct dst_entry *dst, u32 feature)
1930c3adfb8SGilad Ben-Yossef {
194bb5b7c11SDavid S. Miller 	return dst_metric(dst, RTAX_FEATURES) & feature;
1950c3adfb8SGilad Ben-Yossef }
1960c3adfb8SGilad Ben-Yossef 
1971da177e4SLinus Torvalds static inline u32 dst_mtu(const struct dst_entry *dst)
1981da177e4SLinus Torvalds {
199618f9bc7SSteffen Klassert 	return dst->ops->mtu(dst);
2001da177e4SLinus Torvalds }
2011da177e4SLinus Torvalds 
202c1e20f7cSStephen Hemminger /* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */
203c1e20f7cSStephen Hemminger static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metric)
204c1e20f7cSStephen Hemminger {
205c1e20f7cSStephen Hemminger 	return msecs_to_jiffies(dst_metric(dst, metric));
206c1e20f7cSStephen Hemminger }
207c1e20f7cSStephen Hemminger 
2081da177e4SLinus Torvalds static inline u32
2091da177e4SLinus Torvalds dst_allfrag(const struct dst_entry *dst)
2101da177e4SLinus Torvalds {
2110c3adfb8SGilad Ben-Yossef 	int ret = dst_feature(dst,  RTAX_FEATURE_ALLFRAG);
2121da177e4SLinus Torvalds 	return ret;
2131da177e4SLinus Torvalds }
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds static inline int
216d33e4553SDavid S. Miller dst_metric_locked(const struct dst_entry *dst, int metric)
2171da177e4SLinus Torvalds {
2181da177e4SLinus Torvalds 	return dst_metric(dst, RTAX_LOCK) & (1 << metric);
2191da177e4SLinus Torvalds }
2201da177e4SLinus Torvalds 
2211da177e4SLinus Torvalds static inline void dst_hold(struct dst_entry *dst)
2221da177e4SLinus Torvalds {
2235635c10dSEric Dumazet 	/*
2245635c10dSEric Dumazet 	 * If your kernel compilation stops here, please check
2258b207e73SDavid Miller 	 * the placement of __refcnt in struct dst_entry
2265635c10dSEric Dumazet 	 */
2275635c10dSEric Dumazet 	BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
22844ebe791SWei Wang 	WARN_ON(atomic_inc_not_zero(&dst->__refcnt) == 0);
2291da177e4SLinus Torvalds }
2301da177e4SLinus Torvalds 
2310da4af00SWei Wang static inline void dst_use_noref(struct dst_entry *dst, unsigned long time)
23203f49f34SPavel Emelyanov {
23332d18ab1SPaolo Abeni 	if (unlikely(time != dst->lastuse)) {
23403f49f34SPavel Emelyanov 		dst->__use++;
23503f49f34SPavel Emelyanov 		dst->lastuse = time;
23603f49f34SPavel Emelyanov 	}
2370da4af00SWei Wang }
23803f49f34SPavel Emelyanov 
2390da4af00SWei Wang static inline void dst_hold_and_use(struct dst_entry *dst, unsigned long time)
2407fee226aSEric Dumazet {
2410da4af00SWei Wang 	dst_hold(dst);
2420da4af00SWei Wang 	dst_use_noref(dst, time);
2437fee226aSEric Dumazet }
2447fee226aSEric Dumazet 
2457f95e188SEldad Zack static inline struct dst_entry *dst_clone(struct dst_entry *dst)
2461da177e4SLinus Torvalds {
2471da177e4SLinus Torvalds 	if (dst)
248222d7dbdSEric Dumazet 		dst_hold(dst);
2491da177e4SLinus Torvalds 	return dst;
2501da177e4SLinus Torvalds }
2511da177e4SLinus Torvalds 
252a4023dd0SJoe Perches void dst_release(struct dst_entry *dst);
2537fee226aSEric Dumazet 
2545f56f409SWei Wang void dst_release_immediate(struct dst_entry *dst);
2555f56f409SWei Wang 
2567fee226aSEric Dumazet static inline void refdst_drop(unsigned long refdst)
2577fee226aSEric Dumazet {
2587fee226aSEric Dumazet 	if (!(refdst & SKB_DST_NOREF))
2597fee226aSEric Dumazet 		dst_release((struct dst_entry *)(refdst & SKB_DST_PTRMASK));
2607fee226aSEric Dumazet }
2617fee226aSEric Dumazet 
2627fee226aSEric Dumazet /**
2637fee226aSEric Dumazet  * skb_dst_drop - drops skb dst
2647fee226aSEric Dumazet  * @skb: buffer
2657fee226aSEric Dumazet  *
2667fee226aSEric Dumazet  * Drops dst reference count if a reference was taken.
2677fee226aSEric Dumazet  */
268adf30907SEric Dumazet static inline void skb_dst_drop(struct sk_buff *skb)
269adf30907SEric Dumazet {
2707fee226aSEric Dumazet 	if (skb->_skb_refdst) {
2717fee226aSEric Dumazet 		refdst_drop(skb->_skb_refdst);
2727fee226aSEric Dumazet 		skb->_skb_refdst = 0UL;
2737fee226aSEric Dumazet 	}
2747fee226aSEric Dumazet }
2757fee226aSEric Dumazet 
276e79e2595SJoe Stringer static inline void __skb_dst_copy(struct sk_buff *nskb, unsigned long refdst)
2777fee226aSEric Dumazet {
278e79e2595SJoe Stringer 	nskb->_skb_refdst = refdst;
2797fee226aSEric Dumazet 	if (!(nskb->_skb_refdst & SKB_DST_NOREF))
2807fee226aSEric Dumazet 		dst_clone(skb_dst(nskb));
2817fee226aSEric Dumazet }
2827fee226aSEric Dumazet 
283e79e2595SJoe Stringer static inline void skb_dst_copy(struct sk_buff *nskb, const struct sk_buff *oskb)
284e79e2595SJoe Stringer {
285e79e2595SJoe Stringer 	__skb_dst_copy(nskb, oskb->_skb_refdst);
286e79e2595SJoe Stringer }
287e79e2595SJoe Stringer 
2887fee226aSEric Dumazet /**
2895037e9efSEric Dumazet  * dst_hold_safe - Take a reference on a dst if possible
2905037e9efSEric Dumazet  * @dst: pointer to dst entry
2915037e9efSEric Dumazet  *
2925037e9efSEric Dumazet  * This helper returns false if it could not safely
2935037e9efSEric Dumazet  * take a reference on a dst.
2945037e9efSEric Dumazet  */
2955037e9efSEric Dumazet static inline bool dst_hold_safe(struct dst_entry *dst)
2965037e9efSEric Dumazet {
2975037e9efSEric Dumazet 	return atomic_inc_not_zero(&dst->__refcnt);
2985037e9efSEric Dumazet }
2995037e9efSEric Dumazet 
3005037e9efSEric Dumazet /**
301222d7dbdSEric Dumazet  * skb_dst_force - makes sure skb dst is refcounted
3025037e9efSEric Dumazet  * @skb: buffer
3035037e9efSEric Dumazet  *
3045037e9efSEric Dumazet  * If dst is not yet refcounted and not destroyed, grab a ref on it.
305b60a7738SFlorian Westphal  * Returns true if dst is refcounted.
3065037e9efSEric Dumazet  */
307b60a7738SFlorian Westphal static inline bool skb_dst_force(struct sk_buff *skb)
3085037e9efSEric Dumazet {
3095037e9efSEric Dumazet 	if (skb_dst_is_noref(skb)) {
3105037e9efSEric Dumazet 		struct dst_entry *dst = skb_dst(skb);
3115037e9efSEric Dumazet 
312222d7dbdSEric Dumazet 		WARN_ON(!rcu_read_lock_held());
3135037e9efSEric Dumazet 		if (!dst_hold_safe(dst))
3145037e9efSEric Dumazet 			dst = NULL;
3155037e9efSEric Dumazet 
3165037e9efSEric Dumazet 		skb->_skb_refdst = (unsigned long)dst;
3175037e9efSEric Dumazet 	}
318b60a7738SFlorian Westphal 
319b60a7738SFlorian Westphal 	return skb->_skb_refdst != 0UL;
3205037e9efSEric Dumazet }
3215037e9efSEric Dumazet 
322d19d56ddSEric Dumazet 
323d19d56ddSEric Dumazet /**
324290b895eSEric Dumazet  *	__skb_tunnel_rx - prepare skb for rx reinsert
325290b895eSEric Dumazet  *	@skb: buffer
326290b895eSEric Dumazet  *	@dev: tunnel device
327ea23192eSNicolas Dichtel  *	@net: netns for packet i/o
328290b895eSEric Dumazet  *
329290b895eSEric Dumazet  *	After decapsulation, packet is going to re-enter (netif_rx()) our stack,
330290b895eSEric Dumazet  *	so make some cleanups. (no accounting done)
331290b895eSEric Dumazet  */
332ea23192eSNicolas Dichtel static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
333ea23192eSNicolas Dichtel 				   struct net *net)
334290b895eSEric Dumazet {
335290b895eSEric Dumazet 	skb->dev = dev;
336bdeab991STom Herbert 
337bdeab991STom Herbert 	/*
3387539fadcSTom Herbert 	 * Clear hash so that we can recalulate the hash for the
339bdeab991STom Herbert 	 * encapsulated packet, unless we have already determine the hash
340bdeab991STom Herbert 	 * over the L4 4-tuple.
341bdeab991STom Herbert 	 */
3427539fadcSTom Herbert 	skb_clear_hash_if_not_l4(skb);
343290b895eSEric Dumazet 	skb_set_queue_mapping(skb, 0);
344ea23192eSNicolas Dichtel 	skb_scrub_packet(skb, !net_eq(net, dev_net(dev)));
345290b895eSEric Dumazet }
346290b895eSEric Dumazet 
347290b895eSEric Dumazet /**
348d19d56ddSEric Dumazet  *	skb_tunnel_rx - prepare skb for rx reinsert
349d19d56ddSEric Dumazet  *	@skb: buffer
350d19d56ddSEric Dumazet  *	@dev: tunnel device
3518eb1a859SJonathan Neuschäfer  *	@net: netns for packet i/o
352d19d56ddSEric Dumazet  *
353d19d56ddSEric Dumazet  *	After decapsulation, packet is going to re-enter (netif_rx()) our stack,
354d19d56ddSEric Dumazet  *	so make some cleanups, and perform accounting.
355290b895eSEric Dumazet  *	Note: this accounting is not SMP safe.
356d19d56ddSEric Dumazet  */
357ea23192eSNicolas Dichtel static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
358ea23192eSNicolas Dichtel 				 struct net *net)
359d19d56ddSEric Dumazet {
360d19d56ddSEric Dumazet 	/* TODO : stats should be SMP safe */
361d19d56ddSEric Dumazet 	dev->stats.rx_packets++;
362d19d56ddSEric Dumazet 	dev->stats.rx_bytes += skb->len;
363ea23192eSNicolas Dichtel 	__skb_tunnel_rx(skb, dev, net);
364d19d56ddSEric Dumazet }
365d19d56ddSEric Dumazet 
366808c1b69SDaniel Borkmann static inline u32 dst_tclassid(const struct sk_buff *skb)
367808c1b69SDaniel Borkmann {
368808c1b69SDaniel Borkmann #ifdef CONFIG_IP_ROUTE_CLASSID
369808c1b69SDaniel Borkmann 	const struct dst_entry *dst;
370808c1b69SDaniel Borkmann 
371808c1b69SDaniel Borkmann 	dst = skb_dst(skb);
372808c1b69SDaniel Borkmann 	if (dst)
373808c1b69SDaniel Borkmann 		return dst->tclassid;
374808c1b69SDaniel Borkmann #endif
375808c1b69SDaniel Borkmann 	return 0;
376808c1b69SDaniel Borkmann }
377808c1b69SDaniel Borkmann 
378ede2059dSEric W. Biederman int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb);
379aad88724SEric Dumazet static inline int dst_discard(struct sk_buff *skb)
380aad88724SEric Dumazet {
381ede2059dSEric W. Biederman 	return dst_discard_out(&init_net, skb->sk, skb);
382aad88724SEric Dumazet }
383a4023dd0SJoe Perches void *dst_alloc(struct dst_ops *ops, struct net_device *dev, int initial_ref,
384a4023dd0SJoe Perches 		int initial_obsolete, unsigned short flags);
385f38a9eb1SThomas Graf void dst_init(struct dst_entry *dst, struct dst_ops *ops,
386f38a9eb1SThomas Graf 	      struct net_device *dev, int initial_ref, int initial_obsolete,
387f38a9eb1SThomas Graf 	      unsigned short flags);
388a4023dd0SJoe Perches struct dst_entry *dst_destroy(struct dst_entry *dst);
3894a6ce2b6SWei Wang void dst_dev_put(struct dst_entry *dst);
3901da177e4SLinus Torvalds 
3911da177e4SLinus Torvalds static inline void dst_confirm(struct dst_entry *dst)
3921da177e4SLinus Torvalds {
39369cce1d1SDavid S. Miller }
3945110effeSDavid S. Miller 
395d3aaeb38SDavid S. Miller static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr)
396d3aaeb38SDavid S. Miller {
397aaa0c23cSZhouyi Zhou 	struct neighbour *n = dst->ops->neigh_lookup(dst, NULL, daddr);
398aaa0c23cSZhouyi Zhou 	return IS_ERR(n) ? NULL : n;
399f894cbf8SDavid S. Miller }
400f894cbf8SDavid S. Miller 
401f894cbf8SDavid S. Miller static inline struct neighbour *dst_neigh_lookup_skb(const struct dst_entry *dst,
402f894cbf8SDavid S. Miller 						     struct sk_buff *skb)
403f894cbf8SDavid S. Miller {
4040992d67bSGuillaume Nault 	struct neighbour *n;
405394de110SMartin Varghese 
4060992d67bSGuillaume Nault 	if (WARN_ON_ONCE(!dst->ops->neigh_lookup))
4070992d67bSGuillaume Nault 		return NULL;
4080992d67bSGuillaume Nault 
409394de110SMartin Varghese 	n = dst->ops->neigh_lookup(dst, skb, NULL);
410394de110SMartin Varghese 
411aaa0c23cSZhouyi Zhou 	return IS_ERR(n) ? NULL : n;
412d3aaeb38SDavid S. Miller }
413d3aaeb38SDavid S. Miller 
41463fca65dSJulian Anastasov static inline void dst_confirm_neigh(const struct dst_entry *dst,
41563fca65dSJulian Anastasov 				     const void *daddr)
41663fca65dSJulian Anastasov {
41763fca65dSJulian Anastasov 	if (dst->ops->confirm_neigh)
41863fca65dSJulian Anastasov 		dst->ops->confirm_neigh(dst, daddr);
41963fca65dSJulian Anastasov }
42063fca65dSJulian Anastasov 
4211da177e4SLinus Torvalds static inline void dst_link_failure(struct sk_buff *skb)
4221da177e4SLinus Torvalds {
423adf30907SEric Dumazet 	struct dst_entry *dst = skb_dst(skb);
4241da177e4SLinus Torvalds 	if (dst && dst->ops && dst->ops->link_failure)
4251da177e4SLinus Torvalds 		dst->ops->link_failure(skb);
4261da177e4SLinus Torvalds }
4271da177e4SLinus Torvalds 
4281da177e4SLinus Torvalds static inline void dst_set_expires(struct dst_entry *dst, int timeout)
4291da177e4SLinus Torvalds {
4301da177e4SLinus Torvalds 	unsigned long expires = jiffies + timeout;
4311da177e4SLinus Torvalds 
4321da177e4SLinus Torvalds 	if (expires == 0)
4331da177e4SLinus Torvalds 		expires = 1;
4341da177e4SLinus Torvalds 
4351da177e4SLinus Torvalds 	if (dst->expires == 0 || time_before(expires, dst->expires))
4361da177e4SLinus Torvalds 		dst->expires = expires;
4371da177e4SLinus Torvalds }
4381da177e4SLinus Torvalds 
439*6585d7dcSBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip6_output(struct net *, struct sock *,
440*6585d7dcSBrian Vazquez 					 struct sk_buff *));
441*6585d7dcSBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip_output(struct net *, struct sock *,
442*6585d7dcSBrian Vazquez 					 struct sk_buff *));
4431da177e4SLinus Torvalds /* Output packet to network from transport.  */
44413206b6bSEric W. Biederman static inline int dst_output(struct net *net, struct sock *sk, struct sk_buff *skb)
445aad88724SEric Dumazet {
446*6585d7dcSBrian Vazquez 	return INDIRECT_CALL_INET(skb_dst(skb)->output,
447*6585d7dcSBrian Vazquez 				  ip6_output, ip_output,
448*6585d7dcSBrian Vazquez 				  net, sk, skb);
449aad88724SEric Dumazet }
4501da177e4SLinus Torvalds 
451e43b2190SBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip6_input(struct sk_buff *));
452e43b2190SBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip_local_deliver(struct sk_buff *));
4531da177e4SLinus Torvalds /* Input packet from network to transport.  */
4541da177e4SLinus Torvalds static inline int dst_input(struct sk_buff *skb)
4551da177e4SLinus Torvalds {
456e43b2190SBrian Vazquez 	return INDIRECT_CALL_INET(skb_dst(skb)->input,
457e43b2190SBrian Vazquez 				  ip6_input, ip_local_deliver, skb);
4581da177e4SLinus Torvalds }
4591da177e4SLinus Torvalds 
4601da177e4SLinus Torvalds static inline struct dst_entry *dst_check(struct dst_entry *dst, u32 cookie)
4611da177e4SLinus Torvalds {
4621da177e4SLinus Torvalds 	if (dst->obsolete)
4631da177e4SLinus Torvalds 		dst = dst->ops->check(dst, cookie);
4641da177e4SLinus Torvalds 	return dst;
4651da177e4SLinus Torvalds }
4661da177e4SLinus Torvalds 
467815f4e57SHerbert Xu /* Flags for xfrm_lookup flags argument. */
468815f4e57SHerbert Xu enum {
46980c0bc9eSDavid S. Miller 	XFRM_LOOKUP_ICMP = 1 << 0,
470b8c203b2SSteffen Klassert 	XFRM_LOOKUP_QUEUE = 1 << 1,
471ac37e251Shuaibin Wang 	XFRM_LOOKUP_KEEP_DST_REF = 1 << 2,
472815f4e57SHerbert Xu };
473815f4e57SHerbert Xu 
4741da177e4SLinus Torvalds struct flowi;
4751da177e4SLinus Torvalds #ifndef CONFIG_XFRM
476452edd59SDavid S. Miller static inline struct dst_entry *xfrm_lookup(struct net *net,
477452edd59SDavid S. Miller 					    struct dst_entry *dst_orig,
4786f9c9615SEric Dumazet 					    const struct flowi *fl,
4796f9c9615SEric Dumazet 					    const struct sock *sk,
480dee9f4bcSDavid S. Miller 					    int flags)
4811da177e4SLinus Torvalds {
482452edd59SDavid S. Miller 	return dst_orig;
4831da177e4SLinus Torvalds }
484e87b3998SVlad Yasevich 
485bc56b334SBenedict Wong static inline struct dst_entry *
486bc56b334SBenedict Wong xfrm_lookup_with_ifid(struct net *net, struct dst_entry *dst_orig,
487bc56b334SBenedict Wong 		      const struct flowi *fl, const struct sock *sk,
488bc56b334SBenedict Wong 		      int flags, u32 if_id)
489bc56b334SBenedict Wong {
490bc56b334SBenedict Wong 	return dst_orig;
491bc56b334SBenedict Wong }
492bc56b334SBenedict Wong 
493f92ee619SSteffen Klassert static inline struct dst_entry *xfrm_lookup_route(struct net *net,
494f92ee619SSteffen Klassert 						  struct dst_entry *dst_orig,
495f92ee619SSteffen Klassert 						  const struct flowi *fl,
4966f9c9615SEric Dumazet 						  const struct sock *sk,
497f92ee619SSteffen Klassert 						  int flags)
498f92ee619SSteffen Klassert {
499f92ee619SSteffen Klassert 	return dst_orig;
500f92ee619SSteffen Klassert }
501f92ee619SSteffen Klassert 
502e87b3998SVlad Yasevich static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
503e87b3998SVlad Yasevich {
504e87b3998SVlad Yasevich 	return NULL;
505e87b3998SVlad Yasevich }
506e87b3998SVlad Yasevich 
5071da177e4SLinus Torvalds #else
508a4023dd0SJoe Perches struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
5096f9c9615SEric Dumazet 			      const struct flowi *fl, const struct sock *sk,
510452edd59SDavid S. Miller 			      int flags);
511e87b3998SVlad Yasevich 
512bc56b334SBenedict Wong struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
513bc56b334SBenedict Wong 					struct dst_entry *dst_orig,
514bc56b334SBenedict Wong 					const struct flowi *fl,
515bc56b334SBenedict Wong 					const struct sock *sk, int flags,
516bc56b334SBenedict Wong 					u32 if_id);
517bc56b334SBenedict Wong 
518f92ee619SSteffen Klassert struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
5196f9c9615SEric 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 
529f15ca723SNicolas Dichtel static inline void skb_dst_update_pmtu(struct sk_buff *skb, u32 mtu)
530f15ca723SNicolas Dichtel {
531f15ca723SNicolas Dichtel 	struct dst_entry *dst = skb_dst(skb);
532f15ca723SNicolas Dichtel 
533f15ca723SNicolas Dichtel 	if (dst && dst->ops->update_pmtu)
534bd085ef6SHangbin Liu 		dst->ops->update_pmtu(dst, NULL, skb, mtu, true);
535f15ca723SNicolas Dichtel }
536f15ca723SNicolas Dichtel 
53707dc35c6SHangbin Liu /* update dst pmtu but not do neighbor confirm */
53807dc35c6SHangbin Liu static inline void skb_dst_update_pmtu_no_confirm(struct sk_buff *skb, u32 mtu)
53907dc35c6SHangbin Liu {
54007dc35c6SHangbin Liu 	struct dst_entry *dst = skb_dst(skb);
54107dc35c6SHangbin Liu 
54207dc35c6SHangbin Liu 	if (dst && dst->ops->update_pmtu)
54307dc35c6SHangbin Liu 		dst->ops->update_pmtu(dst, NULL, skb, mtu, false);
54407dc35c6SHangbin Liu }
54507dc35c6SHangbin Liu 
5461da177e4SLinus Torvalds #endif /* _NET_DST_H */
547