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.
19 #include <sys/types.h>
20 #include <sys/socket.h>
22 #include <libubox/list.h>
30 static struct list_head devtypes
= LIST_HEAD_INIT(devtypes
);
31 static struct avl_tree devices
;
32 static struct blob_buf b
;
34 static const struct blobmsg_policy dev_attrs
[__DEV_ATTR_MAX
] = {
35 [DEV_ATTR_TYPE
] = { .name
= "type", .type
= BLOBMSG_TYPE_STRING
},
36 [DEV_ATTR_MTU
] = { .name
= "mtu", .type
= BLOBMSG_TYPE_INT32
},
37 [DEV_ATTR_MTU6
] = { .name
= "mtu6", .type
= BLOBMSG_TYPE_INT32
},
38 [DEV_ATTR_MACADDR
] = { .name
= "macaddr", .type
= BLOBMSG_TYPE_STRING
},
39 [DEV_ATTR_TXQUEUELEN
] = { .name
= "txqueuelen", .type
= BLOBMSG_TYPE_INT32
},
40 [DEV_ATTR_ENABLED
] = { .name
= "enabled", .type
= BLOBMSG_TYPE_BOOL
},
41 [DEV_ATTR_IPV6
] = { .name
= "ipv6", .type
= BLOBMSG_TYPE_BOOL
},
42 [DEV_ATTR_IP6SEGMENTROUTING
] = { .name
= "ip6segmentrouting", .type
= BLOBMSG_TYPE_BOOL
},
43 [DEV_ATTR_PROMISC
] = { .name
= "promisc", .type
= BLOBMSG_TYPE_BOOL
},
44 [DEV_ATTR_RPFILTER
] = { .name
= "rpfilter", .type
= BLOBMSG_TYPE_STRING
},
45 [DEV_ATTR_ACCEPTLOCAL
] = { .name
= "acceptlocal", .type
= BLOBMSG_TYPE_BOOL
},
46 [DEV_ATTR_IGMPVERSION
] = { .name
= "igmpversion", .type
= BLOBMSG_TYPE_INT32
},
47 [DEV_ATTR_MLDVERSION
] = { .name
= "mldversion", .type
= BLOBMSG_TYPE_INT32
},
48 [DEV_ATTR_NEIGHREACHABLETIME
] = { .name
= "neighreachabletime", .type
= BLOBMSG_TYPE_INT32
},
49 [DEV_ATTR_NEIGHGCSTALETIME
] = { .name
= "neighgcstaletime", .type
= BLOBMSG_TYPE_INT32
},
50 [DEV_ATTR_DADTRANSMITS
] = { .name
= "dadtransmits", .type
= BLOBMSG_TYPE_INT32
},
51 [DEV_ATTR_MULTICAST_TO_UNICAST
] = { .name
= "multicast_to_unicast", .type
= BLOBMSG_TYPE_BOOL
},
52 [DEV_ATTR_MULTICAST_ROUTER
] = { .name
= "multicast_router", .type
= BLOBMSG_TYPE_INT32
},
53 [DEV_ATTR_MULTICAST_FAST_LEAVE
] = { .name
= "multicast_fast_leave", . type
= BLOBMSG_TYPE_BOOL
},
54 [DEV_ATTR_MULTICAST
] = { .name
="multicast", .type
= BLOBMSG_TYPE_BOOL
},
55 [DEV_ATTR_LEARNING
] = { .name
="learning", .type
= BLOBMSG_TYPE_BOOL
},
56 [DEV_ATTR_UNICAST_FLOOD
] = { .name
="unicast_flood", .type
= BLOBMSG_TYPE_BOOL
},
57 [DEV_ATTR_SENDREDIRECTS
] = { .name
= "sendredirects", .type
= BLOBMSG_TYPE_BOOL
},
58 [DEV_ATTR_NEIGHLOCKTIME
] = { .name
= "neighlocktime", .type
= BLOBMSG_TYPE_INT32
},
59 [DEV_ATTR_ISOLATE
] = { .name
= "isolate", .type
= BLOBMSG_TYPE_BOOL
},
60 [DEV_ATTR_DROP_V4_UNICAST_IN_L2_MULTICAST
] = { .name
= "drop_v4_unicast_in_l2_multicast", .type
= BLOBMSG_TYPE_BOOL
},
61 [DEV_ATTR_DROP_V6_UNICAST_IN_L2_MULTICAST
] = { .name
= "drop_v6_unicast_in_l2_multicast", .type
= BLOBMSG_TYPE_BOOL
},
62 [DEV_ATTR_DROP_GRATUITOUS_ARP
] = { .name
= "drop_gratuitous_arp", .type
= BLOBMSG_TYPE_BOOL
},
63 [DEV_ATTR_DROP_UNSOLICITED_NA
] = { .name
= "drop_unsolicited_na", .type
= BLOBMSG_TYPE_BOOL
},
64 [DEV_ATTR_ARP_ACCEPT
] = { .name
= "arp_accept", .type
= BLOBMSG_TYPE_BOOL
},
65 [DEV_ATTR_AUTH
] = { .name
= "auth", .type
= BLOBMSG_TYPE_BOOL
},
66 [DEV_ATTR_AUTH_VLAN
] = { .name
= "auth_vlan", BLOBMSG_TYPE_ARRAY
},
67 [DEV_ATTR_SPEED
] = { .name
= "speed", .type
= BLOBMSG_TYPE_INT32
},
68 [DEV_ATTR_DUPLEX
] = { .name
= "duplex", .type
= BLOBMSG_TYPE_BOOL
},
69 [DEV_ATTR_VLAN
] = { .name
= "vlan", .type
= BLOBMSG_TYPE_ARRAY
},
70 [DEV_ATTR_PAUSE
] = { .name
= "pause", .type
= BLOBMSG_TYPE_BOOL
},
71 [DEV_ATTR_ASYM_PAUSE
] = { .name
= "asym_pause", .type
= BLOBMSG_TYPE_BOOL
},
72 [DEV_ATTR_RXPAUSE
] = { .name
= "rxpause", .type
= BLOBMSG_TYPE_BOOL
},
73 [DEV_ATTR_TXPAUSE
] = { .name
= "txpause", .type
= BLOBMSG_TYPE_BOOL
},
74 [DEV_ATTR_AUTONEG
] = { .name
= "autoneg", .type
= BLOBMSG_TYPE_BOOL
},
77 const struct uci_blob_param_list device_attr_list
= {
78 .n_params
= __DEV_ATTR_MAX
,
82 static int __devlock
= 0;
84 int device_type_add(struct device_type
*devtype
)
86 if (device_type_get(devtype
->name
)) {
87 netifd_log_message(L_WARNING
, "Device handler '%s' already exists\n",
92 netifd_log_message(L_NOTICE
, "Added device handler type: %s\n",
95 list_add(&devtype
->list
, &devtypes
);
100 device_type_get(const char *tname
)
102 struct device_type
*cur
;
104 list_for_each_entry(cur
, &devtypes
, list
)
105 if (!strcmp(cur
->name
, tname
))
111 static int device_vlan_len(struct kvlist
*kv
, const void *data
)
113 return sizeof(unsigned int);
116 void device_vlan_update(bool done
)
120 avl_for_each_element(&devices
, dev
, avl
) {
121 if (!dev
->vlans
.update
)
125 if (dev
->vlan_aliases
.get_len
)
126 kvlist_free(&dev
->vlan_aliases
);
128 kvlist_init(&dev
->vlan_aliases
, device_vlan_len
);
129 vlist_update(&dev
->vlans
);
131 vlist_flush(&dev
->vlans
);
133 if (dev
->type
->vlan_update
)
134 dev
->type
->vlan_update(dev
);
139 void device_stp_init(void)
143 avl_for_each_element(&devices
, dev
, avl
) {
144 if (!dev
->type
->stp_init
)
147 dev
->type
->stp_init(dev
);
151 static int set_device_state(struct device
*dev
, bool state
)
154 /* Get ifindex for all devices being enabled so a valid */
155 /* ifindex is in place avoiding possible race conditions */
156 device_set_ifindex(dev
, system_if_resolve(dev
));
160 system_if_get_settings(dev
, &dev
->orig_settings
);
161 /* Only keep orig settings based on what needs to be set */
162 dev
->orig_settings
.valid_flags
= dev
->orig_settings
.flags
;
163 dev
->orig_settings
.flags
&= dev
->settings
.flags
;
164 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
169 system_if_apply_settings(dev
, &dev
->orig_settings
, dev
->orig_settings
.flags
);
176 simple_device_set_state(struct device
*dev
, bool state
)
181 pdev
= dev
->parent
.dev
;
182 if (state
&& !pdev
) {
183 pdev
= system_if_get_parent(dev
);
185 device_add_user(&dev
->parent
, pdev
);
190 ret
= device_claim(&dev
->parent
);
192 device_release(&dev
->parent
);
197 return set_device_state(dev
, state
);
200 static struct device
*
201 simple_device_create(const char *name
, struct device_type
*devtype
,
202 struct blob_attr
*attr
)
204 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
205 struct device
*dev
= NULL
;
207 /* device type is unused for simple devices */
210 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
, blob_data(attr
), blob_len(attr
));
211 dev
= device_get(name
, true);
215 dev
->set_state
= simple_device_set_state
;
216 device_init_settings(dev
, tb
);
221 static void simple_device_free(struct device
*dev
)
224 device_remove_user(&dev
->parent
);
228 struct device_type simple_device_type
= {
229 .name
= "Network device",
230 .config_params
= &device_attr_list
,
232 .create
= simple_device_create
,
233 .check_state
= system_if_check
,
234 .free
= simple_device_free
,
238 device_merge_settings(struct device
*dev
, struct device_settings
*n
)
240 struct device_settings
*os
= &dev
->orig_settings
;
241 struct device_settings
*s
= &dev
->settings
;
243 memset(n
, 0, sizeof(*n
));
244 n
->mtu
= s
->flags
& DEV_OPT_MTU
? s
->mtu
: os
->mtu
;
245 n
->mtu6
= s
->flags
& DEV_OPT_MTU6
? s
->mtu6
: os
->mtu6
;
246 n
->txqueuelen
= s
->flags
& DEV_OPT_TXQUEUELEN
?
247 s
->txqueuelen
: os
->txqueuelen
;
249 (s
->flags
& (DEV_OPT_MACADDR
|DEV_OPT_DEFAULT_MACADDR
) ? s
->macaddr
: os
->macaddr
),
251 n
->ipv6
= s
->flags
& DEV_OPT_IPV6
? s
->ipv6
: os
->ipv6
;
252 n
->ip6segmentrouting
= s
->flags
& DEV_OPT_IP6SEGMENTROUTING
? s
->ip6segmentrouting
: os
->ip6segmentrouting
;
253 n
->promisc
= s
->flags
& DEV_OPT_PROMISC
? s
->promisc
: os
->promisc
;
254 n
->rpfilter
= s
->flags
& DEV_OPT_RPFILTER
? s
->rpfilter
: os
->rpfilter
;
255 n
->acceptlocal
= s
->flags
& DEV_OPT_ACCEPTLOCAL
? s
->acceptlocal
: os
->acceptlocal
;
256 n
->igmpversion
= s
->flags
& DEV_OPT_IGMPVERSION
? s
->igmpversion
: os
->igmpversion
;
257 n
->mldversion
= s
->flags
& DEV_OPT_MLDVERSION
? s
->mldversion
: os
->mldversion
;
258 n
->neigh4reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
259 s
->neigh4reachabletime
: os
->neigh4reachabletime
;
260 n
->neigh6reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
261 s
->neigh6reachabletime
: os
->neigh6reachabletime
;
262 n
->neigh4gcstaletime
= s
->flags
& DEV_OPT_NEIGHGCSTALETIME
?
263 s
->neigh4gcstaletime
: os
->neigh4gcstaletime
;
264 n
->neigh6gcstaletime
= s
->flags
& DEV_OPT_NEIGHGCSTALETIME
?
265 s
->neigh6gcstaletime
: os
->neigh6gcstaletime
;
266 n
->neigh4locktime
= s
->flags
& DEV_OPT_NEIGHLOCKTIME
?
267 s
->neigh4locktime
: os
->neigh4locktime
;
268 n
->dadtransmits
= s
->flags
& DEV_OPT_DADTRANSMITS
?
269 s
->dadtransmits
: os
->dadtransmits
;
270 n
->multicast
= s
->flags
& DEV_OPT_MULTICAST
?
271 s
->multicast
: os
->multicast
;
272 n
->multicast_to_unicast
= s
->multicast_to_unicast
;
273 n
->multicast_router
= s
->multicast_router
;
274 n
->multicast_fast_leave
= s
->multicast_fast_leave
;
275 n
->learning
= s
->learning
;
276 n
->unicast_flood
= s
->unicast_flood
;
277 n
->sendredirects
= s
->flags
& DEV_OPT_SENDREDIRECTS
?
278 s
->sendredirects
: os
->sendredirects
;
279 n
->drop_v4_unicast_in_l2_multicast
= s
->flags
& DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
?
280 s
->drop_v4_unicast_in_l2_multicast
: os
->drop_v4_unicast_in_l2_multicast
;
281 n
->drop_v6_unicast_in_l2_multicast
= s
->flags
& DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
?
282 s
->drop_v6_unicast_in_l2_multicast
: os
->drop_v6_unicast_in_l2_multicast
;
283 n
->drop_gratuitous_arp
= s
->flags
& DEV_OPT_DROP_GRATUITOUS_ARP
?
284 s
->drop_gratuitous_arp
: os
->drop_gratuitous_arp
;
285 n
->drop_unsolicited_na
= s
->flags
& DEV_OPT_DROP_UNSOLICITED_NA
?
286 s
->drop_unsolicited_na
: os
->drop_unsolicited_na
;
287 n
->arp_accept
= s
->flags
& DEV_OPT_ARP_ACCEPT
?
288 s
->arp_accept
: os
->arp_accept
;
289 n
->auth
= s
->flags
& DEV_OPT_AUTH
? s
->auth
: os
->auth
;
290 n
->speed
= s
->flags
& DEV_OPT_SPEED
? s
->speed
: os
->speed
;
291 n
->duplex
= s
->flags
& DEV_OPT_DUPLEX
? s
->duplex
: os
->duplex
;
292 n
->pause
= s
->flags
& DEV_OPT_PAUSE
? s
->pause
: os
->pause
;
293 n
->asym_pause
= s
->flags
& DEV_OPT_ASYM_PAUSE
? s
->asym_pause
: os
->asym_pause
;
294 n
->rxpause
= s
->flags
& DEV_OPT_RXPAUSE
? s
->rxpause
: os
->rxpause
;
295 n
->txpause
= s
->flags
& DEV_OPT_TXPAUSE
? s
->txpause
: os
->txpause
;
296 n
->autoneg
= s
->flags
& DEV_OPT_AUTONEG
? s
->autoneg
: os
->autoneg
;
297 n
->flags
= s
->flags
| os
->flags
| os
->valid_flags
;
300 static bool device_fill_vlan_range(struct device_vlan_range
*r
, const char *val
)
302 unsigned long cur_start
, cur_end
;
305 cur_start
= strtoul(val
, &sep
, 0);
309 cur_end
= strtoul(sep
+ 1, &sep
, 0);
310 if (*sep
|| cur_end
< cur_start
)
313 r
->start
= cur_start
;
320 device_set_extra_vlans(struct device
*dev
, struct blob_attr
*data
)
322 struct blob_attr
*cur
;
326 dev
->n_extra_vlan
= 0;
330 n_vlans
= blobmsg_check_array(data
, BLOBMSG_TYPE_STRING
);
334 dev
->extra_vlan
= realloc(dev
->extra_vlan
, n_vlans
* sizeof(*dev
->extra_vlan
));
335 blobmsg_for_each_attr(cur
, data
, rem
)
336 if (device_fill_vlan_range(&dev
->extra_vlan
[dev
->n_extra_vlan
],
337 blobmsg_get_string(cur
)))
342 device_init_settings(struct device
*dev
, struct blob_attr
**tb
)
344 struct device_settings
*s
= &dev
->settings
;
345 struct blob_attr
*cur
;
346 struct ether_addr
*ea
;
347 bool disabled
= false;
350 if ((cur
= tb
[DEV_ATTR_ENABLED
]))
351 disabled
= !blobmsg_get_bool(cur
);
353 if ((cur
= tb
[DEV_ATTR_MTU
]) && blobmsg_get_u32(cur
) >= 68) {
354 s
->mtu
= blobmsg_get_u32(cur
);
355 s
->flags
|= DEV_OPT_MTU
;
358 if ((cur
= tb
[DEV_ATTR_MTU6
]) && blobmsg_get_u32(cur
) >= 1280) {
359 s
->mtu6
= blobmsg_get_u32(cur
);
360 s
->flags
|= DEV_OPT_MTU6
;
363 if ((cur
= tb
[DEV_ATTR_TXQUEUELEN
])) {
364 s
->txqueuelen
= blobmsg_get_u32(cur
);
365 s
->flags
|= DEV_OPT_TXQUEUELEN
;
368 if ((cur
= tb
[DEV_ATTR_MACADDR
])) {
369 ea
= ether_aton(blobmsg_data(cur
));
371 memcpy(s
->macaddr
, ea
, 6);
372 s
->flags
|= DEV_OPT_MACADDR
;
376 if ((cur
= tb
[DEV_ATTR_IPV6
])) {
377 s
->ipv6
= blobmsg_get_bool(cur
);
378 s
->flags
|= DEV_OPT_IPV6
;
381 if ((cur
= tb
[DEV_ATTR_IP6SEGMENTROUTING
])) {
382 s
->ip6segmentrouting
= blobmsg_get_bool(cur
);
383 s
->flags
|= DEV_OPT_IP6SEGMENTROUTING
;
386 if ((cur
= tb
[DEV_ATTR_PROMISC
])) {
387 s
->promisc
= blobmsg_get_bool(cur
);
388 s
->flags
|= DEV_OPT_PROMISC
;
391 if ((cur
= tb
[DEV_ATTR_RPFILTER
])) {
392 if (system_resolve_rpfilter(blobmsg_data(cur
), &s
->rpfilter
))
393 s
->flags
|= DEV_OPT_RPFILTER
;
395 DPRINTF("Failed to resolve rpfilter: %s\n", (char *) blobmsg_data(cur
));
398 if ((cur
= tb
[DEV_ATTR_ACCEPTLOCAL
])) {
399 s
->acceptlocal
= blobmsg_get_bool(cur
);
400 s
->flags
|= DEV_OPT_ACCEPTLOCAL
;
403 if ((cur
= tb
[DEV_ATTR_IGMPVERSION
])) {
404 s
->igmpversion
= blobmsg_get_u32(cur
);
405 if (s
->igmpversion
>= 1 && s
->igmpversion
<= 3)
406 s
->flags
|= DEV_OPT_IGMPVERSION
;
408 DPRINTF("Failed to resolve igmpversion: %d\n", blobmsg_get_u32(cur
));
411 if ((cur
= tb
[DEV_ATTR_MLDVERSION
])) {
412 s
->mldversion
= blobmsg_get_u32(cur
);
413 if (s
->mldversion
>= 1 && s
->mldversion
<= 2)
414 s
->flags
|= DEV_OPT_MLDVERSION
;
416 DPRINTF("Failed to resolve mldversion: %d\n", blobmsg_get_u32(cur
));
419 if ((cur
= tb
[DEV_ATTR_NEIGHREACHABLETIME
])) {
420 s
->neigh6reachabletime
= s
->neigh4reachabletime
= blobmsg_get_u32(cur
);
421 s
->flags
|= DEV_OPT_NEIGHREACHABLETIME
;
424 if ((cur
= tb
[DEV_ATTR_NEIGHGCSTALETIME
])) {
425 s
->neigh6gcstaletime
= s
->neigh4gcstaletime
= blobmsg_get_u32(cur
);
426 s
->flags
|= DEV_OPT_NEIGHGCSTALETIME
;
429 if ((cur
= tb
[DEV_ATTR_NEIGHLOCKTIME
])) {
430 s
->neigh4locktime
= blobmsg_get_u32(cur
);
431 s
->flags
|= DEV_OPT_NEIGHLOCKTIME
;
434 if ((cur
= tb
[DEV_ATTR_DADTRANSMITS
])) {
435 s
->dadtransmits
= blobmsg_get_u32(cur
);
436 s
->flags
|= DEV_OPT_DADTRANSMITS
;
439 if ((cur
= tb
[DEV_ATTR_MULTICAST_TO_UNICAST
])) {
440 s
->multicast_to_unicast
= blobmsg_get_bool(cur
);
441 s
->flags
|= DEV_OPT_MULTICAST_TO_UNICAST
;
444 if ((cur
= tb
[DEV_ATTR_MULTICAST_ROUTER
])) {
445 s
->multicast_router
= blobmsg_get_u32(cur
);
446 if (s
->multicast_router
<= 2)
447 s
->flags
|= DEV_OPT_MULTICAST_ROUTER
;
449 DPRINTF("Invalid value: %d - (Use 0: never, 1: learn, 2: always)\n", blobmsg_get_u32(cur
));
452 if ((cur
= tb
[DEV_ATTR_MULTICAST_FAST_LEAVE
])) {
453 s
->multicast_fast_leave
= blobmsg_get_bool(cur
);
454 s
->flags
|= DEV_OPT_MULTICAST_FAST_LEAVE
;
457 if ((cur
= tb
[DEV_ATTR_MULTICAST
])) {
458 s
->multicast
= blobmsg_get_bool(cur
);
459 s
->flags
|= DEV_OPT_MULTICAST
;
462 if ((cur
= tb
[DEV_ATTR_LEARNING
])) {
463 s
->learning
= blobmsg_get_bool(cur
);
464 s
->flags
|= DEV_OPT_LEARNING
;
467 if ((cur
= tb
[DEV_ATTR_UNICAST_FLOOD
])) {
468 s
->unicast_flood
= blobmsg_get_bool(cur
);
469 s
->flags
|= DEV_OPT_UNICAST_FLOOD
;
472 if ((cur
= tb
[DEV_ATTR_SENDREDIRECTS
])) {
473 s
->sendredirects
= blobmsg_get_bool(cur
);
474 s
->flags
|= DEV_OPT_SENDREDIRECTS
;
477 if ((cur
= tb
[DEV_ATTR_ISOLATE
])) {
478 s
->isolate
= blobmsg_get_bool(cur
);
479 s
->flags
|= DEV_OPT_ISOLATE
;
482 if ((cur
= tb
[DEV_ATTR_DROP_V4_UNICAST_IN_L2_MULTICAST
])) {
483 s
->drop_v4_unicast_in_l2_multicast
= blobmsg_get_bool(cur
);
484 s
->flags
|= DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
;
487 if ((cur
= tb
[DEV_ATTR_DROP_V6_UNICAST_IN_L2_MULTICAST
])) {
488 s
->drop_v6_unicast_in_l2_multicast
= blobmsg_get_bool(cur
);
489 s
->flags
|= DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
;
492 if ((cur
= tb
[DEV_ATTR_DROP_GRATUITOUS_ARP
])) {
493 s
->drop_gratuitous_arp
= blobmsg_get_bool(cur
);
494 s
->flags
|= DEV_OPT_DROP_GRATUITOUS_ARP
;
497 if ((cur
= tb
[DEV_ATTR_DROP_UNSOLICITED_NA
])) {
498 s
->drop_unsolicited_na
= blobmsg_get_bool(cur
);
499 s
->flags
|= DEV_OPT_DROP_UNSOLICITED_NA
;
502 if ((cur
= tb
[DEV_ATTR_ARP_ACCEPT
])) {
503 s
->arp_accept
= blobmsg_get_bool(cur
);
504 s
->flags
|= DEV_OPT_ARP_ACCEPT
;
507 if ((cur
= tb
[DEV_ATTR_AUTH
])) {
508 s
->auth
= blobmsg_get_bool(cur
);
509 s
->flags
|= DEV_OPT_AUTH
;
512 if ((cur
= tb
[DEV_ATTR_SPEED
])) {
513 s
->speed
= blobmsg_get_u32(cur
);
514 s
->flags
|= DEV_OPT_SPEED
;
517 if ((cur
= tb
[DEV_ATTR_DUPLEX
])) {
518 s
->duplex
= blobmsg_get_bool(cur
);
519 s
->flags
|= DEV_OPT_DUPLEX
;
522 if ((cur
= tb
[DEV_ATTR_PAUSE
])) {
523 s
->pause
= blobmsg_get_bool(cur
);
524 s
->flags
|= DEV_OPT_PAUSE
;
527 if ((cur
= tb
[DEV_ATTR_ASYM_PAUSE
])) {
528 s
->asym_pause
= blobmsg_get_bool(cur
);
529 s
->flags
|= DEV_OPT_ASYM_PAUSE
;
532 if ((cur
= tb
[DEV_ATTR_RXPAUSE
])) {
533 s
->rxpause
= blobmsg_get_bool(cur
);
534 s
->flags
|= DEV_OPT_RXPAUSE
;
537 if ((cur
= tb
[DEV_ATTR_TXPAUSE
])) {
538 s
->txpause
= blobmsg_get_bool(cur
);
539 s
->flags
|= DEV_OPT_TXPAUSE
;
542 if ((cur
= tb
[DEV_ATTR_AUTONEG
])) {
543 s
->autoneg
= blobmsg_get_bool(cur
);
544 s
->flags
|= DEV_OPT_AUTONEG
;
547 cur
= tb
[DEV_ATTR_AUTH_VLAN
];
548 free(dev
->config_auth_vlans
);
549 dev
->config_auth_vlans
= cur
? blob_memdup(cur
) : NULL
;
551 device_set_extra_vlans(dev
, tb
[DEV_ATTR_VLAN
]);
552 device_set_disabled(dev
, disabled
);
555 static void __init
dev_init(void)
557 avl_init(&devices
, avl_strcmp
, true, NULL
);
560 static int device_release_cb(void *ctx
, struct safe_list
*list
)
562 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
564 if (!dep
->dev
|| !dep
->claimed
)
571 static int device_broadcast_cb(void *ctx
, struct safe_list
*list
)
573 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
576 /* device might have been removed by an earlier callback */
585 void device_broadcast_event(struct device
*dev
, enum device_event ev
)
587 static const char * const event_names
[] = {
588 [DEV_EVENT_ADD
] = "add",
589 [DEV_EVENT_REMOVE
] = "remove",
590 [DEV_EVENT_UP
] = "up",
591 [DEV_EVENT_DOWN
] = "down",
592 [DEV_EVENT_AUTH_UP
] = "auth_up",
593 [DEV_EVENT_LINK_UP
] = "link_up",
594 [DEV_EVENT_LINK_DOWN
] = "link_down",
595 [DEV_EVENT_TOPO_CHANGE
] = "topo_change",
599 safe_list_for_each(&dev
->aliases
, device_broadcast_cb
, &dev_ev
);
600 safe_list_for_each(&dev
->users
, device_broadcast_cb
, &dev_ev
);
602 if (ev
>= ARRAY_SIZE(event_names
) || !event_names
[ev
] || !dev
->ifname
[0])
605 blob_buf_init(&b
, 0);
606 blobmsg_add_string(&b
, "name", dev
->ifname
);
607 blobmsg_add_u8(&b
, "auth_status", dev
->auth_status
);
608 blobmsg_add_u8(&b
, "present", dev
->present
);
609 blobmsg_add_u8(&b
, "active", dev
->active
);
610 blobmsg_add_u8(&b
, "link_active", dev
->link_active
);
611 netifd_ubus_device_notify(event_names
[ev
], b
.head
, -1);
615 device_fill_default_settings(struct device
*dev
)
617 struct device_settings
*s
= &dev
->settings
;
618 struct ether_addr
*ea
;
620 if (!(s
->flags
& DEV_OPT_MACADDR
)) {
621 ea
= config_get_default_macaddr(dev
->ifname
);
623 memcpy(s
->macaddr
, ea
, 6);
624 s
->flags
|= DEV_OPT_DEFAULT_MACADDR
;
629 int device_claim(struct device_user
*dep
)
631 struct device
*dev
= dep
->dev
;
641 D(DEVICE
, "Claim %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
+ 1);
642 if (++dev
->active
!= 1)
645 device_broadcast_event(dev
, DEV_EVENT_SETUP
);
646 device_fill_default_settings(dev
);
648 /* Get ifindex for external claimed devices so a valid */
649 /* ifindex is in place avoiding possible race conditions */
650 device_set_ifindex(dev
, system_if_resolve(dev
));
654 system_if_get_settings(dev
, &dev
->orig_settings
);
656 ret
= dev
->set_state(dev
, true);
659 device_broadcast_event(dev
, DEV_EVENT_UP
);
661 D(DEVICE
, "claim %s %s failed: %d\n", dev
->type
->name
, dev
->ifname
, ret
);
663 dep
->claimed
= false;
669 void device_release(struct device_user
*dep
)
671 struct device
*dev
= dep
->dev
;
676 dep
->claimed
= false;
678 D(DEVICE
, "Release %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
);
679 assert(dev
->active
>= 0);
684 device_broadcast_event(dev
, DEV_EVENT_TEARDOWN
);
686 dev
->set_state(dev
, false);
691 device_broadcast_event(dev
, DEV_EVENT_DOWN
);
694 int device_check_state(struct device
*dev
)
696 if (!dev
->type
->check_state
)
697 return simple_device_type
.check_state(dev
);
699 return dev
->type
->check_state(dev
);
702 int device_init_virtual(struct device
*dev
, struct device_type
*type
, const char *name
)
707 D(DEVICE
, "Initialize device '%s'\n", name
? name
: "");
708 INIT_SAFE_LIST(&dev
->users
);
709 INIT_SAFE_LIST(&dev
->aliases
);
715 ret
= device_set_ifname(dev
, name
);
721 dev
->set_state
= set_device_state
;
726 int device_init(struct device
*dev
, struct device_type
*type
, const char *ifname
)
730 ret
= device_init_virtual(dev
, type
, ifname
);
734 dev
->avl
.key
= dev
->ifname
;
736 ret
= avl_insert(&devices
, &dev
->avl
);
740 system_if_clear_state(dev
);
745 static struct device
*
746 device_create_default(const char *name
, bool external
)
750 if (!external
&& system_if_force_external(name
))
753 D(DEVICE
, "Create simple device '%s'\n", name
);
754 dev
= calloc(1, sizeof(*dev
));
758 dev
->external
= external
;
759 dev
->set_state
= simple_device_set_state
;
761 if (device_init(dev
, &simple_device_type
, name
) < 0) {
767 dev
->default_config
= true;
769 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
771 device_check_state(dev
);
777 device_find(const char *name
)
781 return avl_find_element(&devices
, name
, dev
, avl
);
785 __device_get(const char *name
, int create
, bool check_vlan
)
789 dev
= avl_find_element(&devices
, name
, dev
, avl
);
791 if (!dev
&& check_vlan
&& strchr(name
, '.'))
792 return get_vlan_device_chain(name
, create
);
795 return device_alias_get(name
+ 1);
798 if (create
> 1 && !dev
->external
) {
799 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
800 dev
->external
= true;
801 device_set_present(dev
, true);
809 return device_create_default(name
, create
> 1);
813 device_delete(struct device
*dev
)
818 D(DEVICE
, "Delete device '%s' from list\n", dev
->ifname
);
819 avl_delete(&devices
, &dev
->avl
);
823 static int device_cleanup_cb(void *ctx
, struct safe_list
*list
)
825 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
827 dep
->cb(dep
, DEV_EVENT_REMOVE
);
833 void device_cleanup(struct device
*dev
)
835 D(DEVICE
, "Clean up device '%s'\n", dev
->ifname
);
836 safe_list_for_each(&dev
->users
, device_cleanup_cb
, NULL
);
837 safe_list_for_each(&dev
->aliases
, device_cleanup_cb
, NULL
);
841 static void __device_set_present(struct device
*dev
, bool state
)
843 if (dev
->present
== state
)
846 dev
->present
= state
;
847 device_broadcast_event(dev
, state
? DEV_EVENT_ADD
: DEV_EVENT_REMOVE
);
851 device_refresh_present(struct device
*dev
)
853 bool state
= dev
->sys_present
;
855 if (dev
->disabled
|| dev
->deferred
)
858 __device_set_present(dev
, state
);
862 device_set_auth_status(struct device
*dev
, bool value
, struct blob_attr
*vlans
)
866 else if (!blob_attr_equal(vlans
, dev
->auth_vlans
))
867 device_set_auth_status(dev
, false, NULL
);
869 free(dev
->auth_vlans
);
870 dev
->auth_vlans
= vlans
? blob_memdup(vlans
) : NULL
;
872 if (dev
->auth_status
== value
)
875 dev
->auth_status
= value
;
879 if (dev
->auth_status
) {
880 device_broadcast_event(dev
, DEV_EVENT_AUTH_UP
);
884 device_broadcast_event(dev
, DEV_EVENT_LINK_DOWN
);
885 if (!dev
->link_active
)
888 device_broadcast_event(dev
, DEV_EVENT_LINK_UP
);
891 void device_set_present(struct device
*dev
, bool state
)
893 if (dev
->sys_present
== state
)
896 D(DEVICE
, "%s '%s' %s present\n", dev
->type
->name
, dev
->ifname
, state
? "is now" : "is no longer" );
897 dev
->sys_present
= state
;
898 device_refresh_present(dev
);
900 safe_list_for_each(&dev
->users
, device_release_cb
, NULL
);
903 void device_set_link(struct device
*dev
, bool state
)
905 if (dev
->link_active
== state
)
908 netifd_log_message(L_NOTICE
, "%s '%s' link is %s\n", dev
->type
->name
, dev
->ifname
, state
? "up" : "down" );
910 dev
->link_active
= state
;
912 dev
->auth_status
= false;
913 device_broadcast_event(dev
, state
? DEV_EVENT_LINK_UP
: DEV_EVENT_LINK_DOWN
);
916 void device_set_ifindex(struct device
*dev
, int ifindex
)
918 if (dev
->ifindex
== ifindex
)
921 dev
->ifindex
= ifindex
;
922 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFINDEX
);
925 int device_set_ifname(struct device
*dev
, const char *name
)
929 if (!strcmp(dev
->ifname
, name
))
932 if (strlen(name
) > sizeof(dev
->ifname
) - 1)
936 avl_delete(&devices
, &dev
->avl
);
938 strcpy(dev
->ifname
, name
);
941 ret
= avl_insert(&devices
, &dev
->avl
);
944 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFNAME
);
949 static int device_refcount(struct device
*dev
)
951 struct list_head
*list
;
954 list_for_each(list
, &dev
->users
.list
)
957 list_for_each(list
, &dev
->aliases
.list
)
964 __device_add_user(struct device_user
*dep
, struct device
*dev
)
966 struct safe_list
*head
;
971 head
= &dev
->aliases
;
975 safe_list_add(&dep
->list
, head
);
976 D(DEVICE
, "Add user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
978 if (dep
->cb
&& dev
->present
) {
979 dep
->cb(dep
, DEV_EVENT_ADD
);
981 dep
->cb(dep
, DEV_EVENT_UP
);
983 if (dev
->link_active
)
984 dep
->cb(dep
, DEV_EVENT_LINK_UP
);
988 void device_add_user(struct device_user
*dep
, struct device
*dev
)
994 device_remove_user(dep
);
999 __device_add_user(dep
, dev
);
1003 device_free(struct device
*dev
)
1006 free(dev
->auth_vlans
);
1008 device_cleanup(dev
);
1009 free(dev
->config_auth_vlans
);
1010 free(dev
->extra_vlan
);
1011 dev
->type
->free(dev
);
1016 __device_free_unused(struct uloop_timeout
*timeout
)
1018 struct device
*dev
, *tmp
;
1020 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1021 if (!safe_list_empty(&dev
->users
) ||
1022 !safe_list_empty(&dev
->aliases
) ||
1023 dev
->current_config
)
1030 void device_free_unused(void)
1032 static struct uloop_timeout free_timer
= {
1033 .cb
= __device_free_unused
,
1036 uloop_timeout_set(&free_timer
, 1);
1039 void device_remove_user(struct device_user
*dep
)
1041 struct device
*dev
= dep
->dev
;
1046 dep
->hotplug
= false;
1048 device_release(dep
);
1050 safe_list_del(&dep
->list
);
1052 D(DEVICE
, "Remove user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
1053 device_free_unused();
1057 device_init_pending(void)
1059 struct device
*dev
, *tmp
;
1061 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1062 if (!dev
->config_pending
)
1065 dev
->type
->config_init(dev
);
1066 dev
->config_pending
= false;
1067 device_check_state(dev
);
1072 device_check_ip6segmentrouting(void)
1075 bool ip6segmentrouting
= false;
1077 avl_for_each_element(&devices
, dev
, avl
)
1078 ip6segmentrouting
|= dev
->settings
.ip6segmentrouting
;
1080 return ip6segmentrouting
;
1083 static enum dev_change_type
1084 device_set_config(struct device
*dev
, struct device_type
*type
,
1085 struct blob_attr
*attr
)
1087 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
1088 const struct uci_blob_param_list
*cfg
= type
->config_params
;
1090 if (type
!= dev
->type
)
1091 return DEV_CONFIG_RECREATE
;
1093 if (dev
->type
->reload
)
1094 return dev
->type
->reload(dev
, attr
);
1096 if (uci_blob_check_equal(dev
->config
, attr
, cfg
))
1097 return DEV_CONFIG_NO_CHANGE
;
1099 if (cfg
== &device_attr_list
) {
1100 memset(tb
, 0, sizeof(tb
));
1103 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
,
1104 blob_data(attr
), blob_len(attr
));
1106 device_init_settings(dev
, tb
);
1107 return DEV_CONFIG_RESTART
;
1109 return DEV_CONFIG_RECREATE
;
1112 enum dev_change_type
1113 device_apply_config(struct device
*dev
, struct device_type
*type
,
1114 struct blob_attr
*config
)
1116 enum dev_change_type change
;
1118 change
= device_set_config(dev
, type
, config
);
1119 if (dev
->external
) {
1120 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
1121 change
= DEV_CONFIG_APPLIED
;
1125 case DEV_CONFIG_RESTART
:
1126 case DEV_CONFIG_APPLIED
:
1127 D(DEVICE
, "Device '%s': config applied\n", dev
->ifname
);
1128 config
= blob_memdup(config
);
1130 dev
->config
= config
;
1131 if (change
== DEV_CONFIG_RESTART
&& dev
->present
) {
1134 device_set_present(dev
, false);
1135 if (dev
->active
&& !dev
->external
) {
1136 ret
= dev
->set_state(dev
, false);
1138 ret
= dev
->set_state(dev
, true);
1141 device_set_present(dev
, true);
1144 case DEV_CONFIG_NO_CHANGE
:
1145 D(DEVICE
, "Device '%s': no configuration change\n", dev
->ifname
);
1147 case DEV_CONFIG_RECREATE
:
1155 device_replace(struct device
*dev
, struct device
*odev
)
1157 struct device_user
*dep
;
1161 device_set_present(odev
, false);
1163 while (!list_empty(&odev
->users
.list
)) {
1164 dep
= list_first_entry(&odev
->users
.list
, struct device_user
, list
.list
);
1165 device_release(dep
);
1169 safe_list_del(&dep
->list
);
1170 __device_add_user(dep
, dev
);
1178 device_reset_config(void)
1182 avl_for_each_element(&devices
, dev
, avl
)
1183 dev
->current_config
= false;
1187 device_reset_old(void)
1189 struct device
*dev
, *tmp
, *ndev
;
1191 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1192 if (dev
->current_config
|| dev
->default_config
)
1195 if (dev
->type
!= &simple_device_type
)
1198 ndev
= device_create_default(dev
->ifname
, dev
->external
);
1202 device_replace(ndev
, dev
);
1207 device_create(const char *name
, struct device_type
*type
,
1208 struct blob_attr
*config
)
1210 struct device
*odev
= NULL
, *dev
;
1211 enum dev_change_type change
;
1213 odev
= device_find(name
);
1215 odev
->current_config
= true;
1216 change
= device_apply_config(odev
, type
, config
);
1218 case DEV_CONFIG_RECREATE
:
1219 D(DEVICE
, "Device '%s': recreate device\n", odev
->ifname
);
1220 device_delete(odev
);
1226 D(DEVICE
, "Create new device '%s' (%s)\n", name
, type
->name
);
1228 config
= blob_memdup(config
);
1232 dev
= type
->create(name
, type
, config
);
1236 dev
->current_config
= true;
1237 dev
->config
= config
;
1239 device_replace(dev
, odev
);
1241 if (!config_init
&& dev
->config_pending
) {
1242 type
->config_init(dev
);
1243 dev
->config_pending
= false;
1246 device_check_state(dev
);
1252 device_dump_status(struct blob_buf
*b
, struct device
*dev
)
1254 struct device_settings st
;
1258 avl_for_each_element(&devices
, dev
, avl
) {
1261 c
= blobmsg_open_table(b
, dev
->ifname
);
1262 device_dump_status(b
, dev
);
1263 blobmsg_close_table(b
, c
);
1269 blobmsg_add_u8(b
, "external", dev
->external
);
1270 blobmsg_add_u8(b
, "present", dev
->present
);
1271 blobmsg_add_string(b
, "type", dev
->type
->name
);
1276 blobmsg_add_u8(b
, "up", !!dev
->active
);
1277 blobmsg_add_u8(b
, "carrier", !!dev
->link_active
);
1278 blobmsg_add_u8(b
, "auth_status", !!dev
->auth_status
);
1280 if (dev
->type
->dump_info
)
1281 dev
->type
->dump_info(dev
, b
);
1283 system_if_dump_info(dev
, b
);
1286 device_merge_settings(dev
, &st
);
1287 if (st
.flags
& DEV_OPT_MTU
)
1288 blobmsg_add_u32(b
, "mtu", st
.mtu
);
1289 if (st
.flags
& DEV_OPT_MTU6
)
1290 blobmsg_add_u32(b
, "mtu6", st
.mtu6
);
1291 if (st
.flags
& DEV_OPT_MACADDR
)
1292 blobmsg_add_string(b
, "macaddr", format_macaddr(st
.macaddr
));
1293 if (st
.flags
& DEV_OPT_TXQUEUELEN
)
1294 blobmsg_add_u32(b
, "txqueuelen", st
.txqueuelen
);
1295 if (st
.flags
& DEV_OPT_IPV6
)
1296 blobmsg_add_u8(b
, "ipv6", st
.ipv6
);
1297 if (st
.flags
& DEV_OPT_IP6SEGMENTROUTING
)
1298 blobmsg_add_u8(b
, "ip6segmentrouting", st
.ip6segmentrouting
);
1299 if (st
.flags
& DEV_OPT_PROMISC
)
1300 blobmsg_add_u8(b
, "promisc", st
.promisc
);
1301 if (st
.flags
& DEV_OPT_RPFILTER
)
1302 blobmsg_add_u32(b
, "rpfilter", st
.rpfilter
);
1303 if (st
.flags
& DEV_OPT_ACCEPTLOCAL
)
1304 blobmsg_add_u8(b
, "acceptlocal", st
.acceptlocal
);
1305 if (st
.flags
& DEV_OPT_IGMPVERSION
)
1306 blobmsg_add_u32(b
, "igmpversion", st
.igmpversion
);
1307 if (st
.flags
& DEV_OPT_MLDVERSION
)
1308 blobmsg_add_u32(b
, "mldversion", st
.mldversion
);
1309 if (st
.flags
& DEV_OPT_NEIGHREACHABLETIME
) {
1310 blobmsg_add_u32(b
, "neigh4reachabletime", st
.neigh4reachabletime
);
1311 blobmsg_add_u32(b
, "neigh6reachabletime", st
.neigh6reachabletime
);
1313 if (st
.flags
& DEV_OPT_NEIGHGCSTALETIME
) {
1314 blobmsg_add_u32(b
, "neigh4gcstaletime", st
.neigh4gcstaletime
);
1315 blobmsg_add_u32(b
, "neigh6gcstaletime", st
.neigh6gcstaletime
);
1317 if (st
.flags
& DEV_OPT_NEIGHLOCKTIME
)
1318 blobmsg_add_u32(b
, "neigh4locktime", st
.neigh4locktime
);
1319 if (st
.flags
& DEV_OPT_DADTRANSMITS
)
1320 blobmsg_add_u32(b
, "dadtransmits", st
.dadtransmits
);
1321 if (st
.flags
& DEV_OPT_MULTICAST_TO_UNICAST
)
1322 blobmsg_add_u8(b
, "multicast_to_unicast", st
.multicast_to_unicast
);
1323 if (st
.flags
& DEV_OPT_MULTICAST_ROUTER
)
1324 blobmsg_add_u32(b
, "multicast_router", st
.multicast_router
);
1325 if (st
.flags
& DEV_OPT_MULTICAST_FAST_LEAVE
)
1326 blobmsg_add_u8(b
, "multicast_fast_leave", st
.multicast_fast_leave
);
1327 if (st
.flags
& DEV_OPT_MULTICAST
)
1328 blobmsg_add_u8(b
, "multicast", st
.multicast
);
1329 if (st
.flags
& DEV_OPT_LEARNING
)
1330 blobmsg_add_u8(b
, "learning", st
.learning
);
1331 if (st
.flags
& DEV_OPT_UNICAST_FLOOD
)
1332 blobmsg_add_u8(b
, "unicast_flood", st
.unicast_flood
);
1333 if (st
.flags
& DEV_OPT_SENDREDIRECTS
)
1334 blobmsg_add_u8(b
, "sendredirects", st
.sendredirects
);
1335 if (st
.flags
& DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
)
1336 blobmsg_add_u8(b
, "drop_v4_unicast_in_l2_multicast", st
.drop_v4_unicast_in_l2_multicast
);
1337 if (st
.flags
& DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
)
1338 blobmsg_add_u8(b
, "drop_v6_unicast_in_l2_multicast", st
.drop_v6_unicast_in_l2_multicast
);
1339 if (st
.flags
& DEV_OPT_DROP_GRATUITOUS_ARP
)
1340 blobmsg_add_u8(b
, "drop_gratuitous_arp", st
.drop_gratuitous_arp
);
1341 if (st
.flags
& DEV_OPT_DROP_UNSOLICITED_NA
)
1342 blobmsg_add_u8(b
, "drop_unsolicited_na", st
.drop_unsolicited_na
);
1343 if (st
.flags
& DEV_OPT_ARP_ACCEPT
)
1344 blobmsg_add_u8(b
, "arp_accept", st
.arp_accept
);
1345 if (st
.flags
& DEV_OPT_AUTH
)
1346 blobmsg_add_u8(b
, "auth", st
.auth
);
1349 s
= blobmsg_open_table(b
, "statistics");
1350 if (dev
->type
->dump_stats
)
1351 dev
->type
->dump_stats(dev
, b
);
1353 system_if_dump_stats(dev
, b
);
1354 blobmsg_close_table(b
, s
);
1357 static void __init
simple_device_type_init(void)
1359 device_type_add(&simple_device_type
);
1362 void device_hotplug_event(const char *name
, bool add
)
1366 wireless_device_hotplug_event(name
, add
);
1368 dev
= device_find(name
);
1369 if (!dev
|| dev
->type
!= &simple_device_type
)
1372 device_set_present(dev
, add
);