1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #ifndef __LXC_NETWORK_H
4 #define __LXC_NETWORK_H
7 #include <linux/types.h>
10 #include <sys/socket.h>
31 * Defines the structure to configure an ipv4 address
32 * @address : ipv4 address
33 * @broadcast : ipv4 broadcast address
34 * @mask : network mask
47 * Defines the structure to configure an ipv6 address
48 * @flags : set the address up
49 * @address : ipv6 address
50 * @broadcast : ipv6 broadcast address
51 * @mask : network mask
55 struct in6_addr mcast
;
56 struct in6_addr acast
;
64 /* Contains information about the host side veth device.
65 * @pair : Name of the host side veth device.
66 * If the user requested that the host veth device be created with a
67 * specific names this field will be set. If this field is set @veth1
69 * @veth1 : Name of the host side veth device.
70 * If the user did not request that the host veth device be created
71 * with a specific name this field will be set. If this field is set
73 * @ifindex : Ifindex of the network device.
79 struct lxc_list ipv4_routes
;
80 struct lxc_list ipv6_routes
;
81 int mode
; /* bridge, router */
92 int mode
; /* private, vepa, bridge, passthru */
96 int mode
; /* l3, l3s, l2 */
97 int isolation
; /* bridge, private, vepa */
100 /* Contains information about the physical network device as seen from the host.
101 * @ifindex : The ifindex of the physical network device in the host's network
110 struct ifla_macvlan macvlan_attr
;
111 struct ifla_ipvlan ipvlan_attr
;
112 struct ifla_phys phys_attr
;
113 struct ifla_veth veth_attr
;
114 struct ifla_vlan vlan_attr
;
118 * Defines a structure to configure a network device
119 * @idx : network counter
120 * @ifindex : ifindex of the network device
121 * Note that this is the ifindex of the network device in
122 * the container's network namespace. If the network device
123 * consists of a pair of network devices (e.g. veth pairs
124 * attached to a network bridge) then this index cannot be
125 * used to identify or modify the host veth device. See
126 * struct ifla_veth for the host side information.
127 * @type : network type (veth, macvlan, vlan, ...)
128 * @flags : flag of the network device (IFF_UP, ... )
129 * @link : lxc.net.[i].link, name of bridge or host iface to attach
131 * @name : lxc.net.[i].name, name of iface on the container side
132 * @created_name : the name with which this interface got created before
133 * being renamed to final_name.
134 * Currenly only used for veth devices.
135 * @hwaddr : mac address
136 * @mtu : maximum transmission unit
137 * @priv : information specific to the specificed network type
138 * Note that this is a union so whether accessing a struct
139 * is possible is dependent on the network type.
140 * @ipv4 : a list of ipv4 addresses to be set on the network device
141 * @ipv6 : a list of ipv6 addresses to be set on the network device
142 * @ipv4_gateway_auto : whether the ipv4 gateway is to be automatically gathered
143 * from the associated @link
144 * @ipv4_gateway_dev : whether the ipv4 gateway is to be set as a device route
145 * @ipv4_gateway : ipv4 gateway
146 * @ipv6_gateway_auto : whether the ipv6 gateway is to be automatically gathered
147 * from the associated @link
148 * @ipv6_gateway_dev : whether the ipv6 gateway is to be set as a device route
149 * @ipv6_gateway : ipv6 gateway
150 * @upscript : a script filename to be executed during interface
152 * @downscript : a script filename to be executed during interface
163 char created_name
[IFNAMSIZ
];
167 struct lxc_list ipv4
;
168 struct lxc_list ipv6
;
169 bool ipv4_gateway_auto
;
170 bool ipv4_gateway_dev
;
171 struct in_addr
*ipv4_gateway
;
172 bool ipv6_gateway_auto
;
173 bool ipv6_gateway_dev
;
174 struct in6_addr
*ipv6_gateway
;
179 /* Convert a string mac address to a socket structure. */
180 extern int lxc_convert_mac(char *macaddr
, struct sockaddr
*sockaddr
);
182 /* Move a device between namespaces. */
183 extern int lxc_netdev_move_by_index(int ifindex
, pid_t pid
, const char *ifname
);
184 extern int lxc_netdev_move_by_name(const char *ifname
, pid_t pid
,
185 const char *newname
);
187 /* Delete a network device. */
188 extern int lxc_netdev_delete_by_name(const char *name
);
189 extern int lxc_netdev_delete_by_index(int ifindex
);
191 /* Change the device name. */
192 extern int lxc_netdev_rename_by_name(const char *oldname
, const char *newname
);
193 extern int lxc_netdev_rename_by_index(int ifindex
, const char *newname
);
195 extern int netdev_set_flag(const char *name
, int flag
);
197 /* Set the device network up or down. */
198 extern int lxc_netdev_isup(const char *name
);
199 extern int lxc_netdev_up(const char *name
);
200 extern int lxc_netdev_down(const char *name
);
202 /* Change the mtu size for the specified device. */
203 extern int lxc_netdev_set_mtu(const char *name
, int mtu
);
205 /* Create a virtual network devices. */
206 extern int lxc_veth_create(const char *name1
, const char *name2
);
207 extern int lxc_macvlan_create(const char *master
, const char *name
, int mode
);
208 extern int lxc_vlan_create(const char *master
, const char *name
,
211 /* Set ip address. */
212 extern int lxc_ipv6_addr_add(int ifindex
, struct in6_addr
*addr
,
213 struct in6_addr
*mcast
,
214 struct in6_addr
*acast
, int prefix
);
216 extern int lxc_ipv4_addr_add(int ifindex
, struct in_addr
*addr
,
217 struct in_addr
*bcast
, int prefix
);
219 /* Get ip address. */
220 extern int lxc_ipv4_addr_get(int ifindex
, struct in_addr
**res
);
221 extern int lxc_ipv6_addr_get(int ifindex
, struct in6_addr
**res
);
223 /* Set default route. */
224 extern int lxc_ipv4_gateway_add(int ifindex
, struct in_addr
*gw
);
225 extern int lxc_ipv6_gateway_add(int ifindex
, struct in6_addr
*gw
);
227 /* Attach an interface to the bridge. */
228 extern int lxc_bridge_attach(const char *bridge
, const char *ifname
);
229 extern int lxc_ovs_delete_port(const char *bridge
, const char *nic
);
231 extern bool is_ovs_bridge(const char *bridge
);
233 /* Create default gateway. */
234 extern int lxc_route_create_default(const char *addr
, const char *ifname
,
237 /* Delete default gateway. */
238 extern int lxc_route_delete_default(const char *addr
, const char *ifname
,
241 /* Activate neighbor proxying. */
242 extern int lxc_neigh_proxy_on(const char *name
, int family
);
244 /* Disable neighbor proxying. */
245 extern int lxc_neigh_proxy_off(const char *name
, int family
);
247 /* Activate IP forwarding. */
248 extern int lxc_ip_forwarding_on(const char *name
, int family
);
250 /* Disable IP forwarding. */
251 extern int lxc_ip_forwarding_off(const char *name
, int family
);
253 /* Generate a new unique network interface name.
254 * Allocated memory must be freed by caller.
256 extern char *lxc_mkifname(char *template);
258 extern const char *lxc_net_type_to_str(int type
);
259 extern int setup_private_host_hw_addr(char *veth1
);
260 extern int netdev_get_mtu(int ifindex
);
261 extern int lxc_network_move_created_netdev_priv(struct lxc_handler
*handler
);
262 extern void lxc_delete_network(struct lxc_handler
*handler
);
263 extern int lxc_find_gateway_addresses(struct lxc_handler
*handler
);
264 extern int lxc_requests_empty_network(struct lxc_handler
*handler
);
265 extern int lxc_restore_phys_nics_to_netns(struct lxc_handler
*handler
);
266 extern int lxc_setup_network_in_child_namespaces(const struct lxc_conf
*conf
,
267 struct lxc_list
*network
);
268 extern int lxc_network_send_to_child(struct lxc_handler
*handler
);
269 extern int lxc_network_recv_from_parent(struct lxc_handler
*handler
);
270 extern int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler
*handler
);
271 extern int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler
*handler
);
272 extern int lxc_netns_set_nsid(int netns_fd
);
273 extern int lxc_netns_get_nsid(__s32 fd
);
274 extern int lxc_create_network(struct lxc_handler
*handler
);
276 extern char *is_wlan(const char *ifname
);
277 extern int lxc_netdev_move_wlan(char *physname
, const char *ifname
, pid_t pid
,
278 const char *newname
);
280 #endif /* __LXC_NETWORK_H */