xref: /openbmc/linux/include/net/dst_cache.h (revision bc5aa3a0)
1 #ifndef _NET_DST_CACHE_H
2 #define _NET_DST_CACHE_H
3 
4 #include <linux/jiffies.h>
5 #include <net/dst.h>
6 #if IS_ENABLED(CONFIG_IPV6)
7 #include <net/ip6_fib.h>
8 #endif
9 
10 struct dst_cache {
11 	struct dst_cache_pcpu __percpu *cache;
12 	unsigned long reset_ts;
13 };
14 
15 /**
16  *	dst_cache_get - perform cache lookup
17  *	@dst_cache: the cache
18  *
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.
22  */
23 struct dst_entry *dst_cache_get(struct dst_cache *dst_cache);
24 
25 /**
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
29  *
30  *	local BH must be disabled.
31  */
32 struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr);
33 
34 /**
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
39  *
40  *	local BH must be disabled.
41  */
42 void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst,
43 		       __be32 saddr);
44 
45 #if IS_ENABLED(CONFIG_IPV6)
46 
47 /**
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
52  *
53  *	local BH must be disabled.
54  */
55 void dst_cache_set_ip6(struct dst_cache *dst_cache, struct dst_entry *dst,
56 		       const struct in6_addr *addr);
57 
58 /**
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
62  *
63  *	local BH must be disabled.
64  */
65 struct dst_entry *dst_cache_get_ip6(struct dst_cache *dst_cache,
66 				    struct in6_addr *saddr);
67 #endif
68 
69 /**
70  *	dst_cache_reset - invalidate the cache contents
71  *	@dst_cache: the cache
72  *
73  *	This do not free the cached dst to avoid races and contentions.
74  *	the dst will be freed on later cache lookup.
75  */
76 static inline void dst_cache_reset(struct dst_cache *dst_cache)
77 {
78 	dst_cache->reset_ts = jiffies;
79 }
80 
81 /**
82  *	dst_cache_init - initialize the cache, allocating the required storage
83  *	@dst_cache: the cache
84  *	@gfp: allocation flags
85  */
86 int dst_cache_init(struct dst_cache *dst_cache, gfp_t gfp);
87 
88 /**
89  *	dst_cache_destroy - empty the cache and free the allocated storage
90  *	@dst_cache: the cache
91  *
92  *	No synchronization is enforced: it must be called only when the cache
93  *	is unsed.
94  */
95 void dst_cache_destroy(struct dst_cache *dst_cache);
96 
97 #endif
98