]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/conf.h
typofixes - https://github.com/vlajos/misspell_fixer
[mirror_lxc.git] / src / lxc / conf.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
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
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 #ifndef __LXC_CONF_H
24 #define __LXC_CONF_H
25
26 #include "config.h"
27
28 #include <netinet/in.h>
29 #include <net/if.h>
30 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <stdbool.h>
33
34 #include "list.h"
35 #include "start.h" /* for lxc_handler */
36
37 #if HAVE_SCMP_FILTER_CTX
38 typedef void * scmp_filter_ctx;
39 #endif
40
41 /* worth moving to configure.ac? */
42 #define subuidfile "/etc/subuid"
43 #define subgidfile "/etc/subgid"
44
45 enum {
46 LXC_NET_EMPTY,
47 LXC_NET_VETH,
48 LXC_NET_MACVLAN,
49 LXC_NET_PHYS,
50 LXC_NET_VLAN,
51 LXC_NET_NONE,
52 LXC_NET_MAXCONFTYPE,
53 };
54
55 /*
56 * Defines the structure to configure an ipv4 address
57 * @address : ipv4 address
58 * @broadcast : ipv4 broadcast address
59 * @mask : network mask
60 */
61 struct lxc_inetdev {
62 struct in_addr addr;
63 struct in_addr bcast;
64 int prefix;
65 };
66
67 struct lxc_route {
68 struct in_addr addr;
69 };
70
71 /*
72 * Defines the structure to configure an ipv6 address
73 * @flags : set the address up
74 * @address : ipv6 address
75 * @broadcast : ipv6 broadcast address
76 * @mask : network mask
77 */
78 struct lxc_inet6dev {
79 struct in6_addr addr;
80 struct in6_addr mcast;
81 struct in6_addr acast;
82 int prefix;
83 };
84
85 struct lxc_route6 {
86 struct in6_addr addr;
87 };
88
89 struct ifla_veth {
90 char *pair; /* pair name */
91 char veth1[IFNAMSIZ]; /* needed for deconf */
92 };
93
94 struct ifla_vlan {
95 unsigned int flags;
96 unsigned int fmask;
97 unsigned short vid;
98 unsigned short pad;
99 };
100
101 struct ifla_macvlan {
102 int mode; /* private, vepa, bridge */
103 };
104
105 union netdev_p {
106 struct ifla_veth veth_attr;
107 struct ifla_vlan vlan_attr;
108 struct ifla_macvlan macvlan_attr;
109 };
110
111 /*
112 * Defines a structure to configure a network device
113 * @link : lxc.network.link, name of bridge or host iface to attach if any
114 * @name : lxc.network.name, name of iface on the container side
115 * @flags : flag of the network device (IFF_UP, ... )
116 * @ipv4 : a list of ipv4 addresses to be set on the network device
117 * @ipv6 : a list of ipv6 addresses to be set on the network device
118 * @upscript : a script filename to be executed during interface configuration
119 * @downscript : a script filename to be executed during interface destruction
120 */
121 struct lxc_netdev {
122 int type;
123 int flags;
124 int ifindex;
125 char *link;
126 char *name;
127 char *hwaddr;
128 char *mtu;
129 union netdev_p priv;
130 struct lxc_list ipv4;
131 struct lxc_list ipv6;
132 struct in_addr *ipv4_gateway;
133 bool ipv4_gateway_auto;
134 struct in6_addr *ipv6_gateway;
135 bool ipv6_gateway_auto;
136 char *upscript;
137 char *downscript;
138 };
139
140 /*
141 * Defines a generic struct to configure the control group.
142 * It is up to the programmer to specify the right subsystem.
143 * @subsystem : the targeted subsystem
144 * @value : the value to set
145 */
146 struct lxc_cgroup {
147 char *subsystem;
148 char *value;
149 };
150
151 enum idtype {
152 ID_TYPE_UID,
153 ID_TYPE_GID
154 };
155
156 /*
157 * id_map is an id map entry. Form in confile is:
158 * lxc.id_map = u 0 9800 100
159 * lxc.id_map = u 1000 9900 100
160 * lxc.id_map = g 0 9800 100
161 * lxc.id_map = g 1000 9900 100
162 * meaning the container can use uids and gids 0-99 and 1000-1099,
163 * with [ug]id 0 mapping to [ug]id 9800 on the host, and [ug]id 1000 to
164 * [ug]id 9900 on the host.
165 */
166 struct id_map {
167 enum idtype idtype;
168 unsigned long hostid, nsid, range;
169 };
170
171 /*
172 * Defines a structure containing a pty information for
173 * virtualizing a tty
174 * @name : the path name of the slave pty side
175 * @master : the file descriptor of the master
176 * @slave : the file descriptor of the slave
177 */
178 struct lxc_pty_info {
179 char name[MAXPATHLEN];
180 int master;
181 int slave;
182 int busy;
183 };
184
185 /*
186 * Defines the number of tty configured and contains the
187 * instantiated ptys
188 * @nbtty = number of configured ttys
189 */
190 struct lxc_tty_info {
191 int nbtty;
192 struct lxc_pty_info *pty_info;
193 };
194
195 struct lxc_tty_state;
196
197 /*
198 * Defines the structure to store the console information
199 * @peer : the file descriptor put/get console traffic
200 * @name : the file name of the slave pty
201 */
202 struct lxc_console {
203 int slave;
204 int master;
205 int peer;
206 struct lxc_pty_info peerpty;
207 struct lxc_epoll_descr *descr;
208 char *path;
209 char *log_path;
210 int log_fd;
211 char name[MAXPATHLEN];
212 struct termios *tios;
213 struct lxc_tty_state *tty_state;
214 };
215
216 /*
217 * Defines a structure to store the rootfs location, the
218 * optionals pivot_root, rootfs mount paths
219 * @rootfs : a path to the rootfs
220 * @pivot_root : a path to a pivot_root location to be used
221 */
222 struct lxc_rootfs {
223 char *path;
224 char *mount;
225 char *pivot;
226 char *options;
227 };
228
229 /*
230 * Automatic mounts for LXC to perform inside the container
231 */
232 enum {
233 LXC_AUTO_PROC_RW = 0x001, /* /proc read-write */
234 LXC_AUTO_PROC_MIXED = 0x002, /* /proc/sys and /proc/sysrq-trigger read-only */
235 LXC_AUTO_PROC_MASK = 0x003,
236
237 LXC_AUTO_SYS_RW = 0x004, /* /sys */
238 LXC_AUTO_SYS_RO = 0x008, /* /sys read-only */
239 LXC_AUTO_SYS_MASK = 0x00C,
240
241 LXC_AUTO_CGROUP_RO = 0x010, /* /sys/fs/cgroup (partial mount, read-only) */
242 LXC_AUTO_CGROUP_RW = 0x020, /* /sys/fs/cgroup (partial mount, read-write) */
243 LXC_AUTO_CGROUP_MIXED = 0x030, /* /sys/fs/cgroup (partial mount, paths r/o, cgroup r/w) */
244 LXC_AUTO_CGROUP_FULL_RO = 0x040, /* /sys/fs/cgroup (full mount, read-only) */
245 LXC_AUTO_CGROUP_FULL_RW = 0x050, /* /sys/fs/cgroup (full mount, read-write) */
246 LXC_AUTO_CGROUP_FULL_MIXED = 0x060, /* /sys/fs/cgroup (full mount, parent r/o, own r/w) */
247 /* These are defined in such a way as to retain
248 * binary compatibility with earlier versions of
249 * this code. If the previous mask is applied,
250 * both of these will default back to the _MIXED
251 * variants, which is safe. */
252 LXC_AUTO_CGROUP_NOSPEC = 0x0B0, /* /sys/fs/cgroup (partial mount, r/w or mixed, depending on caps) */
253 LXC_AUTO_CGROUP_FULL_NOSPEC = 0x0E0, /* /sys/fs/cgroup (full mount, r/w or mixed, depending on caps) */
254 LXC_AUTO_CGROUP_MASK = 0x0F0,
255
256 LXC_AUTO_ALL_MASK = 0x0FF, /* all known settings */
257 };
258
259 /*
260 * Defines the global container configuration
261 * @rootfs : root directory to run the container
262 * @pivotdir : pivotdir path, if not set default will be used
263 * @mount : list of mount points
264 * @tty : numbers of tty
265 * @pts : new pts instance
266 * @mount_list : list of mount point (alternative to fstab file)
267 * @network : network configuration
268 * @utsname : container utsname
269 * @fstab : path to a fstab file format
270 * @caps : list of the capabilities to drop
271 * @keepcaps : list of the capabilities to keep
272 * @tty_info : tty data
273 * @console : console data
274 * @ttydir : directory (under /dev) in which to create console and ttys
275 * @lsm_aa_profile : apparmor profile to switch to or NULL
276 * @lsm_se_context : selinux type to switch to or NULL
277 */
278 enum lxchooks {
279 LXCHOOK_PRESTART, LXCHOOK_PREMOUNT, LXCHOOK_MOUNT, LXCHOOK_AUTODEV,
280 LXCHOOK_START, LXCHOOK_POSTSTOP, LXCHOOK_CLONE, NUM_LXC_HOOKS};
281 extern char *lxchook_names[NUM_LXC_HOOKS];
282
283 struct saved_nic {
284 int ifindex;
285 char *orig_name;
286 };
287
288 struct lxc_conf {
289 int is_execute;
290 char *fstab;
291 int tty;
292 int pts;
293 int reboot;
294 int need_utmp_watch;
295 signed long personality;
296 struct utsname *utsname;
297 struct lxc_list cgroup;
298 struct lxc_list id_map;
299 struct lxc_list network;
300 struct saved_nic *saved_nics;
301 int num_savednics;
302 int auto_mounts;
303 struct lxc_list mount_list;
304 struct lxc_list caps;
305 struct lxc_list keepcaps;
306 struct lxc_tty_info tty_info;
307 struct lxc_console console;
308 struct lxc_rootfs rootfs;
309 char *ttydir;
310 int close_all_fds;
311 struct lxc_list hooks[NUM_LXC_HOOKS];
312
313 char *lsm_aa_profile;
314 int lsm_aa_allow_incomplete;
315 char *lsm_se_context;
316 int tmp_umount_proc;
317 char *seccomp; // filename with the seccomp rules
318 #if HAVE_SCMP_FILTER_CTX
319 scmp_filter_ctx seccomp_ctx;
320 #endif
321 int maincmd_fd;
322 int autodev; // if 1, mount and fill a /dev at start
323 int haltsignal; // signal used to halt container
324 int stopsignal; // signal used to hard stop container
325 int kmsg; // if 1, create /dev/kmsg symlink
326 char *rcfile; // Copy of the top level rcfile we read
327
328 // Logfile and logleve can be set in a container config file.
329 // Those function as defaults. The defaults can be overriden
330 // by command line. However we don't want the command line
331 // specified values to be saved on c->save_config(). So we
332 // store the config file specified values here.
333 char *logfile; // the logfile as specifed in config
334 int loglevel; // loglevel as specifed in config (if any)
335
336 int inherit_ns_fd[LXC_NS_MAX];
337
338 int start_auto;
339 int start_delay;
340 int start_order;
341 struct lxc_list groups;
342 int nbd_idx;
343
344 /* set to true when rootfs has been setup */
345 bool rootfs_setup;
346
347 /* list of included files */
348 struct lxc_list includes;
349 /* config entries which are not "lxc.*" are aliens */
350 struct lxc_list aliens;
351
352 /* list of environment variables we'll add to the container when
353 * started */
354 struct lxc_list environment;
355
356 /* text representation of the config file */
357 char *unexpanded_config;
358 size_t unexpanded_len, unexpanded_alloced;
359
360 /* init command */
361 char *init_cmd;
362 };
363
364 int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
365 const char *lxcpath, char *argv[]);
366
367 extern int detect_shared_rootfs(void);
368
369 /*
370 * Initialize the lxc configuration structure
371 */
372 extern struct lxc_conf *lxc_conf_init(void);
373 extern void lxc_conf_free(struct lxc_conf *conf);
374
375 extern int pin_rootfs(const char *rootfs);
376
377 extern int lxc_requests_empty_network(struct lxc_handler *handler);
378 extern int lxc_create_network(struct lxc_handler *handler);
379 extern void lxc_delete_network(struct lxc_handler *handler);
380 extern int lxc_assign_network(struct lxc_list *networks, pid_t pid);
381 extern int lxc_map_ids(struct lxc_list *idmap, pid_t pid);
382 extern int lxc_find_gateway_addresses(struct lxc_handler *handler);
383
384 extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
385 extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
386
387 extern int lxc_clear_config_network(struct lxc_conf *c);
388 extern int lxc_clear_nic(struct lxc_conf *c, const char *key);
389 extern int lxc_clear_config_caps(struct lxc_conf *c);
390 extern int lxc_clear_config_keepcaps(struct lxc_conf *c);
391 extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key);
392 extern int lxc_clear_mount_entries(struct lxc_conf *c);
393 extern int lxc_clear_automounts(struct lxc_conf *c);
394 extern int lxc_clear_hooks(struct lxc_conf *c, const char *key);
395 extern int lxc_clear_idmaps(struct lxc_conf *c);
396 extern int lxc_clear_groups(struct lxc_conf *c);
397 extern int lxc_clear_environment(struct lxc_conf *c);
398 extern int lxc_delete_autodev(struct lxc_handler *handler);
399
400 extern int do_rootfs_setup(struct lxc_conf *conf, const char *name,
401 const char *lxcpath);
402
403 /*
404 * Configure the container from inside
405 */
406
407 struct cgroup_process_info;
408 extern int lxc_setup(struct lxc_handler *handler);
409
410 extern void lxc_rename_phys_nics_on_shutdown(int netnsfd, struct lxc_conf *conf);
411
412 extern int find_unmapped_nsuid(struct lxc_conf *conf, enum idtype idtype);
413 extern int mapped_hostid(unsigned id, struct lxc_conf *conf, enum idtype idtype);
414 extern int chown_mapped_root(char *path, struct lxc_conf *conf);
415 extern int ttys_shift_ids(struct lxc_conf *c);
416 extern int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data);
417 extern int parse_mntopts(const char *mntopts, unsigned long *mntflags,
418 char **mntdata);
419 extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
420 void remount_all_slave(void);
421 extern void suggest_default_idmap(void);
422 #endif