]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/network.h
network: remove allocation from lxc_mkifname()
[mirror_lxc.git] / src / lxc / network.h
CommitLineData
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
811ef482 26#include <stdbool.h>
ebc73a67
CB
27#include <stdio.h>
28#include <unistd.h>
29#include <arpa/inet.h>
30#include <sys/socket.h>
31
811ef482
CB
32#include "list.h"
33
34struct lxc_conf;
35struct lxc_handler;
36struct lxc_netdev;
37
38enum {
39 LXC_NET_EMPTY,
40 LXC_NET_VETH,
41 LXC_NET_MACVLAN,
42 LXC_NET_PHYS,
43 LXC_NET_VLAN,
44 LXC_NET_NONE,
45 LXC_NET_MAXCONFTYPE,
46};
47
48/*
49 * Defines the structure to configure an ipv4 address
50 * @address : ipv4 address
51 * @broadcast : ipv4 broadcast address
52 * @mask : network mask
53 */
54struct lxc_inetdev {
55 struct in_addr addr;
56 struct in_addr bcast;
57 unsigned int prefix;
58};
59
60struct lxc_route {
61 struct in_addr addr;
62};
63
64/*
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
70 */
71struct lxc_inet6dev {
72 struct in6_addr addr;
73 struct in6_addr mcast;
74 struct in6_addr acast;
75 unsigned int prefix;
76};
77
78struct lxc_route6 {
79 struct in6_addr addr;
80};
81
4239e9c3
CB
82/* Contains information about the host side veth device.
83 * @pair : Name of the host side veth device.
84 * If the user requested that the host veth device be created with a
85 * specific names this field will be set. If this field is set @veth1
86 * is not set.
87 * @veth1 : Name of the host side veth device.
88 * If the user did not request that the host veth device be created
89 * with a specific name this field will be set. If this field is set
90 * @pair is not set.
91 * @ifindex : Ifindex of the network device.
92 */
811ef482 93struct ifla_veth {
de4855a8 94 char pair[IFNAMSIZ];
4239e9c3
CB
95 char veth1[IFNAMSIZ];
96 int ifindex;
811ef482
CB
97};
98
99struct ifla_vlan {
100 unsigned int flags;
101 unsigned int fmask;
102 unsigned short vid;
103 unsigned short pad;
104};
105
106struct ifla_macvlan {
107 int mode; /* private, vepa, bridge, passthru */
108};
109
790255cf
CB
110/* Contains information about the physical network device as seen from the host.
111 * @ifindex : The ifindex of the physical network device in the host's network
112 * namespace.
113 */
114struct ifla_phys {
115 int ifindex;
116};
117
811ef482 118union netdev_p {
790255cf
CB
119 struct ifla_macvlan macvlan_attr;
120 struct ifla_phys phys_attr;
811ef482
CB
121 struct ifla_veth veth_attr;
122 struct ifla_vlan vlan_attr;
811ef482
CB
123};
124
125/*
126 * Defines a structure to configure a network device
085bb443
CB
127 * @idx : network counter
128 * @ifindex : ifindex of the network device
129 * Note that this is the ifindex of the network device in
130 * the container's network namespace. If the network device
131 * consists of a pair of network devices (e.g. veth pairs
132 * attached to a network bridge) then this index cannot be
133 * used to identify or modify the host veth device. See
134 * struct ifla_veth for the host side information.
135 * @type : network type (veth, macvlan, vlan, ...)
136 * @flags : flag of the network device (IFF_UP, ... )
137 * @link : lxc.net.[i].link, name of bridge or host iface to attach
138 * if any
139 * @name : lxc.net.[i].name, name of iface on the container side
140 * @hwaddr : mac address
141 * @mtu : maximum transmission unit
142 * @priv : information specific to the specificed network type
143 * Note that this is a union so whether accessing a struct
144 * is possible is dependent on the network type.
145 * @ipv4 : a list of ipv4 addresses to be set on the network device
146 * @ipv6 : a list of ipv6 addresses to be set on the network device
147 * @ipv4_gateway_auto : whether the ipv4 gateway is to be automatically gathered
148 * from the associated @link
149 * @ipv4_gateway : ipv4 gateway
150 * @ipv6_gateway_auto : whether the ipv6 gateway is to be automatically gathered
151 * from the associated @link
152 * @ipv6_gateway : ipv6 gateway
153 * @upscript : a script filename to be executed during interface
154 * configuration
155 * @downscript : a script filename to be executed during interface
156 * destruction
811ef482
CB
157 */
158struct lxc_netdev {
159 ssize_t idx;
085bb443 160 int ifindex;
811ef482
CB
161 int type;
162 int flags;
de4855a8
CB
163 char link[IFNAMSIZ];
164 char name[IFNAMSIZ];
811ef482
CB
165 char *hwaddr;
166 char *mtu;
167 union netdev_p priv;
168 struct lxc_list ipv4;
169 struct lxc_list ipv6;
811ef482 170 bool ipv4_gateway_auto;
085bb443 171 struct in_addr *ipv4_gateway;
811ef482 172 bool ipv6_gateway_auto;
085bb443 173 struct in6_addr *ipv6_gateway;
811ef482
CB
174 char *upscript;
175 char *downscript;
176};
177
ebc73a67 178/* Convert a string mac address to a socket structure. */
0ad19a3f 179extern int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr);
180
ebc73a67 181/* Move a device between namespaces. */
535e8859 182extern int lxc_netdev_move_by_index(int ifindex, pid_t pid, const char *ifname);
ebc73a67
CB
183extern int lxc_netdev_move_by_name(const char *ifname, pid_t pid,
184 const char *newname);
0ad19a3f 185
ebc73a67 186/* Delete a network device. */
b84f58b9
DL
187extern int lxc_netdev_delete_by_name(const char *name);
188extern int lxc_netdev_delete_by_index(int ifindex);
0ad19a3f 189
ebc73a67 190/* Change the device name. */
b84f58b9
DL
191extern int lxc_netdev_rename_by_name(const char *oldname, const char *newname);
192extern int lxc_netdev_rename_by_index(int ifindex, const char *newname);
b9a5bb58 193
8befa924
SH
194extern int netdev_set_flag(const char *name, int flag);
195
ebc73a67 196/* Set the device network up or down. */
efa1cf45 197extern int lxc_netdev_isup(const char *name);
d472214b
DL
198extern int lxc_netdev_up(const char *name);
199extern int lxc_netdev_down(const char *name);
0ad19a3f 200
ebc73a67 201/* Change the mtu size for the specified device. */
d472214b 202extern int lxc_netdev_set_mtu(const char *name, int mtu);
75d09f83 203
ebc73a67 204/* Create a virtual network devices. */
497353b6 205extern int lxc_veth_create(const char *name1, const char *name2);
e892973e 206extern int lxc_macvlan_create(const char *master, const char *name, int mode);
ebc73a67
CB
207extern int lxc_vlan_create(const char *master, const char *name,
208 unsigned short vid);
26c39028 209
ebc73a67 210/* Activate forwarding.*/
497353b6 211extern int lxc_ip_forward_on(const char *name, int family);
0ad19a3f 212
ebc73a67 213/* Disable forwarding. */
497353b6 214extern int lxc_ip_forward_off(const char *name, int family);
0ad19a3f 215
ebc73a67 216/* Set ip address. */
1f1b18e7
DL
217extern int lxc_ipv6_addr_add(int ifindex, struct in6_addr *addr,
218 struct in6_addr *mcast,
219 struct in6_addr *acast, int prefix);
220
221extern int lxc_ipv4_addr_add(int ifindex, struct in_addr *addr,
222 struct in_addr *bcast, int prefix);
0ad19a3f 223
ebc73a67 224/* Get ip address. */
19a26f82
MK
225extern int lxc_ipv4_addr_get(int ifindex, struct in_addr **res);
226extern int lxc_ipv6_addr_get(int ifindex, struct in6_addr **res);
227
ebc73a67 228/* Set a destination route to an interface. */
77dcf03a
GL
229extern int lxc_ipv4_dest_add(int ifindex, struct in_addr *dest);
230extern int lxc_ipv6_dest_add(int ifindex, struct in6_addr *dest);
231
ebc73a67 232/* Set default route. */
f8fee0e2
MK
233extern int lxc_ipv4_gateway_add(int ifindex, struct in_addr *gw);
234extern int lxc_ipv6_gateway_add(int ifindex, struct in6_addr *gw);
235
ebc73a67 236/* Attach an interface to the bridge. */
581c75e7
CB
237extern int lxc_bridge_attach(const char *bridge, const char *ifname);
238extern int lxc_ovs_delete_port(const char *bridge, const char *nic);
239
240extern bool is_ovs_bridge(const char *bridge);
0ad19a3f 241
ebc73a67 242/* Create default gateway. */
497353b6
DL
243extern int lxc_route_create_default(const char *addr, const char *ifname,
244 int gateway);
0ad19a3f 245
ebc73a67 246/* Delete default gateway. */
497353b6
DL
247extern int lxc_route_delete_default(const char *addr, const char *ifname,
248 int gateway);
0ad19a3f 249
ebc73a67 250/* Activate neighbor proxying. */
497353b6 251extern int lxc_neigh_proxy_on(const char *name, int family);
0ad19a3f 252
ebc73a67 253/* Disable neighbor proxying. */
497353b6 254extern int lxc_neigh_proxy_off(const char *name, int family);
0ad19a3f 255
811ef482
CB
256/* Generate a new unique network interface name.
257 * Allocated memory must be freed by caller.
258 */
966e9f1f 259extern char *lxc_mkifname(char *template);
a0265685 260
72d0e1cb 261extern const char *lxc_net_type_to_str(int type);
8befa924 262extern int setup_private_host_hw_addr(char *veth1);
0130df54 263extern int netdev_get_mtu(int ifindex);
811ef482 264extern int lxc_create_network_priv(struct lxc_handler *handler);
74c6e2b0
CB
265extern int lxc_network_move_created_netdev_priv(const char *lxcpath,
266 char *lxcname,
267 struct lxc_list *network,
268 pid_t pid);
1bd8d726
CB
269extern bool lxc_delete_network_priv(struct lxc_handler *handler);
270extern bool lxc_delete_network_unpriv(struct lxc_handler *handler);
811ef482 271extern int lxc_find_gateway_addresses(struct lxc_handler *handler);
74c6e2b0
CB
272extern int lxc_create_network_unpriv(const char *lxcpath, char *lxcname,
273 struct lxc_list *network, pid_t pid);
811ef482 274extern int lxc_requests_empty_network(struct lxc_handler *handler);
b809f232 275extern int lxc_restore_phys_nics_to_netns(struct lxc_handler *handler);
811ef482
CB
276extern int lxc_setup_network_in_child_namespaces(const struct lxc_conf *conf,
277 struct lxc_list *network);
7ab1ba02
CB
278extern int lxc_network_send_veth_names_to_child(struct lxc_handler *handler);
279extern int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler);
a1ae535a
CB
280extern int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler *handler);
281extern int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler);
ebc73a67
CB
282
283#endif /* __LXC_NETWORK_H */