windows: zapret2's 16 KB cutoff probe

Upstream's cutoff.nix and cutoff-probe.template.sh: z2k-detect (built from
z2k's pinned source for Windows, in zapret2-extras) finds the networks this
line cuts after ~16 KB, and with z2k's own strategies a whitelisted name per
network; z2k-tcp16.lua inside winws2 reads the maps (Z2K_TCP16_*, their
digest in the environment so a new map restarts winws2); what no name fixes
goes to the zapret-cutoff rule-set for the proxy (cutoff.proxyFallback).

Upstream keeps zapret2 off the probe with an nft cgroup rule. Here
z2k-detect is patched to dial from a local port range
(Z2K_TCP16_LOCAL_PORTS, 44000-47999, below Windows' dynamic range) and
winws2 gets --wf-raw-filter leaving that range alone; under the TUN the
probe and the service's own lookups of the line's network go direct.

Rounds as upstream's timer: 5 min after start, every 10 min, probing when
the line's network (ipinfo.io and ifconfig.co agreeing) changed or a day
passed. Request::ZapretCutoff, proxy-ctl zapret cutoff [probe], a card on
the DPI page. Verified live on a line that cuts (25 networks, a name for
each), the Windows z2k-detect under Wine, winws2 --dry-run and --wf-save
with the filter. gui-shot's scroll takes a count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 23:12:43 +03:00
1 parent d33f05c62c
commit 803e18db9d
19 files changed
+721 -18

No files matched your search

+67 -2
View File
@@ -12,7 +12,8 @@
# learner's arguments), @STALLWATCH@; and the paths, @Z2K@ (z2k's files) and @ROOT@ (the
# tree its generator wrote), which winws2 reads where the component is installed.
#
# tools/build-zapret2-extras.sh OUT_DIR (needs git, bash, gawk, python3, nix)
# tools/build-zapret2-extras.sh OUT_DIR (needs git, bash, gawk, python3, nix, go;
# Z2K_DETECT_GOOS=linux: z2k-detect for here)
set -euo pipefail
. "$(dirname "$0")/lib.sh"
OUT=$(realpath -m "${1:?output directory}")
@@ -46,6 +47,70 @@ if old not in s:
open(p, "w").write(s.replace(old, new))
PY
# --- the 16 KB cutoff probe: z2k-detect, as upstream's pkgs/z2k-detect.nix builds it --------
# Its connections leave from the local ports the service names (Z2K_TCP16_LOCAL_PORTS), which
# winws2's filter leaves out, as upstream's nft rule keeps zapret2 off the probe's cgroup.
t=$Z/z2k-detect/internal/tcp16/tcp16.go
grep -qF 'raw, err := d.DialContext(ctx, "tcp", addr)' "$t" || { echo "z2k-detect's tcp16 dial changed"; exit 1; }
sed -i 's|raw, err := d.DialContext(ctx, "tcp", addr)|raw, err := dialFrom(ctx, \&d, addr)|' "$t"
cat >"$Z/z2k-detect/internal/tcp16/localport.go" <<'GO'
package tcp16
// Proxy Suite for Windows: the probe's connections from a range of local ports
// (Z2K_TCP16_LOCAL_PORTS, "lo-hi") that the DPI bypass leaves alone. A port taken
// (or in TIME_WAIT) is passed over for the next.
import (
"context"
"errors"
"net"
"os"
"strconv"
"strings"
"sync/atomic"
)
var portLo, portHi = func() (int, int) {
lo, hi, ok := strings.Cut(os.Getenv("Z2K_TCP16_LOCAL_PORTS"), "-")
a, e1 := strconv.Atoi(lo)
b, e2 := strconv.Atoi(hi)
if !ok || e1 != nil || e2 != nil || a < 1 || b > 65535 || a > b {
return 0, 0
}
return a, b
}()
var nextPort atomic.Uint32
func dialFrom(ctx context.Context, d *net.Dialer, addr string) (net.Conn, error) {
if portLo == 0 {
return d.DialContext(ctx, "tcp", addr)
}
n := uint32(portHi - portLo + 1)
var err error
for i := 0; i < 64; i++ {
dd := *d
dd.LocalAddr = &net.TCPAddr{Port: portLo + int(nextPort.Add(1)%n)}
c, e := dd.DialContext(ctx, "tcp", addr)
if e == nil {
return c, nil
}
err = e
var se *os.SyscallError
if !errors.As(e, &se) || se.Syscall != "bind" {
return nil, e
}
}
return nil, err
}
GO
(
cd "$Z/z2k-detect"
export GOTOOLCHAIN=local GOFLAGS=-mod=mod CGO_ENABLED=0 GOOS=${Z2K_DETECT_GOOS:-windows} GOARCH=amd64
ext=; [ "$GOOS" = windows ] && ext=.exe
go build -trimpath -ldflags "-s -w" -o "$OUT/z2k-detect$ext" ./cmd/z2k-detect
)
# --- proxy-suite's own Lua --------------------------------------------------------------
cp "$UPSTREAM/detect.lua" "$UPSTREAM/persist-every.lua" "$UPSTREAM/strategy-log.lua" "$OUT/lua/"
# The suffix list's path from the environment: it is where the component is installed.
@@ -191,5 +256,5 @@ for name in NFQWS2_PORTS_TCP NFQWS2_PORTS_UDP; do
done >"$OUT/z2k/ports"
grep -q '^NFQWS2_PORTS_TCP=.\+' "$OUT/z2k/ports" || { echo "z2k's ports not found"; exit 1; }
echo "$Z2K_COMMIT" >"$OUT/z2k/.commit"
echo "2026.10.27+z2k.${Z2K_COMMIT:0:7}" >"$OUT/.version"
echo "2026.10.28+z2k.${Z2K_COMMIT:0:7}" >"$OUT/.version"
echo "zapret2-extras $(cat "$OUT/.version") in $OUT"
+2 -2
View File
@@ -6,7 +6,7 @@
#
# Before the shot, SHOT_STEPS does what it lists, in order, each followed by a moment for the
# app to answer: "click:X,Y" (screen points), "type:TEXT" (no spaces), "key:NAME" (xdotool's
# names, e.g. ctrl+a), "scroll:X,Y" (ten steps down, there), "wait:SECONDS".
# names, e.g. ctrl+a), "scroll:X,Y[,N]" (N steps down, there; ten), "wait:SECONDS".
set -euo pipefail
OUT=$(realpath -m "${1:?the screenshot, a .png}"); shift
WAIT=6
@@ -36,7 +36,7 @@ x() { DISPLAY=":$n" "$XDOTOOL/bin/xdotool" "$@"; }
for step in ${SHOT_STEPS:-}; do
case $step in
click:*) p=${step#click:}; x mousemove "${p%,*}" "${p#*,}" click 1 ;;
scroll:*) p=${step#scroll:}; x mousemove "${p%,*}" "${p#*,}" click --repeat 10 5 ;;
scroll:*) IFS=, read -r sx sy sn <<<"${step#scroll:}"; x mousemove "$sx" "$sy" click --repeat "${sn:-10}" 5 ;;
type:*) x type --delay 40 "${step#type:}" ;;
key:*) x key "${step#key:}" ;;
wait:*) sleep "${step#wait:}" ;;