]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/conf.h
provide an example SELinux policy for older releases
[mirror_lxc.git] / src / lxc / conf.h
CommitLineData
0ad19a3f 1/*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
9afe19d6 7 * Daniel Lezcano <daniel.lezcano at free.fr>
0ad19a3f 8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
250b1eec 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0ad19a3f 22 */
f1a4a029
ÇO
23#ifndef __LXC_CONF_H
24#define __LXC_CONF_H
0ad19a3f 25
f424fa8f
SG
26#include "config.h"
27
0ad19a3f 28#include <netinet/in.h>
74a2b586 29#include <net/if.h>
b0a33c1e 30#include <sys/param.h>
8173e600 31#include <sys/types.h>
19a26f82 32#include <stdbool.h>
0ad19a3f 33
f2363e38
ÇO
34#include "list.h"
35#include "start.h" /* for lxc_handler */
e3b4c4c4 36
769872f9
SH
37#if HAVE_SCMP_FILTER_CTX
38typedef void * scmp_filter_ctx;
39#endif
40
13954cce 41enum {
24654103
DL
42 LXC_NET_EMPTY,
43 LXC_NET_VETH,
44 LXC_NET_MACVLAN,
45 LXC_NET_PHYS,
46 LXC_NET_VLAN,
26b797f3 47 LXC_NET_NONE,
24654103 48 LXC_NET_MAXCONFTYPE,
0ad19a3f 49};
50
51/*
52 * Defines the structure to configure an ipv4 address
53 * @address : ipv4 address
54 * @broadcast : ipv4 broadcast address
55 * @mask : network mask
56 */
57struct lxc_inetdev {
58 struct in_addr addr;
59 struct in_addr bcast;
60 int prefix;
61};
62
63struct lxc_route {
64 struct in_addr addr;
65};
66
67/*
68 * Defines the structure to configure an ipv6 address
69 * @flags : set the address up
70 * @address : ipv6 address
71 * @broadcast : ipv6 broadcast address
72 * @mask : network mask
73 */
74struct lxc_inet6dev {
75 struct in6_addr addr;
0093bb8c 76 struct in6_addr mcast;
0ad19a3f 77 struct in6_addr acast;
78 int prefix;
79};
80
81struct lxc_route6 {
82 struct in6_addr addr;
83};
26c39028 84
e892973e
DL
85struct ifla_veth {
86 char *pair; /* pair name */
74a2b586 87 char veth1[IFNAMSIZ]; /* needed for deconf */
e892973e
DL
88};
89
26c39028 90struct ifla_vlan {
85dce4a5
NC
91 unsigned int flags;
92 unsigned int fmask;
7c11d57a
SG
93 unsigned short vid;
94 unsigned short pad;
26c39028
JHS
95};
96
e892973e
DL
97struct ifla_macvlan {
98 int mode; /* private, vepa, bridge */
99};
100
f6cc1de1 101union netdev_p {
e892973e 102 struct ifla_veth veth_attr;
f6cc1de1 103 struct ifla_vlan vlan_attr;
e892973e 104 struct ifla_macvlan macvlan_attr;
f6cc1de1
JHS
105};
106
0ad19a3f 107/*
108 * Defines a structure to configure a network device
e3b4c4c4
ST
109 * @link : lxc.network.link, name of bridge or host iface to attach if any
110 * @name : lxc.network.name, name of iface on the container side
111 * @flags : flag of the network device (IFF_UP, ... )
112 * @ipv4 : a list of ipv4 addresses to be set on the network device
113 * @ipv6 : a list of ipv6 addresses to be set on the network device
114 * @upscript : a script filename to be executed during interface configuration
74a2b586 115 * @downscript : a script filename to be executed during interface destruction
0ad19a3f 116 */
117struct lxc_netdev {
5f4535a3 118 int type;
0ad19a3f 119 int flags;
82d5ae15 120 int ifindex;
9d083402
MT
121 char *link;
122 char *name;
0ad19a3f 123 char *hwaddr;
442cbbe6 124 char *mtu;
f6cc1de1 125 union netdev_p priv;
0ad19a3f 126 struct lxc_list ipv4;
127 struct lxc_list ipv6;
f8fee0e2 128 struct in_addr *ipv4_gateway;
19a26f82 129 bool ipv4_gateway_auto;
f8fee0e2 130 struct in6_addr *ipv6_gateway;
19a26f82 131 bool ipv6_gateway_auto;
e3b4c4c4 132 char *upscript;
74a2b586 133 char *downscript;
0ad19a3f 134};
135
136/*
576f946d 137 * Defines a generic struct to configure the control group.
138 * It is up to the programmer to specify the right subsystem.
139 * @subsystem : the targetted subsystem
140 * @value : the value to set
0ad19a3f 141 */
142struct lxc_cgroup {
576f946d 143 char *subsystem;
144 char *value;
0ad19a3f 145};
146
f6d3e3e4
SH
147enum idtype {
148 ID_TYPE_UID,
149 ID_TYPE_GID
150};
151
152/*
153 * id_map is an id map entry. Form in confile is:
251d0d2a
DE
154 * lxc.id_map = u 0 9800 100
155 * lxc.id_map = u 1000 9900 100
156 * lxc.id_map = g 0 9800 100
157 * lxc.id_map = g 1000 9900 100
158 * meaning the container can use uids and gids 0-99 and 1000-1099,
159 * with [ug]id 0 mapping to [ug]id 9800 on the host, and [ug]id 1000 to
160 * [ug]id 9900 on the host.
f6d3e3e4
SH
161 */
162struct id_map {
163 enum idtype idtype;
251d0d2a 164 unsigned long hostid, nsid, range;
f6d3e3e4
SH
165};
166
b0a33c1e 167/*
168 * Defines a structure containing a pty information for
169 * virtualizing a tty
170 * @name : the path name of the slave pty side
171 * @master : the file descriptor of the master
172 * @slave : the file descriptor of the slave
173 */
174struct lxc_pty_info {
175 char name[MAXPATHLEN];
176 int master;
177 int slave;
178 int busy;
179};
180
181/*
182 * Defines the number of tty configured and contains the
183 * instanciated ptys
184 * @nbtty = number of configured ttys
185 */
186struct lxc_tty_info {
187 int nbtty;
188 struct lxc_pty_info *pty_info;
189};
190
b5159817
DE
191struct lxc_tty_state;
192
63376d7d
DL
193/*
194 * Defines the structure to store the console information
195 * @peer : the file descriptor put/get console traffic
196 * @name : the file name of the slave pty
197 */
198struct lxc_console {
199 int slave;
200 int master;
201 int peer;
b5159817
DE
202 struct lxc_pty_info peerpty;
203 struct lxc_epoll_descr *descr;
28a4b0e5 204 char *path;
596a818d
DE
205 char *log_path;
206 int log_fd;
63376d7d 207 char name[MAXPATHLEN];
e0dc0de7 208 struct termios *tios;
b5159817 209 struct lxc_tty_state *tty_state;
63376d7d
DL
210};
211
33fcb7a0
DL
212/*
213 * Defines a structure to store the rootfs location, the
214 * optionals pivot_root, rootfs mount paths
215 * @rootfs : a path to the rootfs
216 * @pivot_root : a path to a pivot_root location to be used
217 */
218struct lxc_rootfs {
219 char *path;
23b7ea69 220 char *mount;
33fcb7a0 221 char *pivot;
a17b1e65 222 char *options;
33fcb7a0
DL
223};
224
368bbc02
CS
225/*
226 * Automatic mounts for LXC to perform inside the container
227 */
228enum {
b06b8511
CS
229 LXC_AUTO_PROC_RW = 0x001, /* /proc read-write */
230 LXC_AUTO_PROC_MIXED = 0x002, /* /proc/sys and /proc/sysrq-trigger read-only */
231 LXC_AUTO_PROC_MASK = 0x003,
232
233 LXC_AUTO_SYS_RW = 0x004, /* /sys */
234 LXC_AUTO_SYS_RO = 0x008, /* /sys read-only */
235 LXC_AUTO_SYS_MASK = 0x00C,
236
237 LXC_AUTO_CGROUP_RO = 0x010, /* /sys/fs/cgroup (partial mount, read-only) */
238 LXC_AUTO_CGROUP_RW = 0x020, /* /sys/fs/cgroup (partial mount, read-write) */
239 LXC_AUTO_CGROUP_MIXED = 0x030, /* /sys/fs/cgroup (partial mount, paths r/o, cgroup r/w) */
240 LXC_AUTO_CGROUP_FULL_RO = 0x040, /* /sys/fs/cgroup (full mount, read-only) */
241 LXC_AUTO_CGROUP_FULL_RW = 0x050, /* /sys/fs/cgroup (full mount, read-write) */
242 LXC_AUTO_CGROUP_FULL_MIXED = 0x060, /* /sys/fs/cgroup (full mount, parent r/o, own r/w) */
0769b82a
CS
243 /* These are defined in such a way as to retain
244 * binary compatibility with earlier versions of
245 * this code. If the previous mask is applied,
246 * both of these will default back to the _MIXED
247 * variants, which is safe. */
248 LXC_AUTO_CGROUP_NOSPEC = 0x0B0, /* /sys/fs/cgroup (partial mount, r/w or mixed, depending on caps) */
249 LXC_AUTO_CGROUP_FULL_NOSPEC = 0x0E0, /* /sys/fs/cgroup (full mount, r/w or mixed, depending on caps) */
250 LXC_AUTO_CGROUP_MASK = 0x0F0,
b06b8511 251
0769b82a 252 LXC_AUTO_ALL_MASK = 0x0FF, /* all known settings */
368bbc02
CS
253};
254
571e6ec8
DL
255/*
256 * Defines the global container configuration
63376d7d
DL
257 * @rootfs : root directory to run the container
258 * @pivotdir : pivotdir path, if not set default will be used
259 * @mount : list of mount points
260 * @tty : numbers of tty
261 * @pts : new pts instance
262 * @mount_list : list of mount point (alternative to fstab file)
263 * @network : network configuration
264 * @utsname : container utsname
265 * @fstab : path to a fstab file format
1fb86a7c
SH
266 * @caps : list of the capabilities to drop
267 * @keepcaps : list of the capabilities to keep
63376d7d
DL
268 * @tty_info : tty data
269 * @console : console data
7c6ef2a2 270 * @ttydir : directory (under /dev) in which to create console and ttys
fe4de9a6
DE
271 * @lsm_aa_profile : apparmor profile to switch to or NULL
272 * @lsm_se_context : selinux type to switch to or NULL
571e6ec8 273 */
26ddeedd 274enum lxchooks {
f7bee6c6 275 LXCHOOK_PRESTART, LXCHOOK_PREMOUNT, LXCHOOK_MOUNT, LXCHOOK_AUTODEV,
148e91f5 276 LXCHOOK_START, LXCHOOK_POSTSTOP, LXCHOOK_CLONE, NUM_LXC_HOOKS};
72d0e1cb
SG
277extern char *lxchook_names[NUM_LXC_HOOKS];
278
7b35f3d6
SH
279struct saved_nic {
280 int ifindex;
281 char *orig_name;
282};
283
571e6ec8 284struct lxc_conf {
37903589 285 int is_execute;
f979ac15 286 bool unexpanded;
571e6ec8
DL
287 char *fstab;
288 int tty;
289 int pts;
91480a0f 290 int reboot;
828695d9 291 int need_utmp_watch;
9b8e3c96 292 signed long personality;
571e6ec8
DL
293 struct utsname *utsname;
294 struct lxc_list cgroup;
f6d3e3e4 295 struct lxc_list id_map;
5f4535a3 296 struct lxc_list network;
7b35f3d6
SH
297 struct saved_nic *saved_nics;
298 int num_savednics;
368bbc02 299 int auto_mounts;
e7938e9e 300 struct lxc_list mount_list;
81810dd1 301 struct lxc_list caps;
1fb86a7c 302 struct lxc_list keepcaps;
571e6ec8 303 struct lxc_tty_info tty_info;
63376d7d 304 struct lxc_console console;
33fcb7a0 305 struct lxc_rootfs rootfs;
7c6ef2a2 306 char *ttydir;
b119f362 307 int close_all_fds;
26ddeedd 308 struct lxc_list hooks[NUM_LXC_HOOKS];
4a85ce2a 309
fe4de9a6
DE
310 char *lsm_aa_profile;
311 char *lsm_se_context;
5112cd70 312 int tmp_umount_proc;
8f2c3a70 313 char *seccomp; // filename with the seccomp rules
769872f9 314#if HAVE_SCMP_FILTER_CTX
d58c6ad0 315 scmp_filter_ctx seccomp_ctx;
769872f9 316#endif
72d0e1cb 317 int maincmd_fd;
c6883f38 318 int autodev; // if 1, mount and fill a /dev at start
f0f1d8c0
DE
319 int haltsignal; // signal used to halt container
320 int stopsignal; // signal used to hard stop container
7e0e1d94 321 int kmsg; // if 1, create /dev/kmsg symlink
f7bee6c6 322 char *rcfile; // Copy of the top level rcfile we read
b40a606e
SH
323
324 // Logfile and logleve can be set in a container config file.
325 // Those function as defaults. The defaults can be overriden
326 // by command line. However we don't want the command line
327 // specified values to be saved on c->save_config(). So we
328 // store the config file specified values here.
329 char *logfile; // the logfile as specifed in config
330 int loglevel; // loglevel as specifed in config (if any)
9f30a190
MM
331
332 int inherit_ns_fd[LXC_NS_MAX];
ee1e7aa0
SG
333
334 int start_auto;
335 int start_delay;
336 int start_order;
337 struct lxc_list groups;
76a26f55 338 int nbd_idx;
35120d9c
SH
339
340 /* set to true when rootfs has been setup */
341 bool rootfs_setup;
f979ac15
SH
342
343 /* list of included files */
344 struct lxc_list includes;
4184c3e1
SH
345 /* config entries which are not "lxc.*" are aliens */
346 struct lxc_list aliens;
7c661726
MP
347
348 /* list of environment variables we'll add to the container when
349 * started */
350 struct lxc_list environment;
571e6ec8
DL
351};
352
283678ed
SH
353int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
354 const char *lxcpath, char *argv[]);
26ddeedd 355
cc28d0b0
SH
356extern int detect_shared_rootfs(void);
357
089cd8b8
DL
358/*
359 * Initialize the lxc configuration structure
360 */
7b379ab3 361extern struct lxc_conf *lxc_conf_init(void);
8eb5694b 362extern void lxc_conf_free(struct lxc_conf *conf);
089cd8b8 363
0c547523
SH
364extern int pin_rootfs(const char *rootfs);
365
26b797f3 366extern int lxc_requests_empty_network(struct lxc_handler *handler);
e3b4c4c4 367extern int lxc_create_network(struct lxc_handler *handler);
74a2b586 368extern void lxc_delete_network(struct lxc_handler *handler);
82d5ae15 369extern int lxc_assign_network(struct lxc_list *networks, pid_t pid);
f6d3e3e4 370extern int lxc_map_ids(struct lxc_list *idmap, pid_t pid);
19a26f82 371extern int lxc_find_gateway_addresses(struct lxc_handler *handler);
0ad19a3f 372
5e4a62bf 373extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
b0a33c1e 374extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
375
72d0e1cb 376extern int lxc_clear_config_network(struct lxc_conf *c);
12a50cc6 377extern int lxc_clear_nic(struct lxc_conf *c, const char *key);
72d0e1cb 378extern int lxc_clear_config_caps(struct lxc_conf *c);
1fb86a7c 379extern int lxc_clear_config_keepcaps(struct lxc_conf *c);
12a50cc6 380extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key);
72d0e1cb 381extern int lxc_clear_mount_entries(struct lxc_conf *c);
b099e9e9 382extern int lxc_clear_automounts(struct lxc_conf *c);
12a50cc6 383extern int lxc_clear_hooks(struct lxc_conf *c, const char *key);
7d0eb87e 384extern int lxc_clear_idmaps(struct lxc_conf *c);
ee1e7aa0 385extern int lxc_clear_groups(struct lxc_conf *c);
ab799c0b 386extern int lxc_clear_environment(struct lxc_conf *c);
72d0e1cb 387
35120d9c
SH
388extern int do_rootfs_setup(struct lxc_conf *conf, const char *name,
389 const char *lxcpath);
390
0ad19a3f 391/*
392 * Configure the container from inside
393 */
88d5514d 394
368bbc02 395struct cgroup_process_info;
d4ef7c50 396extern int lxc_setup(struct lxc_handler *handler);
7b35f3d6 397
2af6bd1b 398extern void lxc_rename_phys_nics_on_shutdown(int netnsfd, struct lxc_conf *conf);
cf3ef16d 399
2133f58c
SH
400extern int find_unmapped_nsuid(struct lxc_conf *conf, enum idtype idtype);
401extern int mapped_hostid(unsigned id, struct lxc_conf *conf, enum idtype idtype);
c4d10a05
SH
402extern int chown_mapped_root(char *path, struct lxc_conf *conf);
403extern int ttys_shift_ids(struct lxc_conf *c);
4355ab5f 404extern int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data);
a17b1e65
SG
405extern int parse_mntopts(const char *mntopts, unsigned long *mntflags,
406 char **mntdata);
5112cd70 407extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
0ad19a3f 408#endif