wireless: improve reliability of proxyarp support
[project/netifd.git] / wireless.c
index b0b35a100b9f58aad63939d6788572a869ace269..0e6447d5584d7ec707bf8d0e7d2c460b6daf8d6c 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  */
+
+/* The wireless configuration is projected on the following objects
+ *
+ * 1. wireless device
+ * 2. wireless interface
+ * 3. wireless vlan
+ * 4. wireless station
+ *
+ * A wireless device is a phy or simplified a wireless card.
+ * A wireless interface is a SSID on a phy.
+ * A wireless vlan can be assigned to a wireless interface. A wireless interface can
+ *   have multiple vlans.
+ * A wireless station is a client connected to an wireless interface.
+ */
+
 #include <signal.h>
 #include "netifd.h"
 #include "wireless.h"
@@ -49,6 +64,7 @@ enum {
        VIF_ATTR_NETWORK,
        VIF_ATTR_ISOLATE,
        VIF_ATTR_MODE,
+       VIF_ATTR_PROXYARP,
        __VIF_ATTR_MAX,
 };
 
@@ -57,6 +73,7 @@ static const struct blobmsg_policy vif_policy[__VIF_ATTR_MAX] = {
        [VIF_ATTR_NETWORK] = { .name = "network", .type = BLOBMSG_TYPE_ARRAY },
        [VIF_ATTR_ISOLATE] = { .name = "isolate", .type = BLOBMSG_TYPE_BOOL },
        [VIF_ATTR_MODE] = { .name = "mode", .type = BLOBMSG_TYPE_STRING },
+       [VIF_ATTR_PROXYARP] = { .name = "proxy_arp", .type = BLOBMSG_TYPE_BOOL },
 };
 
 static const struct uci_blob_param_list vif_param = {
@@ -82,6 +99,20 @@ static const struct uci_blob_param_list vlan_param = {
        .params = vlan_policy,
 };
 
+enum {
+       STA_ATTR_DISABLED,
+       __STA_ATTR_MAX,
+};
+
+static const struct blobmsg_policy sta_policy[__STA_ATTR_MAX] = {
+       [STA_ATTR_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL },
+};
+
+static const struct uci_blob_param_list station_param = {
+       .n_params = ARRAY_SIZE(sta_policy),
+       .params = sta_policy,
+};
+
 static void
 wireless_handler_stop(struct wireless_device *wdev)
 {
@@ -103,7 +134,7 @@ static void
 vif_config_add_bridge(struct blob_buf *buf, struct blob_attr *networks, bool prepare)
 {
        struct interface *iface;
-       struct device *dev = NULL;
+       struct device *dev = NULL, *orig_dev;
        struct blob_attr *cur;
        const char *network;
        int rem;
@@ -122,17 +153,22 @@ vif_config_add_bridge(struct blob_buf *buf, struct blob_attr *networks, bool pre
                if (!dev)
                        return;
 
-               if (!dev->type->bridge_capability)
+               if (!dev->hotplug_ops)
                        return;
        }
 
        if (!dev)
                return;
 
+       orig_dev = dev;
        if (dev->hotplug_ops && dev->hotplug_ops->prepare)
-               dev->hotplug_ops->prepare(dev);
+               dev->hotplug_ops->prepare(dev, &dev);
+
+       if (!dev || !dev->type->bridge_capability)
+               return;
 
        blobmsg_add_string(buf, "bridge", dev->ifname);
+       blobmsg_add_string(buf, "bridge-ifname", orig_dev->ifname);
 
        if (dev->settings.flags & DEV_OPT_MULTICAST_TO_UNICAST)
                blobmsg_add_u8(buf, "multicast_to_unicast",
@@ -144,6 +180,7 @@ prepare_config(struct wireless_device *wdev, struct blob_buf *buf, bool up)
 {
        struct wireless_interface *vif;
        struct wireless_vlan *vlan;
+       struct wireless_station *sta;
        void *l, *i, *j, *k;
 
        blob_buf_init(&b, 0);
@@ -171,6 +208,18 @@ prepare_config(struct wireless_device *wdev, struct blob_buf *buf, bool up)
                        blobmsg_close_table(&b, k);
                }
                blobmsg_close_table(&b, j);
+
+               j = blobmsg_open_table(&b, "stas");
+               vlist_for_each_element(&wdev->stations, sta, node) {
+                       if (strcmp(sta->vif, vif->name))
+                               continue;
+                       k = blobmsg_open_table(&b, sta->name);
+                       put_container(&b, sta->config, "config");
+                       if (sta->data)
+                               blobmsg_add_blob(&b, sta->data);
+                       blobmsg_close_table(&b, k);
+               }
+               blobmsg_close_table(&b, j);
                blobmsg_close_table(&b, i);
        }
        blobmsg_close_table(&b, l);
@@ -224,7 +273,7 @@ wireless_process_kill_all(struct wireless_device *wdev, int signal, bool free)
        list_for_each_entry_safe(proc, tmp, &wdev->script_proc, list) {
                bool check = wireless_process_check(proc);
 
-               if (check) {
+               if (check && !proc->keep) {
                        D(WIRELESS, "Wireless device '%s' kill pid %d\n", wdev->name, proc->pid);
                        kill(proc->pid, signal);
                }
@@ -242,6 +291,7 @@ wireless_device_free_state(struct wireless_device *wdev)
 {
        struct wireless_interface *vif;
        struct wireless_vlan *vlan;
+       struct wireless_station *sta;
 
        wireless_handler_stop(wdev);
        uloop_timeout_cancel(&wdev->script_check);
@@ -259,9 +309,13 @@ wireless_device_free_state(struct wireless_device *wdev)
                vlan->data = NULL;
                vlan->ifname = NULL;
        }
+       vlist_for_each_element(&wdev->stations, sta, node) {
+               free(sta->data);
+               sta->data = NULL;
+       }
 }
 
-static void wireless_interface_handle_link(struct wireless_interface *vif, bool up)
+static void wireless_interface_handle_link(struct wireless_interface *vif, const char *ifname, bool up)
 {
        struct interface *iface;
        struct blob_attr *cur;
@@ -271,12 +325,17 @@ static void wireless_interface_handle_link(struct wireless_interface *vif, bool
        if (!vif->network || !vif->ifname)
                return;
 
+       if (!ifname)
+               ifname = vif->ifname;
+
        if (up) {
-               struct device *dev = device_get(vif->ifname, 2);
+               struct device *dev = device_get(ifname, 2);
                if (dev) {
                        dev->wireless_isolate = vif->isolate;
+                       dev->wireless_proxyarp = vif->proxyarp;
                        dev->wireless = true;
                        dev->wireless_ap = vif->ap_mode;
+                       dev->bpdu_filter = dev->wireless_ap && ifname == vif->ifname;
                }
        }
 
@@ -287,7 +346,7 @@ static void wireless_interface_handle_link(struct wireless_interface *vif, bool
                if (!iface)
                        continue;
 
-               interface_handle_link(iface, vif->ifname, up, true);
+               interface_handle_link(iface, ifname, NULL, up, true);
        }
 }
 
@@ -307,6 +366,7 @@ static void wireless_vlan_handle_link(struct wireless_vlan *vlan, bool up)
                        dev->wireless_isolate = vlan->isolate;
                        dev->wireless = true;
                        dev->wireless_ap = true;
+                       dev->bpdu_filter = true;
                }
        }
 
@@ -317,7 +377,7 @@ static void wireless_vlan_handle_link(struct wireless_vlan *vlan, bool up)
                if (!iface)
                        continue;
 
-               interface_handle_link(iface, vlan->ifname, up, true);
+               interface_handle_link(iface, vlan->ifname, NULL, up, true);
        }
 }
 
@@ -426,6 +486,7 @@ wireless_device_free(struct wireless_device *wdev)
        wireless_handler_stop(wdev);
        vlist_flush_all(&wdev->interfaces);
        vlist_flush_all(&wdev->vlans);
+       vlist_flush_all(&wdev->stations);
        avl_delete(&wireless_devices.avl, &wdev->node.avl);
        free(wdev->config);
        free(wdev->prev_config);
@@ -462,7 +523,7 @@ wireless_device_mark_down(struct wireless_device *wdev)
                wireless_vlan_handle_link(vlan, false);
 
        vlist_for_each_element(&wdev->interfaces, vif, node)
-               wireless_interface_handle_link(vif, false);
+               wireless_interface_handle_link(vif, NULL, false);
 
        wireless_process_kill_all(wdev, SIGTERM, true);
 
@@ -472,6 +533,7 @@ wireless_device_mark_down(struct wireless_device *wdev)
        wdev_handle_config_change(wdev);
 }
 
