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