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"},
85 {ARPHRD_PHONET
, "phonet"},
87 #ifdef ARPHRD_PHONET_PIPE
88 {ARPHRD_PHONET_PIPE
, "phonet-pipe"},
90 {ARPHRD_IEEE802154
, "ieee802154"},
91 {ARPHRD_VOID
, "void"},
108 extern const struct uci_blob_param_list tunnel_attr_list
;
112 VXLAN_DATA_ATTR_PORT
,
113 VXLAN_DATA_ATTR_MACADDR
,
114 VXLAN_DATA_ATTR_RXCSUM
,
115 VXLAN_DATA_ATTR_TXCSUM
,
116 VXLAN_DATA_ATTR_SRCPORTMIN
,
117 VXLAN_DATA_ATTR_SRCPORTMAX
,
118 VXLAN_DATA_ATTR_LEARNING
,
120 VXLAN_DATA_ATTR_PROXY
,
121 VXLAN_DATA_ATTR_L2MISS
,
122 VXLAN_DATA_ATTR_L3MISS
,
124 VXLAN_DATA_ATTR_AGEING
,
125 VXLAN_DATA_ATTR_LIMIT
,
126 __VXLAN_DATA_ATTR_MAX
153 SIXRD_DATA_RELAY_PREFIX
,
154 __SIXRD_DATA_ATTR_MAX
158 IPIP6_DATA_ENCAPLIMIT
,
160 __IPIP6_DATA_ATTR_MAX
171 extern const struct uci_blob_param_list vxlan_data_attr_list
;
172 extern const struct uci_blob_param_list gre_data_attr_list
;
173 extern const struct uci_blob_param_list vti_data_attr_list
;
174 extern const struct uci_blob_param_list xfrm_data_attr_list
;
175 extern const struct uci_blob_param_list sixrd_data_attr_list
;
176 extern const struct uci_blob_param_list ipip6_data_attr_list
;
177 extern const struct uci_blob_param_list fmr_data_attr_list
;
180 /* stp, forward delay, max age and hello time are always set */
181 BRIDGE_OPT_AGEING_TIME
= (1 << 0),
182 BRIDGE_OPT_ROBUSTNESS
= (1 << 1),
183 BRIDGE_OPT_QUERY_INTERVAL
= (1 << 2),
184 BRIDGE_OPT_QUERY_RESPONSE_INTERVAL
= (1 << 3),
185 BRIDGE_OPT_LAST_MEMBER_INTERVAL
= (1 << 4),
188 struct bridge_config
{
189 enum bridge_opt flags
;
192 const char *stp_proto
;
195 bool multicast_querier
;
198 int query_response_interval
;
199 int last_member_interval
;
201 unsigned short priority
;
214 MACVLAN_OPT_MACADDR
= (1 << 0),
217 struct macvlan_config
{
220 enum macvlan_opt flags
;
221 unsigned char macaddr
[6];
225 VETH_OPT_MACADDR
= (1 << 0),
226 VETH_OPT_PEER_NAME
= (1 << 1),
227 VETH_OPT_PEER_MACADDR
= (1 << 2),
233 unsigned char macaddr
[6];
234 char peer_name
[IFNAMSIZ
];
235 unsigned char peer_macaddr
[6];
239 VLAN_PROTO_8021Q
= 0x8100,
240 VLAN_PROTO_8021AD
= 0x88A8
243 struct vlan_qos_mapping
{
244 struct vlist_simple_node node
; /* entry in vlandev_config->{e,in}gress_qos_mapping_list */
249 struct vlandev_config
{
250 enum vlan_proto proto
;
252 struct vlist_simple_tree ingress_qos_mapping_list
; /* list of struct vlan_qos_mapping */
253 struct vlist_simple_tree egress_qos_mapping_list
; /* list of struct vlan_qos_mapping */
257 BONDING_MODE_BALANCE_RR
,
258 BONDING_MODE_ACTIVE_BACKUP
,
259 BONDING_MODE_BALANCE_XOR
,
260 BONDING_MODE_BROADCAST
,
262 BONDING_MODE_BALANCE_TLB
,
263 BONDING_MODE_BALANCE_ALB
,
267 struct bonding_config
{
268 enum bonding_mode policy
;
269 const char *xmit_hash_policy
;
270 bool all_ports_active
;
272 const char *ad_actor_system
;
273 int ad_actor_sys_prio
;
274 const char *ad_select
;
275 const char *lacp_rate
;
276 int packets_per_port
;
282 const char *primary_reselect
;
283 const char *failover_mac
;
285 int monitor_interval
;
286 struct blob_attr
*arp_target
;
287 bool arp_all_targets
;
288 const char *arp_validate
;
294 static inline int system_get_addr_family(unsigned int flags
)
296 if ((flags
& DEVADDR_FAMILY
) == DEVADDR_INET6
)
302 static inline int system_get_addr_len(unsigned int flags
)
304 if ((flags
& DEVADDR_FAMILY
) != DEVADDR_INET6
)
305 return sizeof(struct in_addr
);
307 return sizeof(struct in6_addr
);
310 extern const char * const bonding_policy_str
[__BONDING_MODE_MAX
];
312 int system_init(void);
314 int system_bridge_addbr(struct device
*bridge
, struct bridge_config
*cfg
);
315 int system_bridge_delbr(struct device
*bridge
);
316 int system_bridge_addif(struct device
*bridge
, struct device
*dev
);
317 int system_bridge_delif(struct device
*bridge
, struct device
*dev
);
318 int system_bridge_vlan(const char *iface
, uint16_t vid
, bool add
, unsigned int vflags
);
319 int system_bridge_vlan_check(struct device
*dev
, char *ifname
);
320 void system_bridge_set_stp_state(struct device
*dev
, bool val
);
322 int system_bonding_set_device(struct device
*dev
, struct bonding_config
*cfg
);
323 int system_bonding_set_port(struct device
*dev
, struct device
*port
, bool add
, bool primary
);
325 int system_macvlan_add(struct device
*macvlan
, struct device
*dev
, struct macvlan_config
*cfg
);
326 int system_macvlan_del(struct device
*macvlan
);
328 int system_veth_add(struct device
*veth
, struct veth_config
*cfg
);
329 int system_veth_del(struct device
*veth
);
331 int system_vlan_add(struct device
*dev
, int id
);
332 int system_vlan_del(struct device
*dev
);
334 int system_vlandev_add(struct device
*vlandev
, struct device
*dev
, struct vlandev_config
*cfg
);
335 int system_vlandev_del(struct device
*vlandev
);
337 void system_if_get_settings(struct device
*dev
, struct device_settings
*s
);
338 void system_if_clear_state(struct device
*dev
);
339 int system_if_up(struct device
*dev
);
340 int system_if_down(struct device
*dev
);
341 int system_if_check(struct device
*dev
);
342 int system_if_resolve(struct device
*dev
);
344 int system_if_dump_info(struct device
*dev
, struct blob_buf
*b
);
345 int system_if_dump_stats(struct device
*dev
, struct blob_buf
*b
);
346 struct device
*system_if_get_parent(struct device
*dev
);
347 bool system_if_force_external(const char *ifname
);
348 void system_if_apply_settings(struct device
*dev
, struct device_settings
*s
,
349 uint64_t apply_mask
);
351 int system_add_address(struct device
*dev
, struct device_addr
*addr
);
352 int system_del_address(struct device
*dev
, struct device_addr
*addr
);
354 int system_add_route(struct device
*dev
, struct device_route
*route
);
355 int system_del_route(struct device
*dev
, struct device_route
*route
);
356 int system_flush_routes(void);
358 int system_add_neighbor(struct device
*dev
, struct device_neighbor
* neighbor
);
359 int system_del_neighbor(struct device
*dev
, struct device_neighbor
* neighbor
);
361 bool system_resolve_rt_type(const char *type
, unsigned int *id
);
362 bool system_resolve_rt_proto(const char *type
, unsigned int *id
);
363 bool system_resolve_rt_table(const char *name
, unsigned int *id
);
364 bool system_is_default_rt_table(unsigned int id
);
365 bool system_resolve_rpfilter(const char *filter
, unsigned int *id
);
367 int system_del_ip_tunnel(const struct device
*dev
);
368 int system_add_ip_tunnel(const struct device
*dev
, struct blob_attr
*attr
);
370 int system_add_iprule(struct iprule
*rule
);
371 int system_del_iprule(struct iprule
*rule
);
372 int system_flush_iprules(void);
374 bool system_resolve_iprule_action(const char *action
, unsigned int *id
);
376 time_t system_get_rtime(void);
378 void system_fd_set_cloexec(int fd
);
380 int system_update_ipv6_mtu(struct device
*dev
, int mtu
);
382 int system_link_netns_move(struct device
*dev
, const pid_t target_ns
, const char *target_ifname
);
383 int system_netns_open(const pid_t target_ns
);
384 int system_netns_set(int netns_fd
);