feat: runtime routing
This commit is contained in:
34 files changed
+1926
-112
No files matched your search
@@ -205,8 +205,13 @@ let
|
||||
};
|
||||
|
||||
selectedTemplates = if derived.pureXrayEnabled then xrayTemplates else singBoxTemplates;
|
||||
# The start script composes the route from these buckets (and the runtime rules); proxy-ctl
|
||||
# reads the sections, the configuration's part of `proxy rules list`.
|
||||
routeModeRules =
|
||||
if derived.pureXrayEnabled then rules.xrayRouteModeRules else rules.singBoxRouteModeRules;
|
||||
(if derived.pureXrayEnabled then rules.xrayRouteModeRules else rules.singBoxRouteModeRules)
|
||||
// {
|
||||
sections = rules.routingSections;
|
||||
};
|
||||
|
||||
tproxyFile = pkgs.writeText "proxy-suite-core" (builtins.toJSON selectedTemplates.tproxy);
|
||||
tunFile = pkgs.writeText "proxy-suite-core" (builtins.toJSON selectedTemplates.tun);
|
||||
|
||||
@@ -1066,6 +1066,11 @@ let
|
||||
runtimeInboundsLock = "${runtimeDir}/proxy-suite-inbounds-runtime.lock";
|
||||
# Per-app profiles added with `proxy-ctl apps add`: <name>.json, next to the declared ones.
|
||||
runtimeAppsDir = "${stateDir}/apps.d";
|
||||
# Routing rules added with `proxy-ctl proxy rules`: rules.json, written by the routing
|
||||
# scope's groups. Root renders it into routingRulesDir (routing-runtime.nix), which the
|
||||
# backends read: rules.json checked, and a rule set per rule that sing-box reloads.
|
||||
runtimeRoutingDir = "${stateDir}/routing.d";
|
||||
routingRulesDir = "${stateDir}/routing";
|
||||
# Shell function for the scripts that read those spools as root. $1 a file: in a spool,
|
||||
# a regular file only, and never through a symlink, which would hand over any file root
|
||||
# can read (a share link or an error message then shows it), nor a FIFO, which would
|
||||
|
||||
@@ -22,7 +22,7 @@ in
|
||||
What the group may do. Empty allows everything.
|
||||
- "services": start, stop and restart services, and `tor newnym`.
|
||||
- "perApp": `proxy-ctl apps run`.
|
||||
- "routing": `proxy pin`, `proxy unpin` and `proxy mode`.
|
||||
- "routing": `proxy pin`, `proxy unpin`, `proxy mode` and `proxy rules`.
|
||||
- "outbounds": add, remove, enable and disable outbounds and subscriptions.
|
||||
- "secrets": read share links, subscription URLs and running configs.
|
||||
- "autoProxy": see and change what autoProxy learned.
|
||||
|
||||
@@ -109,6 +109,61 @@ let
|
||||
routingRules = singBoxRoutingRules;
|
||||
routeModeRules = singBoxRouteModeRules;
|
||||
|
||||
# The configuration's sections in match order, each at a fixed priority that runtime
|
||||
# routing rules (`proxy-ctl proxy rules`) sort among; `proxy rules list` and the Routing tab
|
||||
# show them. Tags as the user wrote them, not as the backend spells them.
|
||||
matchFields = rule: {
|
||||
domains = rule.domains or [ ];
|
||||
ips = rule.ips or [ ];
|
||||
geosites = rule.geosites or [ ];
|
||||
geoips = rule.geoips or [ ];
|
||||
ruleSets = rule.ruleSets or [ ];
|
||||
};
|
||||
routingSections = [
|
||||
{
|
||||
id = "rules";
|
||||
priority = 100;
|
||||
label = "routing.rules";
|
||||
entries =
|
||||
lib.concatMap (
|
||||
ob:
|
||||
let
|
||||
m = matchFields ob.routing;
|
||||
in
|
||||
lib.optional (lib.any (v: v != [ ]) (builtins.attrValues m)) (m // { target = ob.tag; })
|
||||
) proxyCfg.outbounds
|
||||
++ map (rule: matchFields rule // { target = rule.outbound; }) r.rules;
|
||||
}
|
||||
{
|
||||
id = "proxy";
|
||||
priority = 200;
|
||||
label = "routing.proxy: domains and ips";
|
||||
entries = [
|
||||
(matchFields { inherit (r.proxy) domains ips; } // { target = "proxy"; })
|
||||
];
|
||||
}
|
||||
{
|
||||
id = "block";
|
||||
priority = 300;
|
||||
label = "routing.block";
|
||||
entries = [ (matchFields r.block // { target = "block"; }) ];
|
||||
}
|
||||
{
|
||||
id = "direct";
|
||||
priority = 400;
|
||||
label = "routing.direct, private addresses";
|
||||
entries = [ (matchFields (direct // { inherit (r.direct) ruleSets; }) // { target = "direct"; }) ];
|
||||
}
|
||||
{
|
||||
id = "proxyGeo";
|
||||
priority = 500;
|
||||
label = "routing.proxy: geosites, geoips and rule sets";
|
||||
entries = [
|
||||
(matchFields { inherit (r.proxy) geosites geoips ruleSets; } // { target = "proxy"; })
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
in
|
||||
{
|
||||
inherit
|
||||
@@ -124,5 +179,6 @@ in
|
||||
xrayRouteModeRules
|
||||
routeModeRules
|
||||
routingRules
|
||||
routingSections
|
||||
;
|
||||
}
|
||||
@@ -99,6 +99,9 @@ let
|
||||
customRouteRules = map (rule: {
|
||||
category = customRuleCategory rule.outbound;
|
||||
entries = mkCustomRuleEntries rule;
|
||||
# Its share of the DNS mirror below, so a start script that reorders the sections
|
||||
# (runtime routing rules) reorders their lookups with them.
|
||||
dns = customDnsRules rule;
|
||||
}) customRules;
|
||||
|
||||
proxyPrimaryRules = lib.flatten [
|
||||
@@ -172,18 +175,23 @@ let
|
||||
inherit server;
|
||||
};
|
||||
dnsServerFor = category: if category == "direct" then "local" else "remote";
|
||||
singBoxDnsRules =
|
||||
lib.concatMap (
|
||||
rule:
|
||||
lib.optionals (customRuleCategory rule.outbound != "block") (
|
||||
mkDnsRules (dnsServerFor (customRuleCategory rule.outbound)) rule.domains rule.geosites (
|
||||
rule.ruleSets or [ ]
|
||||
)
|
||||
customDnsRules =
|
||||
rule:
|
||||
lib.optionals (customRuleCategory rule.outbound != "block") (
|
||||
mkDnsRules (dnsServerFor (customRuleCategory rule.outbound)) rule.domains rule.geosites (
|
||||
rule.ruleSets or [ ]
|
||||
)
|
||||
) customRules
|
||||
++ mkDnsRules "remote" r.proxy.domains [ ] [ ]
|
||||
++ mkDnsRules "local" direct.domains direct.geosites r.direct.ruleSets
|
||||
++ mkDnsRules "remote" [ ] r.proxy.geosites r.proxy.ruleSets;
|
||||
);
|
||||
dnsSections = {
|
||||
proxyPrimary = mkDnsRules "remote" r.proxy.domains [ ] [ ];
|
||||
direct = mkDnsRules "local" direct.domains direct.geosites r.direct.ruleSets;
|
||||
proxyGeo = mkDnsRules "remote" [ ] r.proxy.geosites r.proxy.ruleSets;
|
||||
};
|
||||
singBoxDnsRules =
|
||||
lib.concatMap (item: item.dns) customRouteRules
|
||||
++ dnsSections.proxyPrimary
|
||||
++ dnsSections.direct
|
||||
++ dnsSections.proxyGeo;
|
||||
|
||||
singBoxRouteModeRules = {
|
||||
common = commonRules;
|
||||
@@ -193,6 +201,8 @@ let
|
||||
safetyDirect = safetyDirectRules;
|
||||
block = blockRules;
|
||||
proxyGeo = proxyGeoRules;
|
||||
# The DNS mirror by section, in singBoxDnsRules' order (custom's is in each rule).
|
||||
dns = dnsSections;
|
||||
};
|
||||
in
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@ let
|
||||
perAppViaRuntime
|
||||
proxySuiteScriptsDir
|
||||
ruleSets
|
||||
routeModeRulesFile
|
||||
pkgs
|
||||
;
|
||||
inherit (ctx.scripts)
|
||||
@@ -93,6 +94,13 @@ in
|
||||
PROXYCHAINS_CONFIG = toString proxychainsConfigFile;
|
||||
PROXYCHAINS_QUIET_ARG = lib.removeSuffix " " proxychainsQuietArg;
|
||||
ROUTE_MODE_STATE_FILE = routeModeStateFile;
|
||||
# The configuration's routing in sections, each at its priority ("sections"), and the
|
||||
# rules `proxy rules` adds: its spool, and what root rendered of it.
|
||||
ROUTING_RULES_FILE = toString routeModeRulesFile;
|
||||
RUNTIME_ROUTING_DIR = constants.runtimeRoutingDir;
|
||||
ROUTING_RULES_DIR = constants.routingRulesDir;
|
||||
GEODATA_GEOSITE_DIR = "${cfg.geodata.singBox.geosite}/share/sing-box/rule-set";
|
||||
GEODATA_GEOIP_DIR = "${cfg.geodata.singBox.geoip}/share/sing-box/rule-set";
|
||||
DEFAULT_ROUTE_MODE = if proxyCfg.routing.default == "proxy" then "blacklist" else "whitelist";
|
||||
AWG_PROFILES_FILE = toString amneziaWgProfileNamesFile;
|
||||
# The WARP devices behind outbounds, each with the unit that carries it.
|
||||
|
||||
@@ -95,6 +95,10 @@ let
|
||||
path = constants.runtimeAppsDir;
|
||||
scope = "perApp";
|
||||
}
|
||||
++ lib.optional proxyEnabled {
|
||||
path = constants.runtimeRoutingDir;
|
||||
scope = "routing";
|
||||
}
|
||||
++ lib.optional derived.zapretCutoffEnabled {
|
||||
path = "${constants.zapret2CutoffDir}/requests";
|
||||
scope = "zapret";
|
||||
@@ -367,6 +371,11 @@ lib.mkMerge [
|
||||
constants.runtimeSubscriptionsDir
|
||||
]
|
||||
))
|
||||
# Routing rules added at runtime (`proxy rules`): the routing scope's. Nothing secret
|
||||
# in them, but root renders what is there into every backend's route.
|
||||
(lib.mkIf (cfg.enable && proxyEnabled) [
|
||||
"d ${constants.runtimeRoutingDir} ${spoolDirMode "routing"} -"
|
||||
])
|
||||
# inbounds.runtime: the users' and listeners' files hold their secrets, so the dir is
|
||||
# as closed as outbounds.d, and group-writable only with the inbounds scope.
|
||||
(lib.mkIf (cfg.enable && derived.proxyInboundsRuntimeEnabled) (
|
||||
|
||||
@@ -22,6 +22,7 @@ let
|
||||
"proxy-suite-outbound-pin@" = "routing";
|
||||
"proxy-suite-outbound-unpin." = "routing";
|
||||
"proxy-suite-route-mode@" = "routing";
|
||||
"proxy-suite-routing-apply." = "routing";
|
||||
"proxy-suite-outbound-reload." = "outbounds";
|
||||
"proxy-suite-subscription-update." = "outbounds";
|
||||
# Tunnels of the AmneziaWG outbounds added at runtime; a global profile's own unit
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# inbounds.routing.blockPrivate (or, without it, this host's loopback), enforced here because
|
||||
# the listener passes names unresolved.
|
||||
# Just before the first direct rule (or last, for a direct final), so names that the
|
||||
# Just before the first direct rule of the configuration (or last, for a direct final), and
|
||||
# scoped to each runtime direct rule above that (insert_guard), so names that the
|
||||
# proxy rules above take stay unresolved and none reaches a direct dial unchecked. Local
|
||||
# mixed-in clients lose names that resolve private. Rules for other inbounds do not count:
|
||||
# autoProxy's direct probe pin would put the guard first, resolving every name, .onion too.
|
||||
@@ -11,11 +12,4 @@
|
||||
{inbound: ["mixed-in"]@rejectMatch@, action: "reject"}]
|
||||
+ (($ARGS.named.host_addresses // []) as $own
|
||||
| if $own == [] or @hostPortsAllOpen@ then [] else [{inbound: ["mixed-in"], ip_cidr: $own@hostPortMatch@, action: "reject"}] end) as $guard
|
||||
| (.route.rules
|
||||
| map((.outbound? // "") == "direct" and ((.inbound? // ["mixed-in"]) | index(["mixed-in"])) != null)
|
||||
| index(true)) as $first_direct
|
||||
| if $first_direct != null then
|
||||
.route.rules = .route.rules[:$first_direct] + $guard + .route.rules[$first_direct:]
|
||||
elif (.route.final // "direct") == "direct" then
|
||||
.route.rules += $guard
|
||||
else . end
|
||||
| insert_guard($guard)
|
||||
@@ -20,7 +20,23 @@ $route_rules[0] as $route_rules | $probe_inbounds[0] as $probe_inbounds
|
||||
| if $clear_dns_rules then
|
||||
.dns.rules = .dns.rules[:@userDnsRuleCount@]
|
||||
+ [.dns.rules[@userDnsRuleCount@:][] | select(.server? == "fakeip" or .domain_suffix? == ["onion"])]
|
||||
else . end
|
||||
else
|
||||
# The DNS mirror composed with the route (routing-compose.jq), runtime rules' lookups
|
||||
# among the configuration's: in place of the configuration's own, which follows the
|
||||
# user's rules and the .onion ones.
|
||||
(($ARGS.named.route_dns // [null])[0]) as $route_dns
|
||||
| if $route_dns == null then . else
|
||||
(.dns.rules // []) as $r
|
||||
| ([$r[@userDnsRuleCount@:][] | .domain_suffix? == ["onion"]] | index(false)
|
||||
// ($r[@userDnsRuleCount@:] | length)) as $onion
|
||||
| (@userDnsRuleCount@ + $onion) as $at
|
||||
| .dns.rules = $r[:$at] + $route_dns + $r[$at + ($ARGS.named.static_dns_count // 0):]
|
||||
end
|
||||
end
|
||||
# The runtime rules' own rule sets, and geodata the configuration does not name.
|
||||
| ([.route.rule_set[]?.tag]) as $have
|
||||
| .route.rule_set = ((.route.rule_set // [])
|
||||
+ [(($ARGS.named.user_rule_sets // [[]])[0])[] | select(.tag as $t | $have | index([$t]) | not)])
|
||||
else . end
|
||||
# autoProxy rules, after the route-mode replace so no mode drops them: pins first
|
||||
# (they only match their own listener), learned rules last before final, so
|
||||
|
||||
@@ -14,7 +14,7 @@ def xray_rewrite_proxy_rule($single_tag):
|
||||
def xray_preserved_rules:
|
||||
[.routing.rules[]
|
||||
| select((.ruleTag? // "") | . == "dns-hijack" or . == "dns-upstream-direct" or . == "dns-upstream-remote"
|
||||
or . == "inbounds-private-guard" or . == "inbounds-host-guard")];
|
||||
or . == "dns-remote-bridge" or . == "inbounds-private-guard" or . == "inbounds-host-guard")];
|
||||
def xray_final_rule($tag; $single_tag):
|
||||
if $tag == "proxy" and "@selectionMode@" == "urltest" then
|
||||
{type:"field",network:"tcp,udp",ruleTag:"final-default"} + xray_proxy_rule_target($single_tag)
|
||||
|
||||
@@ -19,6 +19,38 @@
|
||||
|
||||
let
|
||||
fillTemplate = import ../../lib/fill-template.nix;
|
||||
# A guard for mixed-in's names goes just before the first direct rule that applies to
|
||||
# mixed-in, or last for a direct final. A runtime routing rule (routing-convert.jq: its first
|
||||
# rule set is user:<name>) does not count: one sending a name direct at the top would take the
|
||||
# guard, and its lookup, above every proxy rule. Each such rule above the guard gets the guard
|
||||
# to itself instead, only for what it matches.
|
||||
insertGuardDefs = ''
|
||||
| def runtime_rule: ((.rule_set? // [])[0] // "") | type == "string" and startswith("user:");
|
||||
def direct_for_mixed: (.outbound? // "") == "direct"
|
||||
and ((.inbound? // ["mixed-in"]) | index(["mixed-in"])) != null;
|
||||
# An "and" takes the rule set as one more condition; anything else, "or" included, is
|
||||
# wrapped whole.
|
||||
def scoped($sets):
|
||||
if .type? == "logical" and .mode? == "and" then .rules += [{rule_set: $sets}]
|
||||
else {type: "logical", mode: "and",
|
||||
rules: [del(.action, .strategy, .server), {rule_set: $sets}]}
|
||||
+ ({action, strategy, server} | with_entries(select(.value != null)))
|
||||
end;
|
||||
def first_direct: .route.rules | map(direct_for_mixed and (runtime_rule | not)) | index(true);
|
||||
def insert_guard($guard):
|
||||
(first_direct // (.route.rules | length)) as $limit
|
||||
| .route.rules = [.route.rules | to_entries[] | .key as $i | .value
|
||||
| if $i < $limit and direct_for_mixed and runtime_rule
|
||||
then (. as $rule | $guard[] | scoped($rule.rule_set)), .
|
||||
else . end]
|
||||
| first_direct as $first_direct
|
||||
| if $first_direct != null then
|
||||
.route.rules = .route.rules[:$first_direct] + $guard + .route.rules[$first_direct:]
|
||||
elif (.route.final // "direct") == "direct" then
|
||||
.route.rules += $guard
|
||||
else . end;
|
||||
.
|
||||
'';
|
||||
# XRay's port list: "80,1000-2000".
|
||||
closedPorts = map (
|
||||
r: if r.from == r.to then toString r.from else "${toString r.from}-${toString r.to}"
|
||||
@@ -33,6 +65,7 @@ else
|
||||
(fillTemplate ./backend-filter-sing-box.template.jq {
|
||||
userDnsRuleCount = toString (builtins.length userDnsRules);
|
||||
})
|
||||
+ lib.optionalString (listenerExposed || proxyInboundsGuardPrivate) insertGuardDefs
|
||||
# An outbound on such an interface resolves through it (awg-dns-<tag>), as a declared one
|
||||
# does; only its server cannot be in the build-time config.
|
||||
+ lib.optionalString (awgRuntimeDnsServer != null) ''
|
||||
@@ -58,14 +91,7 @@ else
|
||||
{type: "logical", mode: "and",
|
||||
rules: [{inbound: ["mixed-in"], ip_cidr: ${builtins.toJSON proxyInboundsLoopback}}, $remote],
|
||||
action: "reject"}] as $guard
|
||||
| (.route.rules
|
||||
| map((.outbound? // "") == "direct" and ((.inbound? // ["mixed-in"]) | index(["mixed-in"])) != null)
|
||||
| index(true)) as $first_direct
|
||||
| if $first_direct != null then
|
||||
.route.rules = .route.rules[:$first_direct] + $guard + .route.rules[$first_direct:]
|
||||
elif (.route.final // "direct") == "direct" then
|
||||
.route.rules += $guard
|
||||
else . end
|
||||
| insert_guard($guard)
|
||||
''
|
||||
# No sniffing on mixed-in, where the inbounds' clients arrive: an SNI the rules send direct
|
||||
# would take their connection direct to any address. Their names still route as names.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# The route for a mode, from the configuration's rule buckets (routeModeRulesFile) and the
|
||||
# runtime rules' sections (routing-convert.jq): every section at its priority, a runtime one
|
||||
# ahead of the configuration's at the same number, the common rules first. $mode drops what it
|
||||
# leaves to the final outbound: all-proxy every direct list, all-bypass all but the blocks.
|
||||
# Out: the route rules, the DNS mirror in the same order, and how long the configuration's
|
||||
# own mirror is (the stretch of dns.rules this replaces).
|
||||
def keep: if $mode == "all-proxy" then .cat != "direct"
|
||||
elif $mode == "all-bypass" then .cat == "block" or .cat == "safety"
|
||||
else true end;
|
||||
|
||||
.common as $common
|
||||
| ([.custom[] | {prio: 100, cat: .category, rules: .entries, dns: (.dns // [])}]
|
||||
+ [{prio: 200, cat: "proxy", rules: .proxyPrimary, dns: (.dns.proxyPrimary // [])},
|
||||
{prio: 300, cat: "block", rules: .block, dns: []},
|
||||
{prio: 400, cat: "direct", rules: .direct, dns: (.dns.direct // [])},
|
||||
{prio: 400, cat: "safety", rules: .safetyDirect, dns: []},
|
||||
{prio: 500, cat: "proxy", rules: .proxyGeo, dns: (.dns.proxyGeo // [])}]) as $static
|
||||
# sort_by is stable: runtime sections, already in their order, first among equals.
|
||||
| ($runtime[0] + $static | sort_by(.prio) | map(select(keep))) as $sections
|
||||
| {
|
||||
rules: ($common + ([$sections[].rules[]])),
|
||||
dns: [$sections[].dns[]],
|
||||
staticDnsCount: ([$static[].dns | length] | add // 0)
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
# The rendered runtime routing rules (routing-render.jq) as the backend's: one section each,
|
||||
# at the rule's priority, for routing-compose.jq to sort among the configuration's.
|
||||
# A rule the backend would refuse (an outbound that is gone, a rule set this configuration does
|
||||
# not declare) is left out and said why, so it never fails the whole start.
|
||||
#
|
||||
# $backend: sing-box or xray. $tags (slurped): every outbound tag the config will have.
|
||||
# $rule_sets: the declared routing.ruleSets. $missing_geo (slurped): geosite-X/geoip-X with no
|
||||
# .srs. $dir: where the
|
||||
# rendered rule sets are. $geosite_dir/$geoip_dir: sing-box's geodata. $urltest: pure XRay's
|
||||
# urltest, which prefixes every outbound and balances "proxy".
|
||||
def builtin: . == "proxy" or . == "direct" or . == "block";
|
||||
def category: if . == "direct" then "direct" elif . == "block" then "block" else "proxy" end;
|
||||
def backend_tag: if $backend == "xray" and $urltest and (builtin | not) then "proxy-suite-ob-" + . else . end;
|
||||
def xray_target: if . == "proxy" and $urltest then {balancerTag: "proxy"} else {outboundTag: backend_tag} end;
|
||||
def local_set($tag; $path; $format): {type: "local", format: $format, tag: $tag, path: $path};
|
||||
def why:
|
||||
if (.target | builtin | not) and ((.target | backend_tag) as $t | $tags[0] | index([$t]) | not) then
|
||||
"no outbound or group named \(.target)"
|
||||
elif $backend == "xray" and .ruleSets != [] then
|
||||
"rule sets need the sing-box or hybrid backend"
|
||||
elif (.ruleSets - $rule_sets) != [] then
|
||||
"no rule set named \((.ruleSets - $rule_sets) | join(", ")) in routing.ruleSets"
|
||||
elif ([.geosites[] | "geosite-" + .] + [.geoips[] | "geoip-" + .] | any(. as $g | $missing_geo[0] | index([$g]))) then
|
||||
"no such geosite or geoip: \([.geosites[] | "geosite-" + .] + [.geoips[] | "geoip-" + .] | map(select(. as $g | $missing_geo[0] | index([$g]))) | join(", "))"
|
||||
else null end;
|
||||
|
||||
[.[] | select(.disabled | not)] as $rules
|
||||
| [$rules[] | why as $why | select($why != null) | {name, why: $why}] as $skipped
|
||||
| [$rules[] | select(why == null)] as $ok
|
||||
| {
|
||||
skipped: $skipped,
|
||||
sections: [$ok[] | . as $r | {
|
||||
prio: .priority,
|
||||
cat: (.target | category),
|
||||
name: .name,
|
||||
rules: (
|
||||
if $backend == "xray" then
|
||||
# XRay takes a ruleTag once.
|
||||
({type: "field"} + (.target | xray_target)) as $base
|
||||
| ([.domains[] | "domain:" + .] + [.geosites[] | "geosite:" + .]) as $domain
|
||||
| (.ips + [.geoips[] | "geoip:" + .]) as $ip
|
||||
| (if $domain != [] then [$base + {ruleTag: ("user:" + $r.name), domain: $domain}] else [] end)
|
||||
+ (if $ip != [] then [$base + {ruleTag: ("user:" + $r.name + ":ip"), ip: $ip}] else [] end)
|
||||
else
|
||||
# Always, its own rule set first even while empty: matches added later reach sing-box
|
||||
# by the file alone, no restart. The guards find a runtime rule by that first tag.
|
||||
[{rule_set: (["user:" + .name] + [.geosites[] | "geosite-" + .] + [.geoips[] | "geoip-" + .]
|
||||
+ [.ruleSets[] | "ruleset-" + .]),
|
||||
outbound: .target}]
|
||||
end),
|
||||
# As the configuration's lookups follow its routing (rules/sing-box.nix): names only.
|
||||
dns: (
|
||||
if $backend == "xray" or .target == "block" then []
|
||||
else [{rule_set: (["user-dns:" + .name] + [.geosites[] | "geosite-" + .]
|
||||
+ [.ruleSets[] | "ruleset-" + . + "-dns"]),
|
||||
server: (if .target == "direct" then "local" else "remote" end)}]
|
||||
end)
|
||||
}],
|
||||
rule_sets: (
|
||||
if $backend == "xray" then []
|
||||
else
|
||||
[$ok[] | local_set("user:" + .name; $dir + "/rs/" + .name + ".json"; "source"),
|
||||
local_set("user-dns:" + .name; $dir + "/dns/" + .name + ".json"; "source")]
|
||||
+ ([$ok[].geosites[]] | unique | map(local_set("geosite-" + .; $geosite_dir + "/geosite-" + . + ".srs"; "binary")))
|
||||
+ ([$ok[].geoips[]] | unique | map(local_set("geoip-" + .; $geoip_dir + "/geoip-" + . + ".srs"; "binary")))
|
||||
end)
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
# routing.d/rules.json, as userControl's group wrote it (slurped: one document, else none), to
|
||||
# the rules root applies: each field checked, anything else dropped, a name once. Sorted in
|
||||
# match order (priority, then name).
|
||||
def strs: if type == "array" then [.[] | strings] else [] end;
|
||||
def domain: ascii_downcase | ltrimstr(".") | select(test("^[a-z0-9_-]+(\\.[a-z0-9_-]+)*$") and length <= 253);
|
||||
# Addresses as Go's netip parses them, which both backends do: one the backend refuses would
|
||||
# fail its whole start. No leading zeros, no zone.
|
||||
def v4: test("^(0|[1-9][0-9]{0,2})(\\.(0|[1-9][0-9]{0,2})){3}$") and all(split(".")[]; tonumber <= 255);
|
||||
def v6_groups:
|
||||
split("::") as $parts
|
||||
| ($parts | length) as $n
|
||||
| [$parts[] | select(. != "") | split(":")[]] as $groups
|
||||
| $n <= 2 and ($groups | all(test("^[0-9a-f]{1,4}$")))
|
||||
and (if $n == 2 then ($groups | length) <= 7 else ($groups | length) == 8 end);
|
||||
# An IPv4 tail (::ffff:192.0.2.1) counts as two groups.
|
||||
def v6:
|
||||
test("^[0-9a-f:.]+$") and test(":")
|
||||
and (if test("\\.") then
|
||||
[match("^(.*:)([0-9.]+)$").captures[].string] as $m
|
||||
| ($m | length) == 2 and ($m[1] | v4) and ($m[0] + "0:0" | v6_groups)
|
||||
else v6_groups end);
|
||||
def prefix($max): test("^(0|[1-9][0-9]{0,2})$") and tonumber <= $max;
|
||||
# A bare address is its own /32 or /128.
|
||||
def cidr:
|
||||
ascii_downcase | split("/") as $s
|
||||
| ($s | length) as $n
|
||||
| if $n > 2 then empty
|
||||
elif ($s[0] | v4) then (if $n == 1 then $s[0] + "/32" elif ($s[1] | prefix(32)) then . else empty end)
|
||||
elif ($s[0] | v6) then (if $n == 1 then $s[0] + "/128" elif ($s[1] | prefix(128)) then . else empty end)
|
||||
else empty end;
|
||||
# geosite-NAME.srs, geosite:NAME: "geolocation-!cn" and "google@cn" among them, never a path.
|
||||
def geo: select(test("^[A-Za-z0-9!@._-]{1,64}$") and (startswith(".") | not));
|
||||
def tag: select(test("^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$"));
|
||||
|
||||
(if length == 1 then .[0] else null end)
|
||||
| [(.rules? // []) | if type == "array" then .[] else empty end
|
||||
| objects
|
||||
| select((.name | type) == "string" and (.name | test("^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$")))
|
||||
| select((.target | type) == "string" and (.target | length) >= 1 and (.target | length) <= 128 and (.target | test("[[:cntrl:]]") | not))
|
||||
| {
|
||||
name,
|
||||
target,
|
||||
priority: (if (.priority | type) == "number" then (.priority | floor | if . < -1000000 then -1000000 elif . > 1000000 then 1000000 else . end) else 50 end),
|
||||
disabled: (.disabled == true),
|
||||
domains: ([.domains | strs[] | domain] | unique),
|
||||
ips: ([.ips | strs[] | cidr] | unique),
|
||||
geosites: ([.geosites | strs[] | geo] | unique),
|
||||
geoips: ([.geoips | strs[] | geo] | unique),
|
||||
ruleSets: ([.ruleSets | strs[] | tag] | unique)
|
||||
}]
|
||||
| reduce .[] as $r ([]; if any(.[]; .name == $r.name) then . else . + [$r] end)
|
||||
| sort_by(.priority, .name)
|
||||
@@ -0,0 +1,184 @@
|
||||
# Routing rules added at runtime (`proxy-ctl proxy rules`): rendered from the routing scope's
|
||||
# spool, then composed into each backend's route by the start scripts.
|
||||
#
|
||||
# routing.d/rules.json is the groups'; root renders it into routingRulesDir: rules.json
|
||||
# checked (routing-render.jq), per rule rs/<name>.json (its domains and addresses) and
|
||||
# dns/<name>.json (its domains alone) as sing-box source rule sets, and `structure`, what of
|
||||
# them changes the config itself. A change to a rule's domains or addresses alone reaches a
|
||||
# running sing-box through its rule set files, which it reloads; anything else, and any change
|
||||
# on XRay, which has no rule sets, restarts the backends.
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
jq
|
||||
constants
|
||||
pureXrayEnabled
|
||||
;
|
||||
inherit (constants) runtimeRoutingDir routingRulesDir;
|
||||
coreutils = "${pkgs.coreutils}/bin";
|
||||
|
||||
renderJq = ./routing-render.jq;
|
||||
convertJq = ./routing-convert.jq;
|
||||
composeJq = ./routing-compose.jq;
|
||||
|
||||
# Where sing-box finds geodata the configuration does not name; also how a geosite or geoip
|
||||
# gets checked before XRay is handed one (the two come from the same lists).
|
||||
geositeDir = "${cfg.geodata.singBox.geosite}/share/sing-box/rule-set";
|
||||
geoipDir = "${cfg.geodata.singBox.geoip}/share/sing-box/rule-set";
|
||||
|
||||
# Root, over a spool the groups write: read through no symlink, 4 MiB at most, and checked
|
||||
# field by field. Under a lock: every backend's start script renders too. --sweep also
|
||||
# removes the rule sets of rules that are gone, which apply does once the backends that
|
||||
# watched them have restarted. The spool and output directories as arguments: for the checks.
|
||||
render = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
SWEEP=false
|
||||
if [ "''${1:-}" = --sweep ]; then
|
||||
SWEEP=true
|
||||
shift
|
||||
fi
|
||||
SPOOL=''${1:-${lib.escapeShellArg runtimeRoutingDir}}
|
||||
OUT=''${2:-${lib.escapeShellArg routingRulesDir}}
|
||||
umask 022
|
||||
${coreutils}/mkdir -p "$OUT/rs" "$OUT/dns"
|
||||
${coreutils}/chmod 0755 "$OUT" "$OUT/rs" "$OUT/dns"
|
||||
exec 9> "$OUT/.lock"
|
||||
${pkgs.util-linux}/bin/flock 9
|
||||
|
||||
SRC='{}'
|
||||
if [ -f "$SPOOL/rules.json" ] && [ ! -L "$SPOOL/rules.json" ]; then
|
||||
SRC=$(${coreutils}/dd if="$SPOOL/rules.json" iflag=nofollow,nonblock,fullblock bs=4M count=1 status=none 2>/dev/null) || SRC='{}'
|
||||
fi
|
||||
# Slurped: an empty file, or several documents, is no rules rather than no output.
|
||||
if ! RULES=$(${jq} -c -s -f ${renderJq} <<< "$SRC" 2>/dev/null); then
|
||||
echo "proxy-suite: $SPOOL/rules.json is not valid JSON; no runtime routing rules apply" >&2
|
||||
RULES='[]'
|
||||
fi
|
||||
|
||||
# Renamed in, and only when it changed: sing-box reloads a rule set on every new file.
|
||||
_put() {
|
||||
cat > "$1.tmp"
|
||||
${coreutils}/chmod 644 "$1.tmp"
|
||||
if ${pkgs.diffutils}/bin/cmp -s "$1.tmp" "$1"; then
|
||||
rm -f "$1.tmp"
|
||||
else
|
||||
mv -f "$1.tmp" "$1"
|
||||
fi
|
||||
}
|
||||
printf '%s\n' "$RULES" | _put "$OUT/rules.json"
|
||||
KEEP=" "
|
||||
while IFS=$'\t' read -r NAME SET DNS; do
|
||||
printf '%s\n' "$SET" | _put "$OUT/rs/$NAME.json"
|
||||
printf '%s\n' "$DNS" | _put "$OUT/dns/$NAME.json"
|
||||
KEEP="$KEEP$NAME.json "
|
||||
done < <(${jq} -r '.[]
|
||||
| [.name,
|
||||
({version: 1, rules: ([if .domains != [] then {domain_suffix: .domains} else empty end]
|
||||
+ [if .ips != [] then {ip_cidr: .ips} else empty end])} | tojson),
|
||||
({version: 1, rules: [if .domains != [] then {domain_suffix: .domains} else empty end]} | tojson)]
|
||||
| @tsv' <<< "$RULES")
|
||||
if [ "$SWEEP" = true ]; then
|
||||
for F in "$OUT"/rs/*.json "$OUT"/dns/*.json; do
|
||||
[ -e "$F" ] || continue
|
||||
case "$KEEP" in
|
||||
*" ''${F##*/} "*) ;;
|
||||
*) rm -f "$F" ;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
${jq} -c '${
|
||||
if pureXrayEnabled then
|
||||
"map(select(.disabled | not))"
|
||||
else
|
||||
"map(select(.disabled | not) | del(.domains, .ips))"
|
||||
}' <<< "$RULES" | _put "$OUT/structure"
|
||||
'';
|
||||
|
||||
# The backends whose config holds the rules, with their runtime directories.
|
||||
consumers = [
|
||||
{
|
||||
unit = "proxy-suite-socks";
|
||||
dir = "${constants.runtimeDir}/proxy-suite-socks";
|
||||
}
|
||||
{
|
||||
unit = "proxy-suite-tun";
|
||||
dir = "${constants.runtimeDir}/proxy-suite-tun";
|
||||
}
|
||||
{
|
||||
unit = "proxy-suite-per-app-tun";
|
||||
dir = "${constants.runtimeDir}/proxy-suite-per-app-tun";
|
||||
}
|
||||
];
|
||||
|
||||
# proxy-suite-routing-apply, after every `proxy rules` change: a backend restarts only when
|
||||
# its config would change, the structure it started from (startBlock) no longer the one now.
|
||||
apply = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
${render}
|
||||
${lib.concatMapStrings (c: ''
|
||||
if ${constants.systemctl} is-active --quiet ${c.unit} \
|
||||
&& ! ${pkgs.diffutils}/bin/cmp -s ${lib.escapeShellArg "${routingRulesDir}/structure"} ${lib.escapeShellArg "${c.dir}/routing-structure"}; then
|
||||
${constants.systemctl} restart ${c.unit}
|
||||
fi
|
||||
'') consumers}
|
||||
${render} --sweep
|
||||
'';
|
||||
|
||||
# In a start script, after the outbounds: sets RUNTIME_SECTIONS_JSON (routing-compose.jq's
|
||||
# $runtime) and USER_RULE_SETS_JSON, and writes $RUNTIME_DIR/routing-structure and
|
||||
# routing-skipped.json, the rules left out and why (for proxy-ctl, which anyone may read).
|
||||
startBlock = configFile: ''
|
||||
RUNTIME_SECTIONS_JSON='[]'
|
||||
USER_RULE_SETS_JSON='[]'
|
||||
RUNTIME_ROUTING_SKIPPED='[]'
|
||||
${render}
|
||||
cp ${lib.escapeShellArg "${routingRulesDir}/structure"} "$RUNTIME_DIR/routing-structure"
|
||||
chmod 644 "$RUNTIME_DIR/routing-structure"
|
||||
RUNTIME_ROUTING_JSON=$(cat ${lib.escapeShellArg "${routingRulesDir}/rules.json"})
|
||||
if ${jq} -e 'any(.[]; .disabled | not)' <<< "$RUNTIME_ROUTING_JSON" >/dev/null; then
|
||||
MISSING_GEO_JSON=$(${jq} -r '[.[] | select(.disabled | not)
|
||||
| (.geosites[] | "geosite-" + .), (.geoips[] | "geoip-" + .)] | unique[]' <<< "$RUNTIME_ROUTING_JSON" \
|
||||
| while IFS= read -r GEO; do
|
||||
case "$GEO" in
|
||||
geosite-*) [ -e ${lib.escapeShellArg geositeDir}/"$GEO.srs" ] || printf '%s\n' "$GEO" ;;
|
||||
*) [ -e ${lib.escapeShellArg geoipDir}/"$GEO.srs" ] || printf '%s\n' "$GEO" ;;
|
||||
esac
|
||||
done | ${jq} -R . | ${jq} -cs .)
|
||||
# Slurped: a large subscription's tags outgrow one argument.
|
||||
ROUTING_TAGS_JSON=$(${jq} -c --slurpfile obs <(printf '%s' "$OUTBOUNDS_JSON") \
|
||||
--slurpfile groups <(printf '%s' "''${GROUP_TAGS_JSON:-[]}") \
|
||||
'[($obs[0][]?, .outbounds[]?) | .tag? | strings] + $groups[0] | unique' ${configFile})
|
||||
CONVERTED=$(${jq} -c \
|
||||
--arg backend ${if pureXrayEnabled then "xray" else "sing-box"} \
|
||||
--slurpfile tags <(printf '%s' "$ROUTING_TAGS_JSON") \
|
||||
--argjson rule_sets ${lib.escapeShellArg (builtins.toJSON (map (rs: rs.name) ctx.ruleSets))} \
|
||||
--slurpfile missing_geo <(printf '%s' "$MISSING_GEO_JSON") \
|
||||
--arg dir ${lib.escapeShellArg routingRulesDir} \
|
||||
--arg geosite_dir ${lib.escapeShellArg geositeDir} \
|
||||
--arg geoip_dir ${lib.escapeShellArg geoipDir} \
|
||||
--argjson urltest ${lib.boolToString (pureXrayEnabled && ctx.selectionMode == "urltest")} \
|
||||
-f ${convertJq} <<< "$RUNTIME_ROUTING_JSON")
|
||||
RUNTIME_SECTIONS_JSON=$(${jq} -c '.sections' <<< "$CONVERTED")
|
||||
USER_RULE_SETS_JSON=$(${jq} -c '.rule_sets' <<< "$CONVERTED")
|
||||
RUNTIME_ROUTING_SKIPPED=$(${jq} -c '.skipped' <<< "$CONVERTED")
|
||||
${jq} -r '.[] | "proxy-suite: routing rule \(.name) left out: \(.why)"' <<< "$RUNTIME_ROUTING_SKIPPED" >&2
|
||||
fi
|
||||
printf '%s\n' "$RUNTIME_ROUTING_SKIPPED" > "$RUNTIME_DIR/routing-skipped.json.tmp"
|
||||
chmod 644 "$RUNTIME_DIR/routing-skipped.json.tmp"
|
||||
mv -f "$RUNTIME_DIR/routing-skipped.json.tmp" "$RUNTIME_DIR/routing-skipped.json"
|
||||
'';
|
||||
in
|
||||
{
|
||||
inherit
|
||||
render
|
||||
apply
|
||||
startBlock
|
||||
composeJq
|
||||
geositeDir
|
||||
geoipDir
|
||||
;
|
||||
}
|
||||
@@ -187,6 +187,8 @@ let
|
||||
backendJqFilterFile = pkgs.writeText "proxy-suite-core" backendJqFilter;
|
||||
|
||||
startScripts = import ./start-scripts.nix { ctx = sctx; };
|
||||
routingRuntime = import ./script-blocks/routing-runtime.nix { ctx = sctx; };
|
||||
applyRoutingScript = routingRuntime.apply;
|
||||
inherit (startScripts) startSocks startTun startPerAppTun;
|
||||
|
||||
proxyInboundsScripts = import ./proxy-inbounds-scripts.nix { ctx = sctx; };
|
||||
@@ -240,6 +242,7 @@ in
|
||||
proxyInboundsSubscriptionsFile
|
||||
routeModeStateFile
|
||||
setRouteModeScript
|
||||
applyRoutingScript
|
||||
pinOutboundScript
|
||||
reloadOutboundsScript
|
||||
subscriptionUpdateScript
|
||||
|
||||
@@ -49,6 +49,7 @@ let
|
||||
inherit (constants) serviceUser ifPrivileged;
|
||||
};
|
||||
autoProxyMigrate = import ../autoproxy-migrate.nix { inherit pkgs; };
|
||||
routingRuntime = import ./script-blocks/routing-runtime.nix { inherit ctx; };
|
||||
# Who reads the probe listeners' login (`proxy outbounds test`, `proxy auto probe`).
|
||||
# Local proxy auth with userControl off keeps its group as before.
|
||||
probeLoginMainGroup =
|
||||
@@ -62,35 +63,18 @@ let
|
||||
userControlGroup = lib.escapeShellArg userControlCfg.group;
|
||||
chgrp = "${pkgs.coreutils}/bin/chgrp";
|
||||
|
||||
# Every route mode is the same four assignments over one jq program on the rule buckets.
|
||||
# What a route mode decides beyond which rule buckets it keeps (routing-compose.jq): the
|
||||
# final outbound, and the DNS server for names no rule takes.
|
||||
routeModeArms = [
|
||||
{
|
||||
mode = "blacklist";
|
||||
final = "proxy";
|
||||
dns = "remote";
|
||||
rules = ''
|
||||
.common
|
||||
+ (.custom | map(.entries) | add // [])
|
||||
+ .proxyPrimary
|
||||
+ .block
|
||||
+ .direct
|
||||
+ .safetyDirect
|
||||
+ .proxyGeo
|
||||
'';
|
||||
}
|
||||
{
|
||||
mode = "whitelist";
|
||||
final = "direct";
|
||||
dns = "local";
|
||||
rules = ''
|
||||
.common
|
||||
+ (.custom | map(.entries) | add // [])
|
||||
+ .proxyPrimary
|
||||
+ .block
|
||||
+ .direct
|
||||
+ .safetyDirect
|
||||
+ .proxyGeo
|
||||
'';
|
||||
}
|
||||
{
|
||||
# Only the proxy and block lists are kept: everything else follows the final action.
|
||||
@@ -98,31 +82,18 @@ let
|
||||
final = "proxy";
|
||||
dns = "remote";
|
||||
clearDns = true;
|
||||
rules = ''
|
||||
.common
|
||||
+ (.custom | map(select(.category == "proxy" or .category == "block") | .entries) | add // [])
|
||||
+ .proxyPrimary
|
||||
+ .block
|
||||
+ .safetyDirect
|
||||
+ .proxyGeo
|
||||
'';
|
||||
}
|
||||
{
|
||||
mode = "all-bypass";
|
||||
final = "direct";
|
||||
dns = "local";
|
||||
clearDns = true;
|
||||
rules = ''
|
||||
.common
|
||||
+ (.custom | map(select(.category == "block") | .entries) | add // [])
|
||||
+ .block
|
||||
+ .safetyDirect
|
||||
'';
|
||||
}
|
||||
];
|
||||
# The configured routing.default as a mode: runtime rules compose the route without an
|
||||
# override, and the result is the configuration's own order with theirs among it.
|
||||
defaultRouteMode = if proxyCfg.routing.default == "proxy" then "blacklist" else "whitelist";
|
||||
|
||||
# Written out line by line: the block lands inside a `case`, where the indentation of an
|
||||
# interpolated multi-line value would otherwise be lost.
|
||||
mkRouteModeArm =
|
||||
arm:
|
||||
lib.concatStringsSep "\n" (
|
||||
@@ -133,14 +104,7 @@ let
|
||||
" ROUTE_MODE_ACTIVE=true"
|
||||
]
|
||||
++ lib.optional (arm.clearDns or false) " CLEAR_DNS_RULES=true"
|
||||
++ [ " ROUTE_RULES_JSON=$(${jq} -c '" ]
|
||||
++ map (line: if line == "" then "" else " ${line}") (
|
||||
lib.splitString "\n" (lib.removeSuffix "\n" arm.rules)
|
||||
)
|
||||
++ [
|
||||
" ' \"${routeModeRulesFile}\")"
|
||||
" ;;"
|
||||
]
|
||||
++ [ " ;;" ]
|
||||
);
|
||||
|
||||
routeModeCaseBlock = ''
|
||||
@@ -154,6 +118,27 @@ let
|
||||
esac
|
||||
'';
|
||||
|
||||
# The route, once a mode or a runtime rule calls for one: the buckets and runtime sections
|
||||
# in priority order, and the DNS mirror composed alike.
|
||||
composeRouteBlock = ''
|
||||
if [ "$ROUTE_MODE_ACTIVE" != true ] && [ "$RUNTIME_SECTIONS_JSON" != '[]' ]; then
|
||||
case ${defaultRouteMode} in${
|
||||
lib.concatMapStrings (arm: "\n" + mkRouteModeArm arm) (
|
||||
lib.filter (arm: arm.mode == defaultRouteMode) routeModeArms
|
||||
)
|
||||
}
|
||||
esac
|
||||
fi
|
||||
if [ "$ROUTE_MODE_ACTIVE" = true ]; then
|
||||
COMPOSED_ROUTE_JSON=$(${jq} -c --arg mode "''${ROUTE_MODE:-${defaultRouteMode}}" \
|
||||
--slurpfile runtime <(printf '%s' "$RUNTIME_SECTIONS_JSON") \
|
||||
-f ${routingRuntime.composeJq} "${routeModeRulesFile}")
|
||||
ROUTE_RULES_JSON=$(${jq} -c '.rules' <<< "$COMPOSED_ROUTE_JSON")
|
||||
ROUTE_DNS_JSON=$(${jq} -c '.dns' <<< "$COMPOSED_ROUTE_JSON")
|
||||
STATIC_DNS_COUNT=$(${jq} '.staticDnsCount' <<< "$COMPOSED_ROUTE_JSON")
|
||||
fi
|
||||
'';
|
||||
|
||||
writeProxychainsConfigBlock = ''
|
||||
# proxychains reads its config by words: a password with whitespace in it would come out
|
||||
# as another field, or another line. None then, and proxy-ctl says why.
|
||||
@@ -219,6 +204,8 @@ let
|
||||
ROUTE_FINAL=""
|
||||
DNS_FINAL=""
|
||||
ROUTE_RULES_JSON='[]'
|
||||
ROUTE_DNS_JSON=null
|
||||
STATIC_DNS_COUNT=0
|
||||
ROUTE_MODE_ACTIVE=false
|
||||
CLEAR_DNS_RULES=false
|
||||
${hybridRuntimeHelpersBlock routingMark xraySidecarPort xrayDnsBridgePort}
|
||||
@@ -245,6 +232,10 @@ let
|
||||
${mkOutboundScript routingMark}
|
||||
${lib.optionalString hybridEnabled "_proxy_suite_write_xray_sidecar_config"}
|
||||
|
||||
# Routing rules added at runtime, which name outbounds: after them.
|
||||
${routingRuntime.startBlock configFile}
|
||||
${composeRouteBlock}
|
||||
|
||||
# autoProxy: a loopback listener and a learned rule-set per exit, generated here
|
||||
# because subscription tags only exist at runtime.
|
||||
PROBE_INBOUNDS_JSON='[]'
|
||||
@@ -459,6 +450,9 @@ let
|
||||
} \
|
||||
--argjson route_enabled "$ROUTE_MODE_ACTIVE" \
|
||||
--slurpfile route_rules <(printf '%s' "$ROUTE_RULES_JSON") \
|
||||
--slurpfile route_dns <(printf '%s' "$ROUTE_DNS_JSON") \
|
||||
--argjson static_dns_count "$STATIC_DNS_COUNT" \
|
||||
--slurpfile user_rule_sets <(printf '%s' "$USER_RULE_SETS_JSON") \
|
||||
--arg route_final "$ROUTE_FINAL" \
|
||||
--arg dns_final "$DNS_FINAL" \
|
||||
--argjson clear_dns_rules "$CLEAR_DNS_RULES" \
|
||||
|
||||
@@ -782,6 +782,21 @@ let
|
||||
};
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = proxyEnabled;
|
||||
name = "proxy-suite-routing-apply";
|
||||
value = mkOneshotService {
|
||||
description = "Apply proxy-suite routing rules added at runtime";
|
||||
execStart = scripts.applyRoutingScript;
|
||||
# Root, over the spool the routing scope writes: it renders the rules into the state
|
||||
# directory and restarts the backends whose config they change.
|
||||
stateDirectory = "proxy-suite";
|
||||
extraServiceConfig = {
|
||||
RemainAfterExit = false;
|
||||
}
|
||||
// spoolReaderSandbox [ ];
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = proxyEnabled;
|
||||
name = "proxy-suite-outbound-pin@";
|
||||
|
||||
Reference in new issue
Block a user