fix: xray tun improvements
This commit is contained in:
13 files changed
+110
-159
No files matched your search
@@ -71,7 +71,10 @@ let
|
|||||||
{
|
{
|
||||||
enabled = true;
|
enabled = true;
|
||||||
destOverride = [ "fakedns" ];
|
destOverride = [ "fakedns" ];
|
||||||
metadataOnly = true;
|
# Fake IPs only live in memory: after a restart an app still holding one gets its
|
||||||
|
# domain back from TLS/HTTP/QUIC instead of a dead end. Real IPs are left alone;
|
||||||
|
# the cost is up to 200 ms before a server-speaks-first protocol (SSH, SMTP) starts.
|
||||||
|
metadataOnly = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -142,10 +145,6 @@ let
|
|||||||
enableTunFakeDns ? false,
|
enableTunFakeDns ? false,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
tunDnsServers = [
|
|
||||||
(if (proxyCfg.routing.default == "proxy") then proxyCfg.dns.remote.address else proxyCfg.dns.local.address)
|
|
||||||
(if (proxyCfg.routing.default == "proxy") then proxyCfg.dns.local.address else proxyCfg.dns.remote.address)
|
|
||||||
];
|
|
||||||
tunSniffing = mkSniffing { fakeDnsOnly = enableTunFakeDns; };
|
tunSniffing = mkSniffing { fakeDnsOnly = enableTunFakeDns; };
|
||||||
dnsConfig =
|
dnsConfig =
|
||||||
if enableTunFakeDns then
|
if enableTunFakeDns then
|
||||||
@@ -215,9 +214,7 @@ let
|
|||||||
name = tunInterface;
|
name = tunInterface;
|
||||||
mtu = tunMtu;
|
mtu = tunMtu;
|
||||||
gateway = [ tunAddress ] ++ lib.optionals (tunIPv6Address != null) [ tunIPv6Address ];
|
gateway = [ tunAddress ] ++ lib.optionals (tunIPv6Address != null) [ tunIPv6Address ];
|
||||||
dns = tunDnsServers;
|
|
||||||
userLevel = 0;
|
userLevel = 0;
|
||||||
autoOutboundsInterface = "auto";
|
|
||||||
};
|
};
|
||||||
sniffing = tunSniffing;
|
sniffing = tunSniffing;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -280,11 +280,18 @@ let
|
|||||||
|
|
||||||
tunAutoRouteTableIndex = 2022;
|
tunAutoRouteTableIndex = 2022;
|
||||||
tunAutoRouteRulePriority = 9000;
|
tunAutoRouteRulePriority = 9000;
|
||||||
# Keeps proxy-suite's own daemons (the inbound XRay, replies to its clients included)
|
# Pure-XRay global TUN, below 8998/8999 (AmneziaWG and tg-ws-proxy bypasses).
|
||||||
# out of the pure-XRay global TUN.
|
# proxyMark sockets and proxy-suite's own daemons (the inbound XRay, replies to its
|
||||||
xrayTunServiceUserRulePriority = 8995;
|
# clients included) stay out of the TUN.
|
||||||
xrayTunPerAppTproxyRulePriority = 8996;
|
xrayTunMarkBypassRulePriority = 8992;
|
||||||
xrayTunPerAppTunRulePriority = 8997;
|
xrayTunServiceUserRulePriority = 8993;
|
||||||
|
xrayTunPerAppTproxyRulePriority = 8994;
|
||||||
|
xrayTunPerAppTunRulePriority = 8995;
|
||||||
|
# DNS stays in the TUN for fakedns, even to a LAN resolver.
|
||||||
|
xrayTunDnsRulePriority = 8996;
|
||||||
|
# Routes more specific than default (LAN, container bridges) skip the TUN, so
|
||||||
|
# replies to connections from there leave the way they came.
|
||||||
|
xrayTunMainRulePriority = 8997;
|
||||||
|
|
||||||
xrayGlobalTunIPv6Address = "fd66:19::1/64";
|
xrayGlobalTunIPv6Address = "fd66:19::1/64";
|
||||||
xrayGlobalTunIPv6RoutePrefix = "fd66:19::/64";
|
xrayGlobalTunIPv6RoutePrefix = "fd66:19::/64";
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ let
|
|||||||
perAppTproxyRulesFile
|
perAppTproxyRulesFile
|
||||||
ip
|
ip
|
||||||
nft
|
nft
|
||||||
awk
|
|
||||||
seqBin
|
seqBin
|
||||||
sleepBin
|
sleepBin
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -11,17 +11,11 @@
|
|||||||
perAppTproxyRulesFile,
|
perAppTproxyRulesFile,
|
||||||
ip,
|
ip,
|
||||||
nft,
|
nft,
|
||||||
awk,
|
|
||||||
seqBin,
|
seqBin,
|
||||||
sleepBin,
|
sleepBin,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
defaultUplinkIPv4Source = builders.mkDefaultUplinkIPv4Source {
|
|
||||||
inherit ip awk;
|
|
||||||
errorMessage = "proxy-suite: could not determine the default uplink IPv4 address for app TUN";
|
|
||||||
};
|
|
||||||
|
|
||||||
inherit (constants)
|
inherit (constants)
|
||||||
xrayPerAppTunIPv6Address
|
xrayPerAppTunIPv6Address
|
||||||
xrayPerAppTunIPv6RoutePrefix
|
xrayPerAppTunIPv6RoutePrefix
|
||||||
@@ -47,7 +41,6 @@ let
|
|||||||
tun6_route_prefix=${lib.escapeShellArg xrayPerAppTunIPv6RoutePrefix}
|
tun6_route_prefix=${lib.escapeShellArg xrayPerAppTunIPv6RoutePrefix}
|
||||||
tun_addr=""
|
tun_addr=""
|
||||||
tun_route_prefix=""
|
tun_route_prefix=""
|
||||||
uplink_addr=""
|
|
||||||
|
|
||||||
${builders.cidrNetworkFunction}
|
${builders.cidrNetworkFunction}
|
||||||
|
|
||||||
@@ -68,12 +61,12 @@ let
|
|||||||
${builders.mkIpRouteFlushTable { inherit ip; family = "-6"; table = perAppRoutingTun.routeTable; }}
|
${builders.mkIpRouteFlushTable { inherit ip; family = "-6"; table = perAppRoutingTun.routeTable; }}
|
||||||
${nft} -f ${perAppTunChainFile}
|
${nft} -f ${perAppTunChainFile}
|
||||||
${perAppTunWaitForInterface}
|
${perAppTunWaitForInterface}
|
||||||
${defaultUplinkIPv4Source}
|
|
||||||
tun_addr="''${tun_cidr%%/*}"
|
tun_addr="''${tun_cidr%%/*}"
|
||||||
tun_route_prefix="$(cidr_network "$tun_cidr")"
|
tun_route_prefix="$(cidr_network "$tun_cidr")"
|
||||||
${ip} -4 addr replace "$tun_cidr" dev ${lib.escapeShellArg perAppRoutingTun.interface}
|
${ip} -4 addr replace "$tun_cidr" dev ${lib.escapeShellArg perAppRoutingTun.interface}
|
||||||
${ip} -4 route replace "$tun_route_prefix" dev ${lib.escapeShellArg perAppRoutingTun.interface} src "$tun_addr" table ${toString perAppRoutingTun.routeTable}
|
${ip} -4 route replace "$tun_route_prefix" dev ${lib.escapeShellArg perAppRoutingTun.interface} src "$tun_addr" table ${toString perAppRoutingTun.routeTable}
|
||||||
${ip} -4 route replace default dev ${lib.escapeShellArg perAppRoutingTun.interface} src "$uplink_addr" table ${toString perAppRoutingTun.routeTable}
|
# No uplink src, as in xrayTunUpScript: it goes stale when the uplink address changes.
|
||||||
|
${ip} -4 route replace default dev ${lib.escapeShellArg perAppRoutingTun.interface} table ${toString perAppRoutingTun.routeTable}
|
||||||
${ip} -4 rule add fwmark ${toString perAppRoutingTun.fwmark} table ${toString perAppRoutingTun.routeTable} 2>/dev/null || true
|
${ip} -4 rule add fwmark ${toString perAppRoutingTun.fwmark} table ${toString perAppRoutingTun.routeTable} 2>/dev/null || true
|
||||||
${lib.optionalString pureXrayEnabled ''
|
${lib.optionalString pureXrayEnabled ''
|
||||||
${ip} -6 addr replace "$tun6_cidr" dev ${lib.escapeShellArg perAppRoutingTun.interface}
|
${ip} -6 addr replace "$tun6_cidr" dev ${lib.escapeShellArg perAppRoutingTun.interface}
|
||||||
|
|||||||
@@ -16,17 +16,45 @@ let
|
|||||||
inherit (constants)
|
inherit (constants)
|
||||||
tunAutoRouteTableIndex
|
tunAutoRouteTableIndex
|
||||||
tunAutoRouteRulePriority
|
tunAutoRouteRulePriority
|
||||||
|
xrayTunMarkBypassRulePriority
|
||||||
xrayTunServiceUserRulePriority
|
xrayTunServiceUserRulePriority
|
||||||
xrayTunPerAppTproxyRulePriority
|
xrayTunPerAppTproxyRulePriority
|
||||||
xrayTunPerAppTunRulePriority
|
xrayTunPerAppTunRulePriority
|
||||||
|
xrayTunDnsRulePriority
|
||||||
|
xrayTunMainRulePriority
|
||||||
xrayGlobalTunIPv6Address
|
xrayGlobalTunIPv6Address
|
||||||
xrayGlobalTunIPv6RoutePrefix
|
xrayGlobalTunIPv6RoutePrefix
|
||||||
;
|
;
|
||||||
|
|
||||||
defaultUplinkIPv4Source = builders.mkDefaultUplinkIPv4Source {
|
deleteXrayTunRules = lib.concatMapStrings (
|
||||||
inherit ip;
|
family:
|
||||||
awk = "${pkgs.gawk}/bin/awk";
|
lib.concatMapStrings (priority: builders.mkIpRuleDeleteByPriority { inherit ip family priority; }) [
|
||||||
errorMessage = "proxy-suite: could not determine the default uplink IPv4 address for XRay TUN";
|
xrayTunMarkBypassRulePriority
|
||||||
|
xrayTunServiceUserRulePriority
|
||||||
|
xrayTunPerAppTproxyRulePriority
|
||||||
|
xrayTunPerAppTunRulePriority
|
||||||
|
xrayTunDnsRulePriority
|
||||||
|
xrayTunMainRulePriority
|
||||||
|
tunAutoRouteRulePriority
|
||||||
|
]
|
||||||
|
) [ "-4" "-6" ];
|
||||||
|
|
||||||
|
# Replies to connections from outside (sshd, a game server, anything listening) take
|
||||||
|
# proxyMark, so the fwmark rule sends them back out the way they came instead of into
|
||||||
|
# the TUN, where nothing expects them. Locally started connections stay "original".
|
||||||
|
xrayTunReplyTable = "proxy_suite_xray_tun";
|
||||||
|
xrayTunReplyRules = pkgs.writeText "proxy-suite-xray-tun.nft" ''
|
||||||
|
table inet ${xrayTunReplyTable} {
|
||||||
|
chain output {
|
||||||
|
type route hook output priority mangle; policy accept;
|
||||||
|
ct direction reply meta mark 0 meta mark set ${toString globalTproxy.proxyMark}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
deleteXrayTunReplyTable = builders.mkNftDeleteTable {
|
||||||
|
inherit nft;
|
||||||
|
family = "inet";
|
||||||
|
table = xrayTunReplyTable;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -38,7 +66,6 @@ in
|
|||||||
tun6_route_prefix=${lib.escapeShellArg xrayGlobalTunIPv6RoutePrefix}
|
tun6_route_prefix=${lib.escapeShellArg xrayGlobalTunIPv6RoutePrefix}
|
||||||
tun_addr=""
|
tun_addr=""
|
||||||
tun_route_prefix=""
|
tun_route_prefix=""
|
||||||
uplink_addr=""
|
|
||||||
|
|
||||||
${builders.cidrNetworkFunction}
|
${builders.cidrNetworkFunction}
|
||||||
|
|
||||||
@@ -54,15 +81,9 @@ in
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
${defaultUplinkIPv4Source}
|
${deleteXrayTunRules}
|
||||||
|
${deleteXrayTunReplyTable}
|
||||||
while ${ip} -4 rule del pref ${toString xrayTunPerAppTproxyRulePriority} 2>/dev/null; do :; done
|
${nft} -f ${xrayTunReplyRules}
|
||||||
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
|
|
||||||
|
|
||||||
tun_addr="''${tun_cidr%%/*}"
|
tun_addr="''${tun_cidr%%/*}"
|
||||||
tun_route_prefix="$(cidr_network "$tun_cidr")"
|
tun_route_prefix="$(cidr_network "$tun_cidr")"
|
||||||
@@ -70,7 +91,9 @@ in
|
|||||||
${ip} -4 addr replace "$tun_cidr" dev ${lib.escapeShellArg globalTun.interface}
|
${ip} -4 addr replace "$tun_cidr" dev ${lib.escapeShellArg globalTun.interface}
|
||||||
${ip} -6 addr replace "$tun6_cidr" dev ${lib.escapeShellArg globalTun.interface}
|
${ip} -6 addr replace "$tun6_cidr" dev ${lib.escapeShellArg globalTun.interface}
|
||||||
${ip} -4 route replace "$tun_route_prefix" dev ${lib.escapeShellArg globalTun.interface} src "$tun_addr" table ${toString tunAutoRouteTableIndex}
|
${ip} -4 route replace "$tun_route_prefix" dev ${lib.escapeShellArg globalTun.interface} src "$tun_addr" table ${toString tunAutoRouteTableIndex}
|
||||||
${ip} -4 route replace default dev ${lib.escapeShellArg globalTun.interface} src "$uplink_addr" table ${toString tunAutoRouteTableIndex}
|
# No uplink src: it goes stale when the uplink address changes, and XRay's own sockets
|
||||||
|
# (routed by uid and mark, not bound to an interface) pick theirs from main.
|
||||||
|
${ip} -4 route replace default dev ${lib.escapeShellArg globalTun.interface} table ${toString tunAutoRouteTableIndex}
|
||||||
${ip} -6 route replace "$tun6_route_prefix" dev ${lib.escapeShellArg globalTun.interface} table ${toString tunAutoRouteTableIndex}
|
${ip} -6 route replace "$tun6_route_prefix" dev ${lib.escapeShellArg globalTun.interface} table ${toString tunAutoRouteTableIndex}
|
||||||
${ip} -6 route replace default dev ${lib.escapeShellArg globalTun.interface} table ${toString tunAutoRouteTableIndex}
|
${ip} -6 route replace default dev ${lib.escapeShellArg globalTun.interface} table ${toString tunAutoRouteTableIndex}
|
||||||
${lib.optionalString perAppRoutingTproxy.enable ''
|
${lib.optionalString perAppRoutingTproxy.enable ''
|
||||||
@@ -83,6 +106,12 @@ in
|
|||||||
service_uid=$(${pkgs.coreutils}/bin/id -u ${constants.serviceUser})
|
service_uid=$(${pkgs.coreutils}/bin/id -u ${constants.serviceUser})
|
||||||
${ip} -4 rule add pref ${toString xrayTunServiceUserRulePriority} uidrange "$service_uid-$service_uid" lookup main
|
${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} -6 rule add pref ${toString xrayTunServiceUserRulePriority} uidrange "$service_uid-$service_uid" lookup main
|
||||||
|
for family in -4 -6; do
|
||||||
|
${ip} "$family" rule add pref ${toString xrayTunMarkBypassRulePriority} fwmark ${toString globalTproxy.proxyMark} lookup main
|
||||||
|
${ip} "$family" rule add pref ${toString xrayTunDnsRulePriority} ipproto udp dport 53 table ${toString tunAutoRouteTableIndex}
|
||||||
|
${ip} "$family" rule add pref ${toString xrayTunDnsRulePriority} ipproto tcp dport 53 table ${toString tunAutoRouteTableIndex}
|
||||||
|
${ip} "$family" rule add pref ${toString xrayTunMainRulePriority} lookup main suppress_prefixlength 0
|
||||||
|
done
|
||||||
${ip} -4 rule add pref ${toString tunAutoRouteRulePriority} not fwmark ${toString globalTproxy.proxyMark} table ${toString tunAutoRouteTableIndex}
|
${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}
|
${ip} -6 rule add pref ${toString tunAutoRouteRulePriority} not fwmark ${toString globalTproxy.proxyMark} table ${toString tunAutoRouteTableIndex}
|
||||||
'';
|
'';
|
||||||
@@ -127,31 +156,8 @@ in
|
|||||||
${builders.mkNftDeleteTable { inherit nft; family = "inet"; table = "sing-box"; }}
|
${builders.mkNftDeleteTable { inherit nft; family = "inet"; table = "sing-box"; }}
|
||||||
${builders.mkIpRuleDeleteByTable { inherit ip; family = "-4"; table = tunAutoRouteTableIndex; }}
|
${builders.mkIpRuleDeleteByTable { inherit ip; family = "-4"; table = tunAutoRouteTableIndex; }}
|
||||||
${builders.mkIpRuleDeleteByTable { inherit ip; family = "-6"; table = tunAutoRouteTableIndex; }}
|
${builders.mkIpRuleDeleteByTable { inherit ip; family = "-6"; table = tunAutoRouteTableIndex; }}
|
||||||
${builders.mkIpRuleDeleteByPriority {
|
${deleteXrayTunRules}
|
||||||
inherit ip;
|
${deleteXrayTunReplyTable}
|
||||||
family = "-4";
|
|
||||||
priority = xrayTunPerAppTproxyRulePriority;
|
|
||||||
}}
|
|
||||||
${builders.mkIpRuleDeleteByPriority {
|
|
||||||
inherit ip;
|
|
||||||
family = "-4";
|
|
||||||
priority = xrayTunPerAppTunRulePriority;
|
|
||||||
}}
|
|
||||||
${builders.mkIpRuleDeleteByPriority {
|
|
||||||
inherit ip;
|
|
||||||
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 = "-4"; table = tunAutoRouteTableIndex; }}
|
||||||
${builders.mkIpRouteFlushTable { inherit ip; family = "-6"; table = tunAutoRouteTableIndex; }}
|
${builders.mkIpRouteFlushTable { inherit ip; family = "-6"; table = tunAutoRouteTableIndex; }}
|
||||||
${builders.mkIpLinkDelete { inherit ip; interface = globalTun.interface; }}
|
${builders.mkIpLinkDelete { inherit ip; interface = globalTun.interface; }}
|
||||||
|
|||||||
@@ -9,20 +9,6 @@
|
|||||||
|
|
||||||
if pureXrayEnabled then
|
if pureXrayEnabled then
|
||||||
''
|
''
|
||||||
def xray_bind_outbound($interface):
|
|
||||||
# A loopback hop (the WARP tunnel, the OpenSSH listener) cannot leave through the uplink.
|
|
||||||
if $interface == "" or .protocol == "blackhole" or .protocol == "dns"
|
|
||||||
or ((.settings.address? // "") | test("^(127\\.|::1$|localhost$)")) then
|
|
||||||
.
|
|
||||||
else
|
|
||||||
.streamSettings = (.streamSettings // {})
|
|
||||||
| .streamSettings.sockopt = (.streamSettings.sockopt // {})
|
|
||||||
| if (.streamSettings.sockopt.interface? // "") == "" then
|
|
||||||
.streamSettings.sockopt.interface = $interface
|
|
||||||
else
|
|
||||||
.
|
|
||||||
end
|
|
||||||
end;
|
|
||||||
def xray_proxy_rule_target($single_tag):
|
def xray_proxy_rule_target($single_tag):
|
||||||
if $single_tag != "" then
|
if $single_tag != "" then
|
||||||
{outboundTag:$single_tag}
|
{outboundTag:$single_tag}
|
||||||
@@ -52,15 +38,7 @@ if pureXrayEnabled then
|
|||||||
+ [.dns.servers[] | select((.tag? // "") == $dns_final)]
|
+ [.dns.servers[] | select((.tag? // "") == $dns_final)]
|
||||||
+ [.dns.servers[] | select((.tag? // "") != "fakedns" and (.tag? // "") != $dns_final)])
|
+ [.dns.servers[] | select((.tag? // "") != "fakedns" and (.tag? // "") != $dns_final)])
|
||||||
end;
|
end;
|
||||||
def xray_tun_dns_addresses($dns_final; $local_addr; $remote_addr):
|
.outbounds = ($obs + .outbounds)
|
||||||
if $dns_final == "local" then
|
|
||||||
[$local_addr, $remote_addr]
|
|
||||||
elif $dns_final == "remote" then
|
|
||||||
[$remote_addr, $local_addr]
|
|
||||||
else
|
|
||||||
[$remote_addr, $local_addr]
|
|
||||||
end;
|
|
||||||
.outbounds = (($obs + .outbounds) | map(xray_bind_outbound($xray_bind_interface)))
|
|
||||||
| if $xray_loglevel == "" then . else .log.loglevel = $xray_loglevel end
|
| if $xray_loglevel == "" then . else .log.loglevel = $xray_loglevel end
|
||||||
| if $auth_enabled then
|
| if $auth_enabled then
|
||||||
(.inbounds[] | select(.protocol == "socks" and .tag == "mixed-in") | .settings.auth) = "password"
|
(.inbounds[] | select(.protocol == "socks" and .tag == "mixed-in") | .settings.auth) = "password"
|
||||||
@@ -68,11 +46,12 @@ if pureXrayEnabled then
|
|||||||
else . end
|
else . end
|
||||||
| if $xray_tun_dns_runtime then
|
| if $xray_tun_dns_runtime then
|
||||||
.dns.servers = xray_dns_server_order($dns_final)
|
.dns.servers = xray_dns_server_order($dns_final)
|
||||||
| if $dns_final == "" then
|
# Without a domainStrategy a dial resolves through the system resolver, which under
|
||||||
.
|
# the TUN (resolved's upstream queries included) hands out fake IPs. XRay's own DNS
|
||||||
else
|
# client skips fakedns.
|
||||||
(.inbounds[] | select(.protocol == "tun" and .tag == "tun-in") | .settings.dns) = xray_tun_dns_addresses($dns_final; $xray_dns_local_client; $xray_dns_remote_client)
|
| .outbounds |= map(
|
||||||
end
|
if .protocol == "blackhole" or .protocol == "dns" or .protocol == "loopback" then .
|
||||||
|
else .streamSettings.sockopt.domainStrategy //= "UseIPv4v6" end)
|
||||||
else . end
|
else . end
|
||||||
| if $route_enabled then
|
| if $route_enabled then
|
||||||
.routing.rules = (xray_preserved_rules + $route_rules + [xray_final_rule($route_final; $xray_single_proxy_tag)])
|
.routing.rules = (xray_preserved_rules + $route_rules + [xray_final_rule($route_final; $xray_single_proxy_tag)])
|
||||||
@@ -99,7 +78,7 @@ else
|
|||||||
[.route.rules[]
|
[.route.rules[]
|
||||||
| select(((.action? // "") == "hijack-dns")
|
| select(((.action? // "") == "hijack-dns")
|
||||||
and (((.inbound? // []) | index("xray-dns-in")) != null))];
|
and (((.inbound? // []) | index("xray-dns-in")) != null))];
|
||||||
.outbounds = $obs + .outbounds
|
.outbounds = ($obs + .outbounds)
|
||||||
| if $auth_enabled then
|
| if $auth_enabled then
|
||||||
(.inbounds[] | select(.type == "mixed" and .tag == "mixed-in") | .users) = [{username:$user,password:$password}]
|
(.inbounds[] | select(.type == "mixed" and .tag == "mixed-in") | .users) = [{username:$user,password:$password}]
|
||||||
else . end
|
else . end
|
||||||
|
|||||||
@@ -67,24 +67,11 @@ lib.optionalString hybridEnabled ''
|
|||||||
fi
|
fi
|
||||||
${jq} -n \
|
${jq} -n \
|
||||||
--arg loglevel "$XRAY_LOGLEVEL" \
|
--arg loglevel "$XRAY_LOGLEVEL" \
|
||||||
--arg bind_interface "$XRAY_TUN_BIND_INTERFACE" \
|
|
||||||
--argjson dns_port "$XRAY_SIDECAR_DNS_PORT" \
|
--argjson dns_port "$XRAY_SIDECAR_DNS_PORT" \
|
||||||
--argjson inbounds "$XRAY_INBOUNDS_JSON" \
|
--argjson inbounds "$XRAY_INBOUNDS_JSON" \
|
||||||
--argjson outbounds "$XRAY_OUTBOUNDS_JSON" \
|
--argjson outbounds "$XRAY_OUTBOUNDS_JSON" \
|
||||||
--argjson route_rules "$XRAY_ROUTE_RULES_JSON" \
|
--argjson route_rules "$XRAY_ROUTE_RULES_JSON" \
|
||||||
'
|
'
|
||||||
def bind_xray_sidecar($interface):
|
|
||||||
if $interface == "" then
|
|
||||||
.
|
|
||||||
else
|
|
||||||
.streamSettings = (.streamSettings // {})
|
|
||||||
| .streamSettings.sockopt = (.streamSettings.sockopt // {})
|
|
||||||
| if (.streamSettings.sockopt.interface? // "") == "" then
|
|
||||||
.streamSettings.sockopt.interface = $interface
|
|
||||||
else
|
|
||||||
.
|
|
||||||
end
|
|
||||||
end;
|
|
||||||
{
|
{
|
||||||
log: {
|
log: {
|
||||||
loglevel: (if $loglevel == "" then "warning" else $loglevel end),
|
loglevel: (if $loglevel == "" then "warning" else $loglevel end),
|
||||||
@@ -101,7 +88,7 @@ lib.optionalString hybridEnabled ''
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
inbounds: $inbounds,
|
inbounds: $inbounds,
|
||||||
outbounds: (($outbounds | map(bind_xray_sidecar($bind_interface))) + [{protocol:"freedom",tag:"direct"}]),
|
outbounds: ($outbounds + [{protocol:"freedom",tag:"direct"}]),
|
||||||
routing: {
|
routing: {
|
||||||
domainStrategy: "AsIs",
|
domainStrategy: "AsIs",
|
||||||
rules: ($route_rules + [{type:"field",ip:["127.0.0.1"],port:$dns_port,outboundTag:"direct"}])
|
rules: ($route_rules + [{type:"field",ip:["127.0.0.1"],port:$dns_port,outboundTag:"direct"}])
|
||||||
|
|||||||
@@ -146,7 +146,6 @@ let
|
|||||||
configFile,
|
configFile,
|
||||||
routingMark ? null,
|
routingMark ? null,
|
||||||
enableLocalProxyAuth ? false,
|
enableLocalProxyAuth ? false,
|
||||||
xrayTunEgressBinding ? false,
|
|
||||||
xrayTunDnsRuntime ? false,
|
xrayTunDnsRuntime ? false,
|
||||||
xraySidecarBasePort ? xraySidecarBasePorts.socks,
|
xraySidecarBasePort ? xraySidecarBasePorts.socks,
|
||||||
xrayDnsBridgePort ? xrayDnsBridgePorts.socks,
|
xrayDnsBridgePort ? xrayDnsBridgePorts.socks,
|
||||||
@@ -161,7 +160,6 @@ let
|
|||||||
ROUTE_MODE_STATE_FILE="${routeModeStateFile}"
|
ROUTE_MODE_STATE_FILE="${routeModeStateFile}"
|
||||||
BACKEND_JQ_FILTER=${lib.escapeShellArg backendJqFilterFile}
|
BACKEND_JQ_FILTER=${lib.escapeShellArg backendJqFilterFile}
|
||||||
XRAY_LOGLEVEL=""
|
XRAY_LOGLEVEL=""
|
||||||
XRAY_TUN_BIND_INTERFACE=""
|
|
||||||
XRAY_SINGLE_PROXY_TAG=""
|
XRAY_SINGLE_PROXY_TAG=""
|
||||||
mkdir -p "$RUNTIME_DIR"
|
mkdir -p "$RUNTIME_DIR"
|
||||||
OUTBOUNDS_JSON='[]'
|
OUTBOUNDS_JSON='[]'
|
||||||
@@ -187,22 +185,6 @@ let
|
|||||||
XRAY_LOGLEVEL="$(tr -d '\r\n[:space:]' < "${xrayLoglevelFile}" 2>/dev/null || true)"
|
XRAY_LOGLEVEL="$(tr -d '\r\n[:space:]' < "${xrayLoglevelFile}" 2>/dev/null || true)"
|
||||||
fi
|
fi
|
||||||
''}
|
''}
|
||||||
${lib.optionalString xrayTunEgressBinding ''
|
|
||||||
XRAY_TUN_BIND_INTERFACE="$(${pkgs.iproute2}/bin/ip -4 route get 1.1.1.1 mark ${toString globalTproxy.proxyMark} 2>/dev/null | ${pkgs.gawk}/bin/awk '
|
|
||||||
/dev/ {
|
|
||||||
for (i = 1; i <= NF; i++) {
|
|
||||||
if ($i == "dev" && i + 1 <= NF) {
|
|
||||||
print $(i + 1)
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
')"
|
|
||||||
if [ -z "$XRAY_TUN_BIND_INTERFACE" ]; then
|
|
||||||
echo "proxy-suite: could not determine the default uplink interface for XRay TUN" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
''}
|
|
||||||
|
|
||||||
${routeModeCaseBlock}
|
${routeModeCaseBlock}
|
||||||
|
|
||||||
@@ -350,12 +332,9 @@ let
|
|||||||
--arg dns_final "$DNS_FINAL" \
|
--arg dns_final "$DNS_FINAL" \
|
||||||
--argjson clear_dns_rules "$CLEAR_DNS_RULES" \
|
--argjson clear_dns_rules "$CLEAR_DNS_RULES" \
|
||||||
--arg xray_loglevel "$XRAY_LOGLEVEL" \
|
--arg xray_loglevel "$XRAY_LOGLEVEL" \
|
||||||
--arg xray_bind_interface "$XRAY_TUN_BIND_INTERFACE" \
|
|
||||||
--arg xray_single_proxy_tag "$XRAY_SINGLE_PROXY_TAG" \
|
--arg xray_single_proxy_tag "$XRAY_SINGLE_PROXY_TAG" \
|
||||||
--argjson xray_selectable "$SELECTABLE_TAGS_JSON" \
|
--argjson xray_selectable "$SELECTABLE_TAGS_JSON" \
|
||||||
--argjson xray_tun_dns_runtime ${if xrayTunDnsRuntime then "true" else "false"} \
|
--argjson xray_tun_dns_runtime ${if xrayTunDnsRuntime then "true" else "false"} \
|
||||||
--arg xray_dns_local_client ${lib.escapeShellArg proxyCfg.dns.local.address} \
|
|
||||||
--arg xray_dns_remote_client ${lib.escapeShellArg proxyCfg.dns.remote.address} \
|
|
||||||
-f "$BACKEND_JQ_FILTER" \
|
-f "$BACKEND_JQ_FILTER" \
|
||||||
"${configFile}" > "$RUNTIME_DIR/config.json"
|
"${configFile}" > "$RUNTIME_DIR/config.json"
|
||||||
${lib.optionalString excludeServiceUserFromTun ''
|
${lib.optionalString excludeServiceUserFromTun ''
|
||||||
@@ -446,7 +425,6 @@ let
|
|||||||
runtimeDir = "/run/proxy-suite-tun";
|
runtimeDir = "/run/proxy-suite-tun";
|
||||||
configFile = tunFile;
|
configFile = tunFile;
|
||||||
routingMark = if pureXrayEnabled then globalTproxy.proxyMark else null;
|
routingMark = if pureXrayEnabled then globalTproxy.proxyMark else null;
|
||||||
xrayTunEgressBinding = xrayEnabled;
|
|
||||||
xrayTunDnsRuntime = pureXrayEnabled;
|
xrayTunDnsRuntime = pureXrayEnabled;
|
||||||
xraySidecarBasePort = xraySidecarBasePorts.tun;
|
xraySidecarBasePort = xraySidecarBasePorts.tun;
|
||||||
xrayDnsBridgePort = xrayDnsBridgePorts.tun;
|
xrayDnsBridgePort = xrayDnsBridgePorts.tun;
|
||||||
@@ -458,7 +436,6 @@ let
|
|||||||
runtimeDir = "/run/proxy-suite-per-app-tun";
|
runtimeDir = "/run/proxy-suite-per-app-tun";
|
||||||
configFile = perAppTunFile;
|
configFile = perAppTunFile;
|
||||||
routingMark = if xrayEnabled || globalTproxy.enable then globalTproxy.proxyMark else null;
|
routingMark = if xrayEnabled || globalTproxy.enable then globalTproxy.proxyMark else null;
|
||||||
xrayTunEgressBinding = xrayEnabled;
|
|
||||||
xrayTunDnsRuntime = pureXrayEnabled;
|
xrayTunDnsRuntime = pureXrayEnabled;
|
||||||
xraySidecarBasePort = xraySidecarBasePorts.perAppTun;
|
xraySidecarBasePort = xraySidecarBasePorts.perAppTun;
|
||||||
xrayDnsBridgePort = xrayDnsBridgePorts.perAppTun;
|
xrayDnsBridgePort = xrayDnsBridgePorts.perAppTun;
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ let
|
|||||||
inherit (fixtures)
|
inherit (fixtures)
|
||||||
xrayBackendJqFilter
|
xrayBackendJqFilter
|
||||||
xrayBackendJqFilterFile
|
xrayBackendJqFilterFile
|
||||||
xrayDnsLocalClient
|
|
||||||
xrayDnsRemoteClient
|
|
||||||
xrayFixture
|
xrayFixture
|
||||||
xrayPerAppTunBackendJqFilterFile
|
xrayPerAppTunBackendJqFilterFile
|
||||||
xrayPerAppTunCleanupScript
|
xrayPerAppTunCleanupScript
|
||||||
@@ -62,27 +60,22 @@ let
|
|||||||
--arg dns_final "remote" \
|
--arg dns_final "remote" \
|
||||||
--argjson clear_dns_rules false \
|
--argjson clear_dns_rules false \
|
||||||
--arg xray_loglevel "" \
|
--arg xray_loglevel "" \
|
||||||
--arg xray_bind_interface "eth0" \
|
|
||||||
--arg xray_single_proxy_tag "proxy-suite-ob-primary" \
|
--arg xray_single_proxy_tag "proxy-suite-ob-primary" \
|
||||||
--argjson xray_tun_dns_runtime true \
|
--argjson xray_tun_dns_runtime true \
|
||||||
--arg xray_dns_local_client ${pkgs.lib.escapeShellArg xrayDnsLocalClient} \
|
|
||||||
--arg xray_dns_remote_client ${pkgs.lib.escapeShellArg xrayDnsRemoteClient} \
|
|
||||||
-f ${pkgs.lib.escapeShellArg xrayBackendJqFilterFile} \
|
-f ${pkgs.lib.escapeShellArg xrayBackendJqFilterFile} \
|
||||||
"$input" > "$output"
|
"$input" > "$output"
|
||||||
|
|
||||||
jq -e \
|
jq -e \
|
||||||
--arg remote ${pkgs.lib.escapeShellArg xrayDnsRemoteClient} \
|
|
||||||
--arg local ${pkgs.lib.escapeShellArg xrayDnsLocalClient} \
|
|
||||||
'
|
'
|
||||||
type == "object"
|
type == "object"
|
||||||
and (.dns.servers | length) >= 3
|
and (.dns.servers | length) >= 3
|
||||||
and .dns.servers[0].tag == "fakedns"
|
and .dns.servers[0].tag == "fakedns"
|
||||||
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-hijack")] | length) == 1
|
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-hijack")] | length) == 1
|
||||||
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-upstream-direct")] | length) == 1
|
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-upstream-direct")] | length) == 1
|
||||||
and ([.outbounds[] | select(.tag == "proxy-suite-ob-primary" and (.streamSettings.sockopt.interface? // "") == "eth0")] | length) == 1
|
and ([.outbounds[] | select(.streamSettings.sockopt.interface?)] | length) == 0
|
||||||
and ([.outbounds[] | select(.tag == "dns-out" and ((.streamSettings.sockopt.interface? // "") == ""))] | length) == 1
|
and ([.outbounds[] | select(.protocol == "freedom" or .tag == "proxy-suite-ob-primary") | .streamSettings.sockopt.domainStrategy] | all(. == "UseIPv4v6"))
|
||||||
and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns] | length) == 1
|
and ([.outbounds[] | select(.protocol == "dns") | .streamSettings.sockopt.domainStrategy?] | all(. == null))
|
||||||
and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns][0] == [$remote, $local])
|
and ([.inbounds[] | select(.tag == "tun-in") | .settings | has("dns") or has("autoOutboundsInterface")] | any | not)
|
||||||
and ((.routing | has("balancers")) | not)
|
and ((.routing | has("balancers")) | not)
|
||||||
and ((has("observatory")) | not)
|
and ((has("observatory")) | not)
|
||||||
' "$output" >/dev/null
|
' "$output" >/dev/null
|
||||||
|
|||||||
@@ -85,8 +85,6 @@ let
|
|||||||
selectionMode = xrayFixture.config.services.proxy-suite.proxy.selection;
|
selectionMode = xrayFixture.config.services.proxy-suite.proxy.selection;
|
||||||
};
|
};
|
||||||
xrayBackendJqFilterFile = pkgs.writeText "proxy-suite-xray-backend-filter-check.jq" xrayBackendJqFilter;
|
xrayBackendJqFilterFile = pkgs.writeText "proxy-suite-xray-backend-filter-check.jq" xrayBackendJqFilter;
|
||||||
xrayDnsLocalClient = xrayFixture.config.services.proxy-suite.proxy.dns.local.address;
|
|
||||||
xrayDnsRemoteClient = xrayFixture.config.services.proxy-suite.proxy.dns.remote.address;
|
|
||||||
xrayTunConfigJson = pkgs.writeText "proxy-suite-xray-tun-check.json" (
|
xrayTunConfigJson = pkgs.writeText "proxy-suite-xray-tun-check.json" (
|
||||||
builtins.toJSON xrayTunConfig
|
builtins.toJSON xrayTunConfig
|
||||||
);
|
);
|
||||||
@@ -98,8 +96,6 @@ in
|
|||||||
inherit
|
inherit
|
||||||
xrayBackendJqFilter
|
xrayBackendJqFilter
|
||||||
xrayBackendJqFilterFile
|
xrayBackendJqFilterFile
|
||||||
xrayDnsLocalClient
|
|
||||||
xrayDnsRemoteClient
|
|
||||||
xrayFixture
|
xrayFixture
|
||||||
xrayPerAppTunBackendJqFilterFile
|
xrayPerAppTunBackendJqFilterFile
|
||||||
xrayPerAppTunCleanupScript
|
xrayPerAppTunCleanupScript
|
||||||
|
|||||||
@@ -22,13 +22,11 @@
|
|||||||
!(pkgs.lib.hasInfix ''select(.protocol == "socks" and .tag == "mixed-in") | .settings.users'' xrayBackendJqFilter);
|
!(pkgs.lib.hasInfix ''select(.protocol == "socks" and .tag == "mixed-in") | .settings.users'' xrayBackendJqFilter);
|
||||||
assert pkgs.lib.hasInfix "xray_preserved_rules" xrayBackendJqFilter;
|
assert pkgs.lib.hasInfix "xray_preserved_rules" xrayBackendJqFilter;
|
||||||
assert pkgs.lib.hasInfix "dns-upstream-direct" xrayBackendJqFilter;
|
assert pkgs.lib.hasInfix "dns-upstream-direct" xrayBackendJqFilter;
|
||||||
assert pkgs.lib.hasInfix "xray_tun_dns_addresses" xrayBackendJqFilter;
|
assert pkgs.lib.hasInfix "xray_dns_server_order" xrayBackendJqFilter;
|
||||||
assert pkgs.lib.hasInfix "dns-hijack" xrayBackendJqFilter;
|
assert pkgs.lib.hasInfix "dns-hijack" xrayBackendJqFilter;
|
||||||
assert pkgs.lib.hasInfix ".streamSettings.sockopt.interface = $interface" xrayBackendJqFilter;
|
|
||||||
assert pkgs.lib.hasInfix "del(.routing.balancers)" xrayBackendJqFilter;
|
assert pkgs.lib.hasInfix "del(.routing.balancers)" xrayBackendJqFilter;
|
||||||
assert pkgs.lib.hasInfix "del(.observatory)" xrayBackendJqFilter;
|
assert pkgs.lib.hasInfix "del(.observatory)" xrayBackendJqFilter;
|
||||||
assert pkgs.lib.hasInfix "xray_rewrite_proxy_rule" xrayBackendJqFilter;
|
assert pkgs.lib.hasInfix "xray_rewrite_proxy_rule" xrayBackendJqFilter;
|
||||||
assert pkgs.lib.hasInfix ".protocol == \"dns\"" xrayBackendJqFilter;
|
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -40,10 +40,8 @@
|
|||||||
"172.19.0.1/30"
|
"172.19.0.1/30"
|
||||||
checkConstants.xrayGlobalTunIPv6Address
|
checkConstants.xrayGlobalTunIPv6Address
|
||||||
];
|
];
|
||||||
assert builtins.length tunInbound.settings.dns == 2;
|
|
||||||
assert tunInbound.settings.autoOutboundsInterface == "auto";
|
|
||||||
assert tunInbound.sniffing.destOverride == [ "fakedns" ];
|
assert tunInbound.sniffing.destOverride == [ "fakedns" ];
|
||||||
assert tunInbound.sniffing.metadataOnly == true;
|
assert tunInbound.sniffing.metadataOnly == false;
|
||||||
assert xrayTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
assert xrayTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
||||||
assert tunHasFinalRuleTag;
|
assert tunHasFinalRuleTag;
|
||||||
assert tunHasDirectGeositeRule;
|
assert tunHasDirectGeositeRule;
|
||||||
@@ -67,21 +65,18 @@
|
|||||||
assert tunDirectOutbound.streamSettings.sockopt.mark == 2;
|
assert tunDirectOutbound.streamSettings.sockopt.mark == 2;
|
||||||
assert pkgs.lib.hasInfix "xray-loglevel" xrayTunStartScript;
|
assert pkgs.lib.hasInfix "xray-loglevel" xrayTunStartScript;
|
||||||
assert pkgs.lib.hasInfix "XRAY_SINGLE_PROXY_TAG=" xrayTunStartScript;
|
assert pkgs.lib.hasInfix "XRAY_SINGLE_PROXY_TAG=" xrayTunStartScript;
|
||||||
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1" xrayTunStartScript;
|
|
||||||
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1 mark 2" xrayTunStartScript;
|
|
||||||
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayTunStartScript;
|
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayTunStartScript;
|
||||||
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayTunStartScript;
|
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayTunStartScript;
|
||||||
assert pkgs.lib.hasInfix "xray_tun_dns_runtime" xrayTunStartScript;
|
assert pkgs.lib.hasInfix "xray_tun_dns_runtime" xrayTunStartScript;
|
||||||
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayTunUpScript;
|
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayTunUpScript;
|
||||||
assert pkgs.lib.hasInfix checkConstants.xrayGlobalTunIPv6Address xrayTunUpScript;
|
assert pkgs.lib.hasInfix checkConstants.xrayGlobalTunIPv6Address xrayTunUpScript;
|
||||||
assert pkgs.lib.hasInfix ''uplink_addr="$('' xrayTunUpScript;
|
|
||||||
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev singtun0'' xrayTunUpScript;
|
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev singtun0'' xrayTunUpScript;
|
||||||
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev singtun0'' xrayTunUpScript;
|
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev singtun0'' xrayTunUpScript;
|
||||||
assert pkgs.lib.hasInfix
|
assert pkgs.lib.hasInfix
|
||||||
''route replace "$tun_route_prefix" dev singtun0 src "$tun_addr" table ${toString checkConstants.tunAutoRouteTableIndex}''
|
''route replace "$tun_route_prefix" dev singtun0 src "$tun_addr" table ${toString checkConstants.tunAutoRouteTableIndex}''
|
||||||
xrayTunUpScript;
|
xrayTunUpScript;
|
||||||
assert pkgs.lib.hasInfix
|
assert pkgs.lib.hasInfix
|
||||||
''route replace default dev singtun0 src "$uplink_addr" table ${toString checkConstants.tunAutoRouteTableIndex}''
|
"-4 route replace default dev singtun0 table ${toString checkConstants.tunAutoRouteTableIndex}"
|
||||||
xrayTunUpScript;
|
xrayTunUpScript;
|
||||||
assert pkgs.lib.hasInfix
|
assert pkgs.lib.hasInfix
|
||||||
''-6 route replace "$tun6_route_prefix" dev singtun0 table ${toString checkConstants.tunAutoRouteTableIndex}''
|
''-6 route replace "$tun6_route_prefix" dev singtun0 table ${toString checkConstants.tunAutoRouteTableIndex}''
|
||||||
@@ -104,6 +99,33 @@
|
|||||||
assert pkgs.lib.hasInfix
|
assert pkgs.lib.hasInfix
|
||||||
"-6 rule add pref ${toString checkConstants.tunAutoRouteRulePriority} not fwmark 2 table ${toString checkConstants.tunAutoRouteTableIndex}"
|
"-6 rule add pref ${toString checkConstants.tunAutoRouteRulePriority} not fwmark 2 table ${toString checkConstants.tunAutoRouteTableIndex}"
|
||||||
xrayTunUpScript;
|
xrayTunUpScript;
|
||||||
|
assert pkgs.lib.hasInfix
|
||||||
|
''"$family" rule add pref ${toString checkConstants.xrayTunMarkBypassRulePriority} fwmark 2 lookup main''
|
||||||
|
xrayTunUpScript;
|
||||||
|
assert pkgs.lib.hasInfix
|
||||||
|
''"$family" rule add pref ${toString checkConstants.xrayTunDnsRulePriority} ipproto udp dport 53 table ${toString checkConstants.tunAutoRouteTableIndex}''
|
||||||
|
xrayTunUpScript;
|
||||||
|
assert pkgs.lib.hasInfix
|
||||||
|
''"$family" rule add pref ${toString checkConstants.xrayTunMainRulePriority} lookup main suppress_prefixlength 0''
|
||||||
|
xrayTunUpScript;
|
||||||
|
assert pkgs.lib.hasInfix "proxy-suite-xray-tun.nft" xrayTunUpScript;
|
||||||
|
assert pkgs.lib.hasInfix "delete table inet proxy_suite_xray_tun" xrayTunUpScript;
|
||||||
|
# No uplink src: it would go stale when the uplink address changes.
|
||||||
|
assert !(pkgs.lib.hasInfix "uplink_addr" xrayTunUpScript);
|
||||||
|
# Every rule the up script adds is flushed first, v4 and v6.
|
||||||
|
assert builtins.all (
|
||||||
|
priority:
|
||||||
|
pkgs.lib.hasInfix "-4 rule del pref ${toString priority}" xrayTunUpScript
|
||||||
|
&& pkgs.lib.hasInfix "-6 rule del pref ${toString priority}" xrayTunUpScript
|
||||||
|
) [
|
||||||
|
checkConstants.xrayTunMarkBypassRulePriority
|
||||||
|
checkConstants.xrayTunServiceUserRulePriority
|
||||||
|
checkConstants.xrayTunPerAppTproxyRulePriority
|
||||||
|
checkConstants.xrayTunPerAppTunRulePriority
|
||||||
|
checkConstants.xrayTunDnsRulePriority
|
||||||
|
checkConstants.xrayTunMainRulePriority
|
||||||
|
checkConstants.tunAutoRouteRulePriority
|
||||||
|
];
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -25,30 +25,27 @@
|
|||||||
"172.20.0.1/30"
|
"172.20.0.1/30"
|
||||||
checkConstants.xrayPerAppTunIPv6Address
|
checkConstants.xrayPerAppTunIPv6Address
|
||||||
];
|
];
|
||||||
assert builtins.length perAppTunInbound.settings.dns == 2;
|
|
||||||
assert perAppTunInbound.sniffing.destOverride == [ "fakedns" ];
|
assert perAppTunInbound.sniffing.destOverride == [ "fakedns" ];
|
||||||
assert perAppTunInbound.sniffing.metadataOnly == true;
|
assert perAppTunInbound.sniffing.metadataOnly == false;
|
||||||
assert xrayPerAppTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
assert xrayPerAppTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
||||||
assert (builtins.head xrayPerAppTunConfig.dns.servers).address == "fakedns";
|
assert (builtins.head xrayPerAppTunConfig.dns.servers).address == "fakedns";
|
||||||
assert xrayPerAppTunConfig.dns.tag == "dns-in";
|
assert xrayPerAppTunConfig.dns.tag == "dns-in";
|
||||||
assert builtins.length xrayPerAppTunConfig.fakedns == 2;
|
assert builtins.length xrayPerAppTunConfig.fakedns == 2;
|
||||||
assert perAppTunDirectOutbound.streamSettings.sockopt.mark == 2;
|
assert perAppTunDirectOutbound.streamSettings.sockopt.mark == 2;
|
||||||
assert pkgs.lib.hasInfix "XRAY_SINGLE_PROXY_TAG=" xrayPerAppTunStartScript;
|
assert pkgs.lib.hasInfix "XRAY_SINGLE_PROXY_TAG=" xrayPerAppTunStartScript;
|
||||||
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1" xrayPerAppTunStartScript;
|
|
||||||
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1 mark 2" xrayPerAppTunStartScript;
|
|
||||||
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayPerAppTunStartScript;
|
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayPerAppTunStartScript;
|
||||||
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayPerAppTunStartScript;
|
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayPerAppTunStartScript;
|
||||||
assert pkgs.lib.hasInfix "--routing-mark 2" xrayPerAppTunStartScript;
|
assert pkgs.lib.hasInfix "--routing-mark 2" xrayPerAppTunStartScript;
|
||||||
assert pkgs.lib.hasInfix "xray_tun_dns_runtime" xrayPerAppTunStartScript;
|
assert pkgs.lib.hasInfix "xray_tun_dns_runtime" xrayPerAppTunStartScript;
|
||||||
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayPerAppTunUpScript;
|
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayPerAppTunUpScript;
|
||||||
assert pkgs.lib.hasInfix checkConstants.xrayPerAppTunIPv6Address xrayPerAppTunUpScript;
|
assert pkgs.lib.hasInfix checkConstants.xrayPerAppTunIPv6Address xrayPerAppTunUpScript;
|
||||||
assert pkgs.lib.hasInfix ''uplink_addr="$('' xrayPerAppTunUpScript;
|
assert !(pkgs.lib.hasInfix "uplink_addr" xrayPerAppTunUpScript);
|
||||||
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
|
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
|
||||||
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
|
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
|
||||||
assert pkgs.lib.hasInfix
|
assert pkgs.lib.hasInfix
|
||||||
''route replace "$tun_route_prefix" dev psperapptun0 src "$tun_addr" table 101''
|
''route replace "$tun_route_prefix" dev psperapptun0 src "$tun_addr" table 101''
|
||||||
xrayPerAppTunUpScript;
|
xrayPerAppTunUpScript;
|
||||||
assert pkgs.lib.hasInfix ''route replace default dev psperapptun0 src "$uplink_addr" table 101''
|
assert pkgs.lib.hasInfix "-4 route replace default dev psperapptun0 table 101"
|
||||||
xrayPerAppTunUpScript;
|
xrayPerAppTunUpScript;
|
||||||
assert pkgs.lib.hasInfix ''-6 route replace "$tun6_route_prefix" dev psperapptun0 table 101''
|
assert pkgs.lib.hasInfix ''-6 route replace "$tun6_route_prefix" dev psperapptun0 table 101''
|
||||||
xrayPerAppTunUpScript;
|
xrayPerAppTunUpScript;
|
||||||
|
|||||||
Reference in new issue
Block a user