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