fix: tun and tproxy+zapret regressions

This commit is contained in:
FUFSoB committed 2026-09-27 13:34:24 +05:00
1 parent d5e926b034
commit 845291ee49
7 files changed
+33

No files matched your search

@@ -75,6 +75,9 @@ let
}}
${nft} -f ${perAppTunChainFile}
${perAppTunWaitForInterface}
# The backend may not have brought the link up yet, and routes via a down link fail
# with "Device for nexthop is not up".
${ip} link set dev ${lib.escapeShellArg perAppRoutingTun.interface} up
tun_addr="''${tun_cidr%%/*}"
tun_route_prefix="$(cidr_network "$tun_cidr")"
${ip} -4 addr replace "$tun_cidr" dev ${lib.escapeShellArg perAppRoutingTun.interface}
@@ -109,6 +109,9 @@ in
${deleteXrayTunReplyTable}
${nft} -f ${xrayTunReplyRules}
# XRay may not have brought the link up yet, and routes via a down link fail with
# "Device for nexthop is not up".
${ip} link set dev ${lib.escapeShellArg globalTun.interface} up
tun_addr="''${tun_cidr%%/*}"
tun_route_prefix="$(cidr_network "$tun_cidr")"
+5
View File
@@ -21,6 +21,11 @@ in
tunInterfaces = lib.unique (
lib.optional (cfg.proxy.enable && cfg.proxy.tun.enable) cfg.proxy.tun.interface
++ lib.optional (cfg.proxy.enable && cfg.perAppRouting.tun.enable) cfg.perAppRouting.tun.interface
# TProxy reroutes local apps' packets out lo to the backend's listener; desync there
# corrupts the handshake the backend reads, like on a TUN.
++ lib.optional (
cfg.proxy.enable && (cfg.proxy.tproxy.enable || cfg.perAppRouting.tproxy.enable)
) "lo"
);
# The transparent backends steer the same packets; a per-app zapret instance replaces them.
+1
View File
@@ -148,6 +148,7 @@ in
assert perAppRoutingTunFixture.config.systemd.user.services ? "proxy-suite-per-app-tun-anchor";
assert perAppRoutingTunServiceConfig.ExecStartPre == perAppRoutingTunServiceConfig.ExecStopPost;
# With proxy.ipv6, wrapped apps' IPv6 goes through the app TUN too.
assert pkgs.lib.hasInfix "link set dev psperapptun0 up" perAppRoutingTunUpScript;
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev psperapptun0'' perAppRoutingTunUpScript;
assert pkgs.lib.hasInfix "-6 route replace default dev psperapptun0 table 101"
perAppRoutingTunUpScript;
+19
View File
@@ -84,6 +84,18 @@ let
tunGlobalBase = mkZapretBase tunFixture;
tunPerAppBase = mkZapretBaseFor tunFixture "proxy-suite-per-app-zapret";
tunWithoutPerAppZapretBase = mkZapretBase (mkTunFixture false);
tproxyBase = mkZapretBase (evalProxySuite [
baseModule
{
services.proxy-suite = {
perAppRouting = {
enable = true;
tproxy.enable = true;
};
zapret.enable = true;
};
}
]);
runtime = pkgs.runCommand "proxy-suite-per-app-zapret-runtime-check" { } ''
global_config=${perAppRoutingZapretBase}/config
@@ -158,6 +170,13 @@ let
! grep '^4 ' ipt-rules
done
# TProxy reroutes local apps' packets out lo; desync must stay off it.
source ${tproxyBase}/init.d/sysv/custom.d/50-proxy-suite-custom.sh
zapret_custom_firewall_nft > rules
grep -Fx 'insert rule inet test_zapret postrouting oifname "lo" return comment "proxy-suite TUN bypass"' rules
zapret_custom_firewall 1 > ipt-rules
grep -Fx '4 1 POSTROUTING -t mangle -o lo -m comment --comment proxy-suite global TUN bypass -j RETURN' ipt-rules
touch "$out"
'';
in
@@ -78,6 +78,7 @@
assert pkgs.lib.hasInfix "xray_tun_dns_runtime" xrayTunStartScript;
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayTunUpScript;
assert pkgs.lib.hasInfix checkConstants.globalTunIPv6Address xrayTunUpScript;
assert pkgs.lib.hasInfix "link set dev singtun0 up" xrayTunUpScript;
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev singtun0'' xrayTunUpScript;
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev singtun0'' xrayTunUpScript;
assert pkgs.lib.hasInfix
@@ -39,6 +39,7 @@
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayPerAppTunUpScript;
assert pkgs.lib.hasInfix checkConstants.perAppTunIPv6Address xrayPerAppTunUpScript;
assert !(pkgs.lib.hasInfix "uplink_addr" xrayPerAppTunUpScript);
assert pkgs.lib.hasInfix "link set dev psperapptun0 up" xrayPerAppTunUpScript;
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
assert pkgs.lib.hasInfix