1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_UTS_NAMESPACE_H
3#define _LINUX_UTS_NAMESPACE_H
4
5#include <linux/ns_common.h>
6#include <uapi/linux/utsname.h>
7
8struct user_namespace;
9extern struct user_namespace init_user_ns;
10
11struct uts_namespace {
12 struct new_utsname name;
13 struct user_namespace *user_ns;
14 struct ucounts *ucounts;
15 struct ns_common ns;
16} __randomize_layout;
17
18extern struct uts_namespace init_uts_ns;
19
20#ifdef CONFIG_UTS_NS
21static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
22{
23 return container_of(ns, struct uts_namespace, ns);
24}
25
26static inline void get_uts_ns(struct uts_namespace *ns)
27{
28 ns_ref_inc(ns);
29}
30
31extern struct uts_namespace *copy_utsname(u64 flags,
32 struct user_namespace *user_ns, struct uts_namespace *old_ns);
33extern void free_uts_ns(struct uts_namespace *ns);
34
35static inline void put_uts_ns(struct uts_namespace *ns)
36{
37 if (ns_ref_put(ns))
38 free_uts_ns(ns);
39}
40
41void uts_ns_init(void);
42#else
43static inline void get_uts_ns(struct uts_namespace *ns)
44{
45}
46
47static inline void put_uts_ns(struct uts_namespace *ns)
48{
49}
50
51static inline struct uts_namespace *copy_utsname(u64 flags,
52 struct user_namespace *user_ns, struct uts_namespace *old_ns)
53{
54 if (flags & CLONE_NEWUTS)
55 return ERR_PTR(-EINVAL);
56
57 return old_ns;
58}
59
60static inline void uts_ns_init(void)
61{
62}
63#endif
64
65#endif /* _LINUX_UTS_NAMESPACE_H */
66