net/netfilter/nf_conntrack_timeout.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_conntrack_timeout.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_conntrack_timeout.c- Extension
.c- Size
- 4070 bytes
- Lines
- 168
- 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/percpu.hlinux/kernel.hlinux/netdevice.hlinux/slab.hlinux/export.hnet/netfilter/nf_conntrack.hnet/netfilter/nf_conntrack_core.hnet/netfilter/nf_conntrack_extend.hnet/netfilter/nf_conntrack_l4proto.hnet/netfilter/nf_conntrack_timeout.h
Detected Declarations
function untimeoutfunction nf_ct_untimeoutfunction __nf_ct_timeout_putfunction nf_ct_set_timeoutfunction nf_ct_destroy_timeoutexport nf_ct_timeout_hookexport nf_ct_untimeoutexport nf_ct_set_timeoutexport nf_ct_destroy_timeout
Annotated Snippet
if (!t) {
rcu_read_unlock();
return 0;
}
if (!timeout || t == timeout) {
RCU_INIT_POINTER(timeout_ext->timeout, NULL);
/* No race with nf_conntrack_free() which is called
* only after the conntrack has been removed from
* the hashes.
*/
if (refcount_dec_and_test(&t->refcnt))
kfree_rcu(t, rcu);
}
rcu_read_unlock();
}
/* We are not intended to delete this conntrack. */
return 0;
}
void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout)
{
struct nf_ct_iter_data iter_data = {
.net = net,
.data = timeout,
};
nf_ct_iterate_cleanup_net(untimeout, &iter_data);
}
EXPORT_SYMBOL_GPL(nf_ct_untimeout);
static void __nf_ct_timeout_put(struct nf_ct_timeout *timeout)
{
const struct nf_ct_timeout_hooks *h = rcu_dereference(nf_ct_timeout_hook);
if (h)
h->timeout_put(timeout);
}
int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,
u8 l3num, u8 l4num, const char *timeout_name)
{
const struct nf_ct_timeout_hooks *h;
struct nf_ct_timeout *timeout;
struct nf_conn_timeout *timeout_ext;
const char *errmsg = NULL;
int ret = 0;
WARN_ON_ONCE(!nf_ct_is_template(ct));
rcu_read_lock();
h = rcu_dereference(nf_ct_timeout_hook);
if (!h) {
ret = -ENOENT;
errmsg = "Timeout policy base is empty";
goto out;
}
timeout = h->timeout_find_get(net, timeout_name);
if (!timeout) {
ret = -ENOENT;
pr_info_ratelimited("No such timeout policy \"%s\"\n",
timeout_name);
goto out;
}
if (timeout->l3num != l3num) {
ret = -EINVAL;
pr_info_ratelimited("Timeout policy `%s' can only be used by "
"L%d protocol number %d\n",
timeout_name, 3, timeout->l3num);
goto err_put_timeout;
}
/* Make sure the timeout policy matches any existing protocol tracker,
* otherwise default to generic.
*/
if (timeout->l4proto->l4proto != l4num) {
ret = -EINVAL;
pr_info_ratelimited("Timeout policy `%s' can only be used by "
"L%d protocol number %d\n",
timeout_name, 4, timeout->l4proto->l4proto);
goto err_put_timeout;
}
timeout_ext = nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC);
if (!timeout_ext) {
ret = -ENOMEM;
goto err_put_timeout;
}
Annotation
- Immediate include surface: `linux/types.h`, `linux/netfilter.h`, `linux/skbuff.h`, `linux/vmalloc.h`, `linux/stddef.h`, `linux/err.h`, `linux/percpu.h`, `linux/kernel.h`.
- Detected declarations: `function untimeout`, `function nf_ct_untimeout`, `function __nf_ct_timeout_put`, `function nf_ct_set_timeout`, `function nf_ct_destroy_timeout`, `export nf_ct_timeout_hook`, `export nf_ct_untimeout`, `export nf_ct_set_timeout`, `export nf_ct_destroy_timeout`.
- 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.