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> 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds struct sk_buff; 231da177e4SLinus Torvalds 24fd2c3ef7SEric Dumazet struct dst_entry { 2566727145SAlexey Dobriyan struct net_device *dev; 2662fa8a84SDavid S. Miller struct dst_ops *ops; 2762fa8a84SDavid S. Miller unsigned long _metrics; 281da177e4SLinus Torvalds unsigned long expires; 29def8b4faSAlexey Dobriyan #ifdef CONFIG_XFRM 301da177e4SLinus Torvalds struct xfrm_state *xfrm; 315635c10dSEric Dumazet #else 325635c10dSEric Dumazet void *__pad1; 33def8b4faSAlexey Dobriyan #endif 341da177e4SLinus Torvalds int (*input)(struct sk_buff *); 35ede2059dSEric W. Biederman int (*output)(struct net *net, struct sock *sk, struct sk_buff *skb); 361da177e4SLinus Torvalds 375110effeSDavid S. Miller unsigned short flags; 38f6b72b62SDavid S. Miller #define DST_NOXFRM 0x0002 39f6b72b62SDavid S. Miller #define DST_NOPOLICY 0x0004 401eb04e7cSWei Wang #define DST_NOCOUNT 0x0008 411eb04e7cSWei Wang #define DST_FAKE_RTABLE 0x0010 421eb04e7cSWei Wang #define DST_XFRM_TUNNEL 0x0020 431eb04e7cSWei Wang #define DST_XFRM_QUEUE 0x0040 441eb04e7cSWei Wang #define DST_METADATA 0x0080 45f6b72b62SDavid S. Miller 46f5b0a874SDavid S. Miller /* A non-zero value of dst->obsolete forces by-hand validation 47f5b0a874SDavid S. Miller * of the route entry. Positive values are set by the generic 48f5b0a874SDavid S. Miller * dst layer to indicate that the entry has been forcefully 49f5b0a874SDavid S. Miller * destroyed. 50f5b0a874SDavid S. Miller * 51f5b0a874SDavid S. Miller * Negative values are used by the implementation layer code to 52f5b0a874SDavid S. Miller * force invocation of the dst_ops->check() method. 53f5b0a874SDavid S. Miller */ 5462fa8a84SDavid S. Miller short obsolete; 55f5b0a874SDavid S. Miller #define DST_OBSOLETE_NONE 0 56f5b0a874SDavid S. Miller #define DST_OBSOLETE_DEAD 2 57f5b0a874SDavid S. Miller #define DST_OBSOLETE_FORCE_CHK -1 58ceb33206SDavid S. Miller #define DST_OBSOLETE_KILL -2 5962fa8a84SDavid S. Miller unsigned short header_len; /* more space at head required */ 6062fa8a84SDavid S. Miller unsigned short trailer_len; /* space to reserve at tail */ 6151ce8bd4SJulian Anastasov 62f1dd9c37SZhang Yanmin /* 63f1dd9c37SZhang Yanmin * __refcnt wants to be on a different cache line from 64f1dd9c37SZhang Yanmin * input/output/ops or performance tanks badly 65f1dd9c37SZhang Yanmin */ 668b207e73SDavid Miller #ifdef CONFIG_64BIT 678b207e73SDavid Miller atomic_t __refcnt; /* 64-bit offset 64 */ 688b207e73SDavid Miller #endif 691e19e02cSEric Dumazet int __use; 70f1dd9c37SZhang Yanmin unsigned long lastuse; 71751a587aSJiri Benc struct lwtunnel_state *lwtstate; 728b207e73SDavid Miller struct rcu_head rcu_head; 738b207e73SDavid Miller short error; 748b207e73SDavid Miller short __pad; 758b207e73SDavid Miller __u32 tclassid; 768b207e73SDavid Miller #ifndef CONFIG_64BIT 778b207e73SDavid Miller atomic_t __refcnt; /* 32-bit offset 64 */ 788b207e73SDavid Miller #endif 791da177e4SLinus Torvalds }; 801da177e4SLinus Torvalds 813fb07dafSEric Dumazet struct dst_metrics { 823fb07dafSEric Dumazet u32 metrics[RTAX_MAX]; 839620fef2SEric Dumazet refcount_t refcnt; 84258a980dSGeert Uytterhoeven } __aligned(4); /* Low pointer bits contain DST_METRICS_FLAGS */ 853fb07dafSEric Dumazet extern const struct dst_metrics dst_default_metrics; 863fb07dafSEric Dumazet 87a4023dd0SJoe Perches u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old); 8862fa8a84SDavid S. Miller 8962fa8a84SDavid S. Miller #define DST_METRICS_READ_ONLY 0x1UL 903fb07dafSEric Dumazet #define DST_METRICS_REFCOUNTED 0x2UL 91e5fd387aSMichal Kubeček #define DST_METRICS_FLAGS 0x3UL 9262fa8a84SDavid S. Miller #define __DST_METRICS_PTR(Y) \ 93e5fd387aSMichal Kubeček ((u32 *)((Y) & ~DST_METRICS_FLAGS)) 9462fa8a84SDavid S. Miller #define DST_METRICS_PTR(X) __DST_METRICS_PTR((X)->_metrics) 9562fa8a84SDavid S. Miller 9662fa8a84SDavid S. Miller static inline bool dst_metrics_read_only(const struct dst_entry *dst) 9762fa8a84SDavid S. Miller { 9862fa8a84SDavid S. Miller return dst->_metrics & DST_METRICS_READ_ONLY; 9962fa8a84SDavid S. Miller } 10062fa8a84SDavid S. Miller 101a4023dd0SJoe Perches void __dst_destroy_metrics_generic(struct dst_entry *dst, unsigned long old); 10262fa8a84SDavid S. Miller 10362fa8a84SDavid S. Miller static inline void dst_destroy_metrics_generic(struct dst_entry *dst) 10462fa8a84SDavid S. Miller { 10562fa8a84SDavid S. Miller unsigned long val = dst->_metrics; 10662fa8a84SDavid S. Miller if (!(val & DST_METRICS_READ_ONLY)) 10762fa8a84SDavid S. Miller __dst_destroy_metrics_generic(dst, val); 10862fa8a84SDavid S. Miller } 10962fa8a84SDavid S. Miller 11062fa8a84SDavid S. Miller static inline u32 *dst_metrics_write_ptr(struct dst_entry *dst) 11162fa8a84SDavid S. Miller { 11262fa8a84SDavid S. Miller unsigned long p = dst->_metrics; 11362fa8a84SDavid S. Miller 1141f37070dSStephen Hemminger BUG_ON(!p); 1151f37070dSStephen Hemminger 11662fa8a84SDavid S. Miller if (p & DST_METRICS_READ_ONLY) 11762fa8a84SDavid S. Miller return dst->ops->cow_metrics(dst, p); 11862fa8a84SDavid S. Miller return __DST_METRICS_PTR(p); 11962fa8a84SDavid S. Miller } 12062fa8a84SDavid S. Miller 12162fa8a84SDavid S. Miller /* This may only be invoked before the entry has reached global 12262fa8a84SDavid S. Miller * visibility. 12362fa8a84SDavid S. Miller */ 12462fa8a84SDavid S. Miller static inline void dst_init_metrics(struct dst_entry *dst, 12562fa8a84SDavid S. Miller const u32 *src_metrics, 12662fa8a84SDavid S. Miller bool read_only) 12762fa8a84SDavid S. Miller { 12862fa8a84SDavid S. Miller dst->_metrics = ((unsigned long) src_metrics) | 12962fa8a84SDavid S. Miller (read_only ? DST_METRICS_READ_ONLY : 0); 13062fa8a84SDavid S. Miller } 13162fa8a84SDavid S. Miller 13262fa8a84SDavid S. Miller static inline void dst_copy_metrics(struct dst_entry *dest, const struct dst_entry *src) 13362fa8a84SDavid S. Miller { 13462fa8a84SDavid S. Miller u32 *dst_metrics = dst_metrics_write_ptr(dest); 13562fa8a84SDavid S. Miller 13662fa8a84SDavid S. Miller if (dst_metrics) { 13762fa8a84SDavid S. Miller u32 *src_metrics = DST_METRICS_PTR(src); 13862fa8a84SDavid S. Miller 13962fa8a84SDavid S. Miller memcpy(dst_metrics, src_metrics, RTAX_MAX * sizeof(u32)); 14062fa8a84SDavid S. Miller } 14162fa8a84SDavid S. Miller } 14262fa8a84SDavid S. Miller 14362fa8a84SDavid S. Miller static inline u32 *dst_metrics_ptr(struct dst_entry *dst) 14462fa8a84SDavid S. Miller { 14562fa8a84SDavid S. Miller return DST_METRICS_PTR(dst); 14662fa8a84SDavid S. Miller } 14762fa8a84SDavid S. Miller 1481da177e4SLinus Torvalds static inline u32 1495170ae82SDavid S. Miller dst_metric_raw(const struct dst_entry *dst, const int metric) 1501da177e4SLinus Torvalds { 15162fa8a84SDavid S. Miller u32 *p = DST_METRICS_PTR(dst); 15262fa8a84SDavid S. Miller 15362fa8a84SDavid S. Miller return p[metric-1]; 154defb3519SDavid S. Miller } 155defb3519SDavid S. Miller 1565170ae82SDavid S. Miller static inline u32 1575170ae82SDavid S. Miller dst_metric(const struct dst_entry *dst, const int metric) 1585170ae82SDavid S. Miller { 1590dbaee3bSDavid S. Miller WARN_ON_ONCE(metric == RTAX_HOPLIMIT || 160d33e4553SDavid S. Miller metric == RTAX_ADVMSS || 161d33e4553SDavid S. Miller metric == RTAX_MTU); 1625170ae82SDavid S. Miller return dst_metric_raw(dst, metric); 1635170ae82SDavid S. Miller } 1645170ae82SDavid S. Miller 1650dbaee3bSDavid S. Miller static inline u32 1660dbaee3bSDavid S. Miller dst_metric_advmss(const struct dst_entry *dst) 1670dbaee3bSDavid S. Miller { 1680dbaee3bSDavid S. Miller u32 advmss = dst_metric_raw(dst, RTAX_ADVMSS); 1690dbaee3bSDavid S. Miller 1700dbaee3bSDavid S. Miller if (!advmss) 1710dbaee3bSDavid S. Miller advmss = dst->ops->default_advmss(dst); 1720dbaee3bSDavid S. Miller 1730dbaee3bSDavid S. Miller return advmss; 1740dbaee3bSDavid S. Miller } 1750dbaee3bSDavid S. Miller 176defb3519SDavid S. Miller static inline void dst_metric_set(struct dst_entry *dst, int metric, u32 val) 177defb3519SDavid S. Miller { 17862fa8a84SDavid S. Miller u32 *p = dst_metrics_write_ptr(dst); 179defb3519SDavid S. Miller 18062fa8a84SDavid S. Miller if (p) 18162fa8a84SDavid S. Miller p[metric-1] = val; 1821da177e4SLinus Torvalds } 1831da177e4SLinus Torvalds 184c3a8d947SDaniel Borkmann /* Kernel-internal feature bits that are unallocated in user space. */ 18540f6a2cbSVandana BN #define DST_FEATURE_ECN_CA (1U << 31) 186c3a8d947SDaniel Borkmann 187c3a8d947SDaniel Borkmann #define DST_FEATURE_MASK (DST_FEATURE_ECN_CA) 188c3a8d947SDaniel Borkmann #define DST_FEATURE_ECN_MASK (DST_FEATURE_ECN_CA | RTAX_FEATURE_ECN) 189c3a8d947SDaniel Borkmann 1900c3adfb8SGilad Ben-Yossef static inline u32 1910c3adfb8SGilad Ben-Yossef dst_feature(const struct dst_entry *dst, u32 feature) 1920c3adfb8SGilad Ben-Yossef { 193bb5b7c11SDavid S. Miller return dst_metric(dst, RTAX_FEATURES) & feature; 1940c3adfb8SGilad Ben-Yossef } 1950c3adfb8SGilad Ben-Yossef 1961da177e4SLinus Torvalds static inline u32 dst_mtu(const struct dst_entry *dst) 1971da177e4SLinus Torvalds { 198618f9bc7SSteffen Klassert return dst->ops->mtu(dst); 1991da177e4SLinus Torvalds } 2001da177e4SLinus Torvalds 201c1e20f7cSStephen Hemminger /* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */ 202c1e20f7cSStephen Hemminger static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metric) 203c1e20f7cSStephen Hemminger { 204c1e20f7cSStephen Hemminger return msecs_to_jiffies(dst_metric(dst, metric)); 205c1e20f7cSStephen Hemminger } 206c1e20f7cSStephen Hemminger 2071da177e4SLinus Torvalds static inline u32 2081da177e4SLinus Torvalds dst_allfrag(const struct dst_entry *dst) 2091da177e4SLinus Torvalds { 2100c3adfb8SGilad Ben-Yossef int ret = dst_feature(dst, RTAX_FEATURE_ALLFRAG); 2111da177e4SLinus Torvalds return ret; 2121da177e4SLinus Torvalds } 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds static inline int 215d33e4553SDavid S. Miller dst_metric_locked(const struct dst_entry *dst, int metric) 2161da177e4SLinus Torvalds { 2171da177e4SLinus Torvalds return dst_metric(dst, RTAX_LOCK) & (1 << metric); 2181da177e4SLinus Torvalds } 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds static inline void dst_hold(struct dst_entry *dst) 2211da177e4SLinus Torvalds { 2225635c10dSEric Dumazet /* 2235635c10dSEric Dumazet * If your kernel compilation stops here, please check 2248b207e73SDavid Miller * the placement of __refcnt in struct dst_entry 2255635c10dSEric Dumazet */ 2265635c10dSEric Dumazet BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63); 22744ebe791SWei Wang WARN_ON(atomic_inc_not_zero(&dst->__refcnt) == 0); 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds 2300da4af00SWei Wang static inline void dst_use_noref(struct dst_entry *dst, unsigned long time) 23103f49f34SPavel Emelyanov { 23232d18ab1SPaolo Abeni if (unlikely(time != dst->lastuse)) { 23303f49f34SPavel Emelyanov dst->__use++; 23403f49f34SPavel Emelyanov dst->lastuse = time; 23503f49f34SPavel Emelyanov } 2360da4af00SWei Wang } 23703f49f34SPavel Emelyanov 2380da4af00SWei Wang static inline void dst_hold_and_use(struct dst_entry *dst, unsigned long time) 2397fee226aSEric Dumazet { 2400da4af00SWei Wang dst_hold(dst); 2410da4af00SWei Wang dst_use_noref(dst, time); 2427fee226aSEric Dumazet } 2437fee226aSEric Dumazet 2447f95e188SEldad Zack static inline struct dst_entry *dst_clone(struct dst_entry *dst) 2451da177e4SLinus Torvalds { 2461da177e4SLinus Torvalds if (dst) 247222d7dbdSEric Dumazet dst_hold(dst); 2481da177e4SLinus Torvalds return dst; 2491da177e4SLinus Torvalds } 2501da177e4SLinus Torvalds 251a4023dd0SJoe Perches void dst_release(struct dst_entry *dst); 2527fee226aSEric Dumazet 2535f56f409SWei Wang void dst_release_immediate(struct dst_entry *dst); 2545f56f409SWei Wang 2557fee226aSEric Dumazet static inline void refdst_drop(unsigned long refdst) 2567fee226aSEric Dumazet { 2577fee226aSEric Dumazet if (!(refdst & SKB_DST_NOREF)) 2587fee226aSEric Dumazet dst_release((struct dst_entry *)(refdst & SKB_DST_PTRMASK)); 2597fee226aSEric Dumazet } 2607fee226aSEric Dumazet 2617fee226aSEric Dumazet /** 2627fee226aSEric Dumazet * skb_dst_drop - drops skb dst 2637fee226aSEric Dumazet * @skb: buffer 2647fee226aSEric Dumazet * 2657fee226aSEric Dumazet * Drops dst reference count if a reference was taken. 2667fee226aSEric Dumazet */ 267adf30907SEric Dumazet static inline void skb_dst_drop(struct sk_buff *skb) 268adf30907SEric Dumazet { 2697fee226aSEric Dumazet if (skb->_skb_refdst) { 2707fee226aSEric Dumazet refdst_drop(skb->_skb_refdst); 2717fee226aSEric Dumazet skb->_skb_refdst = 0UL; 2727fee226aSEric Dumazet } 2737fee226aSEric Dumazet } 2747fee226aSEric Dumazet 275e79e2595SJoe Stringer static inline void __skb_dst_copy(struct sk_buff *nskb, unsigned long refdst) 2767fee226aSEric Dumazet { 277e79e2595SJoe Stringer nskb->_skb_refdst = refdst; 2787fee226aSEric Dumazet if (!(nskb->_skb_refdst & SKB_DST_NOREF)) 2797fee226aSEric Dumazet dst_clone(skb_dst(nskb)); 2807fee226aSEric Dumazet } 2817fee226aSEric Dumazet 282e79e2595SJoe Stringer static inline void skb_dst_copy(struct sk_buff *nskb, const struct sk_buff *oskb) 283e79e2595SJoe Stringer { 284e79e2595SJoe Stringer __skb_dst_copy(nskb, oskb->_skb_refdst); 285e79e2595SJoe Stringer } 286e79e2595SJoe Stringer 2877fee226aSEric Dumazet /** 2885037e9efSEric Dumazet * dst_hold_safe - Take a reference on a dst if possible 2895037e9efSEric Dumazet * @dst: pointer to dst entry 2905037e9efSEric Dumazet * 2915037e9efSEric Dumazet * This helper returns false if it could not safely 2925037e9efSEric Dumazet * take a reference on a dst. 2935037e9efSEric Dumazet */ 2945037e9efSEric Dumazet static inline bool dst_hold_safe(struct dst_entry *dst) 2955037e9efSEric Dumazet { 2965037e9efSEric Dumazet return atomic_inc_not_zero(&dst->__refcnt); 2975037e9efSEric Dumazet } 2985037e9efSEric Dumazet 2995037e9efSEric Dumazet /** 300222d7dbdSEric Dumazet * skb_dst_force - makes sure skb dst is refcounted 3015037e9efSEric Dumazet * @skb: buffer 3025037e9efSEric Dumazet * 3035037e9efSEric Dumazet * If dst is not yet refcounted and not destroyed, grab a ref on it. 304b60a7738SFlorian Westphal * Returns true if dst is refcounted. 3055037e9efSEric Dumazet */ 306b60a7738SFlorian Westphal static inline bool skb_dst_force(struct sk_buff *skb) 3075037e9efSEric Dumazet { 3085037e9efSEric Dumazet if (skb_dst_is_noref(skb)) { 3095037e9efSEric Dumazet struct dst_entry *dst = skb_dst(skb); 3105037e9efSEric Dumazet 311222d7dbdSEric Dumazet WARN_ON(!rcu_read_lock_held()); 3125037e9efSEric Dumazet if (!dst_hold_safe(dst)) 3135037e9efSEric Dumazet dst = NULL; 3145037e9efSEric Dumazet 3155037e9efSEric Dumazet skb->_skb_refdst = (unsigned long)dst; 3165037e9efSEric Dumazet } 317b60a7738SFlorian Westphal 318b60a7738SFlorian Westphal return skb->_skb_refdst != 0UL; 3195037e9efSEric Dumazet } 3205037e9efSEric Dumazet 321d19d56ddSEric Dumazet 322d19d56ddSEric Dumazet /** 323290b895eSEric Dumazet * __skb_tunnel_rx - prepare skb for rx reinsert 324290b895eSEric Dumazet * @skb: buffer 325290b895eSEric Dumazet * @dev: tunnel device 326ea23192eSNicolas Dichtel * @net: netns for packet i/o 327290b895eSEric Dumazet * 328290b895eSEric Dumazet * After decapsulation, packet is going to re-enter (netif_rx()) our stack, 329290b895eSEric Dumazet * so make some cleanups. (no accounting done) 330290b895eSEric Dumazet */ 331ea23192eSNicolas Dichtel static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev, 332ea23192eSNicolas Dichtel struct net *net) 333290b895eSEric Dumazet { 334290b895eSEric Dumazet skb->dev = dev; 335bdeab991STom Herbert 336bdeab991STom Herbert /* 3377539fadcSTom Herbert * Clear hash so that we can recalulate the hash for the 338bdeab991STom Herbert * encapsulated packet, unless we have already determine the hash 339bdeab991STom Herbert * over the L4 4-tuple. 340bdeab991STom Herbert */ 3417539fadcSTom Herbert skb_clear_hash_if_not_l4(skb); 342290b895eSEric Dumazet skb_set_queue_mapping(skb, 0); 343ea23192eSNicolas Dichtel skb_scrub_packet(skb, !net_eq(net, dev_net(dev))); 344290b895eSEric Dumazet } 345290b895eSEric Dumazet 346290b895eSEric Dumazet /** 347d19d56ddSEric Dumazet * skb_tunnel_rx - prepare skb for rx reinsert 348d19d56ddSEric Dumazet * @skb: buffer 349d19d56ddSEric Dumazet * @dev: tunnel device 3508eb1a859SJonathan Neuschäfer * @net: netns for packet i/o 351d19d56ddSEric Dumazet * 352d19d56ddSEric Dumazet * After decapsulation, packet is going to re-enter (netif_rx()) our stack, 353d19d56ddSEric Dumazet * so make some cleanups, and perform accounting. 354290b895eSEric Dumazet * Note: this accounting is not SMP safe. 355d19d56ddSEric Dumazet */ 356ea23192eSNicolas Dichtel static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev, 357ea23192eSNicolas Dichtel struct net *net) 358d19d56ddSEric Dumazet { 359d19d56ddSEric Dumazet /* TODO : stats should be SMP safe */ 360d19d56ddSEric Dumazet dev->stats.rx_packets++; 361d19d56ddSEric Dumazet dev->stats.rx_bytes += skb->len; 362ea23192eSNicolas Dichtel __skb_tunnel_rx(skb, dev, net); 363d19d56ddSEric Dumazet } 364d19d56ddSEric Dumazet 365808c1b69SDaniel Borkmann static inline u32 dst_tclassid(const struct sk_buff *skb) 366808c1b69SDaniel Borkmann { 367808c1b69SDaniel Borkmann #ifdef CONFIG_IP_ROUTE_CLASSID 368808c1b69SDaniel Borkmann const struct dst_entry *dst; 369808c1b69SDaniel Borkmann 370808c1b69SDaniel Borkmann dst = skb_dst(skb); 371808c1b69SDaniel Borkmann if (dst) 372808c1b69SDaniel Borkmann return dst->tclassid; 373808c1b69SDaniel Borkmann #endif 374808c1b69SDaniel Borkmann return 0; 375808c1b69SDaniel Borkmann } 376808c1b69SDaniel Borkmann 377ede2059dSEric W. Biederman int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb); 378aad88724SEric Dumazet static inline int dst_discard(struct sk_buff *skb) 379aad88724SEric Dumazet { 380ede2059dSEric W. Biederman return dst_discard_out(&init_net, skb->sk, skb); 381aad88724SEric Dumazet } 382a4023dd0SJoe Perches void *dst_alloc(struct dst_ops *ops, struct net_device *dev, int initial_ref, 383a4023dd0SJoe Perches int initial_obsolete, unsigned short flags); 384f38a9eb1SThomas Graf void dst_init(struct dst_entry *dst, struct dst_ops *ops, 385f38a9eb1SThomas Graf struct net_device *dev, int initial_ref, int initial_obsolete, 386f38a9eb1SThomas Graf unsigned short flags); 387a4023dd0SJoe Perches struct dst_entry *dst_destroy(struct dst_entry *dst); 3884a6ce2b6SWei Wang void dst_dev_put(struct dst_entry *dst); 3891da177e4SLinus Torvalds 3901da177e4SLinus Torvalds static inline void dst_confirm(struct dst_entry *dst) 3911da177e4SLinus Torvalds { 39269cce1d1SDavid S. Miller } 3935110effeSDavid S. Miller 394d3aaeb38SDavid S. Miller static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr) 395d3aaeb38SDavid S. Miller { 396aaa0c23cSZhouyi Zhou struct neighbour *n = dst->ops->neigh_lookup(dst, NULL, daddr); 397aaa0c23cSZhouyi Zhou return IS_ERR(n) ? NULL : n; 398f894cbf8SDavid S. Miller } 399f894cbf8SDavid S. Miller 400f894cbf8SDavid S. Miller static inline struct neighbour *dst_neigh_lookup_skb(const struct dst_entry *dst, 401f894cbf8SDavid S. Miller struct sk_buff *skb) 402f894cbf8SDavid S. Miller { 403*0992d67bSGuillaume Nault struct neighbour *n; 404394de110SMartin Varghese 405*0992d67bSGuillaume Nault if (WARN_ON_ONCE(!dst->ops->neigh_lookup)) 406*0992d67bSGuillaume Nault return NULL; 407*0992d67bSGuillaume Nault 408394de110SMartin Varghese n = dst->ops->neigh_lookup(dst, skb, NULL); 409394de110SMartin Varghese 410aaa0c23cSZhouyi Zhou return IS_ERR(n) ? NULL : n; 411d3aaeb38SDavid S. Miller } 412d3aaeb38SDavid S. Miller 41363fca65dSJulian Anastasov static inline void dst_confirm_neigh(const struct dst_entry *dst, 41463fca65dSJulian Anastasov const void *daddr) 41563fca65dSJulian Anastasov { 41663fca65dSJulian Anastasov if (dst->ops->confirm_neigh) 41763fca65dSJulian Anastasov dst->ops->confirm_neigh(dst, daddr); 41863fca65dSJulian Anastasov } 41963fca65dSJulian Anastasov 4201da177e4SLinus Torvalds static inline void dst_link_failure(struct sk_buff *skb) 4211da177e4SLinus Torvalds { 422adf30907SEric Dumazet struct dst_entry *dst = skb_dst(skb); 4231da177e4SLinus Torvalds if (dst && dst->ops && dst->ops->link_failure) 4241da177e4SLinus Torvalds dst->ops->link_failure(skb); 4251da177e4SLinus Torvalds } 4261da177e4SLinus Torvalds 4271da177e4SLinus Torvalds static inline void dst_set_expires(struct dst_entry *dst, int timeout) 4281da177e4SLinus Torvalds { 4291da177e4SLinus Torvalds unsigned long expires = jiffies + timeout; 4301da177e4SLinus Torvalds 4311da177e4SLinus Torvalds if (expires == 0) 4321da177e4SLinus Torvalds expires = 1; 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds if (dst->expires == 0 || time_before(expires, dst->expires)) 4351da177e4SLinus Torvalds dst->expires = expires; 4361da177e4SLinus Torvalds } 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds /* Output packet to network from transport. */ 43913206b6bSEric W. Biederman static inline int dst_output(struct net *net, struct sock *sk, struct sk_buff *skb) 440aad88724SEric Dumazet { 441ede2059dSEric W. Biederman return skb_dst(skb)->output(net, sk, skb); 442aad88724SEric Dumazet } 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvalds /* Input packet from network to transport. */ 4451da177e4SLinus Torvalds static inline int dst_input(struct sk_buff *skb) 4461da177e4SLinus Torvalds { 447adf30907SEric Dumazet return skb_dst(skb)->input(skb); 4481da177e4SLinus Torvalds } 4491da177e4SLinus Torvalds 4501da177e4SLinus Torvalds static inline struct dst_entry *dst_check(struct dst_entry *dst, u32 cookie) 4511da177e4SLinus Torvalds { 4521da177e4SLinus Torvalds if (dst->obsolete) 4531da177e4SLinus Torvalds dst = dst->ops->check(dst, cookie); 4541da177e4SLinus Torvalds return dst; 4551da177e4SLinus Torvalds } 4561da177e4SLinus Torvalds 457815f4e57SHerbert Xu /* Flags for xfrm_lookup flags argument. */ 458815f4e57SHerbert Xu enum { 45980c0bc9eSDavid S. Miller XFRM_LOOKUP_ICMP = 1 << 0, 460b8c203b2SSteffen Klassert XFRM_LOOKUP_QUEUE = 1 << 1, 461ac37e251Shuaibin Wang XFRM_LOOKUP_KEEP_DST_REF = 1 << 2, 462815f4e57SHerbert Xu }; 463815f4e57SHerbert Xu 4641da177e4SLinus Torvalds struct flowi; 4651da177e4SLinus Torvalds #ifndef CONFIG_XFRM 466452edd59SDavid S. Miller static inline struct dst_entry *xfrm_lookup(struct net *net, 467452edd59SDavid S. Miller struct dst_entry *dst_orig, 4686f9c9615SEric Dumazet const struct flowi *fl, 4696f9c9615SEric Dumazet const struct sock *sk, 470dee9f4bcSDavid S. Miller int flags) 4711da177e4SLinus Torvalds { 472452edd59SDavid S. Miller return dst_orig; 4731da177e4SLinus Torvalds } 474e87b3998SVlad Yasevich 475bc56b334SBenedict Wong static inline struct dst_entry * 476bc56b334SBenedict Wong xfrm_lookup_with_ifid(struct net *net, struct dst_entry *dst_orig, 477bc56b334SBenedict Wong const struct flowi *fl, const struct sock *sk, 478bc56b334SBenedict Wong int flags, u32 if_id) 479bc56b334SBenedict Wong { 480bc56b334SBenedict Wong return dst_orig; 481bc56b334SBenedict Wong } 482bc56b334SBenedict Wong 483f92ee619SSteffen Klassert static inline struct dst_entry *xfrm_lookup_route(struct net *net, 484f92ee619SSteffen Klassert struct dst_entry *dst_orig, 485f92ee619SSteffen Klassert const struct flowi *fl, 4866f9c9615SEric Dumazet const struct sock *sk, 487f92ee619SSteffen Klassert int flags) 488f92ee619SSteffen Klassert { 489f92ee619SSteffen Klassert return dst_orig; 490f92ee619SSteffen Klassert } 491f92ee619SSteffen Klassert 492e87b3998SVlad Yasevich static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst) 493e87b3998SVlad Yasevich { 494e87b3998SVlad Yasevich return NULL; 495e87b3998SVlad Yasevich } 496e87b3998SVlad Yasevich 4971da177e4SLinus Torvalds #else 498a4023dd0SJoe Perches struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, 4996f9c9615SEric Dumazet const struct flowi *fl, const struct sock *sk, 500452edd59SDavid S. Miller int flags); 501e87b3998SVlad Yasevich 502bc56b334SBenedict Wong struct dst_entry *xfrm_lookup_with_ifid(struct net *net, 503bc56b334SBenedict Wong struct dst_entry *dst_orig, 504bc56b334SBenedict Wong const struct flowi *fl, 505bc56b334SBenedict Wong const struct sock *sk, int flags, 506bc56b334SBenedict Wong u32 if_id); 507bc56b334SBenedict Wong 508f92ee619SSteffen Klassert struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig, 5096f9c9615SEric Dumazet const struct flowi *fl, const struct sock *sk, 510f92ee619SSteffen Klassert int flags); 511f92ee619SSteffen Klassert 512e87b3998SVlad Yasevich /* skb attached with this dst needs transformation if dst->xfrm is valid */ 513e87b3998SVlad Yasevich static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst) 514e87b3998SVlad Yasevich { 515e87b3998SVlad Yasevich return dst->xfrm; 516e87b3998SVlad Yasevich } 5171da177e4SLinus Torvalds #endif 5181da177e4SLinus Torvalds 519f15ca723SNicolas Dichtel static inline void skb_dst_update_pmtu(struct sk_buff *skb, u32 mtu) 520f15ca723SNicolas Dichtel { 521f15ca723SNicolas Dichtel struct dst_entry *dst = skb_dst(skb); 522f15ca723SNicolas Dichtel 523f15ca723SNicolas Dichtel if (dst && dst->ops->update_pmtu) 524bd085ef6SHangbin Liu dst->ops->update_pmtu(dst, NULL, skb, mtu, true); 525f15ca723SNicolas Dichtel } 526f15ca723SNicolas Dichtel 52707dc35c6SHangbin Liu /* update dst pmtu but not do neighbor confirm */ 52807dc35c6SHangbin Liu static inline void skb_dst_update_pmtu_no_confirm(struct sk_buff *skb, u32 mtu) 52907dc35c6SHangbin Liu { 53007dc35c6SHangbin Liu struct dst_entry *dst = skb_dst(skb); 53107dc35c6SHangbin Liu 53207dc35c6SHangbin Liu if (dst && dst->ops->update_pmtu) 53307dc35c6SHangbin Liu dst->ops->update_pmtu(dst, NULL, skb, mtu, false); 53407dc35c6SHangbin Liu } 53507dc35c6SHangbin Liu 5361da177e4SLinus Torvalds #endif /* _NET_DST_H */ 537