From 192d769f7587f333a3a0798e2f121be441a95c16 Mon Sep 17 00:00:00 2001 From: tnextday Date: Thu, 16 Jan 2025 10:17:32 +0800 Subject: [PATCH] chore: ensure forced domains are always sniffed (#1793) When a domain matches forceDomain: - SkipList is not checked - Failed attempts are not cached - Sniffing is attempted every time This ensures forced domains are always sniffed regardless of previous failures. --- component/sniffer/dispatcher.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/component/sniffer/dispatcher.go b/component/sniffer/dispatcher.go index ada43176..5d457cf1 100644 --- a/component/sniffer/dispatcher.go +++ b/component/sniffer/dispatcher.go @@ -48,6 +48,10 @@ func (sd *Dispatcher) shouldOverride(metadata *C.Metadata) bool { if metadata.DNSMode == C.DNSMapping && sd.forceDnsMapping { return true } + return sd.forceSniff(metadata) +} + +func (sd *Dispatcher) forceSniff(metadata *C.Metadata) bool { for _, matcher := range sd.forceDomain { if matcher.MatchDomain(metadata.Host) { return true @@ -98,16 +102,21 @@ func (sd *Dispatcher) TCPSniff(conn *N.BufferedConn, metadata *C.Metadata) bool if !inWhitelist { return false } + forceSniffer := sd.forceSniff(metadata) dst := metadata.AddrPort() - if count, ok := sd.skipList.Get(dst); ok && count > 5 { - log.Debugln("[Sniffer] Skip sniffing[%s] due to multiple failures", dst) - return false + if !forceSniffer { + if count, ok := sd.skipList.Get(dst); ok && count > 5 { + log.Debugln("[Sniffer] Skip sniffing[%s] due to multiple failures", dst) + return false + } } host, err := sd.sniffDomain(conn, metadata) if err != nil { - sd.cacheSniffFailed(metadata) + if !forceSniffer { + sd.cacheSniffFailed(metadata) + } log.Debugln("[Sniffer] All sniffing sniff failed with from [%s:%d] to [%s:%d]", metadata.SrcIP, metadata.SrcPort, metadata.String(), metadata.DstPort) return false }