]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/conf.h
lxc_conf logfile and loglevel support
[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 <dlezcano at fr.ibm.com>
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 <netinet/in.h>
27 #include <net/if.h>
28 #include <sys/param.h>
29 #include <stdbool.h>
30
31 #include <lxc/list.h>
32
33 #include <lxc/start.h> /* for lxc_handler */
34
35 enum {
36 LXC_NET_EMPTY,
37 LXC_NET_VETH,
38 LXC_NET_MACVLAN,
39 LXC_NET_PHYS,
40 LXC_NET_VLAN,
41 LXC_NET_MAXCONFTYPE,
42 };
43
44 /*
45 * Defines the structure to configure an ipv4 address
46 * @address : ipv4 address
47 * @broadcast : ipv4 broadcast address
48 * @mask : network mask
49 */
50 struct lxc_inetdev {
51 struct in_addr addr;
52 struct in_addr bcast;
53 int prefix;
54 };
55
56 struct lxc_route {
57 struct in_addr addr;
58 };
59
60 /*
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
66 */
67 struct lxc_inet6dev {
68 struct in6_addr addr;
69 struct in6_addr mcast;
70 struct in6_addr acast;
71 int prefix;
72 };
73
74 struct lxc_route6 {
75 struct in6_addr addr;
76 };
77
78 struct ifla_veth {
79 char *pair; /* pair name */
80 char veth1[IFNAMSIZ]; /* needed for deconf */
81 };
82
83 struct ifla_vlan {
84 uint flags;
85 uint fmask;
86 ushort vid;
87 ushort pad;
88 };
89
90 struct ifla_macvlan {
91 int mode; /* private, vepa, bridge */
92 };
93
94 union netdev_p {
95 struct ifla_veth veth_attr;
96 struct ifla_vlan vlan_attr;
97 struct ifla_macvlan macvlan_attr;
98 };
99
100 /*
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
109 */
110 struct lxc_netdev {
111 int type;
112 int flags;
113 int ifindex;
114 char *link;
115 char *name;
116 char *hwaddr;
117 char *mtu;
118 union netdev_p priv;
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;
125 char *upscript;
126 char *downscript;
127 };
128
129 /*
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
134 */
135 struct lxc_cgroup {
136 char *subsystem;
137 char *value;
138 };
139
140 /*
141 * Defines a structure containing a pty information for
142 * virtualizing a tty
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
146 */
147 struct lxc_pty_info {
148 char name[MAXPATHLEN];
149 int master;
150 int slave;
151 int busy;
152 };
153
154 /*
155 * Defines the number of tty configured and contains the
156 * instanciated ptys
157 * @nbtty = number of configured ttys
158 */
159 struct lxc_tty_info {
160 int nbtty;
161 struct lxc_pty_info *pty_info;
162 };
163
164 /*
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
168 */
169 struct lxc_console {
170 int slave;
171 int master;
172 int peer;
173 char *path;
174 char name[MAXPATHLEN];
175 struct termios *tios;
176 };
177
178 /*
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
183 */
184 struct lxc_rootfs {
185 char *path;
186 char *mount;
187 char *pivot;
188 };
189
190 /*
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
205 #if HAVE_APPARMOR
206 * @aa_profile : apparmor profile to switch to
207 #endif
208 */
209 enum lxchooks {
210 LXCHOOK_PRESTART, LXCHOOK_PREMOUNT, LXCHOOK_MOUNT, LXCHOOK_START,
211 LXCHOOK_POSTSTOP, NUM_LXC_HOOKS};
212 extern char *lxchook_names[NUM_LXC_HOOKS];
213
214 struct lxc_conf {
215 char *fstab;
216 int tty;
217 int pts;
218 int reboot;
219 int need_utmp_watch;
220 int personality;
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;
229 char *ttydir;
230 int close_all_fds;
231 struct lxc_list hooks[NUM_LXC_HOOKS];
232 #if HAVE_APPARMOR
233 char *aa_profile;
234 #endif
235 char *logfile;
236 int loglevel;
237
238 #if HAVE_APPARMOR /* || HAVE_SELINUX || HAVE_SMACK */
239 int lsm_umount_proc;
240 #endif
241 char *seccomp; // filename with the seccomp rules
242 int maincmd_fd;
243 int autodev; // if 1, mount and fill a /dev at start
244 };
245
246 int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf);
247
248 /*
249 * Initialize the lxc configuration structure
250 */
251 extern struct lxc_conf *lxc_conf_init(void);
252 extern void lxc_conf_free(struct lxc_conf *conf);
253
254 extern int pin_rootfs(const char *rootfs);
255
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);
260
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);
263
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);
270
271 /*
272 * Configure the container from inside
273 */
274
275 extern int lxc_setup(const char *name, struct lxc_conf *lxc_conf);
276 #endif