]>
Commit | Line | Data |
---|---|---|
0ad19a3f | 1 | /* |
2 | * lxc: linux Container library | |
3 | * | |
4 | * (C) Copyright IBM Corp. 2007, 2008 | |
5 | * | |
6 | * Authors: | |
9afe19d6 | 7 | * Daniel Lezcano <daniel.lezcano at free.fr> |
0ad19a3f | 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 | |
250b1eec | 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0ad19a3f | 22 | */ |
f1a4a029 ÇO |
23 | #ifndef __LXC_NETWORK_H |
24 | #define __LXC_NETWORK_H | |
0ad19a3f | 25 | |
ebc73a67 | 26 | #include <arpa/inet.h> |
938980ba | 27 | #include <linux/types.h> |
d38dd64a CB |
28 | #include <stdbool.h> |
29 | #include <stdio.h> | |
ebc73a67 | 30 | #include <sys/socket.h> |
d38dd64a | 31 | #include <unistd.h> |
ebc73a67 | 32 | |
811ef482 CB |
33 | #include "list.h" |
34 | ||
35 | struct lxc_conf; | |
36 | struct lxc_handler; | |
37 | struct lxc_netdev; | |
38 | ||
39 | enum { | |
40 | LXC_NET_EMPTY, | |
41 | LXC_NET_VETH, | |
42 | LXC_NET_MACVLAN, | |
c9f52382 | 43 | LXC_NET_IPVLAN, |
811ef482 CB |
44 | LXC_NET_PHYS, |
45 | LXC_NET_VLAN, | |
46 | LXC_NET_NONE, | |
47 | LXC_NET_MAXCONFTYPE, | |
48 | }; | |
49 | ||
50 | /* | |
51 | * Defines the structure to configure an ipv4 address | |
52 | * @address : ipv4 address | |
53 | * @broadcast : ipv4 broadcast address | |
54 | * @mask : network mask | |
55 | */ | |
56 | struct lxc_inetdev { | |
57 | struct in_addr addr; | |
58 | struct in_addr bcast; | |
59 | unsigned int prefix; | |
60 | }; | |
61 | ||
62 | struct lxc_route { | |
63 | struct in_addr addr; | |
64 | }; | |
65 | ||
66 | /* | |
67 | * Defines the structure to configure an ipv6 address | |
68 | * @flags : set the address up | |
69 | * @address : ipv6 address | |
70 | * @broadcast : ipv6 broadcast address | |
71 | * @mask : network mask | |
72 | */ | |
73 | struct lxc_inet6dev { | |
74 | struct in6_addr addr; | |
75 | struct in6_addr mcast; | |
76 | struct in6_addr acast; | |
77 | unsigned int prefix; | |
78 | }; | |
79 | ||
80 | struct lxc_route6 { | |
81 | struct in6_addr addr; | |
82 | }; | |
83 | ||
4239e9c3 CB |
84 | /* Contains information about the host side veth device. |
85 | * @pair : Name of the host side veth device. | |
86 | * If the user requested that the host veth device be created with a | |
87 | * specific names this field will be set. If this field is set @veth1 | |
88 | * is not set. | |
89 | * @veth1 : Name of the host side veth device. | |
90 | * If the user did not request that the host veth device be created | |
91 | * with a specific name this field will be set. If this field is set | |
92 | * @pair is not set. | |
93 | * @ifindex : Ifindex of the network device. | |
94 | */ | |
811ef482 | 95 | struct ifla_veth { |
de4855a8 | 96 | char pair[IFNAMSIZ]; |
4239e9c3 CB |
97 | char veth1[IFNAMSIZ]; |
98 | int ifindex; | |
d4a7da46 | 99 | struct lxc_list ipv4_routes; |
100 | struct lxc_list ipv6_routes; | |
3f0ed090 | 101 | int mode; /* bridge, router */ |
811ef482 CB |
102 | }; |
103 | ||
104 | struct ifla_vlan { | |
105 | unsigned int flags; | |
106 | unsigned int fmask; | |
107 | unsigned short vid; | |
108 | unsigned short pad; | |
109 | }; | |
110 | ||
111 | struct ifla_macvlan { | |
112 | int mode; /* private, vepa, bridge, passthru */ | |
113 | }; | |
114 | ||
c9f52382 | 115 | struct ifla_ipvlan { |
116 | int mode; /* l3, l3s, l2 */ | |
117 | int isolation; /* bridge, private, vepa */ | |
118 | }; | |
119 | ||
790255cf CB |
120 | /* Contains information about the physical network device as seen from the host. |
121 | * @ifindex : The ifindex of the physical network device in the host's network | |
122 | * namespace. | |
123 | */ | |
124 | struct ifla_phys { | |
125 | int ifindex; | |
0b154989 | 126 | int mtu; |
790255cf CB |
127 | }; |
128 | ||
811ef482 | 129 | union netdev_p { |
790255cf | 130 | struct ifla_macvlan macvlan_attr; |
c9f52382 | 131 | struct ifla_ipvlan ipvlan_attr; |
790255cf | 132 | struct ifla_phys phys_attr; |
811ef482 CB |
133 | struct ifla_veth veth_attr; |
134 | struct ifla_vlan vlan_attr; | |
811ef482 CB |
135 | }; |
136 | ||
137 | /* | |
138 | * Defines a structure to configure a network device | |
085bb443 CB |
139 | * @idx : network counter |
140 | * @ifindex : ifindex of the network device | |
141 | * Note that this is the ifindex of the network device in | |
142 | * the container's network namespace. If the network device | |
143 | * consists of a pair of network devices (e.g. veth pairs | |
144 | * attached to a network bridge) then this index cannot be | |
145 | * used to identify or modify the host veth device. See | |
146 | * struct ifla_veth for the host side information. | |
147 | * @type : network type (veth, macvlan, vlan, ...) | |
148 | * @flags : flag of the network device (IFF_UP, ... ) | |
149 | * @link : lxc.net.[i].link, name of bridge or host iface to attach | |
150 | * if any | |
e389f2af CB |
151 | * @name : lxc.net.[i].name, name of iface on the container side |
152 | * @created_name : the name with which this interface got created before | |
153 | * being renamed to final_name. | |
154 | * Currenly only used for veth devices. | |
085bb443 CB |
155 | * @hwaddr : mac address |
156 | * @mtu : maximum transmission unit | |
157 | * @priv : information specific to the specificed network type | |
158 | * Note that this is a union so whether accessing a struct | |
159 | * is possible is dependent on the network type. | |
160 | * @ipv4 : a list of ipv4 addresses to be set on the network device | |
161 | * @ipv6 : a list of ipv6 addresses to be set on the network device | |
162 | * @ipv4_gateway_auto : whether the ipv4 gateway is to be automatically gathered | |
163 | * from the associated @link | |
a2f9a670 | 164 | * @ipv4_gateway_dev : whether the ipv4 gateway is to be set as a device route |
085bb443 CB |
165 | * @ipv4_gateway : ipv4 gateway |
166 | * @ipv6_gateway_auto : whether the ipv6 gateway is to be automatically gathered | |
167 | * from the associated @link | |
a2f9a670 | 168 | * @ipv6_gateway_dev : whether the ipv6 gateway is to be set as a device route |
085bb443 CB |
169 | * @ipv6_gateway : ipv6 gateway |
170 | * @upscript : a script filename to be executed during interface | |
171 | * configuration | |
172 | * @downscript : a script filename to be executed during interface | |
173 | * destruction | |
811ef482 CB |
174 | */ |
175 | struct lxc_netdev { | |
176 | ssize_t idx; | |
085bb443 | 177 | int ifindex; |
811ef482 CB |
178 | int type; |
179 | int flags; | |
de4855a8 | 180 | char link[IFNAMSIZ]; |
6509154d | 181 | bool l2proxy; |
de4855a8 | 182 | char name[IFNAMSIZ]; |
e389f2af | 183 | char created_name[IFNAMSIZ]; |
811ef482 CB |
184 | char *hwaddr; |
185 | char *mtu; | |
186 | union netdev_p priv; | |
187 | struct lxc_list ipv4; | |
188 | struct lxc_list ipv6; | |
811ef482 | 189 | bool ipv4_gateway_auto; |
a2f9a670 | 190 | bool ipv4_gateway_dev; |
085bb443 | 191 | struct in_addr *ipv4_gateway; |
811ef482 | 192 | bool ipv6_gateway_auto; |
a2f9a670 | 193 | bool ipv6_gateway_dev; |
085bb443 | 194 | struct in6_addr *ipv6_gateway; |
811ef482 CB |
195 | char *upscript; |
196 | char *downscript; | |
197 | }; | |
198 | ||
ebc73a67 | 199 | /* Convert a string mac address to a socket structure. */ |
0ad19a3f | 200 | extern int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr); |
201 | ||
ebc73a67 | 202 | /* Move a device between namespaces. */ |
535e8859 | 203 | extern int lxc_netdev_move_by_index(int ifindex, pid_t pid, const char *ifname); |
ebc73a67 CB |
204 | extern int lxc_netdev_move_by_name(const char *ifname, pid_t pid, |
205 | const char *newname); | |
0ad19a3f | 206 | |
ebc73a67 | 207 | /* Delete a network device. */ |
b84f58b9 DL |
208 | extern int lxc_netdev_delete_by_name(const char *name); |
209 | extern int lxc_netdev_delete_by_index(int ifindex); | |
0ad19a3f | 210 | |
ebc73a67 | 211 | /* Change the device name. */ |
b84f58b9 DL |
212 | extern int lxc_netdev_rename_by_name(const char *oldname, const char *newname); |
213 | extern int lxc_netdev_rename_by_index(int ifindex, const char *newname); | |
b9a5bb58 | 214 | |
8befa924 SH |
215 | extern int netdev_set_flag(const char *name, int flag); |
216 | ||
ebc73a67 | 217 | /* Set the device network up or down. */ |
efa1cf45 | 218 | extern int lxc_netdev_isup(const char *name); |
d472214b DL |
219 | extern int lxc_netdev_up(const char *name); |
220 | extern int lxc_netdev_down(const char *name); | |
0ad19a3f | 221 | |
ebc73a67 | 222 | /* Change the mtu size for the specified device. */ |
d472214b | 223 | extern int lxc_netdev_set_mtu(const char *name, int mtu); |
75d09f83 | 224 | |
ebc73a67 | 225 | /* Create a virtual network devices. */ |
497353b6 | 226 | extern int lxc_veth_create(const char *name1, const char *name2); |
e892973e | 227 | extern int lxc_macvlan_create(const char *master, const char *name, int mode); |
ebc73a67 CB |
228 | extern int lxc_vlan_create(const char *master, const char *name, |
229 | unsigned short vid); | |
26c39028 | 230 | |
ebc73a67 | 231 | /* Set ip address. */ |
1f1b18e7 DL |
232 | extern int lxc_ipv6_addr_add(int ifindex, struct in6_addr *addr, |
233 | struct in6_addr *mcast, | |
234 | struct in6_addr *acast, int prefix); | |
235 | ||
236 | extern int lxc_ipv4_addr_add(int ifindex, struct in_addr *addr, | |
237 | struct in_addr *bcast, int prefix); | |
0ad19a3f | 238 | |
ebc73a67 | 239 | /* Get ip address. */ |
19a26f82 MK |
240 | extern int lxc_ipv4_addr_get(int ifindex, struct in_addr **res); |
241 | extern int lxc_ipv6_addr_get(int ifindex, struct in6_addr **res); | |
242 | ||
ebc73a67 | 243 | /* Set default route. */ |
f8fee0e2 MK |
244 | extern int lxc_ipv4_gateway_add(int ifindex, struct in_addr *gw); |
245 | extern int lxc_ipv6_gateway_add(int ifindex, struct in6_addr *gw); | |
246 | ||
ebc73a67 | 247 | /* Attach an interface to the bridge. */ |
581c75e7 CB |
248 | extern int lxc_bridge_attach(const char *bridge, const char *ifname); |
249 | extern int lxc_ovs_delete_port(const char *bridge, const char *nic); | |
250 | ||
251 | extern bool is_ovs_bridge(const char *bridge); | |
0ad19a3f | 252 | |
ebc73a67 | 253 | /* Create default gateway. */ |
497353b6 DL |
254 | extern int lxc_route_create_default(const char *addr, const char *ifname, |
255 | int gateway); | |
0ad19a3f | 256 | |
ebc73a67 | 257 | /* Delete default gateway. */ |
497353b6 DL |
258 | extern int lxc_route_delete_default(const char *addr, const char *ifname, |
259 | int gateway); | |
0ad19a3f | 260 | |
ebc73a67 | 261 | /* Activate neighbor proxying. */ |
497353b6 | 262 | extern int lxc_neigh_proxy_on(const char *name, int family); |
0ad19a3f | 263 | |
ebc73a67 | 264 | /* Disable neighbor proxying. */ |
497353b6 | 265 | extern int lxc_neigh_proxy_off(const char *name, int family); |
0ad19a3f | 266 | |
6dfa9581 TP |
267 | /* Activate IP forwarding. */ |
268 | extern int lxc_ip_forwarding_on(const char *name, int family); | |
269 | ||
270 | /* Disable IP forwarding. */ | |
271 | extern int lxc_ip_forwarding_off(const char *name, int family); | |
272 | ||
811ef482 CB |
273 | /* Generate a new unique network interface name. |
274 | * Allocated memory must be freed by caller. | |
275 | */ | |
966e9f1f | 276 | extern char *lxc_mkifname(char *template); |
a0265685 | 277 | |
72d0e1cb | 278 | extern const char *lxc_net_type_to_str(int type); |
8befa924 | 279 | extern int setup_private_host_hw_addr(char *veth1); |
0130df54 | 280 | extern int netdev_get_mtu(int ifindex); |
e389f2af | 281 | extern int lxc_network_move_created_netdev_priv(struct lxc_handler *handler); |
bb84beda | 282 | extern void lxc_delete_network(struct lxc_handler *handler); |
811ef482 | 283 | extern int lxc_find_gateway_addresses(struct lxc_handler *handler); |
811ef482 | 284 | extern int lxc_requests_empty_network(struct lxc_handler *handler); |
b809f232 | 285 | extern int lxc_restore_phys_nics_to_netns(struct lxc_handler *handler); |
811ef482 CB |
286 | extern int lxc_setup_network_in_child_namespaces(const struct lxc_conf *conf, |
287 | struct lxc_list *network); | |
3c09b97c CB |
288 | extern int lxc_network_send_to_child(struct lxc_handler *handler); |
289 | extern int lxc_network_recv_from_parent(struct lxc_handler *handler); | |
a1ae535a CB |
290 | extern int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler *handler); |
291 | extern int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler); | |
1cd95214 | 292 | extern int lxc_netns_set_nsid(int netns_fd); |
938980ba | 293 | extern int lxc_netns_get_nsid(__s32 fd); |
e389f2af | 294 | extern int lxc_create_network(struct lxc_handler *handler); |
ebc73a67 CB |
295 | |
296 | #endif /* __LXC_NETWORK_H */ |