From e6377f7ec958e07a33ffbc3881e223ec4b3b4b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 31 Mar 2026 15:47:29 +0800 Subject: [PATCH] fix: add missing EnvName, document Strategy invariant, improve rcode display - Add EnvName to four new deprecation constants so users can suppress warnings via ENABLE_DEPRECATED_* environment variables - Add comment explaining why applyDNSRouteOptions skips Strategy - Use dns.RcodeToString in DNSResponseRCodeItem.String() for readability - Remove redundant Fqdn(FqdnToDomain(domain)) round-trip --- dns/router.go | 5 ++++- experimental/deprecated/constants.go | 4 ++++ route/rule/rule_item_response_rcode.go | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dns/router.go b/dns/router.go index 0d0c9519d..e8f1e0f42 100644 --- a/dns/router.go +++ b/dns/router.go @@ -410,6 +410,9 @@ func (r *Router) matchDNS(ctx context.Context, rules []adapter.DNSRule, allowFak } func (r *Router) applyDNSRouteOptions(options *adapter.DNSQueryOptions, routeOptions R.RuleActionDNSRouteOptions) { + // Strategy is intentionally skipped here. A non-default DNS rule action strategy + // forces legacy mode via resolveLegacyDNSMode, so this path is only reachable + // when strategy remains at its default value. if routeOptions.DisableCache { options.DisableCache = true } @@ -658,7 +661,7 @@ func (r *Router) lookupWithRulesType(ctx context.Context, rules []adapter.DNSRul RecursionDesired: true, }, Question: []mDNS.Question{{ - Name: mDNS.Fqdn(FqdnToDomain(domain)), + Name: mDNS.Fqdn(domain), Qtype: qType, Qclass: mDNS.ClassINET, }}, diff --git a/experimental/deprecated/constants.go b/experimental/deprecated/constants.go index 81ed14e04..c9f507387 100644 --- a/experimental/deprecated/constants.go +++ b/experimental/deprecated/constants.go @@ -98,6 +98,7 @@ var OptionIPAcceptAny = Note{ Description: "`ip_accept_any` in DNS rules", DeprecatedVersion: "1.14.0", ScheduledVersion: "1.16.0", + EnvName: "DNS_RULE_IP_ACCEPT_ANY", MigrationLink: "https://sing-box.sagernet.org/configuration/dns/rule/", } @@ -106,6 +107,7 @@ var OptionRuleSetIPCIDRAcceptEmpty = Note{ Description: "`rule_set_ip_cidr_accept_empty` in DNS rules", DeprecatedVersion: "1.14.0", ScheduledVersion: "1.16.0", + EnvName: "DNS_RULE_RULE_SET_IP_CIDR_ACCEPT_EMPTY", MigrationLink: "https://sing-box.sagernet.org/configuration/dns/rule/", } @@ -114,6 +116,7 @@ var OptionLegacyDNSAddressFilter = Note{ Description: "legacy address filter DNS rule items", DeprecatedVersion: "1.14.0", ScheduledVersion: "1.16.0", + EnvName: "LEGACY_DNS_ADDRESS_FILTER", MigrationLink: "https://sing-box.sagernet.org/configuration/dns/rule/", } @@ -122,6 +125,7 @@ var OptionLegacyDNSRuleStrategy = Note{ Description: "`strategy` in DNS rule actions", DeprecatedVersion: "1.14.0", ScheduledVersion: "1.16.0", + EnvName: "LEGACY_DNS_RULE_STRATEGY", MigrationLink: "https://sing-box.sagernet.org/configuration/dns/rule_action/", } diff --git a/route/rule/rule_item_response_rcode.go b/route/rule/rule_item_response_rcode.go index ae2c62248..e416c1d77 100644 --- a/route/rule/rule_item_response_rcode.go +++ b/route/rule/rule_item_response_rcode.go @@ -1,6 +1,7 @@ package rule import ( + "github.com/miekg/dns" "github.com/sagernet/sing-box/adapter" F "github.com/sagernet/sing/common/format" ) @@ -20,5 +21,5 @@ func (r *DNSResponseRCodeItem) Match(metadata *adapter.InboundContext) bool { } func (r *DNSResponseRCodeItem) String() string { - return F.ToString("response_rcode=", r.rcode) + return F.ToString("response_rcode=", dns.RcodeToString[r.rcode]) }