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 197f67fbeaeSBrian Vazquez INDIRECT_CALLABLE_DECLARE(unsigned int ip6_mtu(const struct dst_entry *)); 198f67fbeaeSBrian Vazquez INDIRECT_CALLABLE_DECLARE(unsigned int ipv4_mtu(const struct dst_entry *)); 1991da177e4SLinus Torvalds static inline u32 dst_mtu(const struct dst_entry *dst) 2001da177e4SLinus Torvalds { 201f67fbeaeSBrian Vazquez return INDIRECT_CALL_INET(dst->ops->mtu, ip6_mtu, ipv4_mtu, dst); 2021da177e4SLinus Torvalds } 2031da177e4SLinus Torvalds 204c1e20f7cSStephen Hemminger /* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */ 205c1e20f7cSStephen Hemminger static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metric) 206c1e20f7cSStephen Hemminger { 207c1e20f7cSStephen Hemminger return msecs_to_jiffies(dst_metric(dst, metric)); 208c1e20f7cSStephen Hemminger } 209c1e20f7cSStephen Hemminger 2101da177e4SLinus Torvalds static inline u32 2111da177e4SLinus Torvalds dst_allfrag(const struct dst_entry *dst) 2121da177e4SLinus Torvalds { 2130c3adfb8SGilad Ben-Yossef int ret = dst_feature(dst, RTAX_FEATURE_ALLFRAG); 2141da177e4SLinus Torvalds return ret; 2151da177e4SLinus Torvalds } 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds static inline int 218d33e4553SDavid S. Miller dst_metric_locked(const struct dst_entry *dst, int metric) 2191da177e4SLinus Torvalds { 2201da177e4SLinus Torvalds return dst_metric(dst, RTAX_LOCK) & (1 << metric); 2211da177e4SLinus Torvalds } 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds static inline void dst_hold(struct dst_entry *dst) 2241da177e4SLinus Torvalds { 2255635c10dSEric Dumazet /* 2265635c10dSEric Dumazet * If your kernel compilation stops here, please check 2278b207e73SDavid Miller * the placement of __refcnt in struct dst_entry 2285635c10dSEric Dumazet */ 2295635c10dSEric Dumazet BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63); 23044ebe791SWei Wang WARN_ON(atomic_inc_not_zero(&dst->__refcnt) == 0); 2311da177e4SLinus Torvalds } 2321da177e4SLinus Torvalds 2330da4af00SWei Wang static inline void dst_use_noref(struct dst_entry *dst, unsigned long time) 23403f49f34SPavel Emelyanov { 23532d18ab1SPaolo Abeni if (unlikely(time != dst->lastuse)) { 23603f49f34SPavel Emelyanov dst->__use++; 23703f49f34SPavel Emelyanov dst->lastuse = time; 23803f49f34SPavel Emelyanov } 2390da4af00SWei Wang } 24003f49f34SPavel Emelyanov 2410da4af00SWei Wang static inline void dst_hold_and_use(struct dst_entry *dst, unsigned long time) 2427fee226aSEric Dumazet { 2430da4af00SWei Wang dst_hold(dst); 2440da4af00SWei Wang dst_use_noref(dst, time); 2457fee226aSEric Dumazet } 2467fee226aSEric Dumazet 2477f95e188SEldad Zack static inline struct dst_entry *dst_clone(struct dst_entry *dst) 2481da177e4SLinus Torvalds { 2491da177e4SLinus Torvalds if (dst) 250222d7dbdSEric Dumazet dst_hold(dst); 2511da177e4SLinus Torvalds return dst; 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds 254a4023dd0SJoe Perches void dst_release(struct dst_entry *dst); 2557fee226aSEric Dumazet 2565f56f409SWei Wang void dst_release_immediate(struct dst_entry *dst); 2575f56f409SWei Wang 2587fee226aSEric Dumazet static inline void refdst_drop(unsigned long refdst) 2597fee226aSEric Dumazet { 2607fee226aSEric Dumazet if (!(refdst & SKB_DST_NOREF)) 2617fee226aSEric Dumazet dst_release((struct dst_entry *)(refdst & SKB_DST_PTRMASK)); 2627fee226aSEric Dumazet } 2637fee226aSEric Dumazet 2647fee226aSEric Dumazet /** 2657fee226aSEric Dumazet * skb_dst_drop - drops skb dst 2667fee226aSEric Dumazet * @skb: buffer 2677fee226aSEric Dumazet * 2687fee226aSEric Dumazet * Drops dst reference count if a reference was taken. 2697fee226aSEric Dumazet */ 270adf30907SEric Dumazet static inline void skb_dst_drop(struct sk_buff *skb) 271adf30907SEric Dumazet { 2727fee226aSEric Dumazet if (skb->_skb_refdst) { 2737fee226aSEric Dumazet refdst_drop(skb->_skb_refdst); 2747fee226aSEric Dumazet skb->_skb_refdst = 0UL; 2757fee226aSEric Dumazet } 2767fee226aSEric Dumazet } 2777fee226aSEric Dumazet 278e79e2595SJoe Stringer static inline void __skb_dst_copy(struct sk_buff *nskb, unsigned long refdst) 2797fee226aSEric Dumazet { 280e79e2595SJoe Stringer nskb->_skb_refdst = refdst; 2817fee226aSEric Dumazet if (!(nskb->_skb_refdst & SKB_DST_NOREF)) 2827fee226aSEric Dumazet dst_clone(skb_dst(nskb)); 2837fee226aSEric Dumazet } 2847fee226aSEric Dumazet 285e79e2595SJoe Stringer static inline void skb_dst_copy(struct sk_buff *nskb, const struct sk_buff *oskb) 286e79e2595SJoe Stringer { 287e79e2595SJoe Stringer __skb_dst_copy(nskb, oskb->_skb_refdst); 288e79e2595SJoe Stringer } 289e79e2595SJoe Stringer 2907fee226aSEric Dumazet /** 2915037e9efSEric Dumazet * dst_hold_safe - Take a reference on a dst if possible 2925037e9efSEric Dumazet * @dst: pointer to dst entry 2935037e9efSEric Dumazet * 2945037e9efSEric Dumazet * This helper returns false if it could not safely 2955037e9efSEric Dumazet * take a reference on a dst. 2965037e9efSEric Dumazet */ 2975037e9efSEric Dumazet static inline bool dst_hold_safe(struct dst_entry *dst) 2985037e9efSEric Dumazet { 2995037e9efSEric Dumazet return atomic_inc_not_zero(&dst->__refcnt); 3005037e9efSEric Dumazet } 3015037e9efSEric Dumazet 3025037e9efSEric Dumazet /** 303222d7dbdSEric Dumazet * skb_dst_force - makes sure skb dst is refcounted 3045037e9efSEric Dumazet * @skb: buffer 3055037e9efSEric Dumazet * 3065037e9efSEric Dumazet * If dst is not yet refcounted and not destroyed, grab a ref on it. 307b60a7738SFlorian Westphal * Returns true if dst is refcounted. 3085037e9efSEric Dumazet */ 309b60a7738SFlorian Westphal static inline bool skb_dst_force(struct sk_buff *skb) 3105037e9efSEric Dumazet { 3115037e9efSEric Dumazet if (skb_dst_is_noref(skb)) { 3125037e9efSEric Dumazet struct dst_entry *dst = skb_dst(skb); 3135037e9efSEric Dumazet 314222d7dbdSEric Dumazet WARN_ON(!rcu_read_lock_held()); 3155037e9efSEric Dumazet if (!dst_hold_safe(dst)) 3165037e9efSEric Dumazet dst = NULL; 3175037e9efSEric Dumazet 3185037e9efSEric Dumazet skb->_skb_refdst = (unsigned long)dst; 3195037e9efSEric Dumazet } 320b60a7738SFlorian Westphal 321b60a7738SFlorian Westphal return skb->_skb_refdst != 0UL; 3225037e9efSEric Dumazet } 3235037e9efSEric Dumazet 324d19d56ddSEric Dumazet 325d19d56ddSEric Dumazet /** 326290b895eSEric Dumazet * __skb_tunnel_rx - prepare skb for rx reinsert 327290b895eSEric Dumazet * @skb: buffer 328290b895eSEric Dumazet * @dev: tunnel device 329ea23192eSNicolas Dichtel * @net: netns for packet i/o 330290b895eSEric Dumazet * 331290b895eSEric Dumazet * After decapsulation, packet is going to re-enter (netif_rx()) our stack, 332290b895eSEric Dumazet * so make some cleanups. (no accounting done) 333290b895eSEric Dumazet */ 334ea23192eSNicolas Dichtel static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev, 335ea23192eSNicolas Dichtel struct net *net) 336290b895eSEric Dumazet { 337290b895eSEric Dumazet skb->dev = dev; 338bdeab991STom Herbert 339bdeab991STom Herbert /* 3407539fadcSTom Herbert * Clear hash so that we can recalulate the hash for the 341bdeab991STom Herbert * encapsulated packet, unless we have already determine the hash 342bdeab991STom Herbert * over the L4 4-tuple. 343bdeab991STom Herbert */ 3447539fadcSTom Herbert skb_clear_hash_if_not_l4(skb); 345290b895eSEric Dumazet skb_set_queue_mapping(skb, 0); 346ea23192eSNicolas Dichtel skb_scrub_packet(skb, !net_eq(net, dev_net(dev))); 347290b895eSEric Dumazet } 348290b895eSEric Dumazet 349290b895eSEric Dumazet /** 350d19d56ddSEric Dumazet * skb_tunnel_rx - prepare skb for rx reinsert 351d19d56ddSEric Dumazet * @skb: buffer 352d19d56ddSEric Dumazet * @dev: tunnel device 3538eb1a859SJonathan Neuschäfer * @net: netns for packet i/o 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 368808c1b69SDaniel Borkmann static inline u32 dst_tclassid(const struct sk_buff *skb) 369808c1b69SDaniel Borkmann { 370808c1b69SDaniel Borkmann #ifdef CONFIG_IP_ROUTE_CLASSID 371808c1b69SDaniel Borkmann const struct dst_entry *dst; 372808c1b69SDaniel Borkmann 373808c1b69SDaniel Borkmann dst = skb_dst(skb); 374808c1b69SDaniel Borkmann if (dst) 375808c1b69SDaniel Borkmann return dst->tclassid; 376808c1b69SDaniel Borkmann #endif 377808c1b69SDaniel Borkmann return 0; 378808c1b69SDaniel Borkmann } 379808c1b69SDaniel Borkmann 380ede2059dSEric W. Biederman int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb); 381aad88724SEric Dumazet static inline int dst_discard(struct sk_buff *skb) 382aad88724SEric Dumazet { 383ede2059dSEric W. Biederman return dst_discard_out(&init_net, skb->sk, skb); 384aad88724SEric Dumazet } 385a4023dd0SJoe Perches void *dst_alloc(struct dst_ops *ops, struct net_device *dev, int initial_ref, 386a4023dd0SJoe Perches int initial_obsolete, unsigned short flags); 387f38a9eb1SThomas Graf void dst_init(struct dst_entry *dst, struct dst_ops *ops, 388f38a9eb1SThomas Graf struct net_device *dev, int initial_ref, int initial_obsolete, 389f38a9eb1SThomas Graf unsigned short flags); 390a4023dd0SJoe Perches struct dst_entry *dst_destroy(struct dst_entry *dst); 3914a6ce2b6SWei Wang void dst_dev_put(struct dst_entry *dst); 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds static inline void dst_confirm(struct dst_entry *dst) 3941da177e4SLinus Torvalds { 39569cce1d1SDavid S. Miller } 3965110effeSDavid S. Miller 397d3aaeb38SDavid S. Miller static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr) 398d3aaeb38SDavid S. Miller { 399aaa0c23cSZhouyi Zhou struct neighbour *n = dst->ops->neigh_lookup(dst, NULL, daddr); 400aaa0c23cSZhouyi Zhou return IS_ERR(n) ? NULL : n; 401f894cbf8SDavid S. Miller } 402f894cbf8SDavid S. Miller 403f894cbf8SDavid S. Miller static inline struct neighbour *dst_neigh_lookup_skb(const struct dst_entry *dst, 404f894cbf8SDavid S. Miller struct sk_buff *skb) 405f894cbf8SDavid S. Miller { 4060992d67bSGuillaume Nault struct neighbour *n; 407394de110SMartin Varghese 4080992d67bSGuillaume Nault if (WARN_ON_ONCE(!dst->ops->neigh_lookup)) 4090992d67bSGuillaume Nault return NULL; 4100992d67bSGuillaume Nault 411394de110SMartin Varghese n = dst->ops->neigh_lookup(dst, skb, NULL); 412394de110SMartin Varghese 413aaa0c23cSZhouyi Zhou return IS_ERR(n) ? NULL : n; 414d3aaeb38SDavid S. Miller } 415d3aaeb38SDavid S. Miller 41663fca65dSJulian Anastasov static inline void dst_confirm_neigh(const struct dst_entry *dst, 41763fca65dSJulian Anastasov const void *daddr) 41863fca65dSJulian Anastasov { 41963fca65dSJulian Anastasov if (dst->ops->confirm_neigh) 42063fca65dSJulian Anastasov dst->ops->confirm_neigh(dst, daddr); 42163fca65dSJulian Anastasov } 42263fca65dSJulian Anastasov 4231da177e4SLinus Torvalds static inline void dst_link_failure(struct sk_buff *skb) 4241da177e4SLinus Torvalds { 425adf30907SEric Dumazet struct dst_entry *dst = skb_dst(skb); 4261da177e4SLinus Torvalds if (dst && dst->ops && dst->ops->link_failure) 4271da177e4SLinus Torvalds dst->ops->link_failure(skb); 4281da177e4SLinus Torvalds } 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds static inline void dst_set_expires(struct dst_entry *dst, int timeout) 4311da177e4SLinus Torvalds { 4321da177e4SLinus Torvalds unsigned long expires = jiffies + timeout; 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds if (expires == 0) 4351da177e4SLinus Torvalds expires = 1; 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvalds if (dst->expires == 0 || time_before(expires, dst->expires)) 4381da177e4SLinus Torvalds dst->expires = expires; 4391da177e4SLinus Torvalds } 4401da177e4SLinus Torvalds 4416585d7dcSBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip6_output(struct net *, struct sock *, 4426585d7dcSBrian Vazquez struct sk_buff *)); 4436585d7dcSBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip_output(struct net *, struct sock *, 4446585d7dcSBrian Vazquez struct sk_buff *)); 4451da177e4SLinus Torvalds /* Output packet to network from transport. */ 44613206b6bSEric W. Biederman static inline int dst_output(struct net *net, struct sock *sk, struct sk_buff *skb) 447aad88724SEric Dumazet { 4486585d7dcSBrian Vazquez return INDIRECT_CALL_INET(skb_dst(skb)->output, 4496585d7dcSBrian Vazquez ip6_output, ip_output, 4506585d7dcSBrian Vazquez net, sk, skb); 451aad88724SEric Dumazet } 4521da177e4SLinus Torvalds 453e43b2190SBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip6_input(struct sk_buff *)); 454e43b2190SBrian Vazquez INDIRECT_CALLABLE_DECLARE(int ip_local_deliver(struct sk_buff *)); 4551da177e4SLinus Torvalds /* Input packet from network to transport. */ 4561da177e4SLinus Torvalds static inline int dst_input(struct sk_buff *skb) 4571da177e4SLinus Torvalds { 458e43b2190SBrian Vazquez return INDIRECT_CALL_INET(skb_dst(skb)->input, 459e43b2190SBrian Vazquez ip6_input, ip_local_deliver, skb); 4601da177e4SLinus Torvalds } 4611da177e4SLinus Torvalds 462*bbd807dfSBrian Vazquez INDIRECT_CALLABLE_DECLARE(struct dst_entry *ip6_dst_check(struct dst_entry *, 463*bbd807dfSBrian Vazquez u32)); 464*bbd807dfSBrian Vazquez INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *, 465*bbd807dfSBrian Vazquez u32)); 4661da177e4SLinus Torvalds static inline struct dst_entry *dst_check(struct dst_entry *dst, u32 cookie) 4671da177e4SLinus Torvalds { 4681da177e4SLinus Torvalds if (dst->obsolete) 469*bbd807dfSBrian Vazquez dst = INDIRECT_CALL_INET(dst->ops->check, ip6_dst_check, 470*bbd807dfSBrian Vazquez ipv4_dst_check, dst, cookie); 4711da177e4SLinus Torvalds return dst; 4721da177e4SLinus Torvalds } 4731da177e4SLinus Torvalds 474815f4e57SHerbert Xu /* Flags for xfrm_lookup flags argument. */ 475815f4e57SHerbert Xu enum { 47680c0bc9eSDavid S. Miller XFRM_LOOKUP_ICMP = 1 << 0, 477b8c203b2SSteffen Klassert XFRM_LOOKUP_QUEUE = 1 << 1, 478ac37e251Shuaibin Wang XFRM_LOOKUP_KEEP_DST_REF = 1 << 2, 479815f4e57SHerbert Xu }; 480815f4e57SHerbert Xu 4811da177e4SLinus Torvalds struct flowi; 4821da177e4SLinus Torvalds #ifndef CONFIG_XFRM 483452edd59SDavid S. Miller static inline struct dst_entry *xfrm_lookup(struct net *net, 484452edd59SDavid S. Miller struct dst_entry *dst_orig, 4856f9c9615SEric Dumazet const struct flowi *fl, 4866f9c9615SEric Dumazet const struct sock *sk, 487dee9f4bcSDavid S. Miller int flags) 4881da177e4SLinus Torvalds { 489452edd59SDavid S. Miller return dst_orig; 4901da177e4SLinus Torvalds } 491e87b3998SVlad Yasevich 492bc56b334SBenedict Wong static inline struct dst_entry * 493bc56b334SBenedict Wong xfrm_lookup_with_ifid(struct net *net, struct dst_entry *dst_orig, 494bc56b334SBenedict Wong const struct flowi *fl, const struct sock *sk, 495bc56b334SBenedict Wong int flags, u32 if_id) 496bc56b334SBenedict Wong { 497bc56b334SBenedict Wong return dst_orig; 498bc56b334SBenedict Wong } 499bc56b334SBenedict Wong 500f92ee619SSteffen Klassert static inline struct dst_entry *xfrm_lookup_route(struct net *net, 501f92ee619SSteffen Klassert struct dst_entry *dst_orig, 502f92ee619SSteffen Klassert const struct flowi *fl, 5036f9c9615SEric Dumazet const struct sock *sk, 504f92ee619SSteffen Klassert int flags) 505f92ee619SSteffen Klassert { 506f92ee619SSteffen Klassert return dst_orig; 507f92ee619SSteffen Klassert } 508f92ee619SSteffen Klassert 509e87b3998SVlad Yasevich static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst) 510e87b3998SVlad Yasevich { 511e87b3998SVlad Yasevich return NULL; 512e87b3998SVlad Yasevich } 513e87b3998SVlad Yasevich 5141da177e4SLinus Torvalds #else 515a4023dd0SJoe Perches struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, 5166f9c9615SEric Dumazet const struct flowi *fl, const struct sock *sk, 517452edd59SDavid S. Miller int flags); 518e87b3998SVlad Yasevich 519bc56b334SBenedict Wong struct dst_entry *xfrm_lookup_with_ifid(struct net *net, 520bc56b334SBenedict Wong struct dst_entry *dst_orig, 521bc56b334SBenedict Wong const struct flowi *fl, 522bc56b334SBenedict Wong const struct sock *sk, int flags, 523bc56b334SBenedict Wong u32 if_id); 524bc56b334SBenedict Wong 525f92ee619SSteffen Klassert struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig, 5266f9c9615SEric Dumazet const struct flowi *fl, const struct sock *sk, 527f92ee619SSteffen Klassert int flags); 528f92ee619SSteffen Klassert 529e87b3998SVlad Yasevich /* skb attached with this dst needs transformation if dst->xfrm is valid */ 530e87b3998SVlad Yasevich static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst) 531e87b3998SVlad Yasevich { 532e87b3998SVlad Yasevich return dst->xfrm; 533e87b3998SVlad Yasevich } 5341da177e4SLinus Torvalds #endif 5351da177e4SLinus Torvalds 536f15ca723SNicolas Dichtel static inline void skb_dst_update_pmtu(struct sk_buff *skb, u32 mtu) 537f15ca723SNicolas Dichtel { 538f15ca723SNicolas Dichtel struct dst_entry *dst = skb_dst(skb); 539f15ca723SNicolas Dichtel 540f15ca723SNicolas Dichtel if (dst && dst->ops->update_pmtu) 541bd085ef6SHangbin Liu dst->ops->update_pmtu(dst, NULL, skb, mtu, true); 542f15ca723SNicolas Dichtel } 543f15ca723SNicolas Dichtel 54407dc35c6SHangbin Liu /* update dst pmtu but not do neighbor confirm */ 54507dc35c6SHangbin Liu static inline void skb_dst_update_pmtu_no_confirm(struct sk_buff *skb, u32 mtu) 54607dc35c6SHangbin Liu { 54707dc35c6SHangbin Liu struct dst_entry *dst = skb_dst(skb); 54807dc35c6SHangbin Liu 54907dc35c6SHangbin Liu if (dst && dst->ops->update_pmtu) 55007dc35c6SHangbin Liu dst->ops->update_pmtu(dst, NULL, skb, mtu, false); 55107dc35c6SHangbin Liu } 55207dc35c6SHangbin Liu 5531da177e4SLinus Torvalds #endif /* _NET_DST_H */ 554