2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <netinet/in.h>
28 #include <sys/param.h>
33 #include <lxc/start.h> /* for lxc_handler */
45 * Defines the structure to configure an ipv4 address
46 * @address : ipv4 address
47 * @broadcast : ipv4 broadcast address
48 * @mask : network mask
61 * Defines the structure to configure an ipv6 address
62 * @flags : set the address up
63 * @address : ipv6 address
64 * @broadcast : ipv6 broadcast address
65 * @mask : network mask
69 struct in6_addr mcast
;
70 struct in6_addr acast
;
79 char *pair
; /* pair name */
80 char veth1
[IFNAMSIZ
]; /* needed for deconf */
91 int mode
; /* private, vepa, bridge */
95 struct ifla_veth veth_attr
;
96 struct ifla_vlan vlan_attr
;
97 struct ifla_macvlan macvlan_attr
;
101 * Defines a structure to configure a network device
102 * @link : lxc.network.link, name of bridge or host iface to attach if any
103 * @name : lxc.network.name, name of iface on the container side
104 * @flags : flag of the network device (IFF_UP, ... )
105 * @ipv4 : a list of ipv4 addresses to be set on the network device
106 * @ipv6 : a list of ipv6 addresses to be set on the network device
107 * @upscript : a script filename to be executed during interface configuration
108 * @downscript : a script filename to be executed during interface destruction
119 struct lxc_list ipv4
;
120 struct lxc_list ipv6
;
121 struct in_addr
*ipv4_gateway
;
122 bool ipv4_gateway_auto
;
123 struct in6_addr
*ipv6_gateway
;
124 bool ipv6_gateway_auto
;
130 * Defines a generic struct to configure the control group.
131 * It is up to the programmer to specify the right subsystem.
132 * @subsystem : the targetted subsystem
133 * @value : the value to set
141 * Defines a structure containing a pty information for
143 * @name : the path name of the slave pty side
144 * @master : the file descriptor of the master
145 * @slave : the file descriptor of the slave
147 struct lxc_pty_info
{
148 char name
[MAXPATHLEN
];
155 * Defines the number of tty configured and contains the
157 * @nbtty = number of configured ttys
159 struct lxc_tty_info
{
161 struct lxc_pty_info
*pty_info
;
165 * Defines the structure to store the console information
166 * @peer : the file descriptor put/get console traffic
167 * @name : the file name of the slave pty
174 char name
[MAXPATHLEN
];
175 struct termios
*tios
;
179 * Defines a structure to store the rootfs location, the
180 * optionals pivot_root, rootfs mount paths
181 * @rootfs : a path to the rootfs
182 * @pivot_root : a path to a pivot_root location to be used
191 * Defines the global container configuration
192 * @rootfs : root directory to run the container
193 * @pivotdir : pivotdir path, if not set default will be used
194 * @mount : list of mount points
195 * @tty : numbers of tty
196 * @pts : new pts instance
197 * @mount_list : list of mount point (alternative to fstab file)
198 * @network : network configuration
199 * @utsname : container utsname
200 * @fstab : path to a fstab file format
201 * @caps : list of the capabilities
202 * @tty_info : tty data
203 * @console : console data
204 * @ttydir : directory (under /dev) in which to create console and ttys
206 * @aa_profile : apparmor profile to switch to
210 LXCHOOK_PRESTART
, LXCHOOK_PREMOUNT
, LXCHOOK_MOUNT
, LXCHOOK_START
,
211 LXCHOOK_POSTSTOP
, NUM_LXC_HOOKS
};
212 extern char *lxchook_names
[NUM_LXC_HOOKS
];
221 struct utsname
*utsname
;
222 struct lxc_list cgroup
;
223 struct lxc_list network
;
224 struct lxc_list mount_list
;
225 struct lxc_list caps
;
226 struct lxc_tty_info tty_info
;
227 struct lxc_console console
;
228 struct lxc_rootfs rootfs
;
231 struct lxc_list hooks
[NUM_LXC_HOOKS
];
238 #if HAVE_APPARMOR /* || HAVE_SELINUX || HAVE_SMACK */
241 char *seccomp
; // filename with the seccomp rules
243 int autodev
; // if 1, mount and fill a /dev at start
246 int run_lxc_hooks(const char *name
, char *hook
, struct lxc_conf
*conf
);
249 * Initialize the lxc configuration structure
251 extern struct lxc_conf
*lxc_conf_init(void);
252 extern void lxc_conf_free(struct lxc_conf
*conf
);
254 extern int pin_rootfs(const char *rootfs
);
256 extern int lxc_create_network(struct lxc_handler
*handler
);
257 extern void lxc_delete_network(struct lxc_handler
*handler
);
258 extern int lxc_assign_network(struct lxc_list
*networks
, pid_t pid
);
259 extern int lxc_find_gateway_addresses(struct lxc_handler
*handler
);
261 extern int lxc_create_tty(const char *name
, struct lxc_conf
*conf
);
262 extern void lxc_delete_tty(struct lxc_tty_info
*tty_info
);
264 extern int lxc_clear_config_network(struct lxc_conf
*c
);
265 extern int lxc_clear_nic(struct lxc_conf
*c
, const char *key
);
266 extern int lxc_clear_config_caps(struct lxc_conf
*c
);
267 extern int lxc_clear_cgroups(struct lxc_conf
*c
, const char *key
);
268 extern int lxc_clear_mount_entries(struct lxc_conf
*c
);
269 extern int lxc_clear_hooks(struct lxc_conf
*c
, const char *key
);
272 * Configure the container from inside
275 extern int lxc_setup(const char *name
, struct lxc_conf
*lxc_conf
);