]>
Commit | Line | Data |
---|---|---|
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 | ||
16 | struct lxc_conf; | |
17 | struct lxc_handler; | |
18 | struct lxc_netdev; | |
19 | ||
20 | enum { | |
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 | */ | |
37 | struct lxc_inetdev { | |
38 | struct in_addr addr; | |
39 | struct in_addr bcast; | |
40 | unsigned int prefix; | |
41 | }; | |
42 | ||
43 | struct 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 | */ | |
54 | struct lxc_inet6dev { | |
55 | struct in6_addr addr; | |
56 | struct in6_addr mcast; | |
57 | struct in6_addr acast; | |
58 | unsigned int prefix; | |
59 | }; | |
60 | ||
61 | struct 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 | 76 | struct 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 | ||
88 | struct ifla_vlan { | |
89 | unsigned int flags; | |
90 | unsigned int fmask; | |
91 | unsigned short vid; | |
92 | unsigned short pad; | |
93 | }; | |
94 | ||
95 | struct ifla_macvlan { | |
96 | int mode; /* private, vepa, bridge, passthru */ | |
97 | }; | |
98 | ||
c9f52382 | 99 | struct 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 | */ | |
108 | struct ifla_phys { | |
109 | int ifindex; | |
0b154989 | 110 | int mtu; |
790255cf CB |
111 | }; |
112 | ||
811ef482 | 113 | union 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 | */ |
159 | struct 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 */ |