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