at v6.17 2.7 kB view raw
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/ns_common.h> 9#include <uapi/linux/nsfs.h> 10 11struct pid_namespace; 12struct nsset; 13struct path; 14struct task_struct; 15struct inode; 16 17struct proc_ns_operations { 18 const char *name; 19 const char *real_ns_name; 20 int type; 21 struct ns_common *(*get)(struct task_struct *task); 22 void (*put)(struct ns_common *ns); 23 int (*install)(struct nsset *nsset, struct ns_common *ns); 24 struct user_namespace *(*owner)(struct ns_common *ns); 25 struct ns_common *(*get_parent)(struct ns_common *ns); 26} __randomize_layout; 27 28extern const struct proc_ns_operations netns_operations; 29extern const struct proc_ns_operations utsns_operations; 30extern const struct proc_ns_operations ipcns_operations; 31extern const struct proc_ns_operations pidns_operations; 32extern const struct proc_ns_operations pidns_for_children_operations; 33extern const struct proc_ns_operations userns_operations; 34extern const struct proc_ns_operations mntns_operations; 35extern const struct proc_ns_operations cgroupns_operations; 36extern const struct proc_ns_operations timens_operations; 37extern const struct proc_ns_operations timens_for_children_operations; 38 39/* 40 * We always define these enumerators 41 */ 42enum { 43 PROC_IPC_INIT_INO = IPC_NS_INIT_INO, 44 PROC_UTS_INIT_INO = UTS_NS_INIT_INO, 45 PROC_USER_INIT_INO = USER_NS_INIT_INO, 46 PROC_PID_INIT_INO = PID_NS_INIT_INO, 47 PROC_CGROUP_INIT_INO = CGROUP_NS_INIT_INO, 48 PROC_TIME_INIT_INO = TIME_NS_INIT_INO, 49 PROC_NET_INIT_INO = NET_NS_INIT_INO, 50 PROC_MNT_INIT_INO = MNT_NS_INIT_INO, 51}; 52 53#ifdef CONFIG_PROC_FS 54 55extern int proc_alloc_inum(unsigned int *pino); 56extern void proc_free_inum(unsigned int inum); 57 58#else /* CONFIG_PROC_FS */ 59 60static inline int proc_alloc_inum(unsigned int *inum) 61{ 62 *inum = 1; 63 return 0; 64} 65static inline void proc_free_inum(unsigned int inum) {} 66 67#endif /* CONFIG_PROC_FS */ 68 69static inline int ns_alloc_inum(struct ns_common *ns) 70{ 71 WRITE_ONCE(ns->stashed, NULL); 72 return proc_alloc_inum(&ns->inum); 73} 74 75#define ns_free_inum(ns) proc_free_inum((ns)->inum) 76 77#define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) 78extern int ns_get_path(struct path *path, struct task_struct *task, 79 const struct proc_ns_operations *ns_ops); 80typedef struct ns_common *ns_get_path_helper_t(void *); 81extern int ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb, 82 void *private_data); 83 84extern bool ns_match(const struct ns_common *ns, dev_t dev, ino_t ino); 85 86extern int ns_get_name(char *buf, size_t size, struct task_struct *task, 87 const struct proc_ns_operations *ns_ops); 88extern void nsfs_init(void); 89 90#endif /* _LINUX_PROC_NS_H */