mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
refactor: remove dns and tun relationship, the enabled of dns module should be decided by user
This commit is contained in:
parent
2aad9818e8
commit
9d8cd036ff
16
dns/patch.go
16
dns/patch.go
|
@ -1,16 +0,0 @@
|
||||||
package dns
|
|
||||||
|
|
||||||
import D "github.com/miekg/dns"
|
|
||||||
|
|
||||||
type LocalServer struct {
|
|
||||||
handler handler
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServeMsg implement resolver.LocalServer ResolveMsg
|
|
||||||
func (s *LocalServer) ServeMsg(msg *D.Msg) (*D.Msg, error) {
|
|
||||||
return handlerWithContext(s.handler, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewLocalServer(resolver *Resolver, mapper *ResolverEnhancer) *LocalServer {
|
|
||||||
return &LocalServer{handler: NewHandler(resolver, mapper)}
|
|
||||||
}
|
|
|
@ -76,7 +76,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||||
updateProxies(cfg.Proxies, cfg.Providers)
|
updateProxies(cfg.Proxies, cfg.Providers)
|
||||||
updateRules(cfg.Rules, cfg.RuleProviders)
|
updateRules(cfg.Rules, cfg.RuleProviders)
|
||||||
updateSniffer(cfg.Sniffer)
|
updateSniffer(cfg.Sniffer)
|
||||||
updateDNS(cfg.DNS, cfg.Tun)
|
updateDNS(cfg.DNS)
|
||||||
updateGeneral(cfg.General, force)
|
updateGeneral(cfg.General, force)
|
||||||
updateIPTables(cfg)
|
updateIPTables(cfg)
|
||||||
updateTun(cfg.Tun, cfg.DNS)
|
updateTun(cfg.Tun, cfg.DNS)
|
||||||
|
@ -118,7 +118,14 @@ func GetGeneral() *config.General {
|
||||||
|
|
||||||
func updateExperimental(c *config.Config) {}
|
func updateExperimental(c *config.Config) {}
|
||||||
|
|
||||||
func updateDNS(c *config.DNS, t *config.Tun) {
|
func updateDNS(c *config.DNS) {
|
||||||
|
if !c.Enable {
|
||||||
|
resolver.DefaultResolver = nil
|
||||||
|
resolver.DefaultHostMapper = nil
|
||||||
|
dns.ReCreateServer("", nil, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
cfg := dns.Config{
|
cfg := dns.Config{
|
||||||
Main: c.NameServer,
|
Main: c.NameServer,
|
||||||
Fallback: c.Fallback,
|
Fallback: c.Fallback,
|
||||||
|
@ -156,22 +163,7 @@ func updateDNS(c *config.DNS, t *config.Tun) {
|
||||||
resolver.ProxyServerHostResolver = pr
|
resolver.ProxyServerHostResolver = pr
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.Enable {
|
|
||||||
resolver.DefaultLocalServer = dns.NewLocalServer(r, m)
|
|
||||||
log.Infoln("DNS enable IPv6 resolve")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Enable {
|
|
||||||
dns.ReCreateServer(c.Listen, r, m)
|
dns.ReCreateServer(c.Listen, r, m)
|
||||||
} else {
|
|
||||||
if !t.Enable {
|
|
||||||
resolver.DefaultResolver = nil
|
|
||||||
resolver.DefaultHostMapper = nil
|
|
||||||
resolver.DefaultLocalServer = nil
|
|
||||||
resolver.ProxyServerHostResolver = nil
|
|
||||||
}
|
|
||||||
dns.ReCreateServer("", nil, nil)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateHosts(tree *trie.DomainTrie[netip.Addr]) {
|
func updateHosts(tree *trie.DomainTrie[netip.Addr]) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user