ukanth / afwall

AFWall+ (Android Firewall +) - iptables based firewall for Android
GNU General Public License v3.0
2.68k stars 447 forks source link

[ISSUE] “Error applying iptables rules” 30% of cases when Add Delay is selected #1353

Open resolutecake opened 8 months ago

resolutecake commented 8 months ago

Describe the bug Due to inadequate parallelism code, iptables commands are delayed several seconds causes “Error applying iptables rules” — fix: options -w1 -W1 to iptables for Android 11+ — retire Android less than 11, since those devices have unsupported swelling batteries anyway — or fix the non-wait code, I didn’t bother

I would HIGHLY RECOMMEND to always use Add Delay and retire all pre-Android 11 devices

Firewall Logs Please get the log from Menu -> Show Rules -> (menu) Export to storage and attach it here

Smartphone (please complete the following information): Pixel 3/6/Samsung all

Additional context There are two threads doing iptables but each collision waits 1 s: check man iptables to understand how its concurrency is supposed to work

jackpennetta commented 8 months ago

Hi! Yesterday I had to install a fresh Android (upgrading from pie to android 13 [pixel experience]) on my phone with the last magisk root, and everything's going well so I wanted to install Afwall+ to secure my apps' internet connection, as I usually do on fresh androids. Anyway once installed and configured the apk I tried to enable it applying the rules, but it seems to be impossible to proceed: the counter stucks at 46 or 47/113 (no matter which app I select, the same if none selected) for both ipv4 and ipv6 (same disabling ipv6) in "allow selected" mode. Same happens in "block selected" mode. It only enables the firewall in block selected if none is selected. I the previous system I had sporadic "error applying rules" but now I get it every time and then the connection hangs. I understand it may be related with this topic but I'm not sure so I'm asking here before.

Should I try to fix as suggested above (fix: options -w1 -W1 to iptables for Android 11+) ? How am I supposed to apply -w1 -W1 options using the app? Thanks in advance and please pardon me for my bad english

p.s. I forgot to mention that the "add delay" option didn't change anything in this case

Mannshoch commented 8 months ago

Same Problem here, If Afwall work. It seems not working permanently.It seems a bit random bit sometims no Internet connection is possible. I assum that whitelist and unsucessfull load was the causr.

Exporting rules also not worked so I had to remove and downgrade AFWall and recreate all rules.

vsatmydynipnet commented 8 months ago

running into the same problems:

Ruuning LOS20 on Fairphone 3+, rooted with Magisk.

resolutecake commented 8 months ago

The app has several bugs, I am running my own branch

The -w1 -W1 is a code change in the app that I diagnosed and completed. Once the right answer is known, coding the fix is quick. -w1 -W1 are options to the iptables command available in Android since 11, and they allow iptables to retry concurrency collisions rather than doing retries outside the executable.

For some reason multiple threads do the iptables and the parallelism design is bad. This is why rules apply fails in 30% of cases whether with or without AddDelay. When anything fails, AFWall+ goes to a default which is blocking almost anything

I also fixed some crashes that also leads to block everything

3.5.3 is simply not reliable, but that is what people use. AFWall+ is only game in town

resolutecake commented 8 months ago

And you must use Active Rules or there is no VPN control (note: if Active Rule is unselected checkbox settings in LAN and VPN are lost)

If you only want to control wi-fi and wan, Active Rules can be cleared, and fewer rules applications happen that may fail and cause block-all state

resolutecake commented 8 months ago

The fix for AFWall+ bad state is to Apply Rules again If you want it disabled, first enable then disable

Unless the last shown thing was a toaster “Rules applied with success” AFWall+ is in a bad state

Marksway commented 6 months ago

The app has several bugs, I am running my own branch https://github.com/ukanth/afwall/issues/1353#issuecomment-1726709198

Hello. Is it possible to test your build with new changes? If everything works, it might be great to send a pull request.