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
},
79 const struct uci_blob_param_list device_attr_list
= {
80 .n_params
= __DEV_ATTR_MAX
,
84 static int __devlock
= 0;
86 int device_type_add(struct device_type
*devtype
)
88 if (device_type_get(devtype
->name
)) {
89 netifd_log_message(L_WARNING
, "Device handler '%s' already exists\n",
94 netifd_log_message(L_NOTICE
, "Added device handler type: %s\n",
97 list_add(&devtype
->list
, &devtypes
);
102 device_type_get(const char *tname
)
104 struct device_type
*cur
;
106 list_for_each_entry(cur
, &devtypes
, list
)
107 if (!strcmp(cur
->name
, tname
))
113 static int device_vlan_len(struct kvlist
*kv
, const void *data
)
115 return sizeof(unsigned int);
118 void device_vlan_update(bool done
)
122 avl_for_each_element(&devices
, dev
, avl
) {
123 if (!dev
->vlans
.update
)
127 if (dev
->vlan_aliases
.get_len
)
128 kvlist_free(&dev
->vlan_aliases
);
130 kvlist_init(&dev
->vlan_aliases
, device_vlan_len
);
131 vlist_update(&dev
->vlans
);
133 vlist_flush(&dev
->vlans
);
135 if (dev
->type
->vlan_update
)
136 dev
->type
->vlan_update(dev
);
141 void device_stp_init(void)
145 avl_for_each_element(&devices
, dev
, avl
) {
146 if (!dev
->type
->stp_init
)
149 dev
->type
->stp_init(dev
);
153 static int set_device_state(struct device
*dev
, bool state
)
156 /* Get ifindex for all devices being enabled so a valid */
157 /* ifindex is in place avoiding possible race conditions */
158 device_set_ifindex(dev
, system_if_resolve(dev
));
162 system_if_get_settings(dev
, &dev
->orig_settings
);
163 /* Only keep orig settings based on what needs to be set */
164 dev
->orig_settings
.valid_flags
= dev
->orig_settings
.flags
;
165 dev
->orig_settings
.flags
&= dev
->settings
.flags
;
166 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
170 system_if_apply_settings_after_up(dev
, &dev
->settings
);
173 system_if_apply_settings(dev
, &dev
->orig_settings
, dev
->orig_settings
.flags
);
180 simple_device_set_state(struct device
*dev
, bool state
)
185 pdev
= dev
->parent
.dev
;
186 if (state
&& !pdev
) {
187 pdev
= system_if_get_parent(dev
);
189 device_add_user(&dev
->parent
, pdev
);
194 ret
= device_claim(&dev
->parent
);
196 device_release(&dev
->parent
);
201 return set_device_state(dev
, state
);
204 static struct device
*
205 simple_device_create(const char *name
, struct device_type
*devtype
,
206 struct blob_attr
*attr
)
208 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
209 struct device
*dev
= NULL
;
211 /* device type is unused for simple devices */
214 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
, blob_data(attr
), blob_len(attr
));
215 dev
= device_get(name
, true);
219 dev
->set_state
= simple_device_set_state
;
220 device_init_settings(dev
, tb
);
225 static void simple_device_free(struct device
*dev
)
228 device_remove_user(&dev
->parent
);
232 struct device_type simple_device_type
= {
233 .name
= "Network device",
234 .config_params
= &device_attr_list
,
236 .create
= simple_device_create
,
237 .check_state
= system_if_check
,
238 .free
= simple_device_free
,
242 device_merge_settings(struct device
*dev
, struct device_settings
*n
)
244 struct device_settings
*os
= &dev
->orig_settings
;
245 struct device_settings
*s
= &dev
->settings
;
247 memset(n
, 0, sizeof(*n
));
248 n
->mtu
= s
->flags
& DEV_OPT_MTU
? s
->mtu
: os
->mtu
;
249 n
->mtu6
= s
->flags
& DEV_OPT_MTU6
? s
->mtu6
: os
->mtu6
;
250 n
->txqueuelen
= s
->flags
& DEV_OPT_TXQUEUELEN
?
251 s
->txqueuelen
: os
->txqueuelen
;
253 (s
->flags
& (DEV_OPT_MACADDR
|DEV_OPT_DEFAULT_MACADDR
) ? s
->macaddr
: os
->macaddr
),
255 n
->ipv6
= s
->flags
& DEV_OPT_IPV6
? s
->ipv6
: os
->ipv6
;
256 n
->ip6segmentrouting
= s
->flags
& DEV_OPT_IP6SEGMENTROUTING
? s
->ip6segmentrouting
: os
->ip6segmentrouting
;
257 n
->promisc
= s
->flags
& DEV_OPT_PROMISC
? s
->promisc
: os
->promisc
;
258 n
->rpfilter
= s
->flags
& DEV_OPT_RPFILTER
? s
->rpfilter
: os
->rpfilter
;
259 n
->acceptlocal
= s
->flags
& DEV_OPT_ACCEPTLOCAL
? s
->acceptlocal
: os
->acceptlocal
;
260 n
->igmpversion
= s
->flags
& DEV_OPT_IGMPVERSION
? s
->igmpversion
: os
->igmpversion
;
261 n
->mldversion
= s
->flags
& DEV_OPT_MLDVERSION
? s
->mldversion
: os
->mldversion
;
262 n
->neigh4reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
263 s
->neigh4reachabletime
: os
->neigh4reachabletime
;
264 n
->neigh6reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
265 s
->neigh6reachabletime
: os
->neigh6reachabletime
;
266 n
->neigh4gcstaletime
= s
->flags
& DEV_OPT_NEIGHGCSTALETIME
?
267 s
->neigh4gcstaletime
: os
->neigh4gcstaletime
;
268 n
->neigh6gcstaletime
= s
->flags
& DEV_OPT_NEIGHGCSTALETIME
?
269 s
->neigh6gcstaletime
: os
->neigh6gcstaletime
;
270 n
->neigh4locktime
= s
->flags
& DEV_OPT_NEIGHLOCKTIME
?
271 s
->neigh4locktime
: os
->neigh4locktime
;
272 n
->dadtransmits
= s
->flags
& DEV_OPT_DADTRANSMITS
?
273 s
->dadtransmits
: os
->dadtransmits
;
274 n
->multicast
= s
->flags
& DEV_OPT_MULTICAST
?
275 s
->multicast
: os
->multicast
;
276 n
->multicast_to_unicast
= s
->multicast_to_unicast
;
277 n
->multicast_router
= s
->multicast_router
;
278 n
->multicast_fast_leave
= s
->multicast_fast_leave
;
279 n
->learning
= s
->learning
;
280 n
->unicast_flood
= s
->unicast_flood
;
281 n
->sendredirects
= s
->flags
& DEV_OPT_SENDREDIRECTS
?
282 s
->sendredirects
: os
->sendredirects
;
283 n
->drop_v4_unicast_in_l2_multicast
= s
->flags
& DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
?
284 s
->drop_v4_unicast_in_l2_multicast
: os
->drop_v4_unicast_in_l2_multicast
;
285 n
->drop_v6_unicast_in_l2_multicast
= s
->flags
& DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
?
286 s
->drop_v6_unicast_in_l2_multicast
: os
->drop_v6_unicast_in_l2_multicast
;
287 n
->drop_gratuitous_arp
= s
->flags
& DEV_OPT_DROP_GRATUITOUS_ARP
?
288 s
->drop_gratuitous_arp
: os
->drop_gratuitous_arp
;
289 n
->drop_unsolicited_na
= s
->flags
& DEV_OPT_DROP_UNSOLICITED_NA
?
290 s
->drop_unsolicited_na
: os
->drop_unsolicited_na
;
291 n
->arp_accept
= s
->flags
& DEV_OPT_ARP_ACCEPT
?
292 s
->arp_accept
: os
->arp_accept
;
293 n
->auth
= s
->flags
& DEV_OPT_AUTH
? s
->auth
: os
->auth
;
294 n
->speed
= s
->flags
& DEV_OPT_SPEED
? s
->speed
: os
->speed
;
295 n
->duplex
= s
->flags
& DEV_OPT_DUPLEX
? s
->duplex
: os
->duplex
;
296 n
->pause
= s
->flags
& DEV_OPT_PAUSE
? s
->pause
: os
->pause
;
297 n
->asym_pause
= s
->flags
& DEV_OPT_ASYM_PAUSE
? s
->asym_pause
: os
->asym_pause
;
298 n
->rxpause
= s
->flags
& DEV_OPT_RXPAUSE
? s
->rxpause
: os
->rxpause
;
299 n
->txpause
= s
->flags
& DEV_OPT_TXPAUSE
? s
->txpause
: os
->txpause
;
300 n
->autoneg
= s
->flags
& DEV_OPT_AUTONEG
? s
->autoneg
: os
->autoneg
;
301 n
->gro
= s
->flags
& DEV_OPT_GRO
? s
->gro
: os
->gro
;
302 n
->master_ifindex
= s
->flags
& DEV_OPT_MASTER
? s
->master_ifindex
: os
->master_ifindex
;
303 n
->flags
= s
->flags
| os
->flags
| os
->valid_flags
;
306 static bool device_fill_vlan_range(struct device_vlan_range
*r
, const char *val
)
308 unsigned long cur_start
, cur_end
;
311 cur_start
= strtoul(val
, &sep
, 0);
315 cur_end
= strtoul(sep
+ 1, &sep
, 0);
316 if (*sep
|| cur_end
< cur_start
)
319 r
->start
= cur_start
;
326 device_set_extra_vlans(struct device
*dev
, struct blob_attr
*data
)
328 struct blob_attr
*cur
;
332 dev
->n_extra_vlan
= 0;
336 n_vlans
= blobmsg_check_array(data
, BLOBMSG_TYPE_STRING
);
340 dev
->extra_vlan
= realloc(dev
->extra_vlan
, n_vlans
* sizeof(*dev
->extra_vlan
));
341 blobmsg_for_each_attr(cur
, data
, rem
)
342 if (device_fill_vlan_range(&dev
->extra_vlan
[dev
->n_extra_vlan
],
343 blobmsg_get_string(cur
)))
348 device_init_settings(struct device
*dev
, struct blob_attr
**tb
)
350 struct device_settings
*s
= &dev
->settings
;
351 struct blob_attr
*cur
;
352 struct ether_addr
*ea
;
353 bool disabled
= false;
356 if ((cur
= tb
[DEV_ATTR_ENABLED
]))
357 disabled
= !blobmsg_get_bool(cur
);
359 if ((cur
= tb
[DEV_ATTR_MTU
]) && blobmsg_get_u32(cur
) >= 68) {
360 s
->mtu
= blobmsg_get_u32(cur
);
361 s
->flags
|= DEV_OPT_MTU
;
364 if ((cur
= tb
[DEV_ATTR_MTU6
]) && blobmsg_get_u32(cur
) >= 1280) {
365 s
->mtu6
= blobmsg_get_u32(cur
);
366 s
->flags
|= DEV_OPT_MTU6
;
369 if ((cur
= tb
[DEV_ATTR_TXQUEUELEN
])) {
370 s
->txqueuelen
= blobmsg_get_u32(cur
);
371 s
->flags
|= DEV_OPT_TXQUEUELEN
;
374 if ((cur
= tb
[DEV_ATTR_MACADDR
])) {
375 ea
= ether_aton(blobmsg_data(cur
));
377 memcpy(s
->macaddr
, ea
, 6);
378 s
->flags
|= DEV_OPT_MACADDR
;
382 if ((cur
= tb
[DEV_ATTR_IPV6
])) {
383 s
->ipv6
= blobmsg_get_bool(cur
);
384 s
->flags
|= DEV_OPT_IPV6
;
387 if ((cur
= tb
[DEV_ATTR_IP6SEGMENTROUTING
])) {
388 s
->ip6segmentrouting
= blobmsg_get_bool(cur
);
389 s
->flags
|= DEV_OPT_IP6SEGMENTROUTING
;
392 if ((cur
= tb
[DEV_ATTR_PROMISC
])) {
393 s
->promisc
= blobmsg_get_bool(cur
);
394 s
->flags
|= DEV_OPT_PROMISC
;
397 if ((cur
= tb
[DEV_ATTR_RPFILTER
])) {
398 if (system_resolve_rpfilter(blobmsg_data(cur
), &s
->rpfilter
))
399 s
->flags
|= DEV_OPT_RPFILTER
;
401 DPRINTF("Failed to resolve rpfilter: %s\n", (char *) blobmsg_data(cur
));
404 if ((cur
= tb
[DEV_ATTR_ACCEPTLOCAL
])) {
405 s
->acceptlocal
= blobmsg_get_bool(cur
);
406 s
->flags
|= DEV_OPT_ACCEPTLOCAL
;
409 if ((cur
= tb
[DEV_ATTR_IGMPVERSION
])) {
410 s
->igmpversion
= blobmsg_get_u32(cur
);
411 if (s
->igmpversion
>= 1 && s
->igmpversion
<= 3)
412 s
->flags
|= DEV_OPT_IGMPVERSION
;
414 DPRINTF("Failed to resolve igmpversion: %d\n", blobmsg_get_u32(cur
));
417 if ((cur
= tb
[DEV_ATTR_MLDVERSION
])) {
418 s
->mldversion
= blobmsg_get_u32(cur
);
419 if (s
->mldversion
>= 1 && s
->mldversion
<= 2)
420 s
->flags
|= DEV_OPT_MLDVERSION
;
422 DPRINTF("Failed to resolve mldversion: %d\n", blobmsg_get_u32(cur
));
425 if ((cur
= tb
[DEV_ATTR_NEIGHREACHABLETIME
])) {
426 s
->neigh6reachabletime
= s
->neigh4reachabletime
= blobmsg_get_u32(cur
);
427 s
->flags
|= DEV_OPT_NEIGHREACHABLETIME
;
430 if ((cur
= tb
[DEV_ATTR_NEIGHGCSTALETIME
])) {
431 s
->neigh6gcstaletime
= s
->neigh4gcstaletime
= blobmsg_get_u32(cur
);
432 s
->flags
|= DEV_OPT_NEIGHGCSTALETIME
;
435 if ((cur
= tb
[DEV_ATTR_NEIGHLOCKTIME
])) {
436 s
->neigh4locktime
= blobmsg_get_u32(cur
);
437 s
->flags
|= DEV_OPT_NEIGHLOCKTIME
;
440 if ((cur
= tb
[DEV_ATTR_DADTRANSMITS
])) {
441 s
->dadtransmits
= blobmsg_get_u32(cur
);
442 s
->flags
|= DEV_OPT_DADTRANSMITS
;
445 if ((cur
= tb
[DEV_ATTR_MULTICAST_TO_UNICAST
])) {
446 s
->multicast_to_unicast
= blobmsg_get_bool(cur
);
447 s
->flags
|= DEV_OPT_MULTICAST_TO_UNICAST
;
450 if ((cur
= tb
[DEV_ATTR_MULTICAST_ROUTER
])) {
451 s
->multicast_router
= blobmsg_get_u32(cur
);
452 if (s
->multicast_router
<= 2)
453 s
->flags
|= DEV_OPT_MULTICAST_ROUTER
;
455 DPRINTF("Invalid value: %d - (Use 0: never, 1: learn, 2: always)\n", blobmsg_get_u32(cur
));
458 if ((cur
= tb
[DEV_ATTR_MULTICAST_FAST_LEAVE
])) {
459 s
->multicast_fast_leave
= blobmsg_get_bool(cur
);
460 s
->flags
|= DEV_OPT_MULTICAST_FAST_LEAVE
;
463 if ((cur
= tb
[DEV_ATTR_MULTICAST
])) {
464 s
->multicast
= blobmsg_get_bool(cur
);
465 s
->flags
|= DEV_OPT_MULTICAST
;
468 if ((cur
= tb
[DEV_ATTR_LEARNING
])) {
469 s
->learning
= blobmsg_get_bool(cur
);
470 s
->flags
|= DEV_OPT_LEARNING
;
473 if ((cur
= tb
[DEV_ATTR_UNICAST_FLOOD
])) {
474 s
->unicast_flood
= blobmsg_get_bool(cur
);
475 s
->flags
|= DEV_OPT_UNICAST_FLOOD
;
478 if ((cur
= tb
[DEV_ATTR_SENDREDIRECTS
])) {
479 s
->sendredirects
= blobmsg_get_bool(cur
);
480 s
->flags
|= DEV_OPT_SENDREDIRECTS
;
483 if ((cur
= tb
[DEV_ATTR_ISOLATE
])) {
484 s
->isolate
= blobmsg_get_bool(cur
);
485 s
->flags
|= DEV_OPT_ISOLATE
;
488 if ((cur
= tb
[DEV_ATTR_DROP_V4_UNICAST_IN_L2_MULTICAST
])) {
489 s
->drop_v4_unicast_in_l2_multicast
= blobmsg_get_bool(cur
);
490 s
->flags
|= DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
;
493 if ((cur
= tb
[DEV_ATTR_DROP_V6_UNICAST_IN_L2_MULTICAST
])) {
494 s
->drop_v6_unicast_in_l2_multicast
= blobmsg_get_bool(cur
);
495 s
->flags
|= DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
;
498 if ((cur
= tb
[DEV_ATTR_DROP_GRATUITOUS_ARP
])) {
499 s
->drop_gratuitous_arp
= blobmsg_get_bool(cur
);
500 s
->flags
|= DEV_OPT_DROP_GRATUITOUS_ARP
;
503 if ((cur
= tb
[DEV_ATTR_DROP_UNSOLICITED_NA
])) {
504 s
->drop_unsolicited_na
= blobmsg_get_bool(cur
);
505 s
->flags
|= DEV_OPT_DROP_UNSOLICITED_NA
;
508 if ((cur
= tb
[DEV_ATTR_ARP_ACCEPT
])) {
509 s
->arp_accept
= blobmsg_get_bool(cur
);
510 s
->flags
|= DEV_OPT_ARP_ACCEPT
;
513 if ((cur
= tb
[DEV_ATTR_AUTH
])) {
514 s
->auth
= blobmsg_get_bool(cur
);
515 s
->flags
|= DEV_OPT_AUTH
;
518 if ((cur
= tb
[DEV_ATTR_SPEED
])) {
519 s
->speed
= blobmsg_get_u32(cur
);
520 s
->flags
|= DEV_OPT_SPEED
;
523 if ((cur
= tb
[DEV_ATTR_DUPLEX
])) {
524 s
->duplex
= blobmsg_get_bool(cur
);
525 s
->flags
|= DEV_OPT_DUPLEX
;
528 if ((cur
= tb
[DEV_ATTR_PAUSE
])) {
529 s
->pause
= blobmsg_get_bool(cur
);
530 s
->flags
|= DEV_OPT_PAUSE
;
533 if ((cur
= tb
[DEV_ATTR_ASYM_PAUSE
])) {
534 s
->asym_pause
= blobmsg_get_bool(cur
);
535 s
->flags
|= DEV_OPT_ASYM_PAUSE
;
538 if ((cur
= tb
[DEV_ATTR_RXPAUSE
])) {
539 s
->rxpause
= blobmsg_get_bool(cur
);
540 s
->flags
|= DEV_OPT_RXPAUSE
;
543 if ((cur
= tb
[DEV_ATTR_TXPAUSE
])) {
544 s
->txpause
= blobmsg_get_bool(cur
);
545 s
->flags
|= DEV_OPT_TXPAUSE
;
548 if ((cur
= tb
[DEV_ATTR_AUTONEG
])) {
549 s
->autoneg
= blobmsg_get_bool(cur
);
550 s
->flags
|= DEV_OPT_AUTONEG
;
553 if ((cur
= tb
[DEV_ATTR_GRO
])) {
554 s
->gro
= blobmsg_get_bool(cur
);
555 s
->flags
|= DEV_OPT_GRO
;
558 if ((cur
= tb
[DEV_ATTR_MASTER
])) {
559 char *ifname
= blobmsg_get_string(cur
);
560 s
->master_ifindex
= if_nametoindex(ifname
);
561 s
->flags
|= DEV_OPT_MASTER
;
564 cur
= tb
[DEV_ATTR_AUTH_VLAN
];
565 free(dev
->config_auth_vlans
);
566 dev
->config_auth_vlans
= cur
? blob_memdup(cur
) : NULL
;
568 device_set_extra_vlans(dev
, tb
[DEV_ATTR_VLAN
]);
569 device_set_disabled(dev
, disabled
);
572 static void __init
dev_init(void)
574 avl_init(&devices
, avl_strcmp
, true, NULL
);
577 static int device_release_cb(void *ctx
, struct safe_list
*list
)
579 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
581 if (!dep
->dev
|| !dep
->claimed
)
588 static int device_broadcast_cb(void *ctx
, struct safe_list
*list
)
590 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
593 /* device might have been removed by an earlier callback */
602 void device_broadcast_event(struct device
*dev
, enum device_event ev
)
604 static const char * const event_names
[] = {
605 [DEV_EVENT_ADD
] = "add",
606 [DEV_EVENT_REMOVE
] = "remove",
607 [DEV_EVENT_UP
] = "up",
608 [DEV_EVENT_DOWN
] = "down",
609 [DEV_EVENT_AUTH_UP
] = "auth_up",
610 [DEV_EVENT_LINK_UP
] = "link_up",
611 [DEV_EVENT_LINK_DOWN
] = "link_down",
612 [DEV_EVENT_TOPO_CHANGE
] = "topo_change",
616 safe_list_for_each(&dev
->aliases
, device_broadcast_cb
, &dev_ev
);
617 safe_list_for_each(&dev
->users
, device_broadcast_cb
, &dev_ev
);
619 if (ev
>= ARRAY_SIZE(event_names
) || !event_names
[ev
] || !dev
->ifname
[0])
622 blob_buf_init(&b
, 0);
623 blobmsg_add_string(&b
, "name", dev
->ifname
);
624 blobmsg_add_u8(&b
, "auth_status", dev
->auth_status
);
625 blobmsg_add_u8(&b
, "present", dev
->present
);
626 blobmsg_add_u8(&b
, "active", dev
->active
);
627 blobmsg_add_u8(&b
, "link_active", dev
->link_active
);
628 netifd_ubus_device_notify(event_names
[ev
], b
.head
, -1);
632 device_fill_default_settings(struct device
*dev
)
634 struct device_settings
*s
= &dev
->settings
;
635 struct ether_addr
*ea
;
639 if (!(s
->flags
& DEV_OPT_MACADDR
)) {
640 ea
= config_get_default_macaddr(dev
->ifname
);
642 memcpy(s
->macaddr
, ea
, 6);
643 s
->flags
|= DEV_OPT_DEFAULT_MACADDR
;
647 if (!(s
->flags
& DEV_OPT_GRO
)) {
648 ret
= config_get_default_gro(dev
->ifname
);
651 s
->flags
|= DEV_OPT_GRO
;
655 if (!(s
->flags
& DEV_OPT_MASTER
)) {
656 master
= config_get_default_conduit(dev
->ifname
);
658 s
->master_ifindex
= if_nametoindex(master
);
659 s
->flags
|= DEV_OPT_MASTER
;
664 int device_claim(struct device_user
*dep
)
666 struct device
*dev
= dep
->dev
;
676 D(DEVICE
, "Claim %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
+ 1);
677 if (++dev
->active
!= 1)
680 device_broadcast_event(dev
, DEV_EVENT_SETUP
);
681 device_fill_default_settings(dev
);
683 /* Get ifindex for external claimed devices so a valid */
684 /* ifindex is in place avoiding possible race conditions */
685 device_set_ifindex(dev
, system_if_resolve(dev
));
689 system_if_get_settings(dev
, &dev
->orig_settings
);
691 ret
= dev
->set_state(dev
, true);
694 device_broadcast_event(dev
, DEV_EVENT_UP
);
696 D(DEVICE
, "claim %s %s failed: %d\n", dev
->type
->name
, dev
->ifname
, ret
);
698 dep
->claimed
= false;
704 void device_release(struct device_user
*dep
)
706 struct device
*dev
= dep
->dev
;
711 dep
->claimed
= false;
713 D(DEVICE
, "Release %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
);
714 assert(dev
->active
>= 0);
719 device_broadcast_event(dev
, DEV_EVENT_TEARDOWN
);
721 dev
->set_state(dev
, false);
726 device_broadcast_event(dev
, DEV_EVENT_DOWN
);
729 int device_check_state(struct device
*dev
)
731 if (!dev
->type
->check_state
)
732 return simple_device_type
.check_state(dev
);
734 return dev
->type
->check_state(dev
);
737 int device_init_virtual(struct device
*dev
, struct device_type
*type
, const char *name
)
742 D(DEVICE
, "Initialize device '%s'\n", name
? name
: "");
743 INIT_SAFE_LIST(&dev
->users
);
744 INIT_SAFE_LIST(&dev
->aliases
);
750 ret
= device_set_ifname(dev
, name
);
756 dev
->set_state
= set_device_state
;
761 int device_init(struct device
*dev
, struct device_type
*type
, const char *ifname
)
765 ret
= device_init_virtual(dev
, type
, ifname
);
769 dev
->avl
.key
= dev
->ifname
;
771 ret
= avl_insert(&devices
, &dev
->avl
);
775 system_if_clear_state(dev
);
780 static struct device
*
781 device_create_default(const char *name
, bool external
)
785 if (!external
&& system_if_force_external(name
))
788 D(DEVICE
, "Create simple device '%s'\n", name
);
789 dev
= calloc(1, sizeof(*dev
));
793 dev
->external
= external
;
794 dev
->set_state
= simple_device_set_state
;
796 if (device_init(dev
, &simple_device_type
, name
) < 0) {
802 dev
->default_config
= true;
804 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
806 device_check_state(dev
);
812 device_find(const char *name
)
816 return avl_find_element(&devices
, name
, dev
, avl
);
820 __device_get(const char *name
, int create
, bool check_vlan
)
824 dev
= avl_find_element(&devices
, name
, dev
, avl
);
826 if (!dev
&& check_vlan
&& strchr(name
, '.'))
827 return get_vlan_device_chain(name
, create
);
830 return device_alias_get(name
+ 1);
833 if (create
> 1 && !dev
->external
) {
834 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
835 dev
->external
= true;
836 device_set_present(dev
, true);
844 return device_create_default(name
, create
> 1);
848 device_delete(struct device
*dev
)
853 D(DEVICE
, "Delete device '%s' from list\n", dev
->ifname
);
854 avl_delete(&devices
, &dev
->avl
);
858 static int device_cleanup_cb(void *ctx
, struct safe_list
*list
)
860 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
862 dep
->cb(dep
, DEV_EVENT_REMOVE
);
868 void device_cleanup(struct device
*dev
)
870 D(DEVICE
, "Clean up device '%s'\n", dev
->ifname
);
871 safe_list_for_each(&dev
->users
, device_cleanup_cb
, NULL
);
872 safe_list_for_each(&dev
->aliases
, device_cleanup_cb
, NULL
);
876 static void __device_set_present(struct device
*dev
, bool state
)
878 if (dev
->present
== state
)
881 dev
->present
= state
;
882 device_broadcast_event(dev
, state
? DEV_EVENT_ADD
: DEV_EVENT_REMOVE
);
886 device_refresh_present(struct device
*dev
)
888 bool state
= dev
->sys_present
;
890 if (dev
->disabled
|| dev
->deferred
)
893 __device_set_present(dev
, state
);
897 device_set_auth_status(struct device
*dev
, bool value
, struct blob_attr
*vlans
)
901 else if (!blob_attr_equal(vlans
, dev
->auth_vlans
))
902 device_set_auth_status(dev
, false, NULL
);
904 free(dev
->auth_vlans
);
905 dev
->auth_vlans
= vlans
? blob_memdup(vlans
) : NULL
;
907 if (dev
->auth_status
== value
)
910 dev
->auth_status
= value
;
914 if (dev
->auth_status
) {
915 device_broadcast_event(dev
, DEV_EVENT_AUTH_UP
);
919 device_broadcast_event(dev
, DEV_EVENT_LINK_DOWN
);
920 if (!dev
->link_active
)
923 device_broadcast_event(dev
, DEV_EVENT_LINK_UP
);
926 void device_set_present(struct device
*dev
, bool state
)
928 if (dev
->sys_present
== state
)
931 D(DEVICE
, "%s '%s' %s present\n", dev
->type
->name
, dev
->ifname
, state
? "is now" : "is no longer" );
932 dev
->sys_present
= state
;
933 device_refresh_present(dev
);
935 safe_list_for_each(&dev
->users
, device_release_cb
, NULL
);
938 void device_set_link(struct device
*dev
, bool state
)
940 if (dev
->link_active
== state
)
943 netifd_log_message(L_NOTICE
, "%s '%s' link is %s\n", dev
->type
->name
, dev
->ifname
, state
? "up" : "down" );
945 dev
->link_active
= state
;
947 dev
->auth_status
= false;
948 device_broadcast_event(dev
, state
? DEV_EVENT_LINK_UP
: DEV_EVENT_LINK_DOWN
);
951 void device_set_ifindex(struct device
*dev
, int ifindex
)
953 if (dev
->ifindex
== ifindex
)
956 dev
->ifindex
= ifindex
;
957 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFINDEX
);
960 int device_set_ifname(struct device
*dev
, const char *name
)
964 if (!strcmp(dev
->ifname
, name
))
967 if (strlen(name
) > sizeof(dev
->ifname
) - 1)
971 avl_delete(&devices
, &dev
->avl
);
973 strcpy(dev
->ifname
, name
);
976 ret
= avl_insert(&devices
, &dev
->avl
);
979 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFNAME
);
984 static int device_refcount(struct device
*dev
)
986 struct list_head
*list
;
989 list_for_each(list
, &dev
->users
.list
)
992 list_for_each(list
, &dev
->aliases
.list
)
999 __device_add_user(struct device_user
*dep
, struct device
*dev
)
1001 struct safe_list
*head
;
1006 head
= &dev
->aliases
;
1010 safe_list_add(&dep
->list
, head
);
1011 D(DEVICE
, "Add user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
1013 if (dep
->cb
&& dev
->present
) {
1014 dep
->cb(dep
, DEV_EVENT_ADD
);
1016 dep
->cb(dep
, DEV_EVENT_UP
);
1018 if (dev
->link_active
)
1019 dep
->cb(dep
, DEV_EVENT_LINK_UP
);
1023 void device_add_user(struct device_user
*dep
, struct device
*dev
)
1025 if (dep
->dev
== dev
)
1029 device_remove_user(dep
);
1034 __device_add_user(dep
, dev
);
1038 device_free(struct device
*dev
)
1041 free(dev
->auth_vlans
);
1043 device_cleanup(dev
);
1044 free(dev
->config_auth_vlans
);
1045 free(dev
->extra_vlan
);
1046 dev
->type
->free(dev
);
1051 __device_free_unused(struct uloop_timeout
*timeout
)
1053 struct device
*dev
, *tmp
;
1055 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1056 if (!safe_list_empty(&dev
->users
) ||
1057 !safe_list_empty(&dev
->aliases
) ||
1058 dev
->current_config
)
1065 void device_free_unused(void)
1067 static struct uloop_timeout free_timer
= {
1068 .cb
= __device_free_unused
,
1071 uloop_timeout_set(&free_timer
, 1);
1074 void device_remove_user(struct device_user
*dep
)
1076 struct device
*dev
= dep
->dev
;
1081 dep
->hotplug
= false;
1083 device_release(dep
);
1085 safe_list_del(&dep
->list
);
1087 D(DEVICE
, "Remove user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
1088 device_free_unused();
1092 device_init_pending(void)
1094 struct device
*dev
, *tmp
;
1096 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1097 if (!dev
->config_pending
)
1100 dev
->type
->config_init(dev
);
1101 dev
->config_pending
= false;
1102 device_check_state(dev
);
1107 device_check_ip6segmentrouting(void)
1110 bool ip6segmentrouting
= false;
1112 avl_for_each_element(&devices
, dev
, avl
)
1113 ip6segmentrouting
|= dev
->settings
.ip6segmentrouting
;
1115 return ip6segmentrouting
;
1118 static enum dev_change_type
1119 device_set_config(struct device
*dev
, struct device_type
*type
,
1120 struct blob_attr
*attr
)
1122 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
1123 const struct uci_blob_param_list
*cfg
= type
->config_params
;
1125 if (type
!= dev
->type
)
1126 return DEV_CONFIG_RECREATE
;
1128 if (dev
->type
->reload
)
1129 return dev
->type
->reload(dev
, attr
);
1131 if (uci_blob_check_equal(dev
->config
, attr
, cfg
))
1132 return DEV_CONFIG_NO_CHANGE
;
1134 if (cfg
== &device_attr_list
) {
1135 memset(tb
, 0, sizeof(tb
));
1138 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
,
1139 blob_data(attr
), blob_len(attr
));
1141 device_init_settings(dev
, tb
);
1142 return DEV_CONFIG_RESTART
;
1144 return DEV_CONFIG_RECREATE
;
1147 enum dev_change_type
1148 device_apply_config(struct device
*dev
, struct device_type
*type
,
1149 struct blob_attr
*config
)
1151 enum dev_change_type change
;
1153 change
= device_set_config(dev
, type
, config
);
1154 if (dev
->external
) {
1155 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
1156 change
= DEV_CONFIG_APPLIED
;
1160 case DEV_CONFIG_RESTART
:
1161 case DEV_CONFIG_APPLIED
:
1162 D(DEVICE
, "Device '%s': config applied\n", dev
->ifname
);
1163 config
= blob_memdup(config
);
1165 dev
->config
= config
;
1166 if (change
== DEV_CONFIG_RESTART
&& dev
->present
) {
1169 device_set_present(dev
, false);
1170 if (dev
->active
&& !dev
->external
) {
1171 ret
= dev
->set_state(dev
, false);
1173 ret
= dev
->set_state(dev
, true);
1176 device_set_present(dev
, true);
1179 case DEV_CONFIG_NO_CHANGE
:
1180 D(DEVICE
, "Device '%s': no configuration change\n", dev
->ifname
);
1182 case DEV_CONFIG_RECREATE
:
1190 device_replace(struct device
*dev
, struct device
*odev
)
1192 struct device_user
*dep
;
1196 device_set_present(odev
, false);
1198 while (!list_empty(&odev
->users
.list
)) {
1199 dep
= list_first_entry(&odev
->users
.list
, struct device_user
, list
.list
);
1200 device_release(dep
);
1204 safe_list_del(&dep
->list
);
1205 __device_add_user(dep
, dev
);
1213 device_reset_config(void)
1217 avl_for_each_element(&devices
, dev
, avl
)
1218 dev
->current_config
= false;
1222 device_reset_old(void)
1224 struct device
*dev
, *tmp
, *ndev
;
1226 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
1227 if (dev
->current_config
|| dev
->default_config
)
1230 if (dev
->type
!= &simple_device_type
)
1233 ndev
= device_create_default(dev
->ifname
, dev
->external
);
1237 device_replace(ndev
, dev
);
1242 device_create(const char *name
, struct device_type
*type
,
1243 struct blob_attr
*config
)
1245 struct device
*odev
= NULL
, *dev
;
1246 enum dev_change_type change
;
1248 odev
= device_find(name
);
1250 odev
->current_config
= true;
1251 change
= device_apply_config(odev
, type
, config
);
1253 case DEV_CONFIG_RECREATE
:
1254 D(DEVICE
, "Device '%s': recreate device\n", odev
->ifname
);
1255 device_delete(odev
);
1261 D(DEVICE
, "Create new device '%s' (%s)\n", name
, type
->name
);
1263 config
= blob_memdup(config
);
1267 dev
= type
->create(name
, type
, config
);
1271 dev
->current_config
= true;
1272 dev
->config
= config
;
1274 device_replace(dev
, odev
);
1276 if (!config_init
&& dev
->config_pending
) {
1277 type
->config_init(dev
);
1278 dev
->config_pending
= false;
1281 device_check_state(dev
);
1287 device_dump_status(struct blob_buf
*b
, struct device
*dev
)
1289 struct device_settings st
;
1293 avl_for_each_element(&devices
, dev
, avl
) {
1296 c
= blobmsg_open_table(b
, dev
->ifname
);
1297 device_dump_status(b
, dev
);
1298 blobmsg_close_table(b
, c
);
1304 blobmsg_add_u8(b
, "external", dev
->external
);
1305 blobmsg_add_u8(b
, "present", dev
->present
);
1306 blobmsg_add_string(b
, "type", dev
->type
->name
);
1311 blobmsg_add_u8(b
, "up", !!dev
->active
);
1312 blobmsg_add_u8(b
, "carrier", !!dev
->link_active
);
1313 blobmsg_add_u8(b
, "auth_status", !!dev
->auth_status
);
1315 if (dev
->type
->dump_info
)
1316 dev
->type
->dump_info(dev
, b
);
1318 system_if_dump_info(dev
, b
);
1321 device_merge_settings(dev
, &st
);
1322 if (st
.flags
& DEV_OPT_MASTER
) {
1323 char buf
[64], *devname
;
1325 devname
= if_indextoname(st
.master_ifindex
, buf
);
1327 blobmsg_add_string(b
, "conduit", devname
);
1329 if (st
.flags
& DEV_OPT_MTU
)
1330 blobmsg_add_u32(b
, "mtu", st
.mtu
);
1331 if (st
.flags
& DEV_OPT_MTU6
)
1332 blobmsg_add_u32(b
, "mtu6", st
.mtu6
);
1333 if (st
.flags
& DEV_OPT_MACADDR
)
1334 blobmsg_add_string(b
, "macaddr", format_macaddr(st
.macaddr
));
1335 if (st
.flags
& DEV_OPT_TXQUEUELEN
)
1336 blobmsg_add_u32(b
, "txqueuelen", st
.txqueuelen
);
1337 if (st
.flags
& DEV_OPT_IPV6
)
1338 blobmsg_add_u8(b
, "ipv6", st
.ipv6
);
1339 if (st
.flags
& DEV_OPT_IP6SEGMENTROUTING
)
1340 blobmsg_add_u8(b
, "ip6segmentrouting", st
.ip6segmentrouting
);
1341 if (st
.flags
& DEV_OPT_PROMISC
)
1342 blobmsg_add_u8(b
, "promisc", st
.promisc
);
1343 if (st
.flags
& DEV_OPT_RPFILTER
)
1344 blobmsg_add_u32(b
, "rpfilter", st
.rpfilter
);
1345 if (st
.flags
& DEV_OPT_ACCEPTLOCAL
)
1346 blobmsg_add_u8(b
, "acceptlocal", st
.acceptlocal
);
1347 if (st
.flags
& DEV_OPT_IGMPVERSION
)
1348 blobmsg_add_u32(b
, "igmpversion", st
.igmpversion
);
1349 if (st
.flags
& DEV_OPT_MLDVERSION
)
1350 blobmsg_add_u32(b
, "mldversion", st
.mldversion
);
1351 if (st
.flags
& DEV_OPT_NEIGHREACHABLETIME
) {
1352 blobmsg_add_u32(b
, "neigh4reachabletime", st
.neigh4reachabletime
);
1353 blobmsg_add_u32(b
, "neigh6reachabletime", st
.neigh6reachabletime
);
1355 if (st
.flags
& DEV_OPT_NEIGHGCSTALETIME
) {
1356 blobmsg_add_u32(b
, "neigh4gcstaletime", st
.neigh4gcstaletime
);
1357 blobmsg_add_u32(b
, "neigh6gcstaletime", st
.neigh6gcstaletime
);
1359 if (st
.flags
& DEV_OPT_NEIGHLOCKTIME
)
1360 blobmsg_add_u32(b
, "neigh4locktime", st
.neigh4locktime
);
1361 if (st
.flags
& DEV_OPT_DADTRANSMITS
)
1362 blobmsg_add_u32(b
, "dadtransmits", st
.dadtransmits
);
1363 if (st
.flags
& DEV_OPT_MULTICAST_TO_UNICAST
)
1364 blobmsg_add_u8(b
, "multicast_to_unicast", st
.multicast_to_unicast
);
1365 if (st
.flags
& DEV_OPT_MULTICAST_ROUTER
)
1366 blobmsg_add_u32(b
, "multicast_router", st
.multicast_router
);
1367 if (st
.flags
& DEV_OPT_MULTICAST_FAST_LEAVE
)
1368 blobmsg_add_u8(b
, "multicast_fast_leave", st
.multicast_fast_leave
);
1369 if (st
.flags
& DEV_OPT_MULTICAST
)
1370 blobmsg_add_u8(b
, "multicast", st
.multicast
);
1371 if (st
.flags
& DEV_OPT_LEARNING
)
1372 blobmsg_add_u8(b
, "learning", st
.learning
);
1373 if (st
.flags
& DEV_OPT_UNICAST_FLOOD
)
1374 blobmsg_add_u8(b
, "unicast_flood", st
.unicast_flood
);
1375 if (st
.flags
& DEV_OPT_SENDREDIRECTS
)
1376 blobmsg_add_u8(b
, "sendredirects", st
.sendredirects
);
1377 if (st
.flags
& DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST
)
1378 blobmsg_add_u8(b
, "drop_v4_unicast_in_l2_multicast", st
.drop_v4_unicast_in_l2_multicast
);
1379 if (st
.flags
& DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST
)
1380 blobmsg_add_u8(b
, "drop_v6_unicast_in_l2_multicast", st
.drop_v6_unicast_in_l2_multicast
);
1381 if (st
.flags
& DEV_OPT_DROP_GRATUITOUS_ARP
)
1382 blobmsg_add_u8(b
, "drop_gratuitous_arp", st
.drop_gratuitous_arp
);
1383 if (st
.flags
& DEV_OPT_DROP_UNSOLICITED_NA
)
1384 blobmsg_add_u8(b
, "drop_unsolicited_na", st
.drop_unsolicited_na
);
1385 if (st
.flags
& DEV_OPT_ARP_ACCEPT
)
1386 blobmsg_add_u8(b
, "arp_accept", st
.arp_accept
);
1387 if (st
.flags
& DEV_OPT_AUTH
)
1388 blobmsg_add_u8(b
, "auth", st
.auth
);
1389 if (st
.flags
& DEV_OPT_GRO
)
1390 blobmsg_add_u8(b
, "gro", st
.gro
);
1393 s
= blobmsg_open_table(b
, "statistics");
1394 if (dev
->type
->dump_stats
)
1395 dev
->type
->dump_stats(dev
, b
);
1397 system_if_dump_stats(dev
, b
);
1398 blobmsg_close_table(b
, s
);
1401 static void __init
simple_device_type_init(void)
1403 device_type_add(&simple_device_type
);
1406 void device_hotplug_event(const char *name
, bool add
)
1410 wireless_device_hotplug_event(name
, add
);
1412 dev
= device_find(name
);
1413 if (!dev
|| dev
->type
!= &simple_device_type
)
1416 device_set_present(dev
, add
);