2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef __LXC_NETWORK_H
24 #define __LXC_NETWORK_H
26 #include <arpa/inet.h>
27 #include <linux/types.h>
30 #include <sys/socket.h>
51 * Defines the structure to configure an ipv4 address
52 * @address : ipv4 address
53 * @broadcast : ipv4 broadcast address
54 * @mask : network mask
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
75 struct in6_addr mcast
;
76 struct in6_addr acast
;
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
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
93 * @ifindex : Ifindex of the network device.
99 struct lxc_list ipv4_routes
;
100 struct lxc_list ipv6_routes
;
110 struct ifla_macvlan
{
111 int mode
; /* private, vepa, bridge, passthru */
115 int mode
; /* l3, l3s, l2 */
116 int isolation
; /* bridge, private, vepa */
119 /* Contains information about the physical network device as seen from the host.
120 * @ifindex : The ifindex of the physical network device in the host's network
129 struct ifla_macvlan macvlan_attr
;
130 struct ifla_ipvlan ipvlan_attr
;
131 struct ifla_phys phys_attr
;
132 struct ifla_veth veth_attr
;
133 struct ifla_vlan vlan_attr
;
137 * Defines a structure to configure a network device
138 * @idx : network counter
139 * @ifindex : ifindex of the network device
140 * Note that this is the ifindex of the network device in
141 * the container's network namespace. If the network device
142 * consists of a pair of network devices (e.g. veth pairs
143 * attached to a network bridge) then this index cannot be
144 * used to identify or modify the host veth device. See
145 * struct ifla_veth for the host side information.
146 * @type : network type (veth, macvlan, vlan, ...)
147 * @flags : flag of the network device (IFF_UP, ... )
148 * @link : lxc.net.[i].link, name of bridge or host iface to attach
150 * @name : lxc.net.[i].name, name of iface on the container side
151 * @created_name : the name with which this interface got created before
152 * being renamed to final_name.
153 * Currenly only used for veth devices.
154 * @hwaddr : mac address
155 * @mtu : maximum transmission unit
156 * @priv : information specific to the specificed network type
157 * Note that this is a union so whether accessing a struct
158 * is possible is dependent on the network type.
159 * @ipv4 : a list of ipv4 addresses to be set on the network device
160 * @ipv6 : a list of ipv6 addresses to be set on the network device
161 * @ipv4_gateway_auto : whether the ipv4 gateway is to be automatically gathered
162 * from the associated @link
163 * @ipv4_gateway_dev : whether the ipv4 gateway is to be set as a device route
164 * @ipv4_gateway : ipv4 gateway
165 * @ipv6_gateway_auto : whether the ipv6 gateway is to be automatically gathered
166 * from the associated @link
167 * @ipv6_gateway_dev : whether the ipv6 gateway is to be set as a device route
168 * @ipv6_gateway : ipv6 gateway
169 * @upscript : a script filename to be executed during interface
171 * @downscript : a script filename to be executed during interface
182 char created_name
[IFNAMSIZ
];
186 struct lxc_list ipv4
;
187 struct lxc_list ipv6
;
188 bool ipv4_gateway_auto
;
189 bool ipv4_gateway_dev
;
190 struct in_addr
*ipv4_gateway
;
191 bool ipv6_gateway_auto
;
192 bool ipv6_gateway_dev
;
193 struct in6_addr
*ipv6_gateway
;
198 /* Convert a string mac address to a socket structure. */
199 extern int lxc_convert_mac(char *macaddr
, struct sockaddr
*sockaddr
);
201 /* Move a device between namespaces. */
202 extern int lxc_netdev_move_by_index(int ifindex
, pid_t pid
, const char *ifname
);
203 extern int lxc_netdev_move_by_name(const char *ifname
, pid_t pid
,
204 const char *newname
);
206 /* Delete a network device. */
207 extern int lxc_netdev_delete_by_name(const char *name
);
208 extern int lxc_netdev_delete_by_index(int ifindex
);
210 /* Change the device name. */
211 extern int lxc_netdev_rename_by_name(const char *oldname
, const char *newname
);
212 extern int lxc_netdev_rename_by_index(int ifindex
, const char *newname
);
214 extern int netdev_set_flag(const char *name
, int flag
);
216 /* Set the device network up or down. */
217 extern int lxc_netdev_isup(const char *name
);
218 extern int lxc_netdev_up(const char *name
);
219 extern int lxc_netdev_down(const char *name
);
221 /* Change the mtu size for the specified device. */
222 extern int lxc_netdev_set_mtu(const char *name
, int mtu
);
224 /* Create a virtual network devices. */
225 extern int lxc_veth_create(const char *name1
, const char *name2
);
226 extern int lxc_macvlan_create(const char *master
, const char *name
, int mode
);
227 extern int lxc_vlan_create(const char *master
, const char *name
,
230 /* Set ip address. */
231 extern int lxc_ipv6_addr_add(int ifindex
, struct in6_addr
*addr
,
232 struct in6_addr
*mcast
,
233 struct in6_addr
*acast
, int prefix
);
235 extern int lxc_ipv4_addr_add(int ifindex
, struct in_addr
*addr
,
236 struct in_addr
*bcast
, int prefix
);
238 /* Get ip address. */
239 extern int lxc_ipv4_addr_get(int ifindex
, struct in_addr
**res
);
240 extern int lxc_ipv6_addr_get(int ifindex
, struct in6_addr
**res
);
242 /* Set default route. */
243 extern int lxc_ipv4_gateway_add(int ifindex
, struct in_addr
*gw
);
244 extern int lxc_ipv6_gateway_add(int ifindex
, struct in6_addr
*gw
);
246 /* Attach an interface to the bridge. */
247 extern int lxc_bridge_attach(const char *bridge
, const char *ifname
);
248 extern int lxc_ovs_delete_port(const char *bridge
, const char *nic
);
250 extern bool is_ovs_bridge(const char *bridge
);
252 /* Create default gateway. */
253 extern int lxc_route_create_default(const char *addr
, const char *ifname
,
256 /* Delete default gateway. */
257 extern int lxc_route_delete_default(const char *addr
, const char *ifname
,
260 /* Activate neighbor proxying. */
261 extern int lxc_neigh_proxy_on(const char *name
, int family
);
263 /* Disable neighbor proxying. */
264 extern int lxc_neigh_proxy_off(const char *name
, int family
);
266 /* Generate a new unique network interface name.
267 * Allocated memory must be freed by caller.
269 extern char *lxc_mkifname(char *template);
271 extern const char *lxc_net_type_to_str(int type
);
272 extern int setup_private_host_hw_addr(char *veth1
);
273 extern int netdev_get_mtu(int ifindex
);
274 extern int lxc_network_move_created_netdev_priv(struct lxc_handler
*handler
);
275 extern void lxc_delete_network(struct lxc_handler
*handler
);
276 extern int lxc_find_gateway_addresses(struct lxc_handler
*handler
);
277 extern int lxc_requests_empty_network(struct lxc_handler
*handler
);
278 extern int lxc_restore_phys_nics_to_netns(struct lxc_handler
*handler
);
279 extern int lxc_setup_network_in_child_namespaces(const struct lxc_conf
*conf
,
280 struct lxc_list
*network
);
281 extern int lxc_network_send_to_child(struct lxc_handler
*handler
);
282 extern int lxc_network_recv_from_parent(struct lxc_handler
*handler
);
283 extern int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler
*handler
);
284 extern int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler
*handler
);
285 extern int lxc_netns_set_nsid(int netns_fd
);
286 extern int lxc_netns_get_nsid(__s32 fd
);
287 extern int lxc_create_network(struct lxc_handler
*handler
);
289 #endif /* __LXC_NETWORK_H */