浏览代码

Make `domain_resolver` optional when only one DNS server is configured

世界 7 月之前
父节点
当前提交
566b97d5e5
共有 4 个文件被更改,包括 22 次插入2 次删除
  1. 6 1
      common/dialer/dialer.go
  2. 4 0
      docs/configuration/shared/dial.md
  3. 4 0
      docs/configuration/shared/dial.zh.md
  4. 8 1
      option/outbound.go

+ 6 - 1
common/dialer/dialer.go

@@ -104,7 +104,12 @@ func NewWithOptions(options Options) (N.Dialer, error) {
 		} else if options.NewDialer {
 			return nil, E.New("missing domain resolver for domain server address")
 		} else {
-			deprecated.Report(options.Context, deprecated.OptionMissingDomainResolver)
+			transports := dnsTransport.Transports()
+			if len(transports) < 2 {
+				dnsQueryOptions.Transport = dnsTransport.Default()
+			} else {
+				deprecated.Report(options.Context, deprecated.OptionMissingDomainResolver)
+			}
 		}
 		dialer = NewResolveDialer(
 			options.Context,

+ 4 - 0
docs/configuration/shared/dial.md

@@ -106,6 +106,10 @@ Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
 
     `outbound` DNS rule items are deprecated and will be removed in sing-box 1.14.0, so this item will be required for outbound/endpoints using domain name in server address since sing-box 1.14.0.
 
+!!! info ""
+
+    `domain_resolver` or `route.default_domain_resolver` is optional when only one DNS server is configured.
+
 Set domain resolver to use for resolving domain names.
 
 This option uses the same format as the [route DNS rule action](/configuration/dns/rule_action/#route) without the `action` field.

+ 4 - 0
docs/configuration/shared/dial.zh.md

@@ -105,6 +105,10 @@ icon: material/new-box
 
     `outbound` DNS 规则项已弃用,且将在 sing-box 1.14.0 中被移除。因此,从 sing-box 1.14.0 版本开始,所有在服务器地址中使用域名的出站/端点均需配置此项。
 
+!!! info ""
+
+    当只有一个 DNS 服务器已配置时,`domain_resolver` 或 `route.default_domain_resolver` 是可选的。 
+
 用于设置解析域名的域名解析器。
 
 此选项的格式与 [路由 DNS 规则动作](/configuration/dns/rule_action/#route) 相同,但不包含 `action` 字段。  

+ 8 - 1
option/outbound.go

@@ -116,7 +116,14 @@ func (o *DomainResolveOptions) UnmarshalJSON(bytes []byte) error {
 		o.Server = stringValue
 		return nil
 	}
-	return json.Unmarshal(bytes, (*_DomainResolveOptions)(o))
+	err = json.Unmarshal(bytes, (*_DomainResolveOptions)(o))
+	if err != nil {
+		return err
+	}
+	if o.Server == "" {
+		return E.New("empty domain_resolver.server")
+	}
+	return nil
 }
 
 func (o *DialerOptions) TakeDialerOptions() DialerOptions {