fix: eliminate stale verdict poisoning, memory leaks, data races, and per-packet allocations in engine
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
@@ -9,8 +8,6 @@ import (
|
||||
"git.difuse.io/Difuse/Mellaris/ruleset"
|
||||
|
||||
"github.com/bwmarrin/snowflake"
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
||||
type countingRuleset struct {
|
||||
@@ -54,17 +51,17 @@ func TestUDPStreamManagerRebindsByTupleInO1Path(t *testing.T) {
|
||||
t.Fatalf("new manager: %v", err)
|
||||
}
|
||||
|
||||
ipFlow := gopacket.NewFlow(layers.EndpointIPv4, net.IPv4(10, 0, 0, 1).To4(), net.IPv4(10, 0, 0, 2).To4())
|
||||
udp := &layers.UDP{SrcPort: 50000, DstPort: 443, BaseLayer: layers.BaseLayer{Payload: []byte{0x01, 0x00, 0x00, 0x00}}}
|
||||
tuple := udpTupleKey{AIP: [16]byte{10, 0, 0, 1}, BIP: [16]byte{10, 0, 0, 2}, ALen: 4, BLen: 4, APort: 50000, BPort: 443}
|
||||
payload := []byte{0x01, 0x00, 0x00, 0x00}
|
||||
|
||||
ctx1 := &udpContext{Verdict: udpVerdictAccept}
|
||||
mgr.MatchWithContext(100, ipFlow, udp, ctx1)
|
||||
mgr.MatchWithContext(100, tuple, false, payload, ctx1)
|
||||
if got := newCalls.Load(); got != 1 {
|
||||
t.Fatalf("new stream calls=%d want=1", got)
|
||||
}
|
||||
|
||||
ctx2 := &udpContext{Verdict: udpVerdictAccept}
|
||||
mgr.MatchWithContext(200, ipFlow, udp, ctx2)
|
||||
mgr.MatchWithContext(200, tuple, false, payload, ctx2)
|
||||
if got := newCalls.Load(); got != 1 {
|
||||
t.Fatalf("expected stream reuse by tuple, new stream calls=%d want=1", got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user