blob: 57b8060de3e8a8b805eb103113613e1a20a22782 [file] [log] [blame]
From a08f87c88e8abd539dc75b7fcb15fef786d5a61d 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 29/54] mtk: hostapd: 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 7edb9df2e..b8c1af2e3 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.18.0