[][MAC80211][hostapd][Fix wds AP interface adding issue]
[Description]
Fix wds AP interface adding issue.
After hostapd creates a AP_VLAN interface, it adds the interface into
br-lan, and concurrently netifd also tries to add the interface into
br-lan, which might cause a race condition. In hostpad, linux_br_add_if
used to return -1 if ioctl return error.
A status check is added to see if the interface is correctly bridged
before linux_br_add_if return error.
[Release-log]
N/A
Change-Id: I599585cea12b335ba1a37e2df3f1a3807621602c
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7743343
diff --git a/autobuild_mac80211_release/package/network/services/hostapd_new/patches/mtk-0035-hostapd-mtk-Check-the-bridge-after-ioctl-SIOCBRADDIF.patch b/autobuild_mac80211_release/package/network/services/hostapd_new/patches/mtk-0035-hostapd-mtk-Check-the-bridge-after-ioctl-SIOCBRADDIF.patch
new file mode 100644
index 0000000..1937640
--- /dev/null
+++ b/autobuild_mac80211_release/package/network/services/hostapd_new/patches/mtk-0035-hostapd-mtk-Check-the-bridge-after-ioctl-SIOCBRADDIF.patch
@@ -0,0 +1,55 @@
+From 99159b174eb245a7162fe38900971cdff017cf75 Mon Sep 17 00:00:00 2001
+From: Michael Lee <michael-cy.lee@mediatek.com>
+Date: Thu, 13 Jul 2023 13:14:26 +0800
+Subject: [PATCH] hostapd: mtk: Check the bridge after ioctl SIOCBRADDIF failed
+
+If ioctl returns EBUSY on command SIOCBRADDIF, the interface might
+already be bridged by others, and linux_br_add_if should not indicate an
+error in the case.
+
+This patch checks whether the interface is correctly brigded when ioctl
+returns EBUSY.
+
+Signed-off-by: Michael Lee <michael-cy.lee@mediatek.com>
+---
+ src/drivers/linux_ioctl.c | 16 ++++++++++++++--
+ 1 file changed, 14 insertions(+), 2 deletions(-)
+
+diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c
+index 7edb9df..b8c1af2 100644
+--- a/src/drivers/linux_ioctl.c
++++ b/src/drivers/linux_ioctl.c
+@@ -150,7 +150,8 @@ int linux_br_del(int sock, const char *brname)
+ int linux_br_add_if(int sock, const char *brname, const char *ifname)
+ {
+ struct ifreq ifr;
+- int ifindex;
++ int ifindex, ret;
++ char in_br[IFNAMSIZ];
+
+ ifindex = if_nametoindex(ifname);
+ if (ifindex == 0)
+@@ -164,8 +165,19 @@ int linux_br_add_if(int sock, const char *brname, const char *ifname)
+
+ wpa_printf(MSG_DEBUG, "Could not add interface %s into bridge "
+ "%s: %s", ifname, brname, strerror(errno));
++
++ /* If ioctl returns -EBUSY when adding interface into bridge,
++ * the interface might already be added by netifd, so here we
++ * check whether the interface is currently on the right
++ * bridge. */
++ if(errno == EBUSY && linux_br_get(in_br, ifname) == 0 &&
++ os_strcmp(in_br, brname) == 0)
++ ret = 0;
++ else
++ ret = -1;
++
+ errno = saved_errno;
+- return -1;
++ return ret;
+ }
+
+ return 0;
+--
+2.25.1
+