From 0af4c1478efe23f8dfc053a6c18a6838d56d22d1 Mon Sep 17 00:00:00 2001 From: Michael-CY Lee Date: Thu, 14 Dec 2023 10:08:47 +0800 Subject: [PATCH] hostapd: Check the bridge if ioctl SIOCBRADDIF fails If ioctl() returns EBUSY on the command SIOCBRADDIF, the interface might have already been added to the bridge by an external operation (e.g., netifd in OpenWrt), and linux_br_add_if() should not indicate an error. Check whether the interface is correctly brigded when ioctl() returns EBUSY and if so, report success. Signed-off-by: Michael-CY Lee --- src/drivers/linux_ioctl.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c index 7edb9df2e..29abc0c59 100644 --- a/src/drivers/linux_ioctl.c +++ b/src/drivers/linux_ioctl.c @@ -161,11 +161,20 @@ int linux_br_add_if(int sock, const char *brname, const char *ifname) ifr.ifr_ifindex = ifindex; if (ioctl(sock, SIOCBRADDIF, &ifr) < 0) { int saved_errno = errno; + char in_br[IFNAMSIZ]; 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 an interface into the + * bridge, the interface might have already been added by an + * external operation, so check whether the interface is + * currently on the right bridge and ignore the error if it is. + */ + if (errno != EBUSY || linux_br_get(in_br, ifname) != 0 || + os_strcmp(in_br, brname) != 0) + return -1; } return 0; -- 2.47.2