interface: always delete l3 dev on proto down
[project/netifd.git] / interface.c
index f0fd43f..7104750 100644 (file)
@@ -222,11 +222,14 @@ mark_interface_down(struct interface *iface)
 void
 __interface_set_down(struct interface *iface, bool force)
 {
-       switch (iface->state) {
+       enum interface_state state = iface->state;
+       switch (state) {
        case IFS_UP:
-               interface_event(iface, IFEV_DOWN);
        case IFS_SETUP:
                iface->state = IFS_TEARDOWN;
+               if (state == IFS_UP)
+                       interface_event(iface, IFEV_DOWN);
+
                interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, force);
                if (force)
                        interface_flush_state(iface);
@@ -270,7 +273,7 @@ interface_check_state(struct interface *iface)
                }
                break;
        case IFS_DOWN:
-               if (iface->enabled && iface->link_state && !config_init)
+               if (iface->autostart && iface->enabled && iface->link_state && !config_init)
                        __interface_set_up(iface);
                break;
        default:
@@ -325,6 +328,9 @@ interface_cb(struct device_user *dep, enum device_event ev)
         case DEV_EVENT_LINK_DOWN:
                interface_set_link_state(iface, new_state);
                break;
+       case DEV_EVENT_TOPO_CHANGE:
+               interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
+               return;
        default:
                break;
        }
@@ -586,6 +592,8 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
                mark_interface_down(iface);
                if (iface->main_dev.dev)
                        device_release(&iface->main_dev);
+               if (iface->l3_dev.dev)
+                       device_remove_user(&iface->l3_dev);
                interface_handle_config_change(iface);
                break;
        case IFPEV_LINK_LOST:
@@ -596,6 +604,8 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
                mark_interface_down(iface);
                iface->state = IFS_SETUP;
                break;
+       default:
+               return;
        }
 
        interface_write_resolv_conf();
@@ -839,7 +849,7 @@ interface_handle_link(struct interface *iface, const char *name, bool add)
                if (iface->device_config)
                        device_set_config(dev, &simple_device_type, iface->config);
 
-               system_if_apply_settings(dev, &dev->settings);
+               system_if_apply_settings(dev, &dev->settings, dev->settings.flags);
                ret = interface_add_link(iface, dev);
        } else {
                ret = interface_remove_link(iface, dev);