net/netfilter/nf_conntrack_ecache.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_conntrack_ecache.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_conntrack_ecache.c- Extension
.c- Size
- 9346 bytes
- Lines
- 384
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/netfilter.hlinux/skbuff.hlinux/vmalloc.hlinux/stddef.hlinux/err.hlinux/kernel.hlinux/netdevice.hlinux/slab.hlinux/export.hnet/netfilter/nf_conntrack.hnet/netfilter/nf_conntrack_core.hnet/netfilter/nf_conntrack_ecache.hnet/netfilter/nf_conntrack_extend.h
Detected Declarations
enum retry_statefunction ecache_work_evict_listfunction hlist_nulls_for_each_entry_safefunction hlist_nulls_for_each_entry_safefunction ecache_workfunction __nf_conntrack_eventmask_reportfunction nf_ct_ecache_tstamp_refreshfunction nf_conntrack_eventmask_reportfunction nf_ct_deliver_cached_eventsfunction nf_ct_expect_event_reportfunction nf_conntrack_register_notifierfunction nf_conntrack_unregister_notifierfunction nf_conntrack_ecache_workfunction nf_ct_ecache_tstamp_newfunction nf_ct_ecache_ext_addfunction nf_conntrack_ecache_pernet_initfunction nf_conntrack_ecache_pernet_finiexport nf_conn_pernet_ecacheexport nf_conntrack_eventmask_reportexport nf_ct_deliver_cached_eventsexport nf_conntrack_register_notifierexport nf_conntrack_unregister_notifierexport nf_ct_ecache_ext_add
Annotated Snippet
if (nf_conntrack_event(IPCT_DESTROY, ct)) {
ret = STATE_CONGESTED;
break;
}
hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode);
hlist_nulls_add_head(&ct->tuplehash[IP_CT_DIR_REPLY].hnnode, &evicted_list);
if (time_after(stop, jiffies)) {
ret = STATE_RESTART;
break;
}
if (sent++ > 16) {
spin_unlock_bh(&cnet->ecache.dying_lock);
cond_resched();
goto next;
}
}
spin_unlock_bh(&cnet->ecache.dying_lock);
hlist_nulls_for_each_entry_safe(h, n, &evicted_list, hnnode) {
struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h);
hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_REPLY].hnnode);
nf_ct_put(ct);
cond_resched();
}
return ret;
}
static void ecache_work(struct work_struct *work)
{
struct nf_conntrack_net *cnet = container_of(work, struct nf_conntrack_net, ecache.dwork.work);
int ret, delay = -1;
ret = ecache_work_evict_list(cnet);
switch (ret) {
case STATE_CONGESTED:
delay = ECACHE_RETRY_JIFFIES;
break;
case STATE_RESTART:
delay = 0;
break;
case STATE_DONE:
break;
}
if (delay >= 0)
schedule_delayed_work(&cnet->ecache.dwork, delay);
}
static int __nf_conntrack_eventmask_report(struct nf_conntrack_ecache *e,
const u32 events,
const u32 missed,
const struct nf_ct_event *item)
{
struct net *net = nf_ct_net(item->ct);
struct nf_ct_event_notifier *notify;
u32 old, want;
int ret;
if (!((events | missed) & e->ctmask))
return 0;
rcu_read_lock();
notify = rcu_dereference(net->ct.nf_conntrack_event_cb);
if (!notify) {
rcu_read_unlock();
return 0;
}
ret = notify->ct_event(events | missed, item);
rcu_read_unlock();
if (likely(ret >= 0 && missed == 0))
return 0;
do {
old = READ_ONCE(e->missed);
if (ret < 0)
want = old | events;
else
want = old & ~missed;
} while (cmpxchg(&e->missed, old, want) != old);
Annotation
- Immediate include surface: `linux/types.h`, `linux/netfilter.h`, `linux/skbuff.h`, `linux/vmalloc.h`, `linux/stddef.h`, `linux/err.h`, `linux/kernel.h`, `linux/netdevice.h`.
- Detected declarations: `enum retry_state`, `function ecache_work_evict_list`, `function hlist_nulls_for_each_entry_safe`, `function hlist_nulls_for_each_entry_safe`, `function ecache_work`, `function __nf_conntrack_eventmask_report`, `function nf_ct_ecache_tstamp_refresh`, `function nf_conntrack_eventmask_report`, `function nf_ct_deliver_cached_events`, `function nf_ct_expect_event_report`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.