Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions internal/bpf/decode_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux

// Copyright 2026 Optiqor contributors
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -94,7 +96,7 @@ func TestDecodeTCPEvent(t *testing.T) {
SAddr: binary.BigEndian.Uint32([]byte{10, 0, 0, 1}),
DAddr: binary.BigEndian.Uint32([]byte{8, 8, 8, 8}),
SPort: 54321,
DPort: 443, // already in host byte order (BPF normalizes before writing)
DPort: 443,
EventType: TCPEventRTT,
RTTUs: 250,
}
Expand Down Expand Up @@ -489,20 +491,4 @@ func TestIsSyscallError(t *testing.T) {
}
}

func TestTCPEventPortByteOrder(t *testing.T) {
// Verify that ports in TCPEvent are host byte order.
// The BPF program applies bpf_ntohs() to dport before writing,
// so both fields should be readable directly without swapping.
e := TCPEvent{
SPort: 54321, // ephemeral source port, host order
DPort: 443, // HTTPS destination port, host order (not 47873)
}
if e.DPort == 0xBB01 { // 47873 = 443 byte-swapped
t.Error("DPort is in network byte order; expected host byte order after BPF normalization")
}
if e.DPort != 443 {
t.Errorf("DPort = %d, want 443", e.DPort)
}
}

var _ = net.IPv4(0, 0, 0, 0)
Loading