+/* timeout callback to protect the tear down */
 static void
 wireless_device_setup_timeout(struct uloop_timeout *timeout)
 {
@@ -517,6 +579,7 @@ __wireless_device_set_down(struct wireless_device *wdev)
        wireless_device_run_handler(wdev, false);
 }
 
+/* ubus callback network.wireless.notify, command = up */
 static void
 wireless_device_mark_up(struct wireless_device *wdev)
 {
@@ -532,7 +595,7 @@ wireless_device_mark_up(struct wireless_device *wdev)
        D(WIRELESS, "Wireless device '%s' is now up\n", wdev->name);
        wdev->state = IFS_UP;
        vlist_for_each_element(&wdev->interfaces, vif, node)
-               wireless_interface_handle_link(vif, true);
+               wireless_interface_handle_link(vif, NULL, true);
        vlist_for_each_element(&wdev->vlans, vlan, node)
                wireless_vlan_handle_link(vlan, true);
 }
@@ -629,6 +692,7 @@ wdev_create(struct wireless_device *wdev)
        wdev->config = blob_memdup(wdev->config);
 }
 
+/* vlist update call for wireless device list */
 static void
 wdev_update(struct vlist_tree *tree, struct vlist_node *node_new,
            struct vlist_node *node_old)
@@ -648,25 +712,28 @@ wdev_update(struct vlist_tree *tree, struct vlist_node *node_new,
        }
 }
 
