2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
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.
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.
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
28 #include <netinet/in.h>
30 #include <sys/param.h>
31 #include <sys/types.h>
36 #include <lxc/start.h> /* for lxc_handler */
38 #if HAVE_SCMP_FILTER_CTX
39 typedef void * scmp_filter_ctx
;
52 * Defines the structure to configure an ipv4 address
53 * @address : ipv4 address
54 * @broadcast : ipv4 broadcast address
55 * @mask : network mask
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
76 struct in6_addr mcast
;
77 struct in6_addr acast
;
86 char *pair
; /* pair name */
87 char veth1
[IFNAMSIZ
]; /* needed for deconf */
98 int mode
; /* private, vepa, bridge */
102 struct ifla_veth veth_attr
;
103 struct ifla_vlan vlan_attr
;
104 struct ifla_macvlan macvlan_attr
;
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
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
;
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
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.
164 unsigned long hostid
, nsid
, range
;
168 * Defines a structure containing a pty information for
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
174 struct lxc_pty_info
{
175 char name
[MAXPATHLEN
];
182 * Defines the number of tty configured and contains the
184 * @nbtty = number of configured ttys
186 struct lxc_tty_info
{
188 struct lxc_pty_info
*pty_info
;
191 struct lxc_tty_state
;
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
202 struct lxc_pty_info peerpty
;
203 struct lxc_epoll_descr
*descr
;
207 char name
[MAXPATHLEN
];
208 struct termios
*tios
;
209 struct lxc_tty_state
*tty_state
;
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
225 * Automatic mounts for LXC to perform inside the container
228 LXC_AUTO_PROC_RW
= 0x001, /* /proc read-write */
229 LXC_AUTO_PROC_MIXED
= 0x002, /* /proc/sys and /proc/sysrq-trigger read-only */
230 LXC_AUTO_PROC_MASK
= 0x003,
232 LXC_AUTO_SYS_RW
= 0x004, /* /sys */
233 LXC_AUTO_SYS_RO
= 0x008, /* /sys read-only */
234 LXC_AUTO_SYS_MASK
= 0x00C,
236 LXC_AUTO_CGROUP_RO
= 0x010, /* /sys/fs/cgroup (partial mount, read-only) */
237 LXC_AUTO_CGROUP_RW
= 0x020, /* /sys/fs/cgroup (partial mount, read-write) */
238 LXC_AUTO_CGROUP_MIXED
= 0x030, /* /sys/fs/cgroup (partial mount, paths r/o, cgroup r/w) */
239 LXC_AUTO_CGROUP_FULL_RO
= 0x040, /* /sys/fs/cgroup (full mount, read-only) */
240 LXC_AUTO_CGROUP_FULL_RW
= 0x050, /* /sys/fs/cgroup (full mount, read-write) */
241 LXC_AUTO_CGROUP_FULL_MIXED
= 0x060, /* /sys/fs/cgroup (full mount, parent r/o, own r/w) */
242 LXC_AUTO_CGROUP_MASK
= 0x070,
244 LXC_AUTO_ALL_MASK
= 0x07F, /* all known settings */
248 * Defines the global container configuration
249 * @rootfs : root directory to run the container
250 * @pivotdir : pivotdir path, if not set default will be used
251 * @mount : list of mount points
252 * @tty : numbers of tty
253 * @pts : new pts instance
254 * @mount_list : list of mount point (alternative to fstab file)
255 * @network : network configuration
256 * @utsname : container utsname
257 * @fstab : path to a fstab file format
258 * @caps : list of the capabilities to drop
259 * @keepcaps : list of the capabilities to keep
260 * @tty_info : tty data
261 * @console : console data
262 * @ttydir : directory (under /dev) in which to create console and ttys
263 * @lsm_aa_profile : apparmor profile to switch to or NULL
264 * @lsm_se_context : selinux type to switch to or NULL
267 LXCHOOK_PRESTART
, LXCHOOK_PREMOUNT
, LXCHOOK_MOUNT
, LXCHOOK_AUTODEV
,
268 LXCHOOK_START
, LXCHOOK_POSTSTOP
, LXCHOOK_CLONE
, NUM_LXC_HOOKS
};
269 extern char *lxchook_names
[NUM_LXC_HOOKS
];
284 struct utsname
*utsname
;
285 struct lxc_list cgroup
;
286 struct lxc_list id_map
;
287 struct lxc_list network
;
288 struct saved_nic
*saved_nics
;
291 struct lxc_list mount_list
;
292 struct lxc_list caps
;
293 struct lxc_list keepcaps
;
294 struct lxc_tty_info tty_info
;
295 struct lxc_console console
;
296 struct lxc_rootfs rootfs
;
299 struct lxc_list hooks
[NUM_LXC_HOOKS
];
301 char *lsm_aa_profile
;
302 char *lsm_se_context
;
304 char *seccomp
; // filename with the seccomp rules
305 #if HAVE_SCMP_FILTER_CTX
306 scmp_filter_ctx
*seccomp_ctx
;
309 int autodev
; // if 1, mount and fill a /dev at start
310 int stopsignal
; // signal used to stop container
311 int kmsg
; // if 1, create /dev/kmsg symlink
312 char *rcfile
; // Copy of the top level rcfile we read
314 // Logfile and logleve can be set in a container config file.
315 // Those function as defaults. The defaults can be overriden
316 // by command line. However we don't want the command line
317 // specified values to be saved on c->save_config(). So we
318 // store the config file specified values here.
319 char *logfile
; // the logfile as specifed in config
320 int loglevel
; // loglevel as specifed in config (if any)
323 int run_lxc_hooks(const char *name
, char *hook
, struct lxc_conf
*conf
,
324 const char *lxcpath
, char *argv
[]);
326 extern int detect_shared_rootfs(void);
329 * Initialize the lxc configuration structure
331 extern struct lxc_conf
*lxc_conf_init(void);
332 extern void lxc_conf_free(struct lxc_conf
*conf
);
334 extern int pin_rootfs(const char *rootfs
);
336 extern int lxc_create_network(struct lxc_handler
*handler
);
337 extern void lxc_delete_network(struct lxc_handler
*handler
);
338 extern int lxc_assign_network(struct lxc_list
*networks
, pid_t pid
);
339 extern int lxc_map_ids(struct lxc_list
*idmap
, pid_t pid
);
340 extern int lxc_find_gateway_addresses(struct lxc_handler
*handler
);
342 extern int lxc_create_tty(const char *name
, struct lxc_conf
*conf
);
343 extern void lxc_delete_tty(struct lxc_tty_info
*tty_info
);
345 extern int lxc_clear_config_network(struct lxc_conf
*c
);
346 extern int lxc_clear_nic(struct lxc_conf
*c
, const char *key
);
347 extern int lxc_clear_config_caps(struct lxc_conf
*c
);
348 extern int lxc_clear_config_keepcaps(struct lxc_conf
*c
);
349 extern int lxc_clear_cgroups(struct lxc_conf
*c
, const char *key
);
350 extern int lxc_clear_mount_entries(struct lxc_conf
*c
);
351 extern int lxc_clear_hooks(struct lxc_conf
*c
, const char *key
);
354 * Configure the container from inside
357 struct cgroup_process_info
;
358 extern int lxc_setup(const char *name
, struct lxc_conf
*lxc_conf
,
360 struct cgroup_process_info
*cgroup_info
,
363 extern void lxc_rename_phys_nics_on_shutdown(struct lxc_conf
*conf
);
365 extern uid_t
get_mapped_rootid(struct lxc_conf
*conf
);
366 extern int find_unmapped_nsuid(struct lxc_conf
*conf
);
367 extern int mapped_hostid(int id
, struct lxc_conf
*conf
);
368 extern int chown_mapped_root(char *path
, struct lxc_conf
*conf
);
369 extern int ttys_shift_ids(struct lxc_conf
*c
);