/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _NET_DST_CACHE_H2#define _NET_DST_CACHE_H34#include <linux/jiffies.h>5#include <net/dst.h>6#if IS_ENABLED(CONFIG_IPV6)7#include <net/ip6_fib.h>8#endif910struct dst_cache {11struct dst_cache_pcpu __percpu *cache;12unsigned long reset_ts;13};1415/**16* dst_cache_get - perform cache lookup17* @dst_cache: the cache18*19* The caller should use dst_cache_get_ip4() if it need to retrieve the20* 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);2425/**26* dst_cache_get_ip4 - perform cache lookup and fetch ipv4 source address27* @dst_cache: the cache28* @saddr: return value for the retrieved source address29*30* local BH must be disabled.31*/32struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr);3334/**35* dst_cache_set_ip4 - store the ipv4 dst into the cache36* @dst_cache: the cache37* @dst: the entry to be cached38* @saddr: the source address to be stored inside the cache39*40* local BH must be disabled.41*/42void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst,43__be32 saddr);4445#if IS_ENABLED(CONFIG_IPV6)4647/**48* dst_cache_set_ip6 - store the ipv6 dst into the cache49* @dst_cache: the cache50* @dst: the entry to be cached51* @saddr: the source address to be stored inside the cache52*53* local BH must be disabled.54*/55void dst_cache_set_ip6(struct dst_cache *dst_cache, struct dst_entry *dst,56const struct in6_addr *saddr);5758/**59* dst_cache_get_ip6 - perform cache lookup and fetch ipv6 source address60* @dst_cache: the cache61* @saddr: return value for the retrieved source address62*63* local BH must be disabled.64*/65struct dst_entry *dst_cache_get_ip6(struct dst_cache *dst_cache,66struct in6_addr *saddr);67#endif6869/**70* dst_cache_reset - invalidate the cache contents71* @dst_cache: the cache72*73* This does 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{78WRITE_ONCE(dst_cache->reset_ts, jiffies);79}8081/**82* dst_cache_reset_now - invalidate the cache contents immediately83* @dst_cache: the cache84*85* The caller must be sure there are no concurrent users, as this frees86* all dst_cache users immediately, rather than waiting for the next87* per-cpu usage like dst_cache_reset does. Most callers should use the88* higher speed lazily-freed dst_cache_reset function instead.89*/90void dst_cache_reset_now(struct dst_cache *dst_cache);9192/**93* dst_cache_init - initialize the cache, allocating the required storage94* @dst_cache: the cache95* @gfp: allocation flags96*/97int dst_cache_init(struct dst_cache *dst_cache, gfp_t gfp);9899/**100* dst_cache_destroy - empty the cache and free the allocated storage101* @dst_cache: the cache102*103* No synchronization is enforced: it must be called only when the cache104* is unused.105*/106void dst_cache_destroy(struct dst_cache *dst_cache);107108#endif109110111