]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Tidy 14268/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 31 May 2024 13:06:32 +0000 (15:06 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 31 May 2024 13:06:32 +0000 (15:06 +0200)
pdns/protozero.cc
pdns/protozero.hh

index 4b99f49cc60d28dffb74dd39135fa141bd6db090..b5f91f4a49500cae6fac9cbc7c6aca97e2cd8c61 100644 (file)
 #ifndef DISABLE_PROTOBUF
 #include "dnsparser.hh"
 
-void pdns::ProtoZero::Message::encodeComboAddress(const protozero::pbf_tag_type type, const ComboAddress& ca)
+void pdns::ProtoZero::Message::encodeComboAddress(const protozero::pbf_tag_type type, const ComboAddress& address)
 {
-  if (ca.sin4.sin_family == AF_INET) {
-    d_message.add_bytes(type, reinterpret_cast<const char*>(&ca.sin4.sin_addr.s_addr), sizeof(ca.sin4.sin_addr.s_addr));
+  if (address.sin4.sin_family == AF_INET) {
+    d_message.add_bytes(type, reinterpret_cast<const char*>(&address.sin4.sin_addr.s_addr), sizeof(address.sin4.sin_addr.s_addr)); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
   }
-  else if (ca.sin4.sin_family == AF_INET6) {
-    d_message.add_bytes(type, reinterpret_cast<const char*>(&ca.sin6.sin6_addr.s6_addr), sizeof(ca.sin6.sin6_addr.s6_addr));
+  else if (address.sin4.sin_family == AF_INET6) {
+    d_message.add_bytes(type, reinterpret_cast<const char*>(&address.sin6.sin6_addr.s6_addr), sizeof(address.sin6.sin6_addr.s6_addr)); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
   }
 }
 
 void pdns::ProtoZero::Message::encodeNetmask(const protozero::pbf_tag_type type, const Netmask& subnet, uint8_t mask)
 {
   if (!subnet.empty()) {
-    ComboAddress ca(subnet.getNetwork());
-    ca.truncate(mask);
-    if (ca.sin4.sin_family == AF_INET) {
-      d_message.add_bytes(type, reinterpret_cast<const char*>(&ca.sin4.sin_addr.s_addr), sizeof(ca.sin4.sin_addr.s_addr));
+    ComboAddress address(subnet.getNetwork());
+    address.truncate(mask);
+    if (address.sin4.sin_family == AF_INET) {
+      d_message.add_bytes(type, reinterpret_cast<const char*>(&address.sin4.sin_addr.s_addr), sizeof(address.sin4.sin_addr.s_addr)); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
     }
-    else if (ca.sin4.sin_family == AF_INET6) {
-      d_message.add_bytes(type, reinterpret_cast<const char*>(&ca.sin6.sin6_addr.s6_addr), sizeof(ca.sin6.sin6_addr.s6_addr));
+    else if (address.sin4.sin_family == AF_INET6) {
+      d_message.add_bytes(type, reinterpret_cast<const char*>(&address.sin6.sin6_addr.s6_addr), sizeof(address.sin6.sin6_addr.s6_addr)); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
     }
   }
 }
@@ -58,7 +58,7 @@ void pdns::ProtoZero::Message::encodeDNSName(protozero::pbf_writer& pbf, std::st
   // leaving the block will cause the sub writer to compute how much was written based on the new size and update the size accordingly
 }
 
-void pdns::ProtoZero::Message::setRequest(const boost::uuids::uuid& uniqueId, const ComboAddress& requestor, const ComboAddress& local, const DNSName& qname, uint16_t qtype, uint16_t qclass, uint16_t id, pdns::ProtoZero::Message::TransportProtocol proto, size_t len)
+void pdns::ProtoZero::Message::setRequest(const boost::uuids::uuid& uniqueId, const ComboAddress& requestor, const ComboAddress& local, const DNSName& qname, uint16_t qtype, uint16_t qclass, uint16_t qid, pdns::ProtoZero::Message::TransportProtocol proto, size_t len)
 {
   setMessageIdentity(uniqueId);
   setSocketFamily(requestor.sin4.sin_family);
@@ -67,7 +67,7 @@ void pdns::ProtoZero::Message::setRequest(const boost::uuids::uuid& uniqueId, co
   setTo(local);
   setInBytes(len);
   setTime();
-  setId(id);
+  setId(qid);
   setQuestion(qname, qtype, qclass);
   setFromPort(requestor.getPort());
   setToPort(local.getPort());
@@ -85,39 +85,39 @@ void pdns::ProtoZero::Message::addRRsFromPacket(const char* packet, const size_t
     return;
   }
 
-  const dnsheader_aligned dh(packet);
+  const dnsheader_aligned header(packet);
 
-  if (ntohs(dh->ancount) == 0) {
+  if (ntohs(header->ancount) == 0) {
     return;
   }
 
-  if (ntohs(dh->qdcount) == 0) {
+  if (ntohs(header->qdcount) == 0) {
     return;
   }
 
-  PacketReader pr(std::string_view(packet, len));
+  PacketReader packetReader(std::string_view(packet, len));
 
   size_t idx = 0;
   DNSName rrname;
-  uint16_t qdcount = ntohs(dh->qdcount);
-  uint16_t ancount = ntohs(dh->ancount);
-  uint16_t rrtype;
-  uint16_t rrclass;
+  uint16_t qdcount = ntohs(header->qdcount);
+  uint16_t ancount = ntohs(header->ancount);
+  uint16_t rrtype{};
+  uint16_t rrclass{};
   string blob;
-  struct dnsrecordheader ah;
+  dnsrecordheader recordHeader{};
 
-  rrname = pr.getName();
-  rrtype = pr.get16BitInt();
-  rrclass = pr.get16BitInt();
+  rrname = packetReader.getName();
+  rrtype = packetReader.get16BitInt();
+  rrclass = packetReader.get16BitInt();
   (void)rrtype;
   (void)rrclass;
 
   /* consume remaining qd if any */
   if (qdcount > 1) {
     for (idx = 1; idx < qdcount; idx++) {
-      rrname = pr.getName();
-      rrtype = pr.get16BitInt();
-      rrclass = pr.get16BitInt();
+      rrname = packetReader.getName();
+      rrtype = packetReader.get16BitInt();
+      rrclass = packetReader.get16BitInt();
       (void)rrtype;
       (void)rrclass;
     }
@@ -125,27 +125,27 @@ void pdns::ProtoZero::Message::addRRsFromPacket(const char* packet, const size_t
 
   /* parse AN */
   for (idx = 0; idx < ancount; idx++) {
-    rrname = pr.getName();
-    pr.getDnsrecordheader(ah);
+    rrname = packetReader.getName();
+    packetReader.getDnsrecordheader(recordHeader);
 
-    if (ah.d_type == QType::A || ah.d_type == QType::AAAA) {
-      pr.xfrBlob(blob);
+    if (recordHeader.d_type == QType::A || recordHeader.d_type == QType::AAAA) {
+      packetReader.xfrBlob(blob);
 
-      addRR(rrname, ah.d_type, ah.d_class, ah.d_ttl, blob);
+      addRR(rrname, recordHeader.d_type, recordHeader.d_class, recordHeader.d_ttl, blob);
     }
-    else if (ah.d_type == QType::CNAME && includeCNAME) {
+    else if (recordHeader.d_type == QType::CNAME && includeCNAME) {
       protozero::pbf_writer pbf_rr{d_response, static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::ResponseField::rrs)};
 
       encodeDNSName(pbf_rr, d_buffer, static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::name), rrname);
-      pbf_rr.add_uint32(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::type), ah.d_type);
-      pbf_rr.add_uint32(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::class_), ah.d_class);
-      pbf_rr.add_uint32(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::ttl), ah.d_ttl);
+      pbf_rr.add_uint32(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::type), recordHeader.d_type);
+      pbf_rr.add_uint32(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::class_), recordHeader.d_class);
+      pbf_rr.add_uint32(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::ttl), recordHeader.d_ttl);
       DNSName target;
-      pr.xfrName(target, true);
+      packetReader.xfrName(target, true);
       encodeDNSName(pbf_rr, d_buffer, static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::rdata), target);
     }
     else {
-      pr.xfrBlob(blob);
+      packetReader.xfrBlob(blob);
     }
   }
 }
index 1562a2e43e0ad10f3e39498dce57c05822f096e5..b2c96c2184235012e4c0de9d0285950c0ce1d002 100644 (file)
@@ -146,13 +146,13 @@ namespace ProtoZero
       d_buffer(buffer), d_message{d_buffer}
     {
     }
-
+    ~Message() = default;
     Message(const Message&) = delete;
     Message(Message&&) = delete;
     Message& operator=(const Message&) = delete;
     Message& operator=(Message&&) = delete;
 
-    void setRequest(const boost::uuids::uuid& uniqueId, const ComboAddress& requestor, const ComboAddress& local, const DNSName& qname, uint16_t qtype, uint16_t qclass, uint16_t id, TransportProtocol proto, size_t len);
+    void setRequest(const boost::uuids::uuid& uniqueId, const ComboAddress& requestor, const ComboAddress& local, const DNSName& qname, uint16_t qtype, uint16_t qclass, uint16_t qid, TransportProtocol proto, size_t len);
     void setResponse(const DNSName& qname, uint16_t qtype, uint16_t qclass);
 
     void setType(MessageType mtype)
@@ -167,7 +167,7 @@ namespace ProtoZero
 
     void setMessageIdentity(const boost::uuids::uuid& uniqueId)
     {
-      add_bytes(d_message, Field::messageId, reinterpret_cast<const char*>(uniqueId.begin()), uniqueId.size());
+      add_bytes(d_message, Field::messageId, reinterpret_cast<const char*>(uniqueId.begin()), uniqueId.size()); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
     }
 
     void setServerIdentity(const std::string& serverIdentity)
@@ -185,14 +185,14 @@ namespace ProtoZero
       add_enum(d_message, Field::socketProtocol, static_cast<int32_t>(proto));
     }
 
-    void setFrom(const ComboAddress& ca)
+    void setFrom(const ComboAddress& address)
     {
-      encodeComboAddress(static_cast<protozero::pbf_tag_type>(Field::from), ca);
+      encodeComboAddress(static_cast<protozero::pbf_tag_type>(Field::from), address);
     }
 
-    void setTo(const ComboAddress& ca)
+    void setTo(const ComboAddress& address)
     {
-      encodeComboAddress(static_cast<protozero::pbf_tag_type>(Field::to), ca);
+      encodeComboAddress(static_cast<protozero::pbf_tag_type>(Field::to), address);
     }
 
     void setInBytes(uint64_t len)
@@ -202,10 +202,10 @@ namespace ProtoZero
 
     void setTime()
     {
-      struct timespec ts;
-      gettime(&ts, true);
+      timespec timesp{};
+      gettime(&timesp, true);
 
-      setTime(ts.tv_sec, ts.tv_nsec / 1000);
+      setTime(timesp.tv_sec, timesp.tv_nsec / 1000);
     }
 
     void setTime(time_t sec, uint32_t usec)
@@ -215,9 +215,9 @@ namespace ProtoZero
       add_uint32(d_message, Field::timeUsec, usec);
     }
 
-    void setId(uint16_t id)
+    void setId(uint16_t qid)
     {
-      add_uint32(d_message, Field::id, ntohs(id));
+      add_uint32(d_message, Field::id, ntohs(qid));
     }
 
     void setQuestion(const DNSName& qname, uint16_t qtype, uint16_t qclass)
@@ -233,17 +233,17 @@ namespace ProtoZero
       protozero::pbf_writer pbf_meta{d_message, static_cast<protozero::pbf_tag_type>(Field::meta)};
       pbf_meta.add_string(static_cast<protozero::pbf_tag_type>(MetaField::key), key);
       protozero::pbf_writer pbf_meta_value{pbf_meta, static_cast<protozero::pbf_tag_type>(MetaField::value)};
-      for (const auto& s : stringVal) {
-        pbf_meta_value.add_string(static_cast<protozero::pbf_tag_type>(MetaValueField::stringVal), s);
+      for (const auto& str : stringVal) {
+        pbf_meta_value.add_string(static_cast<protozero::pbf_tag_type>(MetaValueField::stringVal), str);
       }
-      for (const auto& i : intVal) {
-        pbf_meta_value.add_uint64(static_cast<protozero::pbf_tag_type>(MetaValueField::intVal), i);
+      for (const auto& val : intVal) {
+        pbf_meta_value.add_uint64(static_cast<protozero::pbf_tag_type>(MetaValueField::intVal), val);
       }
     }
 
-    void setEDNSSubnet(const Netmask& nm, uint8_t mask)
+    void setEDNSSubnet(const Netmask& netmask, uint8_t mask)
     {
-      encodeNetmask(static_cast<protozero::pbf_tag_type>(Field::originalRequestorSubnet), nm, mask);
+      encodeNetmask(static_cast<protozero::pbf_tag_type>(Field::originalRequestorSubnet), netmask, mask);
     }
 
     void setRequestorId(const std::string& req)
@@ -255,13 +255,13 @@ namespace ProtoZero
 
     void setInitialRequestID(const boost::uuids::uuid& uniqueId)
     {
-      add_bytes(d_message, Field::initialRequestId, reinterpret_cast<const char*>(uniqueId.begin()), uniqueId.size());
+      add_bytes(d_message, Field::initialRequestId, reinterpret_cast<const char*>(uniqueId.begin()), uniqueId.size()); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
     }
 
-    void setDeviceId(const std::string& id)
+    void setDeviceId(const std::string& deviceId)
     {
-      if (!id.empty()) {
-        add_string(d_message, Field::deviceId, id);
+      if (!deviceId.empty()) {
+        add_string(d_message, Field::deviceId, deviceId);
       }
     }
 
@@ -346,13 +346,13 @@ namespace ProtoZero
       d_response.add_uint32(static_cast<protozero::pbf_tag_type>(ResponseField::queryTimeUsec), usec);
     }
 
-    void addRRsFromPacket(const char* packet, const size_t len, bool includeCNAME = false);
+    void addRRsFromPacket(const char* packet, size_t len, bool includeCNAME = false);
     void addRR(const DNSName& name, uint16_t uType, uint16_t uClass, uint32_t uTTL, const std::string& blob);
 
   protected:
-    void encodeComboAddress(protozero::pbf_tag_type type, const ComboAddress& ca);
+    void encodeComboAddress(protozero::pbf_tag_type type, const ComboAddress& address);
     void encodeNetmask(protozero::pbf_tag_type type, const Netmask& subnet, uint8_t mask);
-    void encodeDNSName(protozero::pbf_writer& pbf, std::string& buffer, protozero::pbf_tag_type type, const DNSName& name);
+    static void encodeDNSName(protozero::pbf_writer& pbf, std::string& buffer, protozero::pbf_tag_type type, const DNSName& name);
 
     static void add_enum(protozero::pbf_writer& writer, Field type, int32_t value)
     {
@@ -384,9 +384,11 @@ namespace ProtoZero
       writer.add_string(static_cast<protozero::pbf_tag_type>(type), str);
     }
 
+    // NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes)
     std::string& d_buffer;
     protozero::pbf_writer d_message;
     protozero::pbf_writer d_response;
+    // NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes)
   };
 };
 };