Skip to content

Commit 5cbca2f

Browse files
committed
DNS Initial Support
1 parent 54cb7d2 commit 5cbca2f

File tree

11 files changed

+90
-63
lines changed

11 files changed

+90
-63
lines changed

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Using www.github.com/wtfbbqhax/krakatoa
2-
FROM arm64v8/krakatoa AS libpacket_dev_env
2+
FROM amd64/krakatoa AS libpacket_dev_env
33

44
USER root
55
RUN apk update
File renamed without changes.

piglet-bpf-filter/Makefile renamed to bin/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
piglet-bpf-filter: piglet-bpf-filter.cc daq_print.cc daq_print.h
3+
dns-hog: dns_hog.cc daq_print.cc daq_print.h
44
c++ -ggdb -std=c++14 -lstdc++ $^ -lpcap -ldaq -lpacket -o $@
55

66
clean:

piglet-bpf-filter/daq_print.cc renamed to bin/daq_print.cc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ int print_dns(dns const& dns)
3636
{
3737
bool is_response = DNS_QR(dns.h.flags);
3838

39-
if (is_response)
39+
//if (is_response)
4040
{
41-
printf("[dns response] [rcode:%d, id:%d, qdcount: %d, ancount: %d, nscount: %d, arcount:%d]\n",
41+
printf("[dns] [rcode:%d, id:%d, qdcount: %d, ancount: %d, nscount: %d, arcount:%d]\n",
4242
DNS_RCODE(dns.h.flags),
4343
dns.h.id,
4444
dns.h.qdcount,
4545
dns.h.ancount,
4646
dns.h.nscount,
4747
dns.h.arcount);
4848
}
49-
else
50-
{
51-
printf("[dns query] [id:%d, qdcount: %d]\n",
52-
dns.h.id,
53-
dns.h.qdcount);
54-
}
49+
//else
50+
//{
51+
// printf("[dns query] [id:%d, qdcount: %d]\n",
52+
// dns.h.id,
53+
// dns.h.qdcount);
54+
//}
5555

5656
// Parsing Question Section
5757
for (int i = 0; i < dns.h.qdcount; i++)
@@ -78,7 +78,11 @@ int print_dns(dns const& dns)
7878
{
7979
inet_ntop(AF_INET, a.data.data(), addr, sizeof(addr));
8080
human.append(addr, strnlen(addr, INET6_ADDRSTRLEN));
81-
81+
}
82+
else if (a.dns_atype == 28)
83+
{
84+
inet_ntop(AF_INET6, a.data.data(), addr, sizeof(addr));
85+
human.append(addr, strnlen(addr, INET6_ADDRSTRLEN));
8286
}
8387
else
8488
{
@@ -95,6 +99,7 @@ int print_dns(dns const& dns)
9599
// (void)dns[0].questions[i].dns_qclass;
96100
}
97101

102+
printf("\n");
98103
return 0;
99104
}
100105

@@ -179,21 +184,17 @@ print_packet(int const instance_id, DAQ_PktHdr_t const* hdr, uint8_t const * dat
179184
packet_frag_mf(&packet) ? "mf" : "");
180185
}
181186

187+
uint32_t max = packet_paysize(&packet);
188+
const uint8_t *payload = packet_payload(&packet);
182189
if (sport == 53 || dport == 53)
183190
{
184191
dns _dns;
185-
decode_dns(packet_payload(&packet),
186-
packet_paysize(&packet),
187-
&_dns);
192+
decode_dns(payload, max, &_dns);
188193
print_dns(_dns);
189194
}
190195

191-
uint32_t max = packet_paysize(&packet);
192-
const uint8_t *payload = packet_payload(&packet);
193196
max = max > 128 ? 128 : max;
194-
print_data(payload, max);
195-
196-
//print_data(data, len);
197+
//print_data(payload, max);
197198

198199
#ifdef PRINT_PACKET_STATS
199200
// Packet stats are useful for determining decoding errors
File renamed without changes.

bin/dns-hog

2.65 MB
Binary file not shown.

piglet-bpf-filter/piglet-bpf-filter.cc renamed to bin/dns_hog.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
#include <packet/dns.h>
2222
#include <pcap.h>
2323

24-
//#include <sfbpf.h>
25-
//#include <sfbpf_dlt.h>
26-
24+
#define TXT_FG_PURPLE(str) "\e[35m" str "\e[0m"
2725

2826
#include "daq_print.h"
2927

@@ -441,7 +439,8 @@ class DataPlaneWorker
441439
}
442440

443441
verdicts.verdicts[i] = verdict;
444-
printf(matched ? "[match|%s] " : "[%s]", str_from_verdict(verdict));
442+
printf(matched ? "[" TXT_FG_PURPLE("match") "] " : "");
443+
printf("[%s] ", str_from_verdict(verdict));
445444
print_packet(id, hdr, data, hdr->pktlen);
446445
}
447446
}
@@ -508,9 +507,9 @@ int main(int argc, char const* argv[])
508507
//{ "debug", "true" },
509508
};
510509

511-
if (argc < 3)
510+
if (argc < 2)
512511
{
513-
fprintf(stderr, "Usage: piglet-bpf-filter [pass|block|allowlist|blocklist] <BPF expression>\n");
512+
fprintf(stderr, "Usage: piglet-bpf-filter <BPF expression>\n");
514513
exit(1);
515514
}
516515

@@ -520,13 +519,12 @@ int main(int argc, char const* argv[])
520519

521520
DaqConfig pcap_config("pcap", "pcaps/dns.pcap", DAQ_MODE_READ_FILE, vars);
522521
DataPlaneWorker wk0(pcap_config, 0, filter, match_verdict, default_verdict);
522+
523523
sleep(2);
524+
524525
wk0.stop();
525526
wk0.join();
526527

527-
//DataPlaneWorker wk1(vpp_inline_config, 1, filter, match_verdict, default_verdict);
528-
//wk1.stop(); wk1.join();
529-
530528
DAQ::unload_modules();
531529
return 0;
532530
}

bin/pcaps/dns-label-loop.pcap

216 Bytes
Binary file not shown.
File renamed without changes.

include/packet/dns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ enum dns_types {
6464
TYPE_TXT // 16
6565
};
6666

67-
int decode_dns(uint8_t const *pkt, uint32_t const len, dns* dns);
67+
extern "C" int decode_dns(uint8_t const *pkt, uint32_t const len, dns* dns);
6868

6969
#endif /* LIBPACKET_DECODE_DNS_H */

0 commit comments

Comments
 (0)