]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
hostapd: Check the bridge if ioctl SIOCBRADDIF fails
authorMichael-CY Lee <michael-cy.lee@mediatek.com>
Thu, 14 Dec 2023 02:08:47 +0000 (10:08 +0800)
committerJouni Malinen <j@w1.fi>
Sat, 16 Dec 2023 16:16:05 +0000 (18:16 +0200)
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 <michael-cy.lee@mediatek.com>
src/drivers/linux_ioctl.c

index 7edb9df2edd49a3bfafec49ef1b0307ebc99cb6e..29abc0c59e8383ec17240b57a6852869982238ba 100644 (file)
@@ -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;