]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/conf.h
fix network devices cleanup on error
[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 <sys/param.h>
28
29 #include <lxc/list.h>
30
31 enum {
32 LXC_NET_EMPTY,
33 LXC_NET_VETH,
34 LXC_NET_MACVLAN,
35 LXC_NET_PHYS,
36 LXC_NET_VLAN,
37 LXC_NET_MAXCONFTYPE,
38 };
39
40 /*
41 * Defines the structure to configure an ipv4 address
42 * @address : ipv4 address
43 * @broadcast : ipv4 broadcast address
44 * @mask : network mask
45 */
46 struct lxc_inetdev {
47 struct in_addr addr;
48 struct in_addr bcast;
49 int prefix;
50 };
51
52 struct lxc_route {
53 struct in_addr addr;
54 };
55
56 /*
57 * Defines the structure to configure an ipv6 address
58 * @flags : set the address up
59 * @address : ipv6 address
60 * @broadcast : ipv6 broadcast address
61 * @mask : network mask
62 */
63 struct lxc_inet6dev {
64 struct in6_addr addr;
65 struct in6_addr bcast;
66 struct in6_addr acast;
67 int prefix;
68 };
69
70 struct lxc_route6 {
71 struct in6_addr addr;
72 };
73
74 struct ifla_veth {
75 char *pair; /* pair name */
76 };
77
78 struct ifla_vlan {
79 uint flags;
80 uint fmask;
81 ushort vid;
82 ushort pad;
83 };
84
85 struct ifla_macvlan {
86 int mode; /* private, vepa, bridge */
87 };
88
89 union netdev_p {
90 struct ifla_veth veth_attr;
91 struct ifla_vlan vlan_attr;
92 struct ifla_macvlan macvlan_attr;
93 };
94
95 /*
96 * Defines a structure to configure a network device
97 * @link : lxc.network.link, name of bridge or host iface to attach if any
98 * @name : lxc.network.name, name of iface on the container side
99 * @flags : flag of the network device (IFF_UP, ... )
100 * @ipv4 : a list of ipv4 addresses to be set on the network device
101 * @ipv6 : a list of ipv6 addresses to be set on the network device
102 */
103 struct lxc_netdev {
104 int type;
105 int flags;
106 int ifindex;
107 char *link;
108 char *name;
109 char *hwaddr;
110 char *mtu;
111 union netdev_p priv;
112 struct lxc_list ipv4;
113 struct lxc_list ipv6;
114 };
115
116 /*
117 * Defines a generic struct to configure the control group.
118 * It is up to the programmer to specify the right subsystem.
119 * @subsystem : the targetted subsystem
120 * @value : the value to set
121 */
122 struct lxc_cgroup {
123 char *subsystem;
124 char *value;
125 };
126
127 /*
128 * Defines a structure containing a pty information for
129 * virtualizing a tty
130 * @name : the path name of the slave pty side
131 * @master : the file descriptor of the master
132 * @slave : the file descriptor of the slave
133 */
134 struct lxc_pty_info {
135 char name[MAXPATHLEN];
136 int master;
137 int slave;
138 int busy;
139 };
140
141 /*
142 * Defines the number of tty configured and contains the
143 * instanciated ptys
144 * @nbtty = number of configured ttys
145 */
146 struct lxc_tty_info {
147 int nbtty;
148 struct lxc_pty_info *pty_info;
149 };
150
151 /*
152 * Defines the structure to store the console information
153 * @peer : the file descriptor put/get console traffic
154 * @name : the file name of the slave pty
155 */
156 struct lxc_console {
157 int slave;
158 int master;
159 int peer;
160 char name[MAXPATHLEN];
161 struct termios *tios;
162 };
163
164 /*
165 * Defines the global container configuration
166 * @rootfs : root directory to run the container
167 * @pivotdir : pivotdir path, if not set default will be used
168 * @mount : list of mount points
169 * @tty : numbers of tty
170 * @pts : new pts instance
171 * @mount_list : list of mount point (alternative to fstab file)
172 * @network : network configuration
173 * @utsname : container utsname
174 * @fstab : path to a fstab file format
175 * @caps : list of the capabilities
176 * @tty_info : tty data
177 * @console : console data
178 */
179 struct lxc_conf {
180 char *rootfs;
181 char *pivotdir;
182 char *fstab;
183 int tty;
184 int pts;
185 struct utsname *utsname;
186 struct lxc_list cgroup;
187 struct lxc_list network;
188 struct lxc_list mount_list;
189 struct lxc_list caps;
190 struct lxc_tty_info tty_info;
191 struct lxc_console console;
192 };
193
194 /*
195 * Initialize the lxc configuration structure
196 */
197 extern struct lxc_conf *lxc_conf_init(void);
198
199 extern int lxc_create_network(struct lxc_list *networks);
200 extern void lxc_delete_network(struct lxc_list *networks);
201 extern int lxc_assign_network(struct lxc_list *networks, pid_t pid);
202
203 extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
204 extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
205
206 /*
207 * Configure the container from inside
208 */
209
210 struct lxc_handler;
211
212 extern int lxc_setup(const char *name, struct lxc_conf *lxc_conf);
213
214 #endif