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