Skip to content

Commit

Permalink
feat(internal/bpf): enhance NetworkEvent with enums for direction and…
Browse files Browse the repository at this point in the history
… protocol
  • Loading branch information
nullswan committed Sep 22, 2024
1 parent 8f6749f commit 3750040
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
32 changes: 30 additions & 2 deletions internal/bpf/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ type NetworkEvent struct {
Sport uint16
Dport uint16

Direction uint8
Protocol uint8
Direction NetworkEventDirection
Protocol NetworkEventProtocol
}

type NetworkEventDirection uint8

const (
NetworkEventDirectionInbound NetworkEventDirection = 0
NetworkEventDirectionOutbound NetworkEventDirection = 1
)

func (d NetworkEventDirection) String() string {
if d == NetworkEventDirectionInbound {
return "inbound"
}
return "outbound"
}

type NetworkEventProtocol uint8

const (
NetworkEventProtocolTCP NetworkEventProtocol = 6
NetworkEventProtocolUDP NetworkEventProtocol = 17
)

func (p NetworkEventProtocol) String() string {
if p == NetworkEventProtocolTCP {
return "tcp"
}
return "udp"
}
4 changes: 3 additions & 1 deletion internal/bpf/event_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func ProcessNetworkEvent(
Debug("Received network event")
}

if event.Protocol == 17 && event.Direction == 1 && event.Dport == 53 {
if event.Protocol == NetworkEventProtocolUDP &&
event.Direction == NetworkEventDirectionOutbound &&
event.Dport == 53 {
metrics.DNSQueryCounter.WithLabelValues(container).Inc()
}

Expand Down

0 comments on commit 3750040

Please sign in to comment.