fix: various fixes
This commit is contained in:
18 files changed
+471
-88
No files matched your search
@@ -16,6 +16,7 @@ let
|
||||
inherit (constants)
|
||||
tunAutoRouteTableIndex
|
||||
tunAutoRouteRulePriority
|
||||
xrayTunServiceUserRulePriority
|
||||
xrayTunPerAppTproxyRulePriority
|
||||
xrayTunPerAppTunRulePriority
|
||||
xrayGlobalTunIPv6Address
|
||||
@@ -57,6 +58,8 @@ in
|
||||
|
||||
while ${ip} -4 rule del pref ${toString xrayTunPerAppTproxyRulePriority} 2>/dev/null; do :; done
|
||||
while ${ip} -4 rule del pref ${toString xrayTunPerAppTunRulePriority} 2>/dev/null; do :; done
|
||||
while ${ip} -4 rule del pref ${toString xrayTunServiceUserRulePriority} 2>/dev/null; do :; done
|
||||
while ${ip} -6 rule del pref ${toString xrayTunServiceUserRulePriority} 2>/dev/null; do :; done
|
||||
while ${ip} -4 rule del pref ${toString tunAutoRouteRulePriority} 2>/dev/null; do :; done
|
||||
while ${ip} -6 rule del pref ${toString xrayTunPerAppTunRulePriority} 2>/dev/null; do :; done
|
||||
while ${ip} -6 rule del pref ${toString tunAutoRouteRulePriority} 2>/dev/null; do :; done
|
||||
@@ -77,6 +80,9 @@ in
|
||||
${ip} -4 rule add pref ${toString xrayTunPerAppTunRulePriority} fwmark ${toString perAppRoutingTun.fwmark} table ${toString perAppRoutingTun.routeTable}
|
||||
${ip} -6 rule add pref ${toString xrayTunPerAppTunRulePriority} fwmark ${toString perAppRoutingTun.fwmark} table ${toString perAppRoutingTun.routeTable}
|
||||
''}
|
||||
service_uid=$(${pkgs.coreutils}/bin/id -u ${constants.serviceUser})
|
||||
${ip} -4 rule add pref ${toString xrayTunServiceUserRulePriority} uidrange "$service_uid-$service_uid" lookup main
|
||||
${ip} -6 rule add pref ${toString xrayTunServiceUserRulePriority} uidrange "$service_uid-$service_uid" lookup main
|
||||
${ip} -4 rule add pref ${toString tunAutoRouteRulePriority} not fwmark ${toString globalTproxy.proxyMark} table ${toString tunAutoRouteTableIndex}
|
||||
${ip} -6 rule add pref ${toString tunAutoRouteRulePriority} not fwmark ${toString globalTproxy.proxyMark} table ${toString tunAutoRouteTableIndex}
|
||||
'';
|
||||
@@ -136,6 +142,16 @@ in
|
||||
family = "-6";
|
||||
priority = xrayTunPerAppTunRulePriority;
|
||||
}}
|
||||
${builders.mkIpRuleDeleteByPriority {
|
||||
inherit ip;
|
||||
family = "-4";
|
||||
priority = xrayTunServiceUserRulePriority;
|
||||
}}
|
||||
${builders.mkIpRuleDeleteByPriority {
|
||||
inherit ip;
|
||||
family = "-6";
|
||||
priority = xrayTunServiceUserRulePriority;
|
||||
}}
|
||||
${builders.mkIpRouteFlushTable { inherit ip; family = "-4"; table = tunAutoRouteTableIndex; }}
|
||||
${builders.mkIpRouteFlushTable { inherit ip; family = "-6"; table = tunAutoRouteTableIndex; }}
|
||||
${builders.mkIpLinkDelete { inherit ip; interface = globalTun.interface; }}
|
||||
|
||||
@@ -121,12 +121,15 @@ else
|
||||
''
|
||||
+ lib.optionalString proxyInboundsGuardPrivate ''
|
||||
# inbounds.routing.blockPrivate, enforced here because the listener passes names unresolved.
|
||||
# Last, so only traffic falling through to a direct final is resolved. Local mixed-
|
||||
# in clients lose names that resolve private.
|
||||
| if (.route.final // "direct") == "direct" then
|
||||
.route.rules += [
|
||||
{inbound: ["mixed-in"], action: "resolve"},
|
||||
{inbound: ["mixed-in"], ip_is_private: true, action: "reject"}
|
||||
]
|
||||
# Just before the first direct rule (or last, for a direct final), 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.
|
||||
| [{inbound: ["mixed-in"], action: "resolve"},
|
||||
{inbound: ["mixed-in"], ip_is_private: true, action: "reject"}] as $guard
|
||||
| (.route.rules | map((.outbound? // "") == "direct") | 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
|
||||
''
|
||||
@@ -147,6 +147,7 @@ let
|
||||
enableAutoProxy ? false,
|
||||
enableOutboundTest ? false,
|
||||
enableZapretCutoff ? false,
|
||||
excludeServiceUserFromTun ? false,
|
||||
}:
|
||||
pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
@@ -344,6 +345,14 @@ let
|
||||
--arg xray_dns_remote_client ${lib.escapeShellArg proxyCfg.dns.remote.address} \
|
||||
-f "$BACKEND_JQ_FILTER" \
|
||||
"${configFile}" > "$RUNTIME_DIR/config.json"
|
||||
${lib.optionalString excludeServiceUserFromTun ''
|
||||
# proxy-suite's own daemons (the inbound XRay, replies to its clients included)
|
||||
# stay out of the TUN; the uid is only known on this host.
|
||||
SERVICE_UID=$(${pkgs.coreutils}/bin/id -u ${constants.serviceUser})
|
||||
${jq} --argjson uid "$SERVICE_UID" '(.inbounds[] | select(.type == "tun") | .exclude_uid) = [$uid]' \
|
||||
"$RUNTIME_DIR/config.json" > "$RUNTIME_DIR/config.json.next"
|
||||
mv "$RUNTIME_DIR/config.json.next" "$RUNTIME_DIR/config.json"
|
||||
''}
|
||||
# The backend runs as ${constants.serviceUser}: its configs are group-readable.
|
||||
for backend_config in "$RUNTIME_DIR/config.json" "$RUNTIME_DIR/xray-sidecar.json"; do
|
||||
[ -e "$backend_config" ] || continue
|
||||
@@ -416,6 +425,8 @@ let
|
||||
xrayTunDnsRuntime = pureXrayEnabled;
|
||||
xraySidecarBasePort = xraySidecarBasePorts.tun;
|
||||
xrayDnsBridgePort = xrayDnsBridgePorts.tun;
|
||||
# Pure XRay's TUN routes by ip rules instead: see xrayTunUpScript.
|
||||
excludeServiceUserFromTun = !pureXrayEnabled;
|
||||
};
|
||||
|
||||
startPerAppTun = mkStartScript {
|
||||
|
||||
Reference in new issue
Block a user