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 80*9038c320SEric Dumazet netdevice_tracker dev_tracker; 811da177e4SLinus Torvalds }; 821da177e4SLinus Torvalds 833fb07dafSEric Dumazet struct dst_metrics { 843fb07dafSEric Dumazet u32 metrics[RTAX_MAX]; 859620fef2SEric Dumazet refcount_t refcnt; 86258a980dSGeert Uytterhoeven } __aligned(4); /* Low pointer bits contain DST_METRICS_FLAGS */ 873fb07dafSEric Dumazet extern const struct dst_metrics dst_default_metrics; 883fb07dafSEric Dumazet 89a4023dd0SJoe Perches u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old); 9062fa8a84SDavid S. Miller 9162fa8a84SDavid S. Miller #define DST_METRICS_READ_ONLY 0x1UL 923fb07dafSEric Dumazet #define DST_METRICS_REFCOUNTED 0x2UL 93e5fd387aSMichal Kubeček #define DST_METRICS_FLAGS 0x3UL 9462fa8a84SDavid S. Miller #define __DST_METRICS_PTR(Y) \ 95e5fd387aSMichal Kubeček ((u32 *)((Y) & ~DST_METRICS_FLAGS)) 9662fa8a84SDavid S. Miller #define DST_METRICS_PTR(X) __DST_METRICS_PTR((X)->_metrics) 9762fa8a84SDavid S. Miller 9862fa8a84SDavid S. Miller static inline bool dst_metrics_read_only(const struct dst_entry *dst) 9962fa8a84SDavid S. Miller { 10062fa8a84SDavid S. Miller return dst->_metrics & DST_METRICS_READ_ONLY; 10162fa8a84SDavid S. Miller } 10262fa8a84SDavid S. Miller 103a4023dd0SJoe Perches void __dst_destroy_metrics_generic(struct dst_entry *dst, unsigned long old); 10462fa8a84SDavid S. Miller 10562fa8a84SDavid S. Miller static inline void dst_destroy_metrics_generic(struct dst_entry *dst) 10662fa8a84SDavid S. Miller { 10762fa8a84SDavid S. Miller unsigned long val = dst->_metrics; 10862fa8a84SDavid S. Miller if (!(val & DST_METRICS_READ_ONLY)) 10962fa8a84SDavid S. Miller __dst_destroy_metrics_generic(dst, val); 11062fa8a84SDavid S. Miller } 11162fa8a84SDavid S. Miller 11262fa8a84SDavid S. Miller static inline u32 *dst_metrics_write_ptr(struct dst_entry *dst) 11362fa8a84SDavid S. Miller { 11462fa8a84SDavid S. Miller unsigned long p = dst->_metrics; 11562fa8a84SDavid S. Miller 1161f37070dSStephen Hemminger BUG_ON(!p); 1171f37070dSStephen Hemminger 11862fa8a84SDavid S. Miller if (p & DST_METRICS_READ_ONLY) 11962fa8a84SDavid S. Miller return dst->ops->cow_metrics(dst, p); 12062fa8a84SDavid S. Miller return __DST_METRICS_PTR(p); 12162fa8a84SDavid S. Miller } 12262fa8a84SDavid S. Miller 12362fa8a84SDavid S. Miller /* This may only be invoked before the entry has reached global 12462fa8a84SDavid S. Miller * visibility. 12562fa8a84SDavid S. Miller */ 12662fa8a84SDavid S. Miller static inline void dst_init_metrics(struct dst_entry *dst, 12762fa8a84SDavid S. Miller const u32 *src_metrics, 12862fa8a84SDavid S. Miller bool read_only) 12962fa8a84SDavid S. Miller { 13062fa8a84SDavid S. Miller dst->_metrics = ((unsigned long) src_metrics) | 13162fa8a84SDavid S. Miller (read_only ? DST_METRICS_READ_ONLY : 0); 13262fa8a84SDavid S. Miller } 13362fa8a84SDavid S. Miller 13462fa8a84SDavid S. Miller static inline void dst_copy_metrics(struct dst_entry *dest, const struct dst_entry *src) 13562fa8a84SDavid S. Miller { 13662fa8a84SDavid S. Miller u32 *dst_metrics = dst_metrics_write_ptr(dest); 13762fa8a84SDavid S. Miller 13862fa8a84SDavid S. Miller if (dst_metrics) { 13962fa8a84SDavid S. Miller u32 *src_metrics = DST_METRICS_PTR(src); 14062fa8a84SDavid S. Miller 14162fa8a84SDavid S. Miller memcpy(dst_metrics, src_metrics, RTAX_MAX * sizeof(u32)); 14262fa8a84SDavid S. Miller } 14362fa8a84SDavid S. Miller } 14462fa8a84SDavid S. Miller 14562fa8a84SDavid S. Miller static inline u32 *dst_metrics_ptr(struct dst_entry *dst) 14662fa8a84SDavid S. Miller { 14762fa8a84SDavid S. Miller return DST_METRICS_PTR(dst); 14862fa8a84SDavid S. Miller } 14962fa8a84SDavid S. Miller 1501da177e4SLinus Torvalds static inline u32 1515170ae82SDavid S. Miller dst_metric_raw(const struct dst_entry *dst, const int metric) 1521da177e4SLinus Torvalds { 15362fa8a84SDavid S. Miller u32 *p = DST_METRICS_PTR(dst); 15462fa8a84SDavid S. Miller 15562fa8a84SDavid S. Miller return p[metric-1]; 156defb3519SDavid S. Miller } 157defb3519SDavid S. Miller 1585170ae82SDavid S. Miller static inline u32 1595170ae82SDavid S. Miller dst_metric(const struct dst_entry *dst, const int metric) 1605170ae82SDavid S. Miller { 1610dbaee3bSDavid S. Miller WARN_ON_ONCE(metric == RTAX_HOPLIMIT || 162d33e4553SDavid S. Miller metric == RTAX_ADVMSS || 163d33e4553SDavid S. Miller metric == RTAX_MTU); 1645170ae82SDavid S. Miller return dst_metric_raw(dst, metric); 1655170ae82SDavid S. Miller } 1665170ae82SDavid S. Miller 1670dbaee3bSDavid S. Miller static inline u32 1680dbaee3bSDavid S. Miller dst_metric_advmss(const struct dst_entry *dst) 1690dbaee3bSDavid S. Miller { 1700dbaee3bSDavid S. Miller u32 advmss = dst_metric_raw(dst, RTAX_ADVMSS); 1710dbaee3bSDavid S. Miller 1720dbaee3bSDavid S. Miller if (!advmss) 1730dbaee3bSDavid S. Miller advmss = dst->ops->default_advmss(dst); 1740dbaee3bSDavid S. Miller 1750dbaee3bSDavid S. Miller return advmss; 1760dbaee3bSDavid S. Miller } 1770dbaee3bSDavid S. Miller 178defb3519SDavid S. Miller static inline void dst_metric_set(struct dst_entry *dst, int metric, u32 val) 179defb3519SDavid S. Miller { 18062fa8a84SDavid S. Miller u32 *p = dst_metrics_write_ptr(dst); 181defb3519SDavid S. Miller 18262fa8a84SDavid S. Miller if (p) 18362fa8a84SDavid S. Miller p[metric-1] = val; 1841da177e4SLinus Torvalds } 1851da177e4SLinus Torvalds 186c3a8d947SDaniel Borkmann /* Kernel-internal feature bits that are unallocated in user space. */ 18740f6a2cbSVandana BN #define DST_FEATURE_ECN_CA (1U << 31) 188c3a8d947SDaniel Borkmann 189c3a8d947SDaniel Borkmann #define DST_FEATURE_MASK (DST_FEATURE_ECN_CA) 190c3a8d947SDaniel Borkmann #define DST_FEATURE_ECN_MASK (DST_FEATURE_ECN_CA | RTAX_FEATURE_ECN) 191c3a8d947SDaniel Borkmann 1920c3adfb8SGilad Ben-Yossef static inline u32 1930c3adfb8SGilad Ben-Yossef dst_feature(const struct dst_entry *dst, u32 feature) 1940c3adfb8SGilad Ben-Yossef { 195bb5b7c11SDavid S. Miller return dst_metric(dst, RTAX_FEATURES) & feature; 1960c3adfb8SGilad Ben-Yossef } 1970c3adfb8SGilad Ben-Yossef 198f67fbeaeSBrian Vazquez INDIRECT_CALLABLE_DECLARE(unsigned int ip6_mtu(const struct dst_entry *)); 199f67fbeaeSBrian Vazquez INDIRECT_CALLABLE_DECLARE(unsigned int ipv4_mtu(const struct dst_entry *)); 2001da177e4SLinus Torvalds static inline u32 dst_mtu(const struct dst_entry *dst) 2011da177e4SLinus Torvalds { 202f67fbeaeSBrian Vazquez return INDIRECT_CALL_INET(dst->ops->mtu, ip6_mtu, ipv4_mtu, dst); 2031da177e4SLinus Torvalds } 2041da177e4SLinus Torvalds 205c1e20f7cSStephen Hemminger /* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */ 206c1e20f7cSStephen Hemminger static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metric) 207c1e20f7cSStephen Hemminger { 208c1e20f7cSStephen Hemminger return msecs_to_jiffies(dst_metric(dst, metric)); 209c1e20f7cSStephen Hemminger } 210c1e20f7cSStephen Hemminger 2111da177e4SLinus Torvalds static inline u32 2121da177e4SLinus Torvalds dst_allfrag(const struct dst_entry *dst) 2131da177e4SLinus Torvalds { 2140c3adfb8SGilad Ben-Yossef int ret = dst_feature(dst, RTAX_FEATURE_ALLFRAG); 2151da177e4SLinus Torvalds return ret; 2161da177e4SLinus Torvalds } 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds static inline int 219d33e4553SDavid S. Miller dst_metric_locked(const struct dst_entry *dst, int metric) 2201da177e4SLinus Torvalds { 2211da177e4SLinus Torvalds return dst_metric(dst, RTAX_LOCK) & (1 << metric); 2221da177e4SLinus Torvalds } 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds static inline void dst_hold(struct dst_entry *dst) 2251da177e4SLinus Torvalds { 2265635c10dSEric Dumazet /* 2275635c10dSEric Dumazet * If your kernel compilation stops here, please check 2288b207e73SDavid Miller * the placement of __refcnt in struct dst_entry 2295635c10dSEric Dumazet */ 2305635c10dSEric Dumazet BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63); 23144ebe791SWei Wang WARN_ON(atomic_inc_not_zero(&dst->__refcnt) == 0); 2321da177e4SLinus Torvalds } 2331da177e4SLinus Torvalds 2340da4af00SWei Wang static inline void dst_use_noref(struct dst_entry *dst, unsigned long time) 23503f49f34SPavel Emelyanov { 23632d18ab1SPaolo Abeni if (unlikely(time != dst->lastuse)) { 23703f49f34SPavel Emelyanov dst->__use++; 23803f49f34SPavel Emelyanov dst->lastuse = time; 23903f49f34SPavel Emelyanov } 2400da4af00SWei Wang } 24103f49f34SPavel Emelyanov 2420da4af00SWei Wang static inline void dst_hold_and_use(struct dst_entry *dst, unsigned long time) 2437fee226aSEric Dumazet { 2440da4af00SWei Wang dst_hold(dst); 2450da4af00SWei Wang dst_use_noref(dst, time); 2467fee226aSEric Dumazet } 2477fee226aSEric Dumazet 2487f95e188SEldad Zack static inline struct dst_entry *dst_clone(struct dst_entry *dst) 2491da177e4SLinus Torvalds { 2501da177e4SLinus Torvalds if (dst) 251222d7dbdSEric Dumazet dst_hold(dst); 2521da177e4SLinus Torvalds return dst; 2531da177e4SLinus Torvalds } 2541da177e4SLinus Torvalds 255a4023dd0SJoe Perches void dst_release(struct dst_entry *dst); 2567fee226aSEric Dumazet 2575f56f409SWei Wang void dst_release_immediate(struct dst_entry *dst); 2585f56f409SWei Wang 2597fee226aSEric Dumazet static inline void refdst_drop(unsigned long refdst) 2607fee226aSEric Dumazet { 2617fee226aSEric Dumazet if (!(refdst & SKB_DST_NOREF)) 2627fee226aSEric Dumazet dst_release((struct dst_entry *)(refdst & SKB_DST_PTRMASK)); 2637fee226aSEric Dumazet } 2647fee226aSEric Dumazet 2657fee226aSEric Dumazet /** 2667fee226aSEric Dumazet * skb_dst_drop - drops skb dst 2677fee226aSEric Dumazet * @skb: buffer 2687fee226aSEric Dumazet * 2697fee226aSEric Dumazet * Drops dst reference count if a reference was taken. 2707fee226aSEric Dumazet */ 271adf30907SEric Dumazet static inline void skb_dst_drop(struct sk_buff *skb) 272adf30907SEric Dumazet { 2737fee226aSEric Dumazet if (skb->_skb_refdst) { 2747fee226aSEric Dumazet refdst_drop(skb->_skb_refdst); 2757fee226aSEric Dumazet skb->_skb_refdst = 0UL; 2767fee226aSEric Dumazet } 2777fee226aSEric Dumazet } 2787fee226aSEric Dumazet 279e79e2595SJoe Stringer static inline void __skb_dst_copy(struct sk_buff *nskb, unsigned long refdst) 2807fee226aSEric Dumazet { 2818a886b14SPaolo Abeni nskb->slow_gro |= !!refdst; 282e79e2595SJoe Stringer nskb->_skb_refdst = refdst; 2837fee226aSEric Dumazet if (!(nskb->_skb_refdst & SKB_DST_NOREF)) 2847fee226aSEric Dumazet dst_clone(skb_dst(nskb)); 2857fee226aSEric Dumazet } 2867fee226aSEric Dumazet 287e79e2595SJoe Stringer static inline void skb_dst_copy(struct sk_buff *nskb, const struct sk_buff *oskb) 288e79e2595SJoe Stringer { 289e79e2595SJoe Stringer __skb_dst_copy(nskb, oskb->_skb_refdst); 290e79e2595SJoe Stringer } 291e79e2595SJoe Stringer 2927fee226aSEric Dumazet /** 2935037e9efSEric Dumazet * dst_hold_safe - Take a reference on a dst if possible 2945037e9efSEric Dumazet * @dst: pointer to dst entry 2955037e9efSEric Dumazet * 2965037e9efSEric Dumazet * This helper returns false if it could not safely 2975037e9efSEric Dumazet * take a reference on a dst. 2985037e9efSEric Dumazet */ 2995037e9efSEric Dumazet static inline bool dst_hold_safe(struct dst_entry *dst) 3005037e9efSEric Dumazet { 3015037e9efSEric Dumazet return atomic_inc_not_zero(&dst->__refcnt); 3025037e9efSEric Dumazet } 3035037e9efSEric Dumazet 3045037e9efSEric Dumazet /** 305222d7dbdSEric Dumazet * skb_dst_force - makes sure skb dst is refcounted 3065037e9efSEric Dumazet * @skb: buffer 3075037e9efSEric Dumazet * 3085037e9efSEric Dumazet * If dst is not yet refcounted and not destroyed, grab a ref on it. 309b60a7738SFlorian Westphal * Returns true if dst is refcounted. 3105037e9efSEric Dumazet */ 311b60a7738SFlorian Westphal static inline bool skb_dst_force(struct sk_buff *skb) 3125037e9efSEric Dumazet { 3135037e9efSEric Dumazet if (skb_dst_is_noref(skb)) { 3145037e9efSEric Dumazet struct dst_entry *dst = skb_dst(skb); 3155037e9efSEric Dumazet 316222d7dbdSEric Dumazet WARN_ON(!rcu_read_lock_held()); 3175037e9efSEric Dumazet if (!dst_hold_safe(dst)) 3185037e9efSEric Dumazet dst = NULL; 3195037e9efSEric Dumazet 3205037e9efSEric Dumazet skb->_skb_refdst = (unsigned long)dst; 3218a886b14SPaolo Abeni skb->slow_gro |= !!dst; 3225037e9efSEric Dumazet } 323b60a7738SFlorian Westphal 324b60a7738SFlorian Westphal return skb->_skb_refdst != 0UL; 3255037e9efSEric Dumazet } 3265037e9efSEric Dumazet 327d19d56ddSEric Dumazet 328d19d56ddSEric Dumazet /** 329290b895eSEric Dumazet * __skb_tunnel_rx - prepare skb for rx reinsert 330290b895eSEric Dumazet * @skb: buffer 331290b895eSEric Dumazet * @dev: tunnel device 332ea23192eSNicolas Dichtel * @net: netns for packet i/o 333290b895eSEric Dumazet * 334290b895eSEric Dumazet * After decapsulation, packet is going to re-enter (netif_rx()) our stack, 335290b895eSEric Dumazet * so make some cleanups. (no accounting done) 336290b895eSEric Dumazet */ 337ea23192eSNicolas Dichtel static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev, 338ea23192eSNicolas Dichtel struct net *net) 339290b895eSEric Dumazet { 340290b895eSEric Dumazet skb->dev = dev; 341bdeab991STom Herbert 342bdeab991STom Herbert /* 3437539fadcSTom Herbert * Clear hash so that we can recalulate the hash for the 344bdeab991STom Herbert * encapsulated packet, unless we have already determine the hash 345bdeab991STom Herbert * over the L4 4-tuple. 346bdeab991STom Herbert */ 3477539fadcSTom Herbert skb_clear_hash_if_not_l4(skb); 348290b895eSEric Dumazet skb_set_queue_mapping(skb, 0); 349ea23192eSNicolas Dichtel skb_scrub_packet(skb, !net_eq(net, dev_net(dev))); 350290b895eSEric Dumazet } 351290b895eSEric Dumazet 352290b895eSEric Dumazet /** 353d19d56ddSEric Dumazet * skb_tunnel_rx - prepare skb for rx reinsert 354d19d56ddSEric Dumazet * @skb: buffer 355d19d56ddSEric Dumazet * @dev: tunnel device 3568eb1a859SJonathan Neuschäfer * @net: netns for packet i/o 357d19d56ddSEric Dumazet * 358d19d56ddSEric Dumazet * After decapsulation, packet is going to re-enter (netif_rx()) our stack, 359d19d56ddSEric Dumazet * so make some cleanups, and perform accounting. 360290b895eSEric Dumazet * Note: this accounting is not SMP safe. 361d19d56ddSEric Dumazet */ 362ea23192eSNicolas Dichtel static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev, 363ea23192eSNicolas Dichtel struct net *net) 364d19d56ddSEric Dumazet { 365d19d56ddSEric Dumazet /* TODO : stats should be SMP safe */ 366d19d56ddSEric Dumazet dev->stats.rx_packets++; 367d19d56ddSEric Dumazet dev->stats.rx_bytes += skb->len; 368ea23192eSNicolas Dichtel __skb_tunnel_rx(skb, dev, net); 369d19d56ddSEric Dumazet } 370d19d56ddSEric Dumazet 371808c1b69SDaniel Borkmann static inline u32 dst_tclassid(const struct sk_buff *skb) 372808c1b69SDaniel Borkmann { 373808c1b69SDaniel Borkmann #ifdef CONFIG_IP_ROUTE_CLASSID 374808c1b69SDaniel Borkmann const struct dst_entry *dst; 375808c1b69SDaniel Borkmann 376808c1b69SDaniel Borkmann dst = skb_dst(skb); 377808c1b69SDaniel Borkmann if (dst) 378808c1b69SDaniel Borkmann return dst->tclassid; 379808c1b69SDaniel Borkmann #endif 380808c1b69SDaniel Borkmann return 0; 381808c1b69SDaniel Borkmann } 382808c1b69SDaniel Borkmann 383ede2059dSEric W. Biederman int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb); 384aad88724SEric Dumazet static inline int dst_discard(struct sk_buff *skb) 385aad88724SEric Dumazet { 386ede2059dSEric W. Biederman return dst_discard_out(&init_net, skb->sk, skb); 387aad88724SEric Dumazet } 388a4023dd0SJoe Perches void *dst_alloc(struct dst_ops *ops, struct net_device *dev, int initial_ref, 389a4023dd0SJoe Perches int initial_obsolete, unsigned short flags); 390f38a9eb1SThomas Graf void dst_init(struct dst_entry *dst, struct dst_ops *ops, 391f38a9eb1SThomas Graf struct net_device *dev, int initial_ref, int initial_obsolete, 392f38a9eb1SThomas Graf unsigned short flags); 393a4023dd0SJoe Perches struct dst_entry *dst_destroy(struct dst_entry *dst); 3944a6ce2b6SWei Wang void dst_dev_put(struct dst_entry *dst); 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds static inline void dst_confirm(struct dst_entry *dst) 3971da177e4SLinus Torvalds { 39869cce1d1SDavid S. Miller } 3995110effeSDavid S. Miller 400d3aaeb38SDavid S. Miller static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr) 401d3aaeb38SDavid S. Miller { 402aaa0c23cSZhouyi Zhou struct neighbour *n = dst->ops->neigh_lookup(dst, NULL, daddr); 403aaa0c23cSZhouyi Zhou return IS_ERR(n) ? NULL : n; 404f894cbf8SDavid S. Miller } 405f894cbf8SDavid S. Miller 406f894cbf8SDavid S. Miller static inline struct neighbour *dst_neigh_lookup_skb(const struct dst_entry *dst, 407f894cbf8SDavid S. Miller struct sk_buff *skb) 408f894cbf8SDavid S. Miller { 4090992d67bSGuillaume Nault struct neighbour *n; 410394de110SMartin Varghese 4110992d67bSGuillaume Nault if (WARN_ON_ONCE(!dst->ops->neigh_lookup)) 4120992d67bSGuillaume Nault return NULL; 4130992d67bSGuillaume Nault 414394de110SMartin Varghese n = dst->ops->neigh_lookup(dst, skb, NULL); 415394de110SMartin Varghese 416aaa0c23cSZhouyi Zhou return IS_ERR(n) ? NULL : n; 417d3aaeb38SDavid S. Miller } 418d3aaeb38SDavid S. Miller 41963fca65dSJulian Anastasov static inline void dst_confirm_neigh(const struct dst_entry *dst, 42063fca65dSJulian Anastasov const void *daddr) 42163fca65dSJulian Anastasov { 42263fca65dSJulian Anastasov if (dst->ops->confirm_neigh) 42363fca65dSJulian Anastasov dst->ops->confirm_neigh(dst, daddr); 42463fca65dSJulian Anastasov } 42563fca65dSJulian Anastasov 4261da177e4SLinus Torvalds static inline void dst_link_failure(struct sk_buff *skb) 4271da177e4SLinus Torvalds { 428adf30907SEric Dumazet struct dst_entry *dst = skb_dst(skb); 4291da177e4SLinus Torvalds if (dst && dst->ops && dst->ops->link_failure) 4301da177e4SLinus Torvalds dst->ops->link_failure(skb); 4311da177e4SLinus Torvalds } 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds static inline void dst_set_expires(struct dst_entry *dst, int timeout) 4341da177e4SLinus Torvalds { 4351da177e4SLinus Torvalds unsigned long expires = jiffies + timeout; 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvalds if (expires == 0) 4381da177e4SLinus Torvalds expires = 1; 4391da177e4SLinus Torvalds 4401da177e4SLinus Torvalds if (dst->expires == 0 || time_before(expires, dst->expires)) 4411da177e4SLinus Torvalds dst->expires = expires; 4421da177e4SLinus Torvalds } 4431da177e4SLinus Torvalds 4446585d7dcSBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip6_output(struct net *, struct sock *, 4456585d7dcSBrian Vazquez struct sk_buff *)); 4466585d7dcSBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip_output(struct net *, struct sock *, 4476585d7dcSBrian Vazquez struct sk_buff *)); 4481da177e4SLinus Torvalds /* Output packet to network from transport. */ 44913206b6bSEric W. Biederman static inline int dst_output(struct net *net, struct sock *sk, struct sk_buff *skb) 450aad88724SEric Dumazet { 4516585d7dcSBrian Vazquez return INDIRECT_CALL_INET(skb_dst(skb)->output, 4526585d7dcSBrian Vazquez ip6_output, ip_output, 4536585d7dcSBrian Vazquez net, sk, skb); 454aad88724SEric Dumazet } 4551da177e4SLinus Torvalds 456e43b2190SBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip6_input(struct sk_buff *)); 457e43b2190SBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip_local_deliver(struct sk_buff *)); 4581da177e4SLinus Torvalds /* Input packet from network to transport. */ 4591da177e4SLinus Torvalds static inline int dst_input(struct sk_buff *skb) 4601da177e4SLinus Torvalds { 461e43b2190SBrian Vazquez return INDIRECT_CALL_INET(skb_dst(skb)->input, 462e43b2190SBrian Vazquez ip6_input, ip_local_deliver, skb); 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds 465bbd807dfSBrian Vazquez INDIRECT_CALLABLE_DECLARE(struct dst_entry *ip6_dst_check(struct dst_entry *, 466bbd807dfSBrian Vazquez u32)); 467bbd807dfSBrian Vazquez INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *, 468bbd807dfSBrian Vazquez u32)); 4691da177e4SLinus Torvalds static inline struct dst_entry *dst_check(struct dst_entry *dst, u32 cookie) 4701da177e4SLinus Torvalds { 4711da177e4SLinus Torvalds if (dst->obsolete) 472bbd807dfSBrian Vazquez dst = INDIRECT_CALL_INET(dst->ops->check, ip6_dst_check, 473bbd807dfSBrian Vazquez ipv4_dst_check, dst, cookie); 4741da177e4SLinus Torvalds return dst; 4751da177e4SLinus Torvalds } 4761da177e4SLinus Torvalds 477815f4e57SHerbert Xu /* Flags for xfrm_lookup flags argument. */ 478815f4e57SHerbert Xu enum { 47980c0bc9eSDavid S. Miller XFRM_LOOKUP_ICMP = 1 << 0, 480b8c203b2SSteffen Klassert XFRM_LOOKUP_QUEUE = 1 << 1, 481ac37e251Shuaibin Wang XFRM_LOOKUP_KEEP_DST_REF = 1 << 2, 482815f4e57SHerbert Xu }; 483815f4e57SHerbert Xu 4841da177e4SLinus Torvalds struct flowi; 4851da177e4SLinus Torvalds #ifndef CONFIG_XFRM 486452edd59SDavid S. Miller static inline struct dst_entry *xfrm_lookup(struct net *net, 487452edd59SDavid S. Miller struct dst_entry *dst_orig, 4886f9c9615SEric Dumazet const struct flowi *fl, 4896f9c9615SEric Dumazet const struct sock *sk, 490dee9f4bcSDavid S. Miller int flags) 4911da177e4SLinus Torvalds { 492452edd59SDavid S. Miller return dst_orig; 4931da177e4SLinus Torvalds } 494e87b3998SVlad Yasevich 495bc56b334SBenedict Wong static inline struct dst_entry * 496bc56b334SBenedict Wong xfrm_lookup_with_ifid(struct net *net, struct dst_entry *dst_orig, 497bc56b334SBenedict Wong const struct flowi *fl, const struct sock *sk, 498bc56b334SBenedict Wong int flags, u32 if_id) 499bc56b334SBenedict Wong { 500bc56b334SBenedict Wong return dst_orig; 501bc56b334SBenedict Wong } 502bc56b334SBenedict Wong 503f92ee619SSteffen Klassert static inline struct dst_entry *xfrm_lookup_route(struct net *net, 504f92ee619SSteffen Klassert struct dst_entry *dst_orig, 505f92ee619SSteffen Klassert const struct flowi *fl, 5066f9c9615SEric Dumazet const struct sock *sk, 507f92ee619SSteffen Klassert int flags) 508f92ee619SSteffen Klassert { 509f92ee619SSteffen Klassert return dst_orig; 510f92ee619SSteffen Klassert } 511f92ee619SSteffen Klassert 512e87b3998SVlad Yasevich static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst) 513e87b3998SVlad Yasevich { 514e87b3998SVlad Yasevich return NULL; 515e87b3998SVlad Yasevich } 516e87b3998SVlad Yasevich 5171da177e4SLinus Torvalds #else 518a4023dd0SJoe Perches struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, 5196f9c9615SEric Dumazet const struct flowi *fl, const struct sock *sk, 520452edd59SDavid S. Miller int flags); 521e87b3998SVlad Yasevich 522bc56b334SBenedict Wong struct dst_entry *xfrm_lookup_with_ifid(struct net *net, 523bc56b334SBenedict Wong struct dst_entry *dst_orig, 524bc56b334SBenedict Wong const struct flowi *fl, 525bc56b334SBenedict Wong const struct sock *sk, int flags, 526bc56b334SBenedict Wong u32 if_id); 527bc56b334SBenedict Wong 528f92ee619SSteffen Klassert struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig, 5296f9c9615SEric Dumazet const struct flowi *fl, const struct sock *sk, 530f92ee619SSteffen Klassert int flags); 531f92ee619SSteffen Klassert 532e87b3998SVlad Yasevich /* skb attached with this dst needs transformation if dst->xfrm is valid */ 533e87b3998SVlad Yasevich static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst) 534e87b3998SVlad Yasevich { 535e87b3998SVlad Yasevich return dst->xfrm; 536e87b3998SVlad Yasevich } 5371da177e4SLinus Torvalds #endif 5381da177e4SLinus Torvalds 539f15ca723SNicolas Dichtel static inline void skb_dst_update_pmtu(struct sk_buff *skb, u32 mtu) 540f15ca723SNicolas Dichtel { 541f15ca723SNicolas Dichtel struct dst_entry *dst = skb_dst(skb); 542f15ca723SNicolas Dichtel 543f15ca723SNicolas Dichtel if (dst && dst->ops->update_pmtu) 544bd085ef6SHangbin Liu dst->ops->update_pmtu(dst, NULL, skb, mtu, true); 545f15ca723SNicolas Dichtel } 546f15ca723SNicolas Dichtel 54707dc35c6SHangbin Liu /* update dst pmtu but not do neighbor confirm */ 54807dc35c6SHangbin Liu static inline void skb_dst_update_pmtu_no_confirm(struct sk_buff *skb, u32 mtu) 54907dc35c6SHangbin Liu { 55007dc35c6SHangbin Liu struct dst_entry *dst = skb_dst(skb); 55107dc35c6SHangbin Liu 55207dc35c6SHangbin Liu if (dst && dst->ops->update_pmtu) 55307dc35c6SHangbin Liu dst->ops->update_pmtu(dst, NULL, skb, mtu, false); 55407dc35c6SHangbin Liu } 55507dc35c6SHangbin Liu 556c4c877b2SDaniel Borkmann struct dst_entry *dst_blackhole_check(struct dst_entry *dst, u32 cookie); 557c4c877b2SDaniel Borkmann void dst_blackhole_update_pmtu(struct dst_entry *dst, struct sock *sk, 558c4c877b2SDaniel Borkmann struct sk_buff *skb, u32 mtu, bool confirm_neigh); 559c4c877b2SDaniel Borkmann void dst_blackhole_redirect(struct dst_entry *dst, struct sock *sk, 560c4c877b2SDaniel Borkmann struct sk_buff *skb); 561c4c877b2SDaniel Borkmann u32 *dst_blackhole_cow_metrics(struct dst_entry *dst, unsigned long old); 562c4c877b2SDaniel Borkmann struct neighbour *dst_blackhole_neigh_lookup(const struct dst_entry *dst, 563c4c877b2SDaniel Borkmann struct sk_buff *skb, 564c4c877b2SDaniel Borkmann const void *daddr); 565c4c877b2SDaniel Borkmann unsigned int dst_blackhole_mtu(const struct dst_entry *dst); 566c4c877b2SDaniel Borkmann 5671da177e4SLinus Torvalds #endif /* _NET_DST_H */ 568