net/core/net_namespace.c
Source file repositories/reference/linux-study-clean/net/core/net_namespace.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/net_namespace.c- Extension
.c- Size
- 38129 bytes
- Lines
- 1556
- 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/workqueue.hlinux/rtnetlink.hlinux/cache.hlinux/slab.hlinux/list.hlinux/delay.hlinux/sched.hlinux/idr.hlinux/rculist.hlinux/nsproxy.hlinux/fs.hlinux/proc_ns.hlinux/file.hlinux/export.hlinux/user_namespace.hlinux/net_namespace.hlinux/sched/task.hlinux/uidgid.hlinux/proc_fs.hlinux/nstree.hnet/aligned_data.hnet/sock.hnet/netlink.hnet/net_namespace.hnet/netns/generic.h
Detected Declarations
struct net_fill_argsstruct rtnl_net_dump_cbfunction net_assign_genericfunction ops_initfunction ops_pre_exit_listfunction ops_exit_rtnl_listfunction list_for_each_entryfunction list_for_each_entry_continue_reversefunction ops_exit_listfunction list_for_each_entryfunction ops_free_listfunction ops_undo_listfunction list_for_each_entry_continue_reversefunction ops_undo_singlefunction alloc_netidfunction idr_for_eachfunction __peernet2idfunction peernet2id_allocfunction idr_removefunction peernet2idfunction peernet_has_idfunction preinit_net_sysctlfunction preinit_netfunction setup_netfunction list_for_each_entryfunction dec_net_namespacesfunction net_complete_freefunction net_passive_decfunction net_drop_nsfunction net_ns_get_ownershipfunction unhash_nsidfunction for_each_net_rcufunction cleanup_netfunction llist_for_each_entryfunction net_ns_barrierfunction __put_netfunction net_ns_net_debugfsfunction init_net_debugfsfunction net_ns_net_debugfsfunction rtnl_net_newidfunction rtnl_net_get_sizefunction rtnl_net_fillfunction rtnl_net_valid_getid_reqfunction rtnl_net_getidfunction rtnl_net_dumpid_onefunction rtnl_valid_dump_net_reqfunction rtnl_net_dumpidfunction rtnl_net_notifyid
Annotated Snippet
struct net_fill_args {
u32 portid;
u32 seq;
int flags;
int cmd;
int nsid;
bool add_ref;
int ref_nsid;
};
static int rtnl_net_fill(struct sk_buff *skb, struct net_fill_args *args)
{
struct nlmsghdr *nlh;
struct rtgenmsg *rth;
nlh = nlmsg_put(skb, args->portid, args->seq, args->cmd, sizeof(*rth),
args->flags);
if (!nlh)
return -EMSGSIZE;
rth = nlmsg_data(nlh);
rth->rtgen_family = AF_UNSPEC;
if (nla_put_s32(skb, NETNSA_NSID, args->nsid))
goto nla_put_failure;
if (args->add_ref &&
nla_put_s32(skb, NETNSA_CURRENT_NSID, args->ref_nsid))
goto nla_put_failure;
nlmsg_end(skb, nlh);
return 0;
nla_put_failure:
nlmsg_cancel(skb, nlh);
return -EMSGSIZE;
}
static int rtnl_net_valid_getid_req(struct sk_buff *skb,
const struct nlmsghdr *nlh,
struct nlattr **tb,
struct netlink_ext_ack *extack)
{
int i, err;
if (!netlink_strict_get_check(skb))
return nlmsg_parse_deprecated(nlh, sizeof(struct rtgenmsg),
tb, NETNSA_MAX, rtnl_net_policy,
extack);
err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct rtgenmsg), tb,
NETNSA_MAX, rtnl_net_policy,
extack);
if (err)
return err;
for (i = 0; i <= NETNSA_MAX; i++) {
if (!tb[i])
continue;
switch (i) {
case NETNSA_PID:
case NETNSA_FD:
case NETNSA_NSID:
case NETNSA_TARGET_NSID:
break;
default:
NL_SET_ERR_MSG(extack, "Unsupported attribute in peer netns getid request");
return -EINVAL;
}
}
return 0;
}
static int rtnl_net_getid(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack)
{
struct net *net = sock_net(skb->sk);
struct nlattr *tb[NETNSA_MAX + 1];
struct net_fill_args fillargs = {
.portid = NETLINK_CB(skb).portid,
.seq = nlh->nlmsg_seq,
.cmd = RTM_NEWNSID,
};
struct net *peer, *target = net;
struct nlattr *nla;
struct sk_buff *msg;
int err;
Annotation
- Immediate include surface: `linux/workqueue.h`, `linux/rtnetlink.h`, `linux/cache.h`, `linux/slab.h`, `linux/list.h`, `linux/delay.h`, `linux/sched.h`, `linux/idr.h`.
- Detected declarations: `struct net_fill_args`, `struct rtnl_net_dump_cb`, `function net_assign_generic`, `function ops_init`, `function ops_pre_exit_list`, `function ops_exit_rtnl_list`, `function list_for_each_entry`, `function list_for_each_entry_continue_reverse`, `function ops_exit_list`, `function list_for_each_entry`.
- 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.