netifd: add devtype to ubus call
[project/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 struct netdev_type {
27 unsigned short id;
28 const char *name;
29 };
30
31 static const struct netdev_type netdev_types[] = {
32 {ARPHRD_NETROM, "netrom"},
33 {ARPHRD_ETHER, "ethernet"},
34 {ARPHRD_EETHER, "eethernet"},
35 {ARPHRD_AX25, "ax25"},
36 {ARPHRD_PRONET, "pronet"},
37 {ARPHRD_CHAOS, "chaos"},
38 {ARPHRD_IEEE802, "ieee802"},
39 {ARPHRD_ARCNET, "arcnet"},
40 {ARPHRD_APPLETLK, "appletlk"},
41 {ARPHRD_DLCI, "dlci"},
42 {ARPHRD_ATM, "atm"},
43 {ARPHRD_METRICOM, "metricom"},
44 {ARPHRD_IEEE1394, "ieee1394"},
45 {ARPHRD_EUI64, "eui64"},
46 {ARPHRD_INFINIBAND, "infiniband"},
47 {ARPHRD_SLIP, "slip"},
48 {ARPHRD_CSLIP, "cslip"},
49 {ARPHRD_SLIP6, "slip6"},
50 {ARPHRD_CSLIP6, "cslip6"},
51 {ARPHRD_RSRVD, "rsrvd"},
52 {ARPHRD_ADAPT, "adapt"},
53 {ARPHRD_ROSE, "rose"},
54 {ARPHRD_X25, "x25"},
55 {ARPHRD_HWX25, "hwx25"},
56 {ARPHRD_PPP, "ppp"},
57 {ARPHRD_CISCO, "cisco"},
58 {ARPHRD_LAPB, "lapb"},
59 {ARPHRD_DDCMP, "ddcmp"},
60 {ARPHRD_RAWHDLC, "rawhdlc"},
61 {ARPHRD_TUNNEL, "tunnel"},
62 {ARPHRD_TUNNEL6, "tunnel6"},
63 {ARPHRD_FRAD, "frad"},
64 {ARPHRD_SKIP, "skip"},
65 {ARPHRD_LOOPBACK, "loopback"},
66 {ARPHRD_LOCALTLK, "localtlk"},
67 {ARPHRD_FDDI, "fddi"},
68 {ARPHRD_BIF, "bif"},
69 {ARPHRD_SIT, "sit"},
70 {ARPHRD_IPDDP, "ipddp"},
71 {ARPHRD_IPGRE, "ipgre"},
72 {ARPHRD_PIMREG,"pimreg"},
73 {ARPHRD_HIPPI, "hippi"},
74 {ARPHRD_ASH, "ash"},
75 {ARPHRD_ECONET, "econet"},
76 {ARPHRD_IRDA, "irda"},
77 {ARPHRD_FCPP, "fcpp"},
78 {ARPHRD_FCAL, "fcal"},
79 {ARPHRD_FCPL, "fcpl"},
80 {ARPHRD_FCFABRIC, "fcfabric"},
81 {ARPHRD_IEEE80211, "ieee80211"},
82 {ARPHRD_IEEE80211_PRISM, "ie80211-prism"},
83 {ARPHRD_IEEE80211_RADIOTAP, "ieee80211-radiotap"},
84 {ARPHRD_PHONET, "phonet"},
85 {ARPHRD_PHONET_PIPE, "phonet-pipe"},
86 {ARPHRD_IEEE802154, "ieee802154"},
87 {ARPHRD_VOID, "void"},
88 {ARPHRD_NONE, "none"}
89 };
90
91 enum tunnel_param {
92 TUNNEL_ATTR_TYPE,
93 TUNNEL_ATTR_REMOTE,
94 TUNNEL_ATTR_LOCAL,
95 TUNNEL_ATTR_MTU,
96 TUNNEL_ATTR_DF,
97 TUNNEL_ATTR_TTL,
98 TUNNEL_ATTR_TOS,
99 TUNNEL_ATTR_LINK,
100 TUNNEL_ATTR_DATA,
101 __TUNNEL_ATTR_MAX
102 };
103
104 extern const struct uci_blob_param_list tunnel_attr_list;
105
106 enum vxlan_data {
107 VXLAN_DATA_ATTR_ID,
108 VXLAN_DATA_ATTR_PORT,
109 VXLAN_DATA_ATTR_MACADDR,
110 VXLAN_DATA_ATTR_RXCSUM,
111 VXLAN_DATA_ATTR_TXCSUM,
112 VXLAN_DATA_ATTR_SRCPORTMIN,
113 VXLAN_DATA_ATTR_SRCPORTMAX,
114 VXLAN_DATA_ATTR_LEARNING,
115 VXLAN_DATA_ATTR_RSC,
116 VXLAN_DATA_ATTR_PROXY,
117 VXLAN_DATA_ATTR_L2MISS,
118 VXLAN_DATA_ATTR_L3MISS,
119 VXLAN_DATA_ATTR_GBP,
120 VXLAN_DATA_ATTR_AGEING,
121 VXLAN_DATA_ATTR_LIMIT,
122 __VXLAN_DATA_ATTR_MAX
123 };
124
125 enum gre_data {
126 GRE_DATA_IKEY,
127 GRE_DATA_OKEY,
128 GRE_DATA_ICSUM,
129 GRE_DATA_OCSUM,
130 GRE_DATA_ISEQNO,
131 GRE_DATA_OSEQNO,
132 GRE_DATA_ENCAPLIMIT,
133 __GRE_DATA_ATTR_MAX
134 };
135
136 enum vti_data {
137 VTI_DATA_IKEY,
138 VTI_DATA_OKEY,
139 __VTI_DATA_ATTR_MAX
140 };
141
142 enum xfrm_data {
143 XFRM_DATA_IF_ID,
144 __XFRM_DATA_ATTR_MAX
145 };
146
147 enum sixrd_data {
148 SIXRD_DATA_PREFIX,
149 SIXRD_DATA_RELAY_PREFIX,
150 __SIXRD_DATA_ATTR_MAX
151 };
152
153 enum ipip6_data {
154 IPIP6_DATA_ENCAPLIMIT,
155 IPIP6_DATA_FMRS,
156 __IPIP6_DATA_ATTR_MAX
157 };
158
159 enum fmr_data {
160 FMR_DATA_PREFIX6,
161 FMR_DATA_PREFIX4,
162 FMR_DATA_EALEN,
163 FMR_DATA_OFFSET,
164 __FMR_DATA_ATTR_MAX
165 };
166
167 extern const struct uci_blob_param_list vxlan_data_attr_list;
168 extern const struct uci_blob_param_list gre_data_attr_list;
169 extern const struct uci_blob_param_list vti_data_attr_list;
170 extern const struct uci_blob_param_list xfrm_data_attr_list;
171 extern const struct uci_blob_param_list sixrd_data_attr_list;
172 extern const struct uci_blob_param_list ipip6_data_attr_list;
173 extern const struct uci_blob_param_list fmr_data_attr_list;
174
175 enum bridge_opt {
176 /* stp, forward delay, max age and hello time are always set */
177 BRIDGE_OPT_AGEING_TIME = (1 << 0),
178 BRIDGE_OPT_ROBUSTNESS = (1 << 1),
179 BRIDGE_OPT_QUERY_INTERVAL = (1 << 2),
180 BRIDGE_OPT_QUERY_RESPONSE_INTERVAL = (1 << 3),
181 BRIDGE_OPT_LAST_MEMBER_INTERVAL = (1 << 4),
182 };
183
184 struct bridge_config {
185 enum bridge_opt flags;
186 bool stp;
187 bool stp_kernel;
188 const char *stp_proto;
189
190 bool igmp_snoop;
191 bool multicast_querier;
192 int robustness;
193 int query_interval;
194 int query_response_interval;
195 int last_member_interval;
196
197 unsigned short priority;
198 int forward_delay;
199 bool bridge_empty;
200
201 int ageing_time;
202 int hello_time;
203 int max_age;
204 int hash_max;
205
206 bool vlan_filtering;
207 };
208
209 enum macvlan_opt {
210 MACVLAN_OPT_MACADDR = (1 << 0),
211 };
212
213 struct macvlan_config {
214 const char *mode;
215
216 enum macvlan_opt flags;
217 unsigned char macaddr[6];
218 };
219
220 enum veth_opt {
221 VETH_OPT_MACADDR = (1 << 0),
222 VETH_OPT_PEER_NAME = (1 << 1),
223 VETH_OPT_PEER_MACADDR = (1 << 2),
224 };
225
226 struct veth_config {
227 enum veth_opt flags;
228
229 unsigned char macaddr[6];
230 char peer_name[IFNAMSIZ];
231 unsigned char peer_macaddr[6];
232 };
233
234 enum vlan_proto {
235 VLAN_PROTO_8021Q = 0x8100,
236 VLAN_PROTO_8021AD = 0x88A8
237 };
238
239 struct vlan_qos_mapping {
240 struct vlist_simple_node node; /* entry in vlandev_config->{e,in}gress_qos_mapping_list */
241 uint32_t from;
242 uint32_t to;
243 };
244
245 struct vlandev_config {
246 enum vlan_proto proto;
247 uint16_t vid;
248 struct vlist_simple_tree ingress_qos_mapping_list; /* list of struct vlan_qos_mapping */
249 struct vlist_simple_tree egress_qos_mapping_list; /* list of struct vlan_qos_mapping */
250 };
251
252 enum bonding_mode {
253 BONDING_MODE_BALANCE_RR,
254 BONDING_MODE_ACTIVE_BACKUP,
255 BONDING_MODE_BALANCE_XOR,
256 BONDING_MODE_BROADCAST,
257 BONDING_MODE_8023AD,
258 BONDING_MODE_BALANCE_TLB,
259 BONDING_MODE_BALANCE_ALB,
260 __BONDING_MODE_MAX,
261 };
262
263 struct bonding_config {
264 enum bonding_mode policy;
265 const char *xmit_hash_policy;
266 bool all_ports_active;
267 int min_links;
268 const char *ad_actor_system;
269 int ad_actor_sys_prio;
270 const char *ad_select;
271 const char *lacp_rate;
272 int packets_per_port;
273 int lp_interval;
274 bool dynamic_lb;
275 int resend_igmp;
276 int num_peer_notif;
277 const char *primary;
278 const char *primary_reselect;
279 const char *failover_mac;
280 bool monitor_arp;
281 int monitor_interval;
282 struct blob_attr *arp_target;
283 bool arp_all_targets;
284 const char *arp_validate;
285 bool use_carrier;
286 int updelay;
287 int downdelay;
288 };
289
290 static inline int system_get_addr_family(unsigned int flags)
291 {
292 if ((flags & DEVADDR_FAMILY) == DEVADDR_INET6)
293 return AF_INET6;
294 else
295 return AF_INET;
296 }
297
298 static inline int system_get_addr_len(unsigned int flags)
299 {
300 if ((flags & DEVADDR_FAMILY) != DEVADDR_INET6)
301 return sizeof(struct in_addr);
302 else
303 return sizeof(struct in6_addr);
304 }
305
306 extern const char * const bonding_policy_str[__BONDING_MODE_MAX];
307
308 int system_init(void);
309
310 int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg);
311 int system_bridge_delbr(struct device *bridge);
312 int system_bridge_addif(struct device *bridge, struct device *dev);
313 int system_bridge_delif(struct device *bridge, struct device *dev);
314 int system_bridge_vlan(const char *iface, uint16_t vid, bool add, unsigned int vflags);
315 int system_bridge_vlan_check(struct device *dev, char *ifname);
316 void system_bridge_set_stp_state(struct device *dev, bool val);
317
318 int system_bonding_set_device(struct device *dev, struct bonding_config *cfg);
319 int system_bonding_set_port(struct device *dev, struct device *port, bool add, bool primary);
320
321 int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvlan_config *cfg);
322 int system_macvlan_del(struct device *macvlan);
323
324 int system_veth_add(struct device *veth, struct veth_config *cfg);
325 int system_veth_del(struct device *veth);
326
327 int system_vlan_add(struct device *dev, int id);
328 int system_vlan_del(struct device *dev);
329
330 int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlandev_config *cfg);
331 int system_vlandev_del(struct device *vlandev);
332
333 void system_if_get_settings(struct device *dev, struct device_settings *s);
334 void system_if_clear_state(struct device *dev);
335 int system_if_up(struct device *dev);
336 int system_if_down(struct device *dev);
337 int system_if_check(struct device *dev);
338 int system_if_resolve(struct device *dev);
339
340 int system_if_dump_info(struct device *dev, struct blob_buf *b);
341 int system_if_dump_stats(struct device *dev, struct blob_buf *b);
342 struct device *system_if_get_parent(struct device *dev);
343 bool system_if_force_external(const char *ifname);
344 void system_if_apply_settings(struct device *dev, struct device_settings *s,
345 uint64_t apply_mask);
346
347 int system_add_address(struct device *dev, struct device_addr *addr);
348 int system_del_address(struct device *dev, struct device_addr *addr);
349
350 int system_add_route(struct device *dev, struct device_route *route);
351 int system_del_route(struct device *dev, struct device_route *route);
352 int system_flush_routes(void);
353
354 int system_add_neighbor(struct device *dev, struct device_neighbor * neighbor);
355 int system_del_neighbor(struct device *dev, struct device_neighbor * neighbor);
356
357 bool system_resolve_rt_type(const char *type, unsigned int *id);
358 bool system_resolve_rt_proto(const char *type, unsigned int *id);
359 bool system_resolve_rt_table(const char *name, unsigned int *id);
360 bool system_is_default_rt_table(unsigned int id);
361 bool system_resolve_rpfilter(const char *filter, unsigned int *id);
362
363 int system_del_ip_tunnel(const struct device *dev);
364 int system_add_ip_tunnel(const struct device *dev, struct blob_attr *attr);
365
366 int system_add_iprule(struct iprule *rule);
367 int system_del_iprule(struct iprule *rule);
368 int system_flush_iprules(void);
369
370 bool system_resolve_iprule_action(const char *action, unsigned int *id);
371
372 time_t system_get_rtime(void);
373
374 void system_fd_set_cloexec(int fd);
375
376 int system_update_ipv6_mtu(struct device *dev, int mtu);
377
378 int system_link_netns_move(struct device *dev, const pid_t target_ns, const char *target_ifname);
379 int system_netns_open(const pid_t target_ns);
380 int system_netns_set(int netns_fd);
381
382 #endif