]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
nsproxy: Add FOR_EACH_NS_TYPE() X-macro and CLONE_NS_ALL
authorMickaël Salaün <mic@digikod.net>
Thu, 12 Mar 2026 10:04:36 +0000 (11:04 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 26 Mar 2026 14:22:41 +0000 (15:22 +0100)
commit935a04923ad293cd89bf6ec23fc4efc9cf1a0142
treea09427acb100403bdcb6d1492ba2f4b14c43c07a
parent1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
nsproxy: Add FOR_EACH_NS_TYPE() X-macro and CLONE_NS_ALL

Introduce the FOR_EACH_NS_TYPE(X) macro as the single source of truth
for the set of (struct type, CLONE_NEW* flag) pairs that define Linux
namespace types.

Currently, the list of CLONE_NEW* flags is duplicated inline in
multiple call sites and would need another copy in each new consumer.
This makes it easy to miss one when a new namespace type is added.

Derive two things from the X-macro:

- CLONE_NS_ALL: Bitmask of all known CLONE_NEW* flags, usable as a
  validity mask or iteration bound.

- ns_common_type(): Rewritten to use the X-macro via a leading-comma
  _Generic pattern, so the struct-to-flag mapping stays in sync with the
  flag set automatically.

Replace the inline flag enumerations in copy_namespaces(),
unshare_nsproxy_namespaces(), check_setns_flags(), and
ksys_unshare() with CLONE_NS_ALL.

When a new namespace type is added, only FOR_EACH_NS_TYPE needs to
be updated; CLONE_NS_ALL, ns_common_type(), and all the call sites
pick up the change automatically.

Cc: Christian Brauner <brauner@kernel.org>
Cc: Günther Noack <gnoack@google.com>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Link: https://patch.msgid.link/20260312100444.2609563-4-mic@digikod.net
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/ns/ns_common_types.h
kernel/fork.c
kernel/nsproxy.c