fix tun/tproxy not working because of zdy broad ips list
This commit is contained in:
4 files changed
+185
-47
No files matched your search
@@ -66,8 +66,12 @@ services.proxy-suite = {
|
||||
|
||||
zapret = {
|
||||
enable = true;
|
||||
# Default: mirror zapret-covered domains/IPs into sing-box direct routing.
|
||||
# Default: mirror zapret domain lists into sing-box direct routing.
|
||||
syncDirectRouting = true;
|
||||
# Upstream zapret IP ranges are much broader, so keep them opt-in.
|
||||
syncDirectRoutingUpstreamIps = false;
|
||||
# User-defined ipsetAll/ipsetExclude still map into sing-box by default.
|
||||
syncDirectRoutingUserIps = true;
|
||||
};
|
||||
};
|
||||
```
|
||||
@@ -170,7 +174,7 @@ By default all proxied traffic goes to whatever the active outbound is (the sele
|
||||
Global direct routing also has two built-in behaviors:
|
||||
|
||||
- `singBox.routing.enableRuDirect = true` sends `geosite-category-ru` and `geoip-ru` direct by default.
|
||||
- If `zapret.enable = true`, then `zapret.syncDirectRouting = true` mirrors zapret's effective domain/IP lists into sing-box direct rules, including upstream `list-general`, `list-google`, `list-instagram`, `list-soundcloud`, `list-twitter`, plus your `listGeneral`/`ipsetAll`, minus zapret excludes.
|
||||
- If `zapret.enable = true`, then `zapret.syncDirectRouting = true` mirrors zapret's upstream domain hostlists into sing-box direct rules. `zapret.syncDirectRoutingUpstreamIps = false` by default, so upstream zapret IP ranges are not mirrored unless you opt in, while `zapret.syncDirectRoutingUserIps = true` keeps user `ipsetAll`/`ipsetExclude` mirrored by default.
|
||||
|
||||
**Attached to an outbound:**
|
||||
|
||||
@@ -251,20 +255,26 @@ proxy-ctl select <tag> switch to a specific outbound (selector mode)
|
||||
|
||||
## Zapret
|
||||
|
||||
zapret handles DPI-based blocking by mangling packets at the netfilter level. It's separate from the proxy, but by default this module also mirrors zapret-covered domains and IPs into sing-box direct routing so the proxy does not fight zapret for the same traffic.
|
||||
zapret handles DPI-based blocking by mangling packets at the netfilter level. It's separate from the proxy, but by default this module also mirrors zapret-covered domains into sing-box direct routing so the proxy does not fight zapret for the same traffic.
|
||||
|
||||
```nix
|
||||
zapret = {
|
||||
enable = true;
|
||||
configName = "general(ALT)";
|
||||
syncDirectRouting = true; # default
|
||||
syncDirectRouting = true; # default: sync upstream domain lists
|
||||
syncDirectRoutingUpstreamIps = false; # default: do not sync upstream IP ranges
|
||||
syncDirectRoutingUserIps = true; # default: do sync user ipsetAll/ipsetExclude
|
||||
|
||||
# Extra domains beyond zapret's built-in list
|
||||
listGeneral = [ "pixiv.net" "pximg.net" ];
|
||||
};
|
||||
```
|
||||
|
||||
When `syncDirectRouting = true`, the module reuses zapret's upstream `hostlists/list-general.txt`, `hostlists/list-google.txt`, `hostlists/list-instagram.txt`, `hostlists/list-soundcloud.txt`, `hostlists/list-twitter.txt`, and `hostlists/ipset-all.txt`, adds your `listGeneral` and `ipsetAll` entries, and subtracts both upstream and user exclusion lists before generating sing-box direct rules.
|
||||
When `syncDirectRouting = true`, the module reuses zapret's upstream `hostlists/list-general.txt`, `list-google.txt`, `list-instagram.txt`, `list-soundcloud.txt`, and `list-twitter.txt`, adds your `listGeneral`, and subtracts both upstream and user domain exclusions before generating sing-box direct rules.
|
||||
|
||||
When `syncDirectRoutingUpstreamIps = true`, the module also mirrors zapret's upstream `ipset-all.txt`. This is disabled by default because the upstream IP set is intentionally broad.
|
||||
|
||||
When `syncDirectRoutingUserIps = true`, the module mirrors your `ipsetAll` and `ipsetExclude` values into sing-box direct routing even if upstream IP sync stays disabled. This is enabled by default.
|
||||
|
||||
If zapret corrupts traffic for some subnet (e.g. a VM behind a libvirt bridge):
|
||||
|
||||
@@ -359,6 +369,7 @@ services.proxy-suite = {
|
||||
```
|
||||
|
||||
Features:
|
||||
|
||||
- **Status icon**: `network-vpn` (active), `network-vpn-acquiring` (partial), `network-vpn-disconnected` (stopped)
|
||||
- **Toggle TProxy/TUN**: Only shown if the service is enabled in your config
|
||||
- **Restart services**: Restarts `proxy-suite-socks`, and `proxy-suite-tun` if it is active
|
||||
|
||||
@@ -338,7 +338,19 @@ in
|
||||
syncDirectRouting = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "When zapret is enabled, mirror its effective domain and IP lists into sing-box direct routing.";
|
||||
description = "When zapret is enabled, mirror its upstream domain hostlists into sing-box direct routing.";
|
||||
};
|
||||
|
||||
syncDirectRoutingUpstreamIps = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "When zapret is enabled, mirror its upstream ipset ranges into sing-box direct routing.";
|
||||
};
|
||||
|
||||
syncDirectRoutingUserIps = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "When zapret is enabled, mirror user-defined ipsetAll/ipsetExclude entries into sing-box direct routing.";
|
||||
};
|
||||
|
||||
configName = mkOption {
|
||||
@@ -382,8 +394,11 @@ in
|
||||
|
||||
cidrs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
example = [ "192.168.123.0/24" "10.0.0.0/8" ];
|
||||
default = [ ];
|
||||
example = [
|
||||
"192.168.123.0/24"
|
||||
"10.0.0.0/8"
|
||||
];
|
||||
description = ''
|
||||
Subnets to exempt from zapret's NFQUEUE mangle rules.
|
||||
Useful when a VM (libvirt, etc.) is behind NAT and zapret
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
# Routing rules and rule-set definitions for sing-box
|
||||
{ lib, pkgs, cfg, zapret }:
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
cfg,
|
||||
zapret,
|
||||
}:
|
||||
|
||||
let
|
||||
r = cfg.singBox.routing;
|
||||
@@ -10,8 +15,7 @@ let
|
||||
hasPrefix = lib.strings.hasPrefix;
|
||||
splitString = lib.strings.splitString;
|
||||
|
||||
zapretSrc =
|
||||
if builtins.isAttrs zapret && zapret ? outPath then zapret.outPath else zapret;
|
||||
zapretSrc = if builtins.isAttrs zapret && zapret ? outPath then zapret.outPath else zapret;
|
||||
|
||||
parseListFile =
|
||||
path:
|
||||
@@ -23,7 +27,10 @@ let
|
||||
|
||||
subtractItems = items: exclusions: builtins.filter (item: !(builtins.elem item exclusions)) items;
|
||||
|
||||
syncZapretDirect = z.enable && z.syncDirectRouting;
|
||||
syncZapretDirectDomains = z.enable && z.syncDirectRouting;
|
||||
syncZapretDirectUpstreamIps = z.enable && z.syncDirectRoutingUpstreamIps;
|
||||
syncZapretDirectUserIps = z.enable && z.syncDirectRoutingUserIps;
|
||||
syncZapretDirectAnyIps = syncZapretDirectUpstreamIps || syncZapretDirectUserIps;
|
||||
|
||||
zapretDefaultDomainFiles = [
|
||||
"list-general.txt"
|
||||
@@ -34,25 +41,37 @@ let
|
||||
];
|
||||
|
||||
zapretDefaultDomains =
|
||||
if syncZapretDirect then
|
||||
lib.unique (lib.concatMap (file: parseListFile "${zapretSrc}/hostlists/${file}") zapretDefaultDomainFiles)
|
||||
if syncZapretDirectDomains then
|
||||
lib.unique (
|
||||
lib.concatMap (file: parseListFile "${zapretSrc}/hostlists/${file}") zapretDefaultDomainFiles
|
||||
)
|
||||
else
|
||||
[ ];
|
||||
zapretDefaultIps =
|
||||
if syncZapretDirect then parseListFile "${zapretSrc}/hostlists/ipset-all.txt" else [ ];
|
||||
if syncZapretDirectUpstreamIps then parseListFile "${zapretSrc}/hostlists/ipset-all.txt" else [ ];
|
||||
zapretUserIps = if syncZapretDirectUserIps then z.ipsetAll else [ ];
|
||||
zapretExcludedDomains =
|
||||
if syncZapretDirect then parseListFile "${zapretSrc}/hostlists/list-exclude.txt" else [ ];
|
||||
zapretExcludedIps =
|
||||
if syncZapretDirect then parseListFile "${zapretSrc}/hostlists/ipset-exclude.txt" else [ ];
|
||||
if syncZapretDirectDomains then parseListFile "${zapretSrc}/hostlists/list-exclude.txt" else [ ];
|
||||
zapretExcludedIps = lib.unique (
|
||||
(
|
||||
if syncZapretDirectUpstreamIps then
|
||||
parseListFile "${zapretSrc}/hostlists/ipset-exclude.txt"
|
||||
else
|
||||
[ ]
|
||||
)
|
||||
++ (if syncZapretDirectUserIps then z.ipsetExclude else [ ])
|
||||
);
|
||||
|
||||
zapretDirectDomains =
|
||||
if syncZapretDirect then
|
||||
subtractItems (lib.unique (zapretDefaultDomains ++ z.listGeneral)) (lib.unique (zapretExcludedDomains ++ z.listExclude))
|
||||
if syncZapretDirectDomains then
|
||||
subtractItems (lib.unique (zapretDefaultDomains ++ z.listGeneral)) (
|
||||
lib.unique (zapretExcludedDomains ++ z.listExclude)
|
||||
)
|
||||
else
|
||||
[ ];
|
||||
zapretDirectIps =
|
||||
if syncZapretDirect then
|
||||
subtractItems (lib.unique (zapretDefaultIps ++ z.ipsetAll)) (lib.unique (zapretExcludedIps ++ z.ipsetExclude))
|
||||
if syncZapretDirectAnyIps then
|
||||
subtractItems (lib.unique (zapretDefaultIps ++ zapretUserIps)) zapretExcludedIps
|
||||
else
|
||||
[ ];
|
||||
|
||||
@@ -87,29 +106,40 @@ let
|
||||
# In "first" mode the start script renames the first outbound to "proxy",
|
||||
# so any per-outbound routing tag that isn't direct/block/proxy must map
|
||||
# to "proxy" instead of the original tag (which won't exist in sing-box).
|
||||
builtinTags = [ "proxy" "direct" "block" ];
|
||||
builtinTags = [
|
||||
"proxy"
|
||||
"direct"
|
||||
"block"
|
||||
];
|
||||
resolveTag =
|
||||
tag:
|
||||
if sb.selection == "first" && !builtins.elem tag builtinTags then "proxy" else tag;
|
||||
tag: if sb.selection == "first" && !builtins.elem tag builtinTags then "proxy" else tag;
|
||||
|
||||
# Collect per-outbound routing attached directly to outbound definitions.
|
||||
perOutboundRules = lib.concatMap (ob:
|
||||
perOutboundRules = lib.concatMap (
|
||||
ob:
|
||||
let
|
||||
ro = ob.routing;
|
||||
hasAny = ro.domains != [ ] || ro.ips != [ ] || ro.geosites != [ ] || ro.geoips != [ ];
|
||||
in
|
||||
lib.optional hasAny {
|
||||
outbound = resolveTag ob.tag;
|
||||
inherit (ro) domains ips geosites geoips;
|
||||
inherit (ro)
|
||||
domains
|
||||
ips
|
||||
geosites
|
||||
geoips
|
||||
;
|
||||
}
|
||||
) sb.outbounds;
|
||||
|
||||
# All custom rules in priority order: per-outbound first, then explicit routing.rules.
|
||||
customRules = perOutboundRules ++ map (rule: rule // { outbound = resolveTag rule.outbound; }) r.rules;
|
||||
customRules =
|
||||
perOutboundRules ++ map (rule: rule // { outbound = resolveTag rule.outbound; }) r.rules;
|
||||
|
||||
# Build sing-box routing rule entries from a custom rule record.
|
||||
mkCustomRuleEntries =
|
||||
rule: lib.flatten [
|
||||
rule:
|
||||
lib.flatten [
|
||||
(mkDomainRule rule.outbound rule.domains)
|
||||
(mkIPRule rule.outbound rule.ips)
|
||||
(mkRulesetRule rule.outbound (map (s: "geosite-${s}") rule.geosites))
|
||||
@@ -126,10 +156,7 @@ let
|
||||
|
||||
# All geoip names referenced anywhere.
|
||||
allGeoIPNames = lib.unique (
|
||||
r.proxy.geoips
|
||||
++ direct.geoips
|
||||
++ r.block.geoips
|
||||
++ lib.concatMap (rule: rule.geoips) customRules
|
||||
r.proxy.geoips ++ direct.geoips ++ r.block.geoips ++ lib.concatMap (rule: rule.geoips) customRules
|
||||
);
|
||||
|
||||
geositeRuleSets = map (name: {
|
||||
@@ -148,7 +175,10 @@ let
|
||||
|
||||
routingRules = lib.flatten [
|
||||
{
|
||||
network = [ "tcp" "udp" ];
|
||||
network = [
|
||||
"tcp"
|
||||
"udp"
|
||||
];
|
||||
port = 53;
|
||||
action = "hijack-dns";
|
||||
}
|
||||
@@ -167,7 +197,10 @@ let
|
||||
(mkRulesetRule "direct" (map (s: "geosite-${s}") direct.geosites))
|
||||
(mkRulesetRule "direct" (map (s: "geoip-${s}") direct.geoips))
|
||||
|
||||
{ ip_is_private = true; outbound = "direct"; }
|
||||
{
|
||||
ip_is_private = true;
|
||||
outbound = "direct";
|
||||
}
|
||||
|
||||
# Block (before proxy geosets so block can override them)
|
||||
(mkDomainRule "block" r.block.domains)
|
||||
|
||||
+91
-12
@@ -223,6 +223,29 @@ let
|
||||
];
|
||||
zapretSyncRules = mkRoutingRules zapretSyncFixture;
|
||||
|
||||
zapretSyncIpsFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
syncDirectRoutingUpstreamIps = true;
|
||||
};
|
||||
}
|
||||
];
|
||||
zapretSyncIpsRules = mkRoutingRules zapretSyncIpsFixture;
|
||||
|
||||
zapretSyncUserIpsDisabledFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
syncDirectRoutingUserIps = false;
|
||||
ipsetAll = [ "203.0.113.0/24" ];
|
||||
};
|
||||
}
|
||||
];
|
||||
zapretSyncUserIpsDisabledRules = mkRoutingRules zapretSyncUserIpsDisabledFixture;
|
||||
|
||||
zapretSyncDisabledFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
@@ -234,30 +257,63 @@ let
|
||||
];
|
||||
zapretSyncDisabledRules = mkRoutingRules zapretSyncDisabledFixture;
|
||||
|
||||
zapretSyncDomainsOnlyFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
syncDirectRouting = true;
|
||||
syncDirectRoutingUpstreamIps = false;
|
||||
};
|
||||
}
|
||||
];
|
||||
zapretSyncDomainsOnlyRules = mkRoutingRules zapretSyncDomainsOnlyFixture;
|
||||
|
||||
zapretExtrasFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
listGeneral = [ "pixiv.net" ];
|
||||
ipsetAll = [ "203.0.113.0/24" ];
|
||||
};
|
||||
}
|
||||
];
|
||||
zapretExtrasRules = mkRoutingRules zapretExtrasFixture;
|
||||
|
||||
zapretIpExtrasFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
ipsetAll = [ "203.0.113.0/24" ];
|
||||
};
|
||||
}
|
||||
];
|
||||
zapretIpExtrasRules = mkRoutingRules zapretIpExtrasFixture;
|
||||
|
||||
zapretExcludesFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
listExclude = [ "discord.com" ];
|
||||
ipsetExclude = [ "1.1.1.0/24" ];
|
||||
};
|
||||
}
|
||||
];
|
||||
zapretExcludesRules = mkRoutingRules zapretExcludesFixture;
|
||||
|
||||
zapretIpExcludesFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
ipsetExclude = [ "1.1.1.0/24" ];
|
||||
ipsetAll = [ "1.1.1.0/24" ];
|
||||
};
|
||||
}
|
||||
];
|
||||
zapretIpExcludesRules = mkRoutingRules zapretIpExcludesFixture;
|
||||
|
||||
proxyDirectFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
@@ -388,7 +444,27 @@ let
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasDirectIP zapretSyncRules "1.1.1.0/24";
|
||||
assert hasDirectDomain zapretSyncRules "cloudflare-ech.com";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(hasDirectIP zapretSyncRules "1.1.1.0/24");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasDirectDomain zapretSyncDomainsOnlyRules "cloudflare-ech.com";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(hasDirectIP zapretSyncDomainsOnlyRules "1.1.1.0/24");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasDirectIP zapretSyncIpsRules "1.1.1.0/24";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(hasDirectIP zapretSyncUserIpsDisabledRules "203.0.113.0/24");
|
||||
true
|
||||
)
|
||||
(
|
||||
@@ -404,7 +480,7 @@ let
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasDirectIP zapretExtrasRules "203.0.113.0/24";
|
||||
assert hasDirectIP zapretIpExtrasRules "203.0.113.0/24";
|
||||
true
|
||||
)
|
||||
(
|
||||
@@ -412,7 +488,7 @@ let
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(hasDirectIP zapretExcludesRules "1.1.1.0/24");
|
||||
assert !(hasDirectIP zapretIpExcludesRules "1.1.1.0/24");
|
||||
true
|
||||
)
|
||||
(
|
||||
@@ -432,19 +508,21 @@ let
|
||||
true
|
||||
)
|
||||
(
|
||||
assert packagePathMatches trayAutostartFixture.config.environment.systemPackages ".*/[^/]*proxy-suite-tray(-[0-9.]+)?$";
|
||||
assert packagePathMatches trayAutostartFixture.config.environment.systemPackages
|
||||
".*/[^/]*proxy-suite-tray(-[0-9.]+)?$";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert packagePathMatches trayAutostartFixture.config.environment.systemPackages ".*/[^/]*proxy-suite-tray\\.desktop$";
|
||||
assert packagePathMatches trayAutostartFixture.config.environment.systemPackages
|
||||
".*/[^/]*proxy-suite-tray\\.desktop$";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert
|
||||
builtins.match
|
||||
".*/share/xdg/autostart/proxy-suite-tray\\.desktop$"
|
||||
(builtins.unsafeDiscardStringContext trayAutostartFixture.config.environment.etc."xdg/autostart/proxy-suite-tray.desktop".source)
|
||||
!= null;
|
||||
builtins.match ".*/share/xdg/autostart/proxy-suite-tray\\.desktop$" (
|
||||
builtins.unsafeDiscardStringContext
|
||||
trayAutostartFixture.config.environment.etc."xdg/autostart/proxy-suite-tray.desktop".source
|
||||
) != null;
|
||||
true
|
||||
)
|
||||
(
|
||||
@@ -452,7 +530,8 @@ let
|
||||
true
|
||||
)
|
||||
(
|
||||
assert packagePathMatches trayManualFixture.config.environment.systemPackages ".*/[^/]*proxy-suite-tray\\.desktop$";
|
||||
assert packagePathMatches trayManualFixture.config.environment.systemPackages
|
||||
".*/[^/]*proxy-suite-tray\\.desktop$";
|
||||
true
|
||||
)
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user