6 #include <libubox/uloop.h>
12 char *hotplug_cmd_path = DEFAULT_HOTPLUG_PATH;
13 static struct interface *current;
14 static enum interface_event current_ev;
15 static struct list_head pending = LIST_HEAD_INIT(pending);
17 static void task_complete(struct uloop_process *proc, int ret);
18 static struct uloop_process task = {
23 run_cmd(const char *ifname, const char *device, bool up)
30 return task_complete(NULL, -1);
34 uloop_process_add(&task);
38 setenv("ACTION", up ? "ifup" : "ifdown", 1);
39 setenv("INTERFACE", ifname, 1);
41 setenv("DEVICE", device, 1);
42 argv[0] = hotplug_cmd_path;
45 execvp(argv[0], argv);
52 const char *device = NULL;
53 if (list_empty(&pending))
56 current = list_first_entry(&pending, struct interface, hotplug_list);
57 current_ev = current->hotplug_ev;
58 list_del_init(¤t->hotplug_list);
60 if (current_ev == IFEV_UP && current->l3_dev->dev)
61 device = current->l3_dev->dev->ifname;
63 D(SYSTEM, "Call hotplug handler for interface '%s' (%s)\n", current->name, device ? device : "none");
64 run_cmd(current->name, device, current_ev == IFEV_UP);
68 task_complete(struct uloop_process *proc, int ret)
71 D(SYSTEM, "Complete hotplug handler for interface '%s'\n", current->name);
77 * Queue an interface for an up/down event.
78 * An interface can only have one event in the queue and one
79 * event waiting for completion.
80 * When queueing an event that is the same as the one waiting for
81 * completion, remove the interface from the queue
84 interface_queue_event(struct interface *iface, enum interface_event ev)
86 enum interface_event last_ev;
88 D(SYSTEM, "Queue hotplug handler for interface '%s'\n", iface->name);
89 netifd_ubus_interface_event(iface, ev == IFEV_UP);
93 last_ev = iface->hotplug_ev;
95 iface->hotplug_ev = ev;
96 if (last_ev == ev && !list_empty(&iface->hotplug_list))
97 list_del(&iface->hotplug_list);
98 else if (last_ev != ev && list_empty(&iface->hotplug_list))
99 list_add(&iface->hotplug_list, &pending);
101 if (!task.pending && !current)
106 interface_dequeue_event(struct interface *iface)
108 if (iface == current)
111 if (!list_empty(&iface->hotplug_list))
112 list_del_init(&iface->hotplug_list);