Fix DNS upgrade

This commit is contained in:
世界 2025-07-18 21:45:48 +08:00
parent 72dbcd3ad4
commit 534cccce91
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4

View File

@ -180,7 +180,7 @@ func (o *DNSServerOptions) Upgrade(ctx context.Context) error {
options := o.Options.(*LegacyDNSServerOptions)
serverURL, _ := url.Parse(options.Address)
var serverType string
if serverURL.Scheme != "" {
if serverURL != nil && serverURL.Scheme != "" {
serverType = serverURL.Scheme
} else {
switch options.Address {
@ -217,7 +217,7 @@ func (o *DNSServerOptions) Upgrade(ctx context.Context) error {
o.Type = C.DNSTypeUDP
o.Options = &remoteOptions
var serverAddr M.Socksaddr
if serverURL.Scheme == "" {
if serverURL == nil || serverURL.Scheme == "" {
serverAddr = M.ParseSocksaddr(options.Address)
} else {
serverAddr = M.ParseSocksaddr(serverURL.Host)
@ -232,6 +232,9 @@ func (o *DNSServerOptions) Upgrade(ctx context.Context) error {
case C.DNSTypeTCP:
o.Type = C.DNSTypeTCP
o.Options = &remoteOptions
if serverURL == nil {
return E.New("invalid server address")
}
serverAddr := M.ParseSocksaddr(serverURL.Host)
if !serverAddr.IsValid() {
return E.New("invalid server address")
@ -242,6 +245,9 @@ func (o *DNSServerOptions) Upgrade(ctx context.Context) error {
}
case C.DNSTypeTLS, C.DNSTypeQUIC:
o.Type = serverType
if serverURL == nil {
return E.New("invalid server address")
}
serverAddr := M.ParseSocksaddr(serverURL.Host)
if !serverAddr.IsValid() {
return E.New("invalid server address")
@ -261,6 +267,9 @@ func (o *DNSServerOptions) Upgrade(ctx context.Context) error {
},
}
o.Options = &httpsOptions
if serverURL == nil {
return E.New("invalid server address")
}
serverAddr := M.ParseSocksaddr(serverURL.Host)
if !serverAddr.IsValid() {
return E.New("invalid server address")
@ -274,6 +283,9 @@ func (o *DNSServerOptions) Upgrade(ctx context.Context) error {
}
case "rcode":
var rcode int
if serverURL == nil {
return E.New("invalid server address")
}
switch serverURL.Host {
case "success":
rcode = dns.RcodeSuccess
@ -295,6 +307,9 @@ func (o *DNSServerOptions) Upgrade(ctx context.Context) error {
case C.DNSTypeDHCP:
o.Type = C.DNSTypeDHCP
dhcpOptions := DHCPDNSServerOptions{}
if serverURL == nil {
return E.New("invalid server address")
}
if serverURL.Host != "" && serverURL.Host != "auto" {
dhcpOptions.Interface = serverURL.Host
}