net/netfilter/nf_conntrack_proto.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_conntrack_proto.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_conntrack_proto.c- Extension
.c- Size
- 16663 bytes
- Lines
- 699
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/module.hlinux/slab.hlinux/mutex.hlinux/vmalloc.hlinux/stddef.hlinux/err.hlinux/percpu.hlinux/notifier.hlinux/kernel.hlinux/netdevice.hnet/netfilter/nf_conntrack.hnet/netfilter/nf_conntrack_l4proto.hnet/netfilter/nf_conntrack_core.hnet/netfilter/nf_conntrack_bridge.hnet/netfilter/nf_log.hlinux/ip.hlinux/icmp.hlinux/sysctl.hnet/route.hnet/ip.hlinux/netfilter_ipv4.hlinux/netfilter_ipv6.hlinux/netfilter_ipv6/ip6_tables.hnet/netfilter/nf_conntrack_helper.hnet/netfilter/nf_conntrack_zones.hnet/netfilter/nf_conntrack_seqadj.hnet/netfilter/ipv4/nf_conntrack_ipv4.hnet/netfilter/ipv6/nf_conntrack_ipv6.hnet/netfilter/nf_nat_helper.hnet/netfilter/ipv4/nf_defrag_ipv4.h
Detected Declarations
function nf_l4proto_log_invalidfunction nf_ct_l4proto_log_invalidfunction in_vrf_postroutingfunction nf_confirmfunction ipv4_conntrack_infunction ipv4_conntrack_localfunction getorigdstfunction ipv6_getorigdstfunction ipv6_conntrack_infunction ipv6_conntrack_localfunction nf_ct_tcp_fixupfunction nf_ct_netns_do_getfunction nf_ct_netns_do_putfunction nf_ct_netns_inet_getfunction nf_ct_netns_getfunction nf_ct_netns_putfunction nf_ct_bridge_registerfunction nf_ct_bridge_unregisterfunction nf_conntrack_proto_initfunction nf_conntrack_proto_finifunction nf_conntrack_proto_pernet_initexport nf_l4proto_log_invalidexport nf_ct_l4proto_log_invalidexport nf_ct_l4proto_findexport nf_confirmexport nf_ct_netns_getexport nf_ct_netns_putexport nf_ct_bridge_registerexport nf_ct_bridge_unregister
Annotated Snippet
if (helper) {
helper_cb = rcu_dereference(helper->help);
if (helper_cb) {
ret = helper_cb(skb, protoff,
ct, ctinfo);
if (ret != NF_ACCEPT)
return ret;
}
}
}
if (seqadj_needed &&
!nf_ct_seq_adjust(skb, ct, ctinfo, protoff)) {
NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);
return NF_DROP;
}
/* We've seen it coming out the other side: confirm it */
return nf_conntrack_confirm(skb);
}
EXPORT_SYMBOL_GPL(nf_confirm);
static unsigned int ipv4_conntrack_in(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
{
return nf_conntrack_in(skb, state);
}
static unsigned int ipv4_conntrack_local(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
{
if (ip_is_fragment(ip_hdr(skb))) { /* IP_NODEFRAG setsockopt set */
enum ip_conntrack_info ctinfo;
struct nf_conn *tmpl;
tmpl = nf_ct_get(skb, &ctinfo);
if (tmpl && nf_ct_is_template(tmpl)) {
/* when skipping ct, clear templates to avoid fooling
* later targets/matches
*/
skb->_nfct = 0;
nf_ct_put(tmpl);
}
return NF_ACCEPT;
}
return nf_conntrack_in(skb, state);
}
/* Connection tracking may drop packets, but never alters them, so
* make it the first hook.
*/
static const struct nf_hook_ops ipv4_conntrack_ops[] = {
{
.hook = ipv4_conntrack_in,
.pf = NFPROTO_IPV4,
.hooknum = NF_INET_PRE_ROUTING,
.priority = NF_IP_PRI_CONNTRACK,
},
{
.hook = ipv4_conntrack_local,
.pf = NFPROTO_IPV4,
.hooknum = NF_INET_LOCAL_OUT,
.priority = NF_IP_PRI_CONNTRACK,
},
{
.hook = nf_confirm,
.pf = NFPROTO_IPV4,
.hooknum = NF_INET_POST_ROUTING,
.priority = NF_IP_PRI_CONNTRACK_CONFIRM,
},
{
.hook = nf_confirm,
.pf = NFPROTO_IPV4,
.hooknum = NF_INET_LOCAL_IN,
.priority = NF_IP_PRI_CONNTRACK_CONFIRM,
},
};
/* Fast function for those who don't want to parse /proc (and I don't
* blame them).
* Reversing the socket's dst/src point of view gives us the reply
* mapping.
*/
static int
getorigdst(struct sock *sk, int optval, void __user *user, int *len)
{
const struct inet_sock *inet = inet_sk(sk);
Annotation
- Immediate include surface: `linux/types.h`, `linux/netfilter.h`, `linux/module.h`, `linux/slab.h`, `linux/mutex.h`, `linux/vmalloc.h`, `linux/stddef.h`, `linux/err.h`.
- Detected declarations: `function nf_l4proto_log_invalid`, `function nf_ct_l4proto_log_invalid`, `function in_vrf_postrouting`, `function nf_confirm`, `function ipv4_conntrack_in`, `function ipv4_conntrack_local`, `function getorigdst`, `function ipv6_getorigdst`, `function ipv6_conntrack_in`, `function ipv6_conntrack_local`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.