fs/proc/proc_net.c
Source file repositories/reference/linux-study-clean/fs/proc/proc_net.c
File Facts
- System
- Linux kernel
- Corpus path
fs/proc/proc_net.c- Extension
.c- Size
- 10943 bytes
- Lines
- 427
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/errno.hlinux/time.hlinux/proc_fs.hlinux/stat.hlinux/slab.hlinux/init.hlinux/sched.hlinux/sched/task.hlinux/module.hlinux/bitops.hlinux/mount.hlinux/nsproxy.hlinux/uidgid.hnet/net_namespace.hlinux/seq_file.hlinux/security.hinternal.h
Detected Declarations
function Copyrightfunction seq_open_netfunction seq_file_net_put_netfunction seq_release_netfunction bpf_iter_init_seq_netfunction bpf_iter_fini_seq_netfunction pde_datafunction single_open_netfunction single_release_netfunction intfunction pde_datafunction proc_tgid_net_getattrfunction proc_tgid_net_readdirfunction proc_net_ns_initfunction proc_net_ns_exitfunction proc_net_initexport proc_create_net_dataexport proc_create_net_data_writeexport proc_create_net_singleexport proc_create_net_single_write
Annotated Snippet
const struct file_operations proc_net_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
.iterate_shared = proc_tgid_net_readdir,
};
static __net_init int proc_net_ns_init(struct net *net)
{
struct proc_dir_entry *netd, *net_statd;
kuid_t uid;
kgid_t gid;
int err;
/*
* This PDE acts only as an anchor for /proc/${pid}/net hierarchy.
* Corresponding inode (PDE(inode) == net->proc_net) is never
* instantiated therefore blanket zeroing is fine.
* net->proc_net_stat inode is instantiated normally.
*/
err = -ENOMEM;
netd = kmem_cache_zalloc(proc_dir_entry_cache, GFP_KERNEL);
if (!netd)
goto out;
netd->subdir = RB_ROOT;
netd->data = net;
netd->nlink = 2;
netd->namelen = 3;
netd->parent = &proc_root;
netd->name = netd->inline_name;
memcpy(netd->name, "net", 4);
uid = make_kuid(net->user_ns, 0);
if (!uid_valid(uid))
uid = netd->uid;
gid = make_kgid(net->user_ns, 0);
if (!gid_valid(gid))
gid = netd->gid;
proc_set_user(netd, uid, gid);
/* Seed dentry revalidation for /proc/${pid}/net */
pde_force_lookup(netd);
err = -EEXIST;
net_statd = proc_net_mkdir(net, "stat", netd);
if (!net_statd)
goto free_net;
net->proc_net = netd;
net->proc_net_stat = net_statd;
return 0;
free_net:
pde_free(netd);
out:
return err;
}
static __net_exit void proc_net_ns_exit(struct net *net)
{
remove_proc_entry("stat", net->proc_net);
pde_free(net->proc_net);
}
static struct pernet_operations __net_initdata proc_net_ns_ops = {
.init = proc_net_ns_init,
.exit = proc_net_ns_exit,
};
int __init proc_net_init(void)
{
proc_symlink("net", NULL, "self/net");
return register_pernet_subsys(&proc_net_ns_ops);
}
Annotation
- Immediate include surface: `linux/errno.h`, `linux/time.h`, `linux/proc_fs.h`, `linux/stat.h`, `linux/slab.h`, `linux/init.h`, `linux/sched.h`, `linux/sched/task.h`.
- Detected declarations: `function Copyright`, `function seq_open_net`, `function seq_file_net_put_net`, `function seq_release_net`, `function bpf_iter_init_seq_net`, `function bpf_iter_fini_seq_net`, `function pde_data`, `function single_open_net`, `function single_release_net`, `function int`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern 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.