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 */
35 #if HAVE_SCMP_FILTER_CTX
36 typedef void * scmp_filter_ctx
;
49 * Defines the structure to configure an ipv4 address
50 * @address : ipv4 address
51 * @broadcast : ipv4 broadcast address
52 * @mask : network mask
65 * Defines the structure to configure an ipv6 address
66 * @flags : set the address up
67 * @address : ipv6 address
68 * @broadcast : ipv6 broadcast address
69 * @mask : network mask
73 struct in6_addr mcast
;
74 struct in6_addr acast
;
83 char *pair
; /* pair name */
84 char veth1
[IFNAMSIZ
]; /* needed for deconf */
95 int mode
; /* private, vepa, bridge */
99 struct ifla_veth veth_attr
;
100 struct ifla_vlan vlan_attr
;
101 struct ifla_macvlan macvlan_attr
;
105 * Defines a structure to configure a network device
106 * @link : lxc.network.link, name of bridge or host iface to attach if any
107 * @name : lxc.network.name, name of iface on the container side
108 * @flags : flag of the network device (IFF_UP, ... )
109 * @ipv4 : a list of ipv4 addresses to be set on the network device
110 * @ipv6 : a list of ipv6 addresses to be set on the network device
111 * @upscript : a script filename to be executed during interface configuration
112 * @downscript : a script filename to be executed during interface destruction
123 struct lxc_list ipv4
;
124 struct lxc_list ipv6
;
125 struct in_addr
*ipv4_gateway
;
126 bool ipv4_gateway_auto
;
127 struct in6_addr
*ipv6_gateway
;
128 bool ipv6_gateway_auto
;
134 * Defines a generic struct to configure the control group.
135 * It is up to the programmer to specify the right subsystem.
136 * @subsystem : the targetted subsystem
137 * @value : the value to set
145 * Defines a structure containing a pty information for
147 * @name : the path name of the slave pty side
148 * @master : the file descriptor of the master
149 * @slave : the file descriptor of the slave
151 struct lxc_pty_info
{
152 char name
[MAXPATHLEN
];
159 * Defines the number of tty configured and contains the
161 * @nbtty = number of configured ttys
163 struct lxc_tty_info
{
165 struct lxc_pty_info
*pty_info
;
169 * Defines the structure to store the console information
170 * @peer : the file descriptor put/get console traffic
171 * @name : the file name of the slave pty
178 char name
[MAXPATHLEN
];
179 struct termios
*tios
;
183 * Defines a structure to store the rootfs location, the
184 * optionals pivot_root, rootfs mount paths
185 * @rootfs : a path to the rootfs
186 * @pivot_root : a path to a pivot_root location to be used
195 * Defines the global container configuration
196 * @rootfs : root directory to run the container
197 * @pivotdir : pivotdir path, if not set default will be used
198 * @mount : list of mount points
199 * @tty : numbers of tty
200 * @pts : new pts instance
201 * @mount_list : list of mount point (alternative to fstab file)
202 * @network : network configuration
203 * @utsname : container utsname
204 * @fstab : path to a fstab file format
205 * @caps : list of the capabilities
206 * @tty_info : tty data
207 * @console : console data
208 * @ttydir : directory (under /dev) in which to create console and ttys
210 * @aa_profile : apparmor profile to switch to
214 LXCHOOK_PRESTART
, LXCHOOK_PREMOUNT
, LXCHOOK_MOUNT
, LXCHOOK_START
,
215 LXCHOOK_POSTSTOP
, NUM_LXC_HOOKS
};
216 extern char *lxchook_names
[NUM_LXC_HOOKS
];
230 struct utsname
*utsname
;
231 struct lxc_list cgroup
;
232 struct lxc_list network
;
233 struct saved_nic
*saved_nics
;
235 struct lxc_list mount_list
;
236 struct lxc_list caps
;
237 struct lxc_tty_info tty_info
;
238 struct lxc_console console
;
239 struct lxc_rootfs rootfs
;
242 struct lxc_list hooks
[NUM_LXC_HOOKS
];
249 #if HAVE_APPARMOR /* || HAVE_SELINUX || HAVE_SMACK */
252 char *seccomp
; // filename with the seccomp rules
253 #if HAVE_SCMP_FILTER_CTX
254 scmp_filter_ctx
*seccomp_ctx
;
257 int autodev
; // if 1, mount and fill a /dev at start
260 int run_lxc_hooks(const char *name
, char *hook
, struct lxc_conf
*conf
);
262 extern int setup_cgroup(const char *name
, struct lxc_list
*cgroups
);
263 extern int detect_shared_rootfs(void);
266 * Initialize the lxc configuration structure
268 extern struct lxc_conf
*lxc_conf_init(void);
269 extern void lxc_conf_free(struct lxc_conf
*conf
);
271 extern int pin_rootfs(const char *rootfs
);
273 extern int lxc_create_network(struct lxc_handler
*handler
);
274 extern void lxc_delete_network(struct lxc_handler
*handler
);
275 extern int lxc_assign_network(struct lxc_list
*networks
, pid_t pid
);
276 extern int lxc_find_gateway_addresses(struct lxc_handler
*handler
);
278 extern int lxc_create_tty(const char *name
, struct lxc_conf
*conf
);
279 extern void lxc_delete_tty(struct lxc_tty_info
*tty_info
);
281 extern int lxc_clear_config_network(struct lxc_conf
*c
);
282 extern int lxc_clear_nic(struct lxc_conf
*c
, const char *key
);
283 extern int lxc_clear_config_caps(struct lxc_conf
*c
);
284 extern int lxc_clear_cgroups(struct lxc_conf
*c
, const char *key
);
285 extern int lxc_clear_mount_entries(struct lxc_conf
*c
);
286 extern int lxc_clear_hooks(struct lxc_conf
*c
, const char *key
);
289 * Configure the container from inside
292 extern int lxc_setup(const char *name
, struct lxc_conf
*lxc_conf
);
294 extern void lxc_rename_phys_nics_on_shutdown(struct lxc_conf
*conf
);