]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/lxc/conf.h
use same ifndef/define format for all headers
[mirror_lxc.git] / src / lxc / conf.h
index c9657c9054e1c34c1ef2cf110183539a10279d7e..2cfcb7c35ccf97cd556809989613640c9a223020 100644 (file)
@@ -4,7 +4,7 @@
  * (C) Copyright IBM Corp. 2007, 2008
  *
  * Authors:
- * Daniel Lezcano <dlezcano at fr.ibm.com>
+ * Daniel Lezcano <daniel.lezcano at free.fr>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-#ifndef _conf_h
-#define _conf_h
+#ifndef __LXC_CONF_H
+#define __LXC_CONF_H
+
+#include "config.h"
 
 #include <netinet/in.h>
+#include <net/if.h>
 #include <sys/param.h>
+#include <sys/types.h>
+#include <stdbool.h>
+
+#include "list.h"
+#include "start.h" /* for lxc_handler */
 
-#include <lxc/list.h>
+#if HAVE_SCMP_FILTER_CTX
+typedef void * scmp_filter_ctx;
+#endif
 
 enum {
-       EMPTY,
-       VETH,
-       MACVLAN,
-       PHYS,
-       VLAN,
-       MAXCONFTYPE,
+       LXC_NET_EMPTY,
+       LXC_NET_VETH,
+       LXC_NET_MACVLAN,
+       LXC_NET_PHYS,
+       LXC_NET_VLAN,
+       LXC_NET_NONE,
+       LXC_NET_MAXCONFTYPE,
 };
 
 /*
@@ -62,7 +73,7 @@ struct lxc_route {
  */
 struct lxc_inet6dev {
        struct in6_addr addr;
-       struct in6_addr bcast;
+       struct in6_addr mcast;
        struct in6_addr acast;
        int prefix;
 };
