fix: xray tun improvements
This commit is contained in:
13 files changed
+110
-159
No files matched your search
@@ -23,8 +23,6 @@ let
|
||||
inherit (fixtures)
|
||||
xrayBackendJqFilter
|
||||
xrayBackendJqFilterFile
|
||||
xrayDnsLocalClient
|
||||
xrayDnsRemoteClient
|
||||
xrayFixture
|
||||
xrayPerAppTunBackendJqFilterFile
|
||||
xrayPerAppTunCleanupScript
|
||||
@@ -62,27 +60,22 @@ let
|
||||
--arg dns_final "remote" \
|
||||
--argjson clear_dns_rules false \
|
||||
--arg xray_loglevel "" \
|
||||
--arg xray_bind_interface "eth0" \
|
||||
--arg xray_single_proxy_tag "proxy-suite-ob-primary" \
|
||||
--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} \
|
||||
"$input" > "$output"
|
||||
|
||||
jq -e \
|
||||
--arg remote ${pkgs.lib.escapeShellArg xrayDnsRemoteClient} \
|
||||
--arg local ${pkgs.lib.escapeShellArg xrayDnsLocalClient} \
|
||||
'
|
||||
type == "object"
|
||||
and (.dns.servers | length) >= 3
|
||||
and .dns.servers[0].tag == "fakedns"
|
||||
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-hijack")] | 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(.tag == "dns-out" and ((.streamSettings.sockopt.interface? // "") == ""))] | length) == 1
|
||||
and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns] | length) == 1
|
||||
and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns][0] == [$remote, $local])
|
||||
and ([.outbounds[] | select(.streamSettings.sockopt.interface?)] | length) == 0
|
||||
and ([.outbounds[] | select(.protocol == "freedom" or .tag == "proxy-suite-ob-primary") | .streamSettings.sockopt.domainStrategy] | all(. == "UseIPv4v6"))
|
||||
and ([.outbounds[] | select(.protocol == "dns") | .streamSettings.sockopt.domainStrategy?] | all(. == null))
|
||||
and ([.inbounds[] | select(.tag == "tun-in") | .settings | has("dns") or has("autoOutboundsInterface")] | any | not)
|
||||
and ((.routing | has("balancers")) | not)
|
||||
and ((has("observatory")) | not)
|
||||
' "$output" >/dev/null
|
||||
|
||||
@@ -85,8 +85,6 @@ let
|
||||
selectionMode = xrayFixture.config.services.proxy-suite.proxy.selection;
|
||||
};
|
||||
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" (
|
||||
builtins.toJSON xrayTunConfig
|
||||
);
|
||||
@@ -98,8 +96,6 @@ in
|
||||
inherit
|
||||
xrayBackendJqFilter
|
||||
xrayBackendJqFilterFile
|
||||
xrayDnsLocalClient
|
||||
xrayDnsRemoteClient
|
||||
xrayFixture
|
||||
xrayPerAppTunBackendJqFilterFile
|
||||
xrayPerAppTunCleanupScript
|
||||
|
||||
@@ -22,13 +22,11 @@
|
||||
!(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 "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 ".streamSettings.sockopt.interface = $interface" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "del(.routing.balancers)" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "del(.observatory)" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "xray_rewrite_proxy_rule" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ".protocol == \"dns\"" xrayBackendJqFilter;
|
||||
true
|
||||
)
|
||||
];
|
||||
|
||||
@@ -40,10 +40,8 @@
|
||||
"172.19.0.1/30"
|
||||
checkConstants.xrayGlobalTunIPv6Address
|
||||
];
|
||||
assert builtins.length tunInbound.settings.dns == 2;
|
||||
assert tunInbound.settings.autoOutboundsInterface == "auto";
|
||||
assert tunInbound.sniffing.destOverride == [ "fakedns" ];
|
||||
assert tunInbound.sniffing.metadataOnly == true;
|
||||
assert tunInbound.sniffing.metadataOnly == false;
|
||||
assert xrayTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
||||
assert tunHasFinalRuleTag;
|
||||
assert tunHasDirectGeositeRule;
|
||||
@@ -67,21 +65,18 @@
|
||||
assert tunDirectOutbound.streamSettings.sockopt.mark == 2;
|
||||
assert pkgs.lib.hasInfix "xray-loglevel" 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 ''-f "$BACKEND_JQ_FILTER"'' 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 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 ''-6 addr replace "$tun6_cidr" dev singtun0'' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
''route replace "$tun_route_prefix" dev singtun0 src "$tun_addr" table ${toString checkConstants.tunAutoRouteTableIndex}''
|
||||
xrayTunUpScript;
|
||||
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;
|
||||
assert pkgs.lib.hasInfix
|
||||
''-6 route replace "$tun6_route_prefix" dev singtun0 table ${toString checkConstants.tunAutoRouteTableIndex}''
|
||||
@@ -104,6 +99,33 @@
|
||||
assert pkgs.lib.hasInfix
|
||||
"-6 rule add pref ${toString checkConstants.tunAutoRouteRulePriority} not fwmark 2 table ${toString checkConstants.tunAutoRouteTableIndex}"
|
||||
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
|
||||
)
|
||||
];
|
||||
|
||||
@@ -25,30 +25,27 @@
|
||||
"172.20.0.1/30"
|
||||
checkConstants.xrayPerAppTunIPv6Address
|
||||
];
|
||||
assert builtins.length perAppTunInbound.settings.dns == 2;
|
||||
assert perAppTunInbound.sniffing.destOverride == [ "fakedns" ];
|
||||
assert perAppTunInbound.sniffing.metadataOnly == true;
|
||||
assert perAppTunInbound.sniffing.metadataOnly == false;
|
||||
assert xrayPerAppTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
||||
assert (builtins.head xrayPerAppTunConfig.dns.servers).address == "fakedns";
|
||||
assert xrayPerAppTunConfig.dns.tag == "dns-in";
|
||||
assert builtins.length xrayPerAppTunConfig.fakedns == 2;
|
||||
assert perAppTunDirectOutbound.streamSettings.sockopt.mark == 2;
|
||||
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 ''-f "$BACKEND_JQ_FILTER"'' xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "--routing-mark 2" 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 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 ''-6 addr replace "$tun6_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
''route replace "$tun_route_prefix" dev psperapptun0 src "$tun_addr" table 101''
|
||||
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;
|
||||
assert pkgs.lib.hasInfix ''-6 route replace "$tun6_route_prefix" dev psperapptun0 table 101''
|
||||
xrayPerAppTunUpScript;
|
||||
|
||||
Reference in new issue
Block a user