2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
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
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.
14 #ifndef __NETIFD_SYSTEM_H
15 #define __NETIFD_SYSTEM_H
19 #include <sys/socket.h>
20 #include <arpa/inet.h>
22 #include "interface-ip.h"
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"},
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"},
55 {ARPHRD_HWX25
, "hwx25"},
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"},
70 {ARPHRD_IPDDP
, "ipddp"},
71 {ARPHRD_IPGRE
, "ipgre"},
72 {ARPHRD_PIMREG
,"pimreg"},
73 {ARPHRD_HIPPI
, "hippi"},
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"},
104 extern const struct uci_blob_param_list tunnel_attr_list
;
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
,
116 VXLAN_DATA_ATTR_PROXY
,
117 VXLAN_DATA_ATTR_L2MISS
,
118 VXLAN_DATA_ATTR_L3MISS
,
120 VXLAN_DATA_ATTR_AGEING
,
121 VXLAN_DATA_ATTR_LIMIT
,
122 __VXLAN_DATA_ATTR_MAX
149 SIXRD_DATA_RELAY_PREFIX
,
150 __SIXRD_DATA_ATTR_MAX
154 IPIP6_DATA_ENCAPLIMIT
,
156 __IPIP6_DATA_ATTR_MAX
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
;
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),
184 struct bridge_config
{
185 enum bridge_opt flags
;
188 const char *stp_proto
;
191 bool multicast_querier
;
194 int query_response_interval
;
195 int last_member_interval
;
197 unsigned short priority
;
210 MACVLAN_OPT_MACADDR
= (1 << 0),
213 struct macvlan_config
{
216 enum macvlan_opt flags
;
217 unsigned char macaddr
[6];
221 VETH_OPT_MACADDR
= (1 << 0),
222 VETH_OPT_PEER_NAME
= (1 << 1),
223 VETH_OPT_PEER_MACADDR
= (1 << 2),
229 unsigned char macaddr
[6];
230 char peer_name
[IFNAMSIZ
];
231 unsigned char peer_macaddr
[6];
235 VLAN_PROTO_8021Q
= 0x8100,
236 VLAN_PROTO_8021AD
= 0x88A8
239 struct vlan_qos_mapping
{
240 struct vlist_simple_node node
; /* entry in vlandev_config->{e,in}gress_qos_mapping_list */
245 struct vlandev_config
{
246 enum vlan_proto proto
;
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 */
253 BONDING_MODE_BALANCE_RR
,
254 BONDING_MODE_ACTIVE_BACKUP
,
255 BONDING_MODE_BALANCE_XOR
,
256 BONDING_MODE_BROADCAST
,
258 BONDING_MODE_BALANCE_TLB
,
259 BONDING_MODE_BALANCE_ALB
,
263 struct bonding_config
{
264 enum bonding_mode policy
;
265 const char *xmit_hash_policy
;
266 bool all_ports_active
;
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
;
278 const char *primary_reselect
;
279 const char *failover_mac
;
281 int monitor_interval
;
282 struct blob_attr
*arp_target
;
283 bool arp_all_targets
;
284 const char *arp_validate
;
290 static inline int system_get_addr_family(unsigned int flags
)
292 if ((flags
& DEVADDR_FAMILY
) == DEVADDR_INET6
)
298 static inline int system_get_addr_len(unsigned int flags
)
300 if ((flags
& DEVADDR_FAMILY
) != DEVADDR_INET6
)
301 return sizeof(struct in_addr
);
303 return sizeof(struct in6_addr
);
306 extern const char * const bonding_policy_str
[__BONDING_MODE_MAX
];
308 int system_init(void);
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
);
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
);
321 int system_macvlan_add(struct device
*macvlan
, struct device
*dev
, struct macvlan_config
*cfg
);
322 int system_macvlan_del(struct device
*macvlan
);
324 int system_veth_add(struct device
*veth
, struct veth_config
*cfg
);
325 int system_veth_del(struct device
*veth
);
327 int system_vlan_add(struct device
*dev
, int id
);
328 int system_vlan_del(struct device
*dev
);
330 int system_vlandev_add(struct device
*vlandev
, struct device
*dev
, struct vlandev_config
*cfg
);
331 int system_vlandev_del(struct device
*vlandev
);
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
);
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
);
347 int system_add_address(struct device
*dev
, struct device_addr
*addr
);
348 int system_del_address(struct device
*dev
, struct device_addr
*addr
);
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);
354 int system_add_neighbor(struct device
*dev
, struct device_neighbor
* neighbor
);
355 int system_del_neighbor(struct device
*dev
, struct device_neighbor
* neighbor
);
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
);
363 int system_del_ip_tunnel(const struct device
*dev
);
364 int system_add_ip_tunnel(const struct device
*dev
, struct blob_attr
*attr
);
366 int system_add_iprule(struct iprule
*rule
);
367 int system_del_iprule(struct iprule
*rule
);
368 int system_flush_iprules(void);
370 bool system_resolve_iprule_action(const char *action
, unsigned int *id
);
372 time_t system_get_rtime(void);
374 void system_fd_set_cloexec(int fd
);
376 int system_update_ipv6_mtu(struct device
*dev
, int mtu
);
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
);