From 8a41dd31ae64d62a9194a45b4b740e8025db2a4a Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Jul 2024 11:02:28 +0330 Subject: [PATCH] feat: Use direct dns for direct domain rule-sets and fix rule preview --- db/ConfigBuilder.cpp | 11 ++++ db/RouteEntity.cpp | 12 ++++ db/RouteEntity.h | 2 + main/NekoGui.cpp | 5 -- main/NekoGui_DataStore.hpp | 3 - ui/dialog_manage_routes.ui | 130 ++++++++++++++++++------------------- ui/widget/RouteItem.cpp | 2 +- 7 files changed, 91 insertions(+), 74 deletions(-) diff --git a/db/ConfigBuilder.cpp b/db/ConfigBuilder.cpp index 002f0ad..496d973 100644 --- a/db/ConfigBuilder.cpp +++ b/db/ConfigBuilder.cpp @@ -580,6 +580,17 @@ namespace NekoGui { }; } + // Direct domains in rules + QJsonArray directDnsRuleSets; + auto sets = routeChain->get_direct_site_rule_sets(); + for (const auto &item: sets) { + directDnsRuleSets << item; + } + dnsRules += QJsonObject{ + {"rule_set", directDnsRuleSets}, + {"server", "dns-direct"}, + }; + // Underlying 100% Working DNS dnsServers += QJsonObject{ {"tag", "dns-local"}, diff --git a/db/RouteEntity.cpp b/db/RouteEntity.cpp index 8eeb3b7..07113b8 100644 --- a/db/RouteEntity.cpp +++ b/db/RouteEntity.cpp @@ -473,6 +473,18 @@ namespace NekoGui { return res; } + QStringList RoutingChain::get_direct_site_rule_sets() { + auto res = QStringList(); + for (const auto& item: Rules) { + if (item->outboundID == -2) { + for (const auto& rset: item->rule_set) { + if (rset.endsWith("_SITE")) res << rset; + } + } + } + return res; + } + RoutingChain::RoutingChain(const RoutingChain& other) : JsonStore(other) { id = other.id; name = QString(other.name); diff --git a/db/RouteEntity.h b/db/RouteEntity.h index cc47d7c..0f8bced 100644 --- a/db/RouteEntity.h +++ b/db/RouteEntity.h @@ -76,5 +76,7 @@ namespace NekoGui { std::shared_ptr> get_used_outbounds(); std::shared_ptr get_used_rule_sets(); + + QStringList get_direct_site_rule_sets(); }; } // namespace NekoGui \ No newline at end of file diff --git a/main/NekoGui.cpp b/main/NekoGui.cpp index 33e1f07..9c97a1e 100644 --- a/main/NekoGui.cpp +++ b/main/NekoGui.cpp @@ -295,16 +295,11 @@ namespace NekoGui { _add(new configItem("core_box_clash_listen_addr", &core_box_clash_listen_addr, itemType::string)); _add(new configItem("core_box_clash_api_secret", &core_box_clash_api_secret, itemType::string)); _add(new configItem("core_box_underlying_dns", &core_box_underlying_dns, itemType::string)); - _add(new configItem("core_ray_direct_dns", &core_ray_direct_dns, itemType::boolean)); - _add(new configItem("core_ray_freedom_domainStrategy", &core_ray_freedom_domainStrategy, itemType::string)); _add(new configItem("enable_gso", &enable_gso, itemType::boolean)); _add(new configItem("enable_ntp", &enable_ntp, itemType::boolean)); _add(new configItem("ntp_server_address", &ntp_server_address, itemType::string)); _add(new configItem("ntp_server_port", &ntp_server_port, itemType::integer)); _add(new configItem("ntp_interval", &ntp_interval, itemType::string)); -#ifdef Q_OS_WIN - _add(new configItem("core_ray_windows_disable_auto_interface", &core_ray_windows_disable_auto_interface, itemType::boolean)); -#endif } void DataStore::UpdateStartedId(int id) { diff --git a/main/NekoGui_DataStore.hpp b/main/NekoGui_DataStore.hpp index b5b7dbe..9335005 100644 --- a/main/NekoGui_DataStore.hpp +++ b/main/NekoGui_DataStore.hpp @@ -160,9 +160,6 @@ namespace NekoGui { QString core_box_clash_listen_addr = "127.0.0.1"; QString core_box_clash_api_secret = ""; QString core_box_underlying_dns = ""; - bool core_ray_direct_dns = false; - bool core_ray_windows_disable_auto_interface = false; - QString core_ray_freedom_domainStrategy = ""; // Other Core ExtraCore *extraCore = new ExtraCore; diff --git a/ui/dialog_manage_routes.ui b/ui/dialog_manage_routes.ui index 9efc11e..392f1de 100644 --- a/ui/dialog_manage_routes.ui +++ b/ui/dialog_manage_routes.ui @@ -27,6 +27,63 @@ + + + + inbound.domain_strategy +when used, domain destinations are resolved to IP before routing. + + + Inbound Domain Strategy + + + + + + + outbound.domain_strategy +when set, domain destinations are resolved to IP before connect, +also if the connection cannot be established with the current address family (ipv4, ipv6), a fallback connection is created shortly after, with the other address family. + + + Outbound Domain Strategy + + + + + + + + + + + proxy + + + + + direct + + + + + + + + Sniffs the connections intial packet(s?) to identify the protocol and the SNI. Sniff result for destination also rewrites the destionation of the connection to the sniffed SNI. For more data on the sniffed protocol refer to the sing-box's documentation. + + + Sniffing Mode + + + + + + + false + + + @@ -46,28 +103,6 @@ - - - - Sniffs the connections intial packet(s?) to identify the protocol and the SNI. Sniff result for destination also rewrites the destionation of the connection to the sniffed SNI. For more data on the sniffed protocol refer to the sing-box's documentation. - - - Sniffing Mode - - - - - - - outbound.domain_strategy -when set, domain destinations are resolved to IP before connect, -also if the connection cannot be established with the current address family (ipv4, ipv6), a fallback connection is created shortly after, with the other address family. - - - Outbound Domain Strategy - - - @@ -75,48 +110,6 @@ also if the connection cannot be established with the current address family (ip - - - - Routing Profile - - - - - - - - - - false - - - - - - - inbound.domain_strategy -when used, domain destinations are resolved to IP before routing. - - - Inbound Domain Strategy - - - - - - - - proxy - - - - - direct - - - - @@ -127,6 +120,13 @@ when used, domain destinations are resolved to IP before routing. + + + + Routing Profile + + + @@ -442,7 +442,7 @@ For more information, see the document "Configuration/DNS". - QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/ui/widget/RouteItem.cpp b/ui/widget/RouteItem.cpp index 8211ec8..8e1a50f 100644 --- a/ui/widget/RouteItem.cpp +++ b/ui/widget/RouteItem.cpp @@ -118,7 +118,7 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptrrule_attr_text->hide(); ui->rule_attr_data->setTitle(""); ui->rule_attr_box->setEnabled(false); - ui->rule_preview->setEnabled(false); + ui->rule_preview->setReadOnly(true); updateRuleSection(); connect(ui->route_import_json, &QPushButton::clicked, this, [=] {