net/netfilter/nf_conntrack_proto_gre.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_conntrack_proto_gre.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_conntrack_proto_gre.c- Extension
.c- Size
- 12772 bytes
- Lines
- 455
- 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/module.hlinux/types.hlinux/timer.hlinux/list.hlinux/seq_file.hlinux/in.hlinux/netdevice.hlinux/skbuff.hlinux/slab.hnet/dst.hnet/gre.hnet/net_namespace.hnet/netns/generic.hnet/netfilter/nf_conntrack_l4proto.hnet/netfilter/nf_conntrack_helper.hnet/netfilter/nf_conntrack_core.hnet/netfilter/nf_conntrack_timeout.hnet/pptp.hlinux/netfilter/nf_conntrack_proto_gre.hlinux/netfilter/nf_conntrack_pptp.hlinux/netfilter/nfnetlink.hlinux/netfilter/nfnetlink_cttimeout.h
Detected Declarations
enum nf_ct_gre_km_actfunction gre_key_cmpfnfunction gre_keymap_lookupfunction list_for_each_entry_rcufunction nf_ct_gre_km_acceptablefunction nf_ct_gre_keymap_addfunction nf_ct_gre_keymap_destroyfunction gre_pkt_to_tuplefunction gre_print_conntrackfunction nf_conntrack_gre_packetfunction gre_timeout_nlattr_to_objfunction gre_timeout_obj_to_nlattrfunction destroy_sibling_or_expfunction gre_pptp_destroy_siblingsfunction nf_conntrack_gre_init_netexport nf_ct_gre_keymap_addexport nf_ct_gre_keymap_destroyexport gre_pptp_destroy_siblings
Annotated Snippet
if (gre_key_cmpfn(km, t)) {
key = km->tuple.src.u.gre.key;
break;
}
}
pr_debug("lookup src key 0x%x for ", key);
nf_ct_dump_tuple(t);
return key;
}
enum nf_ct_gre_km_act {
NF_CT_GRE_KM_NEW,
NF_CT_GRE_KM_BAD,
NF_CT_GRE_KM_DUP
};
static enum nf_ct_gre_km_act
nf_ct_gre_km_acceptable(const struct nf_ct_pptp_master *ct_pptp_info,
const struct nf_conntrack_tuple *orig,
const struct nf_conntrack_tuple *repl)
{
struct nf_ct_gre_keymap *km_orig, *km_repl;
lockdep_assert_held(&keymap_lock);
km_orig = ct_pptp_info->keymap[IP_CT_DIR_ORIGINAL];
km_repl = ct_pptp_info->keymap[IP_CT_DIR_REPLY];
if (km_orig && km_repl) {
if (!gre_key_cmpfn(km_orig, orig))
return NF_CT_GRE_KM_BAD;
if (!gre_key_cmpfn(km_repl, repl))
return NF_CT_GRE_KM_BAD;
return NF_CT_GRE_KM_DUP;
}
DEBUG_NET_WARN_ON_ONCE(km_orig);
DEBUG_NET_WARN_ON_ONCE(km_repl);
return NF_CT_GRE_KM_NEW;
}
/* add keymap entries, associate with specified master ct */
bool nf_ct_gre_keymap_add(struct nf_conn *ct,
const struct nf_conntrack_tuple *orig,
const struct nf_conntrack_tuple *repl)
{
struct net *net = nf_ct_net(ct);
struct nf_gre_net *net_gre = gre_pernet(net);
struct nf_ct_pptp_master *ct_pptp_info = nfct_help_data(ct);
struct nf_ct_gre_keymap *km_orig, *km_repl;
bool ret = false;
if (!ct_pptp_info)
return false;
km_orig = kmalloc_obj(*km_orig, GFP_ATOMIC);
if (!km_orig)
return false;
km_repl = kmalloc_obj(*km_repl, GFP_ATOMIC);
if (!km_repl)
goto km_free;
memcpy(&km_orig->tuple, orig, sizeof(*orig));
memcpy(&km_repl->tuple, repl, sizeof(*repl));
spin_lock_bh(&keymap_lock);
if (nf_ct_is_dying(ct))
goto unlock_free;
switch (nf_ct_gre_km_acceptable(ct_pptp_info, orig, repl)) {
case NF_CT_GRE_KM_NEW:
break;
case NF_CT_GRE_KM_DUP:
ret = true;
goto unlock_free;
case NF_CT_GRE_KM_BAD:
pr_debug("trying to override keymap for ct %p\n", ct);
goto unlock_free;
}
if (ct_pptp_info->keymap[IP_CT_DIR_ORIGINAL] ||
ct_pptp_info->keymap[IP_CT_DIR_REPLY])
goto unlock_free;
pr_debug("adding new entries %p,%p: ", km_orig, km_repl);
nf_ct_dump_tuple(&km_orig->tuple);
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/timer.h`, `linux/list.h`, `linux/seq_file.h`, `linux/in.h`, `linux/netdevice.h`, `linux/skbuff.h`.
- Detected declarations: `enum nf_ct_gre_km_act`, `function gre_key_cmpfn`, `function gre_keymap_lookup`, `function list_for_each_entry_rcu`, `function nf_ct_gre_km_acceptable`, `function nf_ct_gre_keymap_add`, `function nf_ct_gre_keymap_destroy`, `function gre_pkt_to_tuple`, `function gre_print_conntrack`, `function nf_conntrack_gre_packet`.
- 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.