fix: DNS mapping error when sniffing result is ip, Discard sniffs that result in ip
This commit is contained in:
parent
d617b0f447
commit
7db07630a7
1 changed files with 10 additions and 3 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/Dreamacro/clash/constant/sniffer"
|
"github.com/Dreamacro/clash/constant/sniffer"
|
||||||
"net"
|
"net"
|
||||||
|
"net/netip"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -94,14 +95,14 @@ func (sd *SnifferDispatcher) Enable() bool {
|
||||||
func (sd *SnifferDispatcher) sniffDomain(conn *CN.BufferedConn, metadata *C.Metadata) (string, error) {
|
func (sd *SnifferDispatcher) sniffDomain(conn *CN.BufferedConn, metadata *C.Metadata) (string, error) {
|
||||||
for _, sniffer := range sd.sniffers {
|
for _, sniffer := range sd.sniffers {
|
||||||
if sniffer.SupportNetwork() == C.TCP {
|
if sniffer.SupportNetwork() == C.TCP {
|
||||||
conn.SetReadDeadline(time.Now().Add(3 * time.Second))
|
_ = conn.SetReadDeadline(time.Now().Add(3 * time.Second))
|
||||||
_, err := conn.Peek(1)
|
_, err := conn.Peek(1)
|
||||||
conn.SetReadDeadline(time.Time{})
|
_ = conn.SetReadDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, ok := err.(*net.OpError)
|
_, ok := err.(*net.OpError)
|
||||||
if ok {
|
if ok {
|
||||||
log.Errorln("[Sniffer] [%s] Maybe read timeout, Consider adding skip", metadata.DstIP.String())
|
log.Errorln("[Sniffer] [%s] Maybe read timeout, Consider adding skip", metadata.DstIP.String())
|
||||||
conn.Close()
|
_ = conn.Close()
|
||||||
}
|
}
|
||||||
log.Errorln("[Sniffer] %v", err)
|
log.Errorln("[Sniffer] %v", err)
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -120,6 +121,12 @@ func (sd *SnifferDispatcher) sniffDomain(conn *CN.BufferedConn, metadata *C.Meta
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = netip.ParseAddr(host)
|
||||||
|
if err == nil {
|
||||||
|
log.Debugln("[Sniffer] [%s] Sniff data failed %s", sniffer.Protocol(), metadata.DstIP)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
return host, nil
|
return host, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue