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
},
75 [DEV_ATTR_GRO
] = { .name
= "gro", .type
= BLOBMSG_TYPE_BOOL
},
78 const struct uci_blob_param_list device_attr_list
= {
79 .n_params
= __DEV_ATTR_MAX
,
83 static int __devlock
= 0;
85 int device_type_add(struct device_type
*devtype
)
87 if (device_type_get(devtype
->name
)) {
88 netifd_log_message(L_WARNING
, "Device handler '%s' already exists\n",
93 netifd_log_message(L_NOTICE
, "Added device handler type: %s\n",
96 list_add(&devtype
->list
, &devtypes
);
101 device_type_get(const char *tname
)
103 struct device_type
*cur
;
105 list_for_each_entry(cur
, &devtypes
, list
)
106 if (!strcmp(cur
->name
, tname
))
112 static int device_vlan_len(struct kvlist
*kv
, const void *data
)
114 return sizeof(unsigned int);
117 void device_vlan_update(bool done
)
121 avl_for_each_element(&devices
, dev
, avl
) {
122 if (!dev
->vlans
.update
)
126 if (dev
->vlan_aliases
.get_len
)
127 kvlist_free(&dev
->vlan_aliases
);
129 kvlist_init(&dev
->vlan_aliases
, device_vlan_len
);
130 vlist_update(&dev
->vlans
);
132 vlist_flush(&dev
->vlans
);
134 if (dev
->type
->vlan_update
)
135 dev
->type
->vlan_update(dev
);
140 void device_stp_init(void)
144 avl_for_each_element(&devices
, dev
, avl
) {
145 if (!dev
->type
->stp_init
)
148 dev
->type
->stp_init(dev
);
152 static int set_device_state(struct device
*dev
, bool state
)
155 /* Get ifindex for all devices being enabled so a valid */
156 /* ifindex is in place avoiding possible race conditions */
157 device_set_ifindex(dev
, system_if_resolve(dev
));
161 system_if_get_settings(dev
, &dev
->orig_settings
);
162 /* Only keep orig settings based on what needs to be set */
163 dev
->orig_settings
.valid_flags
= dev
->orig_settings
.flags
;
164 dev
->orig_settings
.flags
&= dev
->settings
.flags
;
165 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
169 system_if_apply_settings_after_up(dev
, &dev
->settings
);
172 system_if_apply_settings(dev
, &dev
->orig_settings
, dev
->orig_settings
.flags
);
179 simple_device_set_state(struct device
*dev
, bool state
)
184 pdev
= dev
->parent
.dev
;
185 if (state
&& !pdev
) {
186 pdev
= system_if_get_parent(dev
);
188 device_add_user(&dev
->parent
, pdev
);
193 ret
= device_claim(&dev
->parent
);
195 device_release(&dev
->parent
);
200 return set_device_state(dev
, state
);
203 static struct device
*
204 simple_device_create(const char *name
, struct device_type
*devtype
,
205 struct blob_attr
*attr
)
207 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
208 struct device
*dev
= NULL
;
210 /* device type is unused for simple devices */
213 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
, blob_data(attr
), blob_len(attr
));
214 dev
= device_get(name
, true);
218 dev
->set_state
= simple_device_set_state
;
219 device_init_settings(dev
, tb
);
224 static void simple_device_free(struct device
*dev
)
227 device_remove_user(&dev
->parent
);
231 struct device_type simple_device_type
= {
232 .name
= "Network device",
233 .config_params
= &device_attr_list
,
235 .create
= simple_device_create
,
236 .check_state
= system_if_check
,
237 .free
= simple_device_free
,
241 device_merge_settings(struct device
*dev
, struct device_settings
*n
)
243 struct device_settings
*os
= &dev
->orig_settings
;
244 struct device_settings
*s
= &dev
->settings
;
246 memset(n
, 0, sizeof(*n
));
247 n
->mtu
= s
->flags
& DEV_OPT_MTU
? s
->mtu
: os
->mtu
;
248 n
->mtu6
= s
->flags
& DEV_OPT_MTU6
? s
->mtu6
: os
->mtu6
;
249 n
->txqueuelen
= s
->flags
& DEV_OPT_TXQUEUELEN
?
250 s
->txqueuelen
: os
->txqueuelen
;
252 (s
->flags
& (DEV_OPT_MACADDR
|DEV_OPT_DEFAULT_MACADDR
) ? s
->macaddr
: os
->macaddr
),
254 n
->ipv6
= s
->flags
& DEV_OPT_IPV6
? s
->ipv6
: os
->ipv6
;
255 n
->ip6segmentrouting
= s
->flags
& DEV_OPT_IP6SEGMENTROUTING
? s
->ip6segmentrouting
: os
->ip6segmentrouting
;
256 n
->promisc
= s
->flags
& DEV_OPT_PROMISC
? s
->promisc
: os
->promisc
;
257 n
->rpfilter
= s
->flags
& DEV_OPT_RPFILTER
? s
->rpfilter
: os
->rpfilter
;
258 n
->acceptlocal
= s
->flags
& DEV_OPT_ACCEPTLOCAL
? s
->acceptlocal
: os
->acceptlocal
;
259 n
->igmpversion
= s
->flags
& DEV_OPT_IGMPVERSION
? s
->igmpversion
: os
->igmpversion
;
260 n
->mldversion
= s
->flags
& DEV_OPT_MLDVERSION
? s
->mldversion
: os
->mldversion
;
261 n
->neigh4reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
262 s
->neigh4reachabletime
: os
->neigh4reachabletime
;
263 n
->neigh6reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
264 s
->neigh6reachabletime
: os
->neigh6reachabletime
;
265 n
->neigh4gcstaletime
= s
->flags
& DEV_OPT_NEIGHGCSTALETIME
?
266 s
->neigh4gcstaletime
: os
->neigh4gcstaletime
;
267 n
->neigh6gcstaletime
= s
->flags
& DEV_OPT_NEIGHGCSTALETIME
?
268 s
->neigh6gcstaletime
: os
->neigh6gcstaletime
;
269 n
->neigh4locktime
= s
->flags
& DEV_OPT_NEIGHLOCKTIME
?
270 s
->neigh4locktime
: os
->neigh4locktime
;
271 n
->dadtransmits
= s
->flags
& DEV_OPT_DADTRANSMITS
?
272 s
->dadtransmits
: os
->dadtransmits
;
273 n
->multicast
= s
->flags
& DEV_OPT_MULTICAST
?
274 s
->multicast
: os
->multicast
;
275 n
->multicast_to_unicast
= s
->multicast_to_unicast
;
276 n
->multicast_router
= s
->multicast_router
;
277 n
->multicast_fast_leave
= s
->multicast_fast_leave
;
278 n
->learning
= s
->learning
;
279 n
->unicast_flood
= s
->unicast_flood
;
280 n
->sendredirects
= s
->flags
& DEV_OPT_SENDREDIRECTS
?
281 s
->sendredirects
: os
->sendredirects
;
282 n
->drop_v4_unicast_in_l2_multicast
= s
->flags
& DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
?
283 s
->drop_v4_unicast_in_l2_multicast
: os
->drop_v4_unicast_in_l2_multicast
;
284 n
->drop_v6_unicast_in_l2_multicast
= s
->flags
& DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
?
285 s
->drop_v6_unicast_in_l2_multicast
: os
->drop_v6_unicast_in_l2_multicast
;
286 n
->drop_gratuitous_arp
= s
->flags
& DEV_OPT_DROP_GRATUITOUS_ARP
?
287 s
->drop_gratuitous_arp
: os
->drop_gratuitous_arp
;
288 n
->drop_unsolicited_na
= s
->flags
& DEV_OPT_DROP_UNSOLICITED_NA
?
289 s
->drop_unsolicited_na
: os
->drop_unsolicited_na
;
290 n
->arp_accept
= s
->flags
& DEV_OPT_ARP_ACCEPT
?
291 s
->arp_accept
: os
->arp_accept
;
292 n
->auth
= s
->flags
& DEV_OPT_AUTH
? s
->auth
: os
->auth
;
293 n
->speed
= s
->flags
& DEV_OPT_SPEED
? s
->speed
: os
->speed
;
294 n
->duplex
= s
->flags
& DEV_OPT_DUPLEX
? s
->duplex
: os
->duplex
;
295 n
->pause
= s
->flags
& DEV_OPT_PAUSE
? s
->pause
: os
->pause
;
296 n
->asym_pause
= s
->flags
& DEV_OPT_ASYM_PAUSE
? s
->asym_pause
: os
->asym_pause
;
297 n
->rxpause
= s
->flags
& DEV_OPT_RXPAUSE
? s
->rxpause
: os
->rxpause
;
298 n
->txpause
= s
->flags
& DEV_OPT_TXPAUSE
? s
->txpause
: os
->txpause
;
299 n
->autoneg
= s
->flags
& DEV_OPT_AUTONEG
? s
->autoneg
: os
->autoneg
;
300 n
->gro
= s
->flags
& DEV_OPT_GRO
? s
->gro
: os
->gro
;
301 n
->flags
= s
->flags
| os
->flags
| os
->valid_flags
;
304 static bool device_fill_vlan_range(struct device_vlan_range
*r
, const char *val
)
306 unsigned long cur_start
, cur_end
;
309 cur_start
= strtoul(val
, &sep
, 0);
313 cur_end
= strtoul(sep
+ 1, &sep
, 0);
314 if (*sep
|| cur_end
< cur_start
)
317 r
->start
= cur_start
;
324 device_set_extra_vlans(struct device
*dev
, struct blob_attr
*data
)
326 struct blob_attr
*cur
;
330 dev
->n_extra_vlan
= 0;
334 n_vlans
= blobmsg_check_array(data
, BLOBMSG_TYPE_STRING
);
338 dev
->extra_vlan
= realloc(dev
->extra_vlan
, n_vlans
* sizeof(*dev
->extra_vlan
));
339 blobmsg_for_each_attr(cur
, data
, rem
)
340 if (device_fill_vlan_range(&dev
->extra_vlan
[dev
->n_extra_vlan
],
341 blobmsg_get_string(cur
)))
346 device_init_settings(struct device
*dev
, struct blob_attr
**tb
)
348 struct device_settings
*s
= &dev
->settings
;
349 struct blob_attr
*cur
;
350 struct ether_addr
*ea
;
351 bool disabled
= false;
354 if ((cur
= tb
[DEV_ATTR_ENABLED
]))
355 disabled
= !blobmsg_get_bool(cur
);
357 if ((cur
= tb
[DEV_ATTR_MTU
]) && blobmsg_get_u32(cur
) >= 68) {
358 s
->mtu
= blobmsg_get_u32(cur
);
359 s
->flags
|= DEV_OPT_MTU
;
362 if ((cur
= tb
[DEV_ATTR_MTU6
]) && blobmsg_get_u32(cur
) >= 1280) {
363 s
->mtu6
= blobmsg_get_u32(cur
);
364 s
->flags
|= DEV_OPT_MTU6
;
367 if ((cur
= tb
[DEV_ATTR_TXQUEUELEN
])) {
368 s
->txqueuelen
= blobmsg_get_u32(cur
);
369 s
->flags
|= DEV_OPT_TXQUEUELEN
;
372 if ((cur
= tb
[DEV_ATTR_MACADDR
])) {
373 ea
= ether_aton(blobmsg_data(cur
));
375 memcpy(s
->macaddr
, ea
, 6);
376 s
->flags
|= DEV_OPT_MACADDR
;
380 if ((cur
= tb
[DEV_ATTR_IPV6
])) {
381 s
->ipv6
= blobmsg_get_bool(cur
);
382 s
->flags
|= DEV_OPT_IPV6
;
385 if ((cur
= tb
[DEV_ATTR_IP6SEGMENTROUTING
])) {
386 s
->ip6segmentrouting
= blobmsg_get_bool(cur
);
387 s
->flags
|= DEV_OPT_IP6SEGMENTROUTING
;
390 if ((cur
= tb
[DEV_ATTR_PROMISC
])) {
391 s
->promisc
= blobmsg_get_bool(cur
);
392 s
->flags
|= DEV_OPT_PROMISC
;
395 if ((cur
= tb
[DEV_ATTR_RPFILTER
])) {
396 if (system_resolve_rpfilter(blobmsg_data(cur
), &s
->rpfilter
))
397 s
->flags
|= DEV_OPT_RPFILTER
;
399 DPRINTF("Failed to resolve rpfilter: %s\n", (char *) blobmsg_data(cur
));
402 if ((cur
= tb
[DEV_ATTR_ACCEPTLOCAL
])) {
403 s
->acceptlocal
= blobmsg_get_bool(cur
);
404 s
->flags
|= DEV_OPT_ACCEPTLOCAL
;
407 if ((cur
= tb
[DEV_ATTR_IGMPVERSION
])) {
408 s
->igmpversion
= blobmsg_get_u32(cur
);
409 if (s
->igmpversion
>= 1 && s
->igmpversion
<= 3)
410 s
->flags
|= DEV_OPT_IGMPVERSION
;
412 DPRINTF("Failed to resolve igmpversion: %d\n", blobmsg_get_u32(cur
));
415 if ((cur
= tb
[DEV_ATTR_MLDVERSION
])) {
416 s
->mldversion
= blobmsg_get_u32(cur
);
417 if (s
->mldversion
>= 1 && s
->mldversion
<= 2)
418 s
->flags
|= DEV_OPT_MLDVERSION
;
420 DPRINTF("Failed to resolve mldversion: %d\n", blobmsg_get_u32(cur
));
423 if ((cur
= tb
[DEV_ATTR_NEIGHREACHABLETIME
])) {
424 s
->neigh6reachabletime
= s
->neigh4reachabletime
= blobmsg_get_u32(cur
);
425 s
->flags
|= DEV_OPT_NEIGHREACHABLETIME
;
428 if ((cur
= tb
[DEV_ATTR_NEIGHGCSTALETIME
])) {
429 s
->neigh6gcstaletime
= s
->neigh4gcstaletime
= blobmsg_get_u32(cur
);
430 s
->flags
|= DEV_OPT_NEIGHGCSTALETIME
;
433 if ((cur
= tb
[DEV_ATTR_NEIGHLOCKTIME
])) {
434 s
->neigh4locktime
= blobmsg_get_u32(cur
);
435 s
->flags
|= DEV_OPT_NEIGHLOCKTIME
;
438 if ((cur
= tb
[DEV_ATTR_DADTRANSMITS
])) {
439 s
->dadtransmits
= blobmsg_get_u32(cur
);
440 s
->flags
|= DEV_OPT_DADTRANSMITS
;
443 if ((cur
= tb
[DEV_ATTR_MULTICAST_TO_UNICAST
])) {
444 s
->multicast_to_unicast
= blobmsg_get_bool(cur
);
445 s
->flags
|= DEV_OPT_MULTICAST_TO_UNICAST
;
448 if ((cur
= tb
[DEV_ATTR_MULTICAST_ROUTER
])) {
449 s
->multicast_router
= blobmsg_get_u32(cur
);
450 if (s
->multicast_router
<= 2)
451 s
->flags
|= DEV_OPT_MULTICAST_ROUTER
;
453 DPRINTF("Invalid value: %d - (Use 0: never, 1: learn, 2: always)\n", blobmsg_get_u32(cur
));
456 if ((cur
= tb
[DEV_ATTR_MULTICAST_FAST_LEAVE
])) {
457 s
->multicast_fast_leave
= blobmsg_get_bool(cur
);
458 s
->flags
|= DEV_OPT_MULTICAST_FAST_LEAVE
;
461 if ((cur
= tb
[DEV_ATTR_MULTICAST
])) {
462 s
->multicast
= blobmsg_get_bool(cur
);
463 s
->flags
|= DEV_OPT_MULTICAST
;
466 if ((cur
= tb
[DEV_ATTR_LEARNING
])) {
467 s
->learning
= blobmsg_get_bool(cur
);
468 s
->flags
|= DEV_OPT_LEARNING
;
471 if ((cur
= tb
[DEV_ATTR_UNICAST_FLOOD
])) {
472 s
->unicast_flood
= blobmsg_get_bool(cur
);
473 s
->flags
|= DEV_OPT_UNICAST_FLOOD
;
476 if ((cur
= tb
[DEV_ATTR_SENDREDIRECTS
])) {
477 s
->sendredirects
= blobmsg_get_bool(cur
);
478 s
->flags
|= DEV_OPT_SENDREDIRECTS
;
481 if ((cur
= tb
[DEV_ATTR_ISOLATE
])) {
482 s
->isolate
= blobmsg_get_bool(cur
);
483 s
->flags
|= DEV_OPT_ISOLATE
;
486 if ((cur
= tb
[DEV_ATTR_DROP_V4_UNICAST_IN_L2_MULTICAST
])) {
487 s
->drop_v4_unicast_in_l2_multicast
= blobmsg_get_bool(cur
);
488 s
->flags
|= DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
;
491 if ((cur
= tb
[DEV_ATTR_DROP_V6_UNICAST_IN_L2_MULTICAST
])) {
492 s
->drop_v6_unicast_in_l2_multicast
= blobmsg_get_bool(cur
);
493 s
->flags
|= DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
;
496 if ((cur
= tb
[DEV_ATTR_DROP_GRATUITOUS_ARP
])) {
497 s
->drop_gratuitous_arp
= blobmsg_get_bool(cur
);
498 s
->flags
|= DEV_OPT_DROP_GRATUITOUS_ARP
;
501 if ((cur
= tb
[DEV_ATTR_DROP_UNSOLICITED_NA
])) {
502 s
->drop_unsolicited_na
= blobmsg_get_bool(cur
);
503 s
->flags
|= DEV_OPT_DROP_UNSOLICITED_NA
;
506 if ((cur
= tb
[DEV_ATTR_ARP_ACCEPT
])) {
507 s
->arp_accept
= blobmsg_get_bool(cur
);
508 s
->flags
|= DEV_OPT_ARP_ACCEPT
;
511 if ((cur
= tb
[DEV_ATTR_AUTH
])) {
512 s
->auth
= blobmsg_get_bool(cur
);
513 s
->flags
|= DEV_OPT_AUTH
;
516 if ((cur
= tb
[DEV_ATTR_SPEED
])) {
517 s
->speed
= blobmsg_get_u32(cur
);
518 s
->flags
|= DEV_OPT_SPEED
;
521 if ((cur
= tb
[DEV_ATTR_DUPLEX
])) {
522 s
->duplex
= blobmsg_get_bool(cur
);
523 s
->flags
|= DEV_OPT_DUPLEX
;
526 if ((cur
= tb
[DEV_ATTR_PAUSE
])) {
527 s
->pause
= blobmsg_get_bool(cur
);
528 s
->flags
|= DEV_OPT_PAUSE
;
531 if ((cur
= tb
[DEV_ATTR_ASYM_PAUSE
])) {
532 s
->asym_pause
= blobmsg_get_bool(cur
);
533 s
->flags
|= DEV_OPT_ASYM_PAUSE
;
536 if ((cur
= tb
[DEV_ATTR_RXPAUSE
])) {
537 s
->rxpause
= blobmsg_get_bool(cur
);
538 s
->flags
|= DEV_OPT_RXPAUSE
;
541 if ((cur
= tb
[DEV_ATTR_TXPAUSE
])) {
542 s
->txpause
= blobmsg_get_bool(cur
);
543 s
->flags
|= DEV_OPT_TXPAUSE
;
546 if ((cur
= tb
[DEV_ATTR_AUTONEG
])) {
547 s
->autoneg
= blobmsg_get_bool(cur
);
548 s
->flags
|= DEV_OPT_AUTONEG
;
551 if ((cur
= tb
[DEV_ATTR_GRO
])) {
552 s
->gro
= blobmsg_get_bool(cur
);
553 s
->flags
|= DEV_OPT_GRO
;
556 cur
= tb
[DEV_ATTR_AUTH_VLAN
];
557 free(dev
->config_auth_vlans
);
558 dev
->config_auth_vlans
= cur
? blob_memdup(cur
) : NULL
;
560 device_set_extra_vlans(dev
, tb
[DEV_ATTR_VLAN
]);
561 device_set_disabled(dev
, disabled
);
564 static void __init
dev_init(void)
566 avl_init(&devices
, avl_strcmp
, true, NULL
);
569 static int device_release_cb(void *ctx
, struct safe_list
*list
)
571 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
573 if (!dep
->dev
|| !dep
->claimed
)
580 static int device_broadcast_cb(void *ctx
, struct safe_list
*list
)
582 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
585 /* device might have been removed by an earlier callback */
594 void device_broadcast_event(struct device
*dev
, enum device_event ev
)
596 static const char * const event_names
[] = {
597 [DEV_EVENT_ADD
] = "add",
598 [DEV_EVENT_REMOVE
] = "remove",
599 [DEV_EVENT_UP
] = "up",
600 [DEV_EVENT_DOWN
] = "down",
601 [DEV_EVENT_AUTH_UP
] = "auth_up",
602 [DEV_EVENT_LINK_UP
] = "link_up",
603 [DEV_EVENT_LINK_DOWN
] = "link_down",
604 [DEV_EVENT_TOPO_CHANGE
] = "topo_change",
608 safe_list_for_each(&dev
->aliases
, device_broadcast_cb
, &dev_ev
);
609 safe_list_for_each(&dev
->users
, device_broadcast_cb
, &dev_ev
);
611 if (ev
>= ARRAY_SIZE(event_names
) || !event_names
[ev
] || !dev
->ifname
[0])
614 blob_buf_init(&b
, 0);
615 blobmsg_add_string(&b
, "name", dev
->ifname
);
616 blobmsg_add_u8(&b
, "auth_status", dev
->auth_status
);
617 blobmsg_add_u8(&b
, "present", dev
->present
);
618 blobmsg_add_u8(&b
, "active", dev
->active
);
619 blobmsg_add_u8(&b
, "link_active", dev
->link_active
);
620 netifd_ubus_device_notify(event_names
[ev
], b
.head
, -1);
624 device_fill_default_settings(struct device
*dev
)
626 struct device_settings
*s
= &dev
->settings
;
627 struct ether_addr
*ea
;
630 if (!(s
->flags
& DEV_OPT_MACADDR
)) {
631 ea
= config_get_default_macaddr(dev
->ifname
);
633 memcpy(s
->macaddr
, ea
, 6);
634 s
->flags
|= DEV_OPT_DEFAULT_MACADDR
;
638 if (!(s
->flags
& DEV_OPT_GRO
)) {
639 ret
= config_get_default_gro(dev
->ifname
);
642 s
->flags
|= DEV_OPT_GRO
;
647 int device_claim(struct device_user
*dep
)
649 struct device
*dev
= dep
->dev
;
659 D(DEVICE
, "Claim %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
+ 1);
660 if (++dev
->active
!= 1)
663 device_broadcast_event(dev
, DEV_EVENT_SETUP
);
664 device_fill_default_settings(dev
);
666 /* Get ifindex for external claimed devices so a valid */
667 /* ifindex is in place avoiding possible race conditions */
668 device_set_ifindex(dev
, system_if_resolve(dev
));
672 system_if_get_settings(dev
, &dev
->orig_settings
);
674 ret
= dev
->set_state(dev
, true);
677 device_broadcast_event(dev
, DEV_EVENT_UP
);
679 D(DEVICE
, "claim %s %s failed: %d\n", dev
->type
->name
, dev
->ifname
, ret
);
681 dep
->claimed
= false;
687 void device_release(struct device_user
*dep
)
689 struct device
*dev
= dep
->dev
;
694 dep
->claimed
= false;
696 D(DEVICE
, "Release %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
);
697 assert(dev
->active
>= 0);
702 device_broadcast_event(dev
, DEV_EVENT_TEARDOWN
);
704 dev
->set_state(dev
, false);
709 device_broadcast_event(dev
, DEV_EVENT_DOWN
);
712 int device_check_state(struct device
*dev
)
714 if (!dev
->type
->check_state
)
715 return simple_device_type
.check_state(dev
);
717 return dev
->type
->check_state(dev
);
720 int device_init_virtual(struct device
*dev
, struct device_type
*type
, const char *name
)
725 D(DEVICE
, "Initialize device '%s'\n", name
? name
: "");
726 INIT_SAFE_LIST(&dev
->users
);
727 INIT_SAFE_LIST(&dev
->aliases
);
733 ret
= device_set_ifname(dev
, name
);
739 dev
->set_state
= set_device_state
;
744 int device_init(struct device
*dev
, struct device_type
*type
, const char *ifname
)
748 ret
= device_init_virtual(dev
, type
, ifname
);
752 dev
->avl
.key
= dev
->ifname
;
754 ret
= avl_insert(&devices
, &dev
->avl
);
758 system_if_clear_state(dev
);
763 static struct device
*
764 device_create_default(const char *name
, bool external
)
768 if (!external
&& system_if_force_external(name
))
771 D(DEVICE
, "Create simple device '%s'\n", name
);
772 dev
= calloc(1, sizeof(*dev
));
776 dev
->external
= external
;
777 dev
->set_state
= simple_device_set_state
;
779 if (device_init(dev
, &simple_device_type
, name
) < 0) {
785 dev
->default_config
= true;
787 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
789 device_check_state(dev
);
795 device_find(const char *name
)
799 return avl_find_element(&devices
, name
, dev
, avl
);
803 __device_get(const char *name
, int create
, bool check_vlan
)
807 dev
= avl_find_element(&devices
, name
, dev
, avl
);
809 if (!dev
&& check_vlan
&& strchr(name
, '.'))
810 return get_vlan_device_chain(name
, create
);
813 return device_alias_get(name
+ 1);
816 if (create
> 1 && !dev
->external
) {
817 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
818 dev
->external
= true;
819 device_set_present(dev
, true);
827 return device_create_default(name
, create
> 1);
831 device_delete(struct device
*dev
)
836 D(DEVICE
, "Delete device '%s' from list\n", dev
->ifname
);
837 avl_delete(&devices
, &dev
->avl
);
841 static int device_cleanup_cb(void *ctx
, struct safe_list
*list
)
843 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
845 dep
->cb(dep
, DEV_EVENT_REMOVE
);
851 void device_cleanup(struct device
*dev
)
853 D(DEVICE
, "Clean up device '%s'\n", dev
->ifname
);
854 safe_list_for_each(&dev
->users
, device_cleanup_cb
, NULL
);
855 safe_list_for_each(&dev
->aliases
, device_cleanup_cb
, NULL
);
859 static void __device_set_present(struct device
*dev
, bool state
)
861 if (dev
->present
== state
)
864 dev
->present
= state
;
865 device_broadcast_event(dev
, state
? DEV_EVENT_ADD
: DEV_EVENT_REMOVE
);
869 device_refresh_present(struct device
*dev
)
871 bool state
= dev
->sys_present
;
873 if (dev
->disabled
|| dev
->deferred
)
876 __device_set_present(dev
, state
);
880 device_set_auth_status(struct device
*dev
, bool value
, struct blob_attr
*vlans
)
884 else if (!blob_attr_equal(vlans
, dev
->auth_vlans
))
885 device_set_auth_status(dev
, false, NULL
);
887 free(dev
->auth_vlans
);
888 dev
->auth_vlans
= vlans
? blob_memdup(vlans
) : NULL
;
890 if (dev
->auth_status
== value
)
893 dev
->auth_status
= value
;
897 if (dev
->auth_status
) {
898 device_broadcast_event(dev
, DEV_EVENT_AUTH_UP
);
902 device_broadcast_event(dev
, DEV_EVENT_LINK_DOWN
);
903 if (!dev
->link_active
)
906 device_broadcast_event(dev
, DEV_EVENT_LINK_UP
);
909 void device_set_present(struct device
*dev
, bool state
)
911 if (dev
->sys_present
== state
)
914 D(DEVICE
, "%s '%s' %s present\n", dev
->type
->name
, dev
->ifname
, state
? "is now" : "is no longer" );
915 dev
->sys_present
= state
;
916 device_refresh_present(dev
);
918 safe_list_for_each(&dev
->users
, device_release_cb
, NULL
);
921 void device_set_link(struct device
*dev
, bool state
)
923 if (dev
->link_active
== state
)
926 netifd_log_message(L_NOTICE
, "%s '%s' link is %s\n", dev
->type
->name
, dev
->ifname
, state
? "up" : "down" );
928 dev
->link_active
= state
;
930 dev
->auth_status
= false;
931 device_broadcast_event(dev
, state
? DEV_EVENT_LINK_UP
: DEV_EVENT_LINK_DOWN
);
934 void device_set_ifindex(struct device
*dev
, int ifindex
)
936 if (dev
->ifindex
== ifindex
)
939 dev
->ifindex
= ifindex
;
940 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFINDEX
);
943 int device_set_ifname(struct device
*dev
, const char *name
)
947 if (!strcmp(dev
->ifname
, name
))
950 if (strlen(name
) > sizeof(dev
->ifname
) - 1)
954 avl_delete(&devices
, &dev
->avl
);
956 strcpy(dev
->ifname
, name
);
959 ret
= avl_insert(&devices
, &dev
->avl
);
962 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFNAME
);
967 static int device_refcount(struct device
*dev
)
969 struct list_head
*list
;
972 list_for_each(list
, &dev
->users
.list
)
975 list_for_each(list
, &dev
->aliases
.list
)
982 __device_add_user(struct device_user
*dep
, struct device
*dev
)
984 struct safe_list
*head
;
989 head
= &dev
->aliases
;
993 safe_list_add(&dep
->list
, head
);
994 D(DEVICE
, "Add user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
996 if (dep
->cb
&& dev
->present
) {
997 dep
->cb(dep
, DEV_EVENT_ADD
);
999 dep
->cb(dep
, DEV_EVENT_UP
);
1001 if (dev
->link_active
)
1002 dep
->cb(dep
, DEV_EVENT_LINK_UP
);
1006 void device_add_user(struct device_user
*dep
, struct device
*dev
)
1008 if (dep
->dev
== dev
)
1012 device_remove_user(dep
);
1017 __device_add_user(dep
, dev
);
1021 device_free(struct device
*dev
)
1024 free(dev
->auth_vlans
);
1026 device_cleanup(dev
);
1027 free(dev
->config_auth_vlans
);
1028 free(dev
->extra_vlan
);
1029 dev
->type
->free(dev
);
1034 __device_free_unused(struct uloop_timeout
*timeout
)
1036 struct device
*dev
, *tmp
;
1038 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1039 if (!safe_list_empty(&dev
->users
) ||
1040 !safe_list_empty(&dev
->aliases
) ||
1041 dev
->current_config
)
1048 void device_free_unused(void)
1050 static struct uloop_timeout free_timer
= {
1051 .cb
= __device_free_unused
,
1054 uloop_timeout_set(&free_timer
, 1);
1057 void device_remove_user(struct device_user
*dep
)
1059 struct device
*dev
= dep
->dev
;
1064 dep
->hotplug
= false;
1066 device_release(dep
);
1068 safe_list_del(&dep
->list
);
1070 D(DEVICE
, "Remove user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
1071 device_free_unused();
1075 device_init_pending(void)
1077 struct device
*dev
, *tmp
;
1079 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1080 if (!dev
->config_pending
)
1083 dev
->type
->config_init(dev
);
1084 dev
->config_pending
= false;
1085 device_check_state(dev
);
1090 device_check_ip6segmentrouting(void)
1093 bool ip6segmentrouting
= false;
1095 avl_for_each_element(&devices
, dev
, avl
)
1096 ip6segmentrouting
|= dev
->settings
.ip6segmentrouting
;
1098 return ip6segmentrouting
;
1101 static enum dev_change_type
1102 device_set_config(struct device
*dev
, struct device_type
*type
,
1103 struct blob_attr
*attr
)
1105 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
1106 const struct uci_blob_param_list
*cfg
= type
->config_params
;
1108 if (type
!= dev
->type
)
1109 return DEV_CONFIG_RECREATE
;
1111 if (dev
->type
->reload
)
1112 return dev
->type
->reload(dev
, attr
);
1114 if (uci_blob_check_equal(dev
->config
, attr
, cfg
))
1115 return DEV_CONFIG_NO_CHANGE
;
1117 if (cfg
== &device_attr_list
) {
1118 memset(tb
, 0, sizeof(tb
));
1121 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
,
1122 blob_data(attr
), blob_len(attr
));
1124 device_init_settings(dev
, tb
);
1125 return DEV_CONFIG_RESTART
;
1127 return DEV_CONFIG_RECREATE
;
1130 enum dev_change_type
1131 device_apply_config(struct device
*dev
, struct device_type
*type
,
1132 struct blob_attr
*config
)
1134 enum dev_change_type change
;
1136 change
= device_set_config(dev
, type
, config
);
1137 if (dev
->external
) {
1138 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
1139 change
= DEV_CONFIG_APPLIED
;
1143 case DEV_CONFIG_RESTART
:
1144 case DEV_CONFIG_APPLIED
:
1145 D(DEVICE
, "Device '%s': config applied\n", dev
->ifname
);
1146 config
= blob_memdup(config
);
1148 dev
->config
= config
;
1149 if (change
== DEV_CONFIG_RESTART
&& dev
->present
) {
1152 device_set_present(dev
, false);
1153 if (dev
->active
&& !dev
->external
) {
1154 ret
= dev
->set_state(dev
, false);
1156 ret
= dev
->set_state(dev
, true);
1159 device_set_present(dev
, true);
1162 case DEV_CONFIG_NO_CHANGE
:
1163 D(DEVICE
, "Device '%s': no configuration change\n", dev
->ifname
);
1165 case DEV_CONFIG_RECREATE
:
1173 device_replace(struct device
*dev
, struct device
*odev
)
1175 struct device_user
*dep
;
1179 device_set_present(odev
, false);
1181 while (!list_empty(&odev
->users
.list
)) {
1182 dep
= list_first_entry(&odev
->users
.list
, struct device_user
, list
.list
);
1183 device_release(dep
);
1187 safe_list_del(&dep
->list
);
1188 __device_add_user(dep
, dev
);
1196 device_reset_config(void)
1200 avl_for_each_element(&devices
, dev
, avl
)
1201 dev
->current_config
= false;
1205 device_reset_old(void)
1207 struct device
*dev
, *tmp
, *ndev
;
1209 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1210 if (dev
->current_config
|| dev
->default_config
)
1213 if (dev
->type
!= &simple_device_type
)
1216 ndev
= device_create_default(dev
->ifname
, dev
->external
);
1220 device_replace(ndev
, dev
);
1225 device_create(const char *name
, struct device_type
*type
,
1226 struct blob_attr
*config
)
1228 struct device
*odev
= NULL
, *dev
;
1229 enum dev_change_type change
;
1231 odev
= device_find(name
);
1233 odev
->current_config
= true;
1234 change
= device_apply_config(odev
, type
, config
);
1236 case DEV_CONFIG_RECREATE
:
1237 D(DEVICE
, "Device '%s': recreate device\n", odev
->ifname
);
1238 device_delete(odev
);
1244 D(DEVICE
, "Create new device '%s' (%s)\n", name
, type
->name
);
1246 config
= blob_memdup(config
);
1250 dev
= type
->create(name
, type
, config
);
1254 dev
->current_config
= true;
1255 dev
->config
= config
;
1257 device_replace(dev
, odev
);
1259 if (!config_init
&& dev
->config_pending
) {
1260 type
->config_init(dev
);
1261 dev
->config_pending
= false;
1264 device_check_state(dev
);
1270 device_dump_status(struct blob_buf
*b
, struct device
*dev
)
1272 struct device_settings st
;
1276 avl_for_each_element(&devices
, dev
, avl
) {
1279 c
= blobmsg_open_table(b
, dev
->ifname
);
1280 device_dump_status(b
, dev
);
1281 blobmsg_close_table(b
, c
);
1287 blobmsg_add_u8(b
, "external", dev
->external
);
1288 blobmsg_add_u8(b
, "present", dev
->present
);
1289 blobmsg_add_string(b
, "type", dev
->type
->name
);
1294 blobmsg_add_u8(b
, "up", !!dev
->active
);
1295 blobmsg_add_u8(b
, "carrier", !!dev
->link_active
);
1296 blobmsg_add_u8(b
, "auth_status", !!dev
->auth_status
);
1298 if (dev
->type
->dump_info
)
1299 dev
->type
->dump_info(dev
, b
);
1301 system_if_dump_info(dev
, b
);
1304 device_merge_settings(dev
, &st
);
1305 if (st
.flags
& DEV_OPT_MTU
)
1306 blobmsg_add_u32(b
, "mtu", st
.mtu
);
1307 if (st
.flags
& DEV_OPT_MTU6
)
1308 blobmsg_add_u32(b
, "mtu6", st
.mtu6
);
1309 if (st
.flags
& DEV_OPT_MACADDR
)
1310 blobmsg_add_string(b
, "macaddr", format_macaddr(st
.macaddr
));
1311 if (st
.flags
& DEV_OPT_TXQUEUELEN
)
1312 blobmsg_add_u32(b
, "txqueuelen", st
.txqueuelen
);
1313 if (st
.flags
& DEV_OPT_IPV6
)
1314 blobmsg_add_u8(b
, "ipv6", st
.ipv6
);
1315 if (st
.flags
& DEV_OPT_IP6SEGMENTROUTING
)
1316 blobmsg_add_u8(b
, "ip6segmentrouting", st
.ip6segmentrouting
);
1317 if (st
.flags
& DEV_OPT_PROMISC
)
1318 blobmsg_add_u8(b
, "promisc", st
.promisc
);
1319 if (st
.flags
& DEV_OPT_RPFILTER
)
1320 blobmsg_add_u32(b
, "rpfilter", st
.rpfilter
);
1321 if (st
.flags
& DEV_OPT_ACCEPTLOCAL
)
1322 blobmsg_add_u8(b
, "acceptlocal", st
.acceptlocal
);
1323 if (st
.flags
& DEV_OPT_IGMPVERSION
)
1324 blobmsg_add_u32(b
, "igmpversion", st
.igmpversion
);
1325 if (st
.flags
& DEV_OPT_MLDVERSION
)
1326 blobmsg_add_u32(b
, "mldversion", st
.mldversion
);
1327 if (st
.flags
& DEV_OPT_NEIGHREACHABLETIME
) {
1328 blobmsg_add_u32(b
, "neigh4reachabletime", st
.neigh4reachabletime
);
1329 blobmsg_add_u32(b
, "neigh6reachabletime", st
.neigh6reachabletime
);
1331 if (st
.flags
& DEV_OPT_NEIGHGCSTALETIME
) {
1332 blobmsg_add_u32(b
, "neigh4gcstaletime", st
.neigh4gcstaletime
);
1333 blobmsg_add_u32(b
, "neigh6gcstaletime", st
.neigh6gcstaletime
);
1335 if (st
.flags
& DEV_OPT_NEIGHLOCKTIME
)
1336 blobmsg_add_u32(b
, "neigh4locktime", st
.neigh4locktime
);
1337 if (st
.flags
& DEV_OPT_DADTRANSMITS
)
1338 blobmsg_add_u32(b
, "dadtransmits", st
.dadtransmits
);
1339 if (st
.flags
& DEV_OPT_MULTICAST_TO_UNICAST
)
1340 blobmsg_add_u8(b
, "multicast_to_unicast", st
.multicast_to_unicast
);
1341 if (st
.flags
& DEV_OPT_MULTICAST_ROUTER
)
1342 blobmsg_add_u32(b
, "multicast_router", st
.multicast_router
);
1343 if (st
.flags
& DEV_OPT_MULTICAST_FAST_LEAVE
)
1344 blobmsg_add_u8(b
, "multicast_fast_leave", st
.multicast_fast_leave
);
1345 if (st
.flags
& DEV_OPT_MULTICAST
)
1346 blobmsg_add_u8(b
, "multicast", st
.multicast
);
1347 if (st
.flags
& DEV_OPT_LEARNING
)
1348 blobmsg_add_u8(b
, "learning", st
.learning
);
1349 if (st
.flags
& DEV_OPT_UNICAST_FLOOD
)
1350 blobmsg_add_u8(b
, "unicast_flood", st
.unicast_flood
);
1351 if (st
.flags
& DEV_OPT_SENDREDIRECTS
)
1352 blobmsg_add_u8(b
, "sendredirects", st
.sendredirects
);
1353 if (st
.flags
& DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
)
1354 blobmsg_add_u8(b
, "drop_v4_unicast_in_l2_multicast", st
.drop_v4_unicast_in_l2_multicast
);
1355 if (st
.flags
& DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
)
1356 blobmsg_add_u8(b
, "drop_v6_unicast_in_l2_multicast", st
.drop_v6_unicast_in_l2_multicast
);
1357 if (st
.flags
& DEV_OPT_DROP_GRATUITOUS_ARP
)
1358 blobmsg_add_u8(b
, "drop_gratuitous_arp", st
.drop_gratuitous_arp
);
1359 if (st
.flags
& DEV_OPT_DROP_UNSOLICITED_NA
)
1360 blobmsg_add_u8(b
, "drop_unsolicited_na", st
.drop_unsolicited_na
);
1361 if (st
.flags
& DEV_OPT_ARP_ACCEPT
)
1362 blobmsg_add_u8(b
, "arp_accept", st
.arp_accept
);
1363 if (st
.flags
& DEV_OPT_AUTH
)
1364 blobmsg_add_u8(b
, "auth", st
.auth
);
1365 if (st
.flags
& DEV_OPT_GRO
)
1366 blobmsg_add_u8(b
, "gro", st
.gro
);
1369 s
= blobmsg_open_table(b
, "statistics");
1370 if (dev
->type
->dump_stats
)
1371 dev
->type
->dump_stats(dev
, b
);
1373 system_if_dump_stats(dev
, b
);
1374 blobmsg_close_table(b
, s
);
1377 static void __init
simple_device_type_init(void)
1379 device_type_add(&simple_device_type
);
1382 void device_hotplug_event(const char *name
, bool add
)
1386 wireless_device_hotplug_event(name
, add
);
1388 dev
= device_find(name
);
1389 if (!dev
|| dev
->type
!= &simple_device_type
)
1392 device_set_present(dev
, add
);