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 (*vlan_update
)(struct device
*);
87 void (*dump_info
)(struct device
*, struct blob_buf
*buf
);
88 void (*dump_stats
)(struct device
*, struct blob_buf
*buf
);
89 int (*check_state
)(struct device
*);
90 void (*free
)(struct device
*);
94 DEV_OPT_MTU
= (1 << 0),
95 DEV_OPT_MACADDR
= (1 << 1),
96 DEV_OPT_TXQUEUELEN
= (1 << 2),
97 DEV_OPT_IPV6
= (1 << 3),
98 DEV_OPT_PROMISC
= (1 << 4),
99 DEV_OPT_RPFILTER
= (1 << 5),
100 DEV_OPT_ACCEPTLOCAL
= (1 << 6),
101 DEV_OPT_IGMPVERSION
= (1 << 7),
102 DEV_OPT_MLDVERSION
= (1 << 8),
103 DEV_OPT_NEIGHREACHABLETIME
= (1 << 9),
104 DEV_OPT_DEFAULT_MACADDR
= (1 << 10),
105 DEV_OPT_AUTH
= (1 << 11),
106 DEV_OPT_MTU6
= (1 << 12),
107 DEV_OPT_DADTRANSMITS
= (1 << 13),
108 DEV_OPT_MULTICAST_TO_UNICAST
= (1 << 14),
109 DEV_OPT_MULTICAST_ROUTER
= (1 << 15),
110 DEV_OPT_MULTICAST
= (1 << 16),
111 DEV_OPT_LEARNING
= (1 << 17),
112 DEV_OPT_UNICAST_FLOOD
= (1 << 18),
113 DEV_OPT_NEIGHGCSTALETIME
= (1 << 19),
114 DEV_OPT_MULTICAST_FAST_LEAVE
= (1 << 20),
115 DEV_OPT_SENDREDIRECTS
= (1 << 21),
116 DEV_OPT_NEIGHLOCKTIME
= (1 << 22),
117 DEV_OPT_ISOLATE
= (1 << 23),
118 DEV_OPT_IP6SEGMENTROUTING
= (1 << 24),
119 DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
= (1 << 25),
120 DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
= (1 << 26),
121 DEV_OPT_DROP_GRATUITOUS_ARP
= (1 << 27),
122 DEV_OPT_DROP_UNSOLICITED_NA
= (1 << 28),
123 DEV_OPT_ARP_ACCEPT
= (1 << 29),
126 /* events broadcasted to all users of a device */
131 DEV_EVENT_UPDATE_IFNAME
,
132 DEV_EVENT_UPDATE_IFINDEX
,
143 /* Topology changed (i.e. bridge member added) */
144 DEV_EVENT_TOPO_CHANGE
,
150 * device dependency with callbacks
153 struct safe_list list
;
159 uint8_t ev_idx
[__DEV_EVENT_MAX
];
162 void (*cb
)(struct device_user
*, enum device_event
);
165 struct device_settings
{
167 unsigned int valid_flags
;
170 unsigned int txqueuelen
;
174 unsigned int rpfilter
;
176 unsigned int igmpversion
;
177 unsigned int mldversion
;
178 unsigned int neigh4reachabletime
;
179 unsigned int neigh6reachabletime
;
180 unsigned int neigh4gcstaletime
;
181 unsigned int neigh6gcstaletime
;
183 unsigned int dadtransmits
;
184 bool multicast_to_unicast
;
185 unsigned int multicast_router
;
186 bool multicast_fast_leave
;
191 bool ip6segmentrouting
;
193 bool drop_v4_unicast_in_l2_multicast
;
194 bool drop_v6_unicast_in_l2_multicast
;
195 bool drop_gratuitous_arp
;
196 bool drop_unsolicited_na
;
202 * link layer device. typically represents a linux network device.
203 * can be used to support VLANs as well
206 struct device_type
*type
;
209 struct safe_list users
;
210 struct safe_list aliases
;
212 struct vlist_tree vlans
;
213 struct kvlist vlan_aliases
;
215 char ifname
[IFNAMSIZ
+ 1];
218 struct blob_attr
*config
;
225 /* DEV_EVENT_LINK_UP */
239 bool wireless_isolate
;
241 struct interface
*config_iface
;
243 /* set interface up or down */
244 device_state_cb set_state
;
246 const struct device_hotplug_ops
*hotplug_ops
;
248 struct device_user parent
;
250 struct device_settings orig_settings
;
251 struct device_settings settings
;
254 struct device_hotplug_ops
{
255 int (*prepare
)(struct device
*dev
, struct device
**bridge_dev
);
256 int (*add
)(struct device
*main
, struct device
*member
, struct blob_attr
*vlan
);
257 int (*del
)(struct device
*main
, struct device
*member
, struct blob_attr
*vlan
);
260 enum bridge_vlan_flags
{
261 BRVLAN_F_SELF
= (1 << 0),
262 BRVLAN_F_PVID
= (1 << 1),
263 BRVLAN_F_UNTAGGED
= (1 << 2),
266 struct bridge_vlan_port
{
272 struct vlist_node node
;
274 struct bridge_vlan_port
*ports
;
277 struct list_head hotplug_ports
;
284 extern const struct uci_blob_param_list device_attr_list
;
285 extern struct device_type simple_device_type
;
286 extern struct device_type tunnel_device_type
;
288 void device_lock(void);
289 void device_unlock(void);
291 void device_vlan_update(bool done
);
293 int device_type_add(struct device_type
*devtype
);
294 struct device_type
*device_type_get(const char *tname
);
295 struct device
*device_create(const char *name
, struct device_type
*type
,
296 struct blob_attr
*config
);
297 void device_merge_settings(struct device
*dev
, struct device_settings
*n
);
298 void device_init_settings(struct device
*dev
, struct blob_attr
**tb
);
299 void device_init_pending(void);
302 device_apply_config(struct device
*dev
, struct device_type
*type
,
303 struct blob_attr
*config
);
305 void device_reset_config(void);
306 void device_reset_old(void);
308 int device_init_virtual(struct device
*dev
, struct device_type
*type
, const char *name
);
309 int device_init(struct device
*dev
, struct device_type
*type
, const char *ifname
);
310 void device_cleanup(struct device
*dev
);
311 struct device
*device_find(const char *name
);
313 struct device
*__device_get(const char *name
, int create
, bool check_vlan
);
314 static inline struct device
*device_get(const char *name
, int create
)
316 return __device_get(name
, create
, true);
319 void device_add_user(struct device_user
*dep
, struct device
*dev
);
320 void device_remove_user(struct device_user
*dep
);
321 void device_broadcast_event(struct device
*dev
, enum device_event ev
);
323 void device_set_present(struct device
*dev
, bool state
);
324 void device_set_link(struct device
*dev
, bool state
);
325 void device_set_ifindex(struct device
*dev
, int ifindex
);
326 int device_set_ifname(struct device
*dev
, const char *name
);
327 void device_refresh_present(struct device
*dev
);
328 int device_claim(struct device_user
*dep
);
329 void device_release(struct device_user
*dep
);
330 int device_check_state(struct device
*dev
);
331 void device_dump_status(struct blob_buf
*b
, struct device
*dev
);
333 void device_free_unused(struct device
*dev
);
335 struct device
*get_vlan_device_chain(const char *ifname
, int create
);
336 void alias_notify_device(const char *name
, struct device
*dev
);
337 struct device
*device_alias_get(const char *name
);
339 void device_set_auth_status(struct device
*dev
, bool value
);
342 device_set_deferred(struct device
*dev
, bool value
)
344 dev
->deferred
= value
;
345 device_refresh_present(dev
);
349 device_set_disabled(struct device
*dev
, bool value
)
351 dev
->disabled
= value
;
352 device_refresh_present(dev
);
356 device_link_active(struct device
*dev
)
358 if (dev
->settings
.auth
&& !dev
->auth_status
)
361 return dev
->link_active
;
364 bool device_check_ip6segmentrouting(void);
365 void device_hotplug_event(const char *name
, bool add
);