developer | 8bff647 | 2023-07-17 11:11:44 +0800 | [diff] [blame^] | 1 | From 99159b174eb245a7162fe38900971cdff017cf75 Mon Sep 17 00:00:00 2001 |
| 2 | From: Michael Lee <michael-cy.lee@mediatek.com> |
| 3 | Date: Thu, 13 Jul 2023 13:14:26 +0800 |
| 4 | Subject: [PATCH] hostapd: mtk: Check the bridge after ioctl SIOCBRADDIF failed |
| 5 | |
| 6 | If ioctl returns EBUSY on command SIOCBRADDIF, the interface might |
| 7 | already be bridged by others, and linux_br_add_if should not indicate an |
| 8 | error in the case. |
| 9 | |
| 10 | This patch checks whether the interface is correctly brigded when ioctl |
| 11 | returns EBUSY. |
| 12 | |
| 13 | Signed-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 | |
| 18 | diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c |
| 19 | index 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 | -- |
| 54 | 2.25.1 |
| 55 | |