aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2021-05-18 12:16:11 +0200
committerFelix Fietkau <nbd@nbd.name>2021-05-18 12:52:52 +0200
commit2d89d7c7482333ecf2697dbca705f627b8bf9b52 (patch)
tree66d33590b8bda87eae9b16ae25ff2a946cafb05f
parent04d21604fd72f337c8a0410d13b3d878914b7e7e (diff)
downloadupstream-2d89d7c7482333ecf2697dbca705f627b8bf9b52.tar.gz
upstream-2d89d7c7482333ecf2697dbca705f627b8bf9b52.tar.bz2
upstream-2d89d7c7482333ecf2697dbca705f627b8bf9b52.zip
hostapd: add ubus notifications for adding/removing vlan interfaces
This can be used to handle network configuration of dynamically created vlan interfaces in a more flexible way Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--package/network/services/hostapd/patches/600-ubus_support.patch38
-rw-r--r--package/network/services/hostapd/patches/700-wifi-reload.patch2
-rw-r--r--package/network/services/hostapd/src/src/ap/ubus.c37
-rw-r--r--package/network/services/hostapd/src/src/ap/ubus.h2
4 files changed, 78 insertions, 1 deletions
diff --git a/package/network/services/hostapd/patches/600-ubus_support.patch b/package/network/services/hostapd/patches/600-ubus_support.patch
index 938840755a..0d1cb2c3e4 100644
--- a/package/network/services/hostapd/patches/600-ubus_support.patch
+++ b/package/network/services/hostapd/patches/600-ubus_support.patch
@@ -424,3 +424,41 @@
}
+--- a/src/ap/vlan_init.c
++++ b/src/ap/vlan_init.c
+@@ -22,6 +22,7 @@
+ static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan,
+ int existsok)
+ {
++ bool vlan_exists = iface_exists(vlan->ifname);
+ int ret;
+ #ifdef CONFIG_WEP
+ int i;
+@@ -36,7 +37,7 @@ static int vlan_if_add(struct hostapd_da
+ }
+ #endif /* CONFIG_WEP */
+
+- if (!iface_exists(vlan->ifname))
++ if (!vlan_exists)
+ ret = hostapd_vlan_if_add(hapd, vlan->ifname);
+ else if (!existsok)
+ return -1;
+@@ -51,6 +52,9 @@ static int vlan_if_add(struct hostapd_da
+ if (hapd->wpa_auth)
+ ret = wpa_auth_ensure_group(hapd->wpa_auth, vlan->vlan_id);
+
++ if (!ret && !vlan_exists)
++ hostapd_ubus_add_vlan(hapd, vlan);
++
+ if (ret == 0)
+ return ret;
+
+@@ -77,6 +81,8 @@ int vlan_if_remove(struct hostapd_data *
+ "WPA deinitialization for VLAN %d failed (%d)",
+ vlan->vlan_id, ret);
+
++ hostapd_ubus_remove_vlan(hapd, vlan);
++
+ return hostapd_vlan_if_remove(hapd, vlan->ifname);
+ }
+
diff --git a/package/network/services/hostapd/patches/700-wifi-reload.patch b/package/network/services/hostapd/patches/700-wifi-reload.patch
index d5520d0b77..b68c1aaa9d 100644
--- a/package/network/services/hostapd/patches/700-wifi-reload.patch
+++ b/package/network/services/hostapd/patches/700-wifi-reload.patch
@@ -174,7 +174,7 @@
hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
-@@ -4493,6 +4493,9 @@ static int wpa_driver_nl80211_set_ap(voi
+@@ -4511,6 +4511,9 @@ static int wpa_driver_nl80211_set_ap(voi
if (ret) {
wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
ret, strerror(-ret));
diff --git a/package/network/services/hostapd/src/src/ap/ubus.c b/package/network/services/hostapd/src/src/ap/ubus.c
index d03b848f94..a34695f36a 100644
--- a/package/network/services/hostapd/src/src/ap/ubus.c
+++ b/package/network/services/hostapd/src/src/ap/ubus.c
@@ -1364,6 +1364,43 @@ void hostapd_ubus_free_bss(struct hostapd_data *hapd)
free(name);
}
+static void
+hostapd_ubus_vlan_action(struct hostapd_data *hapd, struct hostapd_vlan *vlan,
+ const char *action)
+{
+ struct vlan_description *desc = &vlan->vlan_desc;
+ void *c;
+ int i;
+
+ if (!hapd->ubus.obj.has_subscribers)
+ return;
+
+ blob_buf_init(&b, 0);
+ blobmsg_add_string(&b, "ifname", vlan->ifname);
+ blobmsg_add_string(&b, "bridge", vlan->bridge);
+ blobmsg_add_u32(&b, "vlan_id", vlan->vlan_id);
+
+ if (desc->notempty) {
+ blobmsg_add_u32(&b, "untagged", desc->untagged);
+ c = blobmsg_open_array(&b, "tagged");
+ for (i = 0; i < ARRAY_SIZE(desc->tagged) && desc->tagged[i]; i++)
+ blobmsg_add_u32(&b, "", desc->tagged[i]);
+ blobmsg_close_array(&b, c);
+ }
+
+ ubus_notify(ctx, &hapd->ubus.obj, action, b.head, -1);
+}
+
+void hostapd_ubus_add_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan)
+{
+ hostapd_ubus_vlan_action(hapd, vlan, "vlan_add");
+}
+
+void hostapd_ubus_remove_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan)
+{
+ hostapd_ubus_vlan_action(hapd, vlan, "vlan_remove");
+}
+
static const struct ubus_method daemon_methods[] = {
UBUS_METHOD("config_add", hostapd_config_add, config_add_policy),
UBUS_METHOD("config_remove", hostapd_config_remove, config_remove_policy),
diff --git a/package/network/services/hostapd/src/src/ap/ubus.h b/package/network/services/hostapd/src/src/ap/ubus.h
index e16017394f..de0d1182fd 100644
--- a/package/network/services/hostapd/src/src/ap/ubus.h
+++ b/package/network/services/hostapd/src/src/ap/ubus.h
@@ -43,6 +43,8 @@ void hostapd_ubus_add_iface(struct hostapd_iface *iface);
void hostapd_ubus_free_iface(struct hostapd_iface *iface);
void hostapd_ubus_add_bss(struct hostapd_data *hapd);
void hostapd_ubus_free_bss(struct hostapd_data *hapd);
+void hostapd_ubus_add_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan);
+void hostapd_ubus_remove_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan);
int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req);
void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *mac);