diff --git a/go.mod b/go.mod index 702a198..df42e0c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.0 toolchain go1.22.5 -replace github.com/Dreamacro/clash v1.18.0 => github.com/igoogolx/clash v1.19.11 +replace github.com/Dreamacro/clash v1.18.0 => github.com/igoogolx/clash v1.19.12 require ( github.com/Dreamacro/clash v1.18.0 @@ -46,7 +46,7 @@ require ( github.com/go-stack/stack v1.8.1 // indirect github.com/google/btree v1.1.3 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/insomniacslk/dhcp v0.0.0-20241219180459-a662cc47d412 // indirect + github.com/insomniacslk/dhcp v0.0.0-20241224095048-b56fa0d5f25d // indirect github.com/josharian/native v1.1.0 // indirect github.com/mdlayher/netlink v1.7.2 // indirect github.com/mdlayher/socket v0.5.1 // indirect diff --git a/go.sum b/go.sum index bad96b9..588f7b9 100644 --- a/go.sum +++ b/go.sum @@ -60,12 +60,12 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/igoogolx/clash v1.19.11 h1:D80keITYMSzkptYNm1Q8U1BrUxyKpyt9k0ZnxvlpKl4= -github.com/igoogolx/clash v1.19.11/go.mod h1:mcr/HVUlxi5S7oHQjxmG+WabMIGx/IUl1YWTkiOirVc= +github.com/igoogolx/clash v1.19.12 h1:u1WaxmBwDplm4bcuaLaVAs9r6HAN/58iz4qsuSOXCxE= +github.com/igoogolx/clash v1.19.12/go.mod h1:NUvOLI+cnhLGoYPrwOd5gQoKiJVO0/8V41nWx0EUBqs= github.com/igoogolx/sysproxy v1.0.5 h1:bR3ThpCLAo2/hJdUO3V6nsEEYdBS+yaIK4o6ezjXiVM= github.com/igoogolx/sysproxy v1.0.5/go.mod h1:Ivr0fT7jxcG4mfruV+nNoW0IacTjENzztXcM4lQ91as= -github.com/insomniacslk/dhcp v0.0.0-20241219180459-a662cc47d412 h1:Gpj5alZpJhmJYx8Gljb+SxScp5+smvPA9SmajG4RenY= -github.com/insomniacslk/dhcp v0.0.0-20241219180459-a662cc47d412/go.mod h1:VvGYjkZoJyKqlmT1yzakUs4mfKMNB0XdODP0+rdml6k= +github.com/insomniacslk/dhcp v0.0.0-20241224095048-b56fa0d5f25d h1:VkCNWh6tuQLgDBc6KrUOz/L1mCUQGnR1Ujj8uTgpwwk= +github.com/insomniacslk/dhcp v0.0.0-20241224095048-b56fa0d5f25d/go.mod h1:VvGYjkZoJyKqlmT1yzakUs4mfKMNB0XdODP0+rdml6k= github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA= github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= diff --git a/internal/cfg/distribution/dns.go b/internal/cfg/distribution/dns.go index 5bd286c..0e9f1aa 100644 --- a/internal/cfg/distribution/dns.go +++ b/internal/cfg/distribution/dns.go @@ -15,7 +15,11 @@ func NewDnsDistribution( defaultInterfaceName string, disableCache bool, ) (DnsDistribution, error) { + var err error + dd := DnsDistribution{} + + //Boost var bootDnsServers []string for _, server := range bootDns { bootDnsServers = append(bootDnsServers, server+"#"+defaultInterfaceName) @@ -26,9 +30,15 @@ func NewDnsDistribution( if err != nil { return DnsDistribution{}, err } + dd.Boost = SubDnsDistribution{ + Client: boostDnsClient, + Addresses: bootDnsServers, + } + + //Local var localDnsServers []string - for _, server := range bootDns { - localDnsServers = append(localDns, server+"#"+defaultInterfaceName) + for _, server := range localDns { + localDnsServers = append(localDnsServers, server+"#"+defaultInterfaceName) } localDnsClient, err := resolver.New(localDnsServers, defaultInterfaceName, func() (C.Proxy, error) { return conn.GetProxy(constants.PolicyDirect) @@ -36,12 +46,12 @@ func NewDnsDistribution( if err != nil { return DnsDistribution{}, err } - dd := DnsDistribution{} dd.Local = SubDnsDistribution{ Addresses: localDnsServers, Client: localDnsClient, } + //Remote remoteDnsClient, err := resolver.New(remoteDns, defaultInterfaceName, func() (C.Proxy, error) { return conn.GetProxy(constants.PolicyProxy) }, disableCache) @@ -53,11 +63,6 @@ func NewDnsDistribution( Addresses: remoteDns, } - dd.Boost = SubDnsDistribution{ - Client: boostDnsClient, - Addresses: bootDnsServers, - } - cResolver.DefaultResolver = boostDnsClient return dd, nil } diff --git a/internal/dns/client.go b/internal/dns/client.go index b4e7634..f28b0f7 100644 --- a/internal/dns/client.go +++ b/internal/dns/client.go @@ -31,16 +31,27 @@ type Conn interface { WriteTo([]byte, net.Addr) (int, error) } -func getDnsQuestion(msg *D.Msg) (string, string, error) { +func handleMsgWithEmptyAnswer(r *D.Msg) *D.Msg { + msg := &D.Msg{} + msg.Answer = []D.RR{} + + msg.SetRcode(r, D.RcodeSuccess) + msg.Authoritative = true + msg.RecursionAvailable = true + + return msg +} + +func getDnsQuestion(msg *D.Msg) (string, uint16, error) { if len(msg.Question) == 0 { - return "", "", fmt.Errorf("no dns question") + return "", D.TypeNone, fmt.Errorf("no dns question") } name := msg.Question[0].Name if strings.HasSuffix(name, ".") { name = name[:len(name)-1] } qType := msg.Question[0].Qtype - return name, D.TypeToString[qType], nil + return name, qType, nil } func getResponseIp(msg *D.Msg) []net.IP { @@ -96,6 +107,12 @@ func Handle(dnsMessage *D.Msg, metadata *constant.Metadata) (*D.Msg, error) { if err != nil { return nil, fmt.Errorf("invalid dns question, err: %v", err) } + + switch qType { + case D.TypeAAAA, D.TypeSVCB, D.TypeHTTPS: + return handleMsgWithEmptyAnswer(dnsMessage), nil + } + dnsRule, err := getDnsResovler(question, metadata) if err != nil { return nil, fmt.Errorf("fail to get dns resolver, err: %v, question: %v", err, question) @@ -114,6 +131,6 @@ func Handle(dnsMessage *D.Msg, metadata *constant.Metadata) (*D.Msg, error) { } } elapsed := time.Since(start).Milliseconds() - log.Infoln(log.FormatLog(log.DnsPrefix, "target: %v, type: %v, time: %v ms, result: %v"), question, qType, elapsed, resIps) + log.Infoln(log.FormatLog(log.DnsPrefix, "target: %v, type: %v, time: %v ms, result: %v"), question, D.TypeToString[qType], elapsed, resIps) return res, err }