rewrite resolv.conf after any interface state change (not just up)
[project/netifd.git] / interface.c
index 4a42ad9..43d1396 100644 (file)
@@ -170,8 +170,6 @@ interface_event(struct interface *iface, enum interface_event ev)
 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);
@@ -395,7 +393,6 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
                iface->state = IFS_UP;
                iface->start_time = system_get_rtime();
                interface_event(iface, IFEV_UP);
-               interface_write_resolv_conf();
                netifd_log_message(L_NOTICE, "Interface '%s' is now up\n", iface->name);
                break;
        case IFPEV_DOWN:
@@ -404,6 +401,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:
@@ -415,6 +414,8 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
                iface->state = IFS_SETUP;
                break;
        }
+
+       interface_write_resolv_conf();
 }
 
 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state)