static void logOutgoingQuery(const std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>>& outgoingLoggers, boost::optional<RecProtoBufMessage>& message, boost::optional<const boost::uuids::uuid&> initialRequestId, const boost::uuids::uuid& uuid, const ComboAddress& ip, const DNSName& domain, int type, uint16_t qid, bool doTCP, size_t bytes, boost::optional<Netmask>& srcmask)
{
- if(!outgoingLoggers)
+ if (!outgoingLoggers) {
return;
+ }
+
+ bool log = false;
+ for (auto& logger : *outgoingLoggers) {
+ if (logger->logQueries()) {
+ log = true;
+ break;
+ }
+ }
+
+ if (!log) {
+ return;
+ }
message = RecProtoBufMessage(DNSProtoBufMessage::OutgoingQuery, uuid, nullptr, &ip, domain, type, QClass::IN, qid, doTCP, bytes);
message->setServerIdentity(SyncRes::s_serverID);
message->serialize(str);
for (auto& logger : *outgoingLoggers) {
- logger->queueData(str);
+ if (logger->logQueries()) {
+ logger->queueData(str);
+ }
}
}
-static void logIncomingResponse(const std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>>& outgoingLoggers, boost::optional<RecProtoBufMessage>& message, size_t bytes, int rcode, const std::vector<DNSRecord>& records, const struct timeval& queryTime, const std::set<uint16_t>& exportTypes)
+static void logIncomingResponse(const std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>>& outgoingLoggers, boost::optional<RecProtoBufMessage>& message, boost::optional<const boost::uuids::uuid&> initialRequestId, const boost::uuids::uuid& uuid, const ComboAddress& ip, const DNSName& domain, int type, uint16_t qid, bool doTCP, boost::optional<Netmask>& srcmask, size_t bytes, int rcode, const std::vector<DNSRecord>& records, const struct timeval& queryTime, const std::set<uint16_t>& exportTypes)
{
- if(!outgoingLoggers || !message)
+ if (!outgoingLoggers) {
+ return;
+ }
+
+ bool log = false;
+ for (auto& logger : *outgoingLoggers) {
+ if (logger->logResponses()) {
+ log = true;
+ break;
+ }
+ }
+
+ if (!log) {
return;
+ }
+
+ if (!message) {
+ message = RecProtoBufMessage(DNSProtoBufMessage::IncomingResponse, uuid, nullptr, &ip, domain, type, QClass::IN, qid, doTCP, bytes);
+ message->setServerIdentity(SyncRes::s_serverID);
+
+ if (initialRequestId) {
+ message->setInitialRequestID(*initialRequestId);
+ }
+
+ if (srcmask) {
+ message->setEDNSSubnet(*srcmask);
+ }
+ }
+ else {
+ message->updateTime();
+ message->setType(DNSProtoBufMessage::IncomingResponse);
+ message->setBytes(bytes);
+ }
- message->updateTime();
- message->setType(DNSProtoBufMessage::IncomingResponse);
- message->setBytes(bytes);
message->setQueryTime(queryTime.tv_sec, queryTime.tv_usec);
message->setResponseCode(rcode);
message->addRRs(records, exportTypes);
message->serialize(str);
for (auto& logger : *outgoingLoggers) {
- logger->queueData(str);
+ if (logger->logResponses()) {
+ logger->queueData(str);
+ }
}
}
#endif /* HAVE_PROTOBUF */
if(mdp.d_header.rcode == RCode::FormErr && mdp.d_qname.empty() && mdp.d_qtype == 0 && mdp.d_qclass == 0) {
#ifdef HAVE_PROTOBUF
if(outgoingLoggers) {
- logIncomingResponse(outgoingLoggers, pbMessage, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
+ logIncomingResponse(outgoingLoggers, pbMessage, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
}
#endif
lwr->d_validpacket=true;
#ifdef HAVE_PROTOBUF
if(outgoingLoggers) {
- logIncomingResponse(outgoingLoggers, pbMessage, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
+ logIncomingResponse(outgoingLoggers, pbMessage, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
}
#endif
lwr->d_validpacket=true;
g_stats.serverParseError++;
#ifdef HAVE_PROTOBUF
if(outgoingLoggers) {
- logIncomingResponse(outgoingLoggers, pbMessage, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
+ logIncomingResponse(outgoingLoggers, pbMessage, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
}
#endif
lwr->d_validpacket=false;