summaryrefslogtreecommitdiffstats
path: root/dnstap.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dnstap.cc')
-rw-r--r--dnstap.cc71
1 files changed, 59 insertions, 12 deletions
diff --git a/dnstap.cc b/dnstap.cc
index 212c3b5..b032da9 100644
--- a/dnstap.cc
+++ b/dnstap.cc
@@ -7,23 +7,63 @@
#include <protozero/pbf_writer.hpp>
-namespace DnstapBaseFields {
- enum : protozero::pbf_tag_type { identity = 1, version = 2, extra = 3, message = 14, type = 15 };
+namespace DnstapBaseFields
+{
+enum : protozero::pbf_tag_type
+{
+ identity = 1,
+ version = 2,
+ extra = 3,
+ message = 14,
+ type = 15
+};
+}
+
+namespace DnstapMessageTypes
+{
+enum : protozero::pbf_tag_type
+{
+ message = 1
+};
}
-namespace DnstapMessageTypes {
- enum : protozero::pbf_tag_type { message = 1 };
+namespace DnstapSocketFamilyTypes
+{
+enum : protozero::pbf_tag_type
+{
+ inet = 1,
+ inet6 = 2
+};
}
-namespace DnstapSocketFamilyTypes {
- enum : protozero::pbf_tag_type { inet = 1, inet6 = 2 };
+namespace DnstapMessageFields
+{
+enum : protozero::pbf_tag_type
+{
+ type = 1,
+ socket_family = 2,
+ socket_protocol = 3,
+ query_address = 4,
+ response_address = 5,
+ query_port = 6,
+ response_port = 7,
+ query_time_sec = 8,
+ query_time_nsec = 9,
+ query_message = 10,
+ query_zone = 11,
+ response_time_sec = 12,
+ response_time_nsec = 13,
+ response_message = 14
+};
}
-namespace DnstapMessageFields {
- enum : protozero::pbf_tag_type { type = 1, socket_family = 2, socket_protocol = 3, query_address = 4, response_address = 5, query_port = 6, response_port = 7, query_time_sec = 8, query_time_nsec = 9, query_message = 10, query_zone = 11, response_time_sec = 12, response_time_nsec = 13, response_message = 14 };
+std::string&& DnstapMessage::getBuffer()
+{
+ return std::move(d_buffer);
}
-DnstapMessage::DnstapMessage(std::string& buffer, DnstapMessage::MessageType type, const std::string& identity, const ComboAddress* requestor, const ComboAddress* responder, DnstapMessage::ProtocolType protocol, const char* packet, const size_t len, const struct timespec* queryTime, const struct timespec* responseTime, boost::optional<const DNSName&> auth): d_buffer(buffer)
+DnstapMessage::DnstapMessage(std::string&& buffer, DnstapMessage::MessageType type, const std::string& identity, const ComboAddress* requestor, const ComboAddress* responder, DnstapMessage::ProtocolType protocol, const char* packet, const size_t len, const struct timespec* queryTime, const struct timespec* responseTime, const boost::optional<const DNSName&>& auth) :
+ d_buffer(std::move(buffer))
{
protozero::pbf_writer pbf{d_buffer};
@@ -33,7 +73,9 @@ DnstapMessage::DnstapMessage(std::string& buffer, DnstapMessage::MessageType typ
protozero::pbf_writer pbf_message{pbf, DnstapBaseFields::message};
+ // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
pbf_message.add_enum(DnstapMessageFields::type, static_cast<protozero::pbf_tag_type>(type));
+ // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
pbf_message.add_enum(DnstapMessageFields::socket_protocol, static_cast<protozero::pbf_tag_type>(protocol));
if (requestor != nullptr) {
@@ -45,9 +87,11 @@ DnstapMessage::DnstapMessage(std::string& buffer, DnstapMessage::MessageType typ
if (requestor != nullptr) {
if (requestor->sin4.sin_family == AF_INET) {
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
pbf_message.add_bytes(DnstapMessageFields::query_address, reinterpret_cast<const char*>(&requestor->sin4.sin_addr.s_addr), sizeof(requestor->sin4.sin_addr.s_addr));
}
else if (requestor->sin4.sin_family == AF_INET6) {
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
pbf_message.add_bytes(DnstapMessageFields::query_address, reinterpret_cast<const char*>(&requestor->sin6.sin6_addr.s6_addr), sizeof(requestor->sin6.sin6_addr.s6_addr));
}
pbf_message.add_uint32(DnstapMessageFields::query_port, ntohs(requestor->sin4.sin_port));
@@ -55,9 +99,11 @@ DnstapMessage::DnstapMessage(std::string& buffer, DnstapMessage::MessageType typ
if (responder != nullptr) {
if (responder->sin4.sin_family == AF_INET) {
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
pbf_message.add_bytes(DnstapMessageFields::response_address, reinterpret_cast<const char*>(&responder->sin4.sin_addr.s_addr), sizeof(responder->sin4.sin_addr.s_addr));
}
else if (responder->sin4.sin_family == AF_INET6) {
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
pbf_message.add_bytes(DnstapMessageFields::response_address, reinterpret_cast<const char*>(&responder->sin6.sin6_addr.s6_addr), sizeof(responder->sin6.sin6_addr.s6_addr));
}
pbf_message.add_uint32(DnstapMessageFields::response_port, ntohs(responder->sin4.sin_port));
@@ -74,10 +120,11 @@ DnstapMessage::DnstapMessage(std::string& buffer, DnstapMessage::MessageType typ
}
if (packet != nullptr && len >= sizeof(dnsheader)) {
- const struct dnsheader* dh = reinterpret_cast<const struct dnsheader*>(packet);
- if (!dh->qr) {
+ const dnsheader_aligned dnsheader(packet);
+ if (!dnsheader->qr) {
pbf_message.add_bytes(DnstapMessageFields::query_message, packet, len);
- } else {
+ }
+ else {
pbf_message.add_bytes(DnstapMessageFields::response_message, packet, len);
}
}