blob: 193764051c385902682839050e96fd2f5509a29c [file] [log] [blame]
developer1a173672023-12-21 14:49:33 +08001From 99159b174eb245a7162fe38900971cdff017cf75 Mon Sep 17 00:00:00 2001
developer9a587882023-07-17 11:11:44 +08002From: Michael Lee <michael-cy.lee@mediatek.com>
3Date: Thu, 13 Jul 2023 13:14:26 +0800
developer1a173672023-12-21 14:49:33 +08004Subject: [PATCH] hostapd: mtk: Check the bridge after ioctl SIOCBRADDIF failed
developer9a587882023-07-17 11:11:44 +08005
6If ioctl returns EBUSY on command SIOCBRADDIF, the interface might
7already be bridged by others, and linux_br_add_if should not indicate an
8error in the case.
9
10This patch checks whether the interface is correctly brigded when ioctl
11returns EBUSY.
12
13Signed-off-by: Michael Lee <michael-cy.lee@mediatek.com>
14---
15 src/drivers/linux_ioctl.c | 16 ++++++++++++++--
16 1 file changed, 14 insertions(+), 2 deletions(-)
17
18diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c
19index 7edb9df..b8c1af2 100644
20--- a/src/drivers/linux_ioctl.c
21+++ b/src/drivers/linux_ioctl.c
22@@ -150,7 +150,8 @@ int linux_br_del(int sock, const char *brname)
23 int linux_br_add_if(int sock, const char *brname, const char *ifname)
24 {
25 struct ifreq ifr;
26- int ifindex;
27+ int ifindex, ret;
28+ char in_br[IFNAMSIZ];
29
30 ifindex = if_nametoindex(ifname);
31 if (ifindex == 0)
32@@ -164,8 +165,19 @@ int linux_br_add_if(int sock, const char *brname, const char *ifname)
33
34 wpa_printf(MSG_DEBUG, "Could not add interface %s into bridge "
35 "%s: %s", ifname, brname, strerror(errno));
36+
37+ /* If ioctl returns -EBUSY when adding interface into bridge,
38+ * the interface might already be added by netifd, so here we
39+ * check whether the interface is currently on the right
40+ * bridge. */
41+ if(errno == EBUSY && linux_br_get(in_br, ifname) == 0 &&
42+ os_strcmp(in_br, brname) == 0)
43+ ret = 0;
44+ else
45+ ret = -1;
46+
47 errno = saved_errno;
48- return -1;
49+ return ret;
50 }
51
52 return 0;
53--
developer1a173672023-12-21 14:49:33 +0800542.25.1
developer9a587882023-07-17 11:11:44 +080055