From: Remi Gacogne Date: Fri, 28 Sep 2018 14:11:28 +0000 (+0200) Subject: rec: Export the server ID in protobuf messages X-Git-Tag: dnsdist-1.3.3~77^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c165308b66fcaf6bd2517afa165a27027e5919ad;p=thirdparty%2Fpdns.git rec: Export the server ID in protobuf messages --- diff --git a/pdns/dnsmessage.proto b/pdns/dnsmessage.proto index a6ccf509dd..12ece21db3 100644 --- a/pdns/dnsmessage.proto +++ b/pdns/dnsmessage.proto @@ -46,7 +46,7 @@ message PBDNSMessage { } required Type type = 1; optional bytes messageId = 2; // UUID, shared by the query and the response - optional bytes serverIdentity = 3; // UUID of the server emitting the protobuf message + optional bytes serverIdentity = 3; // ID of the server emitting the protobuf message optional SocketFamily socketFamily = 4; optional SocketProtocol socketProtocol = 5; optional bytes from = 6; // DNS requestor (client) diff --git a/pdns/lwres.cc b/pdns/lwres.cc index a0f97902b6..21093ea8e5 100644 --- a/pdns/lwres.cc +++ b/pdns/lwres.cc @@ -56,6 +56,8 @@ static void logOutgoingQuery(std::shared_ptr outgoingLogger, boost return; RecProtoBufMessage message(DNSProtoBufMessage::OutgoingQuery, uuid, nullptr, &ip, domain, type, QClass::IN, qid, doTCP, bytes); + message.setServerIdentity(SyncRes::s_serverID); + if (initialRequestId) { message.setInitialRequestID(*initialRequestId); } @@ -76,6 +78,7 @@ static void logIncomingResponse(std::shared_ptr outgoingLogger, bo return; RecProtoBufMessage message(DNSProtoBufMessage::IncomingResponse, uuid, nullptr, &ip, domain, type, QClass::IN, qid, doTCP, bytes); + message.setServerIdentity(SyncRes::s_serverID); if (initialRequestId) { message.setInitialRequestID(*initialRequestId); } diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 65a8baffe7..1cc480e048 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -773,6 +773,7 @@ static void protobufLogQuery(const std::shared_ptr& logger, uint8_ Netmask requestorNM(remote, remote.sin4.sin_family == AF_INET ? maskV4 : maskV6); const ComboAddress& requestor = requestorNM.getMaskedNetwork(); RecProtoBufMessage message(DNSProtoBufMessage::Query, uniqueId, &requestor, &local, qname, qtype, qclass, id, tcp, len); + message.setServerIdentity(SyncRes::s_serverID); message.setEDNSSubnet(ednssubnet, ednssubnet.isIpv4() ? maskV4 : maskV6); message.setRequestorId(requestorId); message.setDeviceId(deviceId); @@ -1010,6 +1011,7 @@ static void startDoResolve(void *p) Netmask requestorNM(dc->d_source, dc->d_source.sin4.sin_family == AF_INET ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6); const ComboAddress& requestor = requestorNM.getMaskedNetwork(); pbMessage = RecProtoBufMessage(RecProtoBufMessage::Response); + pbMessage->setServerIdentity(SyncRes::s_serverID); pbMessage->update(dc->d_uuid, &requestor, &dc->d_destination, dc->d_tcp, dc->d_mdp.d_header.id); pbMessage->setEDNSSubnet(dc->d_ednssubnet.source, dc->d_ednssubnet.source.isIpv4() ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6); pbMessage->setQuestion(dc->d_mdp.d_qname, dc->d_mdp.d_qtype, dc->d_mdp.d_qclass); @@ -2030,6 +2032,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr #ifdef HAVE_PROTOBUF if(t_protobufServer) { pbMessage = RecProtoBufMessage(DNSProtoBufMessage::DNSProtoBufMessageType::Response); + pbMessage->setServerIdentity(SyncRes::s_serverID); if (logQuery && !(luaconfsLocal->protobufExportConfig.taggedOnly && policyTags.empty())) { protobufLogQuery(t_protobufServer, luaconfsLocal->protobufMaskV4, luaconfsLocal->protobufMaskV6, uniqueId, source, destination, ednssubnet.source, false, dh->id, question.size(), qname, qtype, qclass, policyTags, requestorId, deviceId); } diff --git a/pdns/protobuf.cc b/pdns/protobuf.cc index 60dc3ada31..a726e2c599 100644 --- a/pdns/protobuf.cc +++ b/pdns/protobuf.cc @@ -242,6 +242,13 @@ void DNSProtoBufMessage::setDeviceId(const std::string& deviceId) #endif /* HAVE_PROTOBUF */ } +void DNSProtoBufMessage::setServerIdentity(const std::string& serverId) +{ +#ifdef HAVE_PROTOBUF + d_message.set_serveridentity(serverId); +#endif /* HAVE_PROTOBUF */ +} + void DNSProtoBufMessage::setResponder(const std::string& responder) { #ifdef HAVE_PROTOBUF diff --git a/pdns/protobuf.hh b/pdns/protobuf.hh index 0fab8fa3ac..42491bc87f 100644 --- a/pdns/protobuf.hh +++ b/pdns/protobuf.hh @@ -70,6 +70,7 @@ public: void setResponder(const ComboAddress& responder); void setRequestorId(const std::string& requestorId); void setDeviceId(const std::string& deviceId); + void setServerIdentity(const std::string& serverId); std::string toDebugString() const; void addTag(const std::string& strValue); void addRR(const DNSName& qame, uint16_t utype, uint16_t uClass, uint32_t uTTl, const std::string& strBlob); diff --git a/regression-tests.recursor-dnssec/test_Protobuf.py b/regression-tests.recursor-dnssec/test_Protobuf.py index 3a7bc31775..3f86caf804 100644 --- a/regression-tests.recursor-dnssec/test_Protobuf.py +++ b/regression-tests.recursor-dnssec/test_Protobuf.py @@ -106,6 +106,7 @@ class TestRecursorProtobuf(RecursorTest): self.assertTrue(msg.HasField('socketProtocol')) self.assertEquals(msg.socketProtocol, protocol) self.assertTrue(msg.HasField('messageId')) + self.assertTrue(msg.HasField('serverIdentity')) self.assertTrue(msg.HasField('id')) self.assertEquals(msg.id, query.id) self.assertTrue(msg.HasField('inBytes')) @@ -126,6 +127,7 @@ class TestRecursorProtobuf(RecursorTest): self.assertTrue(msg.HasField('socketProtocol')) self.assertEquals(msg.socketProtocol, protocol) self.assertTrue(msg.HasField('messageId')) + self.assertTrue(msg.HasField('serverIdentity')) self.assertTrue(msg.HasField('id')) self.assertNotEquals(msg.id, query.id) self.assertTrue(msg.HasField('inBytes'))