_ZN27ConcurrentConnectionManagerC2Em:
   30|      4|  {
   31|      4|    setMaxConcurrentConnections(max);
   32|      4|  }
_ZN27ConcurrentConnectionManager27setMaxConcurrentConnectionsEm:
   35|      4|  {
   36|      4|    d_data.lock()->d_maxConcurrentConnections = max;
   37|      4|  }

_ZN17dnsheader_aligned15isMemoryAlignedEPKv:
  227|  20.9k|  {
  228|  20.9k|    return reinterpret_cast<uintptr_t>(mem) % sizeof(uint32_t) == 0; // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
  229|  20.9k|  }
_ZN17dnsheader_alignedC2EPKv:
  232|  20.5k|  {
  233|  20.5k|    if (isMemoryAligned(mem)) {
  ------------------
  |  Branch (233:9): [True: 20.5k, False: 0]
  ------------------
  234|  20.5k|      d_p = reinterpret_cast<const dnsheader*>(mem); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
  235|  20.5k|    }
  236|      0|    else {
  237|      0|      memcpy(&d_h, mem, sizeof(dnsheader));
  238|      0|      d_p = &d_h;
  239|      0|    }
  240|  20.5k|  }
_ZNK17dnsheader_alignedptEv:
  258|   158k|  {
  259|   158k|    return d_p;
  260|   158k|  }

_ZN7dnsdist14PacketMangling23editDNSHeaderFromPacketERNSt3__16vectorIh14noinit_adaptorINS1_9allocatorIhEEEEERKNS1_8functionIFbR9dnsheaderEEE:
  204|    364|  {
  205|    364|    if (packet.size() < sizeof(dnsheader)) {
  ------------------
  |  Branch (205:9): [True: 0, False: 364]
  ------------------
  206|      0|      throw std::runtime_error("Trying to edit the DNS header of a too small packet");
  207|      0|    }
  208|       |
  209|    364|    return editDNSHeaderFromRawPacket(packet.data(), editFunction);
  210|    364|  }
_ZN7dnsdist14PacketMangling26editDNSHeaderFromRawPacketEPvRKNSt3__18functionIFbR9dnsheaderEEE:
  213|    364|  {
  214|    364|    if (dnsheader_aligned::isMemoryAligned(packet)) {
  ------------------
  |  Branch (214:9): [True: 364, False: 0]
  ------------------
  215|       |      // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
  216|    364|      auto* header = reinterpret_cast<dnsheader*>(packet);
  217|    364|      return editFunction(*header);
  218|    364|    }
  219|       |
  220|      0|    dnsheader header{};
  221|      0|    memcpy(&header, packet, sizeof(header));
  222|      0|    if (!editFunction(header)) {
  ------------------
  |  Branch (222:9): [True: 0, False: 0]
  ------------------
  223|      0|      return false;
  224|      0|    }
  225|      0|    memcpy(packet, &header, sizeof(header));
  226|      0|    return true;
  227|      0|  }

_ZN8DynBlockC2Ev:
   78|      4|  {
   79|      4|    until.tv_sec = 0;
   80|      4|    until.tv_nsec = 0;
   81|      4|  }

_Z26rewriteResponseWithoutEDNSRKNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEERS5_:
   35|  2.98k|{
   36|  2.98k|  if (initialPacket.size() < sizeof(dnsheader)) {
  ------------------
  |  Branch (36:7): [True: 8, False: 2.97k]
  ------------------
   37|      8|    return ENOENT;
   38|      8|  }
   39|       |
   40|  2.97k|  const dnsheader_aligned dnsHeader(initialPacket.data());
   41|       |
   42|  2.97k|  if (ntohs(dnsHeader->arcount) == 0) {
  ------------------
  |  Branch (42:7): [True: 248, False: 2.72k]
  ------------------
   43|    248|    return ENOENT;
   44|    248|  }
   45|       |
   46|  2.72k|  if (ntohs(dnsHeader->qdcount) == 0) {
  ------------------
  |  Branch (46:7): [True: 38, False: 2.68k]
  ------------------
   47|     38|    return ENOENT;
   48|     38|  }
   49|       |
   50|       |  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
   51|  2.68k|  PacketReader packetReader(std::string_view(reinterpret_cast<const char*>(initialPacket.data()), initialPacket.size()));
   52|       |
   53|  2.68k|  size_t idx = 0;
   54|  2.68k|  uint16_t qdcount = ntohs(dnsHeader->qdcount);
   55|  2.68k|  uint16_t ancount = ntohs(dnsHeader->ancount);
   56|  2.68k|  uint16_t nscount = ntohs(dnsHeader->nscount);
   57|  2.68k|  uint16_t arcount = ntohs(dnsHeader->arcount);
   58|  2.68k|  string blob;
   59|  2.68k|  dnsrecordheader recordHeader{};
   60|       |
   61|  2.68k|  auto rrname = packetReader.getName();
   62|  2.68k|  auto rrtype = packetReader.get16BitInt();
   63|  2.68k|  auto rrclass = packetReader.get16BitInt();
   64|       |
   65|  2.68k|  GenericDNSPacketWriter<PacketBuffer> packetWriter(newContent, rrname, rrtype, rrclass, dnsHeader->opcode);
   66|  2.68k|  packetWriter.getHeader()->id = dnsHeader->id;
   67|  2.68k|  packetWriter.getHeader()->qr = dnsHeader->qr;
   68|  2.68k|  packetWriter.getHeader()->aa = dnsHeader->aa;
   69|  2.68k|  packetWriter.getHeader()->tc = dnsHeader->tc;
   70|  2.68k|  packetWriter.getHeader()->rd = dnsHeader->rd;
   71|  2.68k|  packetWriter.getHeader()->ra = dnsHeader->ra;
   72|  2.68k|  packetWriter.getHeader()->ad = dnsHeader->ad;
   73|  2.68k|  packetWriter.getHeader()->cd = dnsHeader->cd;
   74|  2.68k|  packetWriter.getHeader()->rcode = dnsHeader->rcode;
   75|       |
   76|       |  /* consume remaining qd if any */
   77|  2.68k|  if (qdcount > 1) {
  ------------------
  |  Branch (77:7): [True: 369, False: 2.32k]
  ------------------
   78|   133k|    for (idx = 1; idx < qdcount; idx++) {
  ------------------
  |  Branch (78:19): [True: 133k, False: 369]
  ------------------
   79|   133k|      rrname = packetReader.getName();
   80|   133k|      rrtype = packetReader.get16BitInt();
   81|   133k|      rrclass = packetReader.get16BitInt();
   82|   133k|      (void)rrtype;
   83|   133k|      (void)rrclass;
   84|   133k|    }
   85|    369|  }
   86|       |
   87|       |  /* copy AN and NS */
   88|  18.2k|  for (idx = 0; idx < ancount; idx++) {
  ------------------
  |  Branch (88:17): [True: 15.5k, False: 2.68k]
  ------------------
   89|  15.5k|    rrname = packetReader.getName();
   90|  15.5k|    packetReader.getDnsrecordheader(recordHeader);
   91|       |
   92|  15.5k|    packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::ANSWER, true);
   93|  15.5k|    packetReader.xfrBlob(blob);
   94|  15.5k|    packetWriter.xfrBlob(blob);
   95|  15.5k|  }
   96|       |
   97|  8.19k|  for (idx = 0; idx < nscount; idx++) {
  ------------------
  |  Branch (97:17): [True: 5.50k, False: 2.68k]
  ------------------
   98|  5.50k|    rrname = packetReader.getName();
   99|  5.50k|    packetReader.getDnsrecordheader(recordHeader);
  100|       |
  101|  5.50k|    packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::AUTHORITY, true);
  102|  5.50k|    packetReader.xfrBlob(blob);
  103|  5.50k|    packetWriter.xfrBlob(blob);
  104|  5.50k|  }
  105|       |  /* consume AR, looking for OPT */
  106|  25.6k|  for (idx = 0; idx < arcount; idx++) {
  ------------------
  |  Branch (106:17): [True: 22.9k, False: 2.68k]
  ------------------
  107|  22.9k|    rrname = packetReader.getName();
  108|  22.9k|    packetReader.getDnsrecordheader(recordHeader);
  109|       |
  110|  22.9k|    if (!rrname.isRoot() || recordHeader.d_type != QType::OPT) {
  ------------------
  |  Branch (110:9): [True: 10.2k, False: 12.7k]
  |  Branch (110:29): [True: 7.67k, False: 5.04k]
  ------------------
  111|  17.0k|      packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::ADDITIONAL, true);
  112|  17.0k|      packetReader.xfrBlob(blob);
  113|  17.0k|      packetWriter.xfrBlob(blob);
  114|  17.0k|    }
  115|  5.92k|    else {
  116|       |
  117|  5.92k|      packetReader.skip(recordHeader.d_clen);
  118|  5.92k|    }
  119|  22.9k|  }
  120|  2.68k|  packetWriter.commit();
  121|       |
  122|  2.68k|  return 0;
  123|  2.72k|}
_Z39slowRewriteEDNSOptionInQueryWithRecordsRKNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEERS5_RbtS9_bbRKNS_12basic_stringIcNS_11char_traitsIcEENS2_IcEEEE:
  154|  1.86k|{
  155|  1.86k|  if (initialPacket.size() < sizeof(dnsheader)) {
  ------------------
  |  Branch (155:7): [True: 0, False: 1.86k]
  ------------------
  156|      0|    return false;
  157|      0|  }
  158|       |
  159|  1.86k|  const dnsheader_aligned dnsHeader(initialPacket.data());
  160|       |
  161|  1.86k|  if (ntohs(dnsHeader->qdcount) == 0) {
  ------------------
  |  Branch (161:7): [True: 5, False: 1.86k]
  ------------------
  162|      5|    return false;
  163|      5|  }
  164|       |
  165|  1.86k|  if (ntohs(dnsHeader->ancount) == 0 && ntohs(dnsHeader->nscount) == 0 && ntohs(dnsHeader->arcount) == 0) {
  ------------------
  |  Branch (165:7): [True: 958, False: 904]
  |  Branch (165:41): [True: 647, False: 311]
  |  Branch (165:75): [True: 0, False: 647]
  ------------------
  166|      0|    throw std::runtime_error("slowRewriteEDNSOptionInQueryWithRecords should not be called for queries that have no records");
  167|      0|  }
  168|       |
  169|  1.86k|  optionAdded = false;
  170|  1.86k|  ednsAdded = true;
  171|       |
  172|       |  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
  173|  1.86k|  PacketReader packetReader(std::string_view(reinterpret_cast<const char*>(initialPacket.data()), initialPacket.size()));
  174|       |
  175|  1.86k|  size_t idx = 0;
  176|  1.86k|  uint16_t qdcount = ntohs(dnsHeader->qdcount);
  177|  1.86k|  uint16_t ancount = ntohs(dnsHeader->ancount);
  178|  1.86k|  uint16_t nscount = ntohs(dnsHeader->nscount);
  179|  1.86k|  uint16_t arcount = ntohs(dnsHeader->arcount);
  180|  1.86k|  string blob;
  181|  1.86k|  dnsrecordheader recordHeader{};
  182|       |
  183|  1.86k|  auto rrname = packetReader.getName();
  184|  1.86k|  auto rrtype = packetReader.get16BitInt();
  185|  1.86k|  auto rrclass = packetReader.get16BitInt();
  186|       |
  187|  1.86k|  GenericDNSPacketWriter<PacketBuffer> packetWriter(newContent, rrname, rrtype, rrclass, dnsHeader->opcode);
  188|  1.86k|  packetWriter.getHeader()->id = dnsHeader->id;
  189|  1.86k|  packetWriter.getHeader()->qr = dnsHeader->qr;
  190|  1.86k|  packetWriter.getHeader()->aa = dnsHeader->aa;
  191|  1.86k|  packetWriter.getHeader()->tc = dnsHeader->tc;
  192|  1.86k|  packetWriter.getHeader()->rd = dnsHeader->rd;
  193|  1.86k|  packetWriter.getHeader()->ra = dnsHeader->ra;
  194|  1.86k|  packetWriter.getHeader()->ad = dnsHeader->ad;
  195|  1.86k|  packetWriter.getHeader()->cd = dnsHeader->cd;
  196|  1.86k|  packetWriter.getHeader()->rcode = dnsHeader->rcode;
  197|       |
  198|       |  /* consume remaining qd if any */
  199|  1.86k|  if (qdcount > 1) {
  ------------------
  |  Branch (199:7): [True: 291, False: 1.57k]
  ------------------
  200|  26.4k|    for (idx = 1; idx < qdcount; idx++) {
  ------------------
  |  Branch (200:19): [True: 26.1k, False: 291]
  ------------------
  201|  26.1k|      rrname = packetReader.getName();
  202|  26.1k|      rrtype = packetReader.get16BitInt();
  203|  26.1k|      rrclass = packetReader.get16BitInt();
  204|  26.1k|      (void)rrtype;
  205|  26.1k|      (void)rrclass;
  206|  26.1k|    }
  207|    291|  }
  208|       |
  209|       |  /* copy AN and NS */
  210|  18.8k|  for (idx = 0; idx < ancount; idx++) {
  ------------------
  |  Branch (210:17): [True: 16.9k, False: 1.86k]
  ------------------
  211|  16.9k|    rrname = packetReader.getName();
  212|  16.9k|    packetReader.getDnsrecordheader(recordHeader);
  213|       |
  214|  16.9k|    packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::ANSWER, true);
  215|  16.9k|    packetReader.xfrBlob(blob);
  216|  16.9k|    packetWriter.xfrBlob(blob);
  217|  16.9k|  }
  218|       |
  219|  8.30k|  for (idx = 0; idx < nscount; idx++) {
  ------------------
  |  Branch (219:17): [True: 6.44k, False: 1.86k]
  ------------------
  220|  6.44k|    rrname = packetReader.getName();
  221|  6.44k|    packetReader.getDnsrecordheader(recordHeader);
  222|       |
  223|  6.44k|    packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::AUTHORITY, true);
  224|  6.44k|    packetReader.xfrBlob(blob);
  225|  6.44k|    packetWriter.xfrBlob(blob);
  226|  6.44k|  }
  227|       |
  228|       |  /* consume AR, looking for OPT */
  229|  24.0k|  for (idx = 0; idx < arcount; idx++) {
  ------------------
  |  Branch (229:17): [True: 22.1k, False: 1.86k]
  ------------------
  230|  22.1k|    rrname = packetReader.getName();
  231|  22.1k|    packetReader.getDnsrecordheader(recordHeader);
  232|       |
  233|  22.1k|    if (!rrname.isRoot() || recordHeader.d_type != QType::OPT) {
  ------------------
  |  Branch (233:9): [True: 10.0k, False: 12.1k]
  |  Branch (233:29): [True: 7.61k, False: 4.50k]
  ------------------
  234|  16.9k|      packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::ADDITIONAL, true);
  235|  16.9k|      packetReader.xfrBlob(blob);
  236|  16.9k|      packetWriter.xfrBlob(blob);
  237|  16.9k|    }
  238|  5.22k|    else {
  239|       |
  240|  5.22k|      ednsAdded = false;
  241|  5.22k|      packetReader.xfrBlob(blob);
  242|       |
  243|  5.22k|      std::vector<std::pair<uint16_t, std::string>> options;
  244|  5.22k|      getEDNSOptionsFromContent(blob, options);
  245|       |
  246|       |      /* getDnsrecordheader() has helpfully converted the TTL for us, which we do not want in that case */
  247|  5.22k|      uint32_t ttl = htonl(recordHeader.d_ttl);
  248|  5.22k|      EDNS0Record edns0{};
  249|  5.22k|      static_assert(sizeof(edns0) == sizeof(ttl), "sizeof(EDNS0Record) must match sizeof(uint32_t) AKA RR TTL size");
  250|  5.22k|      memcpy(&edns0, &ttl, sizeof(edns0));
  251|       |
  252|       |      /* addOrReplaceEDNSOption will set it to false if there is already an existing option */
  253|  5.22k|      optionAdded = true;
  254|  5.22k|      addOrReplaceEDNSOption(options, optionToReplace, optionAdded, overrideExisting, allowMultiple, newOptionContent);
  255|  5.22k|      packetWriter.addOpt(recordHeader.d_class, edns0.extRCode, ntohs(edns0.extFlags), options, edns0.version);
  256|  5.22k|    }
  257|  22.1k|  }
  258|       |
  259|  1.86k|  if (ednsAdded) {
  ------------------
  |  Branch (259:7): [True: 84, False: 1.77k]
  ------------------
  260|     84|    if (newOptionContent.size() == EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE) {
  ------------------
  |  Branch (260:9): [True: 0, False: 84]
  ------------------
  261|      0|      packetWriter.addOpt(dnsdist::configuration::s_EdnsUDPPayloadSize, 0, 0, {{optionToReplace, std::string()}}, 0);
  262|      0|    }
  263|     84|    else {
  264|     84|      packetWriter.addOpt(dnsdist::configuration::s_EdnsUDPPayloadSize, 0, 0, {{optionToReplace, std::string(&newOptionContent.at(EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE), newOptionContent.size() - (EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE))}}, 0);
  265|     84|    }
  266|     84|    optionAdded = true;
  267|     84|  }
  268|       |
  269|  1.86k|  packetWriter.commit();
  270|       |
  271|  1.86k|  return true;
  272|  1.86k|}
_ZN7dnsdist19getEDNSOptionsStartERKNSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEmPtPm:
  281|  3.64k|{
  282|  3.64k|  if (optRDPosition == nullptr || remaining == nullptr) {
  ------------------
  |  Branch (282:7): [True: 0, False: 3.64k]
  |  Branch (282:35): [True: 0, False: 3.64k]
  ------------------
  283|      0|    throw std::runtime_error("Invalid values passed to getEDNSOptionsStart");
  284|      0|  }
  285|       |
  286|  3.64k|  const dnsheader_aligned dnsHeader(packet.data());
  287|       |
  288|  3.64k|  if (qnameWireLength >= packet.size()) {
  ------------------
  |  Branch (288:7): [True: 0, False: 3.64k]
  ------------------
  289|      0|    return ENOENT;
  290|      0|  }
  291|       |
  292|  3.64k|  if (ntohs(dnsHeader->qdcount) != 1 || ntohs(dnsHeader->ancount) != 0 || ntohs(dnsHeader->arcount) != 1 || ntohs(dnsHeader->nscount) != 0) {
  ------------------
  |  Branch (292:7): [True: 616, False: 3.02k]
  |  Branch (292:41): [True: 653, False: 2.37k]
  |  Branch (292:75): [True: 885, False: 1.48k]
  |  Branch (292:109): [True: 57, False: 1.43k]
  ------------------
  293|  2.21k|    return ENOENT;
  294|  2.21k|  }
  295|       |
  296|  1.43k|  size_t pos = sizeof(dnsheader) + qnameWireLength;
  297|  1.43k|  pos += DNS_TYPE_SIZE + DNS_CLASS_SIZE;
  298|       |
  299|  1.43k|  if (pos >= packet.size()) {
  ------------------
  |  Branch (299:7): [True: 16, False: 1.41k]
  ------------------
  300|     16|    return ENOENT;
  301|     16|  }
  302|       |
  303|  1.41k|  if ((pos + /* root */ 1 + DNS_TYPE_SIZE + DNS_CLASS_SIZE) >= packet.size()) {
  ------------------
  |  Branch (303:7): [True: 78, False: 1.33k]
  ------------------
  304|     78|    return ENOENT;
  305|     78|  }
  306|       |
  307|  1.33k|  if (packet[pos] != 0) {
  ------------------
  |  Branch (307:7): [True: 144, False: 1.19k]
  ------------------
  308|       |    /* not the root so not an OPT record */
  309|    144|    return ENOENT;
  310|    144|  }
  311|  1.19k|  pos += 1;
  312|       |
  313|  1.19k|  uint16_t qtype = packet.at(pos) * 256 + packet.at(pos + 1);
  314|  1.19k|  pos += DNS_TYPE_SIZE;
  315|  1.19k|  pos += DNS_CLASS_SIZE;
  316|       |
  317|  1.19k|  if (qtype != QType::OPT || (packet.size() - pos) < (DNS_TTL_SIZE + DNS_RDLENGTH_SIZE)) {
  ------------------
  |  Branch (317:7): [True: 138, False: 1.05k]
  |  Branch (317:30): [True: 8, False: 1.04k]
  ------------------
  318|    146|    return ENOENT;
  319|    146|  }
  320|       |
  321|  1.04k|  pos += DNS_TTL_SIZE;
  322|  1.04k|  *optRDPosition = pos;
  323|  1.04k|  *remaining = packet.size() - pos;
  324|       |
  325|  1.04k|  return 0;
  326|  1.19k|}
