1 #ifndef _NET_DST_CACHE_H
2 #define _NET_DST_CACHE_H
4 #include <linux/jiffies.h>
6 #if IS_ENABLED(CONFIG_IPV6)
7 #include <net/ip6_fib.h>
11 struct dst_cache_pcpu __percpu *cache;
12 unsigned long reset_ts;
16 * dst_cache_get - perform cache lookup
17 * @dst_cache: the cache
19 * The caller should use dst_cache_get_ip4() if it need to retrieve the
20 * source address to be used when xmitting to the cached dst.
21 * local BH must be disabled.
23 struct dst_entry *dst_cache_get(struct dst_cache *dst_cache);
26 * dst_cache_get_ip4 - perform cache lookup and fetch ipv4 source address
27 * @dst_cache: the cache
28 * @saddr: return value for the retrieved source address
30 * local BH must be disabled.
32 struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr);
35 * dst_cache_set_ip4 - store the ipv4 dst into the cache
36 * @dst_cache: the cache
37 * @dst: the entry to be cached
38 * @saddr: the source address to be stored inside the cache
40 * local BH must be disabled.
42 void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst,
45 #if IS_ENABLED(CONFIG_IPV6)
48 * dst_cache_set_ip6 - store the ipv6 dst into the cache
49 * @dst_cache: the cache
50 * @dst: the entry to be cached
51 * @saddr: the source address to be stored inside the cache
53 * local BH must be disabled.
55 void dst_cache_set_ip6(struct dst_cache *dst_cache, struct dst_entry *dst,
56 const struct in6_addr *addr);
59 * dst_cache_get_ip6 - perform cache lookup and fetch ipv6 source address
60 * @dst_cache: the cache
61 * @saddr: return value for the retrieved source address
63 * local BH must be disabled.
65 struct dst_entry *dst_cache_get_ip6(struct dst_cache *dst_cache,
66 struct in6_addr *saddr);
70 * dst_cache_reset - invalidate the cache contents
71 * @dst_cache: the cache
73 * This do not free the cached dst to avoid races and contentions.
74 * the dst will be freed on later cache lookup.
76 static inline void dst_cache_reset(struct dst_cache *dst_cache)
78 dst_cache->reset_ts = jiffies;
82 * dst_cache_init - initialize the cache, allocating the required storage
83 * @dst_cache: the cache
84 * @gfp: allocation flags
86 int dst_cache_init(struct dst_cache *dst_cache, gfp_t gfp);
89 * dst_cache_destroy - empty the cache and free the allocated storage
90 * @dst_cache: the cache
92 * No synchronization is enforced: it must be called only when the cache
95 void dst_cache_destroy(struct dst_cache *dst_cache);