developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 1 | From a08f87c88e8abd539dc75b7fcb15fef786d5a61d Mon Sep 17 00:00:00 2001 |
developer | 9a58788 | 2023-07-17 11:11:44 +0800 | [diff] [blame] | 2 | From: Michael Lee <michael-cy.lee@mediatek.com> |
| 3 | Date: Thu, 13 Jul 2023 13:14:26 +0800 |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 4 | Subject: [PATCH 29/54] mtk: hostapd: Check the bridge after ioctl SIOCBRADDIF |
developer | bddc9db | 2023-09-11 13:34:36 +0800 | [diff] [blame] | 5 | failed |
developer | 9a58788 | 2023-07-17 11:11:44 +0800 | [diff] [blame] | 6 | |
| 7 | If ioctl returns EBUSY on command SIOCBRADDIF, the interface might |
| 8 | already be bridged by others, and linux_br_add_if should not indicate an |
| 9 | error in the case. |
| 10 | |
| 11 | This patch checks whether the interface is correctly brigded when ioctl |
| 12 | returns EBUSY. |
| 13 | |
| 14 | Signed-off-by: Michael Lee <michael-cy.lee@mediatek.com> |
| 15 | --- |
| 16 | src/drivers/linux_ioctl.c | 16 ++++++++++++++-- |
| 17 | 1 file changed, 14 insertions(+), 2 deletions(-) |
| 18 | |
| 19 | diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 20 | index 7edb9df2e..b8c1af2e3 100644 |
developer | 9a58788 | 2023-07-17 11:11:44 +0800 | [diff] [blame] | 21 | --- a/src/drivers/linux_ioctl.c |
| 22 | +++ b/src/drivers/linux_ioctl.c |
| 23 | @@ -150,7 +150,8 @@ int linux_br_del(int sock, const char *brname) |
| 24 | int linux_br_add_if(int sock, const char *brname, const char *ifname) |
| 25 | { |
| 26 | struct ifreq ifr; |
| 27 | - int ifindex; |
| 28 | + int ifindex, ret; |
| 29 | + char in_br[IFNAMSIZ]; |
| 30 | |
| 31 | ifindex = if_nametoindex(ifname); |
| 32 | if (ifindex == 0) |
| 33 | @@ -164,8 +165,19 @@ int linux_br_add_if(int sock, const char *brname, const char *ifname) |
| 34 | |
| 35 | wpa_printf(MSG_DEBUG, "Could not add interface %s into bridge " |
| 36 | "%s: %s", ifname, brname, strerror(errno)); |
| 37 | + |
| 38 | + /* If ioctl returns -EBUSY when adding interface into bridge, |
| 39 | + * the interface might already be added by netifd, so here we |
| 40 | + * check whether the interface is currently on the right |
| 41 | + * bridge. */ |
| 42 | + if(errno == EBUSY && linux_br_get(in_br, ifname) == 0 && |
| 43 | + os_strcmp(in_br, brname) == 0) |
| 44 | + ret = 0; |
| 45 | + else |
| 46 | + ret = -1; |
| 47 | + |
| 48 | errno = saved_errno; |
| 49 | - return -1; |
| 50 | + return ret; |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | -- |
developer | bddc9db | 2023-09-11 13:34:36 +0800 | [diff] [blame] | 55 | 2.18.0 |
developer | 9a58788 | 2023-07-17 11:11:44 +0800 | [diff] [blame] | 56 | |