feat: z2k 16kb probe

This commit is contained in:
fufsob committed 2026-09-13 20:15:20 +00:00
1 parent 441be87b61
commit 09e9945351
18 files changed
+436 -5

No files matched your search

+12
View File
@@ -260,6 +260,18 @@
run list | grep -q 'No hostnames learned'
test ! -s "$state/circular/state.tsv"
# The cutoff verdict names each cut-off network's way through.
mkdir -p "$state/cutoff"
printf '1789000000\n' > "$state/cutoff/ts"
printf 'AS12389\n' > "$state/cutoff/egress"
printf '24940\n14061\n' > "$state/cutoff/asn.txt"
printf '24940\t300.ya.ru\n' > "$state/cutoff/sni.txt"
cutoff=$(env ZAPRET_CUTOFF_ENABLED=1 ZAPRET_STATE_DIR="$state" bash "$proxy_ctl" zapret cutoff)
printf '%s\n' "$cutoff" | grep -q 'from AS12389$'
printf '%s\n' "$cutoff" | grep -qx 'Cutoff: 2 network(s)'
printf '%s\n' "$cutoff" | grep -qE '^ AS24940 +300\.ya\.ru$'
printf '%s\n' "$cutoff" | grep -qE '^ AS14061 +no name - proxy fallback$'
# Without the zapret2 engine there is nothing to inspect.
! env ZAPRET_AUTO_ENABLED=0 ZAPRET_STATE_DIR="$state" bash "$proxy_ctl" zapret auto list
+38
View File
@@ -18,6 +18,7 @@ let
zapret2Tuned
zapret2NoAuto
zapret2Z2k
zapret2NoFallback
;
envValue =
@@ -42,6 +43,8 @@ let
tunedRuntime = runtimeDir zapret2Tuned globalService;
noAutoRuntime = runtimeDir zapret2NoAuto globalService;
z2kRuntime = runtimeDir zapret2Z2k globalService;
cutoffProbe = zapret2Global.config.systemd.services.proxy-suite-zapret2-cutoff.serviceConfig.ExecStart;
socksStart = fixture: fixture.config.systemd.services.proxy-suite-socks.serviceConfig.ExecStart;
proxyCtlEnv = fixture: (mkProxyCtlDerived fixture).wrapperEnv;
in
@@ -76,6 +79,16 @@ in
true
)
# The cutoff probe comes with zapret2, on a timer, and nfqws2 reads its maps.
(
assert zapret2Global.config.systemd.timers ? proxy-suite-zapret2-cutoff;
assert !(zapretDiscordYoutubeGlobal.config.systemd.services ? proxy-suite-zapret2-cutoff);
assert (proxyCtlEnv zapret2Global).ZAPRET_CUTOFF_ENABLED == "1";
assert
envValue zapret2Global globalService "Z2K_TCP16_ASN=" == "/var/lib/proxy-suite/zapret2/cutoff/asn.txt";
true
)
# `proxy-ctl zapret auto` only makes sense when something is learning.
(
assert (proxyCtlEnv zapret2Global).ZAPRET_AUTO_ENABLED == "1";
@@ -140,6 +153,31 @@ in
test "$(grep -oF -- '<HOSTLIST>' "${z2kRuntime}/config" | wc -l)" = 1
grep -qF -- '/lists/whitelist.txt --hostlist-exclude=/var/lib/proxy-suite/zapret2/zapret-hosts-user-exclude.txt' "${z2kRuntime}/config"
# --- 16 KB cutoff ---------------------------------------------------
# The whitelisted-name step runs ahead of rotation, in both sources.
grep -qF -- '/files/lua/z2k-tcp16.lua' "${globalRuntime}/config"
grep -qF -- 'blob=z2k_ch:optional:repeats=8:tcp_ts=-1000 --lua-desync=circular:fails=2:time=300' "${globalRuntime}/config"
grep -qF -- 'blob=z2k_ch:optional:repeats=8:tcp_ts=-1000 --lua-desync=circular:fails=3:time=60:key=rkn_tcp' "${z2kRuntime}/config"
# zapret2 leaves the probe's own connections alone, in every chain.
test "$(grep -c 'ct mark and 0x2000000 != 0 return' "${globalRuntime}/init.d/sysv/custom.d/50-proxy-suite-custom.sh")" = 4
# Cut-off networks without a name become the proxy's rule-set; named ones stay with zapret2.
rules=$(grep -o '/nix/store/[^ ]*-proxy-suite-zapret2-cutoff-rules' ${cutoffProbe} | head -n1)
printf '# networks\n24940\n14061\n' >asn.txt
printf '24940\t300.ya.ru\n' >sni.txt
printf '# map\n24940\t5.9.0.0/16\n14061\t104.131.0.0/16\n14061\t2604:a880::/32\n7777\t1.2.0.0/16\n' >nets.txt
test "$("$rules" asn.txt sni.txt nets.txt)" = '{"version":1,"rules":[{"ip_cidr":["104.131.0.0/16","2604:a880::/32"]}]}'
printf '24940\t300.ya.ru\n14061\tad.adriver.ru\n' >sni.txt
test "$("$rules" asn.txt sni.txt nets.txt)" = '{"version":1,"rules":[]}'
# The probe is built from z2k's source and knows its tcp16 mode.
detect=$(grep -o '/nix/store/[^:]*-z2k-detect-[^:/]*/bin' ${cutoffProbe} | head -n1)
"$detect/z2k-detect" tcp16 -h 2>/dev/null
# The proxy carries what no name fixes, unless the fallback is off.
grep -qF 'tag: "zapret-cutoff"' ${socksStart zapret2Global}
if grep -qF 'zapret-cutoff' ${socksStart zapret2NoFallback}; then exit 1; fi
# --- per-app instance -------------------------------------------------
# Wrapped apps opted in explicitly, so no hostlist gates them.
grep -qx 'MODE_FILTER=none' "${perAppRuntime}/config"
+5
View File
@@ -63,4 +63,9 @@ in
enable = true;
zapret2.strategySource = "z2k";
};
zapret2NoFallback = mkZapret2 {
enable = true;
zapret2.cutoff.proxyFallback = false;
};
}