_Z17generateECSOptionRK12ComboAddressRNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEt:
  330|  2.75k|{
  331|  2.75k|  Netmask sourceNetmask(source, ECSPrefixLength);
  332|  2.75k|  EDNSSubnetOpts ecsOpts;
  333|  2.75k|  ecsOpts.setSource(sourceNetmask);
  334|  2.75k|  string payload = ecsOpts.makeOptString();
  335|  2.75k|  generateEDNSOption(EDNSOptionCode::ECS, payload, res);
  336|  2.75k|}
_Z13generateOptRRRKNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERNS_6vectorIh14noinit_adaptorINS3_IhEEEEEmthb:
  339|    364|{
  340|    364|  const uint8_t name = 0;
  341|    364|  dnsrecordheader dnsHeader{};
  342|    364|  EDNS0Record edns0{};
  343|    364|  edns0.extRCode = ednsrcode;
  344|    364|  edns0.version = 0;
  345|    364|  edns0.extFlags = dnssecOK ? htons(EDNS_HEADER_FLAG_DO) : 0;
  ------------------
  |  Branch (345:20): [True: 0, False: 364]
  ------------------
  346|       |
  347|    364|  if (res.size() >= maximumSize || (maximumSize - res.size()) < (sizeof(name) + sizeof(dnsHeader) + optRData.length())) {
  ------------------
  |  Branch (347:7): [True: 0, False: 364]
  |  Branch (347:36): [True: 0, False: 364]
  ------------------
  348|      0|    return false;
  349|      0|  }
  350|       |
  351|    364|  dnsHeader.d_type = htons(QType::OPT);
  352|    364|  dnsHeader.d_class = htons(udpPayloadSize);
  353|    364|  static_assert(sizeof(EDNS0Record) == sizeof(dnsHeader.d_ttl), "sizeof(EDNS0Record) must match sizeof(dnsrecordheader.d_ttl)");
  354|    364|  memcpy(&dnsHeader.d_ttl, &edns0, sizeof edns0);
  355|    364|  dnsHeader.d_clen = htons(static_cast<uint16_t>(optRData.length()));
  356|       |
  357|    364|  res.reserve(res.size() + sizeof(name) + sizeof(dnsHeader) + optRData.length());
  358|       |  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic)
  359|    364|  res.insert(res.end(), reinterpret_cast<const uint8_t*>(&name), reinterpret_cast<const uint8_t*>(&name) + sizeof(name));
  360|       |  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic)
  361|    364|  res.insert(res.end(), reinterpret_cast<const uint8_t*>(&dnsHeader), reinterpret_cast<const uint8_t*>(&dnsHeader) + sizeof(dnsHeader));
  362|    364|  res.insert(res.end(), optRData.begin(), optRData.end());
  363|       |
  364|    364|  return true;
  365|    364|}
_Z22handleEDNSClientSubnetRNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEEmmRbS7_bRKNS_12basic_stringIcNS_11char_traitsIcEENS2_IcEEEE:
  492|  2.75k|{
  493|  2.75k|  if (qnameWireLength > packet.size()) {
  ------------------
  |  Branch (493:7): [True: 0, False: 2.75k]
  ------------------
  494|      0|    throw std::runtime_error("Invalid value passed to handleEDNSClientSubnet");
  495|      0|  }
  496|       |
  497|  2.75k|  const dnsheader_aligned dnsHeader(packet.data());
  498|       |
  499|  2.75k|  if (ntohs(dnsHeader->ancount) != 0 || ntohs(dnsHeader->nscount) != 0 || (ntohs(dnsHeader->arcount) != 0 && ntohs(dnsHeader->arcount) != 1)) {
  ------------------
  |  Branch (499:7): [True: 907, False: 1.84k]
  |  Branch (499:41): [True: 311, False: 1.53k]
  |  Branch (499:76): [True: 1.50k, False: 35]
  |  Branch (499:110): [True: 649, False: 852]
  ------------------
  500|  1.86k|    PacketBuffer newContent;
  501|  1.86k|    newContent.reserve(packet.size());
  502|       |
  503|  1.86k|    if (!slowRewriteEDNSOptionInQueryWithRecords(packet, newContent, ednsAdded, EDNSOptionCode::ECS, ecsAdded, overrideExisting, false, newECSOption)) {
  ------------------
  |  Branch (503:9): [True: 5, False: 1.86k]
  ------------------
  504|      5|      return false;
  505|      5|    }
  506|       |
  507|  1.86k|    if (newContent.size() > maximumSize) {
  ------------------
  |  Branch (507:9): [True: 27, False: 1.83k]
  ------------------
  508|     27|      ednsAdded = false;
  509|     27|      ecsAdded = false;
  510|     27|      return false;
  511|     27|    }
  512|       |
  513|  1.83k|    packet = std::move(newContent);
  514|  1.83k|    return true;
  515|  1.86k|  }
  516|       |
  517|    887|  uint16_t optRDPosition = 0;
  518|    887|  size_t remaining = 0;
  519|       |
  520|    887|  int res = dnsdist::getEDNSOptionsStart(packet, qnameWireLength, &optRDPosition, &remaining);
  521|       |
  522|    887|  if (res != 0) {
  ------------------
  |  Branch (522:7): [True: 364, False: 523]
  ------------------
  523|       |    /* no EDNS but there might be another record in additional (TSIG?) */
  524|       |    /* Careful, this code assumes that ANCOUNT == 0 && NSCOUNT == 0 */
  525|    364|    size_t minimumPacketSize = sizeof(dnsheader) + qnameWireLength + sizeof(uint16_t) + sizeof(uint16_t);
  526|    364|    if (packet.size() > minimumPacketSize) {
  ------------------
  |  Branch (526:9): [True: 349, False: 15]
  ------------------
  527|    349|      if (ntohs(dnsHeader->arcount) == 0) {
  ------------------
  |  Branch (527:11): [True: 32, False: 317]
  ------------------
  528|       |        /* well now.. */
  529|     32|        packet.resize(minimumPacketSize);
  530|     32|      }
  531|    317|      else {
  532|       |        // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
  533|    317|        uint32_t realPacketLen = getDNSPacketLength(reinterpret_cast<const char*>(packet.data()), packet.size());
  534|    317|        packet.resize(realPacketLen);
  535|    317|      }
  536|    349|    }
  537|       |
  538|    364|    return addEDNSWithECS(packet, maximumSize, newECSOption, ednsAdded, ecsAdded);
  539|    364|  }
  540|       |
  541|    523|  size_t ecsOptionStartPosition = 0;
  542|    523|  size_t ecsOptionSize = 0;
  543|       |  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
  544|    523|  res = getEDNSOption(reinterpret_cast<const char*>(&packet.at(optRDPosition)), remaining, EDNSOptionCode::ECS, &ecsOptionStartPosition, &ecsOptionSize);
  545|       |
  546|    523|  if (res == 0) {
  ------------------
  |  Branch (546:7): [True: 246, False: 277]
  ------------------
  547|       |    /* there is already an ECS value */
  548|    246|    if (!overrideExisting) {
  ------------------
  |  Branch (548:9): [True: 0, False: 246]
  ------------------
  549|      0|      return true;
  550|      0|    }
  551|       |
  552|    246|    return replaceEDNSClientSubnetOption(packet, maximumSize, optRDPosition + ecsOptionStartPosition, ecsOptionSize, optRDPosition, newECSOption);
  553|    246|  }
  554|       |
  555|    277|  if (res != ENOENT) {
  ------------------
  |  Branch (555:7): [True: 84, False: 193]
  ------------------
  556|       |    /* something is wrong */
  557|     84|    return false;
  558|     84|  }
  559|       |
  560|       |  /* we have an EDNS OPT RR but no existing ECS option */
  561|    193|  return addECSToExistingOPT(packet, maximumSize, newECSOption, optRDPosition, ecsAdded);
  562|    277|}
_Z17isEDNSOptionInOptRKNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEEmmtPmPt:
  630|    974|{
  631|    974|  if (optLen < optRecordMinimumSize) {
  ------------------
  |  Branch (631:7): [True: 0, False: 974]
  ------------------
  632|      0|    return false;
  633|      0|  }
  634|    974|  size_t position = optStart + 9;
  635|    974|  uint16_t rdLen = (0x100 * static_cast<unsigned char>(packet.at(position)) + static_cast<unsigned char>(packet.at(position + 1)));
  636|    974|  position += sizeof(rdLen);
  637|    974|  if (rdLen > (optLen - optRecordMinimumSize)) {
  ------------------
  |  Branch (637:7): [True: 29, False: 945]
  ------------------
  638|     29|    return false;
  639|     29|  }
  640|       |
  641|    945|  size_t rdEnd = position + rdLen;
  642|  29.2k|  while ((position + 4) <= rdEnd) {
  ------------------
  |  Branch (642:10): [True: 28.7k, False: 435]
  ------------------
  643|  28.7k|    const uint16_t optionCode = 0x100 * static_cast<unsigned char>(packet.at(position)) + static_cast<unsigned char>(packet.at(position + 1));
  644|  28.7k|    position += sizeof(optionCode);
  645|  28.7k|    const uint16_t optionLen = 0x100 * static_cast<unsigned char>(packet.at(position)) + static_cast<unsigned char>(packet.at(position + 1));
  646|  28.7k|    position += sizeof(optionLen);
  647|       |
  648|  28.7k|    if ((position + optionLen) > rdEnd) {
  ------------------
  |  Branch (648:9): [True: 172, False: 28.6k]
  ------------------
  649|    172|      return false;
  650|    172|    }
  651|       |
  652|  28.6k|    if (optionCode == optionCodeToFind) {
  ------------------
  |  Branch (652:9): [True: 338, False: 28.2k]
  ------------------
  653|    338|      if (optContentStart != nullptr) {
  ------------------
  |  Branch (653:11): [True: 338, False: 0]
  ------------------
  654|    338|        *optContentStart = position;
  655|    338|      }
  656|       |
  657|    338|      if (optContentLen != nullptr) {
  ------------------
  |  Branch (657:11): [True: 338, False: 0]
  ------------------
  658|    338|        *optContentLen = optionLen;
  659|    338|      }
  660|       |
  661|    338|      return true;
  662|    338|    }
  663|  28.2k|    position += optionLen;
  664|  28.2k|  }
  665|    435|  return false;
  666|    945|}
_Z32rewriteResponseWithoutEDNSOptionRKNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEEtRS5_:
  669|  2.98k|{
  670|  2.98k|  if (initialPacket.size() < sizeof(dnsheader)) {
  ------------------
  |  Branch (670:7): [True: 8, False: 2.97k]
  ------------------
  671|      8|    return ENOENT;
  672|      8|  }
  673|       |
  674|  2.97k|  const dnsheader_aligned dnsHeader(initialPacket.data());
  675|       |
  676|  2.97k|  if (ntohs(dnsHeader->arcount) == 0) {
  ------------------
  |  Branch (676:7): [True: 248, False: 2.72k]
  ------------------
  677|    248|    return ENOENT;
  678|    248|  }
  679|       |
  680|  2.72k|  if (ntohs(dnsHeader->qdcount) == 0) {
  ------------------
  |  Branch (680:7): [True: 38, False: 2.68k]
  ------------------
  681|     38|    return ENOENT;
  682|     38|  }
  683|       |
  684|       |  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
  685|  2.68k|  PacketReader packetReader(std::string_view(reinterpret_cast<const char*>(initialPacket.data()), initialPacket.size()));
  686|       |
  687|  2.68k|  size_t idx = 0;
  688|  2.68k|  DNSName rrname;
  689|  2.68k|  uint16_t qdcount = ntohs(dnsHeader->qdcount);
  690|  2.68k|  uint16_t ancount = ntohs(dnsHeader->ancount);
  691|  2.68k|  uint16_t nscount = ntohs(dnsHeader->nscount);
  692|  2.68k|  uint16_t arcount = ntohs(dnsHeader->arcount);
  693|  2.68k|  uint16_t rrtype = 0;
  694|  2.68k|  uint16_t rrclass = 0;
  695|  2.68k|  string blob;
  696|  2.68k|  dnsrecordheader recordHeader{};
  697|       |
  698|  2.68k|  rrname = packetReader.getName();
  699|  2.68k|  rrtype = packetReader.get16BitInt();
  700|  2.68k|  rrclass = packetReader.get16BitInt();
  701|       |
  702|  2.68k|  GenericDNSPacketWriter<PacketBuffer> packetWriter(newContent, rrname, rrtype, rrclass, dnsHeader->opcode);
  703|  2.68k|  packetWriter.getHeader()->id = dnsHeader->id;
  704|  2.68k|  packetWriter.getHeader()->qr = dnsHeader->qr;
  705|  2.68k|  packetWriter.getHeader()->aa = dnsHeader->aa;
  706|  2.68k|  packetWriter.getHeader()->tc = dnsHeader->tc;
  707|  2.68k|  packetWriter.getHeader()->rd = dnsHeader->rd;
  708|  2.68k|  packetWriter.getHeader()->ra = dnsHeader->ra;
  709|  2.68k|  packetWriter.getHeader()->ad = dnsHeader->ad;
  710|  2.68k|  packetWriter.getHeader()->cd = dnsHeader->cd;
  711|  2.68k|  packetWriter.getHeader()->rcode = dnsHeader->rcode;
  712|       |
  713|       |  /* consume remaining qd if any */
  714|  2.68k|  if (qdcount > 1) {
  ------------------
  |  Branch (714:7): [True: 369, False: 2.32k]
  ------------------
  715|   133k|    for (idx = 1; idx < qdcount; idx++) {
  ------------------
  |  Branch (715:19): [True: 133k, False: 369]
  ------------------
  716|   133k|      rrname = packetReader.getName();
  717|   133k|      rrtype = packetReader.get16BitInt();
  718|   133k|      rrclass = packetReader.get16BitInt();
  719|   133k|      (void)rrtype;
  720|   133k|      (void)rrclass;
  721|   133k|    }
  722|    369|  }
  723|       |
  724|       |  /* copy AN and NS */
  725|  18.2k|  for (idx = 0; idx < ancount; idx++) {
  ------------------
  |  Branch (725:17): [True: 15.5k, False: 2.68k]
  ------------------
  726|  15.5k|    rrname = packetReader.getName();
  727|  15.5k|    packetReader.getDnsrecordheader(recordHeader);
  728|       |
  729|  15.5k|    packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::ANSWER, true);
  730|  15.5k|    packetReader.xfrBlob(blob);
  731|  15.5k|    packetWriter.xfrBlob(blob);
  732|  15.5k|  }
  733|       |
  734|  8.19k|  for (idx = 0; idx < nscount; idx++) {
  ------------------
  |  Branch (734:17): [True: 5.50k, False: 2.68k]
  ------------------
  735|  5.50k|    rrname = packetReader.getName();
  736|  5.50k|    packetReader.getDnsrecordheader(recordHeader);
  737|       |
  738|  5.50k|    packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::AUTHORITY, true);
  739|  5.50k|    packetReader.xfrBlob(blob);
  740|  5.50k|    packetWriter.xfrBlob(blob);
  741|  5.50k|  }
  742|       |
  743|       |  /* consume AR, looking for OPT */
  744|  25.6k|  for (idx = 0; idx < arcount; idx++) {
  ------------------
  |  Branch (744:17): [True: 22.9k, False: 2.68k]
  ------------------
  745|  22.9k|    rrname = packetReader.getName();
  746|  22.9k|    packetReader.getDnsrecordheader(recordHeader);
  747|       |
  748|  22.9k|    if (!rrname.isRoot() || recordHeader.d_type != QType::OPT) {
  ------------------
  |  Branch (748:9): [True: 10.2k, False: 12.7k]
  |  Branch (748:29): [True: 7.67k, False: 5.03k]
  ------------------
  749|  17.0k|      packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::ADDITIONAL, true);
  750|  17.0k|      packetReader.xfrBlob(blob);
  751|  17.0k|      packetWriter.xfrBlob(blob);
  752|  17.0k|    }
  753|  5.92k|    else {
  754|  5.92k|      packetWriter.startRecord(rrname, recordHeader.d_type, recordHeader.d_ttl, recordHeader.d_class, DNSResourceRecord::ADDITIONAL, false);
  755|  5.92k|      packetReader.xfrBlob(blob);
  756|  5.92k|      uint16_t rdLen = blob.length();
  757|       |      // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
  758|  5.92k|      removeEDNSOptionFromOptions(reinterpret_cast<unsigned char*>(blob.data()), rdLen, optionCodeToSkip, &rdLen);
  759|       |      /* xfrBlob(string, size) completely ignores size.. */
  760|  5.92k|      if (rdLen > 0) {
  ------------------
  |  Branch (760:11): [True: 2.17k, False: 3.75k]
  ------------------
  761|  2.17k|        blob.resize((size_t)rdLen);
  762|  2.17k|        packetWriter.xfrBlob(blob);
  763|  2.17k|      }
  764|  3.75k|      else {
  765|  3.75k|        packetWriter.commit();
  766|  3.75k|      }
  767|  5.92k|    }
  768|  22.9k|  }
  769|  2.68k|  packetWriter.commit();
  770|       |
  771|  2.68k|  return 0;
  772|  2.72k|}
_Z14getEDNS0RecordRKNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEER11EDNS0Record:
 1044|  2.98k|{
 1045|  2.98k|  uint16_t optStart = 0;
 1046|  2.98k|  size_t optLen = 0;
 1047|  2.98k|  bool last = false;
 1048|  2.98k|  int res = locateEDNSOptRR(packet, &optStart, &optLen, &last);
 1049|  2.98k|  if (res != 0) {
  ------------------
  |  Branch (1049:7): [True: 350, False: 2.63k]
  ------------------
 1050|       |    // no EDNS OPT RR
 1051|    350|    return false;
 1052|    350|  }
 1053|       |
 1054|  2.63k|  if (optLen < optRecordMinimumSize) {
  ------------------
  |  Branch (1054:7): [True: 0, False: 2.63k]
  ------------------
 1055|      0|    return false;
 1056|      0|  }
 1057|       |
 1058|  2.63k|  if (optStart < packet.size() && packet.at(optStart) != 0) {
  ------------------
  |  Branch (1058:7): [True: 974, False: 1.65k]
  |  Branch (1058:35): [True: 31, False: 943]
  ------------------
 1059|       |    // OPT RR Name != '.'
 1060|     31|    return false;
 1061|     31|  }
 1062|       |
 1063|  2.60k|  static_assert(sizeof(EDNS0Record) == sizeof(uint32_t), "sizeof(EDNS0Record) must match sizeof(uint32_t) AKA RR TTL size");
 1064|       |  // copy out 4-byte "ttl" (really the EDNS0 record), after root label (1) + type (2) + class (2).
 1065|  2.60k|  memcpy(&edns0, &packet.at(optStart + 5), sizeof edns0);
 1066|  2.60k|  return true;
 1067|  2.63k|}
