xref: /linux/include/linux/proc_ns.h (revision 18b19abc3709b109676ffd1f48dcd332c2e477d4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * procfs namespace bits
4  */
5 #ifndef _LINUX_PROC_NS_H
6 #define _LINUX_PROC_NS_H
7 
8 #include <linux/nsfs.h>
9 #include <uapi/linux/nsfs.h>
10 
11 struct pid_namespace;
12 struct nsset;
13 struct path;
14 struct task_struct;
15 struct inode;
16 
17 struct proc_ns_operations {
18 	const char *name;
19 	const char *real_ns_name;
20 	struct ns_common *(*get)(struct task_struct *task);
21 	void (*put)(struct ns_common *ns);
22 	int (*install)(struct nsset *nsset, struct ns_common *ns);
23 	struct user_namespace *(*owner)(struct ns_common *ns);
24 	struct ns_common *(*get_parent)(struct ns_common *ns);
25 } __randomize_layout;
26 
27 extern const struct proc_ns_operations netns_operations;
28 extern const struct proc_ns_operations utsns_operations;
29 extern const struct proc_ns_operations ipcns_operations;
30 extern const struct proc_ns_operations pidns_operations;
31 extern const struct proc_ns_operations pidns_for_children_operations;
32 extern const struct proc_ns_operations userns_operations;
33 extern const struct proc_ns_operations mntns_operations;
34 extern const struct proc_ns_operations cgroupns_operations;
35 extern const struct proc_ns_operations timens_operations;
36 extern const struct proc_ns_operations timens_for_children_operations;
37 
38 /*
39  * We always define these enumerators
40  */
41 enum {
42 	PROC_IPC_INIT_INO	= IPC_NS_INIT_INO,
43 	PROC_UTS_INIT_INO	= UTS_NS_INIT_INO,
44 	PROC_USER_INIT_INO	= USER_NS_INIT_INO,
45 	PROC_PID_INIT_INO	= PID_NS_INIT_INO,
46 	PROC_CGROUP_INIT_INO	= CGROUP_NS_INIT_INO,
47 	PROC_TIME_INIT_INO	= TIME_NS_INIT_INO,
48 	PROC_NET_INIT_INO	= NET_NS_INIT_INO,
49 	PROC_MNT_INIT_INO	= MNT_NS_INIT_INO,
50 };
51 
52 #ifdef CONFIG_PROC_FS
53 
54 extern int proc_alloc_inum(unsigned int *pino);
55 extern void proc_free_inum(unsigned int inum);
56 
57 #else /* CONFIG_PROC_FS */
58 
proc_alloc_inum(unsigned int * inum)59 static inline int proc_alloc_inum(unsigned int *inum)
60 {
61 	*inum = 1;
62 	return 0;
63 }
proc_free_inum(unsigned int inum)64 static inline void proc_free_inum(unsigned int inum) {}
65 
66 #endif /* CONFIG_PROC_FS */
67 
68 #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
69 
70 #endif /* _LINUX_PROC_NS_H */
71