split dev_queue
[cor.git] / include / net / dst_cache.h
blob67634675e9197cdbd8225e0e4aa1547d8f09f036
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NET_DST_CACHE_H
3 #define _NET_DST_CACHE_H
5 #include <linux/jiffies.h>
6 #include <net/dst.h>
7 #if IS_ENABLED(CONFIG_IPV6)
8 #include <net/ip6_fib.h>
9 #endif
11 struct dst_cache {
12 struct dst_cache_pcpu __percpu *cache;
13 unsigned long reset_ts;
16 /**
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);
26 /**
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);
35 /**
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,
44 __be32 saddr);
46 #if IS_ENABLED(CONFIG_IPV6)
48 /**
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);
59 /**
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);
68 #endif
70 /**
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;
82 /**
83 * dst_cache_init - initialize the cache, allocating the required storage
84 * @dst_cache: the cache
85 * @gfp: allocation flags
87 int dst_cache_init(struct dst_cache *dst_cache, gfp_t gfp);
89 /**
90 * dst_cache_destroy - empty the cache and free the allocated storage
91 * @dst_cache: the cache
93 * No synchronization is enforced: it must be called only when the cache
94 * is unsed.
96 void dst_cache_destroy(struct dst_cache *dst_cache);
98 #endif