dnsdist-ecs.cc:_ZL22addOrReplaceEDNSOptionRNSt3__16vectorINS_4pairItNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEENS5_IS8_EEEEtRbbbRKS7_:
  126|  4.50k|{
  127|  4.50k|  if (!allowMultiple) {
  ------------------
  |  Branch (127:7): [True: 4.50k, False: 0]
  ------------------
  128|  36.1k|    for (auto it = options.begin(); it != options.end();) {
  ------------------
  |  Branch (128:37): [True: 31.6k, False: 4.50k]
  ------------------
  129|  31.6k|      if (it->first == optionCode) {
  ------------------
  |  Branch (129:11): [True: 1.34k, False: 30.2k]
  ------------------
  130|  1.34k|        optionAdded = false;
  131|       |
  132|  1.34k|        if (!overrideExisting) {
  ------------------
  |  Branch (132:13): [True: 0, False: 1.34k]
  ------------------
  133|      0|          return false;
  134|      0|        }
  135|       |
  136|  1.34k|        it = options.erase(it);
  137|  1.34k|      }
  138|  30.2k|      else {
  139|  30.2k|        ++it;
  140|  30.2k|      }
  141|  31.6k|    }
  142|  4.50k|  }
  143|       |
  144|  4.50k|  if (newOptionContent.size() == EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE) {
  ------------------
  |  Branch (144:7): [True: 0, False: 4.50k]
  ------------------
  145|      0|    options.emplace_back(optionCode, "");
  146|      0|    return true;
  147|      0|  }
  148|       |
  149|  4.50k|  options.emplace_back(optionCode, std::string(&newOptionContent.at(EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE), newOptionContent.size() - (EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE)));
  150|  4.50k|  return true;
  151|  4.50k|}
dnsdist-ecs.cc:_ZL14addEDNSWithECSRNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEEmRKNS_12basic_stringIcNS_11char_traitsIcEENS2_IcEEEERbSE_:
  474|    364|{
  475|    364|  if (!generateOptRR(newECSOption, packet, maximumSize, dnsdist::configuration::s_EdnsUDPPayloadSize, 0, false)) {
  ------------------
  |  Branch (475:7): [True: 0, False: 364]
  ------------------
  476|      0|    return false;
  477|      0|  }
  478|       |
  479|    364|  dnsdist::PacketMangling::editDNSHeaderFromPacket(packet, [](dnsheader& header) {
  480|    364|    uint16_t arcount = ntohs(header.arcount);
  481|    364|    arcount++;
  482|    364|    header.arcount = htons(arcount);
  483|    364|    return true;
  484|    364|  });
  485|    364|  ednsAdded = true;
  486|    364|  ecsAdded = true;
  487|       |
  488|    364|  return true;
  489|    364|}
dnsdist-ecs.cc:_ZZL14addEDNSWithECSRNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEEmRKNS_12basic_stringIcNS_11char_traitsIcEENS2_IcEEEERbSE_ENK3$_0clER9dnsheader:
  479|    364|  dnsdist::PacketMangling::editDNSHeaderFromPacket(packet, [](dnsheader& header) {
  480|    364|    uint16_t arcount = ntohs(header.arcount);
  481|    364|    arcount++;
  482|       |    header.arcount = htons(arcount);
  483|    364|    return true;
  484|    364|  });
dnsdist-ecs.cc:_ZL29replaceEDNSClientSubnetOptionRNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEEmmmmRKNS_12basic_stringIcNS_11char_traitsIcEENS2_IcEEEE:
  368|    246|{
  369|    246|  if (oldEcsOptionStartPosition >= packet.size() || optRDLenPosition >= packet.size()) {
  ------------------
  |  Branch (369:7): [True: 0, False: 246]
  |  Branch (369:53): [True: 0, False: 246]
  ------------------
  370|      0|    throw std::runtime_error("Invalid values passed to replaceEDNSClientSubnetOption");
  371|      0|  }
  372|       |
  373|    246|  if (newECSOption.size() == oldEcsOptionSize) {
  ------------------
  |  Branch (373:7): [True: 3, False: 243]
  ------------------
  374|       |    /* same size as the existing option */
  375|      3|    memcpy(&packet.at(oldEcsOptionStartPosition), newECSOption.c_str(), oldEcsOptionSize);
  376|      3|  }
  377|    243|  else {
  378|       |    /* different size than the existing option */
  379|    243|    const unsigned int newPacketLen = packet.size() + (newECSOption.length() - oldEcsOptionSize);
  380|    243|    const size_t beforeOptionLen = oldEcsOptionStartPosition;
  381|    243|    const size_t dataBehindSize = packet.size() - beforeOptionLen - oldEcsOptionSize;
  382|       |
  383|       |    /* check that it fits in the existing buffer */
  384|    243|    if (newPacketLen > packet.size()) {
  ------------------
  |  Branch (384:9): [True: 179, False: 64]
  ------------------
  385|    179|      if (newPacketLen > maximumSize) {
  ------------------
  |  Branch (385:11): [True: 0, False: 179]
  ------------------
  386|      0|        return false;
  387|      0|      }
  388|       |
  389|    179|      packet.resize(newPacketLen);
  390|    179|    }
  391|       |
  392|       |    /* fix the size of ECS Option RDLen */
  393|    243|    uint16_t newRDLen = (packet.at(optRDLenPosition) * 256) + packet.at(optRDLenPosition + 1);
  394|    243|    newRDLen += (newECSOption.size() - oldEcsOptionSize);
  395|    243|    packet.at(optRDLenPosition) = newRDLen / 256;
  396|    243|    packet.at(optRDLenPosition + 1) = newRDLen % 256;
  397|       |
  398|    243|    if (dataBehindSize > 0) {
  ------------------
  |  Branch (398:9): [True: 225, False: 18]
  ------------------
  399|    225|      memmove(&packet.at(oldEcsOptionStartPosition), &packet.at(oldEcsOptionStartPosition + oldEcsOptionSize), dataBehindSize);
  400|    225|    }
  401|    243|    memcpy(&packet.at(oldEcsOptionStartPosition + dataBehindSize), newECSOption.c_str(), newECSOption.size());
  402|    243|    packet.resize(newPacketLen);
  403|    243|  }
  404|       |
  405|    246|  return true;
  406|    246|}
dnsdist-ecs.cc:_ZL19addECSToExistingOPTRNSt3__16vectorIh14noinit_adaptorINS_9allocatorIhEEEEEmRKNS_12basic_stringIcNS_11char_traitsIcEENS2_IcEEEEmRb:
  443|    193|{
  444|       |  /* we need to add one EDNS0 ECS option, fixing the size of EDNS0 RDLENGTH */
  445|       |  /* getEDNSOptionsStart has already checked that there is exactly one AR,
  446|       |     no NS and no AN */
  447|    193|  uint16_t oldRDLen = (packet.at(optRDLenPosition) * 256) + packet.at(optRDLenPosition + 1);
  448|    193|  if (packet.size() != (optRDLenPosition + sizeof(uint16_t) + oldRDLen)) {
  ------------------
  |  Branch (448:7): [True: 112, False: 81]
  ------------------
  449|       |    /* we are supposed to be the last record, do we have some trailing data to remove? */
  450|       |    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
  451|    112|    uint32_t realPacketLen = getDNSPacketLength(reinterpret_cast<const char*>(packet.data()), packet.size());
  452|    112|    packet.resize(realPacketLen);
  453|    112|  }
  454|       |
  455|    193|  if ((maximumSize - packet.size()) < newECSOption.size()) {
  ------------------
  |  Branch (455:7): [True: 0, False: 193]
  ------------------
  456|      0|    return false;
  457|      0|  }
  458|       |
  459|    193|  const uint32_t computedRDLen = static_cast<uint32_t>(oldRDLen) + newECSOption.size();
  460|    193|  if (computedRDLen > std::numeric_limits<uint16_t>::max()) {
  ------------------
  |  Branch (460:7): [True: 0, False: 193]
  ------------------
  461|      0|    return false;
  462|      0|  }
  463|    193|  const auto newRDLen = static_cast<uint16_t>(computedRDLen);
  464|    193|  packet.at(optRDLenPosition) = newRDLen / 256;
  465|    193|  packet.at(optRDLenPosition + 1) = newRDLen % 256;
  466|       |
  467|    193|  packet.insert(packet.end(), newECSOption.begin(), newECSOption.end());
  468|    193|  ecsAdded = true;
  469|       |
  470|    193|  return true;
  471|    193|}
dnsdist-ecs.cc:_ZL27removeEDNSOptionFromOptionsPhttPt:
  573|  5.03k|{
  574|  5.03k|  const pdns::views::UnsignedCharView view(optionsStart, optionsLen);
  575|  5.03k|  size_t pos = 0;
  576|  48.2k|  while ((pos + 4) <= view.size()) {
  ------------------
  |  Branch (576:10): [True: 45.2k, False: 3.06k]
  ------------------
  577|  45.2k|    size_t optionBeginPos = pos;
  578|  45.2k|    const uint16_t optionCode = 0x100 * view.at(pos) + view.at(pos + 1);
  579|  45.2k|    pos += sizeof(optionCode);
  580|  45.2k|    const uint16_t optionLen = 0x100 * view.at(pos) + view.at(pos + 1);
  581|  45.2k|    pos += sizeof(optionLen);
  582|  45.2k|    if ((pos + optionLen) > view.size()) {
  ------------------
  |  Branch (582:9): [True: 686, False: 44.5k]
  ------------------
  583|    686|      return EINVAL;
  584|    686|    }
  585|  44.5k|    if (optionCode == optionCodeToRemove) {
  ------------------
  |  Branch (585:9): [True: 1.28k, False: 43.2k]
  ------------------
  586|  1.28k|      if (pos + optionLen < view.size()) {
  ------------------
  |  Branch (586:11): [True: 837, False: 449]
  ------------------
  587|       |        /* move remaining options over the removed one,
  588|       |           if any */
  589|       |        // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  590|    837|        memmove(optionsStart + optionBeginPos, optionsStart + pos + optionLen, optionsLen - (pos + optionLen));
  591|    837|      }
  592|  1.28k|      *newOptionsLen = optionsLen - (sizeof(optionCode) + sizeof(optionLen) + optionLen);
  593|  1.28k|      return 0;
  594|  1.28k|    }
  595|  43.2k|    pos += optionLen;
  596|  43.2k|  }
  597|  3.06k|  return ENOENT;
  598|  5.03k|}

_ZN7dnsdist7metrics5StatsC2Ev:
   80|      2|  entries{std::vector<EntryTriple>{
   81|      2|    {"responses", "", &responses},
   82|      2|    {"servfail-responses", "", &servfailResponses},
   83|      2|    {"queries", "", &queries},
   84|      2|    {"frontend-nxdomain", "", &frontendNXDomain},
   85|      2|    {"frontend-servfail", "", &frontendServFail},
   86|      2|    {"frontend-noerror", "", &frontendNoError},
   87|      2|    {"acl-drops", "", &aclDrops},
   88|      2|    {"rule-drop", "", &ruleDrop},
   89|      2|    {"rule-nxdomain", "", &ruleNXDomain},
   90|      2|    {"rule-refused", "", &ruleRefused},
   91|      2|    {"rule-servfail", "", &ruleServFail},
   92|      2|    {"rule-truncated", "", &ruleTruncated},
   93|      2|    {"self-answered", "", &selfAnswered},
   94|      2|    {"downstream-timeouts", "", &downstreamTimeouts},
   95|      2|    {"downstream-send-errors", "", &downstreamSendErrors},
   96|      2|    {"trunc-failures", "", &truncFail},
   97|      2|    {"no-policy", "", &noPolicy},
   98|      2|    {"latency0-1", "", &latency0_1},
   99|      2|    {"latency1-10", "", &latency1_10},
  100|      2|    {"latency10-50", "", &latency10_50},
  101|      2|    {"latency50-100", "", &latency50_100},
  102|      2|    {"latency100-1000", "", &latency100_1000},
  103|      2|    {"latency-slow", "", &latencySlow},
  104|      2|    {"latency-avg100", "", &latencyAvg100},
  105|      2|    {"latency-avg1000", "", &latencyAvg1000},
  106|      2|    {"latency-avg10000", "", &latencyAvg10000},
  107|      2|    {"latency-avg1000000", "", &latencyAvg1000000},
  108|      2|    {"latency-tcp-avg100", "", &latencyTCPAvg100},
  109|      2|    {"latency-tcp-avg1000", "", &latencyTCPAvg1000},
  110|      2|    {"latency-tcp-avg10000", "", &latencyTCPAvg10000},
  111|      2|    {"latency-tcp-avg1000000", "", &latencyTCPAvg1000000},
  112|      2|    {"latency-dot-avg100", "", &latencyDoTAvg100},
  113|      2|    {"latency-dot-avg1000", "", &latencyDoTAvg1000},
  114|      2|    {"latency-dot-avg10000", "", &latencyDoTAvg10000},
  115|      2|    {"latency-dot-avg1000000", "", &latencyDoTAvg1000000},
  116|      2|    {"latency-doh-avg100", "", &latencyDoHAvg100},
  117|      2|    {"latency-doh-avg1000", "", &latencyDoHAvg1000},
  118|      2|    {"latency-doh-avg10000", "", &latencyDoHAvg10000},
  119|      2|    {"latency-doh-avg1000000", "", &latencyDoHAvg1000000},
  120|      2|    {"latency-doq-avg100", "", &latencyDoQAvg100},
  121|      2|    {"latency-doq-avg1000", "", &latencyDoQAvg1000},
  122|      2|    {"latency-doq-avg10000", "", &latencyDoQAvg10000},
  123|      2|    {"latency-doq-avg1000000", "", &latencyDoQAvg1000000},
  124|      2|    {"latency-doh3-avg100", "", &latencyDoH3Avg100},
  125|      2|    {"latency-doh3-avg1000", "", &latencyDoH3Avg1000},
  126|      2|    {"latency-doh3-avg10000", "", &latencyDoH3Avg10000},
  127|      2|    {"latency-doh3-avg1000000", "", &latencyDoH3Avg1000000},
  128|      2|    {"uptime", "", uptimeOfProcess},
  129|      2|    {"real-memory-usage", "", getRealMemoryUsage},
  130|      2|    {"special-memory-usage", "", getSpecialMemoryUsage},
  131|      2|    {"udp-in-errors", "", [](const std::string&) { return udpErrorStats("udp-in-errors"); }},
  132|      2|    {"udp-noport-errors", "", [](const std::string&) { return udpErrorStats("udp-noport-errors"); }},
  133|      2|    {"udp-recvbuf-errors", "", [](const std::string&) { return udpErrorStats("udp-recvbuf-errors"); }},
  134|      2|    {"udp-sndbuf-errors", "", [](const std::string&) { return udpErrorStats("udp-sndbuf-errors"); }},
  135|      2|    {"udp-in-csum-errors", "", [](const std::string&) { return udpErrorStats("udp-in-csum-errors"); }},
  136|      2|    {"udp6-in-errors", "", [](const std::string&) { return udp6ErrorStats("udp6-in-errors"); }},
  137|      2|    {"udp6-recvbuf-errors", "", [](const std::string&) { return udp6ErrorStats("udp6-recvbuf-errors"); }},
  138|      2|    {"udp6-sndbuf-errors", "", [](const std::string&) { return udp6ErrorStats("udp6-sndbuf-errors"); }},
  139|      2|    {"udp6-noport-errors", "", [](const std::string&) { return udp6ErrorStats("udp6-noport-errors"); }},
  140|      2|    {"udp6-in-csum-errors", "", [](const std::string&) { return udp6ErrorStats("udp6-in-csum-errors"); }},
  141|      2|    {"tcp-listen-overflows", "", [](const std::string&) { return tcpErrorStats("ListenOverflows"); }},
  142|      2|    {"noncompliant-queries", "", &nonCompliantQueries},
  143|      2|    {"noncompliant-responses", "", &nonCompliantResponses},
  144|      2|    {"proxy-protocol-invalid", "", &proxyProtocolInvalid},
  145|      2|    {"rdqueries", "", &rdQueries},
  146|      2|    {"empty-queries", "", &emptyQueries},
  147|      2|    {"cache-hits", "", &cacheHits},
  148|      2|    {"cache-misses", "", &cacheMisses},
  149|      2|    {"cpu-iowait", "", getCPUIOWait},
  150|      2|    {"cpu-steal", "", getCPUSteal},
  151|      2|    {"cpu-sys-msec", "", getCPUTimeSystem},
  152|      2|    {"cpu-user-msec", "", getCPUTimeUser},
  153|      2|    {"fd-usage", "", getOpenFileDescriptors},
  154|      2|    {"dyn-blocked", "", &dynBlocked},
  155|      2|#ifndef DISABLE_DYNBLOCKS
  156|      2|    {"dyn-block-nmg-size", "", [](const std::string&) { return dnsdist::DynamicBlocks::getClientAddressDynamicRules().size(); }},
  157|      2|#endif /* DISABLE_DYNBLOCKS */
  158|      2|    {"security-status", "", &securityStatus},
  159|      2|    {"doh-query-pipe-full", "", &dohQueryPipeFull},
  160|      2|    {"doh-response-pipe-full", "", &dohResponsePipeFull},
  161|      2|    {"doq-response-pipe-full", "", &doqResponsePipeFull},
  162|      2|    {"doh3-response-pipe-full", "", &doh3ResponsePipeFull},
  163|      2|    {"outgoing-doh-query-pipe-full", "", &outgoingDoHQueryPipeFull},
  164|      2|    {"tcp-query-pipe-full", "", &tcpQueryPipeFull},
  165|      2|    {"tcp-cross-protocol-query-pipe-full", "", &tcpCrossProtocolQueryPipeFull},
  166|      2|    {"tcp-cross-protocol-response-pipe-full", "", &tcpCrossProtocolResponsePipeFull},
  167|       |    // Latency histogram
  168|      2|    {"latency-sum", "", &latencySum},
  169|      2|    {"latency-count", "", &latencyCount},
  170|      2|  }}
  171|      2|{
  172|      2|}

_ZN16MetricDefinitionC2E20PrometheusMetricTypeRKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_:
   51|    162|    description(_description), customName(customName_), prometheusType(_prometheusType)
   52|    162|  {
   53|    162|  }

_ZN7dnsdist10QueryCount13ConfigurationC2Ev:
   39|      2|  Configuration() = default;

_ZN7dnsdist3udp22UDPTCPCrossQuerySenderC2Ev:
   77|      2|  UDPTCPCrossQuerySender() = default;

_ZN7DNSNameC2ENSt3__117basic_string_viewIcNS0_11char_traitsIcEEEE:
   77|     32|{
   78|     32|  if (content.empty() || (content.size() == 1 && content.at(0) == '.')) {
  ------------------
  |  Branch (78:7): [True: 0, False: 32]
  |  Branch (78:27): [True: 6, False: 26]
  |  Branch (78:50): [True: 4, False: 2]
  ------------------
   79|      4|    d_storage.assign(1U, '\0');
   80|      4|    return;
   81|      4|  }
   82|       |
   83|     28|  if (std::memchr(content.data(), '\\', content.size()) != nullptr) {
  ------------------
  |  Branch (83:7): [True: 0, False: 28]
  ------------------
   84|      0|    d_storage = segmentDNSNameRaw(content.data(), content.size());
   85|      0|    if (d_storage.size() > s_maxDNSNameLength) {
  ------------------
  |  Branch (85:9): [True: 0, False: 0]
  ------------------
   86|      0|      throwSafeRangeError("name too long: ", content);
   87|      0|    }
   88|      0|    return;
   89|      0|  }
   90|       |
   91|     28|  unsigned char lenpos = 0;
   92|     28|  unsigned char labellen = 0;
   93|       |
   94|     28|  d_storage.reserve(content.size() + 1U);
   95|     66|  for (size_t position = 0; position < content.size(); ) {
  ------------------
  |  Branch (95:29): [True: 38, False: 28]
  ------------------
   96|     38|    lenpos = d_storage.size();
   97|     38|    if (content.at(position) == '.') {
  ------------------
  |  Branch (97:9): [True: 0, False: 38]
  ------------------
   98|      0|      throwSafeRangeError("Found . in wrong position in DNSName: ", content);
   99|      0|    }
  100|     38|    d_storage.append(1U, '\0');
  101|     38|    labellen = 0;
  102|     38|    size_t begPosition = position;
  103|    292|    for(; position < content.size() && content.at(position) != '.'; ++position) {
  ------------------
  |  Branch (103:11): [True: 266, False: 26]
  |  Branch (103:40): [True: 254, False: 12]
  ------------------
  104|    254|      labellen++;
  105|    254|    }
  106|       |    // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  107|     38|    d_storage.append(content.begin() + begPosition, content.begin() + position);
  108|     38|    if (position < content.size()) {
  ------------------
  |  Branch (108:9): [True: 12, False: 26]
  ------------------
  109|     12|      ++position;
  110|     12|    }
  111|     38|    if (labellen > s_maxDNSLabelLength) {
  ------------------
  |  Branch (111:9): [True: 0, False: 38]
  ------------------
  112|      0|      throwSafeRangeError("label too long to append: ", content);
  113|      0|    }
  114|       |
  115|     38|    if (position > s_maxDNSNameLength - 1U) {
  ------------------
  |  Branch (115:9): [True: 0, False: 38]
  ------------------
  116|       |      // reserve two bytes, one for length and one for the root label
  117|      0|      throwSafeRangeError("name too long to append: ", content);
  118|      0|    }
  119|       |
  120|     38|    d_storage.at(lenpos) = static_cast<char>(labellen);
  121|     38|  }
  122|     28|  if (d_storage.size() > s_maxDNSNameLength - 1U) {
  ------------------
  |  Branch (122:7): [True: 0, False: 28]
  ------------------
  123|      0|    throwSafeRangeError("name too long: ", content);
  124|      0|  }
  125|     28|  d_storage.append(1U, '\0');
  126|     28|}
