]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/conf.h
cgroups: rework to handle nested containers with multiple and partial mounts
[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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 /*
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 */
174 struct 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 */
186 struct lxc_tty_info {
187 int nbtty;
188 struct lxc_pty_info *pty_info;
189 };
190
191 struct lxc_tty_state;
192
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 */
198 struct lxc_console {
199 int slave;
200 int master;
201 int peer;
202 struct lxc_pty_info peerpty;
203 struct lxc_epoll_descr *descr;
204 char *path;
205 char *log_path;
206 int log_fd;
207 char name[MAXPATHLEN];
208 struct termios *tios;
209 struct lxc_tty_state *tty_state;
210 };
211
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 */
218 struct lxc_rootfs {
219 char *path;
220 char *mount;
221 char *pivot;
222 };
223
224 /*
225 * Defines the global container configuration
226 * @rootfs : root directory to run the container
227 * @pivotdir : pivotdir path, if not set default will be used
228 * @mount : list of mount points
229 * @tty : numbers of tty
230 * @pts : new pts instance
231 * @mount_list : list of mount point (alternative to fstab file)
232 * @network : network configuration
233 * @utsname : container utsname
234 * @fstab : path to a fstab file format
235 * @caps : list of the capabilities
236 * @tty_info : tty data
237 * @console : console data
238 * @ttydir : directory (under /dev) in which to create console and ttys
239 #if HAVE_APPARMOR
240 * @aa_profile : apparmor profile to switch to
241 #endif
242 */
243 enum lxchooks {
244 LXCHOOK_PRESTART, LXCHOOK_PREMOUNT, LXCHOOK_MOUNT, LXCHOOK_AUTODEV,
245 LXCHOOK_START, LXCHOOK_POSTSTOP, LXCHOOK_CLONE, NUM_LXC_HOOKS};
246 extern char *lxchook_names[NUM_LXC_HOOKS];
247
248 struct saved_nic {
249 int ifindex;
250 char *orig_name;
251 };
252
253 struct lxc_conf {
254 int is_execute;
255 char *fstab;
256 int tty;
257 int pts;
258 int reboot;
259 int need_utmp_watch;
260 int personality;
261 struct utsname *utsname;
262 struct lxc_list cgroup;
263 struct lxc_list id_map;
264 struct lxc_list network;
265 struct saved_nic *saved_nics;
266 int num_savednics;
267 struct lxc_list mount_list;
268 struct lxc_list caps;
269 struct lxc_tty_info tty_info;
270 struct lxc_console console;
271 struct lxc_rootfs rootfs;
272 char *ttydir;
273 int close_all_fds;
274 struct lxc_list hooks[NUM_LXC_HOOKS];
275 #if HAVE_APPARMOR
276 char *aa_profile;
277 #endif
278
279 #if HAVE_APPARMOR /* || HAVE_SELINUX || HAVE_SMACK */
280 int lsm_umount_proc;
281 #endif
282 char *seccomp; // filename with the seccomp rules
283 #if HAVE_SCMP_FILTER_CTX
284 scmp_filter_ctx *seccomp_ctx;
285 #endif
286 int maincmd_fd;
287 int autodev; // if 1, mount and fill a /dev at start
288 int stopsignal; // signal used to stop container
289 int kmsg; // if 1, create /dev/kmsg symlink
290 char *rcfile; // Copy of the top level rcfile we read
291
292 // Logfile and logleve can be set in a container config file.
293 // Those function as defaults. The defaults can be overriden
294 // by command line. However we don't want the command line
295 // specified values to be saved on c->save_config(). So we
296 // store the config file specified values here.
297 char *logfile; // the logfile as specifed in config
298 int loglevel; // loglevel as specifed in config (if any)
299 };
300
301 int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
302 const char *lxcpath, char *argv[]);
303
304 extern int detect_shared_rootfs(void);
305
306 /*
307 * Initialize the lxc configuration structure
308 */
309 extern struct lxc_conf *lxc_conf_init(void);
310 extern void lxc_conf_free(struct lxc_conf *conf);
311
312 extern int pin_rootfs(const char *rootfs);
313
314 extern int lxc_create_network(struct lxc_handler *handler);
315 extern void lxc_delete_network(struct lxc_handler *handler);
316 extern int lxc_assign_network(struct lxc_list *networks, pid_t pid);
317 extern int lxc_map_ids(struct lxc_list *idmap, pid_t pid);
318 extern int lxc_find_gateway_addresses(struct lxc_handler *handler);
319
320 extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
321 extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
322
323 extern int lxc_clear_config_network(struct lxc_conf *c);
324 extern int lxc_clear_nic(struct lxc_conf *c, const char *key);
325 extern int lxc_clear_config_caps(struct lxc_conf *c);
326 extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key);
327 extern int lxc_clear_mount_entries(struct lxc_conf *c);
328 extern int lxc_clear_hooks(struct lxc_conf *c, const char *key);
329
330 extern int uid_shift_ttys(int pid, struct lxc_conf *conf);
331
332 /*
333 * Configure the container from inside
334 */
335
336 extern int lxc_setup(const char *name, struct lxc_conf *lxc_conf,
337 const char *lxcpath);
338
339 extern void lxc_rename_phys_nics_on_shutdown(struct lxc_conf *conf);
340 #endif