+
+static void
+interface_change_config(struct interface *if_old, struct interface *if_new)
+{
+ struct blob_attr *old_config = if_old->config;
+ const char *old_ifname = if_old->ifname;
+ const struct proto_handler *proto = if_old->proto_handler;
+
+ interface_clear_errors(if_old);
+ if_old->config = if_new->config;
+ if (!if_old->config_autostart && if_new->config_autostart)
+ if_old->autostart = true;
+
+ if_old->config_autostart = if_new->config_autostart;
+ if_old->ifname = if_new->ifname;
+ if_old->proto_handler = if_new->proto_handler;
+
+ if ((!!old_ifname != !!if_new->ifname) ||
+ (old_ifname && strcmp(old_ifname, if_new->ifname) != 0) ||
+ proto != if_new->proto_handler) {
+ D(INTERFACE, "Reload interface '%s' because of ifname/proto change\n",
+ if_old->name);
+ goto reload;
+ }
+
+ if (!proto->config_params)
+ D(INTERFACE, "No config parameters for interface '%s'\n",
+ if_old->name);
+ else if (!config_check_equal(old_config, if_new->config,
+ proto->config_params)) {
+ D(INTERFACE, "Reload interface '%s because of config changes\n",
+ if_old->name);
+ goto reload;
+ }
+
+ goto out;
+
+reload:
+ set_config_state(if_old, IFC_RELOAD);
+out:
+ free(old_config);
+ free(if_new);
+}
+
+static void
+interface_update(struct vlist_tree *tree, struct vlist_node *node_new,
+ struct vlist_node *node_old)
+{
+ struct interface *if_old = container_of(node_old, struct interface, node);
+ struct interface *if_new = container_of(node_new, struct interface, node);
+
+ if (node_old && node_new) {
+ D(INTERFACE, "Update interface '%s'\n", if_new->name);
+ interface_change_config(if_old, if_new);
+ } else if (node_old) {
+ D(INTERFACE, "Remove interface '%s'\n", if_old->name);
+ set_config_state(if_old, IFC_REMOVE);
+ } else if (node_new) {
+ D(INTERFACE, "Create interface '%s'\n", if_new->name);
+ proto_init_interface(if_new, if_new->config);
+ interface_claim_device(if_new);
+ netifd_ubus_add_interface(if_new);
+ }
+}
+
+
+static void __init
+interface_init_list(void)
+{
+ vlist_init(&interfaces, avl_strcmp, interface_update,
+ struct interface, node, name);
+ interfaces.keep_old = true;
+ interfaces.no_delete = true;
+}