net/core/dst_cache.c
Source file repositories/reference/linux-study-clean/net/core/dst_cache.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/dst_cache.c- Extension
.c- Size
- 4801 bytes
- Lines
- 211
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/percpu.hnet/dst_cache.hnet/route.hnet/ip6_fib.huapi/linux/in.h
Detected Declarations
struct dst_cache_pcpufunction dst_cache_per_cpu_dst_setfunction dst_cache_set_ip4function dst_cache_set_ip6function dst_cache_initfunction dst_cache_destroyfunction dst_cache_reset_nowexport dst_cache_getexport dst_cache_get_ip4export dst_cache_set_ip4export dst_cache_set_ip6export dst_cache_get_ip6export dst_cache_initexport dst_cache_destroyexport dst_cache_reset_now
Annotated Snippet
struct dst_cache_pcpu {
unsigned long refresh_ts;
struct dst_entry *dst;
local_lock_t bh_lock;
u32 cookie;
union {
struct in_addr in_saddr;
struct in6_addr in6_saddr;
};
};
static void dst_cache_per_cpu_dst_set(struct dst_cache_pcpu *dst_cache,
struct dst_entry *dst, u32 cookie)
{
DEBUG_NET_WARN_ON_ONCE(!in_softirq());
dst_release(dst_cache->dst);
if (dst)
dst_hold(dst);
dst_cache->cookie = cookie;
dst_cache->dst = dst;
}
static struct dst_entry *dst_cache_per_cpu_get(struct dst_cache *dst_cache,
struct dst_cache_pcpu *idst)
{
struct dst_entry *dst;
DEBUG_NET_WARN_ON_ONCE(!in_softirq());
dst = idst->dst;
if (!dst)
goto fail;
/* the cache already hold a dst reference; it can't go away */
dst_hold(dst);
if (unlikely(!time_after(idst->refresh_ts,
READ_ONCE(dst_cache->reset_ts)) ||
(READ_ONCE(dst->obsolete) && !dst->ops->check(dst, idst->cookie)))) {
dst_cache_per_cpu_dst_set(idst, NULL, 0);
dst_release(dst);
goto fail;
}
return dst;
fail:
idst->refresh_ts = jiffies;
return NULL;
}
struct dst_entry *dst_cache_get(struct dst_cache *dst_cache)
{
struct dst_entry *dst;
if (!dst_cache->cache)
return NULL;
local_lock_nested_bh(&dst_cache->cache->bh_lock);
dst = dst_cache_per_cpu_get(dst_cache, this_cpu_ptr(dst_cache->cache));
local_unlock_nested_bh(&dst_cache->cache->bh_lock);
return dst;
}
EXPORT_SYMBOL_GPL(dst_cache_get);
struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr)
{
struct dst_cache_pcpu *idst;
struct dst_entry *dst;
if (!dst_cache->cache)
return NULL;
local_lock_nested_bh(&dst_cache->cache->bh_lock);
idst = this_cpu_ptr(dst_cache->cache);
dst = dst_cache_per_cpu_get(dst_cache, idst);
if (!dst) {
local_unlock_nested_bh(&dst_cache->cache->bh_lock);
return NULL;
}
*saddr = idst->in_saddr.s_addr;
local_unlock_nested_bh(&dst_cache->cache->bh_lock);
return dst_rtable(dst);
}
EXPORT_SYMBOL_GPL(dst_cache_get_ip4);
void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst,
__be32 saddr)
{
struct dst_cache_pcpu *idst;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/percpu.h`, `net/dst_cache.h`, `net/route.h`, `net/ip6_fib.h`, `uapi/linux/in.h`.
- Detected declarations: `struct dst_cache_pcpu`, `function dst_cache_per_cpu_dst_set`, `function dst_cache_set_ip4`, `function dst_cache_set_ip6`, `function dst_cache_init`, `function dst_cache_destroy`, `function dst_cache_reset_now`, `export dst_cache_get`, `export dst_cache_get_ip4`, `export dst_cache_set_ip4`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.