Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _NET_DST_CACHE_H
0003 #define _NET_DST_CACHE_H
0004 
0005 #include <linux/jiffies.h>
0006 #include <net/dst.h>
0007 #if IS_ENABLED(CONFIG_IPV6)
0008 #include <net/ip6_fib.h>
0009 #endif
0010 
0011 struct dst_cache {
0012     struct dst_cache_pcpu __percpu *cache;
0013     unsigned long reset_ts;
0014 };
0015 
0016 /**
0017  *  dst_cache_get - perform cache lookup
0018  *  @dst_cache: the cache
0019  *
0020  *  The caller should use dst_cache_get_ip4() if it need to retrieve the
0021  *  source address to be used when xmitting to the cached dst.
0022  *  local BH must be disabled.
0023  */
0024 struct dst_entry *dst_cache_get(struct dst_cache *dst_cache);
0025 
0026 /**
0027  *  dst_cache_get_ip4 - perform cache lookup and fetch ipv4 source address
0028  *  @dst_cache: the cache
0029  *  @saddr: return value for the retrieved source address
0030  *
0031  *  local BH must be disabled.
0032  */
0033 struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr);
0034 
0035 /**
0036  *  dst_cache_set_ip4 - store the ipv4 dst into the cache
0037  *  @dst_cache: the cache
0038  *  @dst: the entry to be cached
0039  *  @saddr: the source address to be stored inside the cache
0040  *
0041  *  local BH must be disabled.
0042  */
0043 void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst,
0044                __be32 saddr);
0045 
0046 #if IS_ENABLED(CONFIG_IPV6)
0047 
0048 /**
0049  *  dst_cache_set_ip6 - store the ipv6 dst into the cache
0050  *  @dst_cache: the cache
0051  *  @dst: the entry to be cached
0052  *  @saddr: the source address to be stored inside the cache
0053  *
0054  *  local BH must be disabled.
0055  */
0056 void dst_cache_set_ip6(struct dst_cache *dst_cache, struct dst_entry *dst,
0057                const struct in6_addr *saddr);
0058 
0059 /**
0060  *  dst_cache_get_ip6 - perform cache lookup and fetch ipv6 source address
0061  *  @dst_cache: the cache
0062  *  @saddr: return value for the retrieved source address
0063  *
0064  *  local BH must be disabled.
0065  */
0066 struct dst_entry *dst_cache_get_ip6(struct dst_cache *dst_cache,
0067                     struct in6_addr *saddr);
0068 #endif
0069 
0070 /**
0071  *  dst_cache_reset - invalidate the cache contents
0072  *  @dst_cache: the cache
0073  *
0074  *  This does not free the cached dst to avoid races and contentions.
0075  *  the dst will be freed on later cache lookup.
0076  */
0077 static inline void dst_cache_reset(struct dst_cache *dst_cache)
0078 {
0079     dst_cache->reset_ts = jiffies;
0080 }
0081 
0082 /**
0083  *  dst_cache_reset_now - invalidate the cache contents immediately
0084  *  @dst_cache: the cache
0085  *
0086  *  The caller must be sure there are no concurrent users, as this frees
0087  *  all dst_cache users immediately, rather than waiting for the next
0088  *  per-cpu usage like dst_cache_reset does. Most callers should use the
0089  *  higher speed lazily-freed dst_cache_reset function instead.
0090  */
0091 void dst_cache_reset_now(struct dst_cache *dst_cache);
0092 
0093 /**
0094  *  dst_cache_init - initialize the cache, allocating the required storage
0095  *  @dst_cache: the cache
0096  *  @gfp: allocation flags
0097  */
0098 int dst_cache_init(struct dst_cache *dst_cache, gfp_t gfp);
0099 
0100 /**
0101  *  dst_cache_destroy - empty the cache and free the allocated storage
0102  *  @dst_cache: the cache
0103  *
0104  *  No synchronization is enforced: it must be called only when the cache
0105  *  is unsed.
0106  */
0107 void dst_cache_destroy(struct dst_cache *dst_cache);
0108 
0109 #endif