+/* wireless netifd script handler */
 static void
 wireless_add_handler(const char *script, const char *name, json_object *obj)
 {
        struct wireless_driver *drv;
        char *name_str, *script_str;
-       json_object *dev_config_obj, *iface_config_obj, *vlan_config_obj;
-       struct uci_blob_param_list *dev_config, *iface_config, *vlan_config;
+       json_object *dev_config_obj, *iface_config_obj, *vlan_config_obj, *station_config_obj;
+       struct uci_blob_param_list *dev_config, *iface_config, *vlan_config, *station_config;
 
        dev_config_obj = json_get_field(obj, "device", json_type_array);
        iface_config_obj = json_get_field(obj, "iface", json_type_array);
        vlan_config_obj = json_get_field(obj, "vlan", json_type_array);
+       station_config_obj = json_get_field(obj, "station", json_type_array);
 
-       if (!dev_config_obj || !iface_config_obj || !vlan_config_obj)
+       if (!dev_config_obj || !iface_config_obj || !vlan_config_obj || !station_config_obj)
                return;
 
        drv = calloc_a(sizeof(*drv),
                &dev_config, sizeof(*dev_config) + sizeof(void *),
                &iface_config, sizeof(*iface_config) + sizeof(void *),
                &vlan_config, sizeof(*vlan_config) + sizeof(void *),
+               &station_config, sizeof(*station_config) + sizeof(void *),
                &name_str, strlen(name) + 1,
                &script_str, strlen(script) + 1);
 
@@ -685,9 +752,14 @@ wireless_add_handler(const char *script, const char *name, json_object *obj)
        vlan_config->next[0] = &vlan_param;
        drv->vlan.config = vlan_config;
 
+       station_config->n_next = 1;
+       station_config->next[0] = &station_param;
+       drv->station.config = station_config;
+
        drv->device.buf = netifd_handler_parse_config(drv->device.config, dev_config_obj);
        drv->interface.buf = netifd_handler_parse_config(drv->interface.config, iface_config_obj);
        drv->vlan.buf = netifd_handler_parse_config(drv->vlan.config, vlan_config_obj);
+       drv->station.buf = netifd_handler_parse_config(drv->station.config, station_config_obj);
 
        drv->node.key = drv->name;
        avl_insert(&wireless_drivers, &drv->node);
@@ -708,6 +780,7 @@ void wireless_init(void)
        netifd_init_script_handlers(drv_fd, wireless_add_handler);
 }
 
