From 5bf106f25d3a6c89ca93a988a01d33172dc1ff03 Mon Sep 17 00:00:00 2001 From: Nova Date: Fri, 14 Feb 2025 13:18:36 +0330 Subject: [PATCH] fix rule order for sniff --- src/configs/ConfigBuilder.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/configs/ConfigBuilder.cpp b/src/configs/ConfigBuilder.cpp index a759bfb..bfa3655 100644 --- a/src/configs/ConfigBuilder.cpp +++ b/src/configs/ConfigBuilder.cpp @@ -365,6 +365,8 @@ namespace NekoGui { status->result->error = "Routing profile does not exist, try resetting the route profile in Routing Settings"; return; } + // copy for modification + routeChain = std::make_shared(*routeChain); // Inbounds // mixed-in @@ -425,12 +427,13 @@ namespace NekoGui { auto sniffRule = std::make_shared(); sniffRule->action = "sniff"; sniffRule->inbound = {"dns-in"}; - routeChain->Rules += sniffRule; auto redirRule = std::make_shared(); redirRule->action = "hijack-dns"; redirRule->inbound = {"dns-in"}; - routeChain->Rules += redirRule; + + routeChain->Rules.prepend(redirRule); + routeChain->Rules.prepend(sniffRule); } if (dataStore->enable_redirect && !status->forTest) { status->inbounds.prepend(QJsonObject{ @@ -443,7 +446,7 @@ namespace NekoGui { sniffRule->action = "sniff"; sniffRule->sniffOverrideDest = true; sniffRule->inbound = {"hijack"}; - routeChain->Rules += sniffRule; + routeChain->Rules.prepend(sniffRule); } // custom inbound @@ -476,7 +479,7 @@ namespace NekoGui { { sniffRule->sniffOverrideDest = true; } - routeChain->Rules += sniffRule; + routeChain->Rules.prepend(sniffRule); } auto neededOutbounds = routeChain->get_used_outbounds(); auto neededRuleSets = routeChain->get_used_rule_sets();