Skip to content

Commit 4d2eb92

Browse files
author
ukanth
committed
#1455 negation to address subnet LAN
1 parent da3d513 commit 4d2eb92

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

  • app/src/main/java/dev/ukanth/ufirewall

app/src/main/java/dev/ukanth/ufirewall/Api.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -892,15 +892,18 @@ private static void addInterfaceRouting(Context ctx, List<String> cmds, boolean
892892

893893
if (G.enableLAN() && !cfg.isWifiTethered) {
894894
// Support multiple LAN subnets (Issue #1362)
895-
boolean hasSubnets = false;
896895
if (ipv6) {
897896
if (!cfg.lanMaskV6.isEmpty()) {
898897
for (String subnet : cfg.lanMaskV6) {
899898
cmds.add("-A " + chainName + "-wifi-fork -d " + subnet + " -j " + chainName + "-wifi-lan");
900899
}
901-
hasSubnets = true;
902-
// Route everything else to WAN
903-
cmds.add("-A " + chainName + "-wifi-fork -j " + chainName + "-wifi-wan");
900+
// Add negation rule to route non-LAN traffic to WAN
901+
// Build negation string for all v6 subnets
902+
StringBuilder negation = new StringBuilder();
903+
for (String subnet : cfg.lanMaskV6) {
904+
negation.append("'!' -d ").append(subnet).append(" ");
905+
}
906+
cmds.add("-A " + chainName + "-wifi-fork " + negation.toString().trim() + " -j " + chainName + "-wifi-wan");
904907
} else {
905908
Log.i(TAG, "no ipv6 found: " + G.enableIPv6() + "," + cfg.lanMaskV6);
906909
}
@@ -909,14 +912,18 @@ private static void addInterfaceRouting(Context ctx, List<String> cmds, boolean
909912
for (String subnet : cfg.lanMaskV4) {
910913
cmds.add("-A " + chainName + "-wifi-fork -d " + subnet + " -j " + chainName + "-wifi-lan");
911914
}
912-
hasSubnets = true;
913-
// Route everything else to WAN
914-
cmds.add("-A " + chainName + "-wifi-fork -j " + chainName + "-wifi-wan");
915+
// Add negation rule to route non-LAN traffic to WAN
916+
// Build negation string for all v4 subnets
917+
StringBuilder negation = new StringBuilder();
918+
for (String subnet : cfg.lanMaskV4) {
919+
negation.append("'!' -d ").append(subnet).append(" ");
920+
}
921+
cmds.add("-A " + chainName + "-wifi-fork " + negation.toString().trim() + " -j " + chainName + "-wifi-wan");
915922
} else {
916923
Log.i(TAG, "no ipv4 found:" + G.enableIPv6() + "," + cfg.lanMaskV4);
917924
}
918925
}
919-
if (!hasSubnets) {
926+
if (cfg.lanMaskV4.isEmpty() && cfg.lanMaskV6.isEmpty()) {
920927
Log.i(TAG, "No ipaddress found for LAN");
921928
// lets find one more time
922929
//atleast allow internet - don't block completely

0 commit comments

Comments
 (0)