d_slog->error(Logr::Error, errno, "Error sending reply with sendmsg", "socket", Logging::Loggable(p.getSocket()), "remote", Logging::Loggable(p.d_remote.toStringWithPort())));
}
- g_rs.submitResponse(p, true);
+ g_rs.submitResponse(p, buffer.length(), true);
}
bool UDPNameserver::receive(DNSPacket& packet, std::string& buffer)
* Function that creates all the stats
* when udpOrTCP is true, it is udp
*/
-void ResponseStats::submitResponse(DNSPacket &p, bool udpOrTCP, bool last) const {
- const string& buf=p.getString();
+void ResponseStats::submitResponse(const DNSPacket &p, size_t length, bool udpOrTCP, bool last) const { // NOLINT(readability-identifier-length)
static AtomicCounter &udpnumanswered=*S.getPointer("udp-answers");
static AtomicCounter &udpnumanswered4=*S.getPointer("udp4-answers");
static AtomicCounter &udpnumanswered6=*S.getPointer("udp6-answers");
if (udpOrTCP) { // udp
udpnumanswered++;
- udpbytesanswered+=buf.length();
+ udpbytesanswered+=length;
if(accountremote.sin4.sin_family==AF_INET) {
udpnumanswered4++;
- udpbytesanswered4+=buf.length();
+ udpbytesanswered4+=length;
} else {
udpnumanswered6++;
- udpbytesanswered6+=buf.length();
+ udpbytesanswered6+=length;
}
} else { //tcp
- tcpbytesanswered+=buf.length();
+ tcpbytesanswered+=length;
if(accountremote.sin4.sin_family==AF_INET) {
- tcpbytesanswered4+=buf.length();
+ tcpbytesanswered4+=length;
} else {
- tcpbytesanswered6+=buf.length();
+ tcpbytesanswered6+=length;
}
if(last) {
tcpnumanswered++;
}
}
- submitResponse(p.qtype.getCode(), buf.length(), p.d.rcode, udpOrTCP);
+ submitResponse(p.qtype.getCode(), length, p.d.rcode, udpOrTCP);
}
public:
ResponseStats();
- void submitResponse(DNSPacket& p, bool udpOrTCP, bool last = true) const;
+ void submitResponse(const DNSPacket& p, size_t length, bool udpOrTCP, bool last = true) const;
void submitResponse(uint16_t qtype, uint16_t respsize, bool udpOrTCP) const;
void submitResponse(uint16_t qtype, uint16_t respsize, uint8_t rcode, bool udpOrTCP) const;
map<uint16_t, uint64_t> getQTypeResponseCounts() const;
buffer.append(p->getString());
writenWithTimeout(outsock, buffer.c_str(), buffer.length(), d_idleTimeout);
- g_rs.submitResponse(*p, false, last);
+ g_rs.submitResponse(*p, buffer.length() - 2, false, last);
}