do not prematurely release the main dev on link loss, should fix DHCP NAK handling
[project/netifd.git] / interface.c
index 3215f49..2456227 100644 (file)
@@ -147,19 +147,29 @@ static void
 interface_event(struct interface *iface, enum interface_event ev)
 {
        struct interface_user *dep, *tmp;
+       struct device *adev = NULL;
 
        list_for_each_entry_safe(dep, tmp, &iface->users, list)
                dep->cb(dep, iface, ev);
 
        list_for_each_entry_safe(dep, tmp, &iface_all_users, list)
                dep->cb(dep, iface, ev);
+
+       switch (ev) {
+       case IFEV_UP:
+               adev = iface->main_dev.dev;
+               /* fall through */
+       case IFEV_DOWN:
+               alias_notify_device(iface->name, adev);
+               break;
+       default:
+               break;
+       }
 }
 
 static void
 interface_flush_state(struct interface *iface)
 {
-       if (iface->main_dev.dev)
-               device_release(&iface->main_dev);
        if (iface->l3_dev.dev)
                device_release(&iface->l3_dev);
        interface_data_flush(iface);
@@ -215,6 +225,8 @@ interface_cb(struct device_user *dep, enum device_event ev)
        }
 
        interface_set_available(iface, new_state);
+       if (!new_state && dep->dev->external)
+               interface_set_main_dev(iface, NULL);
 }
 
 void
@@ -390,6 +402,8 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
 
                netifd_log_message(L_NOTICE, "Interface '%s' is now down\n", iface->name);
                mark_interface_down(iface);
+               if (iface->main_dev.dev)
+                       device_release(&iface->main_dev);
                interface_handle_config_change(iface);
                break;
        case IFPEV_LINK_LOST:
@@ -682,6 +696,7 @@ interface_change_config(struct interface *if_old, struct interface *if_new)
        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;