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
},
53 [DEV_ATTR_MULTICAST
] = { .name
="multicast", .type
= BLOBMSG_TYPE_BOOL
},
56 const struct uci_blob_param_list device_attr_list
= {
57 .n_params
= __DEV_ATTR_MAX
,
61 static int __devlock
= 0;
63 void device_lock(void)
68 void device_unlock(void)
72 device_free_unused(NULL
);
75 static int set_device_state(struct device
*dev
, bool state
)
78 /* Get ifindex for all devices being enabled so a valid */
79 /* ifindex is in place avoiding possible race conditions */
80 device_set_ifindex(dev
, system_if_resolve(dev
));
93 simple_device_set_state(struct device
*dev
, bool state
)
98 pdev
= dev
->parent
.dev
;
100 pdev
= system_if_get_parent(dev
);
102 device_add_user(&dev
->parent
, pdev
);
107 ret
= device_claim(&dev
->parent
);
109 device_release(&dev
->parent
);
114 return set_device_state(dev
, state
);
117 static struct device
*
118 simple_device_create(const char *name
, struct blob_attr
*attr
)
120 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
121 struct device
*dev
= NULL
;
123 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
, blob_data(attr
), blob_len(attr
));
124 dev
= device_get(name
, true);
128 dev
->set_state
= simple_device_set_state
;
129 device_init_settings(dev
, tb
);
134 static void simple_device_free(struct device
*dev
)
137 device_remove_user(&dev
->parent
);
141 const struct device_type simple_device_type
= {
142 .name
= "Network device",
143 .config_params
= &device_attr_list
,
145 .create
= simple_device_create
,
146 .check_state
= system_if_check
,
147 .free
= simple_device_free
,
151 device_merge_settings(struct device
*dev
, struct device_settings
*n
)
153 struct device_settings
*os
= &dev
->orig_settings
;
154 struct device_settings
*s
= &dev
->settings
;
156 memset(n
, 0, sizeof(*n
));
157 n
->mtu
= s
->flags
& DEV_OPT_MTU
? s
->mtu
: os
->mtu
;
158 n
->mtu6
= s
->flags
& DEV_OPT_MTU6
? s
->mtu6
: os
->mtu6
;
159 n
->txqueuelen
= s
->flags
& DEV_OPT_TXQUEUELEN
?
160 s
->txqueuelen
: os
->txqueuelen
;
162 (s
->flags
& DEV_OPT_MACADDR
? s
->macaddr
: os
->macaddr
),
164 n
->ipv6
= s
->flags
& DEV_OPT_IPV6
? s
->ipv6
: os
->ipv6
;
165 n
->promisc
= s
->flags
& DEV_OPT_PROMISC
? s
->promisc
: os
->promisc
;
166 n
->rpfilter
= s
->flags
& DEV_OPT_RPFILTER
? s
->rpfilter
: os
->rpfilter
;
167 n
->acceptlocal
= s
->flags
& DEV_OPT_ACCEPTLOCAL
? s
->acceptlocal
: os
->acceptlocal
;
168 n
->igmpversion
= s
->flags
& DEV_OPT_IGMPVERSION
? s
->igmpversion
: os
->igmpversion
;
169 n
->mldversion
= s
->flags
& DEV_OPT_MLDVERSION
? s
->mldversion
: os
->mldversion
;
170 n
->neigh4reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
171 s
->neigh4reachabletime
: os
->neigh4reachabletime
;
172 n
->neigh6reachabletime
= s
->flags
& DEV_OPT_NEIGHREACHABLETIME
?
173 s
->neigh6reachabletime
: os
->neigh6reachabletime
;
174 n
->dadtransmits
= s
->flags
& DEV_OPT_DADTRANSMITS
?
175 s
->dadtransmits
: os
->dadtransmits
;
176 n
->multicast
= s
->flags
& DEV_OPT_MULTICAST
?
177 s
->multicast
: os
->multicast
;
178 n
->multicast_to_unicast
= s
->multicast_to_unicast
;
179 n
->multicast_router
= s
->multicast_router
;
180 n
->flags
= s
->flags
| os
->flags
| os
->valid_flags
;
184 device_init_settings(struct device
*dev
, struct blob_attr
**tb
)
186 struct device_settings
*s
= &dev
->settings
;
187 struct blob_attr
*cur
;
188 struct ether_addr
*ea
;
189 bool disabled
= false;
192 if ((cur
= tb
[DEV_ATTR_ENABLED
]))
193 disabled
= !blobmsg_get_bool(cur
);
195 if ((cur
= tb
[DEV_ATTR_MTU
])) {
196 s
->mtu
= blobmsg_get_u32(cur
);
197 s
->flags
|= DEV_OPT_MTU
;
200 if ((cur
= tb
[DEV_ATTR_MTU6
])) {
201 s
->mtu6
= blobmsg_get_u32(cur
);
202 s
->flags
|= DEV_OPT_MTU6
;
205 if ((cur
= tb
[DEV_ATTR_TXQUEUELEN
])) {
206 s
->txqueuelen
= blobmsg_get_u32(cur
);
207 s
->flags
|= DEV_OPT_TXQUEUELEN
;
210 if ((cur
= tb
[DEV_ATTR_MACADDR
])) {
211 ea
= ether_aton(blobmsg_data(cur
));
213 memcpy(s
->macaddr
, ea
, 6);
214 s
->flags
|= DEV_OPT_MACADDR
;
218 if ((cur
= tb
[DEV_ATTR_IPV6
])) {
219 s
->ipv6
= blobmsg_get_bool(cur
);
220 s
->flags
|= DEV_OPT_IPV6
;
223 if ((cur
= tb
[DEV_ATTR_PROMISC
])) {
224 s
->promisc
= blobmsg_get_bool(cur
);
225 s
->flags
|= DEV_OPT_PROMISC
;
228 if ((cur
= tb
[DEV_ATTR_RPFILTER
])) {
229 if (system_resolve_rpfilter(blobmsg_data(cur
), &s
->rpfilter
))
230 s
->flags
|= DEV_OPT_RPFILTER
;
232 DPRINTF("Failed to resolve rpfilter: %s\n", (char *) blobmsg_data(cur
));
235 if ((cur
= tb
[DEV_ATTR_ACCEPTLOCAL
])) {
236 s
->acceptlocal
= blobmsg_get_bool(cur
);
237 s
->flags
|= DEV_OPT_ACCEPTLOCAL
;
240 if ((cur
= tb
[DEV_ATTR_IGMPVERSION
])) {
241 s
->igmpversion
= blobmsg_get_u32(cur
);
242 if (s
->igmpversion
>= 1 && s
->igmpversion
<= 3)
243 s
->flags
|= DEV_OPT_IGMPVERSION
;
245 DPRINTF("Failed to resolve igmpversion: %d\n", blobmsg_get_u32(cur
));
248 if ((cur
= tb
[DEV_ATTR_MLDVERSION
])) {
249 s
->mldversion
= blobmsg_get_u32(cur
);
250 if (s
->mldversion
>= 1 && s
->mldversion
<= 2)
251 s
->flags
|= DEV_OPT_MLDVERSION
;
253 DPRINTF("Failed to resolve mldversion: %d\n", blobmsg_get_u32(cur
));
256 if ((cur
= tb
[DEV_ATTR_NEIGHREACHABLETIME
])) {
257 s
->neigh6reachabletime
= s
->neigh4reachabletime
= blobmsg_get_u32(cur
);
258 s
->flags
|= DEV_OPT_NEIGHREACHABLETIME
;
261 if ((cur
= tb
[DEV_ATTR_RPS
])) {
262 s
->rps
= blobmsg_get_bool(cur
);
263 s
->flags
|= DEV_OPT_RPS
;
268 if ((cur
= tb
[DEV_ATTR_XPS
])) {
269 s
->xps
= blobmsg_get_bool(cur
);
270 s
->flags
|= DEV_OPT_XPS
;
275 if ((cur
= tb
[DEV_ATTR_DADTRANSMITS
])) {
276 s
->dadtransmits
= blobmsg_get_u32(cur
);
277 s
->flags
|= DEV_OPT_DADTRANSMITS
;
280 if ((cur
= tb
[DEV_ATTR_MULTICAST_TO_UNICAST
])) {
281 s
->multicast_to_unicast
= blobmsg_get_bool(cur
);
282 s
->flags
|= DEV_OPT_MULTICAST_TO_UNICAST
;
285 if ((cur
= tb
[DEV_ATTR_MULTICAST_ROUTER
])) {
286 s
->multicast_router
= blobmsg_get_u32(cur
);
287 if (s
->multicast_router
<= 2)
288 s
->flags
|= DEV_OPT_MULTICAST_ROUTER
;
290 DPRINTF("Invalid value: %d - (Use 0: never, 1: learn, 2: always)\n", blobmsg_get_u32(cur
));
293 if ((cur
= tb
[DEV_ATTR_MULTICAST
])) {
294 s
->multicast
= blobmsg_get_bool(cur
);
295 s
->flags
|= DEV_OPT_MULTICAST
;
298 device_set_disabled(dev
, disabled
);
301 static void __init
dev_init(void)
303 avl_init(&devices
, avl_strcmp
, true, NULL
);
306 static int device_broadcast_cb(void *ctx
, struct safe_list
*list
)
308 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
311 /* device might have been removed by an earlier callback */
320 void device_broadcast_event(struct device
*dev
, enum device_event ev
)
324 safe_list_for_each(&dev
->aliases
, device_broadcast_cb
, &dev_ev
);
325 safe_list_for_each(&dev
->users
, device_broadcast_cb
, &dev_ev
);
328 int device_claim(struct device_user
*dep
)
330 struct device
*dev
= dep
->dev
;
337 D(DEVICE
, "Claim %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
+ 1);
338 if (++dev
->active
!= 1)
341 device_broadcast_event(dev
, DEV_EVENT_SETUP
);
343 /* Get ifindex for external claimed devices so a valid */
344 /* ifindex is in place avoiding possible race conditions */
345 device_set_ifindex(dev
, system_if_resolve(dev
));
349 system_if_get_settings(dev
, &dev
->orig_settings
);
351 ret
= dev
->set_state(dev
, true);
354 device_broadcast_event(dev
, DEV_EVENT_UP
);
356 D(DEVICE
, "claim %s %s failed: %d\n", dev
->type
->name
, dev
->ifname
, ret
);
358 dep
->claimed
= false;
364 void device_release(struct device_user
*dep
)
366 struct device
*dev
= dep
->dev
;
371 dep
->claimed
= false;
373 D(DEVICE
, "Release %s %s, new active count: %d\n", dev
->type
->name
, dev
->ifname
, dev
->active
);
374 assert(dev
->active
>= 0);
379 device_broadcast_event(dev
, DEV_EVENT_TEARDOWN
);
381 dev
->set_state(dev
, false);
382 device_broadcast_event(dev
, DEV_EVENT_DOWN
);
385 int device_check_state(struct device
*dev
)
387 if (!dev
->type
->check_state
)
388 return simple_device_type
.check_state(dev
);
390 return dev
->type
->check_state(dev
);
393 void device_init_virtual(struct device
*dev
, const struct device_type
*type
, const char *name
)
399 strncpy(dev
->ifname
, name
, IFNAMSIZ
);
401 D(DEVICE
, "Initialize device '%s'\n", dev
->ifname
);
402 INIT_SAFE_LIST(&dev
->users
);
403 INIT_SAFE_LIST(&dev
->aliases
);
407 dev
->set_state
= set_device_state
;
410 int device_init(struct device
*dev
, const struct device_type
*type
, const char *ifname
)
414 device_init_virtual(dev
, type
, ifname
);
416 dev
->avl
.key
= dev
->ifname
;
418 ret
= avl_insert(&devices
, &dev
->avl
);
422 system_if_clear_state(dev
);
423 device_check_state(dev
);
424 dev
->settings
.rps
= default_ps
;
425 dev
->settings
.xps
= default_ps
;
430 static struct device
*
431 device_create_default(const char *name
, bool external
)
435 if (!external
&& system_if_force_external(name
))
438 D(DEVICE
, "Create simple device '%s'\n", name
);
439 dev
= calloc(1, sizeof(*dev
));
443 dev
->external
= external
;
444 dev
->set_state
= simple_device_set_state
;
445 device_init(dev
, &simple_device_type
, name
);
446 dev
->default_config
= true;
448 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
453 device_get(const char *name
, int create
)
457 if (strchr(name
, '.'))
458 return get_vlan_device_chain(name
, create
);
461 return device_alias_get(name
+ 1);
463 dev
= avl_find_element(&devices
, name
, dev
, avl
);
465 if (create
> 1 && !dev
->external
) {
466 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
467 dev
->external
= true;
468 device_set_present(dev
, true);
476 return device_create_default(name
, create
> 1);
480 device_delete(struct device
*dev
)
485 D(DEVICE
, "Delete device '%s' from list\n", dev
->ifname
);
486 avl_delete(&devices
, &dev
->avl
);
490 static int device_cleanup_cb(void *ctx
, struct safe_list
*list
)
492 struct device_user
*dep
= container_of(list
, struct device_user
, list
);
494 dep
->cb(dep
, DEV_EVENT_REMOVE
);
500 void device_cleanup(struct device
*dev
)
502 D(DEVICE
, "Clean up device '%s'\n", dev
->ifname
);
503 safe_list_for_each(&dev
->users
, device_cleanup_cb
, NULL
);
504 safe_list_for_each(&dev
->aliases
, device_cleanup_cb
, NULL
);
508 static void __device_set_present(struct device
*dev
, bool state
)
510 if (dev
->present
== state
)
513 dev
->present
= state
;
514 device_broadcast_event(dev
, state
? DEV_EVENT_ADD
: DEV_EVENT_REMOVE
);
518 device_refresh_present(struct device
*dev
)
520 bool state
= dev
->sys_present
;
522 if (dev
->disabled
|| dev
->deferred
)
525 __device_set_present(dev
, state
);
528 void device_set_present(struct device
*dev
, bool state
)
530 if (dev
->sys_present
== state
)
533 D(DEVICE
, "%s '%s' %s present\n", dev
->type
->name
, dev
->ifname
, state
? "is now" : "is no longer" );
534 dev
->sys_present
= state
;
535 device_refresh_present(dev
);
538 void device_set_link(struct device
*dev
, bool state
)
540 if (dev
->link_active
== state
)
543 netifd_log_message(L_NOTICE
, "%s '%s' link is %s\n", dev
->type
->name
, dev
->ifname
, state
? "up" : "down" );
545 dev
->link_active
= state
;
546 device_broadcast_event(dev
, state
? DEV_EVENT_LINK_UP
: DEV_EVENT_LINK_DOWN
);
549 void device_set_ifindex(struct device
*dev
, int ifindex
)
551 if (dev
->ifindex
== ifindex
)
554 dev
->ifindex
= ifindex
;
555 device_broadcast_event(dev
, DEV_EVENT_UPDATE_IFINDEX
);
558 static int device_refcount(struct device
*dev
)
560 struct list_head
*list
;
563 list_for_each(list
, &dev
->users
.list
)
566 list_for_each(list
, &dev
->aliases
.list
)
573 __device_add_user(struct device_user
*dep
, struct device
*dev
)
575 struct safe_list
*head
;
580 head
= &dev
->aliases
;
584 safe_list_add(&dep
->list
, head
);
585 D(DEVICE
, "Add user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
587 if (dep
->cb
&& dev
->present
) {
588 dep
->cb(dep
, DEV_EVENT_ADD
);
590 dep
->cb(dep
, DEV_EVENT_UP
);
592 if (dev
->link_active
)
593 dep
->cb(dep
, DEV_EVENT_LINK_UP
);
597 void device_add_user(struct device_user
*dep
, struct device
*dev
)
603 device_remove_user(dep
);
608 __device_add_user(dep
, dev
);
612 device_free(struct device
*dev
)
617 dev
->type
->free(dev
);
622 __device_free_unused(struct device
*dev
)
624 if (!safe_list_empty(&dev
->users
) ||
625 !safe_list_empty(&dev
->aliases
) ||
626 dev
->current_config
|| __devlock
)
632 void device_remove_user(struct device_user
*dep
)
634 struct device
*dev
= dep
->dev
;
639 dep
->hotplug
= false;
643 safe_list_del(&dep
->list
);
645 D(DEVICE
, "Remove user for device '%s', refcount=%d\n", dev
->ifname
, device_refcount(dev
));
646 __device_free_unused(dev
);
650 device_free_unused(struct device
*dev
)
655 return __device_free_unused(dev
);
657 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
)
658 __device_free_unused(dev
);
662 device_init_pending(void)
664 struct device
*dev
, *tmp
;
666 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
667 if (!dev
->config_pending
)
670 dev
->type
->config_init(dev
);
671 dev
->config_pending
= false;
675 static enum dev_change_type
676 device_set_config(struct device
*dev
, const struct device_type
*type
,
677 struct blob_attr
*attr
)
679 struct blob_attr
*tb
[__DEV_ATTR_MAX
];
680 const struct uci_blob_param_list
*cfg
= type
->config_params
;
682 if (type
!= dev
->type
)
683 return DEV_CONFIG_RECREATE
;
685 if (dev
->type
->reload
)
686 return dev
->type
->reload(dev
, attr
);
688 if (uci_blob_check_equal(dev
->config
, attr
, cfg
))
689 return DEV_CONFIG_NO_CHANGE
;
691 if (cfg
== &device_attr_list
) {
692 memset(tb
, 0, sizeof(tb
));
695 blobmsg_parse(dev_attrs
, __DEV_ATTR_MAX
, tb
,
696 blob_data(attr
), blob_len(attr
));
698 device_init_settings(dev
, tb
);
699 return DEV_CONFIG_RESTART
;
701 return DEV_CONFIG_RECREATE
;
705 device_apply_config(struct device
*dev
, const struct device_type
*type
,
706 struct blob_attr
*config
)
708 enum dev_change_type change
;
710 change
= device_set_config(dev
, type
, config
);
712 system_if_apply_settings(dev
, &dev
->settings
, dev
->settings
.flags
);
713 change
= DEV_CONFIG_APPLIED
;
717 case DEV_CONFIG_RESTART
:
718 case DEV_CONFIG_APPLIED
:
719 D(DEVICE
, "Device '%s': config applied\n", dev
->ifname
);
720 config
= blob_memdup(config
);
722 dev
->config
= config
;
723 if (change
== DEV_CONFIG_RESTART
&& dev
->present
) {
724 device_set_present(dev
, false);
725 if (dev
->active
&& !dev
->external
) {
726 dev
->set_state(dev
, false);
727 dev
->set_state(dev
, true);
729 device_set_present(dev
, true);
732 case DEV_CONFIG_NO_CHANGE
:
733 D(DEVICE
, "Device '%s': no configuration change\n", dev
->ifname
);
735 case DEV_CONFIG_RECREATE
:
743 device_replace(struct device
*dev
, struct device
*odev
)
745 struct device_user
*dep
, *tmp
;
749 device_set_present(odev
, false);
751 list_for_each_entry_safe(dep
, tmp
, &odev
->users
.list
, list
.list
) {
753 safe_list_del(&dep
->list
);
754 __device_add_user(dep
, dev
);
762 device_reset_config(void)
766 avl_for_each_element(&devices
, dev
, avl
)
767 dev
->current_config
= false;
771 device_reset_old(void)
773 struct device
*dev
, *tmp
, *ndev
;
775 avl_for_each_element_safe(&devices
, dev
, avl
, tmp
) {
776 if (dev
->current_config
|| dev
->default_config
)
779 if (dev
->type
!= &simple_device_type
)
782 ndev
= device_create_default(dev
->ifname
, dev
->external
);
786 device_replace(ndev
, dev
);
791 device_set_default_ps(bool state
)
795 if (state
== default_ps
)
800 avl_for_each_element(&devices
, dev
, avl
) {
801 struct device_settings
*s
= &dev
->settings
;
802 unsigned int apply_mask
= 0;
804 if (!(s
->flags
& DEV_OPT_RPS
)) {
806 apply_mask
|= DEV_OPT_RPS
;
809 if (!(s
->flags
& DEV_OPT_XPS
)) {
811 apply_mask
|= DEV_OPT_XPS
;
817 if (!(dev
->external
|| (dev
->present
&& dev
->active
)) ||
821 system_if_apply_settings(dev
, s
, apply_mask
);
826 device_create(const char *name
, const struct device_type
*type
,
827 struct blob_attr
*config
)
829 struct device
*odev
= NULL
, *dev
;
830 enum dev_change_type change
;
832 odev
= device_get(name
, false);
834 odev
->current_config
= true;
835 change
= device_apply_config(odev
, type
, config
);
837 case DEV_CONFIG_RECREATE
:
838 D(DEVICE
, "Device '%s': recreate device\n", odev
->ifname
);
845 D(DEVICE
, "Create new device '%s' (%s)\n", name
, type
->name
);
847 config
= blob_memdup(config
);
851 dev
= type
->create(name
, config
);
855 dev
->current_config
= true;
856 dev
->config
= config
;
858 device_replace(dev
, odev
);
860 if (!config_init
&& dev
->config_pending
) {
861 type
->config_init(dev
);
862 dev
->config_pending
= false;
869 device_dump_status(struct blob_buf
*b
, struct device
*dev
)
871 struct device_settings st
;
875 avl_for_each_element(&devices
, dev
, avl
) {
878 c
= blobmsg_open_table(b
, dev
->ifname
);
879 device_dump_status(b
, dev
);
880 blobmsg_close_table(b
, c
);
886 blobmsg_add_u8(b
, "external", dev
->external
);
887 blobmsg_add_u8(b
, "present", dev
->present
);
888 blobmsg_add_string(b
, "type", dev
->type
->name
);
893 blobmsg_add_u8(b
, "up", !!dev
->active
);
894 blobmsg_add_u8(b
, "carrier", !!dev
->link_active
);
896 if (dev
->type
->dump_info
)
897 dev
->type
->dump_info(dev
, b
);
899 system_if_dump_info(dev
, b
);
902 device_merge_settings(dev
, &st
);
903 if (st
.flags
& DEV_OPT_MTU
)
904 blobmsg_add_u32(b
, "mtu", st
.mtu
);
905 if (st
.flags
& DEV_OPT_MTU6
)
906 blobmsg_add_u32(b
, "mtu6", st
.mtu6
);
907 if (st
.flags
& DEV_OPT_MACADDR
)
908 blobmsg_add_string(b
, "macaddr", format_macaddr(st
.macaddr
));
909 if (st
.flags
& DEV_OPT_TXQUEUELEN
)
910 blobmsg_add_u32(b
, "txqueuelen", st
.txqueuelen
);
911 if (st
.flags
& DEV_OPT_IPV6
)
912 blobmsg_add_u8(b
, "ipv6", st
.ipv6
);
913 if (st
.flags
& DEV_OPT_PROMISC
)
914 blobmsg_add_u8(b
, "promisc", st
.promisc
);
915 if (st
.flags
& DEV_OPT_RPFILTER
)
916 blobmsg_add_u32(b
, "rpfilter", st
.rpfilter
);
917 if (st
.flags
& DEV_OPT_ACCEPTLOCAL
)
918 blobmsg_add_u8(b
, "acceptlocal", st
.acceptlocal
);
919 if (st
.flags
& DEV_OPT_IGMPVERSION
)
920 blobmsg_add_u32(b
, "igmpversion", st
.igmpversion
);
921 if (st
.flags
& DEV_OPT_MLDVERSION
)
922 blobmsg_add_u32(b
, "mldversion", st
.mldversion
);
923 if (st
.flags
& DEV_OPT_NEIGHREACHABLETIME
) {
924 blobmsg_add_u32(b
, "neigh4reachabletime", st
.neigh4reachabletime
);
925 blobmsg_add_u32(b
, "neigh6reachabletime", st
.neigh6reachabletime
);
927 if (st
.flags
& DEV_OPT_DADTRANSMITS
)
928 blobmsg_add_u32(b
, "dadtransmits", st
.dadtransmits
);
929 if (st
.flags
& DEV_OPT_MULTICAST_TO_UNICAST
)
930 blobmsg_add_u8(b
, "multicast_to_unicast", st
.multicast_to_unicast
);
931 if (st
.flags
& DEV_OPT_MULTICAST_ROUTER
)
932 blobmsg_add_u32(b
, "multicast_router", st
.multicast_router
);
933 if (st
.flags
& DEV_OPT_MULTICAST
)
934 blobmsg_add_u8(b
, "multicast", st
.multicast
);
937 s
= blobmsg_open_table(b
, "statistics");
938 if (dev
->type
->dump_stats
)
939 dev
->type
->dump_stats(dev
, b
);
941 system_if_dump_stats(dev
, b
);
942 blobmsg_close_table(b
, s
);