net/netfilter/nf_queue.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_queue.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_queue.c- Extension
.c- Size
- 5814 bytes
- Lines
- 254
- 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/kernel.hlinux/slab.hlinux/init.hlinux/module.hlinux/proc_fs.hlinux/skbuff.hlinux/netfilter.hlinux/netfilter_ipv4.hlinux/netfilter_ipv6.hlinux/netfilter_bridge.hlinux/seq_file.hlinux/rcupdate.hnet/protocol.hnet/netfilter/nf_queue.hnet/dst.hnf_internals.h
Detected Declarations
function nf_register_queue_handlerfunction nf_unregister_queue_handlerfunction nf_queue_sock_putfunction nf_queue_entry_release_refsfunction nf_queue_entry_freefunction __nf_queue_entry_init_physdevsfunction nf_queue_entry_get_refsfunction nf_queue_nf_hook_dropfunction nf_ip_saveroutefunction nf_ip6_saveroutefunction __nf_queuefunction nf_queueexport nf_register_queue_handlerexport nf_unregister_queue_handlerexport nf_queue_entry_freeexport nf_queue_entry_get_refsexport nf_queue_nf_hook_dropexport nf_queue
Annotated Snippet
if (!sk_is_refcounted(sk)) {
if (!refcount_inc_not_zero(&sk->sk_refcnt))
return -ENOTCONN;
/* drop refcount on skb_orphan */
skb->destructor = sock_edemux;
}
}
entry = kmalloc(sizeof(*entry) + route_key_size, GFP_ATOMIC);
if (!entry)
return -ENOMEM;
if (skb_dst(skb) && !skb_dst_force(skb)) {
kfree(entry);
return -ENETDOWN;
}
*entry = (struct nf_queue_entry) {
.skb = skb,
.skb_dev = skb->dev,
.state = *state,
.hook_index = index,
.size = sizeof(*entry) + route_key_size,
};
__nf_queue_entry_init_physdevs(entry);
if (!nf_queue_entry_get_refs(entry)) {
kfree(entry);
return -ENOTCONN;
}
switch (entry->state.pf) {
case AF_INET:
nf_ip_saveroute(skb, entry);
break;
case AF_INET6:
nf_ip6_saveroute(skb, entry);
break;
}
status = qh->outfn(entry, queuenum);
if (status < 0) {
nf_queue_entry_free(entry);
return status;
}
return 0;
}
/* Packets leaving via this function must come back through nf_reinject(). */
int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,
unsigned int index, unsigned int verdict)
{
int ret;
ret = __nf_queue(skb, state, index, verdict >> NF_VERDICT_QBITS);
if (ret < 0) {
if (ret == -ESRCH &&
(verdict & NF_VERDICT_FLAG_QUEUE_BYPASS))
return 1;
kfree_skb(skb);
}
return 0;
}
EXPORT_SYMBOL_GPL(nf_queue);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/init.h`, `linux/module.h`, `linux/proc_fs.h`, `linux/skbuff.h`, `linux/netfilter.h`, `linux/netfilter_ipv4.h`.
- Detected declarations: `function nf_register_queue_handler`, `function nf_unregister_queue_handler`, `function nf_queue_sock_put`, `function nf_queue_entry_release_refs`, `function nf_queue_entry_free`, `function __nf_queue_entry_init_physdevs`, `function nf_queue_entry_get_refs`, `function nf_queue_nf_hook_drop`, `function nf_ip_saveroute`, `function nf_ip6_saveroute`.
- 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.