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