Skip to content

Commit 900df5f

Browse files
authored
3.0.7 (#8)
* layout * move to parsing dns resources only in deep sample (needs upstream commitin pcpp). switch to buster-slim in docker * edns parse * back out initial csubnet, fix version * fix tests * add -l to specify metrics web server bind host * fix runtime image Co-authored-by: Shannon Weyrick <[email protected]>
1 parent 39c5bf8 commit 900df5f

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:disco AS build
1+
FROM debian:buster-slim AS build
22

33
ENV BUILD_DEPS "g++ cmake make git libpcap-dev pkgconf golang ca-certificates libmaxminddb-dev jq"
44

@@ -32,7 +32,7 @@ RUN \
3232
go get github.com/docopt/docopt-go && \
3333
go build /src/cmd/pktvisor/pktvisor.go
3434

35-
FROM ubuntu:disco AS runtime
35+
FROM debian:buster-slim AS runtime
3636

3737
ENV RUNTIME_DEPS "curl libpcap0.8 libmaxminddb0"
3838

src/config.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
22

33
#cmakedefine MMDB_ENABLE
4-
#cmakedefine PKTVISOR_VERSION_NUM "@PROJECT_VERSION@"
5-
#cmakedefine PKTVISOR_VERSION "@FLAME_VERSION@"
4+
#cmakedefine PKTVISOR_VERSION_NUM "@PKTVISOR_VERSION_NUM@"
5+
#cmakedefine PKTVISOR_VERSION "@PKTVISOR_VERSION@"

src/main.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
static const char USAGE[] =
2424
R"(pktvisord.
2525
Usage:
26-
pktvisord [-b BPF] [-p PORT] [-H HOSTSPEC] [--periods P] [--summary] [--geo-city FILE] [--geo-asn FILE]
26+
pktvisord [-b BPF] [-l HOST] [-p PORT] [-H HOSTSPEC] [--periods P] [--summary] [--geo-city FILE] [--geo-asn FILE]
2727
[--max-deep-sample N]
2828
TARGET
2929
pktvisord (-h | --help)
@@ -34,7 +34,8 @@ static const char USAGE[] =
3434
TARGET is either a network interface, an IP address (4 or 6) or a pcap file (ending in .pcap or .cap)
3535
3636
Options:
37-
-p PORT Run metrics webserver on the given localhost port [default: 10853]
37+
-l HOST Run metrics webserver on the given host or IP [default: localhost]
38+
-p PORT Run metrics webserver on the given port [default: 10853]
3839
-b BPF Filter packets using the given BPF string
3940
--geo-city FILE GeoLite2 City database to use for IP to Geo mapping (if enabled)
4041
--geo-asn FILE GeoLite2 ASN database to use for IP to ASN mapping (if enabled)
@@ -429,11 +430,11 @@ int main(int argc, char *argv[])
429430
openPcap(args["TARGET"].asString(), tcpDnsReassembly, bpf);
430431
if (args["--summary"].asBool()) {
431432
// in summary mode we output a single summary of stats
432-
std::cout << metricsManager->getMetrics() << std::endl;
433+
std::cout << std::endl << metricsManager->getMetrics() << std::endl;
433434
}
434435
else {
435436
// otherwise, merge the max time window available
436-
std::cout << metricsManager->getMetricsMerged(periods) << std::endl;
437+
std::cout << std::endl << metricsManager->getMetricsMerged(periods) << std::endl;
437438
}
438439
} catch (const std::exception &e) {
439440
std::cerr << e.what() << std::endl;
@@ -465,9 +466,13 @@ int main(int argc, char *argv[])
465466
}
466467
httplib::Server svr;
467468
setupRoutes(svr);
469+
auto host = args["-l"].asString();
468470
auto port = args["-p"].asLong();
469-
std::thread httpThread([&svr, port] {
470-
svr.listen("localhost", port);
471+
std::thread httpThread([&svr, host, port] {
472+
std::cerr << "Metrics web server listening on " << host << ":" << port << std::endl;
473+
if (!svr.listen(host.c_str(), port)) {
474+
throw std::runtime_error("unable to listen");
475+
}
471476
});
472477
try {
473478
std::cerr << "Interface " << dev->getName() << std::endl;

src/metrics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ void Metrics::newDNSPacket(pcpp::DnsLayer *dns, Direction dir, pcpp::ProtocolTyp
133133
return;
134134
}
135135

136+
dns->parseResources();
137+
136138
// lock for write
137139
std::unique_lock lock(_sketchMutex);
138140

tests/test_parse_pcap.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ TEST_CASE("Parse DNS UDP IPv4 tests", "[pcap][ipv4][udp][dns]")
2525
numUDP++;
2626
if (dnsRequest.isPacketOfType(pcpp::DNS)) {
2727
pcpp::DnsLayer *dnsLayer = dnsRequest.getLayerOfType<pcpp::DnsLayer>();
28+
dnsLayer->parseResources();
2829
if (numDNS == 0) {
2930
CHECK(dnsLayer->getFirstQuery()->getName() == "utadwnME.POJwOc9R.KtfO.test.com");
3031
CHECK(dnsLayer->getFirstQuery()->getDnsType() == pcpp::DNS_TYPE_AAAA);
@@ -107,6 +108,7 @@ TEST_CASE("Parse DNS UDP IPv6 tests", "[pcap][ipv6][udp][dns]")
107108
numUDP++;
108109
if (dnsRequest.isPacketOfType(pcpp::DNS)) {
109110
pcpp::DnsLayer *dnsLayer = dnsRequest.getLayerOfType<pcpp::DnsLayer>();
111+
dnsLayer->parseResources();
110112
if (numDNS == 0) {
111113
CHECK(dnsLayer->getFirstQuery()->getName() == "LOJ5Pq2._EmpLuAPR.PPLIop.1F8J2R1.eMVq5.test.com");
112114
CHECK(dnsLayer->getFirstQuery()->getDnsType() == pcpp::DNS_TYPE_AAAA);

0 commit comments

Comments
 (0)