Skip to content

Commit

Permalink
fix: 去除controller中更新DNS的接口 and 修复localDNS retry流量为本地DNS时dial为空的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyiguang committed Feb 16, 2023
1 parent c97fdb7 commit 7a1c4d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
11 changes: 5 additions & 6 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package controller
import (
"context"
"fmt"
"github.com/Dreamacro/clash/hub/executor"
"io"
"time"

Expand Down Expand Up @@ -90,11 +89,11 @@ func UpdateRules(params []config.RuleConfig) error {

// UpdateDNS 更新DNS (切记更新DNS只能在初始化的时候做,正式使用时禁止使用否在可能会崩溃)
func UpdateDNS(params config.RawDNS) error {
DNS, err := config.ParseDNSByRawDNS(params)
if err != nil {
return err
}
executor.UpdateDNS(DNS)
//DNS, err := config.ParseDNSByRawDNS(params)
//if err != nil {
// return err
//}
//executor.UpdateDNS(DNS)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions hub/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
updateHosts(cfg.Hosts)
updateProfile(cfg)
updateGeneral(cfg.General, force)
UpdateDNS(cfg.DNS)
updateDNS(cfg.DNS)
updateExperimental(cfg)

SetOtherInbounds(cfg.Inbounds)
Expand Down Expand Up @@ -111,7 +111,7 @@ func GetGeneral() *config.General {

func updateExperimental(c *config.Config) {}

func UpdateDNS(c *config.DNS) {
func updateDNS(c *config.DNS) {
if !c.Enable {
resolver.DefaultResolver = nil
resolver.DefaultHostMapper = nil
Expand Down
16 changes: 9 additions & 7 deletions tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,15 @@ func UpdateOutboundGroup(param outboundgroup.GroupCommonOption) error {
}

func localDNSMetadata(metadata *C.Metadata) *C.Metadata {
ip, err := resolver.ResolveIP(metadata.Host)
if err != nil {
log.Debugln("[DNS] resolve %s error: %s", metadata.Host, err.Error())
} else {
log.Debugln("[DNS] %s --> %s", metadata.Host, ip.String())
metadata.DstIP = ip
metadata.Host = ip.String()
if metadata.Host != "" {
ip, err := resolver.ResolveIP(metadata.Host)
if err != nil {
log.Debugln("[DNS] resolve %s error: %s", metadata.Host, err.Error())
} else {
log.Debugln("[DNS] %s --> %s", metadata.Host, ip.String())
metadata.DstIP = ip
metadata.Host = ip.String()
}
}
return metadata
}

0 comments on commit 7a1c4d5

Please sign in to comment.