162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/* Kernel object name space definitions
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 2002-2003 Patrick Mochel
562306a36Sopenharmony_ci * Copyright (c) 2002-2003 Open Source Development Labs
662306a36Sopenharmony_ci * Copyright (c) 2006-2008 Greg Kroah-Hartman <greg@kroah.com>
762306a36Sopenharmony_ci * Copyright (c) 2006-2008 Novell Inc.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Split from kobject.h by David Howells (dhowells@redhat.com)
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * Please read Documentation/core-api/kobject.rst before using the kobject
1262306a36Sopenharmony_ci * interface, ESPECIALLY the parts about reference counts and object
1362306a36Sopenharmony_ci * destructors.
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#ifndef _LINUX_KOBJECT_NS_H
1762306a36Sopenharmony_ci#define _LINUX_KOBJECT_NS_H
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistruct sock;
2062306a36Sopenharmony_cistruct kobject;
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/*
2362306a36Sopenharmony_ci * Namespace types which are used to tag kobjects and sysfs entries.
2462306a36Sopenharmony_ci * Network namespace will likely be the first.
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_cienum kobj_ns_type {
2762306a36Sopenharmony_ci	KOBJ_NS_TYPE_NONE = 0,
2862306a36Sopenharmony_ci	KOBJ_NS_TYPE_NET,
2962306a36Sopenharmony_ci	KOBJ_NS_TYPES
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci/*
3362306a36Sopenharmony_ci * Callbacks so sysfs can determine namespaces
3462306a36Sopenharmony_ci *   @grab_current_ns: return a new reference to calling task's namespace
3562306a36Sopenharmony_ci *   @netlink_ns: return namespace to which a sock belongs (right?)
3662306a36Sopenharmony_ci *   @initial_ns: return the initial namespace (i.e. init_net_ns)
3762306a36Sopenharmony_ci *   @drop_ns: drops a reference to namespace
3862306a36Sopenharmony_ci */
3962306a36Sopenharmony_cistruct kobj_ns_type_operations {
4062306a36Sopenharmony_ci	enum kobj_ns_type type;
4162306a36Sopenharmony_ci	bool (*current_may_mount)(void);
4262306a36Sopenharmony_ci	void *(*grab_current_ns)(void);
4362306a36Sopenharmony_ci	const void *(*netlink_ns)(struct sock *sk);
4462306a36Sopenharmony_ci	const void *(*initial_ns)(void);
4562306a36Sopenharmony_ci	void (*drop_ns)(void *);
4662306a36Sopenharmony_ci};
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciint kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
4962306a36Sopenharmony_ciint kobj_ns_type_registered(enum kobj_ns_type type);
5062306a36Sopenharmony_ciconst struct kobj_ns_type_operations *kobj_child_ns_ops(const struct kobject *parent);
5162306a36Sopenharmony_ciconst struct kobj_ns_type_operations *kobj_ns_ops(const struct kobject *kobj);
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_cibool kobj_ns_current_may_mount(enum kobj_ns_type type);
5462306a36Sopenharmony_civoid *kobj_ns_grab_current(enum kobj_ns_type type);
5562306a36Sopenharmony_ciconst void *kobj_ns_netlink(enum kobj_ns_type type, struct sock *sk);
5662306a36Sopenharmony_ciconst void *kobj_ns_initial(enum kobj_ns_type type);
5762306a36Sopenharmony_civoid kobj_ns_drop(enum kobj_ns_type type, void *ns);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#endif /* _LINUX_KOBJECT_NS_H */
60