| From 942808028d207776f1a4dbe678166282fb272b37 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 056/104] 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, 15 insertions(+), 1 deletion(-) |
| |
| diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c |
| index 29abc0c59..73d27825d 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) |
| @@ -165,6 +166,17 @@ 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; |
| |
| /* If ioctl() returns EBUSY when adding an interface into the |
| @@ -175,6 +187,8 @@ int linux_br_add_if(int sock, const char *brname, const char *ifname) |
| if (errno != EBUSY || linux_br_get(in_br, ifname) != 0 || |
| os_strcmp(in_br, brname) != 0) |
| return -1; |
| + |
| + return ret; |
| } |
| |
| return 0; |
| -- |
| 2.39.2 |
| |