From: Remi Gacogne Date: Tue, 8 Dec 2020 14:40:38 +0000 (+0100) Subject: dnspcap2protobuf: Use protozero for Protocol Buffer operations X-Git-Tag: rec-4.5.0-alpha1~38^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=471c63d0860de7356ab6dae508047dd62666c5f1;p=thirdparty%2Fpdns.git dnspcap2protobuf: Use protozero for Protocol Buffer operations --- diff --git a/ext/Makefile.am b/ext/Makefile.am index 7c0a42d419..4cf7265338 100644 --- a/ext/Makefile.am +++ b/ext/Makefile.am @@ -9,4 +9,6 @@ DIST_SUBDIRS = \ yahttp EXTRA_DIST = \ - luawrapper/include/LuaContext.hpp + luawrapper/include/LuaContext.hpp \ + protozero/* protozero/include/protozero/* + diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 2d14bb190c..6a0c436a1d 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -112,6 +112,7 @@ if TOOLS bin_PROGRAMS += \ dnsgram \ dnspcap2calidns \ + dnspcap2protobuf \ dnsreplay \ dnsscan \ dnsscope \ @@ -150,6 +151,7 @@ EXTRA_PROGRAMS = \ dnsdemog \ dnsgram \ dnspcap2calidns \ + dnspcap2protobuf \ dnsreplay \ dnsscan \ dnsscope \ @@ -1229,16 +1231,6 @@ dnspcap2calidns_LDADD = \ $(LIBCRYPTO_LIBS) \ $(BOOST_PROGRAM_OPTIONS_LIBS) -if HAVE_PROTOBUF -if HAVE_PROTOC -bin_PROGRAMS += dnspcap2protobuf - -dnsmessage.pb.cc: dnsmessage.proto - $(AM_V_GEN)$(PROTOC) --cpp_out=./ $< - -BUILT_SOURCES += dnsmessage.pb.cc -dnspcap2protobuf.$(OBJEXT): dnsmessage.pb.cc - dnspcap2protobuf_SOURCES = \ base32.cc \ base64.cc base64.hh \ @@ -1254,7 +1246,7 @@ dnspcap2protobuf_SOURCES = \ logger.cc \ misc.cc \ nsecrecords.cc \ - protobuf.cc protobuf.hh \ + protozero.cc protozero.hh \ qtype.cc \ rcpgenerator.cc rcpgenerator.hh \ sillyrecords.cc \ @@ -1264,8 +1256,6 @@ dnspcap2protobuf_SOURCES = \ utility.hh \ uuid-utils.hh uuid-utils.cc -nodist_dnspcap2protobuf_SOURCES=dnsmessage.pb.cc dnsmessage.pb.h - dnspcap2protobuf_LDFLAGS = \ $(AM_LDFLAGS) \ $(LIBCRYPTO_LDFLAGS) \ @@ -1273,11 +1263,8 @@ dnspcap2protobuf_LDFLAGS = \ dnspcap2protobuf_LDADD = \ $(LIBCRYPTO_LIBS) \ - $(PROTOBUF_LIBS) \ $(BOOST_PROGRAM_OPTIONS_LIBS) \ $(RT_LIBS) -endif -endif pdns.conf-dist: pdns_server $(AM_V_GEN)./pdns_server --config=default 2>/dev/null > $@ diff --git a/pdns/dnspcap2protobuf.cc b/pdns/dnspcap2protobuf.cc index 664ba89e5e..a94b736fde 100644 --- a/pdns/dnspcap2protobuf.cc +++ b/pdns/dnspcap2protobuf.cc @@ -26,11 +26,10 @@ #include "iputils.hh" #include "misc.hh" -#include "protobuf.hh" #include "dns.hh" #include "dnspcap.hh" #include "dnsparser.hh" -#include "protobuf.hh" +#include "protozero.hh" #include "uuid-utils.hh" #include "statbag.hh" @@ -75,6 +74,7 @@ try { ind=atoi(argv[3]); std::map > ids; + std::string pbBuffer; try { while (pr.getUDPPacket()) { const dnsheader* dh=(dnsheader*)pr.d_payload; @@ -123,19 +123,23 @@ try { *((char*)&requestor.sin4.sin_addr.s_addr)|=ind; *((char*)&responder.sin4.sin_addr.s_addr)|=ind; - DNSProtoBufMessage message(dh->qr ? DNSProtoBufMessage::DNSProtoBufMessageType::Response : DNSProtoBufMessage::DNSProtoBufMessageType::Query, uniqueId, &requestor, &responder, qname, qtype, qclass, dh->id, false, pr.d_len); - message.setTime(pr.d_pheader.ts.tv_sec, pr.d_pheader.ts.tv_usec); + pbBuffer.clear(); + pdns::ProtoZero::Message pbMessage(pbBuffer); + pbMessage.setType(dh->qr ? 2 : 1); + pbMessage.setRequest(uniqueId, requestor, responder, qname, qtype, qclass, dh->id, false, pr.d_len); + pbMessage.setTime(pr.d_pheader.ts.tv_sec, pr.d_pheader.ts.tv_usec); if (dh->qr) { - message.setResponseCode(dh->rcode); + pbMessage.startResponse(); + pbMessage.setResponseCode(dh->rcode); if (hasQueryTime) { - message.setQueryTime(queryTime.tv_sec, queryTime.tv_usec); + pbMessage.setQueryTime(queryTime.tv_sec, queryTime.tv_usec); } try { - message.addRRsFromPacket((const char*) dh, pr.d_len, true); + pbMessage.addRRsFromPacket((const char*) dh, pr.d_len, true); } - catch(std::exception& e) + catch (const std::exception& e) { cerr<<"Error parsing response records: "<