X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=interface.c;h=59b7ea23cae88dd85409109a0234ee8ae36b0421;hp=5b503144ba0d73a8fd2e96654efbd471068037a2;hb=210b973708d62137b8283d43908292039056f415;hpb=b9f116ece5ca85c38105a8e33f0d9cc818a05694 diff --git a/interface.c b/interface.c index 5b50314..59b7ea2 100644 --- a/interface.c +++ b/interface.c @@ -167,23 +167,56 @@ interface_set_available(struct interface *iface, bool new_state) } static void -interface_do_free(struct interface *iface) +interface_claim_device(struct interface *iface) +{ + struct device *dev; + + if (iface->proto_handler && + !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) { + dev = device_get(iface->ifname, true); + if (dev) + device_add_user(&iface->main_dev, dev); + } +} + + +static void +interface_cleanup(struct interface *iface) { + if (iface->main_dev.dev) + device_remove_user(&iface->main_dev); interface_set_proto_state(iface, NULL); +} + +static void +interface_do_free(struct interface *iface) +{ + interface_cleanup(iface); free(iface->config); netifd_ubus_remove_interface(iface); free(iface); } static void +interface_do_reload(struct interface *iface) +{ + interface_cleanup(iface); + + interface_claim_device(iface); + proto_init_interface(iface, iface->config); + + if (iface->autostart) + interface_set_up(iface); +} + +static void interface_handle_config_change(struct interface *iface) { switch(iface->config_state) { case IFC_NORMAL: break; case IFC_RELOAD: - if (iface->autostart) - interface_set_up(iface); + interface_do_reload(iface); break; case IFC_REMOVE: interface_do_free(iface); @@ -270,7 +303,6 @@ interface_add(struct interface *iface, struct blob_attr *config) { struct blob_attr *tb[IFACE_ATTR_MAX]; struct blob_attr *cur; - struct device *dev; blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb, blob_data(config), blob_len(config)); @@ -278,12 +310,6 @@ interface_add(struct interface *iface, struct blob_attr *config) if ((cur = tb[IFACE_ATTR_IFNAME])) { iface->ifname = blobmsg_data(cur); - if (iface->proto_handler && - !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) { - dev = device_get(iface->ifname, true); - if (dev) - device_add_user(&iface->main_dev, dev); - } } iface->config = config; @@ -384,6 +410,7 @@ interface_change_config(struct interface *if_old, struct interface *if_new) set_config_state(if_old, IFC_RELOAD); free(old_config); + free(if_new); } static void @@ -398,6 +425,7 @@ interface_update(struct vlist_tree *tree, struct vlist_node *node_new, else if (node_old) set_config_state(if_old, IFC_REMOVE); else if (node_new) { + interface_claim_device(if_new); proto_init_interface(if_new, if_new->config); interface_ip_init(if_new); netifd_ubus_add_interface(if_new); @@ -410,4 +438,6 @@ interface_init_list(void) { vlist_init(&interfaces, avl_strcmp, interface_update, struct interface, node, name); + interfaces.keep_old = true; + interfaces.no_delete = true; }