Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _LINUX_UTSNAME_H |
| 3 | #define _LINUX_UTSNAME_H |
| 4 | |
Cedric Le Goater | b119f13 | 2006-10-04 02:15:19 -0700 | [diff] [blame] | 5 | |
| 6 | #include <linux/sched.h> |
| 7 | #include <linux/kref.h> |
| 8 | #include <linux/nsproxy.h> |
Al Viro | 435d5f4 | 2014-10-31 22:56:04 -0400 | [diff] [blame] | 9 | #include <linux/ns_common.h> |
Pavel Emelyanov | 58bfdd6d | 2008-02-08 04:18:21 -0800 | [diff] [blame] | 10 | #include <linux/err.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 11 | #include <uapi/linux/utsname.h> |
Cedric Le Goater | b119f13 | 2006-10-04 02:15:19 -0700 | [diff] [blame] | 12 | |
Lucas De Marchi | f1ecf06 | 2011-11-02 13:39:22 -0700 | [diff] [blame] | 13 | enum uts_proc { |
| 14 | UTS_PROC_OSTYPE, |
| 15 | UTS_PROC_OSRELEASE, |
| 16 | UTS_PROC_VERSION, |
| 17 | UTS_PROC_HOSTNAME, |
| 18 | UTS_PROC_DOMAINNAME, |
| 19 | }; |
| 20 | |
Serge E. Hallyn | 59607db | 2011-03-23 16:43:16 -0700 | [diff] [blame] | 21 | struct user_namespace; |
| 22 | extern struct user_namespace init_user_ns; |
| 23 | |
Serge E. Hallyn | 4865ecf | 2006-10-02 02:18:14 -0700 | [diff] [blame] | 24 | struct uts_namespace { |
| 25 | struct kref kref; |
| 26 | struct new_utsname name; |
Serge E. Hallyn | 59607db | 2011-03-23 16:43:16 -0700 | [diff] [blame] | 27 | struct user_namespace *user_ns; |
Eric W. Biederman | f7af3d1 | 2016-08-08 14:11:25 -0500 | [diff] [blame] | 28 | struct ucounts *ucounts; |
Al Viro | 435d5f4 | 2014-10-31 22:56:04 -0400 | [diff] [blame] | 29 | struct ns_common ns; |
Kees Cook | 3859a27 | 2016-10-28 01:22:25 -0700 | [diff] [blame] | 30 | } __randomize_layout; |
Serge E. Hallyn | 4865ecf | 2006-10-02 02:18:14 -0700 | [diff] [blame] | 31 | extern struct uts_namespace init_uts_ns; |
| 32 | |
Pavel Emelyanov | 58bfdd6d | 2008-02-08 04:18:21 -0800 | [diff] [blame] | 33 | #ifdef CONFIG_UTS_NS |
Serge E. Hallyn | 4865ecf | 2006-10-02 02:18:14 -0700 | [diff] [blame] | 34 | static inline void get_uts_ns(struct uts_namespace *ns) |
| 35 | { |
| 36 | kref_get(&ns->kref); |
| 37 | } |
| 38 | |
Eric W. Biederman | 213dd26 | 2007-07-15 23:41:15 -0700 | [diff] [blame] | 39 | extern struct uts_namespace *copy_utsname(unsigned long flags, |
Eric W. Biederman | bcf58e7 | 2012-07-26 04:02:49 -0700 | [diff] [blame] | 40 | struct user_namespace *user_ns, struct uts_namespace *old_ns); |
Serge E. Hallyn | 4865ecf | 2006-10-02 02:18:14 -0700 | [diff] [blame] | 41 | extern void free_uts_ns(struct kref *kref); |
| 42 | |
| 43 | static inline void put_uts_ns(struct uts_namespace *ns) |
| 44 | { |
| 45 | kref_put(&ns->kref, free_uts_ns); |
| 46 | } |
Pavel Emelyanov | 58bfdd6d | 2008-02-08 04:18:21 -0800 | [diff] [blame] | 47 | #else |
| 48 | static inline void get_uts_ns(struct uts_namespace *ns) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | static inline void put_uts_ns(struct uts_namespace *ns) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | static inline struct uts_namespace *copy_utsname(unsigned long flags, |
Eric W. Biederman | bcf58e7 | 2012-07-26 04:02:49 -0700 | [diff] [blame] | 57 | struct user_namespace *user_ns, struct uts_namespace *old_ns) |
Pavel Emelyanov | 58bfdd6d | 2008-02-08 04:18:21 -0800 | [diff] [blame] | 58 | { |
| 59 | if (flags & CLONE_NEWUTS) |
| 60 | return ERR_PTR(-EINVAL); |
| 61 | |
Eric W. Biederman | bcf58e7 | 2012-07-26 04:02:49 -0700 | [diff] [blame] | 62 | return old_ns; |
Pavel Emelyanov | 58bfdd6d | 2008-02-08 04:18:21 -0800 | [diff] [blame] | 63 | } |
| 64 | #endif |
| 65 | |
Lucas De Marchi | f1ecf06 | 2011-11-02 13:39:22 -0700 | [diff] [blame] | 66 | #ifdef CONFIG_PROC_SYSCTL |
| 67 | extern void uts_proc_notify(enum uts_proc proc); |
| 68 | #else |
| 69 | static inline void uts_proc_notify(enum uts_proc proc) |
| 70 | { |
| 71 | } |
| 72 | #endif |
| 73 | |
Serge E. Hallyn | 0bdd7aa | 2006-10-02 02:18:10 -0700 | [diff] [blame] | 74 | static inline struct new_utsname *utsname(void) |
| 75 | { |
Serge E. Hallyn | 4865ecf | 2006-10-02 02:18:14 -0700 | [diff] [blame] | 76 | return ¤t->nsproxy->uts_ns->name; |
Serge E. Hallyn | 0bdd7aa | 2006-10-02 02:18:10 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static inline struct new_utsname *init_utsname(void) |
| 80 | { |
Serge E. Hallyn | 4865ecf | 2006-10-02 02:18:14 -0700 | [diff] [blame] | 81 | return &init_uts_ns.name; |
Serge E. Hallyn | 0bdd7aa | 2006-10-02 02:18:10 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | extern struct rw_semaphore uts_sem; |
Cedric Le Goater | b119f13 | 2006-10-04 02:15:19 -0700 | [diff] [blame] | 85 | |
Cedric Le Goater | b119f13 | 2006-10-04 02:15:19 -0700 | [diff] [blame] | 86 | #endif /* _LINUX_UTSNAME_H */ |