feat: per-app awg and custom via

This commit is contained in:
FUFSoB committed 2026-10-04 15:39:56 +05:00
1 parent af5b3ff27a
commit 65082aad88
43 files changed
+2674 -197

No files matched your search

@@ -2,7 +2,10 @@ def sing_box_preserved_rules:
[.route.rules[]
| select(((.action? // "") == "hijack-dns")
and (((.inbound? // []) | index("xray-dns-in")) != null))];
.outbounds = ($obs[0] + .outbounds)
# perAppRouting.via's pin rules, which no route mode replaces.
def is_pin: ((.outbound? // "") | type) == "string" and ((.outbound? // "") | startswith("proxy-suite-pin-"));
([.route.rules[]? | select(is_pin)]) as $pin_rules
| .outbounds = ($obs[0] + .outbounds)
| if $auth_enabled then
(.inbounds[] | select(.type == "mixed" and .tag == "mixed-in") | .users) = [{username:$user,password:$password}]
else . end
@@ -27,3 +30,13 @@ def sing_box_preserved_rules:
else . end
| .route.rule_set = ((.route.rule_set // []) + $autoproxy_rule_sets)
| .route.rules = ($probe_pin_rules + .route.rules + $autoproxy_rules)
# Pins after the common hijack-dns and sniff rules, so a pinned app's lookups are answered
# as any other's, and before every rule that picks an outbound.
| .route.rules |= [.[] | select(is_pin | not)]
| (.route.rules | map((.action? // "") == "sniff") | index(true)) as $sniff
| .route.rules = (if $sniff == null then $pin_rules + .route.rules
else .route.rules[:$sniff + 1] + $pin_rules + .route.rules[$sniff + 1:] end)
# Each pin's selector takes any outbound, block first: a slot nobody switched blocks.
| ([.outbounds[].tag | select(startswith("proxy-suite-pin-") | not)]) as $tags
| .outbounds |= map(if .type == "selector" and (.tag | startswith("proxy-suite-pin-"))
then .outbounds = (["block"] + ($tags - ["block"])) | .default = "block" else . end)
@@ -5,6 +5,9 @@
proxyInboundsGuardPrivate,
proxyInboundsGuardStrategy ? null,
userDnsRules ? [ ],
# proxy.dns.remote as a sing-box server, for the AmneziaWG interfaces added at runtime; null
# when there are none.
awgRuntimeDnsServer ? null,
}:
let
@@ -16,6 +19,20 @@ else
(fillTemplate ./backend-filter-sing-box.template.jq {
userDnsRuleCount = toString (builtins.length userDnsRules);
})
# 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) ''
| ([.dns.servers[]?.tag]) as $have
| .dns.servers += [
.outbounds[]
| select(.type == "direct" and (.bind_interface | type) == "string"
and ((.domain_resolver? // "") | type) == "string"
and ((.domain_resolver? // "") | startswith("awg-dns-")))
| select(.domain_resolver as $t | $have | index($t) | not)
| {tag: .domain_resolver, bind_interface} + ${builtins.toJSON awgRuntimeDnsServer}
+ (if .routing_mark then {routing_mark} else {} end)
]
''
+ lib.optionalString proxyInboundsGuardPrivate (
fillTemplate ./backend-filter-private-guard.template.jq {
resolveStrategy = lib.optionalString (
@@ -9,6 +9,7 @@
whitelistBypassJoiners,
awgOutbounds,
awgRuntimeOutbounds ? false,
awgRuntimeIfaceOutbounds ? false,
constants,
pureXrayEnabled,
hybridEnabled,
@@ -182,6 +183,38 @@ let
_proxy_suite_record_tag_source "$1" "$3"
}
${lib.optionalString awgRuntimeIfaceOutbounds ''
# $1 tag, $2 its slot: an AmneziaWG outbound added at runtime on an interface of its
# own, as mkInterfaceOutboundBlock has it. sing-box resolves through the interface
# with a server the backend filter adds for awg-dns-<tag>; XRay resolves as usual.
_proxy_suite_add_awg_interface() {
local ob
case "$2" in
"" | *[!0-9]*) return 1 ;;
esac
[ "$2" -lt ${toString constants.awgRuntimeIfaceSlots} ] || return 1
ob=$(${jq} -nc --arg t "$1" --arg i "${constants.awgRuntimeIfacePrefix}$2" ${
lib.escapeShellArg (
if pureXrayEnabled then
''{protocol: "freedom", tag: $t, streamSettings: {sockopt: ({interface: $i}${
lib.optionalString (routingMark != null) " + {mark: ${toString routingMark}}"
})}}''
else
''{type: "direct", tag: $t, bind_interface: $i, domain_resolver: ("${constants.awgDnsServerTag ""}" + $t)}${
lib.optionalString (routingMark != null) " + {routing_mark: ${toString routingMark}}"
}''
)
}) || return 1
${
if hybridEnabled then
''_proxy_suite_add_sing_box_ob "$ob"''
else
''OUTBOUNDS_JSON=$(${jq} --slurpfile ob <(printf '%s' "$ob") '. + $ob' <<< "$OUTBOUNDS_JSON")''
}
_proxy_suite_record_tag_source "$1" awg
}
''}
# $1 sub tag, $2 file holding its URL, $3 its links file (absent for a cache
# written before links existed: those entries share as JSON until the next update).
_proxy_suite_record_subscription_share() {
@@ -507,7 +540,15 @@ let
case "$RUNTIME_OB_SRC" in
*.json) _proxy_suite_add_json_outbound "$RUNTIME_OB_TAG" "$RUNTIME_OB_SRC" runtime ;;
# Its tunnel (proxy-suite-awg-tunnel@<tag>) checks the port again before listening.
*.awg) _proxy_suite_add_socks_hop "$RUNTIME_OB_TAG" "$(_proxy_suite_read_source "${runtimeOutboundsDir}/$RUNTIME_OB_TAG.port" 2>/dev/null | head -n 1)" runtime ;;
*.awg)
${lib.optionalString awgRuntimeIfaceOutbounds ''
if [ -e "${runtimeOutboundsDir}/$RUNTIME_OB_TAG.iface" ]; then
_proxy_suite_add_awg_interface "$RUNTIME_OB_TAG" "$(_proxy_suite_read_source "${runtimeOutboundsDir}/$RUNTIME_OB_TAG.iface" 2>/dev/null | head -n 1)"
else
''}
_proxy_suite_add_socks_hop "$RUNTIME_OB_TAG" "$(_proxy_suite_read_source "${runtimeOutboundsDir}/$RUNTIME_OB_TAG.port" 2>/dev/null | head -n 1)" runtime
${lib.optionalString awgRuntimeIfaceOutbounds "fi"}
;;
*) _proxy_suite_add_url_outbound "$RUNTIME_OB_TAG" "$(_proxy_suite_read_source "$RUNTIME_OB_SRC")" runtime ;;
esac || { echo "proxy-suite: warning: ignoring runtime outbound '$RUNTIME_OB_TAG'" >&2; continue; }
if [ -s "${runtimeOutboundsDir}/$RUNTIME_OB_TAG.detour" ]; then