_ZN7DNSNameC2EPKcmmbPtS2_PjtPm:
  129|   509k|{
  130|   509k|  if (offset >= len)
  ------------------
  |  Branch (130:7): [True: 3.82k, False: 505k]
  ------------------
  131|  3.82k|    throw std::range_error("Trying to read past the end of the buffer ("+std::to_string(offset)+ " >= "+std::to_string(len)+")");
  132|       |
  133|   505k|  if(!uncompress) {
  ------------------
  |  Branch (133:6): [True: 2.94k, False: 502k]
  ------------------
  134|  2.94k|    if(const void * fnd=memchr(pos+offset, 0, len-offset)) {
  ------------------
  |  Branch (134:21): [True: 2.88k, False: 63]
  ------------------
  135|  2.88k|      d_storage.reserve(2+(const char*)fnd-(pos+offset));
  136|  2.88k|    }
  137|  2.94k|  }
  138|       |
  139|   505k|  packetParser(pos, len, offset, uncompress, qtype, qclass, consumed, 0, minOffset, 0, pointerBudget);
  140|   505k|}
_ZN7DNSName23parsePacketUncompressedERKN4pdns5views16UnsignedCharViewEmb:
  154|   702k|{
  155|   702k|  const size_t initialPos = pos;
  156|   702k|  auto existingSize = d_storage.size();
  157|   702k|  const size_t neededSizeForFinalLabel = /* final empty label length */ (existingSize == 0 ? 1U : 0U);
  ------------------
  |  Branch (157:74): [True: 606k, False: 96.1k]
  ------------------
  158|   702k|  size_t totalLength = 0;
  159|   702k|  unsigned char labellen = 0;
  160|       |
  161|  5.17M|  do {
  162|  5.17M|    labellen = view.at(pos);
  163|  5.17M|    ++pos;
  164|       |
  165|  5.17M|    if (labellen == 0) {
  ------------------
  |  Branch (165:9): [True: 504k, False: 4.67M]
  ------------------
  166|   504k|      --pos;
  167|   504k|      break;
  168|   504k|    }
  169|       |
  170|  4.67M|    if (labellen >= 0xc0) {
  ------------------
  |  Branch (170:9): [True: 197k, False: 4.47M]
  ------------------
  171|   197k|      if (!uncompress) {
  ------------------
  |  Branch (171:11): [True: 64, False: 197k]
  ------------------
  172|     64|        throw std::range_error("Found compressed label, instructed not to follow");
  173|     64|      }
  174|   197k|      --pos;
  175|   197k|      break;
  176|   197k|    }
  177|       |
  178|  4.47M|    if ((labellen & 0xc0) != 0) {
  ------------------
  |  Branch (178:9): [True: 358, False: 4.47M]
  ------------------
  179|    358|      throw std::range_error("Found an invalid label length in qname (only one of the first two bits is set)");
  180|    358|    }
  181|  4.47M|    checkLabelLength(labellen);
  182|       |
  183|       |    // reserve one byte for the label length, plus one byte for the final empty label if we were empty before
  184|  4.47M|    if ((existingSize + totalLength + labellen + 1U + neededSizeForFinalLabel) > s_maxDNSNameLength) {
  ------------------
  |  Branch (184:9): [True: 33, False: 4.47M]
  ------------------
  185|     33|      throw std::range_error("name too long to append");
  186|     33|    }
  187|  4.47M|    if (pos + labellen >= view.size()) {
  ------------------
  |  Branch (187:9): [True: 453, False: 4.47M]
  ------------------
  188|    453|      throw std::range_error("Found an invalid label length in qname");
  189|    453|    }
  190|  4.47M|    pos += labellen;
  191|  4.47M|    totalLength += 1U + labellen;
  192|  4.47M|  }
  193|  4.47M|  while (pos < view.size());
  ------------------
  |  Branch (193:10): [True: 4.47M, False: 0]
  ------------------
  194|       |
  195|   702k|  if (totalLength != 0) {
  ------------------
  |  Branch (195:7): [True: 249k, False: 452k]
  ------------------
  196|   249k|    if (existingSize > 0) {
  ------------------
  |  Branch (196:9): [True: 95.5k, False: 153k]
  ------------------
  197|       |      // remove the last label count, we are about to override it */
  198|  95.5k|      --existingSize;
  199|  95.5k|    }
  200|   249k|    if ((existingSize + totalLength + 1U) > s_maxDNSNameLength) {
  ------------------
  |  Branch (200:9): [True: 0, False: 249k]
  ------------------
  201|      0|      throw std::range_error("name too long to append");
  202|      0|    }
  203|   249k|    d_storage.reserve(existingSize + totalLength + 1);
  204|   249k|    d_storage.resize(existingSize + totalLength);
  205|   249k|    memcpy(&d_storage.at(existingSize), &view.at(initialPos), totalLength);
  206|   249k|    d_storage.append(1, static_cast<char>(0));
  207|   249k|  }
  208|   702k|  return pos;
  209|   702k|}
_ZN7DNSName12packetParserEPKcmmbPtS2_PjittPm:
  213|   702k|{
  214|   702k|  if (offset >= len) {
  ------------------
  |  Branch (214:7): [True: 0, False: 702k]
  ------------------
  215|      0|    throw std::range_error("Trying to read past the end of the buffer ("+std::to_string(offset)+ " >= "+std::to_string(len)+")");
  216|      0|  }
  217|       |
  218|   702k|  if (offset < static_cast<size_t>(minOffset)) {
  ------------------
  |  Branch (218:7): [True: 0, False: 702k]
  ------------------
  219|      0|    throw std::range_error("Trying to read before the beginning of the buffer ("+std::to_string(offset)+ " < "+std::to_string(minOffset)+")");
  220|      0|  }
  221|   702k|  unsigned char labellen{0};
  222|       |
  223|   702k|  pdns::views::UnsignedCharView view(qpos, len);
  224|   702k|  auto pos = parsePacketUncompressed(view, offset, uncompress);
  225|       |
  226|       |
  227|   702k|  labellen = view.at(pos);
  228|   702k|  if (pos == offset && labellen != 0) {
  ------------------
  |  Branch (228:7): [True: 452k, False: 250k]
  |  Branch (228:24): [True: 101k, False: 351k]
  ------------------
  229|       |    // It's a pointer
  230|   101k|    if (pointerBudget != nullptr) {
  ------------------
  |  Branch (230:9): [True: 101k, False: 0]
  ------------------
  231|   101k|      if (*pointerBudget == 0) {
  ------------------
  |  Branch (231:11): [True: 0, False: 101k]
  ------------------
  232|      0|        throw std::range_error("Too many compression pointers processed in packet");
  233|      0|      }
  234|   101k|      (*pointerBudget)--;
  235|   101k|    }
  236|       |    // Are we chasing a pointer chain already for this name?
  237|   101k|    if (pointerChainLength++ > s_maxPointersToPointers) {
  ------------------
  |  Branch (237:9): [True: 11, False: 101k]
  ------------------
  238|     11|      throw std::range_error("Too many pointer to pointers during decompression (" + std::to_string(pointerChainLength) + ")");
  239|     11|    }
  240|   101k|  }
  241|   601k|  else {
  242|   601k|    pointerChainLength = 0; // not an immediate pointer to pointer case any more
  243|   601k|  }
  244|   702k|  pos++;
  245|   702k|  if (labellen != 0 && pos < view.size()) {
  ------------------
  |  Branch (245:7): [True: 197k, False: 505k]
  |  Branch (245:24): [True: 197k, False: 522]
  ------------------
  246|   197k|    if (labellen < 0xc0) {
  ------------------
  |  Branch (246:9): [True: 0, False: 197k]
  ------------------
  247|      0|      throw std::range_error("Invalid label byte during decompression ("+std::to_string(labellen)+")");
  248|      0|    }
  249|       |
  250|   197k|    if (!uncompress) {
  ------------------
  |  Branch (250:9): [True: 0, False: 197k]
  ------------------
  251|      0|      throw std::range_error("Found compressed label, instructed not to follow");
  252|      0|    }
  253|       |
  254|   197k|    labellen &= (~0xc0);
  255|   197k|    size_t newpos = (labellen << 8) + view.at(pos);
  256|       |
  257|   197k|    if (newpos >= offset) {
  ------------------
  |  Branch (257:9): [True: 339, False: 197k]
  ------------------
  258|    339|      throw std::range_error("Found a forward reference during label decompression");
  259|    339|    }
  260|       |
  261|   197k|    if (newpos < minOffset) {
  ------------------
  |  Branch (261:9): [True: 42, False: 196k]
  ------------------
  262|     42|      throw std::range_error("Invalid label position during decompression ("+std::to_string(newpos)+ " < "+std::to_string(minOffset)+")");
  263|     42|    }
  264|       |
  265|   196k|    if (++depth > s_maxPointersPerName) {
  ------------------
  |  Branch (265:9): [True: 6, False: 196k]
  ------------------
  266|      6|      throw std::range_error("Abort label decompression after too many redirects (" + std::to_string(depth) + ")");
  267|      6|    }
  268|       |
  269|   196k|    packetParser(qpos, len, newpos, true, nullptr, nullptr, nullptr, depth, minOffset, pointerChainLength, pointerBudget);
  270|       |
  271|   196k|    pos++;
  272|   196k|  }
  273|       |
  274|   702k|  if (d_storage.empty()) {
  ------------------
  |  Branch (274:7): [True: 351k, False: 351k]
  ------------------
  275|   351k|    d_storage.append(1, static_cast<char>(0)); // we just parsed the root
  276|   351k|  }
  277|       |
  278|   702k|  if (consumed != nullptr) {
  ------------------
  |  Branch (278:7): [True: 504k, False: 197k]
  ------------------
  279|   504k|    *consumed = pos - offset;
  280|   504k|  }
  281|       |
  282|   702k|  if (qtype != nullptr) {
  ------------------
  |  Branch (282:7): [True: 2.81k, False: 699k]
  ------------------
  283|  2.81k|    if (pos + 2 > view.size()) {
  ------------------
  |  Branch (283:9): [True: 45, False: 2.76k]
  ------------------
  284|     45|      throw std::range_error("Trying to read qtype past the end of the buffer ("+std::to_string(pos + 2)+ " > "+std::to_string(len)+")");
  285|     45|    }
  286|  2.76k|    *qtype = view.at(pos)*256 + view.at(pos+1);
  287|  2.76k|  }
  288|       |
  289|   702k|  pos += 2;
  290|   702k|  if (qclass != nullptr) {
  ------------------
  |  Branch (290:7): [True: 2.76k, False: 699k]
  ------------------
  291|  2.76k|    if (pos + 2 > view.size()) {
  ------------------
  |  Branch (291:9): [True: 15, False: 2.75k]
  ------------------
  292|     15|      throw std::range_error("Trying to read qclass past the end of the buffer ("+std::to_string(pos + 2)+ " > "+std::to_string(len)+")");
  293|     15|    }
  294|  2.75k|    *qclass = view.at(pos)*256 + view.at(pos+1);
  295|  2.75k|  }
  296|   702k|}
_ZNK7DNSName10wirelengthEv:
  367|  6.86k|size_t DNSName::wirelength() const {
  368|  6.86k|  return d_storage.length();
  369|  6.86k|}
dnsname.cc:_ZL16checkLabelLengthh:
  143|  4.47M|{
  144|  4.47M|  if (length == 0) {
  ------------------
  |  Branch (144:7): [True: 0, False: 4.47M]
  ------------------
  145|      0|    throw std::range_error("no such thing as an empty label to append");
  146|      0|  }
  147|  4.47M|  if (length > DNSName::s_maxDNSLabelLength) {
  ------------------
  |  Branch (147:7): [True: 0, False: 4.47M]
  ------------------
  148|      0|    throw std::range_error("label too long to append");
  149|      0|  }
  150|  4.47M|}

_Z11dns_tolowerh:
   58|   129k|{
   59|   129k|  return dns_tolower_table[chr];
   60|   129k|}
_Z39pdns_ilexicographical_compare_three_wayNSt3__117basic_string_viewIcNS_11char_traitsIcEEEES3_:
   64|   144k|{
   65|   144k|  const unsigned char *aPtr = (const unsigned char*)a.data(), *bPtr = (const unsigned char*)b.data();
   66|   144k|  const unsigned char *aEptr = aPtr + a.length(), *bEptr = bPtr + b.length();
   67|   741k|  while(aPtr != aEptr && bPtr != bEptr) {
  ------------------
  |  Branch (67:9): [True: 626k, False: 115k]
  |  Branch (67:26): [True: 626k, False: 0]
  ------------------
   68|   626k|    if (*aPtr != *bPtr) {
  ------------------
  |  Branch (68:9): [True: 29.3k, False: 596k]
  ------------------
   69|  29.3k|      if (int rc = dns_tolower(*aPtr) - dns_tolower(*bPtr); rc != 0) {
  ------------------
  |  Branch (69:61): [True: 29.1k, False: 228]
  ------------------
   70|  29.1k|        return rc;
   71|  29.1k|      }
   72|  29.3k|    }
   73|   597k|    aPtr++;
   74|   597k|    bPtr++;
   75|   597k|  }
   76|       |  // At this point, one of the strings has been completely processed.
   77|       |  // Either both have the same length, and they are equal, or one of them
   78|       |  // is larger, and compares as higher.
   79|   115k|  if (aPtr == aEptr) {
  ------------------
  |  Branch (79:7): [True: 115k, False: 0]
  ------------------
   80|   115k|    if (bPtr != bEptr) {
  ------------------
  |  Branch (80:9): [True: 0, False: 115k]
  ------------------
   81|      0|      return -1; // a < b
   82|      0|    }
   83|   115k|  }
   84|      0|  else {
   85|      0|    return 1; // a > b
   86|      0|  }
   87|   115k|  return 0; // a == b
   88|   115k|}
_ZN7DNSNameaSEOS_:
  158|   497k|  {
  159|   497k|    if (this != &rhs) {
  ------------------
  |  Branch (159:9): [True: 497k, False: 0]
  ------------------
  160|   497k|      d_storage = std::move(rhs.d_storage);
  161|   497k|    }
  162|   497k|    return *this;
  163|   497k|  }
_ZNK7DNSName5emptyEv:
  210|   283k|  bool empty() const { return d_storage.empty(); }
_ZNK7DNSName6isRootEv:
  211|   336k|  bool isRoot() const { return d_storage.size()==1 && d_storage[0]==0; }
  ------------------
  |  Branch (211:32): [True: 136k, False: 199k]
  |  Branch (211:55): [True: 136k, False: 0]
  ------------------
_ZNK7DNSName10getStorageEv:
  261|   154k|  const string_t& getStorage() const {
  262|   154k|    return d_storage;
  263|   154k|  }
_ZNK7DNSNameeqERKS_:
  826|  76.8k|{
  827|  76.8k|  if (rhs.empty() != empty() || rhs.d_storage.size() != d_storage.size()) {
  ------------------
  |  Branch (827:7): [True: 0, False: 76.8k]
  |  Branch (827:33): [True: 70.9k, False: 5.92k]
  ------------------
  828|  70.9k|    return false;
  829|  70.9k|  }
  830|       |
  831|  5.92k|  const auto* us = d_storage.cbegin();
  832|  5.92k|  const auto* p = rhs.d_storage.cbegin();
  833|  36.2k|  for (; us != d_storage.cend() && p != rhs.d_storage.cend(); ++us, ++p) {
  ------------------
  |  Branch (833:10): [True: 35.3k, False: 950]
  |  Branch (833:36): [True: 35.3k, False: 0]
  ------------------
  834|  35.3k|    if (dns_tolower(*p) != dns_tolower(*us)) {
  ------------------
  |  Branch (834:9): [True: 4.97k, False: 30.3k]
  ------------------
  835|  4.97k|      return false;
  836|  4.97k|    }
  837|  35.3k|  }
  838|    950|  return true;
  839|  5.92k|}
_ZN7DNSNameC2ERKS_:
  164|  6.86k|  DNSName(const DNSName& a) = default;
_ZN7DNSNameC2Ev:
  148|  7.07k|  DNSName() = default; //!< Constructs an *empty* DNSName, NOT the root!
_ZN15SuffixMatchTreeI8DynBlockEC2ENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEb:
  465|      2|    d_name(std::move(name)), endNode(endNode_)
  466|      2|  {}

_ZN12PacketReader18getDnsrecordheaderER15dnsrecordheader:
  480|   198k|{
  481|   198k|  unsigned char *p = reinterpret_cast<unsigned char*>(&ah);
  482|       |
  483|  2.16M|  for(unsigned int n = 0; n < sizeof(dnsrecordheader); ++n) {
  ------------------
  |  Branch (483:27): [True: 1.97M, False: 198k]
  ------------------
  484|  1.97M|    p[n] = d_content.at(d_pos++);
  485|  1.97M|  }
  486|       |
  487|   198k|  ah.d_type = ntohs(ah.d_type);
  488|   198k|  ah.d_class = ntohs(ah.d_class);
  489|   198k|  ah.d_clen = ntohs(ah.d_clen);
  490|   198k|  ah.d_ttl = ntohl(ah.d_ttl);
  491|       |
  492|   198k|  d_startrecordpos = d_pos; // needed for getBlob later on
  493|   198k|  d_recordlen = ah.d_clen;
  494|   198k|  if (d_pos > d_content.size() || (d_content.size() - d_pos) < (d_recordlen)) {
  ------------------
  |  Branch (494:7): [True: 1.96k, False: 196k]
  |  Branch (494:35): [True: 443, False: 196k]
  ------------------
  495|    443|    throw std::out_of_range("DNS record length (" + std::to_string(d_recordlen) + " starting at " + std::to_string(d_pos) + ") goes beyond the packet's content (" + std::to_string(d_content.size()) + ")");
  496|    443|  }
  497|   198k|}
_ZN12PacketReader11get16BitIntEv:
  583|   597k|{
  584|   597k|  uint16_t ret=0;
  585|   597k|  if (!isWithinRecordBoundaries(d_pos, d_pos + sizeof(ret))) {
  ------------------
  |  Branch (585:7): [True: 0, False: 597k]
  ------------------
  586|      0|    throw std::out_of_range("Attempt to read 16 bit value outside of record");
  587|      0|  }
  588|   597k|  ret+=static_cast<uint8_t>(d_content.at(d_pos++));
  589|   597k|  ret<<=8;
  590|   597k|  ret+=static_cast<uint8_t>(d_content.at(d_pos++));
  591|       |
  592|   597k|  return ret;
  593|   597k|}