@@ -73,13 +84,14 @@ struct lxc_route6 {
 
 struct ifla_veth {
        char *pair; /* pair name */
+       char veth1[IFNAMSIZ]; /* needed for deconf */
 };
 
 struct ifla_vlan {
-       uint   flags;
-       uint   fmask;
-       ushort   vid;
-       ushort   pad;
+       unsigned int   flags;
+       unsigned int   fmask;
+       unsigned short   vid;
+       unsigned short   pad;
 };
 
 struct ifla_macvlan {
@@ -94,11 +106,13 @@ union netdev_p {
 
 /*
  * Defines a structure to configure a network device
- * @link   : lxc.network.link, name of bridge or host iface to attach if any
- * @name   : lxc.network.name, name of iface on the container side
- * @flags  : flag of the network device (IFF_UP, ... )
- * @ipv4   : a list of ipv4 addresses to be set on the network device
- * @ipv6   : a list of ipv6 addresses to be set on the network device
+ * @link       : lxc.network.link, name of bridge or host iface to attach if any
+ * @name       : lxc.network.name, name of iface on the container side
+ * @flags      : flag of the network device (IFF_UP, ... )
+ * @ipv4       : a list of ipv4 addresses to be set on the network device
+ * @ipv6       : a list of ipv6 addresses to be set on the network device
+ * @upscript   : a script filename to be executed during interface configuration
+ * @downscript : a script filename to be executed during interface destruction
  */
 struct lxc_netdev {
        int type;
@@ -111,6 +125,12 @@ struct lxc_netdev {
        union netdev_p priv;
        struct lxc_list ipv4;
        struct lxc_list ipv6;
+       struct in_addr *ipv4_gateway;
+       bool ipv4_gateway_auto;
+       struct in6_addr *ipv6_gateway;
+       bool ipv6_gateway_auto;
+       char *upscript;
+       char *downscript;
 };
 
 /*
@@ -124,6 +144,26 @@ struct lxc_cgroup {
        char *value;
 };
 
+enum idtype {
+       ID_TYPE_UID,
+       ID_TYPE_GID
+};
+
+/*
+ * id_map is an id map entry.  Form in confile is:
+ * lxc.id_map = u 0    9800 100
+ * lxc.id_map = u 1000 9900 100
+ * lxc.id_map = g 0    9800 100
+ * lxc.id_map = g 1000 9900 100
+ * meaning the container can use uids and gids 0-99 and 1000-1099,
+ * with [ug]id 0 mapping to [ug]id 9800 on the host, and [ug]id 1000 to
+ * [ug]id 9900 on the host.
+ */
+struct id_map {
+       enum idtype idtype;
+       unsigned long hostid, nsid, range;
+};
+
 /*
  * Defines a structure containing a pty information for
  * virtualizing a tty
@@ -148,55 +188,203 @@ struct lxc_tty_info {
        struct lxc_pty_info *pty_info;
 };
 
+struct lxc_tty_state;
+
+/*
+ * Defines the structure to store the console information
+ * @peer   : the file descriptor put/get console traffic
+ * @name   : the file name of the slave pty
+ */
+struct lxc_console {
+       int slave;
+       int master;
+       int peer;
+       struct lxc_pty_info peerpty;
+       struct lxc_epoll_descr *descr;
+       char *path;
+       char *log_path;
+       int log_fd;
+       char name[MAXPATHLEN];
+       struct termios *tios;
+       struct lxc_tty_state *tty_state;
+};
+
+/*
+ * Defines a structure to store the rootfs location, the
+ * optionals pivot_root, rootfs mount paths
+ * @rootfs     : a path to the rootfs
+ * @pivot_root : a path to a pivot_root location to be used
+ */
+struct lxc_rootfs {
+       char *path;
+       char *mount;
+       char *pivot;
+       char *options;
+};
+
+/*
+ * Automatic mounts for LXC to perform inside the container
+ */
+enum {
+       LXC_AUTO_PROC_RW              = 0x001,   /* /proc read-write */
+       LXC_AUTO_PROC_MIXED           = 0x002,   /* /proc/sys and /proc/sysrq-trigger read-only */
+       LXC_AUTO_PROC_MASK            = 0x003,
+
+       LXC_AUTO_SYS_RW               = 0x004,   /* /sys */
+       LXC_AUTO_SYS_RO               = 0x008,   /* /sys read-only */
+       LXC_AUTO_SYS_MASK             = 0x00C,
+
+       LXC_AUTO_CGROUP_RO            = 0x010,   /* /sys/fs/cgroup (partial mount, read-only) */
+       LXC_AUTO_CGROUP_RW            = 0x020,   /* /sys/fs/cgroup (partial mount, read-write) */
+       LXC_AUTO_CGROUP_MIXED         = 0x030,   /* /sys/fs/cgroup (partial mount, paths r/o, cgroup r/w) */
+       LXC_AUTO_CGROUP_FULL_RO       = 0x040,   /* /sys/fs/cgroup (full mount, read-only) */
+       LXC_AUTO_CGROUP_FULL_RW       = 0x050,   /* /sys/fs/cgroup (full mount, read-write) */
+       LXC_AUTO_CGROUP_FULL_MIXED    = 0x060,   /* /sys/fs/cgroup (full mount, parent r/o, own r/w) */
+       /* These are defined in such a way as to retain
+        * binary compatibility with earlier versions of
+        * this code. If the previous mask is applied,
+        * both of these will default back to the _MIXED
+        * variants, which is safe. */
+       LXC_AUTO_CGROUP_NOSPEC        = 0x0B0,   /* /sys/fs/cgroup (partial mount, r/w or mixed, depending on caps) */
+       LXC_AUTO_CGROUP_FULL_NOSPEC   = 0x0E0,   /* /sys/fs/cgroup (full mount, r/w or mixed, depending on caps) */
+       LXC_AUTO_CGROUP_MASK          = 0x0F0,
+
+       LXC_AUTO_ALL_MASK             = 0x0FF,   /* all known settings */
+};
+
 /*
  * Defines the global container configuration
- * @rootfs  : the root directory to run the container
- * @mount   : the list of mount points
- * @network : the network configuration
- * @utsname : the container utsname
+ * @rootfs     : root directory to run the container
+ * @pivotdir   : pivotdir path, if not set default will be used
+ * @mount      : list of mount points
+ * @tty        : numbers of tty
+ * @pts        : new pts instance
+ * @mount_list : list of mount point (alternative to fstab file)
+ * @network    : network configuration
+ * @utsname    : container utsname
+ * @fstab      : path to a fstab file format
+ * @caps       : list of the capabilities to drop
+ * @keepcaps   : list of the capabilities to keep
+ * @tty_info   : tty data
+ * @console    : console data
+ * @ttydir     : directory (under /dev) in which to create console and ttys
+ * @lsm_aa_profile : apparmor profile to switch to or NULL
+ * @lsm_se_context : selinux type to switch to or NULL
  */
+enum lxchooks {
+       LXCHOOK_PRESTART, LXCHOOK_PREMOUNT, LXCHOOK_MOUNT, LXCHOOK_AUTODEV,
+       LXCHOOK_START, LXCHOOK_POSTSTOP, LXCHOOK_CLONE, NUM_LXC_HOOKS};
+extern char *lxchook_names[NUM_LXC_HOOKS];
+
+struct saved_nic {
+       int ifindex;
+       char *orig_name;
+};
+
 struct lxc_conf {
-       char *rootfs;
-       char *pivotdir;
+       int is_execute;
        char *fstab;
        int tty;
        int pts;
+       int reboot;
+       int need_utmp_watch;
+       int personality;
        struct utsname *utsname;
        struct lxc_list cgroup;
+       struct lxc_list id_map;
        struct lxc_list network;
+       struct saved_nic *saved_nics;
+       int num_savednics;
+       int auto_mounts;
        struct lxc_list mount_list;
+       struct lxc_list caps;
+       struct lxc_list keepcaps;
        struct lxc_tty_info tty_info;
-       char console[MAXPATHLEN];
+       struct lxc_console console;
+       struct lxc_rootfs rootfs;
+       char *ttydir;
+       int close_all_fds;
+       struct lxc_list hooks[NUM_LXC_HOOKS];
+
+       char *lsm_aa_profile;
+       char *lsm_se_context;
+       int tmp_umount_proc;
+       char *seccomp;  // filename with the seccomp rules
+#if HAVE_SCMP_FILTER_CTX
+       scmp_filter_ctx *seccomp_ctx;
+#endif
+       int maincmd_fd;
+       int autodev;  // if 1, mount and fill a /dev at start
+       int haltsignal; // signal used to halt container
+       int stopsignal; // signal used to hard stop container
+       int kmsg;  // if 1, create /dev/kmsg symlink
+       char *rcfile;   // Copy of the top level rcfile we read
+
+       // Logfile and logleve can be set in a container config file.
+       // Those function as defaults.  The defaults can be overriden
+       // by command line.  However we don't want the command line
+       // specified values to be saved on c->save_config().  So we
+       // store the config file specified values here.
+       char *logfile;  // the logfile as specifed in config
+       int loglevel;   // loglevel as specifed in config (if any)
+
+       int inherit_ns_fd[LXC_NS_MAX];
+
+       int start_auto;
+       int start_delay;
+       int start_order;
+       struct lxc_list groups;
 };
 
+int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
+                 const char *lxcpath, char *argv[]);
+
+extern int detect_shared_rootfs(void);
+
 /*
  * Initialize the lxc configuration structure
  */
 extern struct lxc_conf *lxc_conf_init(void);
+extern void lxc_conf_free(struct lxc_conf *conf);
+
+extern int pin_rootfs(const char *rootfs);
 
-extern int lxc_create_network(struct lxc_list *networks);
+extern int lxc_requests_empty_network(struct lxc_handler *handler);
+extern int lxc_create_network(struct lxc_handler *handler);
+extern void lxc_delete_network(struct lxc_handler *handler);
 extern int lxc_assign_network(struct lxc_list *networks, pid_t pid);
+extern int lxc_map_ids(struct lxc_list *idmap, pid_t pid);
+extern int lxc_find_gateway_addresses(struct lxc_handler *handler);
 
 extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
 extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
 
+extern int lxc_clear_config_network(struct lxc_conf *c);
+extern int lxc_clear_nic(struct lxc_conf *c, const char *key);
+extern int lxc_clear_config_caps(struct lxc_conf *c);
+extern int lxc_clear_config_keepcaps(struct lxc_conf *c);
+extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key);
+extern int lxc_clear_mount_entries(struct lxc_conf *c);
+extern int lxc_clear_automounts(struct lxc_conf *c);
+extern int lxc_clear_hooks(struct lxc_conf *c, const char *key);
+extern int lxc_clear_idmaps(struct lxc_conf *c);
+extern int lxc_clear_groups(struct lxc_conf *c);
+
 /*
  * Configure the container from inside
  */
 
-struct lxc_handler;
-
-extern int lxc_setup(const char *name, struct lxc_conf *lxc_conf);
+struct cgroup_process_info;
+extern int lxc_setup(struct lxc_handler *handler);
 
-extern int conf_has(const char *name, const char *info);
+extern void lxc_rename_phys_nics_on_shutdown(int netnsfd, struct lxc_conf *conf);
 
-#define conf_has_fstab(__name)   conf_has(__name, "fstab")
-#define conf_has_rootfs(__name)  conf_has(__name, "rootfs")
-#define conf_has_pivotdir(__name) conf_has(__name, "pivotdir")
-#define conf_has_utsname(__name) conf_has(__name, "utsname")
-#define conf_has_network(__name) conf_has(__name, "network")
-#define conf_has_console(__name) conf_has(__name, "console")
-#define conf_has_cgroup(__name)  conf_has(__name, "cgroup")
-#define conf_has_tty(__name)     conf_has(__name, "tty")
-#define conf_has_pts(__name)     conf_has(__name, "pts")
+extern int find_unmapped_nsuid(struct lxc_conf *conf, enum idtype idtype);
+extern int mapped_hostid(unsigned id, struct lxc_conf *conf, enum idtype idtype);
+extern int chown_mapped_root(char *path, struct lxc_conf *conf);
+extern int ttys_shift_ids(struct lxc_conf *c);
+extern int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data);
+extern int parse_mntopts(const char *mntopts, unsigned long *mntflags,
+                        char **mntdata);
+extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
 #endif