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
},
52 [DEV_ATTR_MULTICAST_ROUTER
] = { .name
= "multicast_router", .type
= BLOBMSG_TYPE_INT32
},
55 const struct uci_blob_param_list device_attr_list
= {
56 .n_params
= __DEV_ATTR_MAX
,
60 static int __devlock
= 0;
62 void device_lock(void)
67 void device_unlock(void)
71 device_free_unused(NULL
);
74 static int set_device_state(struct device
*dev
, bool state
)
77 /* Set ifindex for all devices being enabled so a valid */
78 /* ifindex is in place avoiding possible race conditions */
79 device_set_ifindex(dev
, system_if_resolve(dev
));
96 simple_device_set_state(struct device
*dev
, bool state
)
101 pdev
= dev
->parent
.dev
;
102 if (state
&& !pdev
) {
103 pdev
= system_if_get_parent(dev
);
105 device_add_user(&dev
->parent
, pdev
);
110 ret
= device_claim(&dev
->parent
);
112 device_release(&dev
->parent
);
117 return set_device_state(dev
, state
);
120 static struct device
*
121 simple_device_create(const char *name
, struct blob_attr
*attr
)
123 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
124 struct device
*dev
= NULL
;
126 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
, blob_data(attr
), blob_len(attr
));
127 dev
= device_get(name
, true);
131 dev
->set_state
= simple_device_set_state
;
132 device_init_settings(dev
, tb
);
137 static void simple_device_free(struct device
*dev
)
140 device_remove_user(&dev
->parent
);
144 const struct device_type simple_device_type
= {
145 .name
= "Network device",
146 .config_params
= &device_attr_list
,
148 .create
= simple_device_create
,
149 .check_state
= system_if_check
,
150 .free
= simple_device_free
,
154 device_merge_settings(struct device
*dev
, struct device_settings
*n
)
156 struct device_settings
*os
= &dev
->orig_settings
;
157 struct device_settings
*s
= &dev
->settings
;
159 memset(n
, 0, sizeof(*n
));
160 n
->mtu
= s
->flags
& DEV_OPT_MTU
? s
->mtu
: os
->mtu
;
161 n
->mtu6
= s
->flags
& DEV_OPT_MTU6
? s
->mtu6
: os
->mtu6
;
162 n
->txqueuelen
= s
->flags
& DEV_OPT_TXQUEUELEN
?
163 s
->txqueuelen
: os
->txqueuelen
;
165 (s
->flags
& DEV_OPT_MACADDR
? s
->macaddr
: os
->macaddr
),
167 n
->ipv6
= s
->flags
& DEV_OPT_IPV6
? s
->ipv6
: os
->ipv6
;
168 n
->promisc
= s
->flags
& DEV_OPT_PROMISC
? s
->promisc
: os
->promisc
;
169 n
->rpfilter
= s
->flags
& DEV_OPT_RPFILTER
? s
->rpfilter
: os
->rpfilter
;
170 n
->acceptlocal
= s
->flags
& DEV_OPT_ACCEPTLOCAL
? s
->acceptlocal
: os
->acceptlocal
;
171 n
->igmpversion
= s
->flags
& DEV_OPT_IGMPVERSION
? s
->igmpversion
: os
->igmpversion
;
172 n
->mldversion
= s
->flags
& DEV_OPT_MLDVERSION
? s
->mldversion
: os
->mldversion
;
173 n
->neigh4reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
174 s
->neigh4reachabletime
: os
->neigh4reachabletime
;
175 n
->neigh6reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
176 s
->neigh6reachabletime
: os
->neigh6reachabletime
;
177 n
->dadtransmits
= s
->flags
& DEV_OPT_DADTRANSMITS
?
178 s
->dadtransmits
: os
->dadtransmits
;
179 n
->multicast_to_unicast
= s
->multicast_to_unicast
;
180 n
->multicast_router
= s
->multicast_router
;
181 n
->flags
= s
->flags
| os
->flags
;
185 device_init_settings(struct device
*dev
, struct blob_attr
**tb
)
187 struct device_settings
*s
= &dev
->settings
;
188 struct blob_attr
*cur
;
189 struct ether_addr
*ea
;
190 bool disabled
= false;
193 if ((cur
= tb
[DEV_ATTR_ENABLED
]))
194 disabled
= !blobmsg_get_bool(cur
);
196 if ((cur
= tb
[DEV_ATTR_MTU
])) {
197 s
->mtu
= blobmsg_get_u32(cur
);
198 s
->flags
|= DEV_OPT_MTU
;
201 if ((cur
= tb
[DEV_ATTR_MTU6
])) {
202 s
->mtu6
= blobmsg_get_u32(cur
);
203 s
->flags
|= DEV_OPT_MTU6
;
206 if ((cur
= tb
[DEV_ATTR_TXQUEUELEN
])) {
207 s
->txqueuelen
= blobmsg_get_u32(cur
);
208 s
->flags
|= DEV_OPT_TXQUEUELEN
;
211 if ((cur
= tb
[DEV_ATTR_MACADDR
])) {
212 ea
= ether_aton(blobmsg_data(cur
));
214 memcpy(s
->macaddr
, ea
, 6);
215 s
->flags
|= DEV_OPT_MACADDR
;
219 if ((cur
= tb
[DEV_ATTR_IPV6
])) {
220 s
->ipv6
= blobmsg_get_bool(cur
);
221 s
->flags
|= DEV_OPT_IPV6
;
224 if ((cur
= tb
[DEV_ATTR_PROMISC
])) {
225 s
->promisc
= blobmsg_get_bool(cur
);
226 s
->flags
|= DEV_OPT_PROMISC
;
229 if ((cur
= tb
[DEV_ATTR_RPFILTER
])) {
230 if (system_resolve_rpfilter(blobmsg_data(cur
), &s
->rpfilter
))
231 s
->flags
|= DEV_OPT_RPFILTER
;
233 DPRINTF("Failed to resolve rpfilter: %s\n", (char *) blobmsg_data(cur
));
236 if ((cur
= tb
[DEV_ATTR_ACCEPTLOCAL
])) {
237 s
->acceptlocal
= blobmsg_get_bool(cur
);
238 s
->flags
|= DEV_OPT_ACCEPTLOCAL
;
241 if ((cur
= tb
[DEV_ATTR_IGMPVERSION
])) {
242 s
->igmpversion
= blobmsg_get_u32(cur
);
243 if (s
->igmpversion
>= 1 && s
->igmpversion
<= 3)
244 s
->flags
|= DEV_OPT_IGMPVERSION
;
246 DPRINTF("Failed to resolve igmpversion: %d\n", blobmsg_get_u32(cur
));
249 if ((cur
= tb
[DEV_ATTR_MLDVERSION
])) {
250 s
->mldversion
= blobmsg_get_u32(cur
);
251 if (s
->mldversion
>= 1 && s
->mldversion
<= 2)
252 s
->flags
|= DEV_OPT_MLDVERSION
;
254 DPRINTF("Failed to resolve mldversion: %d\n", blobmsg_get_u32(cur
));
257 if ((cur
= tb
[DEV_ATTR_NEIGHREACHABLETIME
])) {
258 s
->neigh6reachabletime
= s
->neigh4reachabletime
= blobmsg_get_u32(cur
);
259 s
->flags
|= DEV_OPT_NEIGHREACHABLETIME
;
262 if ((cur
= tb
[DEV_ATTR_RPS
])) {
263 s
->rps
= blobmsg_get_bool(cur
);
264 s
->flags
|= DEV_OPT_RPS
;
269 if ((cur
= tb
[DEV_ATTR_XPS
])) {
270 s
->xps
= blobmsg_get_bool(cur
);
271 s
->flags
|= DEV_OPT_XPS
;
276 if ((cur
= tb
[DEV_ATTR_DADTRANSMITS
])) {
277 s
->dadtransmits
= blobmsg_get_u32(cur
);
278 s
->flags
|= DEV_OPT_DADTRANSMITS
;
281 if ((cur
= tb
[DEV_ATTR_MULTICAST_TO_UNICAST
])) {
282 s
->multicast_to_unicast
= blobmsg_get_bool(cur
);
283 s
->flags
|= DEV_OPT_MULTICAST_TO_UNICAST
;
286 if ((cur
= tb
[DEV_ATTR_MULTICAST_ROUTER
])) {
287 s
->multicast_router
= blobmsg_get_u32(cur
);
288 if (s
->multicast_router
<= 2)
289 s
->flags
|= DEV_OPT_MULTICAST_ROUTER
;
291 DPRINTF("Invalid value: %d - (Use 0: never, 1: learn, 2: always)\n", blobmsg_get_u32(cur
));
294 device_set_disabled(dev
, disabled
);
297 static void __init
dev_init(void)
299 avl_init(&devices
, avl_strcmp
, true, NULL
);
302 static int device_broadcast_cb(void *ctx
, struct safe_list
*list
)
304 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
307 /* device might have been removed by an earlier callback */
316 void device_broadcast_event(struct device
*dev
, enum device_event ev
)
320 safe_list_for_each(&dev
->aliases
, device_broadcast_cb
, &dev_ev
);
321 safe_list_for_each(&dev
->users
, device_broadcast_cb
, &dev_ev
);
324 int device_claim(struct device_user
*dep
)
326 struct device
*dev
= dep
->dev
;
333 D(DEVICE
, "Claim %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
+ 1);
334 if (++dev
->active
!= 1)
337 device_broadcast_event(dev
, DEV_EVENT_SETUP
);
338 ret
= dev
->set_state(dev
, true);
340 device_broadcast_event(dev
, DEV_EVENT_UP
);
342 D(DEVICE
, "claim %s %s failed: %d\n", dev
->type
->name
, dev
->ifname
, ret
);
344 dep
->claimed
= false;
350 void device_release(struct device_user
*dep
)
352 struct device
*dev
= dep
->dev
;
357 dep
->claimed
= false;
359 D(DEVICE
, "Release %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
);
360 assert(dev
->active
>= 0);
365 device_broadcast_event(dev
, DEV_EVENT_TEARDOWN
);
367 dev
->set_state(dev
, false);
368 device_broadcast_event(dev
, DEV_EVENT_DOWN
);
371 int device_check_state(struct device
*dev
)
373 if (!dev
->type
->check_state
)
374 return simple_device_type
.check_state(dev
);
376 return dev
->type
->check_state(dev
);
379 void device_init_virtual(struct device
*dev
, const struct device_type
*type
, const char *name
)
385 strncpy(dev
->ifname
, name
, IFNAMSIZ
);
387 D(DEVICE
, "Initialize device '%s'\n", dev
->ifname
);
388 INIT_SAFE_LIST(&dev
->users
);
389 INIT_SAFE_LIST(&dev
->aliases
);
393 dev
->set_state
= set_device_state
;
396 int device_init(struct device
*dev
, const struct device_type
*type
, const char *ifname
)
400 device_init_virtual(dev
, type
, ifname
);
402 dev
->avl
.key
= dev
->ifname
;
404 ret
= avl_insert(&devices
, &dev
->avl
);
408 system_if_clear_state(dev
);
409 device_check_state(dev
);
410 dev
->settings
.rps
= default_ps
;
411 dev
->settings
.xps
= default_ps
;
416 static struct device
*
417 device_create_default(const char *name
, bool external
)
421 if (!external
&& system_if_force_external(name
))
424 D(DEVICE
, "Create simple device '%s'\n", name
);
425 dev
= calloc(1, sizeof(*dev
));
426 dev
->external
= external
;
427 dev
->set_state
= simple_device_set_state
;
428 device_init(dev
, &simple_device_type
, name
);
429 dev
->default_config
= true;
431 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
436 device_get(const char *name
, int create
)
440 if (strchr(name
, '.'))
441 return get_vlan_device_chain(name
, create
);
444 return device_alias_get(name
+ 1);
446 dev
= avl_find_element(&devices
, name
, dev
, avl
);
448 if (create
> 1 && !dev
->external
) {
449 dev
->external
= true;
450 device_set_present(dev
, true);
458 return device_create_default(name
, create
> 1);
462 device_delete(struct device
*dev
)
467 D(DEVICE
, "Delete device '%s' from list\n", dev
->ifname
);
468 avl_delete(&devices
, &dev
->avl
);
472 static int device_cleanup_cb(void *ctx
, struct safe_list
*list
)
474 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
476 dep
->cb(dep
, DEV_EVENT_REMOVE
);
482 void device_cleanup(struct device
*dev
)
484 D(DEVICE
, "Clean up device '%s'\n", dev
->ifname
);
485 safe_list_for_each(&dev
->users
, device_cleanup_cb
, NULL
);
486 safe_list_for_each(&dev
->aliases
, device_cleanup_cb
, NULL
);
490 static void __device_set_present(struct device
*dev
, bool state
)
492 if (dev
->present
== state
)
495 dev
->present
= state
;
496 device_broadcast_event(dev
, state
? DEV_EVENT_ADD
: DEV_EVENT_REMOVE
);
500 device_refresh_present(struct device
*dev
)
502 bool state
= dev
->sys_present
;
504 if (dev
->disabled
|| dev
->deferred
)
507 __device_set_present(dev
, state
);
510 void device_set_present(struct device
*dev
, bool state
)
512 if (dev
->sys_present
== state
)
515 D(DEVICE
, "%s '%s' %s present\n", dev
->type
->name
, dev
->ifname
, state
? "is now" : "is no longer" );
516 dev
->sys_present
= state
;
517 device_refresh_present(dev
);
520 void device_set_link(struct device
*dev
, bool state
)
522 if (dev
->link_active
== state
)
525 netifd_log_message(L_NOTICE
, "%s '%s' link is %s\n", dev
->type
->name
, dev
->ifname
, state
? "up" : "down" );
527 dev
->link_active
= state
;
528 device_broadcast_event(dev
, state
? DEV_EVENT_LINK_UP
: DEV_EVENT_LINK_DOWN
);
531 void device_set_ifindex(struct device
*dev
, int ifindex
)
533 if (dev
->ifindex
== ifindex
)
536 dev
->ifindex
= ifindex
;
537 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFINDEX
);
540 static int device_refcount(struct device
*dev
)
542 struct list_head
*list
;
545 list_for_each(list
, &dev
->users
.list
)
548 list_for_each(list
, &dev
->aliases
.list
)
555 __device_add_user(struct device_user
*dep
, struct device
*dev
)
557 struct safe_list
*head
;
562 head
= &dev
->aliases
;
566 safe_list_add(&dep
->list
, head
);
567 D(DEVICE
, "Add user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
569 if (dep
->cb
&& dev
->present
) {
570 dep
->cb(dep
, DEV_EVENT_ADD
);
572 dep
->cb(dep
, DEV_EVENT_UP
);
574 if (dev
->link_active
)
575 dep
->cb(dep
, DEV_EVENT_LINK_UP
);
579 void device_add_user(struct device_user
*dep
, struct device
*dev
)
585 device_remove_user(dep
);
590 __device_add_user(dep
, dev
);
594 device_free(struct device
*dev
)
599 dev
->type
->free(dev
);
604 __device_free_unused(struct device
*dev
)
606 if (!safe_list_empty(&dev
->users
) ||
607 !safe_list_empty(&dev
->aliases
) ||
608 dev
->current_config
|| __devlock
)
614 void device_remove_user(struct device_user
*dep
)
616 struct device
*dev
= dep
->dev
;
621 dep
->hotplug
= false;
625 safe_list_del(&dep
->list
);
627 D(DEVICE
, "Remove user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
628 __device_free_unused(dev
);
632 device_free_unused(struct device
*dev
)
637 return __device_free_unused(dev
);
639 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
)
640 __device_free_unused(dev
);
644 device_init_pending(void)
646 struct device
*dev
, *tmp
;
648 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
649 if (!dev
->config_pending
)
652 dev
->type
->config_init(dev
);
653 dev
->config_pending
= false;
657 static enum dev_change_type
658 device_set_config(struct device
*dev
, const struct device_type
*type
,
659 struct blob_attr
*attr
)
661 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
662 const struct uci_blob_param_list
*cfg
= type
->config_params
;
664 if (type
!= dev
->type
)
665 return DEV_CONFIG_RECREATE
;
667 if (dev
->type
->reload
)
668 return dev
->type
->reload(dev
, attr
);
670 if (uci_blob_check_equal(dev
->config
, attr
, cfg
))
671 return DEV_CONFIG_NO_CHANGE
;
673 if (cfg
== &device_attr_list
) {
674 memset(tb
, 0, sizeof(tb
));
677 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
,
678 blob_data(attr
), blob_len(attr
));
680 device_init_settings(dev
, tb
);
681 return DEV_CONFIG_RESTART
;
683 return DEV_CONFIG_RECREATE
;
687 device_apply_config(struct device
*dev
, const struct device_type
*type
,
688 struct blob_attr
*config
)
690 enum dev_change_type change
;
692 change
= device_set_config(dev
, type
, config
);
694 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
695 change
= DEV_CONFIG_APPLIED
;
699 case DEV_CONFIG_RESTART
:
700 case DEV_CONFIG_APPLIED
:
701 D(DEVICE
, "Device '%s': config applied\n", dev
->ifname
);
702 config
= blob_memdup(config
);
704 dev
->config
= config
;
705 if (change
== DEV_CONFIG_RESTART
&& dev
->present
) {
706 device_set_present(dev
, false);
707 if (dev
->active
&& !dev
->external
) {
708 dev
->set_state(dev
, false);
709 dev
->set_state(dev
, true);
711 device_set_present(dev
, true);
714 case DEV_CONFIG_NO_CHANGE
:
715 D(DEVICE
, "Device '%s': no configuration change\n", dev
->ifname
);
717 case DEV_CONFIG_RECREATE
:
725 device_replace(struct device
*dev
, struct device
*odev
)
727 struct device_user
*dep
, *tmp
;
731 device_set_present(odev
, false);
733 list_for_each_entry_safe(dep
, tmp
, &odev
->users
.list
, list
.list
) {
735 safe_list_del(&dep
->list
);
736 __device_add_user(dep
, dev
);
744 device_reset_config(void)
748 avl_for_each_element(&devices
, dev
, avl
)
749 dev
->current_config
= false;
753 device_reset_old(void)
755 struct device
*dev
, *tmp
, *ndev
;
757 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
758 if (dev
->current_config
|| dev
->default_config
)
761 if (dev
->type
!= &simple_device_type
)
764 ndev
= device_create_default(dev
->ifname
, dev
->external
);
768 device_replace(ndev
, dev
);
773 device_set_default_ps(bool state
)
777 if (state
== default_ps
)
782 avl_for_each_element(&devices
, dev
, avl
) {
783 struct device_settings
*s
= &dev
->settings
;
784 unsigned int apply_mask
= 0;
786 if (!(s
->flags
& DEV_OPT_RPS
)) {
788 apply_mask
|= DEV_OPT_RPS
;
791 if (!(s
->flags
& DEV_OPT_XPS
)) {
793 apply_mask
|= DEV_OPT_XPS
;
799 if (!(dev
->external
|| (dev
->present
&& dev
->active
)) ||
803 system_if_apply_settings(dev
, s
, apply_mask
);
808 device_create(const char *name
, const struct device_type
*type
,
809 struct blob_attr
*config
)
811 struct device
*odev
= NULL
, *dev
;
812 enum dev_change_type change
;
814 odev
= device_get(name
, false);
816 odev
->current_config
= true;
817 change
= device_apply_config(odev
, type
, config
);
819 case DEV_CONFIG_RECREATE
:
820 D(DEVICE
, "Device '%s': recreate device\n", odev
->ifname
);
827 D(DEVICE
, "Create new device '%s' (%s)\n", name
, type
->name
);
829 config
= blob_memdup(config
);
833 dev
= type
->create(name
, config
);
837 dev
->current_config
= true;
838 dev
->config
= config
;
840 device_replace(dev
, odev
);
842 if (!config_init
&& dev
->config_pending
) {
843 type
->config_init(dev
);
844 dev
->config_pending
= false;
851 device_dump_status(struct blob_buf
*b
, struct device
*dev
)
853 struct device_settings st
;
857 avl_for_each_element(&devices
, dev
, avl
) {
860 c
= blobmsg_open_table(b
, dev
->ifname
);
861 device_dump_status(b
, dev
);
862 blobmsg_close_table(b
, c
);
868 blobmsg_add_u8(b
, "external", dev
->external
);
869 blobmsg_add_u8(b
, "present", dev
->present
);
870 blobmsg_add_string(b
, "type", dev
->type
->name
);
875 blobmsg_add_u8(b
, "up", !!dev
->active
);
876 blobmsg_add_u8(b
, "carrier", !!dev
->link_active
);
878 if (dev
->type
->dump_info
)
879 dev
->type
->dump_info(dev
, b
);
881 system_if_dump_info(dev
, b
);
884 device_merge_settings(dev
, &st
);
885 if (st
.flags
& DEV_OPT_MTU
)
886 blobmsg_add_u32(b
, "mtu", st
.mtu
);
887 if (st
.flags
& DEV_OPT_MTU6
)
888 blobmsg_add_u32(b
, "mtu6", st
.mtu6
);
889 if (st
.flags
& DEV_OPT_MACADDR
)
890 blobmsg_add_string(b
, "macaddr", format_macaddr(st
.macaddr
));
891 if (st
.flags
& DEV_OPT_TXQUEUELEN
)
892 blobmsg_add_u32(b
, "txqueuelen", st
.txqueuelen
);
893 if (st
.flags
& DEV_OPT_IPV6
)
894 blobmsg_add_u8(b
, "ipv6", st
.ipv6
);
895 if (st
.flags
& DEV_OPT_PROMISC
)
896 blobmsg_add_u8(b
, "promisc", st
.promisc
);
897 if (st
.flags
& DEV_OPT_RPFILTER
)
898 blobmsg_add_u32(b
, "rpfilter", st
.rpfilter
);
899 if (st
.flags
& DEV_OPT_ACCEPTLOCAL
)
900 blobmsg_add_u8(b
, "acceptlocal", st
.acceptlocal
);
901 if (st
.flags
& DEV_OPT_IGMPVERSION
)
902 blobmsg_add_u32(b
, "igmpversion", st
.igmpversion
);
903 if (st
.flags
& DEV_OPT_MLDVERSION
)
904 blobmsg_add_u32(b
, "mldversion", st
.mldversion
);
905 if (st
.flags
& DEV_OPT_NEIGHREACHABLETIME
) {
906 blobmsg_add_u32(b
, "neigh4reachabletime", st
.neigh4reachabletime
);
907 blobmsg_add_u32(b
, "neigh6reachabletime", st
.neigh6reachabletime
);
909 if (st
.flags
& DEV_OPT_DADTRANSMITS
)
910 blobmsg_add_u32(b
, "dadtransmits", st
.dadtransmits
);
911 if (st
.flags
& DEV_OPT_MULTICAST_TO_UNICAST
)
912 blobmsg_add_u8(b
, "multicast_to_unicast", st
.multicast_to_unicast
);
913 if (st
.flags
& DEV_OPT_MULTICAST_ROUTER
)
914 blobmsg_add_u32(b
, "multicast_router", st
.multicast_router
);
917 s
= blobmsg_open_table(b
, "statistics");
918 if (dev
->type
->dump_stats
)
919 dev
->type
->dump_stats(dev
, b
);
921 system_if_dump_stats(dev
, b
);
922 blobmsg_close_table(b
, s
);