_ZN12PacketReader7getNameEv:
  604|   506k|{
  605|   506k|  unsigned int consumed{0};
  606|   506k|  const auto initialPosition = d_pos;
  607|   506k|  try {
  608|   506k|    uint16_t minOffset = d_standalone ? 0 : sizeof(dnsheader);
  ------------------
  |  Branch (608:26): [True: 0, False: 506k]
  ------------------
  609|   506k|    bool uncompress = !d_standalone;
  610|       |
  611|   506k|    DNSName name((const char*) d_content.data(), d_content.size(), d_pos, uncompress, nullptr /* qtype */, nullptr /* qclass */, &consumed, minOffset, &d_pointerBudget);
  612|       |
  613|   506k|    d_pos += consumed;
  614|       |    // if we know the length of the record, and we were parsing a DNS name inside the record contents
  615|       |    // (not the owner name, in which case d_startrecordpos and d_recordlen still refer to the content of the previous record),
  616|       |    // check that we did not go over the record boundary
  617|   506k|    if (!isWithinRecordBoundaries(initialPosition, d_pos, true)) {
  ------------------
  |  Branch (617:9): [True: 0, False: 506k]
  ------------------
  618|      0|      throw std::out_of_range("Attempt to read DNS name outside of record");
  619|      0|    }
  620|   506k|    return name;
  621|   506k|  }
  622|   506k|  catch(const std::range_error& re) {
  623|  4.96k|    throw std::out_of_range(string("dnsname issue: ")+re.what());
  624|  4.96k|  }
  625|   506k|  catch(...) {
  626|      0|    throw std::out_of_range("dnsname issue");
  627|      0|  }
  628|   506k|}
_ZN12PacketReader7xfrBlobERNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE:
  727|   123k|{
  728|   123k|  try {
  729|   123k|    if (d_recordlen != 0 && !(d_pos == (d_startrecordpos + d_recordlen))) {
  ------------------
  |  Branch (729:9): [True: 54.8k, False: 69.0k]
  |  Branch (729:29): [True: 54.8k, False: 0]
  ------------------
  730|  54.8k|      if (d_pos > (d_startrecordpos + d_recordlen)) {
  ------------------
  |  Branch (730:11): [True: 0, False: 54.8k]
  ------------------
  731|      0|        throw std::out_of_range("xfrBlob out of record range");
  732|      0|      }
  733|  54.8k|      blob.assign(&d_content.at(d_pos), &d_content.at(d_startrecordpos + d_recordlen - 1 ) + 1);
  734|  54.8k|    }
  735|  69.0k|    else {
  736|  69.0k|      blob.clear();
  737|  69.0k|    }
  738|       |
  739|   123k|    d_pos = d_startrecordpos + d_recordlen;
  740|   123k|  }
  741|   123k|  catch(...)
  742|   123k|  {
  743|      0|    throw std::out_of_range("xfrBlob out of range");
  744|      0|  }
  745|   123k|}
_Z18getDNSPacketLengthPKcm:
 1329|    429|{
 1330|    429|  uint32_t result = length;
 1331|    429|  if(length < sizeof(dnsheader)) {
  ------------------
  |  Branch (1331:6): [True: 0, False: 429]
  ------------------
 1332|      0|    return result;
 1333|      0|  }
 1334|    429|  try
 1335|    429|  {
 1336|    429|    const dnsheader_aligned dh(packet);
 1337|    429|    DNSPacketMangler dpm(const_cast<char*>(packet), length);
 1338|       |
 1339|    429|    const uint16_t qdcount = ntohs(dh->qdcount);
 1340|   114k|    for(size_t n = 0; n < qdcount; ++n) {
  ------------------
  |  Branch (1340:23): [True: 114k, False: 429]
  ------------------
 1341|   114k|      dpm.skipDomainName();
 1342|       |      /* type and class */
 1343|   114k|      dpm.skipBytes(4);
 1344|   114k|    }
 1345|    429|    const size_t numrecords = ntohs(dh->ancount) + ntohs(dh->nscount) + ntohs(dh->arcount);
 1346|    747|    for(size_t n = 0; n < numrecords; ++n) {
  ------------------
  |  Branch (1346:23): [True: 318, False: 429]
  ------------------
 1347|    318|      dpm.skipDomainName();
 1348|       |      /* type (2), class (2) and ttl (4) */
 1349|    318|      dpm.skipBytes(8);
 1350|    318|      dpm.skipRData();
 1351|    318|    }
 1352|    429|    result = dpm.getOffset();
 1353|    429|  }
 1354|    429|  catch(...)
 1355|    429|  {
 1356|    236|  }
 1357|    429|  return result;
 1358|    429|}

_ZN12PacketReaderC2ERKNSt3__117basic_string_viewIcNS0_11char_traitsIcEEEEtbb:
   72|  11.6k|    : d_pos(initialPos), d_startrecordpos(initialPos), d_internal(internalRepresentation), d_standalone(standalone), d_content(content)
   73|  11.6k|  {
   74|  11.6k|    if (content.size() > std::numeric_limits<uint16_t>::max()) {
  ------------------
  |  Branch (74:9): [True: 0, False: 11.6k]
  ------------------
   75|      0|      throw std::out_of_range("packet too large");
   76|      0|    }
   77|       |
   78|  11.6k|    d_recordlen = static_cast<uint16_t>(content.size());
   79|  11.6k|    d_pointerBudget = static_cast<size_t>(d_recordlen) * s_MaxPointersPerByte;
   80|  11.6k|  }
_ZNK12PacketReader11getPositionEv:
  205|  29.0k|  {
  206|  29.0k|    return d_pos;
  207|  29.0k|  }
_ZN12PacketReader4skipEt:
  210|  74.5k|  {
  211|  74.5k|    size_t stop = d_pos;
  212|  74.5k|    stop += n;
  213|  74.5k|    if (!isWithinRecordBoundaries(d_pos, d_pos + n)) {
  ------------------
  |  Branch (213:9): [True: 0, False: 74.5k]
  ------------------
  214|      0|      throw std::out_of_range("Attempt to skip bytes (" + std::to_string(n) + " starting at " + std::to_string(d_pos) + ") farther than the record's end (" + std::to_string(d_startrecordpos + d_recordlen) + ")");
  215|      0|    }
  216|  74.5k|    if (stop > d_content.size()) {
  ------------------
  |  Branch (216:9): [True: 80, False: 74.4k]
  ------------------
  217|     80|      throw std::out_of_range("Attempt to skip bytes (" + std::to_string(n) + " starting at " + std::to_string(d_pos) + ") farther than the packet's end (" + std::to_string(d_content.size()) + ")");
  218|     80|    }
  219|       |
  220|  74.4k|    d_pos += n;
  221|  74.4k|  }
_ZNK12PacketReader24isWithinRecordBoundariesEmmb:
  227|  1.17M|  {
  228|  1.17M|    if (initialPosition > endPosition) {
  ------------------
  |  Branch (228:9): [True: 0, False: 1.17M]
  ------------------
  229|      0|      return false;
  230|      0|    }
  231|  1.17M|    if (canBeOutsideRecordContent && d_recordlen == 0) {
  ------------------
  |  Branch (231:9): [True: 501k, False: 671k]
  |  Branch (231:38): [True: 103k, False: 398k]
  ------------------
  232|       |      // we don't know the record's length, nothing to check
  233|   103k|      return true;
  234|   103k|    }
  235|  1.07M|    const size_t endOfRecordContent = d_startrecordpos + d_recordlen;
  236|  1.07M|    if (canBeOutsideRecordContent && initialPosition >= endOfRecordContent) {
  ------------------
  |  Branch (236:9): [True: 398k, False: 671k]
  |  Branch (236:38): [True: 85.7k, False: 312k]
  ------------------
  237|       |      // our initial position is after the last known record content,
  238|       |      // we are probably parsing the owner name of the next record,
  239|       |      // nothing to check
  240|  85.7k|      return true;
  241|  85.7k|    }
  242|       |    // are we still inside the record's content?
  243|   984k|    return initialPosition >= d_startrecordpos && initialPosition <= endOfRecordContent && endPosition <= endOfRecordContent;
  ------------------
  |  Branch (243:12): [True: 984k, False: 0]
  |  Branch (243:51): [True: 984k, False: 0]
  |  Branch (243:92): [True: 984k, False: 0]
  ------------------
  244|  1.07M|  }
_ZN16DNSPacketManglerC2EPcm:
  627|    429|    : d_packet(packet), d_length(length), d_notyouroffset(12), d_offset(d_notyouroffset)
  628|    429|  {}
_ZN16DNSPacketMangler14skipDomainNameEv:
  635|   114k|  {
  636|   114k|    uint8_t len{};
  637|   114k|    bool isRoot = true;
  638|   128k|    while ((len = get8BitInt()) != 0) {
  ------------------
  |  Branch (638:12): [True: 16.0k, False: 112k]
  ------------------
  639|  16.0k|      isRoot = false;
  640|  16.0k|      if (len >= 0xc0) { // extended label
  ------------------
  |  Branch (640:11): [True: 1.96k, False: 14.1k]
  ------------------
  641|  1.96k|        get8BitInt();
  642|  1.96k|        return false;
  643|  1.96k|      }
  644|  14.1k|      skipBytes(len);
  645|  14.1k|    }
  646|   112k|    return isRoot;
  647|   114k|  }
_ZN16DNSPacketMangler9skipBytesEt:
  650|   128k|  {
  651|   128k|    moveOffset(bytes);
  652|   128k|  }
_ZN16DNSPacketMangler11get16BitIntEv:
  666|    213|  {
  667|    213|    const char* p = d_packet + d_offset;
  668|    213|    moveOffset(2);
  669|    213|    uint16_t ret;
  670|    213|    memcpy(&ret, p, sizeof(ret));
  671|       |    return ntohs(ret);
  672|    213|  }
_ZN16DNSPacketMangler10get8BitIntEv:
  675|   130k|  {
  676|   130k|    const char* p = d_packet + d_offset;
  677|   130k|    moveOffset(1);
  678|   130k|    return *p;
  679|   130k|  }
_ZN16DNSPacketMangler9skipRDataEv:
  682|    213|  {
  683|    213|    auto toskip = get16BitInt();
  684|    213|    moveOffset(toskip);
  685|    213|  }
_ZNK16DNSPacketMangler9getOffsetEv:
  722|    193|  {
  723|    193|    return d_offset;
  724|    193|  }
_ZN16DNSPacketMangler10moveOffsetEt:
  752|   259k|  {
  753|   259k|    d_notyouroffset += by;
  754|   259k|    if(d_notyouroffset > d_length)
  ------------------
  |  Branch (754:8): [True: 236, False: 259k]
  ------------------
  755|    236|      throw std::out_of_range("dns packet out of range: "+std::to_string(d_notyouroffset) +" > "
  756|    236|      + std::to_string(d_length) );
  757|   259k|  }

