net/netfilter/nf_sockopt.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_sockopt.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_sockopt.c- Extension
.c- Size
- 2849 bytes
- Lines
- 121
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/init.hlinux/module.hlinux/skbuff.hlinux/netfilter.hlinux/mutex.hnet/sock.hnf_internals.h
Detected Declarations
function overlapfunction nf_register_sockoptfunction nf_unregister_sockoptfunction nf_setsockoptfunction nf_getsockoptexport nf_register_sockoptexport nf_unregister_sockoptexport nf_setsockoptexport nf_getsockopt
Annotated Snippet
if (ops->pf == pf) {
if (!try_module_get(ops->owner))
goto out_nosup;
if (get) {
if (val >= ops->get_optmin &&
val < ops->get_optmax)
goto out;
} else {
if (val >= ops->set_optmin &&
val < ops->set_optmax)
goto out;
}
module_put(ops->owner);
}
}
out_nosup:
ops = ERR_PTR(-ENOPROTOOPT);
out:
mutex_unlock(&nf_sockopt_mutex);
return ops;
}
int nf_setsockopt(struct sock *sk, u_int8_t pf, int val, sockptr_t opt,
unsigned int len)
{
struct nf_sockopt_ops *ops;
int ret;
ops = nf_sockopt_find(sk, pf, val, 0);
if (IS_ERR(ops))
return PTR_ERR(ops);
ret = ops->set(sk, val, opt, len);
module_put(ops->owner);
return ret;
}
EXPORT_SYMBOL(nf_setsockopt);
int nf_getsockopt(struct sock *sk, u_int8_t pf, int val, char __user *opt,
int *len)
{
struct nf_sockopt_ops *ops;
int ret;
ops = nf_sockopt_find(sk, pf, val, 1);
if (IS_ERR(ops))
return PTR_ERR(ops);
ret = ops->get(sk, val, opt, len);
module_put(ops->owner);
return ret;
}
EXPORT_SYMBOL(nf_getsockopt);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/skbuff.h`, `linux/netfilter.h`, `linux/mutex.h`, `net/sock.h`, `nf_internals.h`.
- Detected declarations: `function overlap`, `function nf_register_sockopt`, `function nf_unregister_sockopt`, `function nf_setsockopt`, `function nf_getsockopt`, `export nf_register_sockopt`, `export nf_unregister_sockopt`, `export nf_setsockopt`, `export nf_getsockopt`.
- 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.