+/* parse blob config into the wireless interface object */
 static void
 wireless_interface_init_config(struct wireless_interface *vif)
 {
@@ -724,11 +797,16 @@ wireless_interface_init_config(struct wireless_interface *vif)
        if (cur)
                vif->isolate = blobmsg_get_bool(cur);
 
+       cur = tb[VIF_ATTR_PROXYARP];
+       if (cur)
+               vif->proxyarp = blobmsg_get_bool(cur);
+
        cur = tb[VIF_ATTR_MODE];
        if (cur)
                vif->ap_mode = !strcmp(blobmsg_get_string(cur), "ap");
 }
 
+/* vlist update call for wireless interface list */
 static void
 vif_update(struct vlist_tree *tree, struct vlist_node *node_new,
           struct vlist_node *node_old)
@@ -751,7 +829,7 @@ vif_update(struct vlist_tree *tree, struct vlist_node *node_new,
                }
 
                D(WIRELESS, "Update wireless interface %s on device %s\n", vif_new->name, wdev->name);
-               wireless_interface_handle_link(vif_old, false);
+               wireless_interface_handle_link(vif_old, NULL, false);
                free(vif_old->config);
                vif_old->config = blob_memdup(vif_new->config);
                vif_old->isolate = vif_new->isolate;
@@ -765,7 +843,7 @@ vif_update(struct vlist_tree *tree, struct vlist_node *node_new,
                wireless_interface_init_config(vif_new);
        } else if (vif_old) {
                D(WIRELESS, "Delete wireless interface %s on device %s\n", vif_old->name, wdev->name);
-               wireless_interface_handle_link(vif_old, false);
+               wireless_interface_handle_link(vif_old, NULL, false);
                free((void *) vif_old->section);
                free(vif_old->config);
                free(vif_old);
@@ -774,6 +852,7 @@ vif_update(struct vlist_tree *tree, struct vlist_node *node_new,
        wdev_set_config_state(wdev, IFC_RELOAD);
 }
 
+/* parse blob config into the vlan object */
 static void
 wireless_vlan_init_config(struct wireless_vlan *vlan)
 {
@@ -791,6 +870,7 @@ wireless_vlan_init_config(struct wireless_vlan *vlan)
                vlan->isolate = blobmsg_get_bool(cur);
 }
 
+/* vlist update call for vlan list */
 static void
 vlan_update(struct vlist_tree *tree, struct vlist_node *node_new,
            struct vlist_node *node_old)
@@ -835,6 +915,46 @@ vlan_update(struct vlist_tree *tree, struct vlist_node *node_new,
        wdev_set_config_state(wdev, IFC_RELOAD);
 }
 
+/* vlist update call for station list */
+static void
+station_update(struct vlist_tree *tree, struct vlist_node *node_new,
+              struct vlist_node *node_old)
+{
+       struct wireless_station *sta_old = container_of(node_old, struct wireless_station, node);
+       struct wireless_station *sta_new = container_of(node_new, struct wireless_station, node);
+       struct wireless_device *wdev;
+
+       if (sta_old)
+               wdev = sta_old->wdev;
+       else
+               wdev = sta_new->wdev;
+
+       if (sta_old && sta_new) {
+               free((void *) sta_old->section);
+               sta_old->section = strdup(sta_new->section);
+               if (blob_attr_equal(sta_old->config, sta_new->config)) {
+                       free(sta_new);
+                       return;
+               }
+
+               D(WIRELESS, "Update wireless station %s on device %s\n", sta_new->name, wdev->name);
+               free(sta_old->config);
+               sta_old->config = blob_memdup(sta_new->config);
+               free(sta_new);
+       } else if (sta_new) {
+               D(WIRELESS, "Create new wireless station %s on device %s\n", sta_new->name, wdev->name);
+               sta_new->section = strdup(sta_new->section);
+               sta_new->config = blob_memdup(sta_new->config);
+       } else if (sta_old) {
+               D(WIRELESS, "Delete wireless station %s on device %s\n", sta_old->name, wdev->name);
+               free((void *) sta_old->section);
+               free(sta_old->config);
+               free(sta_old);
+       }
+
+       wdev_set_config_state(wdev, IFC_RELOAD);
+}
+
 static void
 wireless_proc_poll_fd(struct uloop_fd *fd, unsigned int events)
 {
@@ -862,6 +982,8 @@ done:
        wireless_close_script_proc_fd(wdev);
 }
 
+/* watchdog and garbage collector for wireless processes.
+ * It cleans up terminated processes. If a process is a requirement for the wireless device, it retries the setup */
 static void
 wireless_device_check_script_tasks(struct uloop_timeout *timeout)
 {
@@ -886,6 +1008,7 @@ wireless_device_check_script_tasks(struct uloop_timeout *timeout)
                uloop_timeout_set(&wdev->script_check, 1000);
 }
 
+/* creates a wireless device object. Called by config */
 void
 wireless_device_create(struct wireless_driver *drv, const char *name, struct blob_attr *data)
 {
@@ -921,6 +1044,8 @@ wireless_device_create(struct wireless_driver *drv, const char *name, struct blo
        wdev->interfaces.keep_old = true;
        vlist_init(&wdev->vlans, avl_strcmp, vlan_update);
        wdev->vlans.keep_old = true;
+       vlist_init(&wdev->stations, avl_strcmp, station_update);
+       wdev->stations.keep_old = true;
 
        wdev->timeout.cb = wireless_device_setup_timeout;
        wdev->script_task.cb = wireless_device_script_task_cb;
@@ -935,6 +1060,50 @@ wireless_device_create(struct wireless_driver *drv, const char *name, struct blo
        vlist_add(&wireless_devices, &wdev->node, wdev->name);
 }
 
+/* creates a wireless station object. Called by config */
+void
+wireless_station_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section)
+{
+       struct wireless_station *sta;
+       struct blob_attr *tb[__STA_ATTR_MAX];
+       struct blob_attr *cur;
+       char *name_buf, *vif_buf;
+       char name[8];
+
+       blobmsg_parse(sta_policy, __STA_ATTR_MAX, tb, blob_data(data), blob_len(data));
+
+       cur = tb[STA_ATTR_DISABLED];
+       if (cur && blobmsg_get_bool(cur))
+               return;
+
+       sprintf(name, "%d", wdev->vlan_idx++);
+
+       sta = calloc_a(sizeof(*sta),
+                      &name_buf, strlen(name) + 1,
+                      &vif_buf, strlen(vif) + 1);
+       sta->name = strcpy(name_buf, name);
+       sta->vif = strcpy(vif_buf, vif);
+       sta->wdev = wdev;
+       sta->config = data;
+       sta->section = section;
+
+       vlist_add(&wdev->stations, &sta->node, sta->name);
+}
+
+/* ubus callback network.wireless.status, runs for every interface, encode the station */
+static void
+wireless_station_status(struct wireless_station *sta, struct blob_buf *b)
+{
+       void *i;
+
+       i = blobmsg_open_table(b, NULL);
+       if (sta->section)
+               blobmsg_add_string(b, "section", sta->section);
+       put_container(b, sta->config, "config");
+       blobmsg_close_table(b, i);
+}
+
+/* create a vlan object. Called by config */
 void
 wireless_vlan_create(struct wireless_device *wdev, char *vif, struct blob_attr *data, const char *section)
 {
@@ -965,6 +1134,7 @@ wireless_vlan_create(struct wireless_device *wdev, char *vif, struct blob_attr *
        vlist_add(&wdev->vlans, &vlan->node, vlan->name);
 }
 
+/* ubus callback network.wireless.status, runs for every interface, encode the vlan informations */
 static void
 wireless_vlan_status(struct wireless_vlan *vlan, struct blob_buf *b)
 {
@@ -979,6 +1149,7 @@ wireless_vlan_status(struct wireless_vlan *vlan, struct blob_buf *b)
        blobmsg_close_table(b, i);
 }
 
+/* create a wireless interface object. Called by config */
 struct wireless_interface* wireless_interface_create(struct wireless_device *wdev, struct blob_attr *data, const char *section)
 {
        struct wireless_interface *vif;
@@ -1004,13 +1175,16 @@ struct wireless_interface* wireless_interface_create(struct wireless_device *wde
        vif->isolate = false;
 
        vlist_add(&wdev->interfaces, &vif->node, vif->name);
-       return vif;
+
+       return vlist_find(&wdev->interfaces, name, vif, node);
 }
 
+/* ubus callback network.wireless.status, runs for every interface */
 static void
 wireless_interface_status(struct wireless_interface *iface, struct blob_buf *b)
 {
        struct wireless_vlan *vlan;
+       struct wireless_station *sta;
        void *i, *j;
 
        i = blobmsg_open_table(b, NULL);
@@ -1024,9 +1198,15 @@ wireless_interface_status(struct wireless_interface *iface, struct blob_buf *b)
                if (!strcmp(iface->name, vlan->vif))
                        wireless_vlan_status(vlan, b);
        blobmsg_close_array(b, j);
+       j = blobmsg_open_array(b, "stations");
+       vlist_for_each_element(&iface->wdev->stations, sta, node)
+               if (!strcmp(iface->name, sta->vif))
+                       wireless_station_status(sta, b);
+       blobmsg_close_array(b, j);
        blobmsg_close_table(b, i);
 }
 
+/* ubus callback network.wireless.status */
 void
 wireless_device_status(struct wireless_device *wdev, struct blob_buf *b)
 {
@@ -1048,6 +1228,7 @@ wireless_device_status(struct wireless_device *wdev, struct blob_buf *b)
        blobmsg_close_table(b, c);
 }
 
+/* ubus callback network.wireless.get_validate */
 void
 wireless_device_get_validate(struct wireless_device *wdev, struct blob_buf *b)
 {
@@ -1072,6 +1253,7 @@ wireless_device_get_validate(struct wireless_device *wdev, struct blob_buf *b)
        blobmsg_close_table(b, c);
 }
 
+/* ubus callback network.wireless.notify, command = set data, for vif */
 static void
 wireless_interface_set_data(struct wireless_interface *vif)
 {
@@ -1092,6 +1274,7 @@ wireless_interface_set_data(struct wireless_interface *vif)
                vif->ifname = blobmsg_data(cur);
 }
 
+/* ubus callback network.wireless.notify, command = set data, for vlan */
 static void
 wireless_vlan_set_data(struct wireless_vlan *vlan)
 {
@@ -1112,6 +1295,7 @@ wireless_vlan_set_data(struct wireless_vlan *vlan)
                vlan->ifname = blobmsg_data(cur);
 }
 
+/* ubus callback network.wireless.notify, command = process add */
 static int
 wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data)
 {
@@ -1119,12 +1303,14 @@ wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data
                PROC_ATTR_PID,
                PROC_ATTR_EXE,
                PROC_ATTR_REQUIRED,
+               PROC_ATTR_KEEP,
                __PROC_ATTR_MAX
        };
        static const struct blobmsg_policy proc_policy[__PROC_ATTR_MAX] = {
                [PROC_ATTR_PID] = { .name = "pid", .type = BLOBMSG_TYPE_INT32 },
                [PROC_ATTR_EXE] = { .name = "exe", .type = BLOBMSG_TYPE_STRING },
                [PROC_ATTR_REQUIRED] = { .name = "required", .type = BLOBMSG_TYPE_BOOL },
+               [PROC_ATTR_KEEP] = { .name = "keep", .type = BLOBMSG_TYPE_BOOL },
        };
        struct blob_attr *tb[__PROC_ATTR_MAX];
        struct wireless_process *proc;
@@ -1151,6 +1337,9 @@ wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data
        if (tb[PROC_ATTR_REQUIRED])
                proc->required = blobmsg_get_bool(tb[PROC_ATTR_REQUIRED]);
 
+       if (tb[PROC_ATTR_KEEP])
+               proc->keep = blobmsg_get_bool(tb[PROC_ATTR_KEEP]);
+
        D(WIRELESS, "Wireless device '%s' add pid %d\n", wdev->name, proc->pid);
        list_add(&proc->list, &wdev->script_proc);
        uloop_timeout_set(&wdev->script_check, 0);
@@ -1158,6 +1347,7 @@ wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data
        return 0;
 }
 
+/* ubus callback network.wireless.notify, command = process kill all */
 static int
 wireless_device_process_kill_all(struct wireless_device *wdev, struct blob_attr *data,
                                 struct ubus_request_data *req)
@@ -1198,6 +1388,7 @@ wireless_device_process_kill_all(struct wireless_device *wdev, struct blob_attr
        return 0;
 }
 
+/* ubus callback network.wireless.notify, command = set_retry */
 static int
 wireless_device_set_retry(struct wireless_device *wdev, struct blob_attr *data)
 {
@@ -1222,6 +1413,7 @@ enum {
        NOTIFY_CMD_SET_RETRY = 4,
 };
 
+/* ubus callback network.wireless.notify */
 int
 wireless_device_notify(struct wireless_device *wdev, struct blob_attr *data,
                       struct ubus_request_data *req)
@@ -1305,6 +1497,7 @@ wireless_device_notify(struct wireless_device *wdev, struct blob_attr *data,
        return 0;
 }
 
+/* called on startup and by netifd reload() */
 void
 wireless_start_pending(void)
 {
@@ -1313,3 +1506,36 @@ wireless_start_pending(void)
        vlist_for_each_element(&wireless_devices, wdev, node)
                __wireless_device_set_up(wdev, 0);
 }
+
+void wireless_device_hotplug_event(const char *name, bool add)
+{
+       struct wireless_interface *vif;
+       struct wireless_device *wdev;
+       const char *s;
+       int len;
+
+       s = strstr(name, ".sta");
+       if (s) {
+               if (strchr(s + 4, '.'))
+                       return;
+
+               len = s - name;
+       } else if (!device_find(name)) {
+               len = strlen(name);
+       } else {
+               return;
+       }
+
+       vlist_for_each_element(&wireless_devices, wdev, node) {
+               vlist_for_each_element(&wdev->interfaces, vif, node) {
+                       if (!vif->ifname)
+                               continue;
+
+                       if (strlen(vif->ifname) != len ||
+                           strncmp(vif->ifname, name, len) != 0)
+                               continue;
+
+                       wireless_interface_handle_link(vif, name, add);
+               }
+       }
+}