]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/conf.h
confile.c: clear entries if no value
[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 _conf_h
24 #define _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 <lxc/list.h>
35
36 #include <lxc/start.h> /* for lxc_handler */
37
38 #if HAVE_SCMP_FILTER_CTX
39 typedef void * scmp_filter_ctx;
40 #endif
41
42 enum {
43 LXC_NET_EMPTY,
44 LXC_NET_VETH,
45 LXC_NET_MACVLAN,
46 LXC_NET_PHYS,
47 LXC_NET_VLAN,
48 LXC_NET_MAXCONFTYPE,
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 */
57 struct lxc_inetdev {
58 struct in_addr addr;
59 struct in_addr bcast;
60 int prefix;
61 };
62
63 struct 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 */
74 struct lxc_inet6dev {
75 struct in6_addr addr;
76 struct in6_addr mcast;
77 struct in6_addr acast;
78 int prefix;
79 };
80
81 struct lxc_route6 {
82 struct in6_addr addr;
83 };
84
85 struct ifla_veth {
86 char *pair; /* pair name */
87 char veth1[IFNAMSIZ]; /* needed for deconf */
88 };
89
90 struct ifla_vlan {
91 uint flags;
92 uint fmask;
93 unsigned short vid;
94 unsigned short pad;
95 };
96
97 struct ifla_macvlan {
98 int mode; /* private, vepa, bridge */
99 };
100
101 union netdev_p {
102 struct ifla_veth veth_attr;
103 struct ifla_vlan vlan_attr;
104 struct ifla_macvlan macvlan_attr;
105 };
106
107 /*
108 * Defines a structure to configure a network device
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
115 * @downscript : a script filename to be executed during interface destruction
116 */
117 struct lxc_netdev {
118 int type;
119 int flags;
120 int ifindex;
121 char *link;
122 char *name;
123 char *hwaddr;
124 char *mtu;
125 union netdev_p priv;
126 struct lxc_list ipv4;
127 struct lxc_list ipv6;
128 struct in_addr *ipv4_gateway;
129 bool ipv4_gateway_auto;
130 struct in6_addr *ipv6_gateway;
131 bool ipv6_gateway_auto;
132 char *upscript;
133 char *downscript;
134 };
135
136 /*
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
141 */
142 struct lxc_cgroup {
143 char *subsystem;
144 char *value;
145 };
146
147 enum idtype {
148 ID_TYPE_UID,
149 ID_TYPE_GID
150 };
151
152 /*
153 * id_map is an id map entry. Form in confile is:
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.
161 */
162 struct id_map {
163 enum idtype idtype;
164 unsigned long hostid, nsid, range;
165 };
166
167 extern int lxc_free_idmap(struct lxc_list *idmap);
168
169 /*
170 * Defines a structure containing a pty information for
171 * virtualizing a tty
172 * @name : the path name of the slave pty side
173 * @master : the file descriptor of the master
174 * @slave : the file descriptor of the slave
175 */
176 struct lxc_pty_info {
177 char name[MAXPATHLEN];
178 int master;
179 int slave;
180 int busy;
181 };
182
183 /*
184 * Defines the number of tty configured and contains the
185 * instanciated ptys
186 * @nbtty = number of configured ttys
187 */
188 struct lxc_tty_info {
189 int nbtty;
190 struct lxc_pty_info *pty_info;
191 };
192
193 struct lxc_tty_state;
194
195 /*
196 * Defines the structure to store the console information
197 * @peer : the file descriptor put/get console traffic
198 * @name : the file name of the slave pty
199 */
200 struct lxc_console {
201 int slave;
202 int master;
203 int peer;
204 struct lxc_pty_info peerpty;
205 struct lxc_epoll_descr *descr;
206 char *path;
207 char *log_path;
208 int log_fd;
209 char name[MAXPATHLEN];
210 struct termios *tios;
211 struct lxc_tty_state *tty_state;
212 };
213
214 /*
215 * Defines a structure to store the rootfs location, the
216 * optionals pivot_root, rootfs mount paths
217 * @rootfs : a path to the rootfs
218 * @pivot_root : a path to a pivot_root location to be used
219 */
220 struct lxc_rootfs {
221 char *path;
222 char *mount;
223 char *pivot;
224 };
225
226 /*
227 * Automatic mounts for LXC to perform inside the container
228 */
229 enum {
230 LXC_AUTO_PROC_RW = 0x001, /* /proc read-write */
231 LXC_AUTO_PROC_MIXED = 0x002, /* /proc/sys and /proc/sysrq-trigger read-only */
232 LXC_AUTO_PROC_MASK = 0x003,
233
234 LXC_AUTO_SYS_RW = 0x004, /* /sys */
235 LXC_AUTO_SYS_RO = 0x008, /* /sys read-only */
236 LXC_AUTO_SYS_MASK = 0x00C,
237
238 LXC_AUTO_CGROUP_RO = 0x010, /* /sys/fs/cgroup (partial mount, read-only) */
239 LXC_AUTO_CGROUP_RW = 0x020, /* /sys/fs/cgroup (partial mount, read-write) */
240 LXC_AUTO_CGROUP_MIXED = 0x030, /* /sys/fs/cgroup (partial mount, paths r/o, cgroup r/w) */
241 LXC_AUTO_CGROUP_FULL_RO = 0x040, /* /sys/fs/cgroup (full mount, read-only) */
242 LXC_AUTO_CGROUP_FULL_RW = 0x050, /* /sys/fs/cgroup (full mount, read-write) */
243 LXC_AUTO_CGROUP_FULL_MIXED = 0x060, /* /sys/fs/cgroup (full mount, parent r/o, own r/w) */
244 LXC_AUTO_CGROUP_MASK = 0x070,
245
246 LXC_AUTO_ALL_MASK = 0x07F, /* all known settings */
247 };
248
249 /*
250 * Defines the global container configuration
251 * @rootfs : root directory to run the container
252 * @pivotdir : pivotdir path, if not set default will be used
253 * @mount : list of mount points
254 * @tty : numbers of tty
255 * @pts : new pts instance
256 * @mount_list : list of mount point (alternative to fstab file)
257 * @network : network configuration
258 * @utsname : container utsname
259 * @fstab : path to a fstab file format
260 * @caps : list of the capabilities to drop
261 * @keepcaps : list of the capabilities to keep
262 * @tty_info : tty data
263 * @console : console data
264 * @ttydir : directory (under /dev) in which to create console and ttys
265 * @lsm_aa_profile : apparmor profile to switch to or NULL
266 * @lsm_se_context : selinux type to switch to or NULL
267 */
268 enum lxchooks {
269 LXCHOOK_PRESTART, LXCHOOK_PREMOUNT, LXCHOOK_MOUNT, LXCHOOK_AUTODEV,
270 LXCHOOK_START, LXCHOOK_POSTSTOP, LXCHOOK_CLONE, NUM_LXC_HOOKS};
271 extern char *lxchook_names[NUM_LXC_HOOKS];
272
273 struct saved_nic {
274 int ifindex;
275 char *orig_name;
276 };
277
278 struct lxc_conf {
279 int is_execute;
280 char *fstab;
281 int tty;
282 int pts;
283 int reboot;
284 int need_utmp_watch;
285 int personality;
286 struct utsname *utsname;
287 struct lxc_list cgroup;
288 struct lxc_list id_map;
289 struct lxc_list network;
290 struct saved_nic *saved_nics;
291 int num_savednics;
292 int auto_mounts;
293 struct lxc_list mount_list;
294 struct lxc_list caps;
295 struct lxc_list keepcaps;
296 struct lxc_tty_info tty_info;
297 struct lxc_console console;
298 struct lxc_rootfs rootfs;
299 char *ttydir;
300 int close_all_fds;
301 struct lxc_list hooks[NUM_LXC_HOOKS];
302
303 char *lsm_aa_profile;
304 char *lsm_se_context;
305 int lsm_umount_proc;
306 char *seccomp; // filename with the seccomp rules
307 #if HAVE_SCMP_FILTER_CTX
308 scmp_filter_ctx *seccomp_ctx;
309 #endif
310 int maincmd_fd;
311 int autodev; // if 1, mount and fill a /dev at start
312 int stopsignal; // signal used to stop container
313 int kmsg; // if 1, create /dev/kmsg symlink
314 char *rcfile; // Copy of the top level rcfile we read
315
316 // Logfile and logleve can be set in a container config file.
317 // Those function as defaults. The defaults can be overriden
318 // by command line. However we don't want the command line
319 // specified values to be saved on c->save_config(). So we
320 // store the config file specified values here.
321 char *logfile; // the logfile as specifed in config
322 int loglevel; // loglevel as specifed in config (if any)
323
324 int inherit_ns_fd[LXC_NS_MAX];
325 };
326
327 int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
328 const char *lxcpath, char *argv[]);
329
330 extern int detect_shared_rootfs(void);
331
332 /*
333 * Initialize the lxc configuration structure
334 */
335 extern struct lxc_conf *lxc_conf_init(void);
336 extern void lxc_conf_free(struct lxc_conf *conf);
337
338 extern int pin_rootfs(const char *rootfs);
339
340 extern int lxc_create_network(struct lxc_handler *handler);
341 extern void lxc_delete_network(struct lxc_handler *handler);
342 extern int lxc_assign_network(struct lxc_list *networks, pid_t pid);
343 extern int lxc_map_ids(struct lxc_list *idmap, pid_t pid);
344 extern int lxc_find_gateway_addresses(struct lxc_handler *handler);
345
346 extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
347 extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
348
349 extern int lxc_clear_config_network(struct lxc_conf *c);
350 extern int lxc_clear_nic(struct lxc_conf *c, const char *key);
351 extern int lxc_clear_config_caps(struct lxc_conf *c);
352 extern int lxc_clear_config_keepcaps(struct lxc_conf *c);
353 extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key);
354 extern int lxc_clear_mount_entries(struct lxc_conf *c);
355 extern int lxc_clear_hooks(struct lxc_conf *c, const char *key);
356 extern int lxc_clear_idmaps(struct lxc_conf *c);
357
358 /*
359 * Configure the container from inside
360 */
361
362 struct cgroup_process_info;
363 extern int lxc_setup(const char *name, struct lxc_conf *lxc_conf,
364 const char *lxcpath,
365 struct cgroup_process_info *cgroup_info,
366 void *data);
367
368 extern void lxc_rename_phys_nics_on_shutdown(struct lxc_conf *conf);
369
370 extern uid_t get_mapped_rootid(struct lxc_conf *conf);
371 extern int find_unmapped_nsuid(struct lxc_conf *conf);
372 extern int mapped_hostid(int id, struct lxc_conf *conf);
373 extern int chown_mapped_root(char *path, struct lxc_conf *conf);
374 extern int ttys_shift_ids(struct lxc_conf *c);
375 extern int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data);
376 #endif