Skip to content

Commit

Permalink
Strict domain strategy.
Browse files Browse the repository at this point in the history
  • Loading branch information
bia-pain-bache committed Nov 5, 2024
1 parent 36cf3db commit 5455689
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/cores-configs/clash.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ const clashConfigTemp = {
"strict-route": true,
"auto-detect-interface": true,
"dns-hijack": ["any:53"],
"include-android-user": [ 0, 10, 999 ],
"mtu": 9000
},
"sniffer": {
Expand Down
5 changes: 3 additions & 2 deletions src/cores-configs/sing-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ function buildSingBoxWarpOutbound (proxySettings, warpConfigs, remark, endpoint,
return outbound;
}

function buildSingBoxChainOutbound (chainProxyParams) {
function buildSingBoxChainOutbound (chainProxyParams, enableIPv6) {
if (["socks", "http"].includes(chainProxyParams.protocol)) {
const { protocol, host, port, user, pass } = chainProxyParams;

Expand All @@ -452,6 +452,7 @@ function buildSingBoxChainOutbound (chainProxyParams) {
tag: "",
server: hostName,
server_port: +port,
domain_strategy: enableIPv6 ? "prefer_ipv4" : "ipv4_only",
uuid: uuid,
flow: flow,
detour: ""
Expand Down Expand Up @@ -584,7 +585,7 @@ export async function getSingBoxCustomConfig(request, env, isFragment) {
if (outProxy) {
const proxyParams = JSON.parse(outProxyParams);
try {
chainProxyOutbound = buildSingBoxChainOutbound(proxyParams);
chainProxyOutbound = buildSingBoxChainOutbound(proxyParams, enableIPv6);
} catch (error) {
console.log('An error occured while parsing chain proxy: ', error);
chainProxyOutbound = undefined;
Expand Down
15 changes: 9 additions & 6 deletions src/cores-configs/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function buildXrayRoutingRules (proxySettings, outboundAddrs, isChain, isBalance
return rules;
}

function buildXrayVLESSOutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure) {
function buildXrayVLESSOutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure, enableIPv6) {
let outbound = {
protocol: "vless",
settings: {
Expand Down Expand Up @@ -269,14 +269,15 @@ function buildXrayVLESSOutbound (tag, address, port, host, sni, proxyIP, isFragm
if (isFragment) {
outbound.streamSettings.sockopt.dialerProxy = "fragment";
} else {
outbound.streamSettings.sockopt.tcpKeepAliveIdle = 100;
outbound.streamSettings.sockopt.tcpKeepAliveIdle = 60;
outbound.streamSettings.sockopt.tcpNoDelay = true;
outbound.streamSettings.sockopt.domainStrategy = enableIPv6 ? "UseIPv4v6" : "UseIPv4";
}

return outbound;
}

function buildXrayTrojanOutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure) {
function buildXrayTrojanOutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure, enableIPv6) {
let outbound = {
protocol: "trojan",
settings: {
Expand Down Expand Up @@ -316,8 +317,9 @@ function buildXrayTrojanOutbound (tag, address, port, host, sni, proxyIP, isFrag
if (isFragment) {
outbound.streamSettings.sockopt.dialerProxy = "fragment";
} else {
outbound.streamSettings.sockopt.tcpKeepAliveIdle = 100;
outbound.streamSettings.sockopt.tcpKeepAliveIdle = 60;
outbound.streamSettings.sockopt.tcpNoDelay = true;
outbound.streamSettings.sockopt.domainStrategy = enableIPv6 ? "UseIPv4v6" : "UseIPv4";
}

return outbound;
Expand Down Expand Up @@ -572,6 +574,7 @@ function buildXrayConfig (proxySettings, remark, isFragment, isBalancer, isChain
fragment.length = `${lengthMin}-${lengthMax}`;
fragment.interval = `${intervalMin}-${intervalMax}`;
fragment.packets = fragmentPackets;
config.outbounds[0].settings.domainStrategy = enableIPv6 ? "UseIPv4v6" : "UseIPv4";
} else {
config.outbounds.shift();
}
Expand Down Expand Up @@ -702,8 +705,8 @@ export async function getXrayCustomConfigs(request, env, isFragment) {
customConfig.dns = await buildXrayDNS(proxySettings, [addr], undefined);
customConfig.routing.rules = buildXrayRoutingRules(proxySettings, [addr], chainProxy, false, false);
let outbound = protocol === 'VLESS'
? buildXrayVLESSOutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr)
: buildXrayTrojanOutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr);
? buildXrayVLESSOutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr, enableIPv6)
: buildXrayTrojanOutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr, enableIPv6);

customConfig.outbounds.unshift({...outbound});
outbound.tag = `prox-${proxyIndex}`;
Expand Down

0 comments on commit 5455689

Please sign in to comment.