system-linux: improve handling of device rename
[oweals/netifd.git] / system.h
1 /*
2  * netifd - network interface daemon
3  * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14 #ifndef __NETIFD_SYSTEM_H
15 #define __NETIFD_SYSTEM_H
16
17 #include <net/if.h>
18 #include <sys/time.h>
19 #include <sys/socket.h>
20 #include <arpa/inet.h>
21 #include "device.h"
22 #include "interface-ip.h"
23 #include "iprule.h"
24 #include "utils.h"
25
26 enum tunnel_param {
27         TUNNEL_ATTR_TYPE,
28         TUNNEL_ATTR_REMOTE,
29         TUNNEL_ATTR_LOCAL,
30         TUNNEL_ATTR_MTU,
31         TUNNEL_ATTR_DF,
32         TUNNEL_ATTR_TTL,
33         TUNNEL_ATTR_TOS,
34         TUNNEL_ATTR_LINK,
35         TUNNEL_ATTR_DATA,
36         __TUNNEL_ATTR_MAX
37 };
38
39 extern const struct uci_blob_param_list tunnel_attr_list;
40
41 enum vxlan_data {
42         VXLAN_DATA_ATTR_ID,
43         VXLAN_DATA_ATTR_PORT,
44         VXLAN_DATA_ATTR_MACADDR,
45         VXLAN_DATA_ATTR_RXCSUM,
46         VXLAN_DATA_ATTR_TXCSUM,
47         __VXLAN_DATA_ATTR_MAX
48 };
49
50 enum gre_data {
51         GRE_DATA_IKEY,
52         GRE_DATA_OKEY,
53         GRE_DATA_ICSUM,
54         GRE_DATA_OCSUM,
55         GRE_DATA_ISEQNO,
56         GRE_DATA_OSEQNO,
57         GRE_DATA_ENCAPLIMIT,
58         __GRE_DATA_ATTR_MAX
59 };
60
61 enum vti_data {
62         VTI_DATA_IKEY,
63         VTI_DATA_OKEY,
64         __VTI_DATA_ATTR_MAX
65 };
66
67 enum xfrm_data {
68         XFRM_DATA_IF_ID,
69         __XFRM_DATA_ATTR_MAX
70 };
71
72 enum sixrd_data {
73         SIXRD_DATA_PREFIX,
74         SIXRD_DATA_RELAY_PREFIX,
75         __SIXRD_DATA_ATTR_MAX
76 };
77
78 enum ipip6_data {
79         IPIP6_DATA_ENCAPLIMIT,
80         IPIP6_DATA_FMRS,
81         __IPIP6_DATA_ATTR_MAX
82 };
83
84 enum fmr_data {
85         FMR_DATA_PREFIX6,
86         FMR_DATA_PREFIX4,
87         FMR_DATA_EALEN,
88         FMR_DATA_OFFSET,
89         __FMR_DATA_ATTR_MAX
90 };
91
92 extern const struct uci_blob_param_list vxlan_data_attr_list;
93 extern const struct uci_blob_param_list gre_data_attr_list;
94 extern const struct uci_blob_param_list vti_data_attr_list;
95 extern const struct uci_blob_param_list xfrm_data_attr_list;
96 extern const struct uci_blob_param_list sixrd_data_attr_list;
97 extern const struct uci_blob_param_list ipip6_data_attr_list;
98 extern const struct uci_blob_param_list fmr_data_attr_list;
99
100 enum bridge_opt {
101         /* stp and forward delay always set */
102         BRIDGE_OPT_AGEING_TIME              = (1 << 0),
103         BRIDGE_OPT_HELLO_TIME               = (1 << 1),
104         BRIDGE_OPT_MAX_AGE                  = (1 << 2),
105         BRIDGE_OPT_ROBUSTNESS               = (1 << 3),
106         BRIDGE_OPT_QUERY_INTERVAL           = (1 << 4),
107         BRIDGE_OPT_QUERY_RESPONSE_INTERVAL  = (1 << 5),
108         BRIDGE_OPT_LAST_MEMBER_INTERVAL     = (1 << 6),
109 };
110
111 struct bridge_config {
112         enum bridge_opt flags;
113         bool stp;
114
115         bool igmp_snoop;
116         bool multicast_querier;
117         int robustness;
118         int query_interval;
119         int query_response_interval;
120         int last_member_interval;
121
122         unsigned short priority;
123         int forward_delay;
124         bool bridge_empty;
125
126         int ageing_time;
127         int hello_time;
128         int max_age;
129         int hash_max;
130 };
131
132 enum macvlan_opt {
133         MACVLAN_OPT_MACADDR = (1 << 0),
134 };
135
136 struct macvlan_config {
137         const char *mode;
138
139         enum macvlan_opt flags;
140         unsigned char macaddr[6];
141 };
142
143 enum veth_opt {
144         VETH_OPT_MACADDR = (1 << 0),
145         VETH_OPT_PEER_NAME = (1 << 1),
146         VETH_OPT_PEER_MACADDR = (1 << 2),
147 };
148
149 struct veth_config {
150         enum veth_opt flags;
151
152         unsigned char macaddr[6];
153         char peer_name[IFNAMSIZ];
154         unsigned char peer_macaddr[6];
155 };
156
157 enum vlan_proto {
158         VLAN_PROTO_8021Q = 0x8100,
159         VLAN_PROTO_8021AD = 0x88A8
160 };
161
162 struct vlan_qos_mapping {
163         struct vlist_simple_node node; /* entry in vlandev_config->{e,in}gress_qos_mapping_list */
164         uint32_t from;
165         uint32_t to;
166 };
167
168 struct vlandev_config {
169         enum vlan_proto proto;
170         uint16_t vid;
171         struct vlist_simple_tree ingress_qos_mapping_list; /* list of struct vlan_qos_mapping */
172         struct vlist_simple_tree egress_qos_mapping_list;  /* list of struct vlan_qos_mapping */
173 };
174
175 static inline int system_get_addr_family(unsigned int flags)
176 {
177         if ((flags & DEVADDR_FAMILY) == DEVADDR_INET6)
178                 return AF_INET6;
179         else
180                 return AF_INET;
181 }
182
183 static inline int system_get_addr_len(unsigned int flags)
184 {
185         if ((flags & DEVADDR_FAMILY) != DEVADDR_INET6)
186                 return sizeof(struct in_addr);
187         else
188                 return sizeof(struct in6_addr);
189 }
190
191 int system_init(void);
192
193 int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg);
194 int system_bridge_delbr(struct device *bridge);
195 int system_bridge_addif(struct device *bridge, struct device *dev);
196 int system_bridge_delif(struct device *bridge, struct device *dev);
197
198 int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvlan_config *cfg);
199 int system_macvlan_del(struct device *macvlan);
200
201 int system_veth_add(struct device *veth, struct veth_config *cfg);
202 int system_veth_del(struct device *veth);
203
204 int system_vlan_add(struct device *dev, int id);
205 int system_vlan_del(struct device *dev);
206
207 int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlandev_config *cfg);
208 int system_vlandev_del(struct device *vlandev);
209
210 void system_if_get_settings(struct device *dev, struct device_settings *s);
211 void system_if_clear_state(struct device *dev);
212 int system_if_up(struct device *dev);
213 int system_if_down(struct device *dev);
214 int system_if_check(struct device *dev);
215 int system_if_resolve(struct device *dev);
216
217 int system_if_dump_info(struct device *dev, struct blob_buf *b);
218 int system_if_dump_stats(struct device *dev, struct blob_buf *b);
219 struct device *system_if_get_parent(struct device *dev);
220 bool system_if_force_external(const char *ifname);
221 void system_if_apply_settings(struct device *dev, struct device_settings *s,
222                               unsigned int apply_mask);
223
224 int system_add_address(struct device *dev, struct device_addr *addr);
225 int system_del_address(struct device *dev, struct device_addr *addr);
226
227 int system_add_route(struct device *dev, struct device_route *route);
228 int system_del_route(struct device *dev, struct device_route *route);
229 int system_flush_routes(void);
230
231 int system_add_neighbor(struct device *dev, struct device_neighbor * neighbor);
232 int system_del_neighbor(struct device *dev, struct device_neighbor * neighbor);
233
234 bool system_resolve_rt_type(const char *type, unsigned int *id);
235 bool system_resolve_rt_proto(const char *type, unsigned int *id);
236 bool system_resolve_rt_table(const char *name, unsigned int *id);
237 bool system_is_default_rt_table(unsigned int id);
238 bool system_resolve_rpfilter(const char *filter, unsigned int *id);
239
240 int system_del_ip_tunnel(const char *name, struct blob_attr *attr);
241 int system_add_ip_tunnel(const char *name, struct blob_attr *attr);
242
243 int system_add_iprule(struct iprule *rule);
244 int system_del_iprule(struct iprule *rule);
245 int system_flush_iprules(void);
246
247 bool system_resolve_iprule_action(const char *action, unsigned int *id);
248
249 time_t system_get_rtime(void);
250
251 void system_fd_set_cloexec(int fd);
252
253 int system_update_ipv6_mtu(struct device *dev, int mtu);
254
255 int system_link_netns_move(struct device *dev, const pid_t target_ns, const char *target_ifname);
256 int system_netns_open(const pid_t target_ns);
257 int system_netns_set(int netns_fd);
258
259 #endif