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