| /* SPDX-License-Identifier: GPL-2.0-only */ | |
| // Copyright (c) 2026 Jarkko Sakkinen | |
| #ifndef UCELLS_UAPI_H | |
| #define UCELLS_UAPI_H | |
| #include <asm/unistd.h> | |
| #include <fcntl.h> | |
| #include <limits.h> | |
| #include <linux/capability.h> | |
| #include <linux/mount.h> | |
| #include <linux/nsfs.h> | |
| #include <linux/sched.h> | |
| #include <stddef.h> | |
| #include <stdint.h> | |
| #define SYS_CELL_CREATE 473 | |
| #define SYS_CELL_CONFIGURE 474 | |
| #define SYS_CELL_INFO 475 | |
| #define SYS_CELL_OPEN 476 | |
| #define SYS_CELL_KILL 477 | |
| #define SYS_PIDFD_CONFIGURE 478 | |
| #define CELL_SELF (-10005) | |
| #define CELL_INFO_SIZE_VER0 80 | |
| #define PIDFD_EMPTY O_NOCTTY | |
| #define ID_WINDOW_FIRST (1U << 31) | |
| #define ID_BLOCK_SIZE 65536U | |
| #define ID_TOTAL_BLOCKS 32767U | |
| #define ID_WINDOW_LAST (ID_WINDOW_FIRST + ID_TOTAL_BLOCKS * ID_BLOCK_SIZE - 1) | |
| #define EMBRYO_KEY_MAX 32 | |
| #define EMBRYO_MAX_STRINGS 4096 | |
| #define EMBRYO_MAX_BLOCK (256UL * 1024) | |
| #define EMBRYO_MAX_FDS 256 | |
| #define EMBRYO_MAX_FD_NUM 4095 | |
| #define CELL_NGROUPS_MAX 65536 | |
| #define CELL_KEY_MAX 64 | |
| #define UTS_HOSTNAME_MAX 64 | |
| #define CELL_CAP_LAST 40 | |
| #define CELL_INFO_ID (1ULL << 0) | |
| #define CELL_INFO_STATE (1ULL << 1) | |
| #define CELL_INFO_EXIT (1ULL << 2) | |
| #define CELL_INFO_BUDGET (1ULL << 3) | |
| #define CELL_INFO_IDS (1ULL << 4) | |
| #define CELL_INFO_CAPS (1ULL << 5) | |
| #define CELL_INFO_IDS_FIRST (1ULL << 6) | |
| #define CELL_INFO_NET_RIGHTS (1ULL << 7) | |
| #define CELL_INFO_ALL 0xffULL | |
| #define CELL_NET_LINK (1ULL << 0) | |
| #define CELL_NET_LINK_NEW (1ULL << 1) | |
| #define CELL_NET_ADDR (1ULL << 2) | |
| #define CELL_NET_ROUTE (1ULL << 3) | |
| #define CELL_NET_FILTER (1ULL << 4) | |
| #define CELL_NET_TC (1ULL << 5) | |
| #define CELL_NET_TUN (1ULL << 6) | |
| #define CELL_NET_SYSCTL (1ULL << 7) | |
| #define CELL_NET_SOCKOPT (1ULL << 8) | |
| #define CELL_NET_RAW (1ULL << 9) | |
| #define CELL_NET_ALL 0x3ffULL | |
| struct cell_info { | |
| uint64_t mask; | |
| uint64_t supported_mask; | |
| uint64_t id; | |
| uint64_t parent_id; | |
| uint32_t state; | |
| uint32_t flags; | |
| int32_t exit_status; | |
| uint32_t ids_count; | |
| uint64_t budget_cgroupid; | |
| uint64_t caps; | |
| uint32_t ids_first; | |
| uint32_t spare; | |
| uint64_t net_rights; | |
| }; | |
| struct pidfd_cred { | |
| uint32_t uid; | |
| uint32_t gid; | |
| uint32_t ngroups; | |
| uint32_t spare; | |
| uint64_t groups; | |
| }; | |
| static_assert(sizeof(struct cell_info) == CELL_INFO_SIZE_VER0); | |
| static_assert(offsetof(struct cell_info, state) == 32); | |
| static_assert(offsetof(struct cell_info, budget_cgroupid) == 48); | |
| static_assert(offsetof(struct cell_info, ids_first) == 64); | |
| static_assert(offsetof(struct cell_info, net_rights) == 72); | |
| static_assert(sizeof(struct pidfd_cred) == 24); | |
| static_assert(offsetof(struct pidfd_cred, groups) == 16); | |
| static_assert(ID_WINDOW_LAST == 4294901759U); | |
| enum cell_state { | |
| CELL_BUILDING = 0, | |
| CELL_SEALED = 1, | |
| CELL_RUNNING = 2, | |
| CELL_DYING = 3, | |
| CELL_DEAD = 4, | |
| }; | |
| enum cell_configure_cmd { | |
| CELL_SET_FLAG = 0, | |
| CELL_SET_STRING = 1, | |
| CELL_SET_BINARY = 2, | |
| CELL_SET_FD = 3, | |
| CELL_CMD_SEAL = 4, | |
| }; | |
| enum pidfd_configure_cmd { | |
| PIDFD_SET_STRING = 0, | |
| PIDFD_SET_BINARY = 1, | |
| PIDFD_SET_FD = 2, | |
| PIDFD_CMD_START = 3, | |
| }; | |
| #define CELL_OPEN_SLOT 0 | |
| enum id_shape { | |
| ID_UNSET, | |
| ID_SINGLE, | |
| ID_BLOCK, | |
| }; | |
| enum open_slot { | |
| OPEN_SLOT_NET, | |
| OPEN_SLOT_PIDS, | |
| }; | |
| enum net_slot_mode { | |
| NET_SLOT_NONE, | |
| NET_SLOT_NEW, | |
| NET_SLOT_PROVIDED_FD, | |
| }; | |
| struct file_identity { | |
| uint64_t dev; | |
| uint64_t ino; | |
| }; | |
| struct caller_cred { | |
| uint32_t uid; | |
| uint32_t gid; | |
| uint32_t fsuid; | |
| }; | |
| struct string_block { | |
| char *data; | |
| char **items; | |
| }; | |
| struct cred_spec { | |
| uint32_t uid; | |
| uint32_t gid; | |
| uint32_t *groups; | |
| size_t nr_groups; | |
| }; | |
| enum embryo_action_type { | |
| EMBRYO_EXEC, | |
| EMBRYO_ARGV, | |
| EMBRYO_ENVP, | |
| EMBRYO_CRED, | |
| EMBRYO_PLACE_FD, | |
| EMBRYO_CGROUP_FD, | |
| }; | |
| struct embryo_action { | |
| enum embryo_action_type type; | |
| union { | |
| char *exec; | |
| struct string_block strings; | |
| struct cred_spec cred; | |
| int target_fd; | |
| }; | |
| }; | |
| enum slot_action_type { | |
| SLOT_HOSTNAME, | |
| SLOT_NET_NEW, | |
| SLOT_IDS, | |
| SLOT_CAPS, | |
| SLOT_NET_RIGHTS, | |
| SLOT_ROOT_FD, | |
| SLOT_BUDGET_FD, | |
| SLOT_NET_FD, | |
| }; | |
| struct slot_action { | |
| enum slot_action_type type; | |
| union { | |
| char hostname[UTS_HOSTNAME_MAX + 1]; | |
| enum id_shape shape; | |
| uint64_t caps; | |
| uint64_t rights; | |
| }; | |
| }; | |
| int file_identity_of_fd(int fd, struct file_identity *id); | |
| bool file_identity_equal(const struct file_identity *a, | |
| const struct file_identity *b); | |
| int id_shape_validate_caller(enum id_shape shape, uint32_t uid, uint32_t gid); | |
| bool valid_utf8(const char *bytes, size_t len); | |
| int string_block_parse(char *data, size_t len, struct string_block *out); | |
| void string_block_destroy(struct string_block *block); | |
| void cred_spec_sort_groups(struct cred_spec *cred); | |
| int embryo_action_string(const char *key, char *value, | |
| struct embryo_action *out); | |
| int embryo_action_fd(const char *key, struct embryo_action *out); | |
| void embryo_action_destroy(struct embryo_action *action); | |
| int slot_action_string(const char *key, const char *val, | |
| struct slot_action *out); | |
| int slot_action_binary(const char *key, const void *value, size_t len, | |
| struct slot_action *out); | |
| int slot_action_fd(const char *key, struct slot_action *out); | |
| int slot_action_flag(const char *key); | |
| int parse_open_slot(const char *key, enum open_slot *out); | |
| #endif |