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_DEVICE_H
15 #define __NETIFD_DEVICE_H
17 #include <libubox/avl.h>
18 #include <libubox/safe_list.h>
19 #include <libubox/kvlist.h>
20 #include <netinet/in.h>
25 struct device_hotplug_ops
;
29 typedef int (*device_state_cb
)(struct device
*, bool up
);
44 DEV_ATTR_NEIGHREACHABLETIME
,
45 DEV_ATTR_DADTRANSMITS
,
46 DEV_ATTR_MULTICAST_TO_UNICAST
,
47 DEV_ATTR_MULTICAST_ROUTER
,
48 DEV_ATTR_MULTICAST_FAST_LEAVE
,
51 DEV_ATTR_UNICAST_FLOOD
,
52 DEV_ATTR_NEIGHGCSTALETIME
,
53 DEV_ATTR_SENDREDIRECTS
,
54 DEV_ATTR_NEIGHLOCKTIME
,
56 DEV_ATTR_IP6SEGMENTROUTING
,
57 DEV_ATTR_DROP_V4_UNICAST_IN_L2_MULTICAST
,
58 DEV_ATTR_DROP_V6_UNICAST_IN_L2_MULTICAST
,
59 DEV_ATTR_DROP_GRATUITOUS_ARP
,
60 DEV_ATTR_DROP_UNSOLICITED_NA
,
66 enum dev_change_type
{
74 struct list_head list
;
77 bool bridge_capability
;
78 const char *name_prefix
;
80 const struct uci_blob_param_list
*config_params
;
82 struct device
*(*create
)(const char *name
, struct device_type
*devtype
,
83 struct blob_attr
*attr
);
84 void (*config_init
)(struct device
*);
85 enum dev_change_type (*reload
)(struct device
*, struct blob_attr
*);
86 void (*dump_info
)(struct device
*, struct blob_buf
*buf
);
87 void (*dump_stats
)(struct device
*, struct blob_buf
*buf
);
88 int (*check_state
)(struct device
*);
89 void (*free
)(struct device
*);
93 DEV_OPT_MTU
= (1 << 0),
94 DEV_OPT_MACADDR
= (1 << 1),
95 DEV_OPT_TXQUEUELEN
= (1 << 2),
96 DEV_OPT_IPV6
= (1 << 3),
97 DEV_OPT_PROMISC
= (1 << 4),
98 DEV_OPT_RPFILTER
= (1 << 5),
99 DEV_OPT_ACCEPTLOCAL
= (1 << 6),
100 DEV_OPT_IGMPVERSION
= (1 << 7),
101 DEV_OPT_MLDVERSION
= (1 << 8),
102 DEV_OPT_NEIGHREACHABLETIME
= (1 << 9),
103 DEV_OPT_DEFAULT_MACADDR
= (1 << 10),
104 DEV_OPT_AUTH
= (1 << 11),
105 DEV_OPT_MTU6
= (1 << 12),
106 DEV_OPT_DADTRANSMITS
= (1 << 13),
107 DEV_OPT_MULTICAST_TO_UNICAST
= (1 << 14),
108 DEV_OPT_MULTICAST_ROUTER
= (1 << 15),
109 DEV_OPT_MULTICAST
= (1 << 16),
110 DEV_OPT_LEARNING
= (1 << 17),
111 DEV_OPT_UNICAST_FLOOD
= (1 << 18),
112 DEV_OPT_NEIGHGCSTALETIME
= (1 << 19),
113 DEV_OPT_MULTICAST_FAST_LEAVE
= (1 << 20),
114 DEV_OPT_SENDREDIRECTS
= (1 << 21),
115 DEV_OPT_NEIGHLOCKTIME
= (1 << 22),
116 DEV_OPT_ISOLATE
= (1 << 23),
117 DEV_OPT_IP6SEGMENTROUTING
= (1 << 24),
118 DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
= (1 << 25),
119 DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
= (1 << 26),
120 DEV_OPT_DROP_GRATUITOUS_ARP
= (1 << 27),
121 DEV_OPT_DROP_UNSOLICITED_NA
= (1 << 28),
122 DEV_OPT_ARP_ACCEPT
= (1 << 29),
125 /* events broadcasted to all users of a device */
130 DEV_EVENT_UPDATE_IFNAME
,
131 DEV_EVENT_UPDATE_IFINDEX
,
142 /* Topology changed (i.e. bridge member added) */
143 DEV_EVENT_TOPO_CHANGE
,
149 * device dependency with callbacks
152 struct safe_list list
;
158 uint8_t ev_idx
[__DEV_EVENT_MAX
];
161 void (*cb
)(struct device_user
*, enum device_event
);
164 struct device_settings
{
166 unsigned int valid_flags
;
169 unsigned int txqueuelen
;
173 unsigned int rpfilter
;
175 unsigned int igmpversion
;
176 unsigned int mldversion
;
177 unsigned int neigh4reachabletime
;
178 unsigned int neigh6reachabletime
;
179 unsigned int neigh4gcstaletime
;
180 unsigned int neigh6gcstaletime
;
182 unsigned int dadtransmits
;
183 bool multicast_to_unicast
;
184 unsigned int multicast_router
;
185 bool multicast_fast_leave
;
190 bool ip6segmentrouting
;
192 bool drop_v4_unicast_in_l2_multicast
;
193 bool drop_v6_unicast_in_l2_multicast
;
194 bool drop_gratuitous_arp
;
195 bool drop_unsolicited_na
;
201 * link layer device. typically represents a linux network device.
202 * can be used to support VLANs as well
205 struct device_type
*type
;
208 struct safe_list users
;
209 struct safe_list aliases
;
211 struct vlist_tree vlans
;
212 struct kvlist vlan_aliases
;
214 char ifname
[IFNAMSIZ
+ 1];
217 struct blob_attr
*config
;
224 /* DEV_EVENT_LINK_UP */
238 bool wireless_isolate
;
240 struct interface
*config_iface
;
242 /* set interface up or down */
243 device_state_cb set_state
;
245 const struct device_hotplug_ops
*hotplug_ops
;
247 struct device_user parent
;
249 struct device_settings orig_settings
;
250 struct device_settings settings
;
253 struct device_hotplug_ops
{
254 int (*prepare
)(struct device
*dev
, struct device
**bridge_dev
);
255 int (*add
)(struct device
*main
, struct device
*member
, struct blob_attr
*vlan
);
256 int (*del
)(struct device
*main
, struct device
*member
);
259 enum bridge_vlan_flags
{
260 BRVLAN_F_SELF
= (1 << 0),
261 BRVLAN_F_PVID
= (1 << 1),
262 BRVLAN_F_UNTAGGED
= (1 << 2),
265 struct bridge_vlan_port
{
271 struct vlist_node node
;
273 struct bridge_vlan_port
*ports
;
276 struct list_head hotplug_ports
;
282 extern const struct uci_blob_param_list device_attr_list
;
283 extern struct device_type simple_device_type
;
284 extern struct device_type tunnel_device_type
;
286 void device_lock(void);
287 void device_unlock(void);
289 void device_vlan_update(bool done
);
291 int device_type_add(struct device_type
*devtype
);
292 struct device_type
*device_type_get(const char *tname
);
293 struct device
*device_create(const char *name
, struct device_type
*type
,
294 struct blob_attr
*config
);
295 void device_merge_settings(struct device
*dev
, struct device_settings
*n
);
296 void device_init_settings(struct device
*dev
, struct blob_attr
**tb
);
297 void device_init_pending(void);
300 device_apply_config(struct device
*dev
, struct device_type
*type
,
301 struct blob_attr
*config
);
303 void device_reset_config(void);
304 void device_reset_old(void);
306 int device_init_virtual(struct device
*dev
, struct device_type
*type
, const char *name
);
307 int device_init(struct device
*dev
, struct device_type
*type
, const char *ifname
);
308 void device_cleanup(struct device
*dev
);
309 struct device
*device_find(const char *name
);
310 struct device
*device_get(const char *name
, int create
);
311 void device_add_user(struct device_user
*dep
, struct device
*dev
);
312 void device_remove_user(struct device_user
*dep
);
313 void device_broadcast_event(struct device
*dev
, enum device_event ev
);
315 void device_set_present(struct device
*dev
, bool state
);
316 void device_set_link(struct device
*dev
, bool state
);
317 void device_set_ifindex(struct device
*dev
, int ifindex
);
318 int device_set_ifname(struct device
*dev
, const char *name
);
319 void device_refresh_present(struct device
*dev
);
320 int device_claim(struct device_user
*dep
);
321 void device_release(struct device_user
*dep
);
322 int device_check_state(struct device
*dev
);
323 void device_dump_status(struct blob_buf
*b
, struct device
*dev
);
325 void device_free_unused(struct device
*dev
);
327 struct device
*get_vlan_device_chain(const char *ifname
, bool create
);
328 void alias_notify_device(const char *name
, struct device
*dev
);
329 struct device
*device_alias_get(const char *name
);
331 void device_set_auth_status(struct device
*dev
, bool value
);
334 device_set_deferred(struct device
*dev
, bool value
)
336 dev
->deferred
= value
;
337 device_refresh_present(dev
);
341 device_set_disabled(struct device
*dev
, bool value
)
343 dev
->disabled
= value
;
344 device_refresh_present(dev
);
348 device_link_active(struct device
*dev
)
350 if (dev
->settings
.auth
&& !dev
->auth_status
)
353 return dev
->link_active
;
356 bool device_check_ip6segmentrouting(void);