feat: tproxy lan gateway, killswitch; fix: zapret2 fixes, various other

This commit is contained in:
FUFSoB committed 2026-09-23 01:12:31 +05:00
1 parent 4bcc168b2a
commit ae8f65da2e
54 files changed
+1880 -143

No files matched your search

+1
View File
@@ -21,6 +21,7 @@
./gui.nix
./tui.nix
./user-control.nix
./kill-switch.nix
./host.nix
];
+2
View File
@@ -68,6 +68,8 @@ in
allowedTCPPorts = internalOption (types.listOf types.port) [ ];
allowedUDPPorts = internalOption (types.listOf types.port) [ ];
extraReversePathFilterRules = internalOption types.lines "";
# nftables firewall only: iptables has no such hook.
extraInputRules = internalOption types.lines "";
trustedInterfaces = internalOption (types.listOf types.str) [ ];
};
# Kernel parameters the services also set when they start.
@@ -0,0 +1,11 @@
{ lib, ... }:
{
options.services.proxy-suite.killSwitch.enable = lib.mkEnableOption ''
a kill switch for the global tunnels (proxy.tun, proxy.tproxy and global AmneziaWG profiles):
once one starts, outgoing traffic that would leave outside it is rejected, also while it
restarts, after it crashes or after its handshake gives up. LAN destinations, DHCP and NTP
stay open; tproxy.lanInterfaces clients keep the LAN but lose the internet. Only
`proxy-ctl killswitch off`, `proxy off`, `proxy tun off`, `proxy tproxy off` or `awg off`
lift it (proxy-suite-killswitch)
'';
}
@@ -28,6 +28,7 @@ in
ips = list "IP CIDRs sent through the proxy." [ "1.1.1.0/24" ];
geosites = list "Geosite names sent through the proxy." [ "netflix" ];
geoips = list "Geoip names sent through the proxy." [ "us" ];
ruleSets = list "Names from ruleSets sent through the proxy." [ "antifilter" ];
};
direct = {
@@ -39,6 +40,7 @@ in
ips = list "IP CIDRs sent direct." [ "10.10.0.0/16" ];
geosites = list "Geosite names sent direct." [ "category-ru" ];
geoips = list "Geoip names sent direct." [ "ru" ];
ruleSets = list "Names from ruleSets sent direct." [ "ru-services" ];
};
block = {
@@ -46,6 +48,7 @@ in
ips = list "IP CIDRs blocked." [ "203.0.113.0/24" ];
geosites = list "Geosite names blocked." [ "category-ads-all" ];
geoips = list "Geoip names blocked." [ "cn" ];
ruleSets = list "Names from ruleSets blocked." [ "ads" ];
};
rules = mkOption {
@@ -63,5 +66,54 @@ in
}
];
};
ruleSets = mkOption {
type = types.attrsOf (
types.submodule {
options = {
url = mkOption {
type = types.strMatching "https?://.+";
description = "Where the sing-box rule set is downloaded from.";
example = "https://example.com/antifilter.srs";
};
format = mkOption {
type = types.nullOr (
types.enum [
"binary"
"source"
]
);
default = null;
description = ''"binary" (.srs) or "source" (JSON). Null goes by the URL: .srs is binary.'';
};
detour = mkOption {
type = types.enum [
"proxy"
"direct"
];
default = "proxy";
description = "Downloaded through the local proxy, or directly.";
};
};
}
);
default = { };
description = ''
sing-box rule sets kept up to date at runtime, for the ruleSets of proxy, direct, block,
rules and an outbound's routing. They are fetched every ruleSetUpdateInterval and on
`proxy-ctl proxy rulesets update`, and sing-box picks up a new file without a restart;
until the first fetch one matches nothing. Not for backend = "xray".
'';
example = {
antifilter.url = "https://example.com/antifilter.srs";
};
};
ruleSetUpdateInterval = mkOption {
type = types.str;
default = "1d";
description = "How often ruleSets are downloaded again (systemd time span).";
example = "6h";
};
};
}
@@ -41,5 +41,16 @@ in
"fd00::/8"
];
};
lanInterfaces = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
Interfaces whose forwarded TCP and UDP is taken through the proxy too: devices on them
that use this host as their gateway. Turns on IP forwarding for the rest (ping, the LAN
itself), which is routed as it is. Needs the nftables firewall on NixOS.
'';
example = [ "br0" ];
};
};
}
+12 -2
View File
@@ -10,6 +10,12 @@ let
geosites = list "Geosite names to match (see geodata)." [ "netflix" ];
geoips = list "Geoip names to match (see geodata; the defaults are country codes only)." [ "us" ];
};
# The client's routing also matches downloaded rule sets, which XRay cannot read.
clientRoutingFields = routingFields // {
ruleSets = list "Names from proxy.routing.ruleSets to match (sing-box and hybrid backends)." [
"antifilter"
];
};
routingRuleType = types.submodule {
options = {
@@ -19,7 +25,7 @@ let
example = "vps-de";
};
}
// routingFields;
// clientRoutingFields;
};
dnsUpstreamType = types.submodule {
@@ -78,10 +84,14 @@ in
dnsUpstreamType
perAppRoutingProfileType
routingFields
clientRoutingFields
routingRuleType
;
}
// import ./types/outbounds.nix { inherit lib routingFields; }
// import ./types/outbounds.nix {
inherit lib;
routingFields = clientRoutingFields;
}
// import ./types/zapret.nix { inherit lib; }
// import ./types/inbounds.nix { inherit lib; }
// import ./types/amnezia-wg.nix { inherit lib; }
@@ -254,6 +254,7 @@ let
"vless"
"vmess"
"trojan"
"hysteria2"
"shadowsocks"
"socks"
"http"
@@ -264,7 +265,8 @@ let
description = ''
Protocol. Set exactly one of type, xrayJson, or jsonFile. "amneziawg" is an AmneziaWG
server on UDP port, with its own interface (see amneziaWg); its traffic is handed to XRay
and leaves like any other listener's.
and leaves like any other listener's. "hysteria2" is QUIC on UDP port: it needs tls (a
certificate) and takes passwords, and no transport, reality or flow.
'';
example = "vless";
};
@@ -345,6 +347,11 @@ let
jsonFile = nullStr "Runtime path to a raw XRay inbound (no share link); tag is overridden and port, if left out, filled in." "/run/secrets/proxy-inbound-vless.json";
hysteria.masquerade = nullStr ''
Site that a hysteria2 listener serves, reverse-proxied, to anything that is not a client
(a browser, a prober). Null answers them with 404.
'' "https://www.example.com";
amneziaWg = mkOption {
type = mkAmneziaWgType name;
default = { };
+2 -1
View File
@@ -125,7 +125,8 @@ in
Some lines let TLS to certain hosting networks handshake and then cut it at 12-34 KB,
which no strategy fixes. z2k's probe checks this line against ~110 known targets when
its network changes and once a day, and for each cut-off network searches a whitelisted
name that nfqws2 then puts into a fake ClientHello: thousands of short TLS connections to
name that nfqws2 then puts into a fake ClientHello (strategySource "z2k" only; ahead of
the nfqws2-keenetic strategies it breaks them): thousands of short TLS connections to
foreign hosting IPs per full run, sent directly and never touched by zapret2. State and
maps live in /var/lib/proxy-suite/zapret2/cutoff; `proxy-ctl zapret cutoff` shows them.
'';