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
},
76 [DEV_ATTR_MASTER
] = { .name
= "conduit", .type
= BLOBMSG_TYPE_STRING
},
77 [DEV_ATTR_EEE
] = { .name
= "eee", .type
= BLOBMSG_TYPE_BOOL
},
80 const struct uci_blob_param_list device_attr_list
= {
81 .n_params
= __DEV_ATTR_MAX
,
85 static int __devlock
= 0;
87 int device_type_add(struct device_type
*devtype
)
89 if (device_type_get(devtype
->name
)) {
90 netifd_log_message(L_WARNING
, "Device handler '%s' already exists\n",
95 netifd_log_message(L_NOTICE
, "Added device handler type: %s\n",
98 list_add(&devtype
->list
, &devtypes
);
103 device_type_get(const char *tname
)
105 struct device_type
*cur
;
107 list_for_each_entry(cur
, &devtypes
, list
)
108 if (!strcmp(cur
->name
, tname
))
114 static int device_vlan_len(struct kvlist
*kv
, const void *data
)
116 return sizeof(unsigned int);
119 void device_vlan_update(bool done
)
123 avl_for_each_element(&devices
, dev
, avl
) {
124 if (!dev
->vlans
.update
)
128 if (dev
->vlan_aliases
.get_len
)
129 kvlist_free(&dev
->vlan_aliases
);
131 kvlist_init(&dev
->vlan_aliases
, device_vlan_len
);
132 vlist_update(&dev
->vlans
);
134 vlist_flush(&dev
->vlans
);
136 if (dev
->type
->vlan_update
)
137 dev
->type
->vlan_update(dev
);
142 void device_stp_init(void)
146 avl_for_each_element(&devices
, dev
, avl
) {
147 if (!dev
->type
->stp_init
)
150 dev
->type
->stp_init(dev
);
154 static int set_device_state(struct device
*dev
, bool state
)
157 /* Get ifindex for all devices being enabled so a valid */
158 /* ifindex is in place avoiding possible race conditions */
159 device_set_ifindex(dev
, system_if_resolve(dev
));
163 system_if_get_settings(dev
, &dev
->orig_settings
);
164 /* Only keep orig settings based on what needs to be set */
165 dev
->orig_settings
.valid_flags
= dev
->orig_settings
.flags
;
166 dev
->orig_settings
.flags
&= dev
->settings
.flags
;
167 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
171 system_if_apply_settings_after_up(dev
, &dev
->settings
);
174 system_if_apply_settings(dev
, &dev
->orig_settings
, dev
->orig_settings
.flags
);
176 /* Restore any settings present in UCI which may have
177 * failed to apply so that they will be re-attempted
178 * the next time the device is brought up */
179 dev
->settings
.flags
|= dev
->settings
.valid_flags
;
186 simple_device_set_state(struct device
*dev
, bool state
)
191 pdev
= dev
->parent
.dev
;
192 if (state
&& !pdev
) {
193 pdev
= system_if_get_parent(dev
);
195 device_add_user(&dev
->parent
, pdev
);
200 ret
= device_claim(&dev
->parent
);
202 device_release(&dev
->parent
);
207 return set_device_state(dev
, state
);
210 static struct device
*
211 simple_device_create(const char *name
, struct device_type
*devtype
,
212 struct blob_attr
*attr
)
214 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
215 struct device
*dev
= NULL
;
217 /* device type is unused for simple devices */
220 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
, blob_data(attr
), blob_len(attr
));
221 dev
= device_get(name
, true);
225 dev
->set_state
= simple_device_set_state
;
226 device_init_settings(dev
, tb
);
231 static void simple_device_free(struct device
*dev
)
234 device_remove_user(&dev
->parent
);
238 struct device_type simple_device_type
= {
239 .name
= "Network device",
240 .config_params
= &device_attr_list
,
242 .create
= simple_device_create
,
243 .check_state
= system_if_check
,
244 .free
= simple_device_free
,
248 device_merge_settings(struct device
*dev
, struct device_settings
*n
)
250 struct device_settings
*os
= &dev
->orig_settings
;
251 struct device_settings
*s
= &dev
->settings
;
253 memset(n
, 0, sizeof(*n
));
254 n
->mtu
= s
->flags
& DEV_OPT_MTU
? s
->mtu
: os
->mtu
;
255 n
->mtu6
= s
->flags
& DEV_OPT_MTU6
? s
->mtu6
: os
->mtu6
;
256 n
->txqueuelen
= s
->flags
& DEV_OPT_TXQUEUELEN
?
257 s
->txqueuelen
: os
->txqueuelen
;
259 (s
->flags
& (DEV_OPT_MACADDR
|DEV_OPT_DEFAULT_MACADDR
) ? s
->macaddr
: os
->macaddr
),
261 n
->ipv6
= s
->flags
& DEV_OPT_IPV6
? s
->ipv6
: os
->ipv6
;
262 n
->ip6segmentrouting
= s
->flags
& DEV_OPT_IP6SEGMENTROUTING
? s
->ip6segmentrouting
: os
->ip6segmentrouting
;
263 n
->promisc
= s
->flags
& DEV_OPT_PROMISC
? s
->promisc
: os
->promisc
;
264 n
->rpfilter
= s
->flags
& DEV_OPT_RPFILTER
? s
->rpfilter
: os
->rpfilter
;
265 n
->acceptlocal
= s
->flags
& DEV_OPT_ACCEPTLOCAL
? s
->acceptlocal
: os
->acceptlocal
;
266 n
->igmpversion
= s
->flags
& DEV_OPT_IGMPVERSION
? s
->igmpversion
: os
->igmpversion
;
267 n
->mldversion
= s
->flags
& DEV_OPT_MLDVERSION
? s
->mldversion
: os
->mldversion
;
268 n
->neigh4reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
269 s
->neigh4reachabletime
: os
->neigh4reachabletime
;
270 n
->neigh6reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
271 s
->neigh6reachabletime
: os
->neigh6reachabletime
;
272 n
->neigh4gcstaletime
= s
->flags
& DEV_OPT_NEIGHGCSTALETIME
?
273 s
->neigh4gcstaletime
: os
->neigh4gcstaletime
;
274 n
->neigh6gcstaletime
= s
->flags
& DEV_OPT_NEIGHGCSTALETIME
?
275 s
->neigh6gcstaletime
: os
->neigh6gcstaletime
;
276 n
->neigh4locktime
= s
->flags
& DEV_OPT_NEIGHLOCKTIME
?
277 s
->neigh4locktime
: os
->neigh4locktime
;
278 n
->dadtransmits
= s
->flags
& DEV_OPT_DADTRANSMITS
?
279 s
->dadtransmits
: os
->dadtransmits
;
280 n
->multicast
= s
->flags
& DEV_OPT_MULTICAST
?
281 s
->multicast
: os
->multicast
;
282 n
->multicast_to_unicast
= s
->multicast_to_unicast
;
283 n
->multicast_router
= s
->multicast_router
;
284 n
->multicast_fast_leave
= s
->multicast_fast_leave
;
285 n
->learning
= s
->learning
;
286 n
->unicast_flood
= s
->unicast_flood
;
287 n
->sendredirects
= s
->flags
& DEV_OPT_SENDREDIRECTS
?
288 s
->sendredirects
: os
->sendredirects
;
289 n
->drop_v4_unicast_in_l2_multicast
= s
->flags
& DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
?
290 s
->drop_v4_unicast_in_l2_multicast
: os
->drop_v4_unicast_in_l2_multicast
;
291 n
->drop_v6_unicast_in_l2_multicast
= s
->flags
& DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
?
292 s
->drop_v6_unicast_in_l2_multicast
: os
->drop_v6_unicast_in_l2_multicast
;
293 n
->drop_gratuitous_arp
= s
->flags
& DEV_OPT_DROP_GRATUITOUS_ARP
?
294 s
->drop_gratuitous_arp
: os
->drop_gratuitous_arp
;
295 n
->drop_unsolicited_na
= s
->flags
& DEV_OPT_DROP_UNSOLICITED_NA
?
296 s
->drop_unsolicited_na
: os
->drop_unsolicited_na
;
297 n
->arp_accept
= s
->flags
& DEV_OPT_ARP_ACCEPT
?
298 s
->arp_accept
: os
->arp_accept
;
299 n
->auth
= s
->flags
& DEV_OPT_AUTH
? s
->auth
: os
->auth
;
300 n
->speed
= s
->flags
& DEV_OPT_SPEED
? s
->speed
: os
->speed
;
301 n
->duplex
= s
->flags
& DEV_OPT_DUPLEX
? s
->duplex
: os
->duplex
;
302 n
->pause
= s
->flags
& DEV_OPT_PAUSE
? s
->pause
: os
->pause
;
303 n
->asym_pause
= s
->flags
& DEV_OPT_ASYM_PAUSE
? s
->asym_pause
: os
->asym_pause
;
304 n
->rxpause
= s
->flags
& DEV_OPT_RXPAUSE
? s
->rxpause
: os
->rxpause
;
305 n
->txpause
= s
->flags
& DEV_OPT_TXPAUSE
? s
->txpause
: os
->txpause
;
306 n
->autoneg
= s
->flags
& DEV_OPT_AUTONEG
? s
->autoneg
: os
->autoneg
;
307 n
->gro
= s
->flags
& DEV_OPT_GRO
? s
->gro
: os
->gro
;
308 n
->eee
= s
->flags
& DEV_OPT_EEE
? s
->eee
: os
->eee
;
309 n
->master_ifindex
= s
->flags
& DEV_OPT_MASTER
? s
->master_ifindex
: os
->master_ifindex
;
310 n
->flags
= s
->flags
| os
->flags
| os
->valid_flags
;
313 static bool device_fill_vlan_range(struct device_vlan_range
*r
, const char *val
)
315 unsigned long cur_start
, cur_end
;
318 cur_start
= strtoul(val
, &sep
, 0);
322 cur_end
= strtoul(sep
+ 1, &sep
, 0);
323 if (*sep
|| cur_end
< cur_start
)
326 r
->start
= cur_start
;
333 device_set_extra_vlans(struct device
*dev
, struct blob_attr
*data
)
335 struct blob_attr
*cur
;
339 dev
->n_extra_vlan
= 0;
343 n_vlans
= blobmsg_check_array(data
, BLOBMSG_TYPE_STRING
);
347 dev
->extra_vlan
= realloc(dev
->extra_vlan
, n_vlans
* sizeof(*dev
->extra_vlan
));
348 blobmsg_for_each_attr(cur
, data
, rem
)
349 if (device_fill_vlan_range(&dev
->extra_vlan
[dev
->n_extra_vlan
],
350 blobmsg_get_string(cur
)))
355 device_init_settings(struct device
*dev
, struct blob_attr
**tb
)
357 struct device_settings
*s
= &dev
->settings
;
358 struct blob_attr
*cur
;
359 struct ether_addr
*ea
;
360 bool disabled
= false;
363 s
->flags
&= DEV_OPT_ISOLATE
;
366 if ((cur
= tb
[DEV_ATTR_ENABLED
]))
367 disabled
= !blobmsg_get_bool(cur
);
369 if ((cur
= tb
[DEV_ATTR_MTU
]) && blobmsg_get_u32(cur
) >= 68) {
370 s
->mtu
= blobmsg_get_u32(cur
);
371 s
->flags
|= DEV_OPT_MTU
;
374 if ((cur
= tb
[DEV_ATTR_MTU6
]) && blobmsg_get_u32(cur
) >= 1280) {
375 s
->mtu6
= blobmsg_get_u32(cur
);
376 s
->flags
|= DEV_OPT_MTU6
;
379 if ((cur
= tb
[DEV_ATTR_TXQUEUELEN
])) {
380 s
->txqueuelen
= blobmsg_get_u32(cur
);
381 s
->flags
|= DEV_OPT_TXQUEUELEN
;
384 if ((cur
= tb
[DEV_ATTR_MACADDR
])) {
385 ea
= ether_aton(blobmsg_data(cur
));
387 memcpy(s
->macaddr
, ea
, 6);
388 s
->flags
|= DEV_OPT_MACADDR
;
392 if ((cur
= tb
[DEV_ATTR_IPV6
])) {
393 s
->ipv6
= blobmsg_get_bool(cur
);
394 s
->flags
|= DEV_OPT_IPV6
;
397 if ((cur
= tb
[DEV_ATTR_IP6SEGMENTROUTING
])) {
398 s
->ip6segmentrouting
= blobmsg_get_bool(cur
);
399 s
->flags
|= DEV_OPT_IP6SEGMENTROUTING
;
402 if ((cur
= tb
[DEV_ATTR_PROMISC
])) {
403 s
->promisc
= blobmsg_get_bool(cur
);
404 s
->flags
|= DEV_OPT_PROMISC
;
407 if ((cur
= tb
[DEV_ATTR_RPFILTER
])) {
408 if (system_resolve_rpfilter(blobmsg_data(cur
), &s
->rpfilter
))
409 s
->flags
|= DEV_OPT_RPFILTER
;
411 D(DEVICE
, "Failed to resolve rpfilter: %s", (char *) blobmsg_data(cur
));
414 if ((cur
= tb
[DEV_ATTR_ACCEPTLOCAL
])) {
415 s
->acceptlocal
= blobmsg_get_bool(cur
);
416 s
->flags
|= DEV_OPT_ACCEPTLOCAL
;
419 if ((cur
= tb
[DEV_ATTR_IGMPVERSION
])) {
420 s
->igmpversion
= blobmsg_get_u32(cur
);
421 if (s
->igmpversion
>= 1 && s
->igmpversion
<= 3)
422 s
->flags
|= DEV_OPT_IGMPVERSION
;
424 D(DEVICE
, "Failed to resolve igmpversion: %d", blobmsg_get_u32(cur
));
427 if ((cur
= tb
[DEV_ATTR_MLDVERSION
])) {
428 s
->mldversion
= blobmsg_get_u32(cur
);
429 if (s
->mldversion
>= 1 && s
->mldversion
<= 2)
430 s
->flags
|= DEV_OPT_MLDVERSION
;
432 D(DEVICE
, "Failed to resolve mldversion: %d", blobmsg_get_u32(cur
));
435 if ((cur
= tb
[DEV_ATTR_NEIGHREACHABLETIME
])) {
436 s
->neigh6reachabletime
= s
->neigh4reachabletime
= blobmsg_get_u32(cur
);
437 s
->flags
|= DEV_OPT_NEIGHREACHABLETIME
;
440 if ((cur
= tb
[DEV_ATTR_NEIGHGCSTALETIME
])) {
441 s
->neigh6gcstaletime
= s
->neigh4gcstaletime
= blobmsg_get_u32(cur
);
442 s
->flags
|= DEV_OPT_NEIGHGCSTALETIME
;
445 if ((cur
= tb
[DEV_ATTR_NEIGHLOCKTIME
])) {
446 s
->neigh4locktime
= blobmsg_get_u32(cur
);
447 s
->flags
|= DEV_OPT_NEIGHLOCKTIME
;
450 if ((cur
= tb
[DEV_ATTR_DADTRANSMITS
])) {
451 s
->dadtransmits
= blobmsg_get_u32(cur
);
452 s
->flags
|= DEV_OPT_DADTRANSMITS
;
455 if ((cur
= tb
[DEV_ATTR_MULTICAST_TO_UNICAST
])) {
456 s
->multicast_to_unicast
= blobmsg_get_bool(cur
);
457 s
->flags
|= DEV_OPT_MULTICAST_TO_UNICAST
;
460 if ((cur
= tb
[DEV_ATTR_MULTICAST_ROUTER
])) {
461 s
->multicast_router
= blobmsg_get_u32(cur
);
462 if (s
->multicast_router
<= 2)
463 s
->flags
|= DEV_OPT_MULTICAST_ROUTER
;
465 D(DEVICE
, "Invalid value: %d - (Use 0: never, 1: learn, 2: always)", blobmsg_get_u32(cur
));
468 if ((cur
= tb
[DEV_ATTR_MULTICAST_FAST_LEAVE
])) {
469 s
->multicast_fast_leave
= blobmsg_get_bool(cur
);
470 s
->flags
|= DEV_OPT_MULTICAST_FAST_LEAVE
;
473 if ((cur
= tb
[DEV_ATTR_MULTICAST
])) {
474 s
->multicast
= blobmsg_get_bool(cur
);
475 s
->flags
|= DEV_OPT_MULTICAST
;
478 if ((cur
= tb
[DEV_ATTR_LEARNING
])) {
479 s
->learning
= blobmsg_get_bool(cur
);
480 s
->flags
|= DEV_OPT_LEARNING
;
483 if ((cur
= tb
[DEV_ATTR_UNICAST_FLOOD
])) {
484 s
->unicast_flood
= blobmsg_get_bool(cur
);
485 s
->flags
|= DEV_OPT_UNICAST_FLOOD
;
488 if ((cur
= tb
[DEV_ATTR_SENDREDIRECTS
])) {
489 s
->sendredirects
= blobmsg_get_bool(cur
);
490 s
->flags
|= DEV_OPT_SENDREDIRECTS
;
493 if ((cur
= tb
[DEV_ATTR_ISOLATE
])) {
494 s
->isolate
= blobmsg_get_bool(cur
);
495 s
->flags
|= DEV_OPT_ISOLATE
;
498 if ((cur
= tb
[DEV_ATTR_DROP_V4_UNICAST_IN_L2_MULTICAST
])) {
499 s
->drop_v4_unicast_in_l2_multicast
= blobmsg_get_bool(cur
);
500 s
->flags
|= DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
;
503 if ((cur
= tb
[DEV_ATTR_DROP_V6_UNICAST_IN_L2_MULTICAST
])) {
504 s
->drop_v6_unicast_in_l2_multicast
= blobmsg_get_bool(cur
);
505 s
->flags
|= DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
;
508 if ((cur
= tb
[DEV_ATTR_DROP_GRATUITOUS_ARP
])) {
509 s
->drop_gratuitous_arp
= blobmsg_get_bool(cur
);
510 s
->flags
|= DEV_OPT_DROP_GRATUITOUS_ARP
;
513 if ((cur
= tb
[DEV_ATTR_DROP_UNSOLICITED_NA
])) {
514 s
->drop_unsolicited_na
= blobmsg_get_bool(cur
);
515 s
->flags
|= DEV_OPT_DROP_UNSOLICITED_NA
;
518 if ((cur
= tb
[DEV_ATTR_ARP_ACCEPT
])) {
519 s
->arp_accept
= blobmsg_get_bool(cur
);
520 s
->flags
|= DEV_OPT_ARP_ACCEPT
;
523 if ((cur
= tb
[DEV_ATTR_AUTH
])) {
524 s
->auth
= blobmsg_get_bool(cur
);
525 s
->flags
|= DEV_OPT_AUTH
;
528 if ((cur
= tb
[DEV_ATTR_SPEED
])) {
529 s
->speed
= blobmsg_get_u32(cur
);
530 s
->flags
|= DEV_OPT_SPEED
;
533 if ((cur
= tb
[DEV_ATTR_DUPLEX
])) {
534 s
->duplex
= blobmsg_get_bool(cur
);
535 s
->flags
|= DEV_OPT_DUPLEX
;
538 if ((cur
= tb
[DEV_ATTR_PAUSE
])) {
539 s
->pause
= blobmsg_get_bool(cur
);
540 s
->flags
|= DEV_OPT_PAUSE
;
543 if ((cur
= tb
[DEV_ATTR_ASYM_PAUSE
])) {
544 s
->asym_pause
= blobmsg_get_bool(cur
);
545 s
->flags
|= DEV_OPT_ASYM_PAUSE
;
548 if ((cur
= tb
[DEV_ATTR_RXPAUSE
])) {
549 s
->rxpause
= blobmsg_get_bool(cur
);
550 s
->flags
|= DEV_OPT_RXPAUSE
;
553 if ((cur
= tb
[DEV_ATTR_TXPAUSE
])) {
554 s
->txpause
= blobmsg_get_bool(cur
);
555 s
->flags
|= DEV_OPT_TXPAUSE
;
558 if ((cur
= tb
[DEV_ATTR_AUTONEG
])) {
559 s
->autoneg
= blobmsg_get_bool(cur
);
560 s
->flags
|= DEV_OPT_AUTONEG
;
563 if ((cur
= tb
[DEV_ATTR_GRO
])) {
564 s
->gro
= blobmsg_get_bool(cur
);
565 s
->flags
|= DEV_OPT_GRO
;
568 if ((cur
= tb
[DEV_ATTR_MASTER
])) {
569 char *ifname
= blobmsg_get_string(cur
);
570 s
->master_ifindex
= if_nametoindex(ifname
);
571 s
->flags
|= DEV_OPT_MASTER
;
574 if ((cur
= tb
[DEV_ATTR_EEE
])) {
575 s
->eee
= blobmsg_get_bool(cur
);
576 s
->flags
|= DEV_OPT_EEE
;
579 /* Remember the settings present in UCI */
580 s
->valid_flags
= s
->flags
;
582 cur
= tb
[DEV_ATTR_AUTH_VLAN
];
583 free(dev
->config_auth_vlans
);
584 dev
->config_auth_vlans
= cur
? blob_memdup(cur
) : NULL
;
586 device_set_extra_vlans(dev
, tb
[DEV_ATTR_VLAN
]);
587 device_set_disabled(dev
, disabled
);
590 static void __init
dev_init(void)
592 avl_init(&devices
, avl_strcmp
, true, NULL
);
595 static int device_release_cb(void *ctx
, struct safe_list
*list
)
597 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
599 if (!dep
->dev
|| !dep
->claimed
)
606 static int device_broadcast_cb(void *ctx
, struct safe_list
*list
)
608 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
611 /* device might have been removed by an earlier callback */
620 void device_broadcast_event(struct device
*dev
, enum device_event ev
)
622 static const char * const event_names
[] = {
623 [DEV_EVENT_ADD
] = "add",
624 [DEV_EVENT_REMOVE
] = "remove",
625 [DEV_EVENT_UP
] = "up",
626 [DEV_EVENT_DOWN
] = "down",
627 [DEV_EVENT_AUTH_UP
] = "auth_up",
628 [DEV_EVENT_LINK_UP
] = "link_up",
629 [DEV_EVENT_LINK_DOWN
] = "link_down",
630 [DEV_EVENT_TOPO_CHANGE
] = "topo_change",
634 safe_list_for_each(&dev
->aliases
, device_broadcast_cb
, &dev_ev
);
635 safe_list_for_each(&dev
->users
, device_broadcast_cb
, &dev_ev
);
637 if (ev
>= ARRAY_SIZE(event_names
) || !event_names
[ev
] || !dev
->ifname
[0])
640 blob_buf_init(&b
, 0);
641 blobmsg_add_string(&b
, "name", dev
->ifname
);
642 blobmsg_add_u8(&b
, "auth_status", dev
->auth_status
);
643 blobmsg_add_u8(&b
, "present", dev
->present
);
644 blobmsg_add_u8(&b
, "active", dev
->active
);
645 blobmsg_add_u8(&b
, "link_active", dev
->link_active
);
646 netifd_ubus_device_notify(event_names
[ev
], b
.head
, -1);
650 device_fill_default_settings(struct device
*dev
)
652 struct device_settings
*s
= &dev
->settings
;
653 struct ether_addr
*ea
;
657 if (!(s
->flags
& DEV_OPT_MACADDR
)) {
658 ea
= config_get_default_macaddr(dev
->ifname
);
660 memcpy(s
->macaddr
, ea
, 6);
661 s
->flags
|= DEV_OPT_DEFAULT_MACADDR
;
665 if (!(s
->flags
& DEV_OPT_GRO
)) {
666 ret
= config_get_default_gro(dev
->ifname
);
669 s
->flags
|= DEV_OPT_GRO
;
673 if (!(s
->flags
& DEV_OPT_MASTER
)) {
674 master
= config_get_default_conduit(dev
->ifname
);
676 s
->master_ifindex
= if_nametoindex(master
);
677 s
->flags
|= DEV_OPT_MASTER
;
682 int device_claim(struct device_user
*dep
)
684 struct device
*dev
= dep
->dev
;
694 D(DEVICE
, "Claim %s %s, new active count: %d", dev
->type
->name
, dev
->ifname
, dev
->active
+ 1);
695 if (++dev
->active
!= 1)
698 device_broadcast_event(dev
, DEV_EVENT_SETUP
);
699 device_fill_default_settings(dev
);
701 /* Get ifindex for external claimed devices so a valid */
702 /* ifindex is in place avoiding possible race conditions */
703 device_set_ifindex(dev
, system_if_resolve(dev
));
707 system_if_get_settings(dev
, &dev
->orig_settings
);
709 ret
= dev
->set_state(dev
, true);
712 device_broadcast_event(dev
, DEV_EVENT_UP
);
714 D(DEVICE
, "claim %s %s failed: %d", dev
->type
->name
, dev
->ifname
, ret
);
716 dep
->claimed
= false;
722 void device_release(struct device_user
*dep
)
724 struct device
*dev
= dep
->dev
;
729 dep
->claimed
= false;
731 D(DEVICE
, "Release %s %s, new active count: %d", dev
->type
->name
, dev
->ifname
, dev
->active
);
732 assert(dev
->active
>= 0);
737 device_broadcast_event(dev
, DEV_EVENT_TEARDOWN
);
739 dev
->set_state(dev
, false);
744 device_broadcast_event(dev
, DEV_EVENT_DOWN
);
747 int device_check_state(struct device
*dev
)
749 if (!dev
->type
->check_state
)
750 return simple_device_type
.check_state(dev
);
752 return dev
->type
->check_state(dev
);
755 int device_init_virtual(struct device
*dev
, struct device_type
*type
, const char *name
)
760 D(DEVICE
, "Initialize device '%s'", name
? name
: "");
761 INIT_SAFE_LIST(&dev
->users
);
762 INIT_SAFE_LIST(&dev
->aliases
);
768 ret
= device_set_ifname(dev
, name
);
770 netifd_log_message(L_WARNING
, "Failed to initalize device '%s'\n", name
);
776 dev
->set_state
= set_device_state
;
781 int device_init(struct device
*dev
, struct device_type
*type
, const char *ifname
)
785 ret
= device_init_virtual(dev
, type
, ifname
);
789 dev
->avl
.key
= dev
->ifname
;
791 ret
= avl_insert(&devices
, &dev
->avl
);
795 system_if_clear_state(dev
);
800 static struct device
*
801 device_create_default(const char *name
, bool external
)
805 if (!external
&& system_if_force_external(name
))
808 D(DEVICE
, "Create simple device '%s'", name
);
809 dev
= calloc(1, sizeof(*dev
));
813 dev
->external
= external
;
814 dev
->set_state
= simple_device_set_state
;
816 if (device_init(dev
, &simple_device_type
, name
) < 0) {
822 dev
->default_config
= true;
824 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
826 device_check_state(dev
);
832 device_find(const char *name
)
836 return avl_find_element(&devices
, name
, dev
, avl
);
840 __device_get(const char *name
, int create
, bool check_vlan
)
844 dev
= avl_find_element(&devices
, name
, dev
, avl
);
846 if (!dev
&& check_vlan
&& strchr(name
, '.'))
847 return get_vlan_device_chain(name
, create
);
850 return device_alias_get(name
+ 1);
853 if (create
> 1 && !dev
->external
) {
854 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
855 dev
->external
= true;
856 device_set_present(dev
, true);
864 return device_create_default(name
, create
> 1);
868 device_delete(struct device
*dev
)
873 D(DEVICE
, "Delete device '%s' from list", dev
->ifname
);
874 avl_delete(&devices
, &dev
->avl
);
878 static int device_cleanup_cb(void *ctx
, struct safe_list
*list
)
880 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
882 dep
->cb(dep
, DEV_EVENT_REMOVE
);
888 void device_cleanup(struct device
*dev
)
890 D(DEVICE
, "Clean up device '%s'", dev
->ifname
);
891 safe_list_for_each(&dev
->users
, device_cleanup_cb
, NULL
);
892 safe_list_for_each(&dev
->aliases
, device_cleanup_cb
, NULL
);
896 static void __device_set_present(struct device
*dev
, bool state
, bool force
)
898 if (dev
->present
== state
&& !force
)
901 dev
->present
= state
;
902 device_broadcast_event(dev
, state
? DEV_EVENT_ADD
: DEV_EVENT_REMOVE
);
906 device_refresh_present(struct device
*dev
)
908 bool state
= dev
->sys_present
;
910 if (dev
->disabled
|| dev
->deferred
)
913 __device_set_present(dev
, state
, false);
917 device_set_auth_status(struct device
*dev
, bool value
, struct blob_attr
*vlans
)
921 else if (!blob_attr_equal(vlans
, dev
->auth_vlans
))
922 device_set_auth_status(dev
, false, NULL
);
924 free(dev
->auth_vlans
);
925 dev
->auth_vlans
= vlans
? blob_memdup(vlans
) : NULL
;
927 if (dev
->auth_status
== value
)
930 dev
->auth_status
= value
;
934 if (dev
->auth_status
) {
935 device_broadcast_event(dev
, DEV_EVENT_AUTH_UP
);
939 device_broadcast_event(dev
, DEV_EVENT_LINK_DOWN
);
940 if (!dev
->link_active
)
943 device_broadcast_event(dev
, DEV_EVENT_LINK_UP
);
946 void device_set_present(struct device
*dev
, bool state
)
948 if (dev
->sys_present
== state
)
951 D(DEVICE
, "%s '%s' %s present", dev
->type
->name
, dev
->ifname
, state
? "is now" : "is no longer" );
952 dev
->sys_present
= state
;
954 __device_set_present(dev
, state
, true);
956 device_refresh_present(dev
);
958 safe_list_for_each(&dev
->users
, device_release_cb
, NULL
);
961 void device_set_link(struct device
*dev
, bool state
)
963 if (dev
->link_active
== state
)
966 netifd_log_message(L_NOTICE
, "%s '%s' link is %s\n", dev
->type
->name
, dev
->ifname
, state
? "up" : "down" );
968 dev
->link_active
= state
;
970 dev
->auth_status
= false;
971 device_broadcast_event(dev
, state
? DEV_EVENT_LINK_UP
: DEV_EVENT_LINK_DOWN
);
974 void device_set_ifindex(struct device
*dev
, int ifindex
)
976 if (dev
->ifindex
== ifindex
)
979 dev
->ifindex
= ifindex
;
980 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFINDEX
);
983 int device_set_ifname(struct device
*dev
, const char *name
)
987 if (!strcmp(dev
->ifname
, name
))
990 if (strlen(name
) > sizeof(dev
->ifname
) - 1) {
991 netifd_log_message(L_WARNING
, "Cannot set device name: '%s' is longer than max size %zd\n",
992 name
, sizeof(dev
->ifname
) - 1);
997 avl_delete(&devices
, &dev
->avl
);
999 strcpy(dev
->ifname
, name
);
1002 ret
= avl_insert(&devices
, &dev
->avl
);
1005 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFNAME
);
1010 static int device_refcount(struct device
*dev
)
1012 struct list_head
*list
;
1015 list_for_each(list
, &dev
->users
.list
)
1018 list_for_each(list
, &dev
->aliases
.list
)
1025 __device_add_user(struct device_user
*dep
, struct device
*dev
)
1027 struct safe_list
*head
;
1032 head
= &dev
->aliases
;
1036 safe_list_add(&dep
->list
, head
);
1037 D(DEVICE
, "Add user for device '%s', refcount=%d", dev
->ifname
, device_refcount(dev
));
1039 if (dep
->cb
&& dev
->present
) {
1040 dep
->cb(dep
, DEV_EVENT_ADD
);
1042 dep
->cb(dep
, DEV_EVENT_UP
);
1044 if (dev
->link_active
)
1045 dep
->cb(dep
, DEV_EVENT_LINK_UP
);
1049 void device_add_user(struct device_user
*dep
, struct device
*dev
)
1051 if (dep
->dev
== dev
)
1055 device_remove_user(dep
);
1060 __device_add_user(dep
, dev
);
1064 device_free(struct device
*dev
)
1067 free(dev
->auth_vlans
);
1069 device_cleanup(dev
);
1070 free(dev
->config_auth_vlans
);
1071 free(dev
->extra_vlan
);
1072 dev
->type
->free(dev
);
1077 __device_free_unused(struct uloop_timeout
*timeout
)
1079 struct device
*dev
, *tmp
;
1081 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1082 if (!safe_list_empty(&dev
->users
) ||
1083 !safe_list_empty(&dev
->aliases
) ||
1084 dev
->current_config
)
1091 void device_free_unused(void)
1093 static struct uloop_timeout free_timer
= {
1094 .cb
= __device_free_unused
,
1097 uloop_timeout_set(&free_timer
, 1);
1100 void device_remove_user(struct device_user
*dep
)
1102 struct device
*dev
= dep
->dev
;
1107 dep
->hotplug
= false;
1109 device_release(dep
);
1111 safe_list_del(&dep
->list
);
1113 D(DEVICE
, "Remove user for device '%s', refcount=%d", dev
->ifname
, device_refcount(dev
));
1114 device_free_unused();
1118 device_init_pending(void)
1120 struct device
*dev
, *tmp
;
1122 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1123 if (!dev
->config_pending
)
1126 dev
->type
->config_init(dev
);
1127 dev
->config_pending
= false;
1128 device_check_state(dev
);
1133 device_check_ip6segmentrouting(void)
1136 bool ip6segmentrouting
= false;
1138 avl_for_each_element(&devices
, dev
, avl
)
1139 ip6segmentrouting
|= dev
->settings
.ip6segmentrouting
;
1141 return ip6segmentrouting
;
1144 static enum dev_change_type
1145 device_set_config(struct device
*dev
, struct device_type
*type
,
1146 struct blob_attr
*attr
)
1148 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
1149 const struct uci_blob_param_list
*cfg
= type
->config_params
;
1151 if (type
!= dev
->type
)
1152 return DEV_CONFIG_RECREATE
;
1154 if (dev
->type
->reload
)
1155 return dev
->type
->reload(dev
, attr
);
1157 if (uci_blob_check_equal(dev
->config
, attr
, cfg
))
1158 return DEV_CONFIG_NO_CHANGE
;
1160 if (cfg
== &device_attr_list
) {
1161 memset(tb
, 0, sizeof(tb
));
1164 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
,
1165 blob_data(attr
), blob_len(attr
));
1167 device_init_settings(dev
, tb
);
1168 return DEV_CONFIG_RESTART
;
1170 return DEV_CONFIG_RECREATE
;
1173 enum dev_change_type
1174 device_apply_config(struct device
*dev
, struct device_type
*type
,
1175 struct blob_attr
*config
)
1177 enum dev_change_type change
;
1179 change
= device_set_config(dev
, type
, config
);
1180 if (dev
->external
) {
1181 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
1182 change
= DEV_CONFIG_APPLIED
;
1186 case DEV_CONFIG_RESTART
:
1187 case DEV_CONFIG_APPLIED
:
1188 D(DEVICE
, "Device '%s': config applied", dev
->ifname
);
1189 config
= blob_memdup(config
);
1191 dev
->config
= config
;
1192 if (change
== DEV_CONFIG_RESTART
&& dev
->present
) {
1195 device_set_present(dev
, false);
1196 if (dev
->active
&& !dev
->external
) {
1197 ret
= dev
->set_state(dev
, false);
1199 ret
= dev
->set_state(dev
, true);
1202 device_set_present(dev
, true);
1205 case DEV_CONFIG_NO_CHANGE
:
1206 D(DEVICE
, "Device '%s': no configuration change", dev
->ifname
);
1208 case DEV_CONFIG_RECREATE
:
1216 device_replace(struct device
*dev
, struct device
*odev
)
1218 struct device_user
*dep
;
1222 device_set_present(odev
, false);
1224 while (!list_empty(&odev
->users
.list
)) {
1225 dep
= list_first_entry(&odev
->users
.list
, struct device_user
, list
.list
);
1226 device_release(dep
);
1230 safe_list_del(&dep
->list
);
1231 __device_add_user(dep
, dev
);
1239 device_reset_config(void)
1243 avl_for_each_element(&devices
, dev
, avl
)
1244 dev
->current_config
= false;
1248 device_reset_old(void)
1250 struct device
*dev
, *tmp
, *ndev
;
1252 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1253 if (dev
->current_config
|| dev
->default_config
)
1256 if (dev
->type
!= &simple_device_type
)
1259 ndev
= device_create_default(dev
->ifname
, dev
->external
);
1263 device_replace(ndev
, dev
);
1268 device_create(const char *name
, struct device_type
*type
,
1269 struct blob_attr
*config
)
1271 struct device
*odev
= NULL
, *dev
;
1272 enum dev_change_type change
;
1274 odev
= device_find(name
);
1276 odev
->current_config
= true;
1277 change
= device_apply_config(odev
, type
, config
);
1279 case DEV_CONFIG_RECREATE
:
1280 D(DEVICE
, "Device '%s': recreate device", odev
->ifname
);
1281 device_delete(odev
);
1287 D(DEVICE
, "Create new device '%s' (%s)", name
, type
->name
);
1289 config
= blob_memdup(config
);
1293 dev
= type
->create(name
, type
, config
);
1297 dev
->current_config
= true;
1298 dev
->config
= config
;
1300 device_replace(dev
, odev
);
1302 if (!config_init
&& dev
->config_pending
) {
1303 type
->config_init(dev
);
1304 dev
->config_pending
= false;
1307 device_check_state(dev
);
1313 device_dump_status(struct blob_buf
*b
, struct device
*dev
)
1315 struct device_settings st
;
1319 avl_for_each_element(&devices
, dev
, avl
) {
1322 c
= blobmsg_open_table(b
, dev
->ifname
);
1323 device_dump_status(b
, dev
);
1324 blobmsg_close_table(b
, c
);
1330 blobmsg_add_u8(b
, "external", dev
->external
);
1331 blobmsg_add_u8(b
, "present", dev
->present
);
1332 blobmsg_add_string(b
, "type", dev
->type
->name
);
1337 blobmsg_add_u8(b
, "up", !!dev
->active
);
1338 blobmsg_add_u8(b
, "carrier", !!dev
->link_active
);
1339 blobmsg_add_u8(b
, "auth_status", !!dev
->auth_status
);
1341 if (dev
->type
->dump_info
)
1342 dev
->type
->dump_info(dev
, b
);
1344 system_if_dump_info(dev
, b
);
1347 device_merge_settings(dev
, &st
);
1348 if (st
.flags
& DEV_OPT_MASTER
) {
1349 char buf
[64], *devname
;
1351 devname
= if_indextoname(st
.master_ifindex
, buf
);
1353 blobmsg_add_string(b
, "conduit", devname
);
1355 if (st
.flags
& DEV_OPT_MTU
)
1356 blobmsg_add_u32(b
, "mtu", st
.mtu
);
1357 if (st
.flags
& DEV_OPT_MTU6
)
1358 blobmsg_add_u32(b
, "mtu6", st
.mtu6
);
1359 if (st
.flags
& DEV_OPT_MACADDR
)
1360 blobmsg_add_string(b
, "macaddr", format_macaddr(st
.macaddr
));
1361 if (st
.flags
& DEV_OPT_TXQUEUELEN
)
1362 blobmsg_add_u32(b
, "txqueuelen", st
.txqueuelen
);
1363 if (st
.flags
& DEV_OPT_IPV6
)
1364 blobmsg_add_u8(b
, "ipv6", st
.ipv6
);
1365 if (st
.flags
& DEV_OPT_IP6SEGMENTROUTING
)
1366 blobmsg_add_u8(b
, "ip6segmentrouting", st
.ip6segmentrouting
);
1367 if (st
.flags
& DEV_OPT_PROMISC
)
1368 blobmsg_add_u8(b
, "promisc", st
.promisc
);
1369 if (st
.flags
& DEV_OPT_RPFILTER
)
1370 blobmsg_add_u32(b
, "rpfilter", st
.rpfilter
);
1371 if (st
.flags
& DEV_OPT_ACCEPTLOCAL
)
1372 blobmsg_add_u8(b
, "acceptlocal", st
.acceptlocal
);
1373 if (st
.flags
& DEV_OPT_IGMPVERSION
)
1374 blobmsg_add_u32(b
, "igmpversion", st
.igmpversion
);
1375 if (st
.flags
& DEV_OPT_MLDVERSION
)
1376 blobmsg_add_u32(b
, "mldversion", st
.mldversion
);
1377 if (st
.flags
& DEV_OPT_NEIGHREACHABLETIME
) {
1378 blobmsg_add_u32(b
, "neigh4reachabletime", st
.neigh4reachabletime
);
1379 blobmsg_add_u32(b
, "neigh6reachabletime", st
.neigh6reachabletime
);
1381 if (st
.flags
& DEV_OPT_NEIGHGCSTALETIME
) {
1382 blobmsg_add_u32(b
, "neigh4gcstaletime", st
.neigh4gcstaletime
);
1383 blobmsg_add_u32(b
, "neigh6gcstaletime", st
.neigh6gcstaletime
);
1385 if (st
.flags
& DEV_OPT_NEIGHLOCKTIME
)
1386 blobmsg_add_u32(b
, "neigh4locktime", st
.neigh4locktime
);
1387 if (st
.flags
& DEV_OPT_DADTRANSMITS
)
1388 blobmsg_add_u32(b
, "dadtransmits", st
.dadtransmits
);
1389 if (st
.flags
& DEV_OPT_MULTICAST_TO_UNICAST
)
1390 blobmsg_add_u8(b
, "multicast_to_unicast", st
.multicast_to_unicast
);
1391 if (st
.flags
& DEV_OPT_MULTICAST_ROUTER
)
1392 blobmsg_add_u32(b
, "multicast_router", st
.multicast_router
);
1393 if (st
.flags
& DEV_OPT_MULTICAST_FAST_LEAVE
)
1394 blobmsg_add_u8(b
, "multicast_fast_leave", st
.multicast_fast_leave
);
1395 if (st
.flags
& DEV_OPT_MULTICAST
)
1396 blobmsg_add_u8(b
, "multicast", st
.multicast
);
1397 if (st
.flags
& DEV_OPT_LEARNING
)
1398 blobmsg_add_u8(b
, "learning", st
.learning
);
1399 if (st
.flags
& DEV_OPT_UNICAST_FLOOD
)
1400 blobmsg_add_u8(b
, "unicast_flood", st
.unicast_flood
);
1401 if (st
.flags
& DEV_OPT_SENDREDIRECTS
)
1402 blobmsg_add_u8(b
, "sendredirects", st
.sendredirects
);
1403 if (st
.flags
& DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
)
1404 blobmsg_add_u8(b
, "drop_v4_unicast_in_l2_multicast", st
.drop_v4_unicast_in_l2_multicast
);
1405 if (st
.flags
& DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
)
1406 blobmsg_add_u8(b
, "drop_v6_unicast_in_l2_multicast", st
.drop_v6_unicast_in_l2_multicast
);
1407 if (st
.flags
& DEV_OPT_DROP_GRATUITOUS_ARP
)
1408 blobmsg_add_u8(b
, "drop_gratuitous_arp", st
.drop_gratuitous_arp
);
1409 if (st
.flags
& DEV_OPT_DROP_UNSOLICITED_NA
)
1410 blobmsg_add_u8(b
, "drop_unsolicited_na", st
.drop_unsolicited_na
);
1411 if (st
.flags
& DEV_OPT_ARP_ACCEPT
)
1412 blobmsg_add_u8(b
, "arp_accept", st
.arp_accept
);
1413 if (st
.flags
& DEV_OPT_AUTH
)
1414 blobmsg_add_u8(b
, "auth", st
.auth
);
1415 if (st
.flags
& DEV_OPT_GRO
)
1416 blobmsg_add_u8(b
, "gro", st
.gro
);
1417 if (st
.flags
& DEV_OPT_EEE
)
1418 blobmsg_add_u8(b
, "eee", st
.eee
);
1421 s
= blobmsg_open_table(b
, "statistics");
1422 if (dev
->type
->dump_stats
)
1423 dev
->type
->dump_stats(dev
, b
);
1425 system_if_dump_stats(dev
, b
);
1426 blobmsg_close_table(b
, s
);
1429 static void __init
simple_device_type_init(void)
1431 device_type_add(&simple_device_type
);
1434 void device_hotplug_event(const char *name
, bool add
)
1438 wireless_device_hotplug_event(name
, add
);
1440 dev
= device_find(name
);
1441 if (!dev
|| dev
->type
!= &simple_device_type
)
1444 device_set_present(dev
, add
);