nterface-ip: remove superfluous iface check in interface_ip_set_enabled()
[project/netifd.git] / interface-event.c
index 1c8134f..86e8f54 100644 (file)
@@ -30,7 +30,15 @@ static void task_complete(struct uloop_process *proc, int ret);
 static struct uloop_process task = {
        .cb = task_complete,
 };
-static const char * const eventnames[] = {"ifdown", "ifup", "ifupdate"};
+static const char * const eventnames[] = {
+       [IFEV_DOWN] = "ifdown",
+       [IFEV_UP] = "ifup",
+       [IFEV_UP_FAILED] = "ifup-failed",
+       [IFEV_UPDATE] = "ifupdate",
+       [IFEV_FREE] = "free",
+       [IFEV_RELOAD] = "reload",
+       [IFEV_LINK_UP] = "iflink",
+};
 
 static void
 run_cmd(const char *ifname, const char *device, enum interface_event event,
@@ -83,7 +91,7 @@ call_hotplug(void)
        current_ev = current->hotplug_ev;
        list_del_init(&current->hotplug_list);
 
-       if (current_ev == IFEV_UP && current->l3_dev.dev)
+       if ((current_ev == IFEV_UP || current_ev == IFEV_UPDATE) && current->l3_dev.dev)
                device = current->l3_dev.dev->ifname;
 
        D(SYSTEM, "Call hotplug handler for interface '%s', event '%s' (%s)\n",
@@ -117,25 +125,18 @@ interface_queue_event(struct interface *iface, enum interface_event ev)
 
        netifd_ubus_interface_notify(iface, ev != IFEV_DOWN);
 
+       /* no hotplug.d calls for link up */
+       if (ev == IFEV_LINK_UP)
+               return;
+
        if (current == iface) {
                /* an event for iface is being processed */
                if (!list_empty(&iface->hotplug_list)) {
-                       /* an additional event for iface is pending */
-                       if ((ev != current_ev || ev == IFEV_UPDATE) &&
-                       !(iface->hotplug_ev == IFEV_UP && ev == IFEV_UPDATE)) {
-                               /* if incoming event is different from the one
-                                * being handled or if it is an update,
-                                * overwrite pending event, but never
-                                * overwrite an ifup with an ifupdate */
+                       /* an additional event for iface is pending   */
+                       /* overwrite pending event if it differs from */
+                       /* an update                                  */
+                       if (ev != IFEV_UPDATE)
                                iface->hotplug_ev = ev;
-                       }
-                       else if (ev == current_ev && ev != IFEV_UPDATE) {
-                               /* if incoming event is not an ifupdate
-                                * and is the same as the one that is
-                                * being handled, remove it from the
-                                * pending list */
-                               list_del_init(&iface->hotplug_list);
-                       }
                }
                else {
                        /* no additional event for iface is pending */
@@ -189,15 +190,18 @@ static void interface_event_cb(struct interface_user *dep, struct interface *ifa
                               enum interface_event ev)
 {
        switch (ev) {
+               case IFEV_LINK_UP:
                case IFEV_UP:
+               case IFEV_UP_FAILED:
                case IFEV_UPDATE:
                case IFEV_DOWN:
                        interface_queue_event(iface, ev);
                        break;
                case IFEV_FREE:
-               case IFEV_RELOAD:
                        interface_dequeue_event(iface);
                        break;
+               default:
+                       break;
        }
 }