]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/conf.h
tree-wide: minimize liburing.h inclusion
[mirror_lxc.git] / src / lxc / conf.h
CommitLineData
cc73685d
CB
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
f1a4a029
ÇO
3#ifndef __LXC_CONF_H
4#define __LXC_CONF_H
0ad19a3f 5
481f03ef
CB
6#include "config.h"
7
9e99997b 8#include <linux/magic.h>
74a2b586 9#include <net/if.h>
1a0e70ac 10#include <netinet/in.h>
d38dd64a
CB
11#include <stdbool.h>
12#include <stdio.h>
b0a33c1e 13#include <sys/param.h>
8173e600 14#include <sys/types.h>
9e99997b
CB
15#include <sys/vfs.h>
16
4822319f 17#include "attach_options.h"
d84b26bc 18#include "caps.h"
d7f19646 19#include "compiler.h"
87d0990c 20#include "hlist.h"
f2363e38 21#include "list.h"
c3e3c21a 22#include "lxcseccomp.h"
ee91fa06 23#include "memory_utils.h"
734a677e 24#include "namespace.h"
732375f5 25#include "ringbuf.h"
d38dd64a 26#include "start.h"
734a677e 27#include "state.h"
4e86cad3 28#include "storage/storage.h"
02efd041 29#include "string_utils.h"
64a04c84 30#include "syscall_wrappers.h"
0ed9b1bc 31#include "terminal.h"
e3b4c4c4 32
d38dd64a
CB
33#if HAVE_SYS_RESOURCE_H
34#include <sys/resource.h>
35#endif
36
769872f9
SH
37#if HAVE_SCMP_FILTER_CTX
38typedef void * scmp_filter_ctx;
39#endif
40
64a04c84
CB
41typedef signed long personality_t;
42
97e9cfa0
SH
43/* worth moving to configure.ac? */
44#define subuidfile "/etc/subuid"
45#define subgidfile "/etc/subgid"
46
0ad19a3f 47/*
43654d34
CB
48 * Defines a generic struct to configure the control group. It is up to the
49 * programmer to specify the right subsystem.
ec64264d 50 * @subsystem : the targeted subsystem
576f946d 51 * @value : the value to set
54860ed0
CB
52 * @version : The version of the cgroup filesystem on which the controller
53 * resides.
43654d34
CB
54 *
55 * @controllers : The controllers to use for this container.
56 * @dir : The name of the directory containing the container's cgroup.
57 * Not that this is a per-container setting.
0ad19a3f 58 */
59struct lxc_cgroup {
43654d34
CB
60 union {
61 /* information about a specific controller */
62 struct /* controller */ {
54860ed0 63 int version;
43654d34
CB
64 char *subsystem;
65 char *value;
66 };
67
68 /* meta information about cgroup configuration */
69 struct /* meta */ {
70 char *controllers;
71 char *dir;
a900cbaf 72 char *monitor_dir;
7696c1f9 73 char *monitor_pivot_dir;
a900cbaf
WB
74 char *container_dir;
75 char *namespace_dir;
9caee129 76 bool relative;
c55353f8
SH
77 /* If an unpriv user in pure unified-only hierarchy
78 * starts a container, then we ask systemd to create
79 * a scope for us, and create the monitor and container
80 * cgroups under that.
81 * This will ignore the above things like monitor_dir
82 */
83 char *systemd_scope;
43654d34
CB
84 };
85 };
c9dbb8ed
CB
86
87 struct list_head head;
0ad19a3f 88};
89
ee91fa06
CB
90static void free_lxc_cgroup(struct lxc_cgroup *ptr)
91{
92 if (ptr) {
93 free(ptr->subsystem);
94 free(ptr->value);
95 free_disarm(ptr);
96 }
97}
98define_cleanup_function(struct lxc_cgroup *, free_lxc_cgroup);
99
c6d09e15 100#if !HAVE_SYS_RESOURCE_H
3a0e314d 101#define RLIM_INFINITY ((unsigned long)-1)
c6d09e15
WB
102struct rlimit {
103 unsigned long rlim_cur;
104 unsigned long rlim_max;
223797c3 105 struct list_head head;
c6d09e15
WB
106};
107#endif
3a0e314d 108
c6d09e15
WB
109/*
110 * Defines a structure to configure resource limits to set via setrlimit().
111 * @resource : the resource name in lowercase without the RLIMIT_ prefix
112 * @limit : the limit to set
113 */
114struct lxc_limit {
115 char *resource;
116 struct rlimit limit;
223797c3 117 struct list_head head;
c6d09e15
WB
118};
119
8fa831e0
CB
120static void free_lxc_limit(struct lxc_limit *ptr)
121{
122 if (ptr) {
631d2715 123 free_disarm(ptr->resource);
8fa831e0
CB
124 free_disarm(ptr);
125 }
126}
127define_cleanup_function(struct lxc_limit *, free_lxc_limit);
128
f6d3e3e4
SH
129enum idtype {
130 ID_TYPE_UID,
131 ID_TYPE_GID
132};
133
7edd0540
L
134/*
135 * Defines a structure to configure kernel parameters at runtime.
136 * @key : the kernel parameters will be configured without the "lxc.sysctl" prefix
137 * @value : the value to set
138 */
139struct lxc_sysctl {
140 char *key;
141 char *value;
ba9f9347 142 struct list_head head;
7edd0540
L
143};
144
f10c80d2
CB
145static void free_lxc_sysctl(struct lxc_sysctl *ptr)
146{
147 if (ptr) {
148 free(ptr->key);
149 free(ptr->value);
150 free_disarm(ptr);
151 }
152}
153define_cleanup_function(struct lxc_sysctl *, free_lxc_sysctl);
154
61d7a733
YT
155/*
156 * Defines a structure to configure proc filesystem at runtime.
157 * @filename : the proc filesystem will be configured without the "lxc.proc" prefix
158 * @value : the value to set
159 */
160struct lxc_proc {
161 char *filename;
162 char *value;
91d04bf9 163 struct list_head head;
61d7a733
YT
164};
165
83332c24
CB
166static void free_lxc_proc(struct lxc_proc *ptr)
167{
168 if (ptr) {
169 free(ptr->filename);
170 free(ptr->value);
171 free_disarm(ptr);
172 }
173}
174define_cleanup_function(struct lxc_proc *, free_lxc_proc);
175
f6d3e3e4
SH
176/*
177 * id_map is an id map entry. Form in confile is:
bdcbb6b3
CB
178 * lxc.idmap = u 0 9800 100
179 * lxc.idmap = u 1000 9900 100
180 * lxc.idmap = g 0 9800 100
181 * lxc.idmap = g 1000 9900 100
251d0d2a
DE
182 * meaning the container can use uids and gids 0-99 and 1000-1099,
183 * with [ug]id 0 mapping to [ug]id 9800 on the host, and [ug]id 1000 to
184 * [ug]id 9900 on the host.
f6d3e3e4
SH
185 */
186struct id_map {
187 enum idtype idtype;
251d0d2a 188 unsigned long hostid, nsid, range;
0589d744 189 struct list_head head;
f6d3e3e4
SH
190};
191
0e4be3cf 192/* Defines the number of tty configured and contains the
a589434e 193 * instantiated ptys
885766f5 194 * @max = number of configured ttys
b0a33c1e 195 */
196struct lxc_tty_info {
885766f5
CB
197 size_t max;
198 char *dir;
199 char *tty_names;
2520facd 200 struct lxc_terminal_info *tty;
b0a33c1e 201};
202
0b932f9d
CB
203typedef enum lxc_mount_options_t {
204 LXC_MOUNT_CREATE_DIR = 0,
205 LXC_MOUNT_CREATE_FILE = 1,
206 LXC_MOUNT_OPTIONAL = 2,
207 LXC_MOUNT_RELATIVE = 3,
f6815906
CB
208 LXC_MOUNT_IDMAP = 4,
209 LXC_MOUNT_MAX = 5,
0b932f9d
CB
210} lxc_mount_options_t;
211
212__hidden extern const char *lxc_mount_options_info[LXC_MOUNT_MAX];
213
214struct lxc_mount_options {
2df612d4
CB
215 unsigned int create_dir : 1;
216 unsigned int create_file : 1;
217 unsigned int optional : 1;
218 unsigned int relative : 1;
3eb23230
CB
219 unsigned int bind_recursively : 1;
220 unsigned int propagate_recursively : 1;
2df612d4 221 unsigned int bind : 1;
f6815906 222 char userns_path[PATH_MAX];
423374e9
CB
223 unsigned long mnt_flags;
224 unsigned long prop_flags;
225 char *data;
c1115e15 226 struct mount_attr attr;
e73af35b 227 char *raw_options;
0b932f9d
CB
228};
229
13bb312d 230/* Defines a structure to store the rootfs location, the
33fcb7a0 231 * optionals pivot_root, rootfs mount paths
953db219
CB
232 * @path : the rootfs source (directory or device)
233 * @mount : where it is mounted
952b5031 234 * @buf : static buffer to construct paths
953db219 235 * @bev_type : optional backing store type
953db219 236 * @managed : whether it is managed by LXC
ea57e424 237 * @dfd_mnt : fd for @mount
a5a08920 238 * @dfd_dev : fd for /dev of the container
33fcb7a0
DL
239 */
240struct lxc_rootfs {
ea11a215 241 int dfd_host;
79ff643d 242
33fcb7a0 243 char *path;
79ff643d 244 int fd_path_pin;
4b875ef9 245 int dfd_idmapped;
79ff643d
CB
246
247 int dfd_mnt;
23b7ea69 248 char *mount;
79ff643d
CB
249
250 int dfd_dev;
251
952b5031 252 char buf[PATH_MAX];
b3b8c97f 253 char *bdev_type;
6e54330c 254 bool managed;
0b932f9d 255 struct lxc_mount_options mnt_opts;
4e86cad3 256 struct lxc_storage *storage;
33fcb7a0
DL
257};
258
368bbc02
CS
259/*
260 * Automatic mounts for LXC to perform inside the container
261 */
262enum {
62054cf3
CB
263 /* /proc read-write */
264 LXC_AUTO_PROC_RW = BIT(0),
265 /* /proc/sys and /proc/sysrq-trigger read-only */
266 LXC_AUTO_PROC_MIXED = BIT(1),
267 LXC_AUTO_PROC_MASK = LXC_AUTO_PROC_RW |
268 LXC_AUTO_PROC_MIXED,
269 /* /sys read-write */
270 LXC_AUTO_SYS_RW = BIT(2),
271 /* /sys read-only */
272 LXC_AUTO_SYS_RO = BIT(3),
273 /* /sys read-only and /sys/class/net read-write */
274 LXC_AUTO_SYS_MIXED = LXC_AUTO_SYS_RW |
275 LXC_AUTO_SYS_RO,
276 LXC_AUTO_SYS_MASK = LXC_AUTO_SYS_MIXED,
277
278 /* /sys/fs/cgroup (partial mount, read-only) */
279 LXC_AUTO_CGROUP_RO = BIT(4),
280 /* /sys/fs/cgroup (partial mount, read-write) */
281 LXC_AUTO_CGROUP_RW = BIT(5),
282 /* /sys/fs/cgroup (partial mount, paths r/o, cgroup r/w) */
283 LXC_AUTO_CGROUP_MIXED = LXC_AUTO_CGROUP_RO |
284 LXC_AUTO_CGROUP_RW,
285 /* /sys/fs/cgroup (full mount, read-only) */
286 LXC_AUTO_CGROUP_FULL_RO = BIT(6),
287 /* /sys/fs/cgroup (full mount, read-write) */
288 LXC_AUTO_CGROUP_FULL_RW = BIT(7),
289 /* /sys/fs/cgroup (full mount, parent r/o, own r/w) */
290 LXC_AUTO_CGROUP_FULL_MIXED = LXC_AUTO_CGROUP_FULL_RO |
291 LXC_AUTO_CGROUP_FULL_RW,
d90d3007
CB
292
293 /*
294 * Mount a pure read-write cgroup2 layout in the container independent
295 * of the cgroup layout used on the host.
296 */
297 LXC_AUTO_CGROUP2_RW = BIT(8),
298 /*
299 * Mount a pure read-only cgroup2 layout in the container independent
300 * of the cgroup layout used on the host.
301 */
302 LXC_AUTO_CGROUP2_RO = BIT(9),
303
3a0e314d
CB
304 /*
305 * These are defined in such a way as to retain binary compatibility
306 * with earlier versions of this code. If the previous mask is applied,
307 * both of these will default back to the _MIXED variants, which is
308 * safe.
309 */
62054cf3
CB
310 /* /sys/fs/cgroup (partial mount, r/w or mixed, depending on caps) */
311 LXC_AUTO_CGROUP_NOSPEC = 0x0B0,
312 /* /sys/fs/cgroup (full mount, r/w or mixed, depending on caps) */
313 LXC_AUTO_CGROUP_FULL_NOSPEC = 0x0E0,
314 /* mount cgroups even when cgroup namespaces are supported */
d90d3007 315 LXC_AUTO_CGROUP_FORCE = BIT(10),
62054cf3
CB
316 /* all known cgroup options */
317 LXC_AUTO_CGROUP_MASK = LXC_AUTO_CGROUP_MIXED |
318 LXC_AUTO_CGROUP_FULL_MIXED |
319 LXC_AUTO_CGROUP_NOSPEC |
320 LXC_AUTO_CGROUP_FULL_NOSPEC |
d90d3007
CB
321 LXC_AUTO_CGROUP_FORCE |
322 LXC_AUTO_CGROUP2_RW |
323 LXC_AUTO_CGROUP2_RO,
62054cf3
CB
324
325 /* shared mount point */
d90d3007 326 LXC_AUTO_SHMOUNTS = BIT(11),
62054cf3
CB
327 /* shared mount point mask */
328 LXC_AUTO_SHMOUNTS_MASK = LXC_AUTO_SHMOUNTS,
329
330 /* all known settings */
331 LXC_AUTO_ALL_MASK = LXC_AUTO_PROC_MASK |
332 LXC_AUTO_SYS_MASK |
333 LXC_AUTO_CGROUP_MASK,
368bbc02
CS
334};
335
26ddeedd 336enum lxchooks {
1a0e70ac
CB
337 LXCHOOK_PRESTART,
338 LXCHOOK_PREMOUNT,
339 LXCHOOK_MOUNT,
340 LXCHOOK_AUTODEV,
341 LXCHOOK_START,
342 LXCHOOK_STOP,
343 LXCHOOK_POSTSTOP,
344 LXCHOOK_CLONE,
345 LXCHOOK_DESTROY,
08dd2805 346 LXCHOOK_START_HOST,
1a0e70ac
CB
347 NUM_LXC_HOOKS
348};
72d0e1cb 349
59eac805 350__hidden extern char *lxchook_names[NUM_LXC_HOOKS];
7b35f3d6 351
d39b10eb
CB
352struct lxc_state_client {
353 int clientfd;
354 lxc_state_t states[MAX_STATE];
d2e75eba 355 struct list_head head;
d39b10eb
CB
356};
357
4b9dc703 358typedef enum lxc_bpf_devices_rule_t {
4b9dc703
CB
359 LXC_BPF_DEVICE_CGROUP_ALLOWLIST = 0,
360 LXC_BPF_DEVICE_CGROUP_DENYLIST = 1,
361} lxc_bpf_devices_rule_t;
fda39d45 362
4bfb655e
CB
363struct device_item {
364 char type;
365 int major;
366 int minor;
367 char access[4];
368 int allow;
93de768e 369 struct list_head head;
a134099d
CB
370};
371
372struct bpf_devices {
373 lxc_bpf_devices_rule_t list_type;
93de768e 374 struct list_head devices;
4bfb655e
CB
375};
376
70fd7fc9
CB
377struct timens_offsets {
378 /* Currently, either s_boot or ns_boot is set, but not both. */
379 int64_t s_boot;
380 int64_t ns_boot;
381
382 /* Currently, either s_monotonic or ns_monotonic is set, but not both. */
383 int64_t s_monotonic;
384 int64_t ns_monotonic;
385};
386
c294a68d
CB
387struct environment_entry {
388 char *key;
389 char *val;
390 struct list_head head;
391};
392
20ab7578
CB
393struct cap_entry {
394 char *cap_name;
7418b27f 395 __u32 cap;
20ab7578
CB
396 struct list_head head;
397};
398
399struct caps {
400 int keep;
401 struct list_head list;
402};
403
be0bc4d1
CB
404struct string_entry {
405 char *val;
406 struct list_head head;
407};
408
571e6ec8 409struct lxc_conf {
c7b17051
CB
410 /* Pointer to the name of the container. Do not free! */
411 const char *name;
07c4ea31 412 bool is_execute;
91480a0f 413 int reboot;
64a04c84 414 personality_t personality;
571e6ec8 415 struct utsname *utsname;
edd64e17 416
54860ed0 417 struct {
c9dbb8ed
CB
418 struct list_head cgroup;
419 struct list_head cgroup2;
a134099d 420 struct bpf_devices bpf_devices;
54860ed0 421 };
edd64e17 422
46ad64ab 423 struct {
0589d744 424 struct list_head id_map;
c7e345ae 425
edd64e17
CB
426 /*
427 * Pointer to the idmap entry for the container's root uid in
428 * the id_map list. Do not free!
429 */
5173b710 430 const struct id_map *root_nsuid_map;
c7e345ae 431
edd64e17
CB
432 /*
433 * Pointer to the idmap entry for the container's root gid in
434 * the id_map list. Do not free!
435 */
5173b710 436 const struct id_map *root_nsgid_map;
46ad64ab 437 };
edd64e17 438
87d0990c 439 struct list_head netdevs;
448d7b0c
CB
440
441 struct {
442 char *fstab;
443 int auto_mounts;
be0bc4d1 444 struct list_head mount_entries;
448d7b0c
CB
445 };
446
20ab7578 447 struct caps caps;
885766f5 448
a2db71c0 449 /* /dev/tty<idx> devices */
885766f5 450 struct lxc_tty_info ttys;
a2db71c0
CB
451 /* /dev/console device */
452 struct lxc_terminal console;
453 /* maximum pty devices allowed by devpts mount */
e528c735 454 size_t pty_max;
f797f05e
CB
455 /* file descriptor for the container's /dev/pts mount */
456 int devpts_fd;
885766f5 457
32fd6cf3
CB
458 /* set to true when rootfs has been setup */
459 bool rootfs_setup;
33fcb7a0 460 struct lxc_rootfs rootfs;
32fd6cf3 461
b3187a81 462 bool close_all_fds;
44ae0fb6
CB
463
464 struct {
465 unsigned int hooks_version;
5090de3e 466 struct list_head hooks[NUM_LXC_HOOKS];
44ae0fb6 467 };
4a85ce2a 468
fe4de9a6 469 char *lsm_aa_profile;
1800f924
WB
470 char *lsm_aa_profile_computed;
471 bool lsm_aa_profile_created;
472 unsigned int lsm_aa_allow_nesting;
a56e2df9 473 unsigned int lsm_aa_allow_incomplete;
1fb1e667 474 struct list_head lsm_aa_raw;
fe4de9a6 475 char *lsm_se_context;
4fef78bc 476 char *lsm_se_keyring_context;
8f818a84 477 bool keyring_disable_session;
952b5031 478 bool transient_procfs_mnt;
c3e3c21a 479 struct lxc_seccomp seccomp;
72d0e1cb 480 int maincmd_fd;
1a0e70ac 481 unsigned int autodev; /* if 1, mount and fill a /dev at start */
63012bdd 482 int autodevtmpfssize; /* size of the /dev tmpfs */
1a0e70ac
CB
483 int haltsignal; /* signal used to halt container */
484 int rebootsignal; /* signal used to reboot container */
485 int stopsignal; /* signal used to hard stop container */
486 char *rcfile; /* Copy of the top level rcfile we read */
487
b9949538 488 /* Logfile and loglevel can be set in a container config file. Those
7b660465 489 * function as defaults. The defaults can be overridden by command line.
1a0e70ac
CB
490 * However we don't want the command line specified values to be saved
491 * on c->save_config(). So we store the config file specified values
492 * here. */
98020c31
JS
493 char *logfile; /* the logfile as specified in config */
494 int loglevel; /* loglevel as specified in config (if any) */
858377e4 495 int logfd;
9f30a190 496
3590152f
CB
497 unsigned int start_auto;
498 unsigned int start_delay;
ee1e7aa0 499 int start_order;
ffb2a35f 500 struct list_head groups;
76a26f55 501 int nbd_idx;
35120d9c 502
a8dfe4e0 503 /* unshare the mount namespace in the monitor */
226dc30e 504 unsigned int monitor_unshare;
258f8051 505 unsigned int monitor_signal_pdeath;
a8dfe4e0 506
7c661726
MP
507 /* list of environment variables we'll add to the container when
508 * started */
c294a68d 509 struct list_head environment;
6b0d5538
SH
510
511 /* text representation of the config file */
512 char *unexpanded_config;
32fd6cf3
CB
513 size_t unexpanded_len;
514 size_t unexpanded_alloced;
67c660d0 515
5cda27c1
SH
516 /* default command for lxc-execute */
517 char *execute_cmd;
518
67c660d0
SG
519 /* init command */
520 char *init_cmd;
56f8ff00 521
4822319f 522 /* The uid to use for the container. */
c5cd20ce 523 uid_t init_uid;
4822319f 524 /* The gid to use for the container. */
c5cd20ce 525 gid_t init_gid;
4822319f
CB
526 /* The groups to use for the container. */
527 lxc_groups_t init_groups;
8796becf
CB
528
529 /* indicator if the container will be destroyed on shutdown */
66ffdb1a 530 unsigned int ephemeral;
76d0127f
CB
531
532 /* The facility to pass to syslog. Let's users establish as what type of
533 * program liblxc is supposed to write to the syslog. */
534 char *syslog;
5a46f283
CB
535
536 /* Whether PR_SET_NO_NEW_PRIVS will be set for the container. */
537 bool no_new_privs;
c6d09e15
WB
538
539 /* RLIMIT_* limits */
223797c3 540 struct list_head limits;
7ec2e32a 541
43654d34
CB
542 /* Contains generic info about the cgroup configuration for this
543 * container. Note that struct lxc_cgroup contains a union. It is only
544 * valid to access the members of the anonymous "meta" struct within
545 * that union.
546 */
547 struct lxc_cgroup cgroup_meta;
28d9e29e 548
b074bbf1 549 struct {
1d8d3676 550 int ns_clone;
abeb5bba 551 int ns_keep;
b074bbf1
CB
552 char *ns_share[LXC_NS_MAX];
553 };
3c491553
L
554
555 /* init working directory */
9e132956 556 char *init_cwd;
3c491553 557
d39b10eb 558 /* A list of clients registered to be informed about a container state. */
d2e75eba 559 struct list_head state_clients;
7edd0540
L
560
561 /* sysctls */
ba9f9347 562 struct list_head sysctls;
61d7a733
YT
563
564 /* procs */
91d04bf9 565 struct list_head procs;
adf0ba1f 566
7a41e857 567 struct shmount {
adf0ba1f
LT
568 /* Absolute path to the shared mount point on the host */
569 char *path_host;
570 /* Absolute path (in the container) to the shared mount point */
571 char *path_cont;
7a41e857 572 } shmount;
70fd7fc9
CB
573
574 struct timens_offsets timens;
09996a48
CB
575
576 bool sched_core;
577 __u64 sched_core_cookie;
571e6ec8
DL
578};
579
efb7e304
CB
580__hidden extern int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, size_t buf_size)
581 __access_r(3, 4);
344c9d81 582
d7f19646 583extern thread_local struct lxc_conf *current_config;
858377e4 584
efb7e304
CB
585__hidden extern int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf, char *argv[]);
586__hidden extern struct lxc_conf *lxc_conf_init(void);
587__hidden extern void lxc_conf_free(struct lxc_conf *conf);
4e86cad3
CB
588__hidden extern int lxc_storage_prepare(struct lxc_conf *conf);
589__hidden extern int lxc_rootfs_prepare(struct lxc_conf *conf, bool userns);
590__hidden extern void lxc_storage_put(struct lxc_conf *conf);
239f29c9 591__hidden extern int lxc_rootfs_init(struct lxc_conf *conf, bool userns);
4b875ef9 592__hidden extern int lxc_rootfs_prepare_parent(struct lxc_handler *handler);
1b82d721 593__hidden extern int lxc_idmapped_mounts_parent(struct lxc_handler *handler);
0589d744 594__hidden extern int lxc_map_ids(struct list_head *idmap, pid_t pid);
efb7e304
CB
595__hidden extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
596__hidden extern void lxc_delete_tty(struct lxc_tty_info *ttys);
597__hidden extern int lxc_clear_config_caps(struct lxc_conf *c);
efb7e304
CB
598__hidden extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version);
599__hidden extern int lxc_clear_mount_entries(struct lxc_conf *c);
600__hidden extern int lxc_clear_automounts(struct lxc_conf *c);
601__hidden extern int lxc_clear_hooks(struct lxc_conf *c, const char *key);
602__hidden extern int lxc_clear_idmaps(struct lxc_conf *c);
603__hidden extern int lxc_clear_groups(struct lxc_conf *c);
604__hidden extern int lxc_clear_environment(struct lxc_conf *c);
605__hidden extern int lxc_clear_limits(struct lxc_conf *c, const char *key);
606__hidden extern int lxc_delete_autodev(struct lxc_handler *handler);
607__hidden extern int lxc_clear_autodev_tmpfs_size(struct lxc_conf *c);
efb7e304
CB
608__hidden extern int lxc_setup_rootfs_prepare_root(struct lxc_conf *conf, const char *name,
609 const char *lxcpath);
610__hidden extern int lxc_setup(struct lxc_handler *handler);
611__hidden extern int lxc_setup_parent(struct lxc_handler *handler);
223797c3 612__hidden extern int setup_resource_limits(struct lxc_conf *conf, pid_t pid);
efb7e304
CB
613__hidden extern int find_unmapped_nsid(const struct lxc_conf *conf, enum idtype idtype);
614__hidden extern int mapped_hostid(unsigned id, const struct lxc_conf *conf, enum idtype idtype);
615__hidden extern int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data,
616 const char *fn_name);
617__hidden extern int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data,
618 const char *fn_name);
d94eb390 619__hidden extern int parse_mntopts_legacy(const char *mntopts, unsigned long *mntflags, char **mntdata);
efb7e304 620__hidden extern int parse_propagationopts(const char *mntopts, unsigned long *pflags);
1b82d721 621__hidden extern int parse_lxc_mount_attrs(struct lxc_mount_options *opts, char *mnt_opts);
704cadd5 622__hidden extern int parse_mount_attrs(struct lxc_mount_options *opts, const char *mntopts);
efb7e304 623__hidden extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
efb7e304 624__hidden extern void suggest_default_idmap(void);
be0bc4d1
CB
625__hidden extern FILE *make_anonymous_mount_file(const struct list_head *mount,
626 bool include_nesting_helpers);
efb7e304
CB
627__hidden extern int run_script(const char *name, const char *section, const char *script, ...);
628__hidden extern int run_script_argv(const char *name, unsigned int hook_version, const char *section,
629 const char *script, const char *hookname, char **argsin);
309ae287 630
7418b27f
CB
631__hidden extern bool has_cap(__u32 cap, struct lxc_conf *conf);
632static inline bool lxc_wants_cap(__u32 cap, struct lxc_conf *conf)
309ae287 633{
7418b27f
CB
634 __u32 last_cap;
635 int ret;
636
637 ret = lxc_caps_last_cap(&last_cap);
638 if (ret)
639 return false;
640
641 if (last_cap < cap)
d84b26bc
CB
642 return false;
643
20ab7578 644 return has_cap(cap, conf);
309ae287
CB
645}
646
ba9f9347 647__hidden extern int setup_sysctl_parameters(struct lxc_conf *conf);
efb7e304 648__hidden extern int lxc_clear_sysctls(struct lxc_conf *c, const char *key);
91d04bf9 649__hidden extern int setup_proc_filesystem(struct lxc_conf *conf, pid_t pid);
efb7e304
CB
650__hidden extern int lxc_clear_procs(struct lxc_conf *c, const char *key);
651__hidden extern int lxc_clear_apparmor_raw(struct lxc_conf *c);
652__hidden extern int lxc_clear_namespace(struct lxc_conf *c);
653__hidden extern int userns_exec_minimal(const struct lxc_conf *conf, int (*fn_parent)(void *),
654 void *fn_parent_data, int (*fn_child)(void *),
655 void *fn_child_data);
656__hidden extern int userns_exec_mapped_root(const char *path, int path_fd,
657 const struct lxc_conf *conf);
6e1a327a
CB
658static inline int chown_mapped_root(const char *path, const struct lxc_conf *conf)
659{
660 return userns_exec_mapped_root(path, -EBADF, conf);
661}
5ae72b98 662
493ae3fe 663__hidden extern int lxc_sync_fds_parent(struct lxc_handler *handler);
111ed96e 664__hidden extern int lxc_sync_fds_child(struct lxc_handler *handler);
68f3899e 665
02efd041
CB
666static inline const char *get_rootfs_mnt(const struct lxc_rootfs *rootfs)
667{
668 static const char *s = "/";
669
670 return !is_empty_string(rootfs->path) ? rootfs->mount : s;
671}
672
423374e9
CB
673static inline void put_lxc_mount_options(struct lxc_mount_options *mnt_opts)
674{
675 mnt_opts->create_dir = 0;
676 mnt_opts->create_file = 0;
677 mnt_opts->optional = 0;
678 mnt_opts->relative = 0;
679 mnt_opts->userns_path[0] = '\0';
680 mnt_opts->mnt_flags = 0;
681 mnt_opts->prop_flags = 0;
682
423374e9 683 free_disarm(mnt_opts->data);
e73af35b 684 free_disarm(mnt_opts->raw_options);
423374e9
CB
685}
686
79ff643d
CB
687static inline void put_lxc_rootfs(struct lxc_rootfs *rootfs, bool unpin)
688{
689 if (rootfs) {
690 close_prot_errno_disarm(rootfs->dfd_host);
691 close_prot_errno_disarm(rootfs->dfd_mnt);
692 close_prot_errno_disarm(rootfs->dfd_dev);
693 if (unpin)
694 close_prot_errno_disarm(rootfs->fd_path_pin);
4b875ef9 695 close_prot_errno_disarm(rootfs->dfd_idmapped);
423374e9 696 put_lxc_mount_options(&rootfs->mnt_opts);
4e86cad3
CB
697 storage_put(rootfs->storage);
698 rootfs->storage = NULL;
79ff643d
CB
699 }
700}
701
a7744f12
CB
702static inline void lxc_clear_cgroup2_devices(struct bpf_devices *bpf_devices)
703{
93de768e 704 struct device_item *device, *n;
a7744f12 705
93de768e
CB
706 list_for_each_entry_safe(device, n, &bpf_devices->devices, head)
707 list_del(&device->head);
a7744f12 708
93de768e 709 INIT_LIST_HEAD(&bpf_devices->devices);
a7744f12
CB
710}
711
64a04c84
CB
712static inline int lxc_personality(personality_t persona)
713{
714 if (persona < 0)
715 return ret_errno(EINVAL);
716
717 return personality(persona);
718}
719
c294a68d 720__hidden extern int lxc_set_environment(const struct lxc_conf *conf);
7418b27f 721__hidden extern int parse_cap(const char *cap_name, __u32 *cap);
c294a68d 722
1a0e70ac 723#endif /* __LXC_CONF_H */