Skip to content

Commit

Permalink
fix: correctly assign the subtype value in flow for drop reason
Browse files Browse the repository at this point in the history
Signed-off-by: Anubhab Majumdar <[email protected]>
  • Loading branch information
anubhabMajumdar committed May 31, 2024
1 parent 316b8f8 commit 7249d8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/utils/flow_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ func AddDropReason(f *flow.Flow, meta *RetinaMetadata, dropReason uint32) {
meta.DropReason = DropReason(dropReason)

f.Verdict = flow.Verdict_DROPPED
f.EventType = &flow.CiliumEventType{
Type: int32(api.MessageTypeDrop),
SubType: int32(api.TraceToNetwork), // This is a drop event and direction is determined later.
}

// Set the drop reason.
// Retina drop reasons are different from the drop reasons available in flow library.
Expand All @@ -285,6 +281,11 @@ func AddDropReason(f *flow.Flow, meta *RetinaMetadata, dropReason uint32) {
default:
f.DropReasonDesc = flow.DropReason_DROP_REASON_UNKNOWN
}

f.EventType = &flow.CiliumEventType{
Type: int32(api.MessageTypeDrop),
SubType: int32(f.GetDropReasonDesc()), // This is the drop reason.
}
}

func DropReasonDescription(f *flow.Flow) string {
Expand Down
1 change: 1 addition & 0 deletions pkg/utils/utils_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func TestAddDropReason(t *testing.T) {
assert.Equal(t, f.DropReasonDesc, tc.expectedDesc)
assert.Equal(t, f.Verdict, flow.Verdict_DROPPED)
assert.NotNil(t, f.EventType.Type, 1)
assert.EqualValues(t, f.EventType.GetSubType(), int32(tc.expectedDesc))
assert.NotNil(t, DropReasonDescription(f), DropReason_name[int32(tc.dropReason)])
})
}
Expand Down

0 comments on commit 7249d8c

Please sign in to comment.