^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * net/dst.h Protocol independent destination cache definitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef _NET_DST_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define _NET_DST_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <net/dst_ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/refcount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/neighbour.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct sk_buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct dst_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct dst_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) unsigned long _metrics;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) unsigned long expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #ifdef CONFIG_XFRM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct xfrm_state *xfrm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) void *__pad1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int (*input)(struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int (*output)(struct net *net, struct sock *sk, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned short flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define DST_NOXFRM 0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define DST_NOPOLICY 0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DST_NOCOUNT 0x0008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define DST_FAKE_RTABLE 0x0010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define DST_XFRM_TUNNEL 0x0020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define DST_XFRM_QUEUE 0x0040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define DST_METADATA 0x0080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* A non-zero value of dst->obsolete forces by-hand validation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * of the route entry. Positive values are set by the generic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * dst layer to indicate that the entry has been forcefully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * destroyed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * Negative values are used by the implementation layer code to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * force invocation of the dst_ops->check() method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) short obsolete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define DST_OBSOLETE_NONE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define DST_OBSOLETE_DEAD 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define DST_OBSOLETE_FORCE_CHK -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define DST_OBSOLETE_KILL -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned short header_len; /* more space at head required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) unsigned short trailer_len; /* space to reserve at tail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * __refcnt wants to be on a different cache line from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * input/output/ops or performance tanks badly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) atomic_t __refcnt; /* 64-bit offset 64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int __use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned long lastuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct lwtunnel_state *lwtstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) short error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) short __pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) __u32 tclassid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #ifndef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) atomic_t __refcnt; /* 32-bit offset 64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct dst_metrics {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u32 metrics[RTAX_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) refcount_t refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) } __aligned(4); /* Low pointer bits contain DST_METRICS_FLAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) extern const struct dst_metrics dst_default_metrics;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define DST_METRICS_READ_ONLY 0x1UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define DST_METRICS_REFCOUNTED 0x2UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define DST_METRICS_FLAGS 0x3UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define __DST_METRICS_PTR(Y) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ((u32 *)((Y) & ~DST_METRICS_FLAGS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define DST_METRICS_PTR(X) __DST_METRICS_PTR((X)->_metrics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static inline bool dst_metrics_read_only(const struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return dst->_metrics & DST_METRICS_READ_ONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) void __dst_destroy_metrics_generic(struct dst_entry *dst, unsigned long old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static inline void dst_destroy_metrics_generic(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned long val = dst->_metrics;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (!(val & DST_METRICS_READ_ONLY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) __dst_destroy_metrics_generic(dst, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static inline u32 *dst_metrics_write_ptr(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) unsigned long p = dst->_metrics;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) BUG_ON(!p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (p & DST_METRICS_READ_ONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return dst->ops->cow_metrics(dst, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return __DST_METRICS_PTR(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* This may only be invoked before the entry has reached global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * visibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static inline void dst_init_metrics(struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) const u32 *src_metrics,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) bool read_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) dst->_metrics = ((unsigned long) src_metrics) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) (read_only ? DST_METRICS_READ_ONLY : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static inline void dst_copy_metrics(struct dst_entry *dest, const struct dst_entry *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) u32 *dst_metrics = dst_metrics_write_ptr(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (dst_metrics) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) u32 *src_metrics = DST_METRICS_PTR(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) memcpy(dst_metrics, src_metrics, RTAX_MAX * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static inline u32 *dst_metrics_ptr(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return DST_METRICS_PTR(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static inline u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) dst_metric_raw(const struct dst_entry *dst, const int metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) u32 *p = DST_METRICS_PTR(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return p[metric-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static inline u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) dst_metric(const struct dst_entry *dst, const int metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) WARN_ON_ONCE(metric == RTAX_HOPLIMIT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) metric == RTAX_ADVMSS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) metric == RTAX_MTU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return dst_metric_raw(dst, metric);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static inline u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) dst_metric_advmss(const struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) u32 advmss = dst_metric_raw(dst, RTAX_ADVMSS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!advmss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) advmss = dst->ops->default_advmss(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return advmss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static inline void dst_metric_set(struct dst_entry *dst, int metric, u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) u32 *p = dst_metrics_write_ptr(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) p[metric-1] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* Kernel-internal feature bits that are unallocated in user space. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define DST_FEATURE_ECN_CA (1U << 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define DST_FEATURE_MASK (DST_FEATURE_ECN_CA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #define DST_FEATURE_ECN_MASK (DST_FEATURE_ECN_CA | RTAX_FEATURE_ECN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static inline u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) dst_feature(const struct dst_entry *dst, u32 feature)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return dst_metric(dst, RTAX_FEATURES) & feature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static inline u32 dst_mtu(const struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return dst->ops->mtu(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return msecs_to_jiffies(dst_metric(dst, metric));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static inline u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) dst_allfrag(const struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int ret = dst_feature(dst, RTAX_FEATURE_ALLFRAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) dst_metric_locked(const struct dst_entry *dst, int metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return dst_metric(dst, RTAX_LOCK) & (1 << metric);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static inline void dst_hold(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * If your kernel compilation stops here, please check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * the placement of __refcnt in struct dst_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) WARN_ON(atomic_inc_not_zero(&dst->__refcnt) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static inline void dst_use_noref(struct dst_entry *dst, unsigned long time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (unlikely(time != dst->lastuse)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) dst->__use++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) dst->lastuse = time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static inline void dst_hold_and_use(struct dst_entry *dst, unsigned long time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) dst_hold(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) dst_use_noref(dst, time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static inline struct dst_entry *dst_clone(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) dst_hold(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) void dst_release(struct dst_entry *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) void dst_release_immediate(struct dst_entry *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static inline void refdst_drop(unsigned long refdst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!(refdst & SKB_DST_NOREF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) dst_release((struct dst_entry *)(refdst & SKB_DST_PTRMASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * skb_dst_drop - drops skb dst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * @skb: buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * Drops dst reference count if a reference was taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static inline void skb_dst_drop(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (skb->_skb_refdst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) refdst_drop(skb->_skb_refdst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) skb->_skb_refdst = 0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static inline void __skb_dst_copy(struct sk_buff *nskb, unsigned long refdst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) nskb->_skb_refdst = refdst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (!(nskb->_skb_refdst & SKB_DST_NOREF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) dst_clone(skb_dst(nskb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static inline void skb_dst_copy(struct sk_buff *nskb, const struct sk_buff *oskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) __skb_dst_copy(nskb, oskb->_skb_refdst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * dst_hold_safe - Take a reference on a dst if possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * @dst: pointer to dst entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * This helper returns false if it could not safely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * take a reference on a dst.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static inline bool dst_hold_safe(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return atomic_inc_not_zero(&dst->__refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * skb_dst_force - makes sure skb dst is refcounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * @skb: buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * If dst is not yet refcounted and not destroyed, grab a ref on it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * Returns true if dst is refcounted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static inline bool skb_dst_force(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (skb_dst_is_noref(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) WARN_ON(!rcu_read_lock_held());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (!dst_hold_safe(dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) skb->_skb_refdst = (unsigned long)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return skb->_skb_refdst != 0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * __skb_tunnel_rx - prepare skb for rx reinsert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * @skb: buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * @dev: tunnel device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * @net: netns for packet i/o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * After decapsulation, packet is going to re-enter (netif_rx()) our stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * so make some cleanups. (no accounting done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * Clear hash so that we can recalulate the hash for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * encapsulated packet, unless we have already determine the hash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * over the L4 4-tuple.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) skb_clear_hash_if_not_l4(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) skb_set_queue_mapping(skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) skb_scrub_packet(skb, !net_eq(net, dev_net(dev)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * skb_tunnel_rx - prepare skb for rx reinsert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * @skb: buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * @dev: tunnel device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * @net: netns for packet i/o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * After decapsulation, packet is going to re-enter (netif_rx()) our stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * so make some cleanups, and perform accounting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * Note: this accounting is not SMP safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /* TODO : stats should be SMP safe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) dev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) dev->stats.rx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) __skb_tunnel_rx(skb, dev, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static inline u32 dst_tclassid(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) #ifdef CONFIG_IP_ROUTE_CLASSID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) const struct dst_entry *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return dst->tclassid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static inline int dst_discard(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return dst_discard_out(&init_net, skb->sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) void *dst_alloc(struct dst_ops *ops, struct net_device *dev, int initial_ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int initial_obsolete, unsigned short flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) void dst_init(struct dst_entry *dst, struct dst_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct net_device *dev, int initial_ref, int initial_obsolete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) unsigned short flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct dst_entry *dst_destroy(struct dst_entry *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) void dst_dev_put(struct dst_entry *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static inline void dst_confirm(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct neighbour *n = dst->ops->neigh_lookup(dst, NULL, daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return IS_ERR(n) ? NULL : n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static inline struct neighbour *dst_neigh_lookup_skb(const struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct neighbour *n = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* The packets from tunnel devices (eg bareudp) may have only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * metadata in the dst pointer of skb. Hence a pointer check of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * neigh_lookup is needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (dst->ops->neigh_lookup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) n = dst->ops->neigh_lookup(dst, skb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return IS_ERR(n) ? NULL : n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static inline void dst_confirm_neigh(const struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) const void *daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (dst->ops->confirm_neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) dst->ops->confirm_neigh(dst, daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static inline void dst_link_failure(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (dst && dst->ops && dst->ops->link_failure)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) dst->ops->link_failure(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static inline void dst_set_expires(struct dst_entry *dst, int timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) unsigned long expires = jiffies + timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (expires == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) expires = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (dst->expires == 0 || time_before(expires, dst->expires))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) dst->expires = expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* Output packet to network from transport. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static inline int dst_output(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return skb_dst(skb)->output(net, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* Input packet from network to transport. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) static inline int dst_input(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return skb_dst(skb)->input(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static inline struct dst_entry *dst_check(struct dst_entry *dst, u32 cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (dst->obsolete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) dst = dst->ops->check(dst, cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /* Flags for xfrm_lookup flags argument. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) XFRM_LOOKUP_ICMP = 1 << 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) XFRM_LOOKUP_QUEUE = 1 << 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) XFRM_LOOKUP_KEEP_DST_REF = 1 << 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct flowi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) #ifndef CONFIG_XFRM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static inline struct dst_entry *xfrm_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) struct dst_entry *dst_orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) const struct flowi *fl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return dst_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static inline struct dst_entry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) xfrm_lookup_with_ifid(struct net *net, struct dst_entry *dst_orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) const struct flowi *fl, const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) int flags, u32 if_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return dst_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static inline struct dst_entry *xfrm_lookup_route(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct dst_entry *dst_orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) const struct flowi *fl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return dst_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) const struct flowi *fl, const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) struct dst_entry *dst_orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) const struct flowi *fl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) const struct sock *sk, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) u32 if_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) const struct flowi *fl, const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /* skb attached with this dst needs transformation if dst->xfrm is valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return dst->xfrm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static inline void skb_dst_update_pmtu(struct sk_buff *skb, u32 mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (dst && dst->ops->update_pmtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) dst->ops->update_pmtu(dst, NULL, skb, mtu, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* update dst pmtu but not do neighbor confirm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) static inline void skb_dst_update_pmtu_no_confirm(struct sk_buff *skb, u32 mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (dst && dst->ops->update_pmtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) dst->ops->update_pmtu(dst, NULL, skb, mtu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct dst_entry *dst_blackhole_check(struct dst_entry *dst, u32 cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) void dst_blackhole_update_pmtu(struct dst_entry *dst, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct sk_buff *skb, u32 mtu, bool confirm_neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) void dst_blackhole_redirect(struct dst_entry *dst, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) u32 *dst_blackhole_cow_metrics(struct dst_entry *dst, unsigned long old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) struct neighbour *dst_blackhole_neigh_lookup(const struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) const void *daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) unsigned int dst_blackhole_mtu(const struct dst_entry *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) #endif /* _NET_DST_H */