analyzer: make http3/quic handling more reliable
Some checks failed
Quality check / Static analysis (push) Has been cancelled
Quality check / Tests (push) Has been cancelled

This commit is contained in:
2026-02-11 15:44:26 +05:30
parent a6075db4ba
commit c3fe0ea16f

View File

@@ -131,6 +131,17 @@ func (m *udpStreamManager) MatchWithContext(streamID uint32, ipFlow gopacket.Flo
rev := false rev := false
value, ok := m.streams.Get(streamID) value, ok := m.streams.Get(streamID)
if !ok { if !ok {
// Fallback: conntrack IDs can change during early flow lifetime on some systems.
// Try to find an existing stream by 5-tuple before creating a new stream.
matchedKey, matchedValue, matchedRev, found := m.findByFlow(ipFlow, udp.TransportFlow())
if found {
value = matchedValue
rev = matchedRev
if matchedKey != streamID {
m.streams.Remove(matchedKey)
m.streams.Add(streamID, matchedValue)
}
} else {
// New stream // New stream
value = &udpStreamValue{ value = &udpStreamValue{
Stream: m.factory.New(ipFlow, udp.TransportFlow(), udp, uc), Stream: m.factory.New(ipFlow, udp.TransportFlow(), udp, uc),
@@ -138,6 +149,7 @@ func (m *udpStreamManager) MatchWithContext(streamID uint32, ipFlow gopacket.Flo
UDPFlow: udp.TransportFlow(), UDPFlow: udp.TransportFlow(),
} }
m.streams.Add(streamID, value) m.streams.Add(streamID, value)
}
} else { } else {
// Stream ID exists, but is it really the same stream? // Stream ID exists, but is it really the same stream?
ok, rev = value.Match(ipFlow, udp.TransportFlow()) ok, rev = value.Match(ipFlow, udp.TransportFlow())
@@ -157,6 +169,19 @@ func (m *udpStreamManager) MatchWithContext(streamID uint32, ipFlow gopacket.Flo
} }
} }
func (m *udpStreamManager) findByFlow(ipFlow, udpFlow gopacket.Flow) (key uint32, value *udpStreamValue, rev bool, found bool) {
for _, k := range m.streams.Keys() {
v, ok := m.streams.Peek(k)
if !ok || v == nil {
continue
}
if ok2, rev2 := v.Match(ipFlow, udpFlow); ok2 {
return k, v, rev2, true
}
}
return 0, nil, false, false
}
type udpStream struct { type udpStream struct {
info ruleset.StreamInfo info ruleset.StreamInfo
virgin bool // true if no packets have been processed virgin bool // true if no packets have been processed