+
+static void
+set_config_state(struct interface *iface, enum interface_config_state s)
+{
+ iface->config_state = s;
+ if (iface->state == IFS_DOWN)
+ interface_handle_config_change(iface);
+ else
+ __interface_set_down(iface, false);
+}
+
+void
+interface_update_start(struct interface *iface)
+{
+ interface_ip_update_start(&iface->proto_ip);
+}
+
+void
+interface_update_complete(struct interface *iface)
+{
+ interface_ip_update_complete(&iface->proto_ip);
+}
+
+static void
+interface_replace_dns(struct interface_ip_settings *new, struct interface_ip_settings *old)
+{
+ vlist_simple_replace(&new->dns_servers, &old->dns_servers);
+ vlist_simple_replace(&new->dns_search, &old->dns_search);
+}
+
+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 char *old_parent_ifname = if_old->parent_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->device_config = if_new->device_config;
+ if_old->config_autostart = if_new->config_autostart;
+ if_old->ifname = if_new->ifname;
+ if_old->parent_ifname = if_new->parent_ifname;
+ if_old->proto_handler = if_new->proto_handler;
+
+#define FIELD_CHANGED_STR(field) \
+ ((!!if_old->field != !!old_ ## field) || \
+ (old_ ## field && \
+ strcmp(old_ ## field, if_old->field) != 0))
+
+ if (FIELD_CHANGED_STR(parent_ifname)) {
+ if (if_old->parent_iface.iface)
+ interface_remove_user(&if_old->parent_iface);
+ goto reload;
+ }
+
+ if (FIELD_CHANGED_STR(ifname) || 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;
+ }
+
+#define UPDATE(field) ({ \
+ bool __changed = (if_old->field != if_new->field); \
+ if_old->field = if_new->field; \
+ __changed; \
+ })
+
+ if (UPDATE(metric) || UPDATE(proto_ip.no_defaultroute)) {
+ interface_ip_set_enabled(&if_old->config_ip, false);
+ interface_ip_set_enabled(&if_old->config_ip, if_new->config_ip.enabled);
+ interface_ip_set_enabled(&if_old->proto_ip, false);
+ interface_ip_set_enabled(&if_old->proto_ip, if_new->proto_ip.enabled);
+ }
+
+ UPDATE(proto_ip.no_dns);
+ interface_replace_dns(&if_old->config_ip, &if_new->config_ip);
+ interface_write_resolv_conf();
+
+#undef UPDATE
+
+ goto out;
+
+reload:
+ set_config_state(if_old, IFC_RELOAD);
+out:
+ if_new->config = NULL;
+ interface_cleanup(if_new, false);
+ 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);
+ interfaces.keep_old = true;
+ interfaces.no_delete = true;
+}