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>
21 #include <net/ethernet.h>
24 #include <netinet/ether.h>
31 static struct avl_tree devices
;
32 static bool default_ps
= true;
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_PROMISC
] = { .name
= "promisc", .type
= BLOBMSG_TYPE_BOOL
},
43 [DEV_ATTR_RPFILTER
] = { .name
= "rpfilter", .type
= BLOBMSG_TYPE_STRING
},
44 [DEV_ATTR_ACCEPTLOCAL
] = { .name
= "acceptlocal", .type
= BLOBMSG_TYPE_BOOL
},
45 [DEV_ATTR_IGMPVERSION
] = { .name
= "igmpversion", .type
= BLOBMSG_TYPE_INT32
},
46 [DEV_ATTR_MLDVERSION
] = { .name
= "mldversion", .type
= BLOBMSG_TYPE_INT32
},
47 [DEV_ATTR_NEIGHREACHABLETIME
] = { .name
= "neighreachabletime", .type
= BLOBMSG_TYPE_INT32
},
48 [DEV_ATTR_RPS
] = { .name
= "rps", .type
= BLOBMSG_TYPE_BOOL
},
49 [DEV_ATTR_XPS
] = { .name
= "xps", .type
= BLOBMSG_TYPE_BOOL
},
50 [DEV_ATTR_DADTRANSMITS
] = { .name
= "dadtransmits", .type
= BLOBMSG_TYPE_INT32
},
51 [DEV_ATTR_MULTICAST_TO_UNICAST
] = { .name
= "multicast_to_unicast", .type
= BLOBMSG_TYPE_BOOL
},
54 const struct uci_blob_param_list device_attr_list
= {
55 .n_params
= __DEV_ATTR_MAX
,
59 static int __devlock
= 0;
61 void device_lock(void)
66 void device_unlock(void)
70 device_free_unused(NULL
);
73 static int set_device_state(struct device
*dev
, bool state
)
76 /* Set ifindex for all devices being enabled so a valid */
77 /* ifindex is in place avoiding possible race conditions */
78 device_set_ifindex(dev
, system_if_resolve(dev
));
95 simple_device_set_state(struct device
*dev
, bool state
)
100 pdev
= dev
->parent
.dev
;
101 if (state
&& !pdev
) {
102 pdev
= system_if_get_parent(dev
);
104 device_add_user(&dev
->parent
, pdev
);
109 ret
= device_claim(&dev
->parent
);
111 device_release(&dev
->parent
);
116 return set_device_state(dev
, state
);
119 static struct device
*
120 simple_device_create(const char *name
, struct blob_attr
*attr
)
122 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
123 struct device
*dev
= NULL
;
125 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
, blob_data(attr
), blob_len(attr
));
126 dev
= device_get(name
, true);
130 dev
->set_state
= simple_device_set_state
;
131 device_init_settings(dev
, tb
);
136 static void simple_device_free(struct device
*dev
)
139 device_remove_user(&dev
->parent
);
143 const struct device_type simple_device_type
= {
144 .name
= "Network device",
145 .config_params
= &device_attr_list
,
147 .create
= simple_device_create
,
148 .check_state
= system_if_check
,
149 .free
= simple_device_free
,
153 device_merge_settings(struct device
*dev
, struct device_settings
*n
)
155 struct device_settings
*os
= &dev
->orig_settings
;
156 struct device_settings
*s
= &dev
->settings
;
158 memset(n
, 0, sizeof(*n
));
159 n
->mtu
= s
->flags
& DEV_OPT_MTU
? s
->mtu
: os
->mtu
;
160 n
->mtu6
= s
->flags
& DEV_OPT_MTU6
? s
->mtu6
: os
->mtu6
;
161 n
->txqueuelen
= s
->flags
& DEV_OPT_TXQUEUELEN
?
162 s
->txqueuelen
: os
->txqueuelen
;
164 (s
->flags
& DEV_OPT_MACADDR
? s
->macaddr
: os
->macaddr
),
166 n
->ipv6
= s
->flags
& DEV_OPT_IPV6
? s
->ipv6
: os
->ipv6
;
167 n
->promisc
= s
->flags
& DEV_OPT_PROMISC
? s
->promisc
: os
->promisc
;
168 n
->rpfilter
= s
->flags
& DEV_OPT_RPFILTER
? s
->rpfilter
: os
->rpfilter
;
169 n
->acceptlocal
= s
->flags
& DEV_OPT_ACCEPTLOCAL
? s
->acceptlocal
: os
->acceptlocal
;
170 n
->igmpversion
= s
->flags
& DEV_OPT_IGMPVERSION
? s
->igmpversion
: os
->igmpversion
;
171 n
->mldversion
= s
->flags
& DEV_OPT_MLDVERSION
? s
->mldversion
: os
->mldversion
;
172 n
->neigh4reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
173 s
->neigh4reachabletime
: os
->neigh4reachabletime
;
174 n
->neigh6reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
175 s
->neigh6reachabletime
: os
->neigh6reachabletime
;
176 n
->dadtransmits
= s
->flags
& DEV_OPT_DADTRANSMITS
?
177 s
->dadtransmits
: os
->dadtransmits
;
178 n
->multicast_to_unicast
= s
->multicast_to_unicast
;
179 n
->flags
= s
->flags
| os
->flags
;
183 device_init_settings(struct device
*dev
, struct blob_attr
**tb
)
185 struct device_settings
*s
= &dev
->settings
;
186 struct blob_attr
*cur
;
187 struct ether_addr
*ea
;
188 bool disabled
= false;
191 if ((cur
= tb
[DEV_ATTR_ENABLED
]))
192 disabled
= !blobmsg_get_bool(cur
);
194 if ((cur
= tb
[DEV_ATTR_MTU
])) {
195 s
->mtu
= blobmsg_get_u32(cur
);
196 s
->flags
|= DEV_OPT_MTU
;
199 if ((cur
= tb
[DEV_ATTR_MTU6
])) {
200 s
->mtu6
= blobmsg_get_u32(cur
);
201 s
->flags
|= DEV_OPT_MTU6
;
204 if ((cur
= tb
[DEV_ATTR_TXQUEUELEN
])) {
205 s
->txqueuelen
= blobmsg_get_u32(cur
);
206 s
->flags
|= DEV_OPT_TXQUEUELEN
;
209 if ((cur
= tb
[DEV_ATTR_MACADDR
])) {
210 ea
= ether_aton(blobmsg_data(cur
));
212 memcpy(s
->macaddr
, ea
, 6);
213 s
->flags
|= DEV_OPT_MACADDR
;
217 if ((cur
= tb
[DEV_ATTR_IPV6
])) {
218 s
->ipv6
= blobmsg_get_bool(cur
);
219 s
->flags
|= DEV_OPT_IPV6
;
222 if ((cur
= tb
[DEV_ATTR_PROMISC
])) {
223 s
->promisc
= blobmsg_get_bool(cur
);
224 s
->flags
|= DEV_OPT_PROMISC
;
227 if ((cur
= tb
[DEV_ATTR_RPFILTER
])) {
228 if (system_resolve_rpfilter(blobmsg_data(cur
), &s
->rpfilter
))
229 s
->flags
|= DEV_OPT_RPFILTER
;
231 DPRINTF("Failed to resolve rpfilter: %s\n", (char *) blobmsg_data(cur
));
234 if ((cur
= tb
[DEV_ATTR_ACCEPTLOCAL
])) {
235 s
->acceptlocal
= blobmsg_get_bool(cur
);
236 s
->flags
|= DEV_OPT_ACCEPTLOCAL
;
239 if ((cur
= tb
[DEV_ATTR_IGMPVERSION
])) {
240 s
->igmpversion
= blobmsg_get_u32(cur
);
241 if (s
->igmpversion
>= 1 && s
->igmpversion
<= 3)
242 s
->flags
|= DEV_OPT_IGMPVERSION
;
244 DPRINTF("Failed to resolve igmpversion: %d\n", blobmsg_get_u32(cur
));
247 if ((cur
= tb
[DEV_ATTR_MLDVERSION
])) {
248 s
->mldversion
= blobmsg_get_u32(cur
);
249 if (s
->mldversion
>= 1 && s
->mldversion
<= 2)
250 s
->flags
|= DEV_OPT_MLDVERSION
;
252 DPRINTF("Failed to resolve mldversion: %d\n", blobmsg_get_u32(cur
));
255 if ((cur
= tb
[DEV_ATTR_NEIGHREACHABLETIME
])) {
256 s
->neigh6reachabletime
= s
->neigh4reachabletime
= blobmsg_get_u32(cur
);
257 s
->flags
|= DEV_OPT_NEIGHREACHABLETIME
;
260 if ((cur
= tb
[DEV_ATTR_RPS
])) {
261 s
->rps
= blobmsg_get_bool(cur
);
262 s
->flags
|= DEV_OPT_RPS
;
267 if ((cur
= tb
[DEV_ATTR_XPS
])) {
268 s
->xps
= blobmsg_get_bool(cur
);
269 s
->flags
|= DEV_OPT_XPS
;
274 if ((cur
= tb
[DEV_ATTR_DADTRANSMITS
])) {
275 s
->dadtransmits
= blobmsg_get_u32(cur
);
276 s
->flags
|= DEV_OPT_DADTRANSMITS
;
279 if ((cur
= tb
[DEV_ATTR_MULTICAST_TO_UNICAST
])) {
280 s
->multicast_to_unicast
= blobmsg_get_bool(cur
);
281 s
->flags
|= DEV_OPT_MULTICAST_TO_UNICAST
;
284 device_set_disabled(dev
, disabled
);
287 static void __init
dev_init(void)
289 avl_init(&devices
, avl_strcmp
, true, NULL
);
292 static int device_broadcast_cb(void *ctx
, struct safe_list
*list
)
294 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
297 /* device might have been removed by an earlier callback */
306 void device_broadcast_event(struct device
*dev
, enum device_event ev
)
310 safe_list_for_each(&dev
->aliases
, device_broadcast_cb
, &dev_ev
);
311 safe_list_for_each(&dev
->users
, device_broadcast_cb
, &dev_ev
);
314 int device_claim(struct device_user
*dep
)
316 struct device
*dev
= dep
->dev
;
323 D(DEVICE
, "Claim %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
+ 1);
324 if (++dev
->active
!= 1)
327 device_broadcast_event(dev
, DEV_EVENT_SETUP
);
328 ret
= dev
->set_state(dev
, true);
330 device_broadcast_event(dev
, DEV_EVENT_UP
);
332 D(DEVICE
, "claim %s %s failed: %d\n", dev
->type
->name
, dev
->ifname
, ret
);
334 dep
->claimed
= false;
340 void device_release(struct device_user
*dep
)
342 struct device
*dev
= dep
->dev
;
347 dep
->claimed
= false;
349 D(DEVICE
, "Release %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
);
350 assert(dev
->active
>= 0);
355 device_broadcast_event(dev
, DEV_EVENT_TEARDOWN
);
357 dev
->set_state(dev
, false);
358 device_broadcast_event(dev
, DEV_EVENT_DOWN
);
361 int device_check_state(struct device
*dev
)
363 if (!dev
->type
->check_state
)
364 return simple_device_type
.check_state(dev
);
366 return dev
->type
->check_state(dev
);
369 void device_init_virtual(struct device
*dev
, const struct device_type
*type
, const char *name
)
375 strncpy(dev
->ifname
, name
, IFNAMSIZ
);
377 D(DEVICE
, "Initialize device '%s'\n", dev
->ifname
);
378 INIT_SAFE_LIST(&dev
->users
);
379 INIT_SAFE_LIST(&dev
->aliases
);
383 dev
->set_state
= set_device_state
;
386 int device_init(struct device
*dev
, const struct device_type
*type
, const char *ifname
)
390 device_init_virtual(dev
, type
, ifname
);
392 dev
->avl
.key
= dev
->ifname
;
394 ret
= avl_insert(&devices
, &dev
->avl
);
398 system_if_clear_state(dev
);
399 device_check_state(dev
);
400 dev
->settings
.rps
= default_ps
;
401 dev
->settings
.xps
= default_ps
;
406 static struct device
*
407 device_create_default(const char *name
, bool external
)
411 if (!external
&& system_if_force_external(name
))
414 D(DEVICE
, "Create simple device '%s'\n", name
);
415 dev
= calloc(1, sizeof(*dev
));
416 dev
->external
= external
;
417 dev
->set_state
= simple_device_set_state
;
418 device_init(dev
, &simple_device_type
, name
);
419 dev
->default_config
= true;
421 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
426 device_get(const char *name
, int create
)
430 if (strchr(name
, '.'))
431 return get_vlan_device_chain(name
, create
);
434 return device_alias_get(name
+ 1);
436 dev
= avl_find_element(&devices
, name
, dev
, avl
);
438 if (create
> 1 && !dev
->external
) {
439 dev
->external
= true;
440 device_set_present(dev
, true);
448 return device_create_default(name
, create
> 1);
452 device_delete(struct device
*dev
)
457 D(DEVICE
, "Delete device '%s' from list\n", dev
->ifname
);
458 avl_delete(&devices
, &dev
->avl
);
462 static int device_cleanup_cb(void *ctx
, struct safe_list
*list
)
464 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
466 dep
->cb(dep
, DEV_EVENT_REMOVE
);
472 void device_cleanup(struct device
*dev
)
474 D(DEVICE
, "Clean up device '%s'\n", dev
->ifname
);
475 safe_list_for_each(&dev
->users
, device_cleanup_cb
, NULL
);
476 safe_list_for_each(&dev
->aliases
, device_cleanup_cb
, NULL
);
480 static void __device_set_present(struct device
*dev
, bool state
)
482 if (dev
->present
== state
)
485 dev
->present
= state
;
486 device_broadcast_event(dev
, state
? DEV_EVENT_ADD
: DEV_EVENT_REMOVE
);
490 device_refresh_present(struct device
*dev
)
492 bool state
= dev
->sys_present
;
494 if (dev
->disabled
|| dev
->deferred
)
497 __device_set_present(dev
, state
);
500 void device_set_present(struct device
*dev
, bool state
)
502 if (dev
->sys_present
== state
)
505 D(DEVICE
, "%s '%s' %s present\n", dev
->type
->name
, dev
->ifname
, state
? "is now" : "is no longer" );
506 dev
->sys_present
= state
;
507 device_refresh_present(dev
);
510 void device_set_link(struct device
*dev
, bool state
)
512 if (dev
->link_active
== state
)
515 netifd_log_message(L_NOTICE
, "%s '%s' link is %s\n", dev
->type
->name
, dev
->ifname
, state
? "up" : "down" );
517 dev
->link_active
= state
;
518 device_broadcast_event(dev
, state
? DEV_EVENT_LINK_UP
: DEV_EVENT_LINK_DOWN
);
521 void device_set_ifindex(struct device
*dev
, int ifindex
)
523 if (dev
->ifindex
== ifindex
)
526 dev
->ifindex
= ifindex
;
527 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFINDEX
);
530 static int device_refcount(struct device
*dev
)
532 struct list_head
*list
;
535 list_for_each(list
, &dev
->users
.list
)
538 list_for_each(list
, &dev
->aliases
.list
)
545 __device_add_user(struct device_user
*dep
, struct device
*dev
)
547 struct safe_list
*head
;
552 head
= &dev
->aliases
;
556 safe_list_add(&dep
->list
, head
);
557 D(DEVICE
, "Add user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
559 if (dep
->cb
&& dev
->present
) {
560 dep
->cb(dep
, DEV_EVENT_ADD
);
562 dep
->cb(dep
, DEV_EVENT_UP
);
564 if (dev
->link_active
)
565 dep
->cb(dep
, DEV_EVENT_LINK_UP
);
569 void device_add_user(struct device_user
*dep
, struct device
*dev
)
575 device_remove_user(dep
);
580 __device_add_user(dep
, dev
);
584 device_free(struct device
*dev
)
589 dev
->type
->free(dev
);
594 __device_free_unused(struct device
*dev
)
596 if (!safe_list_empty(&dev
->users
) ||
597 !safe_list_empty(&dev
->aliases
) ||
598 dev
->current_config
|| __devlock
)
604 void device_remove_user(struct device_user
*dep
)
606 struct device
*dev
= dep
->dev
;
611 dep
->hotplug
= false;
615 safe_list_del(&dep
->list
);
617 D(DEVICE
, "Remove user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
618 __device_free_unused(dev
);
622 device_free_unused(struct device
*dev
)
627 return __device_free_unused(dev
);
629 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
)
630 __device_free_unused(dev
);
634 device_init_pending(void)
636 struct device
*dev
, *tmp
;
638 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
639 if (!dev
->config_pending
)
642 dev
->type
->config_init(dev
);
643 dev
->config_pending
= false;
647 static enum dev_change_type
648 device_set_config(struct device
*dev
, const struct device_type
*type
,
649 struct blob_attr
*attr
)
651 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
652 const struct uci_blob_param_list
*cfg
= type
->config_params
;
654 if (type
!= dev
->type
)
655 return DEV_CONFIG_RECREATE
;
657 if (dev
->type
->reload
)
658 return dev
->type
->reload(dev
, attr
);
660 if (uci_blob_check_equal(dev
->config
, attr
, cfg
))
661 return DEV_CONFIG_NO_CHANGE
;
663 if (cfg
== &device_attr_list
) {
664 memset(tb
, 0, sizeof(tb
));
667 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
,
668 blob_data(attr
), blob_len(attr
));
670 device_init_settings(dev
, tb
);
671 return DEV_CONFIG_RESTART
;
673 return DEV_CONFIG_RECREATE
;
677 device_apply_config(struct device
*dev
, const struct device_type
*type
,
678 struct blob_attr
*config
)
680 enum dev_change_type change
;
682 change
= device_set_config(dev
, type
, config
);
684 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
685 change
= DEV_CONFIG_APPLIED
;
689 case DEV_CONFIG_RESTART
:
690 case DEV_CONFIG_APPLIED
:
691 D(DEVICE
, "Device '%s': config applied\n", dev
->ifname
);
692 config
= blob_memdup(config
);
694 dev
->config
= config
;
695 if (change
== DEV_CONFIG_RESTART
&& dev
->present
) {
696 device_set_present(dev
, false);
697 if (dev
->active
&& !dev
->external
) {
698 dev
->set_state(dev
, false);
699 dev
->set_state(dev
, true);
701 device_set_present(dev
, true);
704 case DEV_CONFIG_NO_CHANGE
:
705 D(DEVICE
, "Device '%s': no configuration change\n", dev
->ifname
);
707 case DEV_CONFIG_RECREATE
:
715 device_replace(struct device
*dev
, struct device
*odev
)
717 struct device_user
*dep
, *tmp
;
721 device_set_present(odev
, false);
723 list_for_each_entry_safe(dep
, tmp
, &odev
->users
.list
, list
.list
) {
725 safe_list_del(&dep
->list
);
726 __device_add_user(dep
, dev
);
734 device_reset_config(void)
738 avl_for_each_element(&devices
, dev
, avl
)
739 dev
->current_config
= false;
743 device_reset_old(void)
745 struct device
*dev
, *tmp
, *ndev
;
747 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
748 if (dev
->current_config
|| dev
->default_config
)
751 if (dev
->type
!= &simple_device_type
)
754 ndev
= device_create_default(dev
->ifname
, dev
->external
);
758 device_replace(ndev
, dev
);
763 device_set_default_ps(bool state
)
767 if (state
== default_ps
)
772 avl_for_each_element(&devices
, dev
, avl
) {
773 struct device_settings
*s
= &dev
->settings
;
774 unsigned int apply_mask
= 0;
776 if (!(s
->flags
& DEV_OPT_RPS
)) {
778 apply_mask
|= DEV_OPT_RPS
;
781 if (!(s
->flags
& DEV_OPT_XPS
)) {
783 apply_mask
|= DEV_OPT_XPS
;
789 if (!(dev
->external
|| (dev
->present
&& dev
->active
)) ||
793 system_if_apply_settings(dev
, s
, apply_mask
);
798 device_create(const char *name
, const struct device_type
*type
,
799 struct blob_attr
*config
)
801 struct device
*odev
= NULL
, *dev
;
802 enum dev_change_type change
;
804 odev
= device_get(name
, false);
806 odev
->current_config
= true;
807 change
= device_apply_config(odev
, type
, config
);
809 case DEV_CONFIG_RECREATE
:
810 D(DEVICE
, "Device '%s': recreate device\n", odev
->ifname
);
817 D(DEVICE
, "Create new device '%s' (%s)\n", name
, type
->name
);
819 config
= blob_memdup(config
);
823 dev
= type
->create(name
, config
);
827 dev
->current_config
= true;
828 dev
->config
= config
;
830 device_replace(dev
, odev
);
832 if (!config_init
&& dev
->config_pending
) {
833 type
->config_init(dev
);
834 dev
->config_pending
= false;
841 device_dump_status(struct blob_buf
*b
, struct device
*dev
)
843 struct device_settings st
;
847 avl_for_each_element(&devices
, dev
, avl
) {
850 c
= blobmsg_open_table(b
, dev
->ifname
);
851 device_dump_status(b
, dev
);
852 blobmsg_close_table(b
, c
);
858 blobmsg_add_u8(b
, "external", dev
->external
);
859 blobmsg_add_u8(b
, "present", dev
->present
);
860 blobmsg_add_string(b
, "type", dev
->type
->name
);
865 blobmsg_add_u8(b
, "up", !!dev
->active
);
866 blobmsg_add_u8(b
, "carrier", !!dev
->link_active
);
868 if (dev
->type
->dump_info
)
869 dev
->type
->dump_info(dev
, b
);
871 system_if_dump_info(dev
, b
);
874 device_merge_settings(dev
, &st
);
875 if (st
.flags
& DEV_OPT_MTU
)
876 blobmsg_add_u32(b
, "mtu", st
.mtu
);
877 if (st
.flags
& DEV_OPT_MTU6
)
878 blobmsg_add_u32(b
, "mtu6", st
.mtu6
);
879 if (st
.flags
& DEV_OPT_MACADDR
)
880 blobmsg_add_string(b
, "macaddr", format_macaddr(st
.macaddr
));
881 if (st
.flags
& DEV_OPT_TXQUEUELEN
)
882 blobmsg_add_u32(b
, "txqueuelen", st
.txqueuelen
);
883 if (st
.flags
& DEV_OPT_IPV6
)
884 blobmsg_add_u8(b
, "ipv6", st
.ipv6
);
885 if (st
.flags
& DEV_OPT_PROMISC
)
886 blobmsg_add_u8(b
, "promisc", st
.promisc
);
887 if (st
.flags
& DEV_OPT_RPFILTER
)
888 blobmsg_add_u32(b
, "rpfilter", st
.rpfilter
);
889 if (st
.flags
& DEV_OPT_ACCEPTLOCAL
)
890 blobmsg_add_u8(b
, "acceptlocal", st
.acceptlocal
);
891 if (st
.flags
& DEV_OPT_IGMPVERSION
)
892 blobmsg_add_u32(b
, "igmpversion", st
.igmpversion
);
893 if (st
.flags
& DEV_OPT_MLDVERSION
)
894 blobmsg_add_u32(b
, "mldversion", st
.mldversion
);
895 if (st
.flags
& DEV_OPT_NEIGHREACHABLETIME
) {
896 blobmsg_add_u32(b
, "neigh4reachabletime", st
.neigh4reachabletime
);
897 blobmsg_add_u32(b
, "neigh6reachabletime", st
.neigh6reachabletime
);
899 if (st
.flags
& DEV_OPT_DADTRANSMITS
)
900 blobmsg_add_u32(b
, "dadtransmits", st
.dadtransmits
);
901 if (st
.flags
& DEV_OPT_MULTICAST_TO_UNICAST
)
902 blobmsg_add_u8(b
, "multicast_to_unicast", st
.multicast_to_unicast
);
905 s
= blobmsg_open_table(b
, "statistics");
906 if (dev
->type
->dump_stats
)
907 dev
->type
->dump_stats(dev
, b
);
909 system_if_dump_stats(dev
, b
);
910 blobmsg_close_table(b
, s
);