1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NET_DST_CACHE_H
3 #define _NET_DST_CACHE_H
5 #include <linux/jiffies.h>
7 #if IS_ENABLED(CONFIG_IPV6)
8 #include <net/ip6_fib.h>
12 struct dst_cache_pcpu __percpu *cache;
13 unsigned long reset_ts;
17 * dst_cache_get - perform cache lookup
18 * @dst_cache: the cache
20 * The caller should use dst_cache_get_ip4() if it need to retrieve the
21 * source address to be used when xmitting to the cached dst.
22 * local BH must be disabled.
24 struct dst_entry *dst_cache_get(struct dst_cache *dst_cache);
27 * dst_cache_get_ip4 - perform cache lookup and fetch ipv4 source address
28 * @dst_cache: the cache
29 * @saddr: return value for the retrieved source address
31 * local BH must be disabled.
33 struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr);
36 * dst_cache_set_ip4 - store the ipv4 dst into the cache
37 * @dst_cache: the cache
38 * @dst: the entry to be cached
39 * @saddr: the source address to be stored inside the cache
41 * local BH must be disabled.
43 void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst,
46 #if IS_ENABLED(CONFIG_IPV6)
49 * dst_cache_set_ip6 - store the ipv6 dst into the cache
50 * @dst_cache: the cache
51 * @dst: the entry to be cached
52 * @saddr: the source address to be stored inside the cache
54 * local BH must be disabled.
56 void dst_cache_set_ip6(struct dst_cache *dst_cache, struct dst_entry *dst,
57 const struct in6_addr *saddr);
60 * dst_cache_get_ip6 - perform cache lookup and fetch ipv6 source address
61 * @dst_cache: the cache
62 * @saddr: return value for the retrieved source address
64 * local BH must be disabled.
66 struct dst_entry *dst_cache_get_ip6(struct dst_cache *dst_cache,
67 struct in6_addr *saddr);
71 * dst_cache_reset - invalidate the cache contents
72 * @dst_cache: the cache
74 * This does not free the cached dst to avoid races and contentions.
75 * the dst will be freed on later cache lookup.
77 static inline void dst_cache_reset(struct dst_cache *dst_cache)
79 dst_cache->reset_ts = jiffies;
83 * dst_cache_reset_now - invalidate the cache contents immediately
84 * @dst_cache: the cache
86 * The caller must be sure there are no concurrent users, as this frees
87 * all dst_cache users immediately, rather than waiting for the next
88 * per-cpu usage like dst_cache_reset does. Most callers should use the
89 * higher speed lazily-freed dst_cache_reset function instead.
91 void dst_cache_reset_now(struct dst_cache *dst_cache);
94 * dst_cache_init - initialize the cache, allocating the required storage
95 * @dst_cache: the cache
96 * @gfp: allocation flags
98 int dst_cache_init(struct dst_cache *dst_cache, gfp_t gfp);
101 * dst_cache_destroy - empty the cache and free the allocated storage
102 * @dst_cache: the cache
104 * No synchronization is enforced: it must be called only when the cache
107 void dst_cache_destroy(struct dst_cache *dst_cache);