hostapd: Check the bridge after ioctl SIOCBRADDIF failed

Michael-CY Lee michael-cy.lee at mediatek.com
Wed Dec 13 18:01:10 PST 2023


From: Michael Lee <michael-cy.lee at mediatek.com>

If ioctl returns EBUSY on the command SIOCBRADDIF, the interface might
already be bridged by others (e.g. netifd in OpenWrt), and linux_br_add_if
should not indicate an error.

This patch checks whether the interface is correctly brigded when ioctl
returns EBUSY.

Signed-off-by: Michael-CY Lee <michael-cy.lee at mediatek.com>
---
 src/drivers/linux_ioctl.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c
index 7edb9df..b606fac 100644
--- a/src/drivers/linux_ioctl.c
+++ b/src/drivers/linux_ioctl.c
@@ -151,6 +151,7 @@ int linux_br_add_if(int sock, const char *brname, const char *ifname)
 {
 	struct ifreq ifr;
 	int ifindex;
+	char in_br[IFNAMSIZ];
 
 	ifindex = if_nametoindex(ifname);
 	if (ifindex == 0)
@@ -165,7 +166,14 @@ 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));
 		errno = saved_errno;
-		return -1;
+
+		/* If ioctl returns EBUSY when adding interface into bridge,
+		 * the interface might already be added by others, so checks
+		 * 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)
+			return -1;
 	}
 
 	return 0;
-- 
2.25.1




More information about the Hostap mailing list