Skip to content

Commit 4a553ba

Browse files
authored
Filter out local hostname queries (#13)
1 parent 830edae commit 4a553ba

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

dns.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"errors"
88
"fmt"
99
"log"
10+
"os"
11+
"strings"
1012
"time"
1113

1214
"github.com/cilium/ebpf/ringbuf"
@@ -65,6 +67,16 @@ func processUDPPackets(ctx context.Context, reader *ringbuf.Reader) {
6567
continue // Skip HINFO queries
6668
}
6769

70+
// Skip DNS queries for the current hostname
71+
if len(dnsLayer.Questions) > 0 {
72+
queryName := strings.TrimSuffix(string(dnsLayer.Questions[0].Name), ".")
73+
if hostname, err := os.Hostname(); err == nil {
74+
if strings.EqualFold(queryName, hostname) {
75+
continue // Skip queries for current hostname
76+
}
77+
}
78+
}
79+
6880
entry := statEntry{
6981
SrcPort: udpPktDetails.SrcPort,
7082
SrcIP: bytesToAddr(udpPktDetails.Srcip.In6U.U6Addr8),

0 commit comments

Comments
 (0)