Skip to content

Commit

Permalink
Fix bug in swapAB (#417)
Browse files Browse the repository at this point in the history
Swap hashA and hashB when swapAB is flagged
  • Loading branch information
ronensc committed Mar 30, 2023
1 parent 1410840 commit 93fe348
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/pipeline/extract/conntrack/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ func NewConnBuilder(metrics *metricsType) *connBuilder {
}

func (cb *connBuilder) Hash(h totalHashType) *connBuilder {
if cb.shouldSwapAB {
h.hashA, h.hashB = h.hashB, h.hashA
}
cb.conn.hash = h
return cb
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/extract/conntrack/conntrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func (ct *conntrackImpl) Extract(flowLogs []config.GenericMap) []config.GenericM
} else {
builder := NewConnBuilder(ct.metrics)
conn = builder.
Hash(computedHash).
ShouldSwapAB(ct.config.TCPFlags.SwapAB && ct.shouldSwapAB(fl)).
KeysFrom(fl, ct.config.KeyDefinition, ct.endpointAFields, ct.endpointBFields).
Aggregators(ct.aggregators).
Hash(computedHash).
Build()
ct.connStore.addConnection(computedHash.hashTotal, conn)
ct.connStore.updateNextHeartbeatTime(computedHash.hashTotal)
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/extract/conntrack/conntrack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ func TestSwapAB(t *testing.T) {
startTime.Add(0 * time.Second),
[]config.GenericMap{flTCP1},
[]config.GenericMap{
newMockRecordNewConnAB(ipA, portA, ipB, portB, protocolTCP, 111, 0, 11, 0, 1).withHash(hashIdTCP).markFirst().get(),
newMockRecordNewConnAB(ipA, portA, ipB, portB, protocolTCP, 0, 111, 0, 11, 1).withHash(hashIdTCP).markFirst().get(),
},
},
}
Expand Down

0 comments on commit 93fe348

Please sign in to comment.