From 7354332daab56d43c3d3c296b4d03f6e8dbb2583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 17 Apr 2025 15:49:36 +0800 Subject: [PATCH] Fix missing handling of legacy `domain_strategy` options --- common/dialer/dialer.go | 40 +++++--- docs/configuration/shared/dial.md | 2 +- docs/configuration/shared/dial.zh.md | 4 + docs/migration.md | 55 +++++++++- docs/migration.zh.md | 146 ++++++++++++++++++--------- experimental/deprecated/constants.go | 14 +++ 6 files changed, 195 insertions(+), 66 deletions(-) diff --git a/common/dialer/dialer.go b/common/dialer/dialer.go index 7bf05d1b..7bf8ff02 100644 --- a/common/dialer/dialer.go +++ b/common/dialer/dialer.go @@ -83,6 +83,7 @@ func NewWithOptions(options Options) (N.Dialer, error) { dialOptions.DomainStrategy != option.DomainStrategy(C.DomainStrategyAsIS) { //nolint:staticcheck strategy = C.DomainStrategy(dialOptions.DomainStrategy) + deprecated.Report(options.Context, deprecated.OptionLegacyDomainStrategyOptions) } server = dialOptions.DomainResolver.Server dnsQueryOptions = adapter.DNSQueryOptions{ @@ -95,22 +96,31 @@ func NewWithOptions(options Options) (N.Dialer, error) { resolveFallbackDelay = time.Duration(dialOptions.FallbackDelay) } else if options.DirectResolver { return nil, E.New("missing domain resolver for domain server address") - } else if defaultOptions.DomainResolver != "" { - dnsQueryOptions = defaultOptions.DomainResolveOptions - transport, loaded := dnsTransport.Transport(defaultOptions.DomainResolver) - if !loaded { - return nil, E.New("default domain resolver not found: " + defaultOptions.DomainResolver) - } - dnsQueryOptions.Transport = transport - resolveFallbackDelay = time.Duration(dialOptions.FallbackDelay) } else { - transports := dnsTransport.Transports() - if len(transports) < 2 { - dnsQueryOptions.Transport = dnsTransport.Default() - } else if options.NewDialer { - return nil, E.New("missing domain resolver for domain server address") - } else if !options.DirectOutbound { - deprecated.Report(options.Context, deprecated.OptionMissingDomainResolver) + if defaultOptions.DomainResolver != "" { + dnsQueryOptions = defaultOptions.DomainResolveOptions + transport, loaded := dnsTransport.Transport(defaultOptions.DomainResolver) + if !loaded { + return nil, E.New("default domain resolver not found: " + defaultOptions.DomainResolver) + } + dnsQueryOptions.Transport = transport + resolveFallbackDelay = time.Duration(dialOptions.FallbackDelay) + } else { + transports := dnsTransport.Transports() + if len(transports) < 2 { + dnsQueryOptions.Transport = dnsTransport.Default() + } else if options.NewDialer { + return nil, E.New("missing domain resolver for domain server address") + } else if !options.DirectOutbound { + deprecated.Report(options.Context, deprecated.OptionMissingDomainResolver) + } + } + if + //nolint:staticcheck + dialOptions.DomainStrategy != option.DomainStrategy(C.DomainStrategyAsIS) { + //nolint:staticcheck + dnsQueryOptions.Strategy = C.DomainStrategy(dialOptions.DomainStrategy) + deprecated.Report(options.Context, deprecated.OptionLegacyDomainStrategyOptions) } } dialer = NewResolveDialer( diff --git a/docs/configuration/shared/dial.md b/docs/configuration/shared/dial.md index f7507531..97fbfce3 100644 --- a/docs/configuration/shared/dial.md +++ b/docs/configuration/shared/dial.md @@ -206,7 +206,7 @@ Only take effect when `domain_strategy` or `network_strategy` is set. !!! failure "Deprecated in sing-box 1.12.0" - `domain_strategy` is merged to [domain_resolver](#domain_resolver) in sing-box 1.12.0. + `domain_strategy` is deprecated and will be removed in sing-box 1.14.0, check [Migration](/migration/#migrate-outbound-domain-strategy-option-to-domain-resolver). Available values: `prefer_ipv4`, `prefer_ipv6`, `ipv4_only`, `ipv6_only`. diff --git a/docs/configuration/shared/dial.zh.md b/docs/configuration/shared/dial.zh.md index 5abd6ad9..292cdc7c 100644 --- a/docs/configuration/shared/dial.zh.md +++ b/docs/configuration/shared/dial.zh.md @@ -194,6 +194,10 @@ icon: material/new-box #### domain_strategy +!!! failure "已在 sing-box 1.12.0 废弃" + + `domain_strategy` 已废弃且将在 sing-box 1.14.0 中被移除,参阅 [迁移指南](/migration/#migrate-outbound-domain-strategy-option-to-domain-resolver)。 + 可选值:`prefer_ipv4` `prefer_ipv6` `ipv4_only` `ipv6_only`。 如果设置,域名将在请求发出之前解析为 IP。 diff --git a/docs/migration.md b/docs/migration.md index 895f48f1..ca50a70a 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -516,13 +516,13 @@ DNS servers are refactored for better performance and scalability. The legacy outbound DNS rules are deprecated and can be replaced by new domain resolver options. !!! info "References" - + [DNS rule](/configuration/dns/rule/#outbound) / [Dial Fields](/configuration/shared/dial/#domain_resolver) / [Route](/configuration/route/#domain_resolver) === ":material-card-remove: Deprecated" - + ```json { "dns": { @@ -586,6 +586,57 @@ The legacy outbound DNS rules are deprecated and can be replaced by new domain r } ``` +### Migrate outbound domain strategy option to domain resolver + +!!! info "References" + + [Dial Fields](/configuration/shared/dial/#domain_strategy) + +The `domain_strategy` option in Dial Fields has been deprecated and can be replaced with the new domain resolver option. + +Note that due to the use of Dial Fields by some of the new DNS servers introduced in sing-box 1.12, +some people mistakenly believe that `domain_strategy` is the same feature as in the legacy DNS servers. + +=== ":material-card-remove: Deprecated" + + ```json + { + "outbounds": [ + { + "type": "socks", + "server": "example.org", + "server_port": 2080, + "domain_strategy": "prefer_ipv4", + } + ] + } + ``` + +=== ":material-card-multiple: New" + + ```json + { + "dns": { + "servers": [ + { + "type": "local" + } + ] + }, + "outbounds": [ + { + "type": "socks", + "server": "example.org", + "server_port": 2080, + "domain_resolver": { + "server": "local", + "strategy": "prefer_ipv4" + } + } + ] + } + ``` + ## 1.11.0 ### Migrate legacy special outbounds to rule actions diff --git a/docs/migration.zh.md b/docs/migration.zh.md index f82f2521..a2779e23 100644 --- a/docs/migration.zh.md +++ b/docs/migration.zh.md @@ -16,7 +16,7 @@ DNS 服务器已经重构。 === "Local" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -28,9 +28,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -46,7 +46,7 @@ DNS 服务器已经重构。 === "TCP" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -58,9 +58,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -77,7 +77,7 @@ DNS 服务器已经重构。 === "UDP" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -89,9 +89,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -108,7 +108,7 @@ DNS 服务器已经重构。 === "TLS" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -120,9 +120,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -139,7 +139,7 @@ DNS 服务器已经重构。 === "HTTPS" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -151,9 +151,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -170,7 +170,7 @@ DNS 服务器已经重构。 === "QUIC" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -182,9 +182,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -201,7 +201,7 @@ DNS 服务器已经重构。 === "HTTP3" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -213,9 +213,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -232,7 +232,7 @@ DNS 服务器已经重构。 === "DHCP" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -247,9 +247,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -269,7 +269,7 @@ DNS 服务器已经重构。 === "FakeIP" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -299,9 +299,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -333,7 +333,7 @@ DNS 服务器已经重构。 === "RCode" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -345,9 +345,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -368,7 +368,7 @@ DNS 服务器已经重构。 === "带有域名地址的服务器" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -385,9 +385,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -410,7 +410,7 @@ DNS 服务器已经重构。 === "带有域策略的服务器" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -434,9 +434,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -466,7 +466,7 @@ DNS 服务器已经重构。 === "带有客户端子网的服务器" === ":material-card-remove: 弃用的" - + ```json { "dns": { @@ -483,9 +483,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "dns": { @@ -586,6 +586,56 @@ DNS 服务器已经重构。 } ``` +### 迁移出站域名策略选项到域名解析器 + +拨号字段中的 `domain_strategy` 选项已被弃用,可以用新的域名解析器选项替代。 + +请注意,由于 sing-box 1.12 中引入的一些新 DNS 服务器使用了拨号字段,一些人错误地认为 `domain_strategy` 与旧 DNS 服务器中的功能相同。 + +!!! info "参考" + + [拨号字段](/configuration/shared/dial/#domain_strategy) + +=== ":material-card-remove: 弃用的" + + ```json + { + "outbounds": [ + { + "type": "socks", + "server": "example.org", + "server_port": 2080, + "domain_strategy": "prefer_ipv4", + } + ] + } + ``` + +=== ":material-card-multiple: 新的" + + ```json + { + "dns": { + "servers": [ + { + "type": "local" + } + ] + }, + "outbounds": [ + { + "type": "socks", + "server": "example.org", + "server_port": 2080, + "domain_resolver": { + "server": "local", + "strategy": "prefer_ipv4" + } + } + ] + } + ``` + ## 1.11.0 ### 迁移旧的特殊出站到规则动作 @@ -601,7 +651,7 @@ DNS 服务器已经重构。 === "Block" === ":material-card-remove: 弃用的" - + ```json { "outbounds": [ @@ -614,7 +664,7 @@ DNS 服务器已经重构。 "rules": [ { ..., - + "outbound": "block" } ] @@ -623,14 +673,14 @@ DNS 服务器已经重构。 ``` === ":material-card-multiple: 新的" - + ```json { "route": { "rules": [ { ..., - + "action": "reject" } ] @@ -641,13 +691,13 @@ DNS 服务器已经重构。 === "DNS" === ":material-card-remove: 弃用的" - + ```json { "inbound": [ { ..., - + "sniff": true } ], @@ -667,9 +717,9 @@ DNS 服务器已经重构。 } } ``` - + === ":material-card-multiple: 新的" - + ```json { "route": { @@ -1133,4 +1183,4 @@ sing-box 1.9.0 使 QueryFullProcessImageNameW 输出 Win32 路径(如 `C:\fold } } } - ``` \ No newline at end of file + ``` diff --git a/experimental/deprecated/constants.go b/experimental/deprecated/constants.go index 16216716..5dfdfd47 100644 --- a/experimental/deprecated/constants.go +++ b/experimental/deprecated/constants.go @@ -161,6 +161,7 @@ var OptionLegacyDNSFakeIPOptions = Note{ Description: "legacy DNS fakeip options", DeprecatedVersion: "1.12.0", ScheduledVersion: "1.14.0", + EnvName: "LEGACY_DNS_FAKEIP_OPTIONS", MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-to-new-dns-server-formats", } @@ -169,6 +170,7 @@ var OptionOutboundDNSRuleItem = Note{ Description: "outbound DNS rule item", DeprecatedVersion: "1.12.0", ScheduledVersion: "1.14.0", + EnvName: "OUTBOUND_DNS_RULE_ITEM", MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver", } @@ -177,6 +179,7 @@ var OptionMissingDomainResolver = Note{ Description: "missing `route.default_domain_resolver` or `domain_resolver` in dial fields", DeprecatedVersion: "1.12.0", ScheduledVersion: "1.14.0", + EnvName: "MISSING_DOMAIN_RESOLVER", MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver", } @@ -185,9 +188,19 @@ var OptionLegacyECHOptions = Note{ Description: "legacy ECH options", DeprecatedVersion: "1.12.0", ScheduledVersion: "1.13.0", + EnvName: "LEGACY_ECH_OPTIONS", MigrationLink: "https://sing-box.sagernet.org/deprecated/#legacy-ech-fields", } +var OptionLegacyDomainStrategyOptions = Note{ + Name: "legacy-domain-strategy-options", + Description: "legacy domain strategy options", + DeprecatedVersion: "1.12.0", + ScheduledVersion: "1.14.0", + EnvName: "LEGACY_DOMAIN_STRATEGY_OPTIONS", + MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-domain-strategy-options", +} + var Options = []Note{ OptionBadMatchSource, OptionGEOIP, @@ -204,4 +217,5 @@ var Options = []Note{ OptionOutboundDNSRuleItem, OptionMissingDomainResolver, OptionLegacyECHOptions, + OptionLegacyDomainStrategyOptions, }