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