_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEEC2ERS6_RK7DNSNametth:
   43|  6.86k|  d_qname(qname), d_content(content)
   44|  6.86k|{
   45|  6.86k|  d_content.clear();
   46|  6.86k|  dnsheader dnsheader;
   47|       |
   48|  6.86k|  memset(&dnsheader, 0, sizeof(dnsheader));
   49|  6.86k|  dnsheader.id=0;
   50|  6.86k|  dnsheader.qdcount=htons(1);
   51|  6.86k|  dnsheader.opcode=opcode;
   52|       |
   53|  6.86k|  const uint8_t* ptr=(const uint8_t*)&dnsheader;
   54|  6.86k|  d_content.reserve(sizeof(dnsheader) + qname.wirelength() + sizeof(qtype) + sizeof(qclass));
   55|  6.86k|  d_content.resize(sizeof(dnsheader));
   56|  6.86k|  uint8_t* dptr=(&*d_content.begin());
   57|       |
   58|  6.86k|  memcpy(dptr, ptr, sizeof(dnsheader));
   59|  6.86k|  d_namepositions.reserve(16);
   60|  6.86k|  xfrName(qname, false);
   61|  6.86k|  xfr16BitInt(qtype);
   62|  6.86k|  xfr16BitInt(qclass);
   63|       |
   64|  6.86k|  if (d_content.size() > std::numeric_limits<decltype(d_truncatemarker)>::max()) {
  ------------------
  |  Branch (64:7): [True: 0, False: 6.86k]
  ------------------
   65|      0|    throw std::range_error("Trying to build a packet larger than " + std::to_string(std::numeric_limits<decltype(d_truncatemarker)>::max()) + " bytes");
   66|      0|  }
   67|  6.86k|  d_truncatemarker = d_content.size();
   68|  6.86k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE11startRecordERK7DNSNametjtN17DNSResourceRecord5PlaceEb:
   77|   124k|{
   78|   124k|  d_compress = compress;
   79|   124k|  commit();
   80|   124k|  if (d_content.size() > std::numeric_limits<decltype(d_rollbackmarker)>::max()) {
  ------------------
  |  Branch (80:7): [True: 0, False: 124k]
  ------------------
   81|      0|    throw std::range_error("Trying to build a packet larger than " + std::to_string(std::numeric_limits<decltype(d_rollbackmarker)>::max()) + " bytes");
   82|      0|  }
   83|   124k|  d_rollbackmarker = d_content.size();
   84|       |
   85|   124k|  if (compress && !name.isRoot() && d_qname==name) {  // don't do the whole label compression thing if we *know* we can get away with "see question" - except when compressing the root
  ------------------
  |  Branch (85:7): [True: 114k, False: 9.67k]
  |  Branch (85:19): [True: 76.8k, False: 37.5k]
  |  Branch (85:37): [True: 950, False: 75.8k]
  ------------------
   86|    950|    static const std::array<unsigned char, 2> marker{0xc0, 0x0c};
   87|    950|    d_content.insert(d_content.end(), reinterpret_cast<const char *>(marker.begin()), reinterpret_cast<const char *>(marker.end()));
   88|    950|  }
   89|   123k|  else {
   90|   123k|    xfrName(name, compress);
   91|   123k|  }
   92|   124k|  xfr16BitInt(qtype);
   93|   124k|  xfr16BitInt(qclass);
   94|   124k|  xfr32BitInt(ttl);
   95|   124k|  xfr16BitInt(0); // this will be the record size
   96|   124k|  d_recordplace = place;
   97|       |
   98|   124k|  d_sor = d_content.size(); // this will remind us where to stuff the record size
   99|   124k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE6addOptEtttRKNS1_INS0_4pairItNS0_12basic_stringIcNS0_11char_traitsIcEENS3_IcEEEEEENS3_ISE_EEEEh:
  102|  4.58k|{
  103|  4.58k|  uint32_t ttl=0;
  104|       |
  105|  4.58k|  EDNS0Record stuff;
  106|       |
  107|  4.58k|  stuff.version = version;
  108|  4.58k|  stuff.extFlags = htons(ednsFlags);
  109|       |
  110|       |  /* RFC 6891 section 4 on the Extended RCode wire format
  111|       |   *    EXTENDED-RCODE
  112|       |   *        Forms the upper 8 bits of extended 12-bit RCODE (together with the
  113|       |   *        4 bits defined in [RFC1035].  Note that EXTENDED-RCODE value 0
  114|       |   *        indicates that an unextended RCODE is in use (values 0 through 15).
  115|       |   */
  116|       |  // XXX Should be check for extRCode > 1<<12 ?
  117|  4.58k|  stuff.extRCode = extRCode>>4;
  118|  4.58k|  if (extRCode != 0) { // As this trumps the existing RCODE
  ------------------
  |  Branch (118:7): [True: 1.40k, False: 3.18k]
  ------------------
  119|  1.40k|    getHeader()->rcode = extRCode;
  120|  1.40k|  }
  121|       |
  122|  4.58k|  static_assert(sizeof(EDNS0Record) == sizeof(ttl), "sizeof(EDNS0Record) must match sizeof(ttl)");
  123|  4.58k|  memcpy(&ttl, &stuff, sizeof(stuff));
  124|       |
  125|  4.58k|  ttl=ntohl(ttl); // will be reversed later on
  126|       |
  127|  4.58k|  startRecord(g_rootdnsname, QType::OPT, ttl, udpsize, DNSResourceRecord::ADDITIONAL, false);
  128|  34.8k|  for(auto const &option : options) {
  ------------------
  |  Branch (128:26): [True: 34.8k, False: 4.58k]
  ------------------
  129|  34.8k|    xfr16BitInt(option.first);
  130|  34.8k|    xfr16BitInt(option.second.length());
  131|  34.8k|    xfrBlob(option.second);
  132|  34.8k|  }
  133|  4.58k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE6commitEv:
  574|   128k|{
  575|   128k|  if (d_sor == 0) {
  ------------------
  |  Branch (575:7): [True: 7.62k, False: 120k]
  ------------------
  576|  7.62k|    return;
  577|  7.62k|  }
  578|       |
  579|   120k|  if (d_sor < 2 || d_sor > d_content.size()) {
  ------------------
  |  Branch (579:7): [True: 0, False: 120k]
  |  Branch (579:20): [True: 0, False: 120k]
  ------------------
  580|      0|    throw std::range_error("Invalid start of record when trying to build a packet: " + std::to_string(d_sor) + " / " + std::to_string(d_content.size()));
  581|      0|  }
  582|       |
  583|   120k|  if (d_content.size() > std::numeric_limits<uint16_t>::max()) {
  ------------------
  |  Branch (583:7): [True: 61, False: 120k]
  ------------------
  584|     61|    throw std::range_error("Trying to build a packet larger than " + std::to_string(std::numeric_limits<uint16_t>::max()) + " bytes");
  585|     61|  }
  586|       |
  587|   120k|  uint16_t rlen = d_content.size() - d_sor;
  588|   120k|  d_content.at(d_sor-2) = rlen >> 8;
  589|   120k|  d_content.at(d_sor-1) = rlen & 0xff;
  590|   120k|  d_sor = 0;
  591|   120k|  auto* dh = reinterpret_cast<dnsheader*>( &*d_content.begin());
  592|   120k|  switch(d_recordplace) {
  ------------------
  |  Branch (592:10): [True: 120k, False: 0]
  ------------------
  593|      0|  case DNSResourceRecord::QUESTION:
  ------------------
  |  Branch (593:3): [True: 0, False: 120k]
  ------------------
  594|      0|    dh->qdcount = htons(ntohs(dh->qdcount) + 1);
  595|      0|    break;
  596|  45.5k|  case DNSResourceRecord::ANSWER:
  ------------------
  |  Branch (596:3): [True: 45.5k, False: 75.0k]
  ------------------
  597|  45.5k|    dh->ancount = htons(ntohs(dh->ancount) + 1);
  598|  45.5k|    break;
  599|  16.0k|  case DNSResourceRecord::AUTHORITY:
  ------------------
  |  Branch (599:3): [True: 16.0k, False: 104k]
  ------------------
  600|  16.0k|    dh->nscount = htons(ntohs(dh->nscount) + 1);
  601|  16.0k|    break;
  602|  58.9k|  case DNSResourceRecord::ADDITIONAL:
  ------------------
  |  Branch (602:3): [True: 58.9k, False: 61.6k]
  ------------------
  603|  58.9k|    dh->arcount = htons(ntohs(dh->arcount) + 1);
  604|  58.9k|    break;
  605|   120k|  }
  606|       |
  607|   120k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE11xfr32BitIntEm:
  155|   124k|{
  156|   124k|  if (val > std::numeric_limits<uint32_t>::max()) {
  ------------------
  |  Branch (156:7): [True: 0, False: 124k]
  ------------------
  157|      0|    throw runtime_error("Value too large to fit in 32 bits");
  158|      0|  }
  159|   124k|  uint32_t rval=htonl(static_cast<uint32_t>(val));
  160|   124k|  uint8_t* ptr=reinterpret_cast<uint8_t*>(&rval);
  161|   124k|  d_content.insert(d_content.end(), ptr, ptr+4);
  162|   124k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE11xfr16BitIntEm:
  165|   455k|{
  166|   455k|  if (val > std::numeric_limits<uint16_t>::max()) {
  ------------------
  |  Branch (166:7): [True: 0, False: 455k]
  ------------------
  167|      0|    throw runtime_error("Value too large to fit in 16 bits");
  168|      0|  }
  169|   455k|  uint16_t rval=htons(static_cast<uint16_t>(val));
  170|   455k|  uint8_t* ptr=reinterpret_cast<uint8_t*>(&rval);
  171|   455k|  d_content.insert(d_content.end(), ptr, ptr+2);
  172|   455k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE7xfrNameERK7DNSNameb:
  395|   129k|{
  396|   129k|  if(l_verbose)
  ------------------
  |  Branch (396:6): [Folded, False: 129k]
  ------------------
  397|      0|    cout<<"Wants to write "<<name<<", compress="<<compress<<", canonic="<<d_canonic<<", LC="<<d_lowerCase<<endl;
  398|   129k|  if(d_canonic || d_lowerCase)   // d_lowerCase implies canonic
  ------------------
  |  Branch (398:6): [True: 0, False: 129k]
  |  Branch (398:19): [True: 0, False: 129k]
  ------------------
  399|      0|    compress=false;
  400|       |
  401|   129k|  if(name.empty() || name.isRoot()) { // for speed
  ------------------
  |  Branch (401:6): [True: 0, False: 129k]
  |  Branch (401:22): [True: 51.2k, False: 78.6k]
  ------------------
  402|  51.2k|    d_content.push_back(0);
  403|  51.2k|    return;
  404|  51.2k|  }
  405|       |
  406|  78.6k|  uint16_t li=0;
  407|  78.6k|  uint16_t matchlen=0;
  408|  78.6k|  if(d_compress && compress && (li=lookupName(name, &matchlen)) && li < maxCompressionOffset) {
  ------------------
  |  Branch (408:6): [True: 75.8k, False: 2.77k]
  |  Branch (408:20): [True: 75.8k, False: 0]
  |  Branch (408:32): [True: 17.2k, False: 58.6k]
  |  Branch (408:68): [True: 17.2k, False: 0]
  ------------------
  409|  17.2k|    const auto& dns=name.getStorage();
  410|  17.2k|    if(l_verbose)
  ------------------
  |  Branch (410:8): [Folded, False: 17.2k]
  ------------------
  411|      0|      cout<<"Found a substring of "<<matchlen<<" bytes from the back, offset: "<<li<<", dnslen: "<<dns.size()<<endl;
  412|       |    // found a substring, if www.powerdns.com matched powerdns.com, we get back matchlen = 13
  413|       |
  414|  17.2k|    unsigned int pos=d_content.size();
  415|  17.2k|    if(pos < maxCompressionOffset && matchlen != dns.size()) {
  ------------------
  |  Branch (415:8): [True: 14.7k, False: 2.52k]
  |  Branch (415:38): [True: 2.20k, False: 12.5k]
  ------------------
  416|  2.20k|      if(l_verbose)
  ------------------
  |  Branch (416:10): [Folded, False: 2.20k]
  ------------------
  417|      0|        cout<<"Inserting pos "<<pos<<" for "<<name<<" for compressed case"<<endl;
  418|  2.20k|      d_namepositions.push_back(pos);
  419|  2.20k|    }
  420|       |
  421|  17.2k|    if(l_verbose)
  ------------------
  |  Branch (421:8): [Folded, False: 17.2k]
  ------------------
  422|      0|      cout<<"Going to write unique part: '"<<makeHexDump(string(dns.c_str(), dns.c_str() + dns.size() - matchlen)) <<"'"<<endl;
  423|  17.2k|    d_content.insert(d_content.end(), (const unsigned char*)dns.c_str(), (const unsigned char*)dns.c_str() + dns.size() - matchlen);
  424|  17.2k|    uint16_t offset=li;
  425|  17.2k|    offset|=0xc000;
  426|       |
  427|  17.2k|    d_content.push_back((char)(offset >> 8));
  428|  17.2k|    d_content.push_back((char)(offset & 0xff));
  429|  17.2k|  }
  430|  61.4k|  else {
  431|  61.4k|    unsigned int pos=d_content.size();
  432|  61.4k|    if(l_verbose)
  ------------------
  |  Branch (432:8): [Folded, False: 61.4k]
  ------------------
  433|      0|      cout<<"Found nothing, we are at pos "<<pos<<", inserting whole name"<<endl;
  434|  61.4k|    if(pos < maxCompressionOffset) {
  ------------------
  |  Branch (434:8): [True: 34.6k, False: 26.7k]
  ------------------
  435|  34.6k|      if(l_verbose)
  ------------------
  |  Branch (435:10): [Folded, False: 34.6k]
  ------------------
  436|      0|        cout<<"Inserting pos "<<pos<<" for "<<name<<" for uncompressed case"<<endl;
  437|  34.6k|      d_namepositions.push_back(pos);
  438|  34.6k|    }
  439|       |
  440|  61.4k|    std::unique_ptr<DNSName> lc;
  441|  61.4k|    if(d_lowerCase)
  ------------------
  |  Branch (441:8): [True: 0, False: 61.4k]
  ------------------
  442|      0|      lc = make_unique<DNSName>(name.makeLowerCase());
  443|       |
  444|  61.4k|    const DNSName::string_t& raw = (lc ? *lc : name).getStorage();
  ------------------
  |  Branch (444:37): [True: 0, False: 61.4k]
  ------------------
  445|  61.4k|    if(l_verbose)
  ------------------
  |  Branch (445:8): [Folded, False: 61.4k]
  ------------------
  446|      0|      cout<<"Writing out the whole thing "<<makeHexDump(string(raw.c_str(),  raw.c_str() + raw.length()))<<endl;
  447|  61.4k|    d_content.insert(d_content.end(), raw.c_str(), raw.c_str() + raw.size());
  448|  61.4k|  }
  449|  78.6k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE7xfrBlobERKNS0_12basic_stringIcNS0_11char_traitsIcEENS3_IcEEEEi:
  452|   151k|{
  453|   151k|  const uint8_t* ptr=reinterpret_cast<const uint8_t*>(blob.c_str());
  454|   151k|  d_content.insert(d_content.end(), ptr, ptr+blob.size());
  455|   151k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE9getHeaderEv:
   71|  63.1k|{
   72|  63.1k|  return reinterpret_cast<dnsheader*>(&*d_content.begin());
   73|  63.1k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE10lookupNameERK7DNSNamePt:
  229|  75.8k|{
  230|       |  // iterate over the written labels, see if we find a match
  231|  75.8k|  const auto& raw = name.getStorage();
  232|       |
  233|       |  /* name might be a.root-servers.net, we need to be able to benefit from finding:
  234|       |     b.root-servers.net, or even:
  235|       |     b\xc0\x0c
  236|       |  */
  237|  75.8k|  unsigned int bestpos=0;
  238|  75.8k|  *matchLen = 0;
  239|       |
  240|       |  // positions of each label in the name we are trying to compress
  241|  75.8k|  boost::container::static_vector<uint16_t, 34> positionsInName;
  242|       |  // positions of labels in the packet we are building
  243|  75.8k|  boost::container::static_vector<uint16_t, 34> positionsInPacket;
  244|       |
  245|  75.8k|  try {
  246|  2.01M|    for(auto riter= raw.cbegin(); riter < raw.cend(); ) {
  ------------------
  |  Branch (246:35): [True: 1.95M, False: 52.4k]
  ------------------
  247|  1.95M|      if (*riter == 0) {
  ------------------
  |  Branch (247:11): [True: 23.4k, False: 1.93M]
  ------------------
  248|  23.4k|        break;
  249|  23.4k|      }
  250|  1.93M|      positionsInName.push_back(riter - raw.cbegin());
  251|  1.93M|      riter += *riter + 1;
  252|  1.93M|    }
  253|  75.8k|  }
  254|  75.8k|  catch (const std::bad_alloc& ba) {
  255|  52.4k|    if (l_verbose) {
  ------------------
  |  Branch (255:9): [Folded, False: 52.4k]
  ------------------
  256|      0|      cout << "Domain " << name << " too large to compress" << endl;
  257|      0|    }
  258|  52.4k|    return 0;
  259|  52.4k|  }
  260|       |
  261|  23.4k|  if (l_verbose) {
  ------------------
  |  Branch (261:7): [Folded, False: 23.4k]
  ------------------
  262|      0|    cout<<"Input vector for lookup "<<name<<": ";
  263|      0|    for (const auto n : positionsInName) {
  ------------------
  |  Branch (263:23): [True: 0, False: 0]
  ------------------
  264|      0|      cout << n << " ";
  265|      0|    }
  266|      0|    cout<<endl;
  267|      0|    cout<<makeHexDump(string(raw.c_str(), raw.c_str()+raw.size()))<<endl;
  268|      0|  }
  269|       |
  270|  23.4k|  if (l_verbose) {
  ------------------
  |  Branch (270:7): [Folded, False: 23.4k]
  ------------------
  271|      0|    cout << "Have " << d_namepositions.size() << " to ponder" << endl;
  272|      0|  }
  273|       |
  274|  23.4k|  int counter=1;
  275|   198k|  for (const auto positionInPacket : d_namepositions) {
  ------------------
  |  Branch (275:36): [True: 198k, False: 9.08k]
  ------------------
  276|       |    // here it's a bit tricky because the names might be compressed,
  277|       |    // so we will gather all labels composing the name, following
  278|       |    // pointers if needed
  279|       |    // for example if there is an uncompressed \1a\1b\1c\0 we will store
  280|       |    // the position of \1a, \1b, \1c
  281|       |    // if there is instead \1a followed by a pointer to \1b\1c\0 earlier
  282|       |    // in the packet we will store the position of \1a, \1b, \1c as well
  283|       |    // they will just be disjoint
  284|   198k|    if (l_verbose) {
  ------------------
  |  Branch (284:9): [Folded, False: 198k]
  ------------------
  285|      0|      cout<<"Pos: "<<positionInPacket<<", "<<d_content.size()<<endl;
  286|      0|      DNSName pname(reinterpret_cast<const char*>(d_content.data()), d_content.size(), positionInPacket, true); // only for debugging
  287|      0|      cout<<"Looking at '"<<pname<<"' in packet at position "<<positionInPacket<<"/"<<d_content.size()<<", option "<<counter<<"/"<<d_namepositions.size()<<endl;
  288|      0|      ++counter;
  289|      0|    }
  290|   198k|    size_t pointerQuota = 50U;
  291|       |    // memcmp here makes things _slower_
  292|   198k|    positionsInPacket.clear();
  293|   198k|    try {
  294|  4.33M|      for (auto iter = d_content.cbegin() + positionInPacket; iter < d_content.cend() && pointerQuota > 0;) {
  ------------------
  |  Branch (294:63): [True: 4.23M, False: 100k]
  |  Branch (294:63): [True: 4.23M, False: 100k]
  |  Branch (294:90): [True: 4.23M, False: 0]
  ------------------
  295|  4.23M|        uint8_t labelLength = *iter;
  296|  4.23M|        const uint16_t currentPos = (iter - d_content.cbegin());
  297|  4.23M|        if (l_verbose) {
  ------------------
  |  Branch (297:13): [Folded, False: 4.23M]
  ------------------
  298|      0|          cout << "Found label length: " << std::to_string(labelLength) << " at " << currentPos << endl;
  299|      0|        }
  300|  4.23M|        if (labelLength & 0xc0) {
  ------------------
  |  Branch (300:13): [True: 51.4k, False: 4.18M]
  ------------------
  301|  51.4k|          uint16_t npos = 0x100*(labelLength & (~0xc0)) + *++iter;
  302|       |          // check against going forward
  303|  51.4k|          if (npos >= currentPos || npos < sizeof(dnsheader)) {
  ------------------
  |  Branch (303:15): [True: 0, False: 51.4k]
  |  Branch (303:37): [True: 0, False: 51.4k]
  ------------------
  304|       |            /* something is not right */
  305|      0|            break;
  306|      0|          }
  307|       |
  308|       |          // jump to the target of the pointer
  309|  51.4k|          iter = d_content.begin() + npos;
  310|  51.4k|          if (l_verbose) {
  ------------------
  |  Branch (310:15): [Folded, False: 51.4k]
  ------------------
  311|      0|            cout << "Is compressed label to newpos " << npos << ", going there" << endl;
  312|      0|          }
  313|       |
  314|  51.4k|          if (pointerQuota >= 1) {
  ------------------
  |  Branch (314:15): [True: 51.4k, False: 0]
  ------------------
  315|  51.4k|            pointerQuota--;
  316|  51.4k|            continue;
  317|  51.4k|          }
  318|       |
  319|       |          // out of pointer quota, let's stop there
  320|      0|          break;
  321|  51.4k|        }
  322|       |
  323|  4.18M|        if (labelLength == 0) {
  ------------------
  |  Branch (323:13): [True: 96.9k, False: 4.08M]
  ------------------
  324|  96.9k|          break;
  325|  96.9k|        }
  326|       |
  327|  4.08M|        if (currentPos >= maxCompressionOffset) {
  ------------------
  |  Branch (327:13): [True: 635, False: 4.08M]
  ------------------
  328|    635|          break; // compression pointers cannot point here
  329|    635|        }
  330|       |
  331|  4.08M|        positionsInPacket.push_back(currentPos);
  332|       |        // jump to the next label
  333|  4.08M|        iter += labelLength + 1;
  334|  4.08M|      }
  335|   198k|    }
  336|   198k|    catch (const std::bad_alloc& ba) {
  337|   100k|      if (l_verbose) {
  ------------------
  |  Branch (337:11): [Folded, False: 100k]
  ------------------
  338|      0|        cout << "Domain " << name << " too large to compress" << endl;
  339|      0|      }
  340|   100k|      continue;
  341|   100k|    }
  342|       |
  343|  97.5k|    if (l_verbose) {
  ------------------
  |  Branch (343:9): [Folded, False: 97.5k]
  ------------------
  344|      0|      cout<<"Packet vector: "<<endl;
  345|      0|      for (const auto n : positionsInPacket) {
  ------------------
  |  Branch (345:25): [True: 0, False: 0]
  ------------------
  346|      0|        cout << n << " ";
  347|      0|      }
  348|      0|      cout<<endl;
  349|      0|    }
  350|       |
  351|  97.5k|    auto positionInNameIter = positionsInName.crbegin();
  352|  97.5k|    auto positionInPacketIter = positionsInPacket.crbegin();
  353|  97.5k|    unsigned int cmatchlen=1;
  354|   198k|    for(; positionInNameIter != positionsInName.crend() && positionInPacketIter != positionsInPacket.crend(); ++positionInNameIter, ++positionInPacketIter) {
  ------------------
  |  Branch (354:11): [True: 198k, False: 0]
  |  Branch (354:11): [True: 193k, False: 5.58k]
  |  Branch (354:60): [True: 193k, False: 5.58k]
  ------------------
  355|       |      // positionInNameIter is an offset in raw, pvect an offset in packet
  356|   193k|      uint8_t nlen = raw[*positionInNameIter];
  357|   193k|      uint8_t plen = d_content[*positionInPacketIter];
  358|       |
  359|   193k|      if (l_verbose) {
  ------------------
  |  Branch (359:11): [Folded, False: 193k]
  ------------------
  360|      0|        cout << "nlnen=" << (int)nlen << ", plen=" << (int)plen << endl;
  361|      0|      }
  362|       |
  363|   193k|      if (nlen != plen) {
  ------------------
  |  Branch (363:11): [True: 48.5k, False: 144k]
  ------------------
  364|  48.5k|        break;
  365|  48.5k|      }
  366|       |
  367|   144k|      auto rawpart = std::string_view(raw.c_str() + *positionInNameIter + 1, nlen); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  368|   144k|      auto pktpart = std::string_view((const char*)&d_content[*positionInPacketIter] + 1, nlen); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  369|   144k|      if (pdns_ilexicographical_compare_three_way(rawpart, pktpart) != 0) {
  ------------------
  |  Branch (369:11): [True: 29.1k, False: 115k]
  ------------------
  370|  29.1k|        if (l_verbose) {
  ------------------
  |  Branch (370:13): [Folded, False: 29.1k]
  ------------------
  371|      0|          cout << "Mismatch: " << rawpart << " != " << pktpart << endl;
  372|      0|        }
  373|  29.1k|        break;
  374|  29.1k|      }
  375|       |
  376|   115k|      cmatchlen += nlen + 1;
  377|   115k|      if (cmatchlen == raw.length()) { // have matched all of it, can't improve
  ------------------
  |  Branch (377:11): [True: 14.3k, False: 101k]
  ------------------
  378|  14.3k|        if (l_verbose) {
  ------------------
  |  Branch (378:13): [Folded, False: 14.3k]
  ------------------
  379|      0|          cout << "Stopping search, matched whole name" << endl;
  380|      0|        }
  381|       |
  382|  14.3k|        *matchLen = cmatchlen;
  383|  14.3k|        return *positionInPacketIter;
  384|  14.3k|      }
  385|   115k|    }
  386|  83.1k|    if (positionInPacketIter != positionsInPacket.crbegin() && *matchLen < cmatchlen) {
  ------------------
  |  Branch (386:9): [True: 14.4k, False: 68.7k]
  |  Branch (386:9): [True: 8.90k, False: 74.2k]
  |  Branch (386:64): [True: 8.90k, False: 5.58k]
  ------------------
  387|  8.90k|      *matchLen = cmatchlen;
  388|  8.90k|      bestpos = *--positionInPacketIter;
  389|  8.90k|    }
  390|  83.1k|  }
  391|  9.08k|  return bestpos;
  392|  23.4k|}

_Z17getNextEDNSOptionPKcmRtS1_:
   28|  14.1k|{
   29|  14.1k|  if (data == nullptr || dataLen < (sizeof(uint16_t) + sizeof(uint16_t))) {
  ------------------
  |  Branch (29:7): [True: 0, False: 14.1k]
  |  Branch (29:26): [True: 0, False: 14.1k]
  ------------------
   30|      0|    return false;
   31|      0|  }
   32|       |
   33|  14.1k|  size_t pos = 0;
   34|  14.1k|  const auto* ptr = reinterpret_cast<const uint8_t*>(data);
   35|       |
   36|  14.1k|  optionCode = (static_cast<uint16_t>(ptr[pos]) * 256) + ptr[pos + 1];
   37|  14.1k|  pos += EDNS_OPTION_CODE_SIZE;
   38|       |
   39|  14.1k|  optionLen = (static_cast<uint16_t>(ptr[pos]) * 256) + ptr[pos + 1];
   40|  14.1k|  pos += EDNS_OPTION_LENGTH_SIZE;
   41|  14.1k|  (void)pos;
   42|       |
   43|  14.1k|  return true;
   44|  14.1k|}
_Z13getEDNSOptionPKcmtPmS1_:
   48|    523|{
   49|    523|  if (optRR == nullptr || optionValuePosition == nullptr || optionValueSize == nullptr) {
  ------------------
  |  Branch (49:7): [True: 0, False: 523]
  |  Branch (49:27): [True: 0, False: 523]
  |  Branch (49:61): [True: 0, False: 523]
  ------------------
   50|      0|    return EINVAL;
   51|      0|  }
   52|       |
   53|    523|  size_t pos = 0;
   54|    523|  if (len < DNS_RDLENGTH_SIZE) {
  ------------------
  |  Branch (54:7): [True: 0, False: 523]
  ------------------
   55|      0|    return EINVAL;
   56|      0|  }
   57|       |
   58|    523|  const uint16_t rdLen = (((unsigned char)optRR[pos]) * 256) + ((unsigned char)optRR[pos + 1]);
   59|    523|  size_t rdPos = 0;
   60|    523|  pos += DNS_RDLENGTH_SIZE;
   61|    523|  if ((pos + rdLen) > len) {
  ------------------
  |  Branch (61:7): [True: 34, False: 489]
  ------------------
   62|     34|    return EINVAL;
   63|     34|  }
   64|       |
   65|  14.3k|  while (len >= (pos + EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE) && rdLen >= (rdPos + EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE)) {
  ------------------
  |  Branch (65:10): [True: 14.2k, False: 106]
  |  Branch (65:76): [True: 14.1k, False: 87]
  ------------------
   66|  14.1k|    uint16_t optionCode{};
   67|  14.1k|    uint16_t optionLen{};
   68|  14.1k|    if (!getNextEDNSOption(optRR + pos, len - pos, optionCode, optionLen)) {
  ------------------
  |  Branch (68:9): [True: 0, False: 14.1k]
  ------------------
   69|      0|      break;
   70|      0|    }
   71|       |
   72|  14.1k|    pos += EDNS_OPTION_CODE_SIZE;
   73|  14.1k|    rdPos += EDNS_OPTION_CODE_SIZE;
   74|  14.1k|    pos += EDNS_OPTION_LENGTH_SIZE;
   75|  14.1k|    rdPos += EDNS_OPTION_LENGTH_SIZE;
   76|       |
   77|  14.1k|    if (optionLen > (rdLen - rdPos) || optionLen > (len - pos)) {
  ------------------
  |  Branch (77:9): [True: 50, False: 14.1k]
  |  Branch (77:40): [True: 0, False: 14.1k]
  ------------------
   78|     50|      return EINVAL;
   79|     50|    }
   80|       |
   81|  14.1k|    if (optionCode == wantedOption) {
  ------------------
  |  Branch (81:9): [True: 246, False: 13.9k]
  ------------------
   82|    246|      *optionValuePosition = pos - (EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE);
   83|    246|      *optionValueSize = optionLen + EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE;
   84|    246|      return 0;
   85|    246|    }
   86|       |    /* skip this option */
   87|  13.9k|    pos += optionLen;
   88|  13.9k|    rdPos += optionLen;
   89|  13.9k|  }
   90|       |
   91|    193|  return ENOENT;
   92|    489|}
_Z25getEDNSOptionsFromContentRKNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERNS_6vectorINS_4pairItS5_EENS3_ISA_EEEE:
  197|  4.50k|{
  198|  4.50k|  size_t pos = 0;
  199|  4.50k|  const size_t contentLength = content.size();
  200|       |
  201|  36.1k|  while (pos < contentLength && (contentLength - pos) >= (EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE)) {
  ------------------
  |  Branch (201:10): [True: 33.2k, False: 2.85k]
  |  Branch (201:33): [True: 32.5k, False: 684]
  ------------------
  202|  32.5k|    uint16_t code = (static_cast<unsigned char>(content.at(pos)) * 256) + static_cast<unsigned char>(content.at(pos + 1));
  203|  32.5k|    pos += EDNS_OPTION_CODE_SIZE;
  204|  32.5k|    uint16_t len = (static_cast<unsigned char>(content.at(pos)) * 256) + static_cast<unsigned char>(content.at(pos + 1));
  205|  32.5k|    pos += EDNS_OPTION_LENGTH_SIZE;
  206|       |
  207|  32.5k|    if (pos > contentLength || len > (contentLength - pos)) {
  ------------------
  |  Branch (207:9): [True: 0, False: 32.5k]
  |  Branch (207:32): [True: 966, False: 31.6k]
  ------------------
  208|    966|      return false;
  209|    966|    }
  210|       |
  211|  31.6k|    options.emplace_back(code, content.substr(pos, len));
  212|  31.6k|    pos += len;
  213|  31.6k|  }
  214|       |
  215|  3.53k|  return true;
  216|  4.50k|}
_Z18generateEDNSOptiontRKNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERS5_:
  219|  2.75k|{
  220|  2.75k|  const uint16_t ednsOptionCode = htons(optionCode);
  221|       |  const uint16_t payloadLen = htons(payload.length());
  222|  2.75k|  res.append(reinterpret_cast<const char*>(&ednsOptionCode), sizeof ednsOptionCode);
  223|  2.75k|  res.append(reinterpret_cast<const char*>(&payloadLen), sizeof payloadLen);
  224|  2.75k|  res.append(payload);
  225|  2.75k|}
_Z15locateEDNSOptRRINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEEiRKT_PtPmPb:
  229|  5.96k|{
  230|  5.96k|  if (optStart == nullptr || optLen == nullptr || last == nullptr) {
  ------------------
  |  Branch (230:7): [True: 0, False: 5.96k]
  |  Branch (230:30): [True: 0, False: 5.96k]
  |  Branch (230:51): [True: 0, False: 5.96k]
  ------------------
  231|      0|    throw std::runtime_error("Invalid values passed to locateEDNSOptRR");
  232|      0|  }
  233|       |
  234|  5.96k|  if (packet.size() < sizeof(dnsheader)) {
  ------------------
  |  Branch (234:7): [True: 16, False: 5.95k]
  ------------------
  235|     16|    throw std::runtime_error("Packet passed to locateEDNSOptRR was too small");
  236|     16|  }
  237|       |
  238|  5.95k|  const dnsheader_aligned dnsHeader(packet.data());
  239|       |
  240|  5.95k|  if (ntohs(dnsHeader->arcount) == 0) {
  ------------------
  |  Branch (240:7): [True: 496, False: 5.45k]
  ------------------
  241|    496|    return ENOENT;
  242|    496|  }
  243|       |
  244|  5.45k|  if (ntohs(dnsHeader->qdcount) != 1) {
  ------------------
  |  Branch (244:7): [True: 1.06k, False: 4.38k]
  ------------------
  245|  1.06k|    throw std::runtime_error("Packet passed to locateEDNSOptRR did not have QDCOUNT=1");
  246|  1.06k|  }
  247|       |
  248|       |  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
  249|  4.38k|  PacketReader packetReader(std::string_view(reinterpret_cast<const char*>(packet.data()), packet.size()));
  250|       |
  251|  4.38k|  size_t idx = 0;
  252|  4.38k|  DNSName rrname;
  253|  4.38k|  uint16_t ancount = ntohs(dnsHeader->ancount);
  254|  4.38k|  uint16_t nscount = ntohs(dnsHeader->nscount);
  255|  4.38k|  uint16_t arcount = ntohs(dnsHeader->arcount);
  256|  4.38k|  dnsrecordheader recordHeader{};
  257|       |
  258|       |  /* consume query section */
  259|  4.38k|  rrname = packetReader.getName();
  260|  4.38k|  packetReader.skip(4); // Skip Type and Class
  261|       |
  262|       |  /* consume AN and NS */
  263|  46.4k|  for (idx = 0; idx < ancount + nscount; idx++) {
  ------------------
  |  Branch (263:17): [True: 42.0k, False: 4.38k]
  ------------------
  264|  42.0k|    rrname = packetReader.getName();
  265|  42.0k|    packetReader.getDnsrecordheader(recordHeader);
  266|  42.0k|    packetReader.skip(recordHeader.d_clen);
  267|  42.0k|  }
  268|       |
  269|       |  /* consume AR, looking for OPT */
  270|  29.5k|  for (idx = 0; idx < arcount; idx++) {
  ------------------
  |  Branch (270:17): [True: 27.1k, False: 2.43k]
  ------------------
  271|  27.1k|    uint16_t start = packetReader.getPosition();
  272|  27.1k|    rrname = packetReader.getName();
  273|  27.1k|    packetReader.getDnsrecordheader(recordHeader);
  274|       |
  275|  27.1k|    if (rrname.isRoot() && recordHeader.d_type == QType::OPT) {
  ------------------
  |  Branch (275:9): [True: 10.3k, False: 16.7k]
  |  Branch (275:28): [True: 1.94k, False: 8.41k]
  ------------------
  276|  1.94k|      *optStart = start;
  277|  1.94k|      *optLen = (packetReader.getPosition() - start) + recordHeader.d_clen;
  278|       |
  279|  1.94k|      if (packet.size() < (*optStart + *optLen)) {
  ------------------
  |  Branch (279:11): [True: 0, False: 1.94k]
  ------------------
  280|      0|        throw std::range_error("Opt record overflow");
  281|      0|      }
  282|       |
  283|  1.94k|      if (idx == ((size_t)arcount - 1)) {
  ------------------
  |  Branch (283:11): [True: 996, False: 952]
  ------------------
  284|    996|        *last = true;
  285|    996|      }
  286|    952|      else {
  287|    952|        *last = false;
  288|    952|      }
  289|  1.94k|      return 0;
  290|  1.94k|    }
  291|  25.1k|    packetReader.skip(recordHeader.d_clen);
  292|  25.1k|  }
  293|       |
  294|  2.43k|  return ENOENT;
  295|  4.38k|}

_ZNK14EDNSSubnetOpts13makeOptStringEv:
   97|  2.75k|{
   98|  2.75k|  std::string ret;
   99|  2.75k|  EDNSSubnetOptsWire esow{};
  100|  2.75k|  uint16_t family = htons(source.isIPv4() ? 1 : 2);
  ------------------
  |  Branch (100:21): [True: 2.75k, False: 0]
  ------------------
  101|  2.75k|  esow.family = family;
  102|  2.75k|  esow.sourcePrefixLength = source.getBits();
  103|  2.75k|  esow.scopePrefixLength = scopeBits;
  104|       |  // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast)
  105|  2.75k|  ret.assign(reinterpret_cast<const char*>(&esow), sizeof(esow));
  106|  2.75k|  size_t octetsout = esow.sourcePrefixLength > 0U ? ((esow.sourcePrefixLength - 1) >> 3) + 1 : 0U;
  ------------------
  |  Branch (106:22): [True: 2.75k, False: 0]
  ------------------
  107|       |
  108|  2.75k|  ComboAddress src = source.getNetwork();
  109|  2.75k|  src.truncate(esow.sourcePrefixLength);
  110|       |
  111|  2.75k|  if (source.isIPv4()) {
  ------------------
  |  Branch (111:7): [True: 2.75k, False: 0]
  ------------------
  112|  2.75k|    if (octetsout > sizeof(src.sin4.sin_addr.s_addr)) {
  ------------------
  |  Branch (112:9): [True: 0, False: 2.75k]
  ------------------
  113|      0|      throw std::runtime_error("Trying to copy too many bytes while generating an EDNS Client Subnet option");
  114|      0|    }
  115|  2.75k|    ret.append(reinterpret_cast<const char*>(&src.sin4.sin_addr.s_addr), octetsout);
  116|  2.75k|  }
  117|      0|  else {
  118|      0|    if (octetsout > sizeof(src.sin6.sin6_addr.s6_addr)) {
  ------------------
  |  Branch (118:9): [True: 0, False: 0]
  ------------------
  119|      0|      throw std::runtime_error("Trying to copy too many bytes while generating an EDNS Client Subnet option");
  120|      0|    }
  121|      0|    ret.append(reinterpret_cast<const char*>(&src.sin6.sin6_addr.s6_addr), octetsout);
  122|      0|  }
  123|       |  // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast)
  124|  2.75k|  return ret;
  125|  2.75k|}

_ZN14EDNSSubnetOpts9setSourceERK7Netmask:
   30|  2.75k|  {
   31|  2.75k|    source = netmask;
   32|  2.75k|  }

_ZN22EpollRegisterOurselvesC2Ev:
   72|      2|  {
   73|      2|    FDMultiplexer::getMultiplexerMap().emplace(0, &makeEpoll); // priority 0!
   74|      2|  }

_ZN10LuaContextC2Eb:
  110|      2|    {
  111|       |        // luaL_newstate can return null if allocation failed
  112|       |#if defined(__SANITIZE_THREAD__) && defined(LUAJIT_VERSION) && defined(__aarch64__)
  113|       |        // on arm64 with luajit and TSAN, allocation may fail spuriously, so keep retrying a bit
  114|       |        int tries = 100;
  115|       |#else
  116|      2|        int tries = 1;
  117|      2|#endif
  118|      2|        for (; tries > 0; tries--) {
  ------------------
  |  Branch (118:16): [True: 2, False: 0]
  ------------------
  119|      2|          mState = luaL_newstate();
  120|      2|          if (mState != nullptr) { break; }
  ------------------
  |  Branch (120:15): [True: 2, False: 0]
  ------------------
  121|      2|        }
  122|      2|#undef RETRIES
  123|      2|        if (mState == nullptr)
  ------------------
  |  Branch (123:13): [True: 0, False: 2]
  ------------------
  124|      0|            throw std::bad_alloc();
  125|       |
  126|       |        // setting the panic function
  127|      2|        lua_atpanic(mState, [](lua_State* state) -> int {
  128|      2|            const std::string str = lua_tostring(state, -1);
  129|      2|            lua_pop(state, 1);
  130|      2|            assert(false && "lua_atpanic triggered");
  131|      2|            exit(0);
  132|      2|        });
  133|       |
  134|       |        // opening default library if required to do so
  135|      2|        if (openDefaultLibs)
  ------------------
  |  Branch (135:13): [True: 2, False: 0]
  ------------------
  136|      2|            luaL_openlibs(mState);
  137|       |
  138|      2|        writeGlobalEq();
  139|      2|        lua_pushliteral(mState, LUACONTEXT_DEBUG_TRACEBACK); // ref
  ------------------
  |  |  276|      2|	lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
  ------------------
  140|      2|        lua_getglobal(mState, "debug"); // ref, debug
  ------------------
  |  |  279|      2|#define lua_getglobal(L,s)	lua_getfield(L, LUA_GLOBALSINDEX, (s))
  |  |  ------------------
  |  |  |  |   38|      2|#define LUA_GLOBALSINDEX	(-10002)
  |  |  ------------------
  ------------------
  141|      2|        lua_getfield(mState, -1, "traceback"); // ref, debug, traceback
  142|      2|        lua_remove(mState, -2); // ref, traceback
  143|      2|        lua_settable(mState, LUA_REGISTRYINDEX); // []
  ------------------
  |  |   36|      2|#define LUA_REGISTRYINDEX	(-10000)
  ------------------
  144|      2|    }
_ZN10LuaContext13writeGlobalEqEv:
  146|      2|    void writeGlobalEq() {
  147|      2|      const auto eqFunction = [](lua_State* lua) -> int {
  148|      2|        try {
  149|      2|          lua_pushstring(lua, "__eq");
  150|      2|          lua_gettable(lua, -2);
  151|       |          /* if not found, return false */
  152|      2|          if (lua_isnil(lua, -1)) {
  153|      2|            lua_pop(lua, 2);
  154|      2|            lua_pushboolean(lua, false);
  155|      2|            return 1;
  156|      2|          }
  157|      2|          lua_insert(lua, lua_gettop(lua)-2);
  158|      2|          return callRaw(lua, PushedObject{lua, 3}, 1).release();
  159|      2|        } catch(...) {
  160|      2|          Pusher<std::exception_ptr>::push(lua, std::current_exception()).release();
  161|      2|          luaError(lua);
  162|      2|        }
  163|      2|      };
  164|      2|      lua_pushcfunction(mState, eqFunction);
  ------------------
  |  |  262|      2|#define lua_pushcfunction(L,f)	lua_pushcclosure(L, (f), 0)
  ------------------
  165|      2|      lua_setglobal(mState, LUACONTEXT_GLOBAL_EQ);
  ------------------
  |  |  278|      2|#define lua_setglobal(L,s)	lua_setfield(L, LUA_GLOBALSINDEX, (s))
  |  |  ------------------
  |  |  |  |   38|      2|#define LUA_GLOBALSINDEX	(-10002)
  |  |  ------------------
  ------------------
  166|      2|    };
_ZN10LuaContextC2EOS_:
  172|      2|        mState(s.mState)
  173|      2|    {
  174|      2|        s.mState = luaL_newstate();
  175|      2|    }
_ZN10LuaContextD2Ev:
  200|      2|    {
  201|      2|        assert(mState);
  ------------------
  |  Branch (201:9): [True: 2, False: 0]
  ------------------
  202|      2|        lua_close(mState);
  203|      2|    }

LLVMFuzzerTestOneInput:
   32|  2.98k|{
   33|  2.98k|  if (size > std::numeric_limits<uint16_t>::max()) {
  ------------------
  |  Branch (33:7): [True: 5, False: 2.98k]
  ------------------
   34|      5|    return 0;
   35|      5|  }
   36|       |
   37|  2.98k|  const PacketBuffer packet(data, data + size);
   38|       |
   39|       |  // Wire-format EDNS/OPT parsing on the raw packet.
   40|  2.98k|  try {
   41|  2.98k|    EDNS0Record edns0{};
   42|  2.98k|    getEDNS0Record(packet, edns0);
   43|  2.98k|  }
   44|  2.98k|  catch (...) {
   45|  1.65k|  }
   46|       |
   47|  2.98k|  try {
   48|  2.98k|    uint16_t optStart = 0;
   49|  2.98k|    size_t optLen = 0;
   50|  2.98k|    bool last = false;
   51|  2.98k|    if (locateEDNSOptRR(packet, &optStart, &optLen, &last) == 0) {
  ------------------
  |  Branch (51:9): [True: 974, False: 2.00k]
  ------------------
   52|    974|      size_t optContentStart = 0;
   53|    974|      uint16_t optContentLen = 0;
   54|    974|      isEDNSOptionInOpt(packet, optStart, optLen, EDNSOptionCode::ECS,
   55|    974|                        &optContentStart, &optContentLen);
   56|    974|    }
   57|  2.98k|  }
   58|  2.98k|  catch (...) {
   59|  1.65k|  }
   60|       |
   61|  2.98k|  try {
   62|  2.98k|    PacketBuffer newContent;
   63|  2.98k|    rewriteResponseWithoutEDNS(packet, newContent);
   64|  2.98k|  }
   65|  2.98k|  catch (...) {
   66|  2.08k|  }
   67|       |
   68|  2.98k|  try {
   69|  2.98k|    PacketBuffer newContent;
   70|  2.98k|    rewriteResponseWithoutEDNSOption(packet, EDNSOptionCode::ECS, newContent);
   71|  2.98k|  }
   72|  2.98k|  catch (...) {
   73|  2.08k|  }
   74|       |
   75|       |  // ECS add/replace; needs the question name's wire length.
   76|  2.98k|  try {
   77|  2.98k|    uint16_t qtype = 0;
   78|  2.98k|    uint16_t qclass = 0;
   79|  2.98k|    unsigned int consumed = 0;
   80|  2.98k|    const DNSName qname(reinterpret_cast<const char*>(data), size,
   81|  2.98k|                        sizeof(dnsheader), false, &qtype, &qclass, &consumed);
   82|       |
   83|  2.98k|    uint16_t optRDPosition = 0;
   84|  2.98k|    size_t remaining = 0;
   85|  2.98k|    dnsdist::getEDNSOptionsStart(packet, consumed, &optRDPosition, &remaining);
   86|       |
   87|  2.98k|    PacketBuffer mutablePacket(packet);
   88|  2.98k|    bool ednsAdded = false;
   89|  2.98k|    bool ecsAdded = false;
   90|  2.98k|    std::string newECSOption;
   91|  2.98k|    const ComboAddress source("192.0.2.1");
   92|  2.98k|    generateECSOption(source, newECSOption, 24);
   93|  2.98k|    handleEDNSClientSubnet(mutablePacket, mutablePacket.size() + 512, consumed,
   94|  2.98k|                           ednsAdded, ecsAdded, true, newECSOption);
   95|  2.98k|  }
   96|  2.98k|  catch (...) {
   97|  2.00k|  }
   98|       |
   99|  2.98k|  return 0;
  100|  2.98k|}

_ZN12ComboAddress8truncateEj:
  366|  2.75k|{
  367|  2.75k|  uint8_t* start{};
  368|  2.75k|  int len = 4;
  369|  2.75k|  if (sin4.sin_family == AF_INET) {
  ------------------
  |  Branch (369:7): [True: 2.75k, False: 0]
  ------------------
  370|  2.75k|    if (bits >= 32) {
  ------------------
  |  Branch (370:9): [True: 0, False: 2.75k]
  ------------------
  371|      0|      return;
  372|      0|    }
  373|  2.75k|    start = reinterpret_cast<uint8_t*>(&sin4.sin_addr.s_addr); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
  374|  2.75k|    len = 4;
  375|  2.75k|  }
  376|      0|  else {
  377|      0|    if (bits >= 128) {
  ------------------
  |  Branch (377:9): [True: 0, False: 0]
  ------------------
  378|      0|      return;
  379|      0|    }
  380|      0|    start = reinterpret_cast<uint8_t*>(&sin6.sin6_addr.s6_addr); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
  381|      0|    len = 16;
  382|      0|  }
  383|       |
  384|  2.75k|  auto tozero = (len * 8) - bits; // if set to 22, this will clear 1 byte, as it should
  385|       |
  386|  2.75k|  memset(start + len - (tozero / 8), 0, tozero / 8); // blot out the whole bytes on the right NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  387|       |
  388|  2.75k|  auto bitsleft = tozero % 8; // 2 bits left to clear
  389|  2.75k|  if (bitsleft == 0) {
  ------------------
  |  Branch (389:7): [True: 2.75k, False: 0]
  ------------------
  390|       |    // the memset() above cleared whole bytes only, and for 0 bits the byte we
  391|       |    // would look at is the one before the address
  392|  2.75k|    return;
  393|  2.75k|  }
  394|       |
  395|       |  // a b c d, to truncate to 22 bits, we just zeroed 'd' and need to zero 2 bits from c
  396|       |  // so and by '11111100', which is ~((1<<2)-1)  = ~3
  397|      0|  uint8_t* place = start + len - 1 - (tozero / 8); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  398|      0|  *place &= (~((1 << bitsleft) - 1));
  399|      0|}

_ZN12ComboAddressC2ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEt:
  247|  2.75k|  {
  248|  2.75k|    memset(&sin6, 0, sizeof(sin6));
  249|  2.75k|    sin4.sin_family = AF_INET;
  250|  2.75k|    sin4.sin_port = 0;
  251|  2.75k|    if (makeIPv4sockaddr(str, &sin4) != 0) {
  ------------------
  |  Branch (251:9): [True: 0, False: 2.75k]
  ------------------
  252|      0|      sin6.sin6_family = AF_INET6;
  253|      0|      if (makeIPv6sockaddr(str, &sin6) < 0) {
  ------------------
  |  Branch (253:11): [True: 0, False: 0]
  ------------------
  254|      0|        throw PDNSException("Unable to convert presentation address '" + str + "'");
  255|      0|      }
  256|      0|    }
  257|  2.75k|    if (sin4.sin_port == 0) { // 'str' overrides port!
  ------------------
  |  Branch (257:9): [True: 2.75k, False: 2]
  ------------------
  258|       |      sin4.sin_port = htons(port);
  259|  2.75k|    }
  260|  2.75k|  }
_ZN12ComboAddressC2Ev:
  212|  2.76k|  {
  213|       |    sin4.sin_family = AF_INET;
  214|  2.76k|    sin4.sin_addr.s_addr = 0;
  215|  2.76k|    sin4.sin_port = 0;
  216|  2.76k|    sin6.sin6_scope_id = 0;
  217|  2.76k|    sin6.sin6_flowinfo = 0;
  218|  2.76k|  }
_ZNK12ComboAddress6isIPv4Ev:
  267|  2.75k|  {
  268|       |    return sin4.sin_family == AF_INET;
  269|  2.75k|  }
_ZN7NetmaskC2Ev:
  696|  2.76k|  {
  697|  2.76k|    d_network.sin4.sin_family = 0; // disable this doing anything useful
  698|  2.76k|    d_network.sin4.sin_port = 0; // this guarantees d_network compares identical
  699|  2.76k|  }
_ZN7NetmaskC2ERK12ComboAddressh:
  702|  2.75k|    d_network(network)
  703|  2.75k|  {
  704|  2.75k|    d_network.sin4.sin_port = 0;
  705|  2.75k|    setBits(bits);
  706|  2.75k|  }
_ZN7Netmask7setBitsEh:
  721|  2.75k|  {
  722|  2.75k|    d_bits = d_network.isIPv4() ? std::min(value, static_cast<uint8_t>(32U)) : std::min(value, static_cast<uint8_t>(128U));
  ------------------
  |  Branch (722:14): [True: 2.75k, False: 0]
  ------------------
  723|       |
  724|  2.75k|    if (d_bits < 32) {
  ------------------
  |  Branch (724:9): [True: 2.75k, False: 0]
  ------------------
  725|  2.75k|      d_mask = ~(0xFFFFFFFF >> d_bits);
  726|  2.75k|    }
  727|      0|    else {
  728|       |      // note that d_mask is unused for IPv6
  729|      0|      d_mask = 0xFFFFFFFF;
  730|      0|    }
  731|       |
  732|  2.75k|    if (isIPv4()) {
  ------------------
  |  Branch (732:9): [True: 2.75k, False: 0]
  ------------------
  733|  2.75k|      d_network.sin4.sin_addr.s_addr = htonl(ntohl(d_network.sin4.sin_addr.s_addr) & d_mask);
  734|  2.75k|    }
  735|      0|    else if (isIPv6()) {
  ------------------
  |  Branch (735:14): [True: 0, False: 0]
  ------------------
  736|      0|      uint8_t bytes = d_bits / 8;
  737|      0|      auto* address = reinterpret_cast<uint8_t*>(&d_network.sin6.sin6_addr.s6_addr); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
  738|      0|      uint8_t bits = d_bits % 8;
  739|      0|      auto mask = static_cast<uint8_t>(~(0xFF >> bits));
  740|       |
  741|      0|      if (bytes < sizeof(d_network.sin6.sin6_addr.s6_addr)) {
  ------------------
  |  Branch (741:11): [True: 0, False: 0]
  ------------------
  742|      0|        address[bytes] &= mask; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  743|      0|      }
  744|       |
  745|      0|      for (size_t idx = bytes + 1; idx < sizeof(d_network.sin6.sin6_addr.s6_addr); ++idx) {
  ------------------
  |  Branch (745:36): [True: 0, False: 0]
  ------------------
  746|      0|        address[idx] = 0; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  747|      0|      }
  748|      0|    }
  749|  2.75k|  }
_ZNK7Netmask10getNetworkEv:
  862|  2.75k|  {
  863|  2.75k|    return d_network;
  864|  2.75k|  }
_ZNK7Netmask7getBitsEv:
  872|  2.75k|  {
  873|  2.75k|    return d_bits;
  874|  2.75k|  }
_ZNK7Netmask6isIPv4Ev:
  882|  8.26k|  {
  883|       |    return d_network.sin4.sin_family == AF_INET;
  884|  8.26k|  }
_ZN19AddressAndPortRangeC2Ev:
 1885|      2|    d_addrMask(0), d_portMask(0)
 1886|      2|  {
 1887|      2|    d_addr.sin4.sin_family = 0; // disable this doing anything useful
 1888|      2|    d_addr.sin4.sin_port = 0; // this guarantees d_network compares identical
 1889|      2|  }
_ZN12NetmaskGroupC2Ev:
 1722|      8|  NetmaskGroup() noexcept = default;
_ZN11NetmaskTreeIb7NetmaskEC2Ev:
 1327|      8|    d_root(new TreeNode()), d_left(nullptr)
 1328|      8|  {
 1329|      8|  }
_ZN11NetmaskTreeIb7NetmaskE8TreeNodeC2Ev:
 1032|      8|      parent(nullptr), node(), assigned(false), d_bits(0)
 1033|      8|    {
 1034|      8|    }
_ZN11NetmaskTreeI8DynBlock19AddressAndPortRangeE8TreeNodeC2Ev:
 1032|      2|      parent(nullptr), node(), assigned(false), d_bits(0)
 1033|      2|    {
 1034|      2|    }
_ZN11NetmaskTreeI8DynBlock19AddressAndPortRangeEC2Ev:
 1327|      2|    d_root(new TreeNode()), d_left(nullptr)
 1328|      2|  {
 1329|      2|  }

_ZN11LockGuardedINSt3__15dequeINS0_10unique_ptrI18CrossProtocolQueryNS0_14default_deleteIS3_EEEENS0_9allocatorIS6_EEEEEC2Ev:
  314|      2|  explicit LockGuarded() = default;
_ZN11LockGuardedINSt3__110shared_ptrIN7dnsdist13configuration20RuntimeConfigurationEEEEC2EOS5_:
  310|      2|    d_value(std::move(value))
  311|      2|  {
  312|      2|  }
_ZN11LockGuardedIN19DynBlockMaintenance4TopsEEC2Ev:
  314|      2|  explicit LockGuarded() = default;
_ZN11LockGuardedINSt3__16vectorINS0_10shared_ptrI18DynBlockRulesGroupEENS0_9allocatorIS4_EEEEEC2Ev:
  314|      2|  explicit LockGuarded() = default;
_ZN11LockGuardedINSt3__110shared_ptrI11NetmaskTreeI8DynBlock19AddressAndPortRangeEEEEC2EOS6_:
  310|      2|    d_value(std::move(value))
  311|      2|  {
  312|      2|  }
_ZN11LockGuardedINSt3__110shared_ptrI15SuffixMatchTreeI8DynBlockEEEEC2EOS5_:
  310|      2|    d_value(std::move(value))
  311|      2|  {
  312|      2|  }
_ZN20RecursiveLockGuardedI10LuaContextEC2EOS0_:
  415|      2|    d_value(std::move(value))
  416|      2|  {
  417|      2|  }
_ZN11LockGuardedINSt3__16vectorINS0_10shared_ptrIN7dnsdist16ServiceDiscovery18UpgradeableBackendEEENS0_9allocatorIS6_EEEEEC2Ev:
  314|      2|  explicit LockGuarded() = default;
_ZN11LockGuardedINSt3__16vectorINS0_4pairI7timevalNS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEEENS7_ISA_EEEEEC2Ev:
  314|      2|  explicit LockGuarded() = default;
_ZN11LockGuardedIN27ConcurrentConnectionManager4DataEEC2Ev:
  314|      4|  explicit LockGuarded() = default;
_ZN11LockGuardedIN27ConcurrentConnectionManager4DataEE4lockEv:
  322|      4|  {
  323|      4|    return LockGuardedHolder<T>(d_value, d_mutex);
  324|      4|  }
_ZN17LockGuardedHolderIN27ConcurrentConnectionManager4DataEEC2ERS1_RNSt3__15mutexE:
  236|      4|    d_lock(mutex), d_value(value)
  237|      4|  {
  238|      4|  }
_ZNK17LockGuardedHolderIN27ConcurrentConnectionManager4DataEEptEv:
  246|      4|  {
  247|      4|    return &d_value;
  248|      4|  }
_ZN11LockGuardedINSt3__16vectorINS0_8functionIFvvEEENS0_9allocatorIS4_EEEEEC2Ev:
  314|      2|  explicit LockGuarded() = default;
_ZN11LockGuardedINSt3__16vectorINS0_4pairINS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEENS0_8functionIFvvEEEEENS6_ISC_EEEEEC2Ev:
  314|      2|  explicit LockGuarded() = default;
_ZN11LockGuardedINSt3__16vectorINS0_8functionIFvRKNS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEbEEENS6_ISC_EEEEEC2Ev:
  314|      2|  explicit LockGuarded() = default;
_ZN17SharedLockGuardedIN5boost15circular_bufferIN7dnsdist17MacAddressesCache5EntryENSt3__19allocatorIS4_EEEEEC2Ev:
  583|      2|  explicit SharedLockGuarded() = default;
_ZN17SharedLockGuardedINSt3__13mapINS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEENS1_IS7_N7dnsdist7metrics14MutableCounterENS0_4lessIS7_EENS5_INS0_4pairIKS7_SA_EEEEEENSB_IvEENS5_INSD_ISE_SH_EEEEEEEC2Ev:
  583|      2|  explicit SharedLockGuarded() = default;
_ZN17SharedLockGuardedINSt3__13mapINS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEENS1_IS7_N7dnsdist7metrics12MutableGaugeENS0_4lessIS7_EENS5_INS0_4pairIKS7_SA_EEEEEENSB_IvEENS5_INSD_ISE_SH_EEEEEEEC2Ev:
  583|      2|  explicit SharedLockGuarded() = default;
_ZN17SharedLockGuardedINSt3__16vectorIN7dnsdist7metrics5Stats11EntryTripleENS0_9allocatorIS5_EEEEEC2EOS8_:
  579|      2|    d_value(std::move(value))
  580|      2|  {
  581|      2|  }
_ZN17SharedLockGuardedINSt3__113unordered_mapINS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEjNS0_4hashIS7_EENS0_8equal_toIS7_EENS5_INS0_4pairIKS7_jEEEEEEEC2Ev:
  583|      2|  explicit SharedLockGuarded() = default;
_ZN11LockGuardedIN15TLSSessionCache9CacheDataEEC2Ev:
  314|      2|  explicit LockGuarded() = default;
_ZN11LockGuardedIN5boost11multi_index21multi_index_containerIN7dnsdist11ClientEntryENS1_10indexed_byINS1_13hashed_uniqueINS1_3tagINS3_10AddressTagEN4mpl_2naESA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_EENS1_6memberIS4_19AddressAndPortRangeXadL_ZNS4_6d_addrEEEEENSD_4hashESA_EENS1_18ordered_non_uniqueINS7_INS3_7TimeTagESA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_EENSC_IS4_lXadL_ZNS4_10d_lastSeenEEEEESA_EESA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_SA_EENSt3__19allocatorIS4_EEEEEC2Ev:
  314|     32|  explicit LockGuarded() = default;
_ZN17SharedLockGuardedINSt3__113unordered_mapINS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEENS0_7variantIJNS0_8functionIFvRKN6YaHTTP7RequestERNSA_8ResponseERKN4Logr6LoggerEEEENS9_IFvSD_SF_EEEEEENS0_4hashIS7_EENS0_8equal_toIS7_EENS5_INS0_4pairIKS7_SO_EEEEEEEC2Ev:
  583|      2|  explicit SharedLockGuarded() = default;
_ZN11LockGuardedIbEC2EOb:
  310|      2|    d_value(std::move(value))
  311|      2|  {
  312|      2|  }

_Z11getHostnamev:
  479|      2|{
  480|      2|  const size_t maxHostNameBufSize = getMaxHostNameSize() + 1;
  481|      2|  std::string hostname;
  482|      2|  hostname.resize(maxHostNameBufSize, 0);
  483|       |
  484|      2|  if (gethostname(hostname.data(), maxHostNameBufSize) == -1) {
  ------------------
  |  Branch (484:7): [True: 0, False: 2]
  ------------------
  485|      0|    return std::nullopt;
  486|      0|  }
  487|       |
  488|      2|  hostname.resize(strlen(hostname.c_str()));
  489|      2|  return std::make_optional(hostname);
  490|      2|}
_Z16makeIPv4sockaddrRKNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEP11sockaddr_in:
  778|  2.75k|{
  779|  2.75k|  std::string str(arg);
  780|  2.75k|  if (str.empty()) {
  ------------------
  |  Branch (780:7): [True: 0, False: 2.75k]
  ------------------
  781|      0|    return -1;
  782|      0|  }
  783|  2.75k|  struct in_addr inp{};
  784|       |
  785|  2.75k|  string::size_type pos = str.find(':');
  786|  2.75k|  if (pos == string::npos) { // no port specified, not touching the port
  ------------------
  |  Branch (786:7): [True: 2.75k, False: 2]
  ------------------
  787|  2.75k|    if (inet_aton(str.c_str(), &inp) != 0) {
  ------------------
  |  Branch (787:9): [True: 2.75k, False: 0]
  ------------------
  788|  2.75k|      ret->sin_addr.s_addr = inp.s_addr;
  789|  2.75k|      return 0;
  790|  2.75k|    }
  791|      0|    return -1;
  792|  2.75k|  }
  793|      2|  if (*(str.c_str() + pos + 1) == 0) { // trailing :
  ------------------
  |  Branch (793:7): [True: 0, False: 2]
  ------------------
  794|      0|    return -1;
  795|      0|  }
  796|       |
  797|      2|  auto* eptr = str.data() + str.size();
  798|      2|  int port = static_cast<int>(strtol(str.c_str() + pos + 1, &eptr, 10));
  799|      2|  if (port < 0 || port > 65535) {
  ------------------
  |  Branch (799:7): [True: 0, False: 2]
  |  Branch (799:19): [True: 0, False: 2]
  ------------------
  800|      0|    return -1;
  801|      0|  }
  802|      2|  if (*eptr != 0) {
  ------------------
  |  Branch (802:7): [True: 0, False: 2]
  ------------------
  803|      0|    return -1;
  804|      0|  }
  805|       |
  806|      2|  ret->sin_port = htons(port);
  807|      2|  if (inet_aton(str.substr(0, pos).c_str(), &inp) != 0) {
  ------------------
  |  Branch (807:7): [True: 2, False: 0]
  ------------------
  808|      2|    ret->sin_addr.s_addr = inp.s_addr;
  809|      2|    return 0;
  810|      2|  }
  811|      0|  return -1;
  812|      2|}
misc.cc:_ZL18getMaxHostNameSizev:
  462|      2|{
  463|      2|#if defined(HOST_NAME_MAX)
  464|      2|  return HOST_NAME_MAX;
  465|      0|#endif
  466|       |
  467|      0|#if defined(_SC_HOST_NAME_MAX)
  468|      0|  auto tmp = sysconf(_SC_HOST_NAME_MAX);
  469|      0|  if (tmp != -1) {
  ------------------
  |  Branch (469:7): [True: 0, False: 0]
  ------------------
  470|      0|    return tmp;
  471|      0|  }
  472|      0|#endif
  473|       |
  474|      0|  const size_t maxHostNameSize = 255;
  475|      0|  return maxHostNameSize;
  476|      0|}

_ZN13FDMultiplexer17getMultiplexerMapEv:
  259|      4|  {
  260|      4|    static FDMultiplexermap_t theMap;
  261|      4|    return theMap;
  262|      4|  }

_ZN14noinit_adaptorINSt3__19allocatorIhEEEC2Ev:
   22|  10.8k|  noinit_adaptor(): Allocator() { }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhRKhJEEEvPT_OT0_DpOT1_:
   36|  20.9M|  void construct(U* p, V&& v, Args&&... args) {
   37|  20.9M|    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
   38|  20.9M|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE7destroyIhEEvPT_:
   41|  75.7M|  void destroy(U* p) {
   42|  75.7M|    p->~U();
   43|  75.7M|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhRhJEEEvPT_OT0_DpOT1_:
   36|  11.6M|  void construct(U* p, V&& v, Args&&... args) {
   37|  11.6M|    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
   38|  11.6M|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhEEvPT_:
   31|  83.4k|  void construct(U* p) {
   32|  83.4k|    ::new((void*)p) U;
   33|  83.4k|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhhJEEEvPT_OT0_DpOT1_:
   36|  30.4M|  void construct(U* p, V&& v, Args&&... args) {
   37|  30.4M|    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
   38|  30.4M|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhRKcJEEEvPT_OT0_DpOT1_:
   36|  12.6M|  void construct(U* p, V&& v, Args&&... args) {
   37|  12.6M|    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
   38|  12.6M|  }

_ZN17RegisterOurselvesC2Ev:
   58|      2|  {
   59|      2|    FDMultiplexer::getMultiplexerMap().emplace(2, &make);
   60|      2|  }

qtype.cc:_ZL12swapElementsRKNSt3__13mapIKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEtNS_4lessIS7_EENS4_INS_4pairIS7_tEEEEEE:
  103|      2|{
  104|      2|  std::map<uint16_t, const std::string> ret;
  105|       |
  106|    138|  for (const auto& name : names) {
  ------------------
  |  Branch (106:25): [True: 138, False: 2]
  ------------------
  107|    138|    ret.emplace(name.second, name.first);
  108|    138|  }
  109|      2|  return ret;
  110|      2|}

_ZN5QTypeC2Et:
   49|      2|    code(qtype) {}
_ZNK6QClasscvtEv:
  201|      8|  {
  202|      8|    return qclass;
  203|      8|  }

_ZN17GlobalStateHolderIN7dnsdist13configuration20RuntimeConfigurationEEC2Ev:
  105|      2|    d_state(std::make_shared<T>())
  106|      2|  {}
_ZN17GlobalStateHolderI11NetmaskTreeI8DynBlock19AddressAndPortRangeEEC2Ev:
  105|      2|    d_state(std::make_shared<T>())
  106|      2|  {}
_ZN17GlobalStateHolderI15SuffixMatchTreeI8DynBlockEEC2Ev:
  105|      2|    d_state(std::make_shared<T>())
  106|      2|  {}

_ZN4pdns12stat_t_traitImEC2Em:
   39|     92|    {
   40|     92|      new(&counter) atomic_t(value);
   41|     92|    }
_ZN4pdns12stat_t_traitIdEC2Ed:
   39|     48|    {
   40|     48|      new(&counter) atomic_t(value);
   41|     48|    }

_ZN4pdns5views16UnsignedCharViewC2EPKcm:
   33|   702k|    view(data_, size_)
   34|   702k|  {
   35|   702k|  }
_ZN4pdns5views16UnsignedCharViewC2EPKhm:
   38|  5.03k|    view(reinterpret_cast<const char*>(data_), size_)
   39|  5.03k|  {
   40|  5.03k|  }
_ZNK4pdns5views16UnsignedCharView2atEm:
   44|  6.51M|  {
   45|  6.51M|    return reinterpret_cast<const unsigned char&>(view.at(pos));
   46|  6.51M|  }
_ZNK4pdns5views16UnsignedCharView4sizeEv:
   60|  9.24M|  {
   61|  9.24M|    return view.size();
   62|  9.24M|  }

