Skip to content

Commit 1f10618

Browse files
committed
Need to differentiate between cached dns response vs incomplete ones
Signed-off-by: Mohamed Mahmoud <[email protected]>
1 parent eedc708 commit 1f10618

9 files changed

+11
-12
lines changed

bpf/dns_tracker.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define DNS_QR_FLAG 0x8000
1010
#define UDP_MAXMSG 512
1111
#define EINVAL 22
12+
#define ENOENT 2
1213

1314
struct dns_header {
1415
u16 id;
@@ -66,6 +67,7 @@ static __always_inline u8 calc_dns_header_offset(pkt_info *pkt, void *data_end)
6667

6768
static __always_inline int track_dns_packet(struct __sk_buff *skb, pkt_info *pkt) {
6869
void *data_end = (void *)(long)skb->data_end;
70+
int ret = 0;
6971
if (pkt->id->dst_port == dns_port || pkt->id->src_port == dns_port) {
7072
dns_flow_id dns_req;
7173

@@ -75,7 +77,6 @@ static __always_inline int track_dns_packet(struct __sk_buff *skb, pkt_info *pkt
7577
}
7678

7779
struct dns_header dns;
78-
int ret;
7980
u32 dns_offset = (long)pkt->l4_hdr - (long)skb->data + len;
8081

8182
if ((ret = bpf_skb_load_bytes(skb, dns_offset, &dns, sizeof(dns))) < 0) {
@@ -97,12 +98,14 @@ static __always_inline int track_dns_packet(struct __sk_buff *skb, pkt_info *pkt
9798
if (value != NULL) {
9899
pkt->dns_latency = ts - *value;
99100
bpf_map_delete_elem(&dns_flows, &dns_req);
101+
} else {
102+
ret = ENOENT;
100103
}
101104
pkt->dns_id = dns_id;
102105
pkt->dns_flags = flags;
103106
} // end of dns response
104107
}
105-
return 0;
108+
return ret;
106109
}
107110

108111
#endif // __DNS_TRACKER_H__

pkg/decode/decode_protobuf.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,7 @@ func RecordToMap(fr *flow.Record) config.GenericMap {
120120
out["DnsId"] = dnsID
121121
out["DnsFlags"] = fr.Metrics.DnsRecord.Flags
122122
out["DnsFlagsResponseCode"] = DNSRcodeToStr(uint32(fr.Metrics.DnsRecord.Flags) & 0xF)
123-
if fr.Metrics.DnsRecord.Latency != 0 {
124-
out["DnsLatencyMs"] = fr.DNSLatency.Milliseconds()
125-
}
126-
// Not sure about the logic here, why erasing errno?
127-
out["DnsErrno"] = uint32(0)
123+
out["DnsLatencyMs"] = fr.DNSLatency.Milliseconds()
128124
}
129125
}
130126

pkg/decode/decode_protobuf_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestPBFlowToMap(t *testing.T) {
101101
"DnsId": uint16(1),
102102
"DnsFlags": uint16(0x80),
103103
"DnsFlagsResponseCode": "NoError",
104-
"DnsErrno": uint32(0),
104+
"DnsErrno": uint8(0),
105105
"TimeFlowRttNs": someDuration.Nanoseconds(),
106106
}, out)
107107

pkg/ebpf/bpf_arm64_bpfel.o

-48 Bytes
Binary file not shown.

pkg/ebpf/bpf_powerpc_bpfel.o

-56 Bytes
Binary file not shown.

pkg/ebpf/bpf_s390_bpfeb.o

-56 Bytes
Binary file not shown.

pkg/ebpf/bpf_x86_bpfel.o

-56 Bytes
Binary file not shown.

pkg/flow/deduper.go

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (c *deduperCache) checkDupe(r *Record, justMark, mergeDup bool, fwd *[]*Rec
8888
fEntry.dnsRecord.Flags = r.Metrics.DnsRecord.Flags
8989
fEntry.dnsRecord.Id = r.Metrics.DnsRecord.Id
9090
fEntry.dnsRecord.Latency = r.Metrics.DnsRecord.Latency
91+
fEntry.dnsRecord.Errno = r.Metrics.DnsRecord.Errno
9192
}
9293
// If the new flow has flowRTT then enrich the flow in the case with the same RTT and mark it duplicate
9394
if r.Metrics.FlowRtt != 0 && *fEntry.flowRTT == 0 {

pkg/flow/record.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ func Accumulate(r *ebpf.BpfFlowMetrics, src *ebpf.BpfFlowMetrics) {
106106
if src.DnsRecord.Id != 0 {
107107
r.DnsRecord.Id = src.DnsRecord.Id
108108
}
109+
if r.DnsRecord.Errno < src.DnsRecord.Errno {
110+
r.DnsRecord.Errno = src.DnsRecord.Errno
111+
}
109112
if r.DnsRecord.Latency < src.DnsRecord.Latency {
110113
r.DnsRecord.Latency = src.DnsRecord.Latency
111114
}
@@ -117,10 +120,6 @@ func Accumulate(r *ebpf.BpfFlowMetrics, src *ebpf.BpfFlowMetrics) {
117120
if src.Dscp != 0 {
118121
r.Dscp = src.Dscp
119122
}
120-
// Accumulate DNSErrno
121-
if src.DnsRecord.Errno != 0 {
122-
r.DnsRecord.Errno = src.DnsRecord.Errno
123-
}
124123
}
125124

126125
// IP returns the net.IP equivalent object

0 commit comments

Comments
 (0)