]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnspcap2protobuf: Use protozero for Protocol Buffer operations
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 8 Dec 2020 14:40:38 +0000 (15:40 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 5 Jan 2021 09:25:40 +0000 (10:25 +0100)
ext/Makefile.am
pdns/Makefile.am
pdns/dnspcap2protobuf.cc

index 7c0a42d4199fc6feaaaf3168da99b1e499b1e689..4cf7265338f01e448bc554e8ab63f778b82ab865 100644 (file)
@@ -9,4 +9,6 @@ DIST_SUBDIRS = \
        yahttp
 
 EXTRA_DIST = \
-       luawrapper/include/LuaContext.hpp
+       luawrapper/include/LuaContext.hpp \
+       protozero/* protozero/include/protozero/*
+
index 2d14bb190ca2109be2d26daef562027d59386ab9..6a0c436a1d12fbafd77cce8f375e6fa45b598e63 100644 (file)
@@ -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 > $@
index 664ba89e5ecbc3eb615b1ed4c599678597a14fc6..a94b736fdeb70a00aa3a642678b02e799e56460a 100644 (file)
 
 #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<uint16_t,std::pair<boost::uuids::uuid,struct timeval> > 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: "<<e.what()<<endl;
         }
@@ -145,12 +149,9 @@ try {
         }
       }
 
-      std::string str;
-      message.serialize(str);
-
-      uint16_t mlen = htons(str.length());
+      uint16_t mlen = htons(pbBuffer.length());
       fwrite(&mlen, 1, sizeof(mlen), fp.get());
-      fwrite(str.c_str(), 1, str.length(), fp.get());
+      fwrite(pbBuffer.c_str(), 1, pbBuffer.length(), fp.get());
     }
   }
   catch (const std::exception& e) {