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

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

_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|   582k|{
  130|   582k|  if (offset >= len)
  ------------------
  |  Branch (130:7): [True: 3.96k, False: 578k]
  ------------------
  131|  3.96k|    throw std::range_error("Trying to read past the end of the buffer ("+std::to_string(offset)+ " >= "+std::to_string(len)+")");
  132|       |
  133|   578k|  if(!uncompress) {
  ------------------
  |  Branch (133:6): [True: 3.07k, False: 575k]
  ------------------
  134|  3.07k|    if(const void * fnd=memchr(pos+offset, 0, len-offset)) {
  ------------------
  |  Branch (134:21): [True: 3.02k, False: 59]
  ------------------
  135|  3.02k|      d_storage.reserve(2+(const char*)fnd-(pos+offset));
  136|  3.02k|    }
  137|  3.07k|  }
  138|       |
  139|   578k|  packetParser(pos, len, offset, uncompress, qtype, qclass, consumed, 0, minOffset, 0, pointerBudget);
  140|   578k|}
_ZN7DNSName23parsePacketUncompressedERKN4pdns5views16UnsignedCharViewEmb:
  154|   790k|{
  155|   790k|  const size_t initialPos = pos;
  156|   790k|  auto existingSize = d_storage.size();
  157|   790k|  const size_t neededSizeForFinalLabel = /* final empty label length */ (existingSize == 0 ? 1U : 0U);
  ------------------
  |  Branch (157:74): [True: 687k, False: 102k]
  ------------------
  158|   790k|  size_t totalLength = 0;
  159|   790k|  unsigned char labellen = 0;
  160|       |
  161|  5.52M|  do {
  162|  5.52M|    labellen = view.at(pos);
  163|  5.52M|    ++pos;
  164|       |
  165|  5.52M|    if (labellen == 0) {
  ------------------
  |  Branch (165:9): [True: 576k, False: 4.94M]
  ------------------
  166|   576k|      --pos;
  167|   576k|      break;
  168|   576k|    }
  169|       |
  170|  4.94M|    if (labellen >= 0xc0) {
  ------------------
  |  Branch (170:9): [True: 212k, False: 4.73M]
  ------------------
  171|   212k|      if (!uncompress) {
  ------------------
  |  Branch (171:11): [True: 66, False: 212k]
  ------------------
  172|     66|        throw std::range_error("Found compressed label, instructed not to follow");
  173|     66|      }
  174|   212k|      --pos;
  175|   212k|      break;
  176|   212k|    }
  177|       |
  178|  4.73M|    if ((labellen & 0xc0) != 0) {
  ------------------
  |  Branch (178:9): [True: 368, False: 4.73M]
  ------------------
  179|    368|      throw std::range_error("Found an invalid label length in qname (only one of the first two bits is set)");
  180|    368|    }
  181|  4.73M|    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.73M|    if ((existingSize + totalLength + labellen + 1U + neededSizeForFinalLabel) > s_maxDNSNameLength) {
  ------------------
  |  Branch (184:9): [True: 31, False: 4.73M]
  ------------------
  185|     31|      throw std::range_error("name too long to append");
  186|     31|    }
  187|  4.73M|    if (pos + labellen >= view.size()) {
  ------------------
  |  Branch (187:9): [True: 534, False: 4.73M]
  ------------------
  188|    534|      throw std::range_error("Found an invalid label length in qname");
  189|    534|    }
  190|  4.73M|    pos += labellen;
  191|  4.73M|    totalLength += 1U + labellen;
  192|  4.73M|  }
  193|  4.73M|  while (pos < view.size());
  ------------------
  |  Branch (193:10): [True: 4.73M, False: 0]
  ------------------
  194|       |
  195|   789k|  if (totalLength != 0) {
  ------------------
  |  Branch (195:7): [True: 257k, False: 531k]
  ------------------
  196|   257k|    if (existingSize > 0) {
  ------------------
  |  Branch (196:9): [True: 101k, False: 155k]
  ------------------
  197|       |      // remove the last label count, we are about to override it */
  198|   101k|      --existingSize;
  199|   101k|    }
  200|   257k|    if ((existingSize + totalLength + 1U) > s_maxDNSNameLength) {
  ------------------
  |  Branch (200:9): [True: 0, False: 257k]
  ------------------
  201|      0|      throw std::range_error("name too long to append");
  202|      0|    }
  203|   257k|    d_storage.reserve(existingSize + totalLength + 1);
  204|   257k|    d_storage.resize(existingSize + totalLength);
  205|   257k|    memcpy(&d_storage.at(existingSize), &view.at(initialPos), totalLength);
  206|   257k|    d_storage.append(1, static_cast<char>(0));
  207|   257k|  }
  208|   789k|  return pos;
  209|   789k|}
_ZN7DNSName12packetParserEPKcmmbPtS2_PjittPm:
  213|   790k|{
  214|   790k|  if (offset >= len) {
  ------------------
  |  Branch (214:7): [True: 0, False: 790k]
  ------------------
  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|   790k|  if (offset < static_cast<size_t>(minOffset)) {
  ------------------
  |  Branch (218:7): [True: 0, False: 790k]
  ------------------
  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|   790k|  unsigned char labellen{0};
  222|       |
  223|   790k|  pdns::views::UnsignedCharView view(qpos, len);
  224|   790k|  auto pos = parsePacketUncompressed(view, offset, uncompress);
  225|       |
  226|       |
  227|   790k|  labellen = view.at(pos);
  228|   790k|  if (pos == offset && labellen != 0) {
  ------------------
  |  Branch (228:7): [True: 531k, False: 258k]
  |  Branch (228:24): [True: 109k, False: 422k]
  ------------------
  229|       |    // It's a pointer
  230|   109k|    if (pointerBudget != nullptr) {
  ------------------
  |  Branch (230:9): [True: 109k, False: 0]
  ------------------
  231|   109k|      if (*pointerBudget == 0) {
  ------------------
  |  Branch (231:11): [True: 0, False: 109k]
  ------------------
  232|      0|        throw std::range_error("Too many compression pointers processed in packet");
  233|      0|      }
  234|   109k|      (*pointerBudget)--;
  235|   109k|    }
  236|       |    // Are we chasing a pointer chain already for this name?
  237|   109k|    if (pointerChainLength++ > s_maxPointersToPointers) {
  ------------------
  |  Branch (237:9): [True: 11, False: 109k]
  ------------------
  238|     11|      throw std::range_error("Too many pointer to pointers during decompression (" + std::to_string(pointerChainLength) + ")");
  239|     11|    }
  240|   109k|  }
  241|   680k|  else {
  242|   680k|    pointerChainLength = 0; // not an immediate pointer to pointer case any more
  243|   680k|  }
  244|   790k|  pos++;
  245|   790k|  if (labellen != 0 && pos < view.size()) {
  ------------------
  |  Branch (245:7): [True: 212k, False: 577k]
  |  Branch (245:24): [True: 211k, False: 532]
  ------------------
  246|   211k|    if (labellen < 0xc0) {
  ------------------
  |  Branch (246:9): [True: 0, False: 211k]
  ------------------
  247|      0|      throw std::range_error("Invalid label byte during decompression ("+std::to_string(labellen)+")");
  248|      0|    }
  249|       |
  250|   211k|    if (!uncompress) {
  ------------------
  |  Branch (250:9): [True: 0, False: 211k]
  ------------------
  251|      0|      throw std::range_error("Found compressed label, instructed not to follow");
  252|      0|    }
  253|       |
  254|   211k|    labellen &= (~0xc0);
  255|   211k|    size_t newpos = (labellen << 8) + view.at(pos);
  256|       |
  257|   211k|    if (newpos >= offset) {
  ------------------
  |  Branch (257:9): [True: 343, False: 211k]
  ------------------
  258|    343|      throw std::range_error("Found a forward reference during label decompression");
  259|    343|    }
  260|       |
  261|   211k|    if (newpos < minOffset) {
  ------------------
  |  Branch (261:9): [True: 34, False: 211k]
  ------------------
  262|     34|      throw std::range_error("Invalid label position during decompression ("+std::to_string(newpos)+ " < "+std::to_string(minOffset)+")");
  263|     34|    }
  264|       |
  265|   211k|    if (++depth > s_maxPointersPerName) {
  ------------------
  |  Branch (265:9): [True: 6, False: 211k]
  ------------------
  266|      6|      throw std::range_error("Abort label decompression after too many redirects (" + std::to_string(depth) + ")");
  267|      6|    }
  268|       |
  269|   211k|    packetParser(qpos, len, newpos, true, nullptr, nullptr, nullptr, depth, minOffset, pointerChainLength, pointerBudget);
  270|       |
  271|   211k|    pos++;
  272|   211k|  }
  273|       |
  274|   789k|  if (d_storage.empty()) {
  ------------------
  |  Branch (274:7): [True: 422k, False: 367k]
  ------------------
  275|   422k|    d_storage.append(1, static_cast<char>(0)); // we just parsed the root
  276|   422k|  }
  277|       |
  278|   789k|  if (consumed != nullptr) {
  ------------------
  |  Branch (278:7): [True: 577k, False: 212k]
  ------------------
  279|   577k|    *consumed = pos - offset;
  280|   577k|  }
  281|       |
  282|   789k|  if (qtype != nullptr) {
  ------------------
  |  Branch (282:7): [True: 2.94k, False: 786k]
  ------------------
  283|  2.94k|    if (pos + 2 > view.size()) {
  ------------------
  |  Branch (283:9): [True: 43, False: 2.89k]
  ------------------
  284|     43|      throw std::range_error("Trying to read qtype past the end of the buffer ("+std::to_string(pos + 2)+ " > "+std::to_string(len)+")");
  285|     43|    }
  286|  2.89k|    *qtype = view.at(pos)*256 + view.at(pos+1);
  287|  2.89k|  }
  288|       |
  289|   789k|  pos += 2;
  290|   789k|  if (qclass != nullptr) {
  ------------------
  |  Branch (290:7): [True: 2.89k, False: 786k]
  ------------------
  291|  2.89k|    if (pos + 2 > view.size()) {
  ------------------
  |  Branch (291:9): [True: 15, False: 2.88k]
  ------------------
  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.88k|    *qclass = view.at(pos)*256 + view.at(pos+1);
  295|  2.88k|  }
  296|   789k|}
_ZNK7DNSName10wirelengthEv:
  367|  7.18k|size_t DNSName::wirelength() const {
  368|  7.18k|  return d_storage.length();
  369|  7.18k|}
dnsname.cc:_ZL16checkLabelLengthh:
  143|  4.73M|{
  144|  4.73M|  if (length == 0) {
  ------------------
  |  Branch (144:7): [True: 0, False: 4.73M]
  ------------------
  145|      0|    throw std::range_error("no such thing as an empty label to append");
  146|      0|  }
  147|  4.73M|  if (length > DNSName::s_maxDNSLabelLength) {
  ------------------
  |  Branch (147:7): [True: 0, False: 4.73M]
  ------------------
  148|      0|    throw std::range_error("label too long to append");
  149|      0|  }
  150|  4.73M|}

_Z11dns_tolowerh:
   58|   120k|{
   59|   120k|  return dns_tolower_table[chr];
   60|   120k|}
_Z39pdns_ilexicographical_compare_three_wayNSt3__117basic_string_viewIcNS_11char_traitsIcEEEES3_:
   64|   131k|{
   65|   131k|  const unsigned char *aPtr = (const unsigned char*)a.data(), *bPtr = (const unsigned char*)b.data();
   66|   131k|  const unsigned char *aEptr = aPtr + a.length(), *bEptr = bPtr + b.length();
   67|   636k|  while(aPtr != aEptr && bPtr != bEptr) {
  ------------------
  |  Branch (67:9): [True: 535k, False: 100k]
  |  Branch (67:26): [True: 535k, False: 0]
  ------------------
   68|   535k|    if (*aPtr != *bPtr) {
  ------------------
  |  Branch (68:9): [True: 30.8k, False: 505k]
  ------------------
   69|  30.8k|      if (int rc = dns_tolower(*aPtr) - dns_tolower(*bPtr); rc != 0) {
  ------------------
  |  Branch (69:61): [True: 30.5k, False: 228]
  ------------------
   70|  30.5k|        return rc;
   71|  30.5k|      }
   72|  30.8k|    }
   73|   505k|    aPtr++;
   74|   505k|    bPtr++;
   75|   505k|  }
   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|   100k|  if (aPtr == aEptr) {
  ------------------
  |  Branch (79:7): [True: 100k, False: 0]
  ------------------
   80|   100k|    if (bPtr != bEptr) {
  ------------------
  |  Branch (80:9): [True: 0, False: 100k]
  ------------------
   81|      0|      return -1; // a < b
   82|      0|    }
   83|   100k|  }
   84|      0|  else {
   85|      0|    return 1; // a > b
   86|      0|  }
   87|   100k|  return 0; // a == b
   88|   100k|}
_ZN7DNSNameaSEOS_:
  158|   569k|  {
  159|   569k|    if (this != &rhs) {
  ------------------
  |  Branch (159:9): [True: 569k, False: 0]
  ------------------
  160|   569k|      d_storage = std::move(rhs.d_storage);
  161|   569k|    }
  162|   569k|    return *this;
  163|   569k|  }
_ZNK7DNSName5emptyEv:
  210|   306k|  bool empty() const { return d_storage.empty(); }
_ZNK7DNSName6isRootEv:
  211|   364k|  bool isRoot() const { return d_storage.size()==1 && d_storage[0]==0; }
  ------------------
  |  Branch (211:32): [True: 147k, False: 216k]
  |  Branch (211:55): [True: 147k, False: 0]
  ------------------
_ZNK7DNSName10getStorageEv:
  261|   167k|  const string_t& getStorage() const {
  262|   167k|    return d_storage;
  263|   167k|  }
_ZNK7DNSNameeqERKS_:
  826|  82.9k|{
  827|  82.9k|  if (rhs.empty() != empty() || rhs.d_storage.size() != d_storage.size()) {
  ------------------
  |  Branch (827:7): [True: 0, False: 82.9k]
  |  Branch (827:33): [True: 77.6k, False: 5.33k]
  ------------------
  828|  77.6k|    return false;
  829|  77.6k|  }
  830|       |
  831|  5.33k|  const auto* us = d_storage.cbegin();
  832|  5.33k|  const auto* p = rhs.d_storage.cbegin();
  833|  30.2k|  for (; us != d_storage.cend() && p != rhs.d_storage.cend(); ++us, ++p) {
  ------------------
  |  Branch (833:10): [True: 29.5k, False: 728]
  |  Branch (833:36): [True: 29.5k, False: 0]
  ------------------
  834|  29.5k|    if (dns_tolower(*p) != dns_tolower(*us)) {
  ------------------
  |  Branch (834:9): [True: 4.61k, False: 24.9k]
  ------------------
  835|  4.61k|      return false;
  836|  4.61k|    }
  837|  29.5k|  }
  838|    728|  return true;
  839|  5.33k|}
_ZN7DNSNameC2ERKS_:
  164|  7.18k|  DNSName(const DNSName& a) = default;
_ZN7DNSNameC2Ev:
  148|  7.40k|  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:
  475|   211k|{
  476|   211k|  unsigned char *p = reinterpret_cast<unsigned char*>(&ah);
  477|       |
  478|  2.31M|  for(unsigned int n = 0; n < sizeof(dnsrecordheader); ++n) {
  ------------------
  |  Branch (478:27): [True: 2.10M, False: 211k]
  ------------------
  479|  2.10M|    p[n] = d_content.at(d_pos++);
  480|  2.10M|  }
  481|       |
  482|   211k|  ah.d_type = ntohs(ah.d_type);
  483|   211k|  ah.d_class = ntohs(ah.d_class);
  484|   211k|  ah.d_clen = ntohs(ah.d_clen);
  485|   211k|  ah.d_ttl = ntohl(ah.d_ttl);
  486|       |
  487|   211k|  d_startrecordpos = d_pos; // needed for getBlob later on
  488|   211k|  d_recordlen = ah.d_clen;
  489|   211k|  if (d_pos > d_content.size() || (d_content.size() - d_pos) < (d_recordlen)) {
  ------------------
  |  Branch (489:7): [True: 1.91k, False: 209k]
  |  Branch (489:35): [True: 567, False: 209k]
  ------------------
  490|    567|    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()) + ")");
  491|    567|  }
  492|   211k|}
_ZN12PacketReader11get16BitIntEv:
  578|   715k|{
  579|   715k|  uint16_t ret=0;
  580|   715k|  if (!isWithinRecordBoundaries(d_pos, d_pos + sizeof(ret))) {
  ------------------
  |  Branch (580:7): [True: 0, False: 715k]
  ------------------
  581|      0|    throw std::out_of_range("Attempt to read 16 bit value outside of record");
  582|      0|  }
  583|   715k|  ret+=static_cast<uint8_t>(d_content.at(d_pos++));
  584|   715k|  ret<<=8;
  585|   715k|  ret+=static_cast<uint8_t>(d_content.at(d_pos++));
  586|       |
  587|   715k|  return ret;
  588|   715k|}
_ZN12PacketReader7getNameEv:
  599|   579k|{
  600|   579k|  unsigned int consumed{0};
  601|   579k|  const auto initialPosition = d_pos;
  602|   579k|  try {
  603|   579k|    uint16_t minOffset = d_standalone ? 0 : sizeof(dnsheader);
  ------------------
  |  Branch (603:26): [True: 0, False: 579k]
  ------------------
  604|   579k|    bool uncompress = !d_standalone;
  605|       |
  606|   579k|    DNSName name((const char*) d_content.data(), d_content.size(), d_pos, uncompress, nullptr /* qtype */, nullptr /* qclass */, &consumed, minOffset, &d_pointerBudget);
  607|       |
  608|   579k|    d_pos += consumed;
  609|       |    // if we know the length of the record, and we were parsing a DNS name inside the record contents
  610|       |    // (not the owner name, in which case d_startrecordpos and d_recordlen still refer to the content of the previous record),
  611|       |    // check that we did not go over the record boundary
  612|   579k|    if (!isWithinRecordBoundaries(initialPosition, d_pos, true)) {
  ------------------
  |  Branch (612:9): [True: 0, False: 579k]
  ------------------
  613|      0|      throw std::out_of_range("Attempt to read DNS name outside of record");
  614|      0|    }
  615|   579k|    return name;
  616|   579k|  }
  617|   579k|  catch(const std::range_error& re) {
  618|  5.17k|    throw std::out_of_range(string("dnsname issue: ")+re.what());
  619|  5.17k|  }
  620|   579k|  catch(...) {
  621|      0|    throw std::out_of_range("dnsname issue");
  622|      0|  }
  623|   579k|}
_ZN12PacketReader7xfrBlobERNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE:
  725|   134k|{
  726|   134k|  try {
  727|   134k|    if (d_recordlen != 0 && !(d_pos == (d_startrecordpos + d_recordlen))) {
  ------------------
  |  Branch (727:9): [True: 53.8k, False: 80.2k]
  |  Branch (727:29): [True: 53.8k, False: 0]
  ------------------
  728|  53.8k|      if (d_pos > (d_startrecordpos + d_recordlen)) {
  ------------------
  |  Branch (728:11): [True: 0, False: 53.8k]
  ------------------
  729|      0|        throw std::out_of_range("xfrBlob out of record range");
  730|      0|      }
  731|  53.8k|      blob.assign(&d_content.at(d_pos), &d_content.at(d_startrecordpos + d_recordlen - 1 ) + 1);
  732|  53.8k|    }
  733|  80.2k|    else {
  734|  80.2k|      blob.clear();
  735|  80.2k|    }
  736|       |
  737|   134k|    d_pos = d_startrecordpos + d_recordlen;
  738|   134k|  }
  739|   134k|  catch(...)
  740|   134k|  {
  741|      0|    throw std::out_of_range("xfrBlob out of range");
  742|      0|  }
  743|   134k|}
_Z18getDNSPacketLengthPKcm:
 1327|    483|{
 1328|    483|  uint32_t result = length;
 1329|    483|  if(length < sizeof(dnsheader)) {
  ------------------
  |  Branch (1329:6): [True: 0, False: 483]
  ------------------
 1330|      0|    return result;
 1331|      0|  }
 1332|    483|  try
 1333|    483|  {
 1334|    483|    const dnsheader_aligned dh(packet);
 1335|    483|    DNSPacketMangler dpm(const_cast<char*>(packet), length);
 1336|       |
 1337|    483|    const uint16_t qdcount = ntohs(dh->qdcount);
 1338|   119k|    for(size_t n = 0; n < qdcount; ++n) {
  ------------------
  |  Branch (1338:23): [True: 119k, False: 483]
  ------------------
 1339|   119k|      dpm.skipDomainName();
 1340|       |      /* type and class */
 1341|   119k|      dpm.skipBytes(4);
 1342|   119k|    }
 1343|    483|    const size_t numrecords = ntohs(dh->ancount) + ntohs(dh->nscount) + ntohs(dh->arcount);
 1344|    846|    for(size_t n = 0; n < numrecords; ++n) {
  ------------------
  |  Branch (1344:23): [True: 363, False: 483]
  ------------------
 1345|    363|      dpm.skipDomainName();
 1346|       |      /* type (2), class (2) and ttl (4) */
 1347|    363|      dpm.skipBytes(8);
 1348|    363|      dpm.skipRData();
 1349|    363|    }
 1350|    483|    result = dpm.getOffset();
 1351|    483|  }
 1352|    483|  catch(...)
 1353|    483|  {
 1354|    240|  }
 1355|    483|  return result;
 1356|    483|}

_ZN12PacketReaderC2ERKNSt3__117basic_string_viewIcNS0_11char_traitsIcEEEEtbb:
   72|  12.1k|    : d_pos(initialPos), d_startrecordpos(initialPos), d_internal(internalRepresentation), d_standalone(standalone), d_content(content)
   73|  12.1k|  {
   74|  12.1k|    if (content.size() > std::numeric_limits<uint16_t>::max()) {
  ------------------
  |  Branch (74:9): [True: 0, False: 12.1k]
  ------------------
   75|      0|      throw std::out_of_range("packet too large");
   76|      0|    }
   77|       |
   78|  12.1k|    d_recordlen = static_cast<uint16_t>(content.size());
   79|  12.1k|    d_pointerBudget = static_cast<size_t>(d_recordlen) * s_MaxPointersPerByte;
   80|  12.1k|  }
_ZNK12PacketReader11getPositionEv:
  212|  29.5k|  {
  213|  29.5k|    return d_pos;
  214|  29.5k|  }
_ZN12PacketReader4skipEt:
  217|  77.6k|  {
  218|  77.6k|    size_t stop = d_pos;
  219|  77.6k|    stop += n;
  220|  77.6k|    if (!isWithinRecordBoundaries(d_pos, d_pos + n)) {
  ------------------
  |  Branch (220:9): [True: 0, False: 77.6k]
  ------------------
  221|      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) + ")");
  222|      0|    }
  223|  77.6k|    if (stop > d_content.size()) {
  ------------------
  |  Branch (223:9): [True: 90, False: 77.5k]
  ------------------
  224|     90|      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()) + ")");
  225|     90|    }
  226|       |
  227|  77.5k|    d_pos += n;
  228|  77.5k|  }
_ZNK12PacketReader24isWithinRecordBoundariesEmmb:
  234|  1.36M|  {
  235|  1.36M|    if (initialPosition > endPosition) {
  ------------------
  |  Branch (235:9): [True: 0, False: 1.36M]
  ------------------
  236|      0|      return false;
  237|      0|    }
  238|  1.36M|    if (canBeOutsideRecordContent && d_recordlen == 0) {
  ------------------
  |  Branch (238:9): [True: 574k, False: 793k]
  |  Branch (238:38): [True: 118k, False: 455k]
  ------------------
  239|       |      // we don't know the record's length, nothing to check
  240|   118k|      return true;
  241|   118k|    }
  242|  1.24M|    const size_t endOfRecordContent = d_startrecordpos + d_recordlen;
  243|  1.24M|    if (canBeOutsideRecordContent && initialPosition >= endOfRecordContent) {
  ------------------
  |  Branch (243:9): [True: 455k, False: 793k]
  |  Branch (243:38): [True: 83.2k, False: 372k]
  ------------------
  244|       |      // our initial position is after the last known record content,
  245|       |      // we are probably parsing the owner name of the next record,
  246|       |      // nothing to check
  247|  83.2k|      return true;
  248|  83.2k|    }
  249|       |    // are we still inside the record's content?
  250|  1.16M|    return initialPosition >= d_startrecordpos && initialPosition <= endOfRecordContent && endPosition <= endOfRecordContent;
  ------------------
  |  Branch (250:12): [True: 1.16M, False: 0]
  |  Branch (250:51): [True: 1.16M, False: 0]
  |  Branch (250:92): [True: 1.16M, False: 0]
  ------------------
  251|  1.24M|  }
_ZN16DNSPacketManglerC2EPcm:
  669|    483|    : d_packet(packet), d_length(length), d_notyouroffset(12), d_offset(d_notyouroffset)
  670|    483|  {}
_ZN16DNSPacketMangler14skipDomainNameEv:
  677|   119k|  {
  678|   119k|    uint8_t len{};
  679|   119k|    bool isRoot = true;
  680|   137k|    while ((len = get8BitInt()) != 0) {
  ------------------
  |  Branch (680:12): [True: 19.6k, False: 117k]
  ------------------
  681|  19.6k|      isRoot = false;
  682|  19.6k|      if (len >= 0xc0) { // extended label
  ------------------
  |  Branch (682:11): [True: 1.69k, False: 17.9k]
  ------------------
  683|  1.69k|        get8BitInt();
  684|  1.69k|        return false;
  685|  1.69k|      }
  686|  17.9k|      skipBytes(len);
  687|  17.9k|    }
  688|   117k|    return isRoot;
  689|   119k|  }
_ZN16DNSPacketMangler9skipBytesEt:
  692|   137k|  {
  693|   137k|    moveOffset(bytes);
  694|   137k|  }
_ZN16DNSPacketMangler11get16BitIntEv:
  708|    267|  {
  709|    267|    const char* p = d_packet + d_offset;
  710|    267|    moveOffset(2);
  711|    267|    uint16_t ret;
  712|    267|    memcpy(&ret, p, sizeof(ret));
  713|       |    return ntohs(ret);
  714|    267|  }
_ZN16DNSPacketMangler10get8BitIntEv:
  717|   138k|  {
  718|   138k|    const char* p = d_packet + d_offset;
  719|   138k|    moveOffset(1);
  720|   138k|    return *p;
  721|   138k|  }
_ZN16DNSPacketMangler9skipRDataEv:
  724|    267|  {
  725|    267|    auto toskip = get16BitInt();
  726|    267|    moveOffset(toskip);
  727|    267|  }
_ZNK16DNSPacketMangler9getOffsetEv:
  764|    243|  {
  765|    243|    return d_offset;
  766|    243|  }
_ZN16DNSPacketMangler10moveOffsetEt:
  794|   276k|  {
  795|   276k|    d_notyouroffset += by;
  796|   276k|    if(d_notyouroffset > d_length)
  ------------------
  |  Branch (796:8): [True: 240, False: 276k]
  ------------------
  797|    240|      throw std::out_of_range("dns packet out of range: "+std::to_string(d_notyouroffset) +" > "
  798|    240|      + std::to_string(d_length) );
  799|   276k|  }

_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEEC2ERS6_RK7DNSNametth:
   43|  7.18k|  d_qname(qname), d_content(content)
   44|  7.18k|{
   45|  7.18k|  d_content.clear();
   46|  7.18k|  dnsheader dnsheader;
   47|       |
   48|  7.18k|  memset(&dnsheader, 0, sizeof(dnsheader));
   49|  7.18k|  dnsheader.id=0;
   50|  7.18k|  dnsheader.qdcount=htons(1);
   51|  7.18k|  dnsheader.opcode=opcode;
   52|       |
   53|  7.18k|  const uint8_t* ptr=(const uint8_t*)&dnsheader;
   54|  7.18k|  d_content.reserve(sizeof(dnsheader) + qname.wirelength() + sizeof(qtype) + sizeof(qclass));
   55|  7.18k|  d_content.resize(sizeof(dnsheader));
   56|  7.18k|  uint8_t* dptr=(&*d_content.begin());
   57|       |
   58|  7.18k|  memcpy(dptr, ptr, sizeof(dnsheader));
   59|  7.18k|  d_namepositions.reserve(16);
   60|  7.18k|  xfrName(qname, false);
   61|  7.18k|  xfr16BitInt(qtype);
   62|  7.18k|  xfr16BitInt(qclass);
   63|       |
   64|  7.18k|  if (d_content.size() > std::numeric_limits<decltype(d_truncatemarker)>::max()) {
  ------------------
  |  Branch (64:7): [True: 0, False: 7.18k]
  ------------------
   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|  7.18k|  d_truncatemarker = d_content.size();
   68|  7.18k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE11startRecordERK7DNSNametjtN17DNSResourceRecord5PlaceEb:
   77|   134k|{
   78|   134k|  d_compress = compress;
   79|   134k|  commit();
   80|   134k|  if (d_content.size() > std::numeric_limits<decltype(d_rollbackmarker)>::max()) {
  ------------------
  |  Branch (80:7): [True: 0, False: 134k]
  ------------------
   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|   134k|  d_rollbackmarker = d_content.size();
   84|       |
   85|   134k|  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: 123k, False: 10.3k]
  |  Branch (85:19): [True: 82.9k, False: 40.9k]
  |  Branch (85:37): [True: 728, False: 82.2k]
  ------------------
   86|    728|    static const std::array<unsigned char, 2> marker{0xc0, 0x0c};
   87|    728|    d_content.insert(d_content.end(), reinterpret_cast<const char *>(marker.begin()), reinterpret_cast<const char *>(marker.end()));
   88|    728|  }
   89|   133k|  else {
   90|   133k|    xfrName(name, compress);
   91|   133k|  }
   92|   134k|  xfr16BitInt(qtype);
   93|   134k|  xfr16BitInt(qclass);
   94|   134k|  xfr32BitInt(ttl);
   95|   134k|  xfr16BitInt(0); // this will be the record size
   96|   134k|  d_recordplace = place;
   97|       |
   98|   134k|  d_sor = d_content.size(); // this will remind us where to stuff the record size
   99|   134k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE6addOptEtttRKNS1_INS0_4pairItNS0_12basic_stringIcNS0_11char_traitsIcEENS3_IcEEEEEENS3_ISE_EEEEh:
  102|  4.93k|{
  103|  4.93k|  uint32_t ttl=0;
  104|       |
  105|  4.93k|  EDNS0Record stuff;
  106|       |
  107|  4.93k|  stuff.version = version;
  108|  4.93k|  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.93k|  stuff.extRCode = extRCode>>4;
  118|  4.93k|  if (extRCode != 0) { // As this trumps the existing RCODE
  ------------------
  |  Branch (118:7): [True: 1.97k, False: 2.95k]
  ------------------
  119|  1.97k|    getHeader()->rcode = extRCode;
  120|  1.97k|  }
  121|       |
  122|  4.93k|  static_assert(sizeof(EDNS0Record) == sizeof(ttl), "sizeof(EDNS0Record) must match sizeof(ttl)");
  123|  4.93k|  memcpy(&ttl, &stuff, sizeof(stuff));
  124|       |
  125|  4.93k|  ttl=ntohl(ttl); // will be reversed later on
  126|       |
  127|  4.93k|  startRecord(g_rootdnsname, QType::OPT, ttl, udpsize, DNSResourceRecord::ADDITIONAL, false);
  128|  35.5k|  for(auto const &option : options) {
  ------------------
  |  Branch (128:26): [True: 35.5k, False: 4.93k]
  ------------------
  129|  35.5k|    xfr16BitInt(option.first);
  130|  35.5k|    xfr16BitInt(option.second.length());
  131|  35.5k|    xfrBlob(option.second);
  132|  35.5k|  }
  133|  4.93k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE6commitEv:
  594|   138k|{
  595|   138k|  if (d_sor == 0) {
  ------------------
  |  Branch (595:7): [True: 7.75k, False: 130k]
  ------------------
  596|  7.75k|    return;
  597|  7.75k|  }
  598|       |
  599|   130k|  if (d_sor < 2 || d_sor > d_content.size()) {
  ------------------
  |  Branch (599:7): [True: 0, False: 130k]
  |  Branch (599:20): [True: 0, False: 130k]
  ------------------
  600|      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()));
  601|      0|  }
  602|       |
  603|   130k|  if (d_content.size() > std::numeric_limits<uint16_t>::max()) {
  ------------------
  |  Branch (603:7): [True: 61, False: 130k]
  ------------------
  604|     61|    throw std::range_error("Trying to build a packet larger than " + std::to_string(std::numeric_limits<uint16_t>::max()) + " bytes");
  605|     61|  }
  606|       |
  607|   130k|  uint16_t rlen = d_content.size() - d_sor;
  608|   130k|  d_content.at(d_sor-2) = rlen >> 8;
  609|   130k|  d_content.at(d_sor-1) = rlen & 0xff;
  610|   130k|  d_sor = 0;
  611|   130k|  auto* dh = reinterpret_cast<dnsheader*>( &*d_content.begin());
  612|   130k|  switch(d_recordplace) {
  ------------------
  |  Branch (612:10): [True: 130k, False: 0]
  ------------------
  613|      0|  case DNSResourceRecord::QUESTION:
  ------------------
  |  Branch (613:3): [True: 0, False: 130k]
  ------------------
  614|      0|    dh->qdcount = htons(ntohs(dh->qdcount) + 1);
  615|      0|    break;
  616|  46.7k|  case DNSResourceRecord::ANSWER:
  ------------------
  |  Branch (616:3): [True: 46.7k, False: 83.8k]
  ------------------
  617|  46.7k|    dh->ancount = htons(ntohs(dh->ancount) + 1);
  618|  46.7k|    break;
  619|  17.8k|  case DNSResourceRecord::AUTHORITY:
  ------------------
  |  Branch (619:3): [True: 17.8k, False: 112k]
  ------------------
  620|  17.8k|    dh->nscount = htons(ntohs(dh->nscount) + 1);
  621|  17.8k|    break;
  622|  66.0k|  case DNSResourceRecord::ADDITIONAL:
  ------------------
  |  Branch (622:3): [True: 66.0k, False: 64.5k]
  ------------------
  623|  66.0k|    dh->arcount = htons(ntohs(dh->arcount) + 1);
  624|  66.0k|    break;
  625|   130k|  }
  626|       |
  627|   130k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE11xfr32BitIntEm:
  155|   134k|{
  156|   134k|  if (val > std::numeric_limits<uint32_t>::max()) {
  ------------------
  |  Branch (156:7): [True: 0, False: 134k]
  ------------------
  157|      0|    throw runtime_error("Value too large to fit in 32 bits");
  158|      0|  }
  159|   134k|  uint32_t rval=htonl(static_cast<uint32_t>(val));
  160|   134k|  uint8_t* ptr=reinterpret_cast<uint8_t*>(&rval);
  161|   134k|  d_content.insert(d_content.end(), ptr, ptr+4);
  162|   134k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE11xfr16BitIntEm:
  165|   488k|{
  166|   488k|  if (val > std::numeric_limits<uint16_t>::max()) {
  ------------------
  |  Branch (166:7): [True: 0, False: 488k]
  ------------------
  167|      0|    throw runtime_error("Value too large to fit in 16 bits");
  168|      0|  }
  169|   488k|  uint16_t rval=htons(static_cast<uint16_t>(val));
  170|   488k|  uint8_t* ptr=reinterpret_cast<uint8_t*>(&rval);
  171|   488k|  d_content.insert(d_content.end(), ptr, ptr+2);
  172|   488k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE7xfrNameERK7DNSNameb:
  415|   140k|{
  416|   140k|  if(l_verbose)
  ------------------
  |  Branch (416:6): [Folded, False: 140k]
  ------------------
  417|      0|    cout<<"Wants to write "<<name<<", compress="<<compress<<", canonic="<<d_canonic<<", LC="<<d_lowerCase<<endl;
  418|   140k|  if(d_canonic || d_lowerCase)   // d_lowerCase implies canonic
  ------------------
  |  Branch (418:6): [True: 0, False: 140k]
  |  Branch (418:19): [True: 0, False: 140k]
  ------------------
  419|      0|    compress=false;
  420|       |
  421|   140k|  if(name.empty() || name.isRoot()) { // for speed
  ------------------
  |  Branch (421:6): [True: 0, False: 140k]
  |  Branch (421:22): [True: 55.4k, False: 85.1k]
  ------------------
  422|  55.4k|    d_content.push_back(0);
  423|  55.4k|    return;
  424|  55.4k|  }
  425|       |
  426|  85.1k|  uint16_t li=0;
  427|  85.1k|  uint16_t matchlen=0;
  428|  85.1k|  if(d_compress && compress && (li=lookupName(name, &matchlen)) && li < maxCompressionOffset) {
  ------------------
  |  Branch (428:6): [True: 82.2k, False: 2.92k]
  |  Branch (428:20): [True: 82.2k, False: 0]
  |  Branch (428:32): [True: 18.6k, False: 63.5k]
  |  Branch (428:68): [True: 18.6k, False: 0]
  ------------------
  429|  18.6k|    const auto& dns=name.getStorage();
  430|  18.6k|    if(l_verbose)
  ------------------
  |  Branch (430:8): [Folded, False: 18.6k]
  ------------------
  431|      0|      cout<<"Found a substring of "<<matchlen<<" bytes from the back, offset: "<<li<<", dnslen: "<<dns.size()<<endl;
  432|       |    // found a substring, if www.powerdns.com matched powerdns.com, we get back matchlen = 13
  433|       |
  434|  18.6k|    unsigned int pos=d_content.size();
  435|  18.6k|    if(pos < maxCompressionOffset && matchlen != dns.size()) {
  ------------------
  |  Branch (435:8): [True: 15.7k, False: 2.85k]
  |  Branch (435:38): [True: 2.34k, False: 13.4k]
  ------------------
  436|  2.34k|      if(l_verbose)
  ------------------
  |  Branch (436:10): [Folded, False: 2.34k]
  ------------------
  437|      0|        cout<<"Inserting pos "<<pos<<" for "<<name<<" for compressed case"<<endl;
  438|  2.34k|      d_namepositions.push_back(pos);
  439|  2.34k|    }
  440|       |
  441|  18.6k|    if(l_verbose)
  ------------------
  |  Branch (441:8): [Folded, False: 18.6k]
  ------------------
  442|      0|      cout<<"Going to write unique part: '"<<makeHexDump(string(dns.c_str(), dns.c_str() + dns.size() - matchlen)) <<"'"<<endl;
  443|  18.6k|    d_content.insert(d_content.end(), (const unsigned char*)dns.c_str(), (const unsigned char*)dns.c_str() + dns.size() - matchlen);
  444|  18.6k|    uint16_t offset=li;
  445|  18.6k|    offset|=0xc000;
  446|       |
  447|  18.6k|    d_content.push_back((char)(offset >> 8));
  448|  18.6k|    d_content.push_back((char)(offset & 0xff));
  449|  18.6k|  }
  450|  66.4k|  else {
  451|  66.4k|    unsigned int pos=d_content.size();
  452|  66.4k|    if(l_verbose)
  ------------------
  |  Branch (452:8): [Folded, False: 66.4k]
  ------------------
  453|      0|      cout<<"Found nothing, we are at pos "<<pos<<", inserting whole name"<<endl;
  454|  66.4k|    if(pos < maxCompressionOffset) {
  ------------------
  |  Branch (454:8): [True: 38.4k, False: 28.0k]
  ------------------
  455|  38.4k|      if(l_verbose)
  ------------------
  |  Branch (455:10): [Folded, False: 38.4k]
  ------------------
  456|      0|        cout<<"Inserting pos "<<pos<<" for "<<name<<" for uncompressed case"<<endl;
  457|  38.4k|      d_namepositions.push_back(pos);
  458|  38.4k|    }
  459|       |
  460|  66.4k|    std::unique_ptr<DNSName> lc;
  461|  66.4k|    if(d_lowerCase)
  ------------------
  |  Branch (461:8): [True: 0, False: 66.4k]
  ------------------
  462|      0|      lc = make_unique<DNSName>(name.makeLowerCase());
  463|       |
  464|  66.4k|    const DNSName::string_t& raw = (lc ? *lc : name).getStorage();
  ------------------
  |  Branch (464:37): [True: 0, False: 66.4k]
  ------------------
  465|  66.4k|    if(l_verbose)
  ------------------
  |  Branch (465:8): [Folded, False: 66.4k]
  ------------------
  466|      0|      cout<<"Writing out the whole thing "<<makeHexDump(string(raw.c_str(),  raw.c_str() + raw.length()))<<endl;
  467|  66.4k|    d_content.insert(d_content.end(), raw.c_str(), raw.c_str() + raw.size());
  468|  66.4k|  }
  469|  85.1k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE7xfrBlobERKNS0_12basic_stringIcNS0_11char_traitsIcEENS3_IcEEEEi:
  472|   162k|{
  473|   162k|  const uint8_t* ptr=reinterpret_cast<const uint8_t*>(blob.c_str());
  474|   162k|  d_content.insert(d_content.end(), ptr, ptr+blob.size());
  475|   162k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE9getHeaderEv:
   71|  66.6k|{
   72|  66.6k|  return reinterpret_cast<dnsheader*>(&*d_content.begin());
   73|  66.6k|}
_ZN22GenericDNSPacketWriterINSt3__16vectorIh14noinit_adaptorINS0_9allocatorIhEEEEEE10lookupNameERK7DNSNamePt:
  249|  82.2k|{
  250|       |  // iterate over the written labels, see if we find a match
  251|  82.2k|  const auto& raw = name.getStorage();
  252|       |
  253|       |  /* name might be a.root-servers.net, we need to be able to benefit from finding:
  254|       |     b.root-servers.net, or even:
  255|       |     b\xc0\x0c
  256|       |  */
  257|  82.2k|  unsigned int bestpos=0;
  258|  82.2k|  *matchLen = 0;
  259|       |
  260|       |  // positions of each label in the name we are trying to compress
  261|  82.2k|  boost::container::static_vector<uint16_t, 34> positionsInName;
  262|       |  // positions of labels in the packet we are building
  263|  82.2k|  boost::container::static_vector<uint16_t, 34> positionsInPacket;
  264|       |
  265|  82.2k|  try {
  266|  2.15M|    for(auto riter= raw.cbegin(); riter < raw.cend(); ) {
  ------------------
  |  Branch (266:35): [True: 2.09M, False: 56.2k]
  ------------------
  267|  2.09M|      if (*riter == 0) {
  ------------------
  |  Branch (267:11): [True: 25.9k, False: 2.06M]
  ------------------
  268|  25.9k|        break;
  269|  25.9k|      }
  270|  2.06M|      positionsInName.push_back(riter - raw.cbegin());
  271|  2.06M|      riter += *riter + 1;
  272|  2.06M|    }
  273|  82.2k|  }
  274|  82.2k|  catch (const std::bad_alloc& ba) {
  275|  56.2k|    if (l_verbose) {
  ------------------
  |  Branch (275:9): [Folded, False: 56.2k]
  ------------------
  276|      0|      cout << "Domain " << name << " too large to compress" << endl;
  277|      0|    }
  278|  56.2k|    return 0;
  279|  56.2k|  }
  280|       |
  281|  25.9k|  if (l_verbose) {
  ------------------
  |  Branch (281:7): [Folded, False: 25.9k]
  ------------------
  282|      0|    cout<<"Input vector for lookup "<<name<<": ";
  283|      0|    for (const auto n : positionsInName) {
  ------------------
  |  Branch (283:23): [True: 0, False: 0]
  ------------------
  284|      0|      cout << n << " ";
  285|      0|    }
  286|      0|    cout<<endl;
  287|      0|    cout<<makeHexDump(string(raw.c_str(), raw.c_str()+raw.size()))<<endl;
  288|      0|  }
  289|       |
  290|  25.9k|  if (l_verbose) {
  ------------------
  |  Branch (290:7): [Folded, False: 25.9k]
  ------------------
  291|      0|    cout << "Have " << d_namepositions.size() << " to ponder" << endl;
  292|      0|  }
  293|       |
  294|  25.9k|  int counter=1;
  295|   202k|  for (const auto positionInPacket : d_namepositions) {
  ------------------
  |  Branch (295:36): [True: 202k, False: 10.0k]
  ------------------
  296|       |    // here it's a bit tricky because the names might be compressed,
  297|       |    // so we will gather all labels composing the name, following
  298|       |    // pointers if needed
  299|       |    // for example if there is an uncompressed \1a\1b\1c\0 we will store
  300|       |    // the position of \1a, \1b, \1c
  301|       |    // if there is instead \1a followed by a pointer to \1b\1c\0 earlier
  302|       |    // in the packet we will store the position of \1a, \1b, \1c as well
  303|       |    // they will just be disjoint
  304|   202k|    if (l_verbose) {
  ------------------
  |  Branch (304:9): [Folded, False: 202k]
  ------------------
  305|      0|      cout<<"Pos: "<<positionInPacket<<", "<<d_content.size()<<endl;
  306|      0|      DNSName pname(reinterpret_cast<const char*>(d_content.data()), d_content.size(), positionInPacket, true); // only for debugging
  307|      0|      cout<<"Looking at '"<<pname<<"' in packet at position "<<positionInPacket<<"/"<<d_content.size()<<", option "<<counter<<"/"<<d_namepositions.size()<<endl;
  308|      0|      ++counter;
  309|      0|    }
  310|   202k|    size_t pointerQuota = 50U;
  311|       |    // memcmp here makes things _slower_
  312|   202k|    positionsInPacket.clear();
  313|   202k|    try {
  314|  3.99M|      for (auto iter = d_content.cbegin() + positionInPacket; iter < d_content.cend() && pointerQuota > 0;) {
  ------------------
  |  Branch (314:63): [True: 3.90M, False: 91.1k]
  |  Branch (314:63): [True: 3.90M, False: 91.1k]
  |  Branch (314:90): [True: 3.90M, False: 0]
  ------------------
  315|  3.90M|        uint8_t labelLength = *iter;
  316|  3.90M|        const uint16_t currentPos = (iter - d_content.cbegin());
  317|  3.90M|        if (l_verbose) {
  ------------------
  |  Branch (317:13): [Folded, False: 3.90M]
  ------------------
  318|      0|          cout << "Found label length: " << std::to_string(labelLength) << " at " << currentPos << endl;
  319|      0|        }
  320|  3.90M|        if (labelLength & 0xc0) {
  ------------------
  |  Branch (320:13): [True: 53.4k, False: 3.85M]
  ------------------
  321|  53.4k|          uint16_t npos = 0x100*(labelLength & (~0xc0)) + *++iter;
  322|       |          // check against going forward
  323|  53.4k|          if (npos >= currentPos || npos < sizeof(dnsheader)) {
  ------------------
  |  Branch (323:15): [True: 0, False: 53.4k]
  |  Branch (323:37): [True: 0, False: 53.4k]
  ------------------
  324|       |            /* something is not right */
  325|      0|            break;
  326|      0|          }
  327|       |
  328|       |          // jump to the target of the pointer
  329|  53.4k|          iter = d_content.begin() + npos;
  330|  53.4k|          if (l_verbose) {
  ------------------
  |  Branch (330:15): [Folded, False: 53.4k]
  ------------------
  331|      0|            cout << "Is compressed label to newpos " << npos << ", going there" << endl;
  332|      0|          }
  333|       |
  334|  53.4k|          if (pointerQuota >= 1) {
  ------------------
  |  Branch (334:15): [True: 53.4k, False: 0]
  ------------------
  335|  53.4k|            pointerQuota--;
  336|  53.4k|            continue;
  337|  53.4k|          }
  338|       |
  339|       |          // out of pointer quota, let's stop there
  340|      0|          break;
  341|  53.4k|        }
  342|       |
  343|  3.85M|        if (labelLength == 0) {
  ------------------
  |  Branch (343:13): [True: 110k, False: 3.74M]
  ------------------
  344|   110k|          break;
  345|   110k|        }
  346|       |
  347|  3.74M|        if (currentPos >= maxCompressionOffset) {
  ------------------
  |  Branch (347:13): [True: 417, False: 3.74M]
  ------------------
  348|    417|          break; // compression pointers cannot point here
  349|    417|        }
  350|       |
  351|  3.74M|        positionsInPacket.push_back(currentPos);
  352|       |        // jump to the next label
  353|  3.74M|        iter += labelLength + 1;
  354|  3.74M|      }
  355|   202k|    }
  356|   202k|    catch (const std::bad_alloc& ba) {
  357|  91.1k|      if (l_verbose) {
  ------------------
  |  Branch (357:11): [Folded, False: 91.1k]
  ------------------
  358|      0|        cout << "Domain " << name << " too large to compress" << endl;
  359|      0|      }
  360|  91.1k|      continue;
  361|  91.1k|    }
  362|       |
  363|   111k|    if (l_verbose) {
  ------------------
  |  Branch (363:9): [Folded, False: 111k]
  ------------------
  364|      0|      cout<<"Packet vector: "<<endl;
  365|      0|      for (const auto n : positionsInPacket) {
  ------------------
  |  Branch (365:25): [True: 0, False: 0]
  ------------------
  366|      0|        cout << n << " ";
  367|      0|      }
  368|      0|      cout<<endl;
  369|      0|    }
  370|       |
  371|   111k|    auto positionInNameIter = positionsInName.crbegin();
  372|   111k|    auto positionInPacketIter = positionsInPacket.crbegin();
  373|   111k|    unsigned int cmatchlen=1;
  374|   195k|    for(; positionInNameIter != positionsInName.crend() && positionInPacketIter != positionsInPacket.crend(); ++positionInNameIter, ++positionInPacketIter) {
  ------------------
  |  Branch (374:11): [True: 195k, False: 0]
  |  Branch (374:11): [True: 190k, False: 5.19k]
  |  Branch (374:60): [True: 190k, False: 5.19k]
  ------------------
  375|       |      // positionInNameIter is an offset in raw, pvect an offset in packet
  376|   190k|      uint8_t nlen = raw[*positionInNameIter];
  377|   190k|      uint8_t plen = d_content[*positionInPacketIter];
  378|       |
  379|   190k|      if (l_verbose) {
  ------------------
  |  Branch (379:11): [Folded, False: 190k]
  ------------------
  380|      0|        cout << "nlnen=" << (int)nlen << ", plen=" << (int)plen << endl;
  381|      0|      }
  382|       |
  383|   190k|      if (nlen != plen) {
  ------------------
  |  Branch (383:11): [True: 59.5k, False: 131k]
  ------------------
  384|  59.5k|        break;
  385|  59.5k|      }
  386|       |
  387|   131k|      auto rawpart = std::string_view(raw.c_str() + *positionInNameIter + 1, nlen); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  388|   131k|      auto pktpart = std::string_view((const char*)&d_content[*positionInPacketIter] + 1, nlen); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
  389|   131k|      if (pdns_ilexicographical_compare_three_way(rawpart, pktpart) != 0) {
  ------------------
  |  Branch (389:11): [True: 30.5k, False: 100k]
  ------------------
  390|  30.5k|        if (l_verbose) {
  ------------------
  |  Branch (390:13): [Folded, False: 30.5k]
  ------------------
  391|      0|          cout << "Mismatch: " << rawpart << " != " << pktpart << endl;
  392|      0|        }
  393|  30.5k|        break;
  394|  30.5k|      }
  395|       |
  396|   100k|      cmatchlen += nlen + 1;
  397|   100k|      if (cmatchlen == raw.length()) { // have matched all of it, can't improve
  ------------------
  |  Branch (397:11): [True: 15.9k, False: 84.5k]
  ------------------
  398|  15.9k|        if (l_verbose) {
  ------------------
  |  Branch (398:13): [Folded, False: 15.9k]
  ------------------
  399|      0|          cout << "Stopping search, matched whole name" << endl;
  400|      0|        }
  401|       |
  402|  15.9k|        *matchLen = cmatchlen;
  403|  15.9k|        return *positionInPacketIter;
  404|  15.9k|      }
  405|   100k|    }
  406|  95.3k|    if (positionInPacketIter != positionsInPacket.crbegin() && *matchLen < cmatchlen) {
  ------------------
  |  Branch (406:9): [True: 14.5k, False: 80.8k]
  |  Branch (406:9): [True: 8.05k, False: 87.3k]
  |  Branch (406:64): [True: 8.05k, False: 6.46k]
  ------------------
  407|  8.05k|      *matchLen = cmatchlen;
  408|  8.05k|      bestpos = *--positionInPacketIter;
  409|  8.05k|    }
  410|  95.3k|  }
  411|  10.0k|  return bestpos;
  412|  25.9k|}

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

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

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

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

_ZN12ComboAddress8truncateEj:
  366|  2.88k|{
  367|  2.88k|  uint8_t* start{};
  368|  2.88k|  int len = 4;
  369|  2.88k|  if (sin4.sin_family == AF_INET) {
  ------------------
  |  Branch (369:7): [True: 2.88k, False: 0]
  ------------------
  370|  2.88k|    if (bits >= 32) {
  ------------------
  |  Branch (370:9): [True: 0, False: 2.88k]
  ------------------
  371|      0|      return;
  372|      0|    }
  373|  2.88k|    start = reinterpret_cast<uint8_t*>(&sin4.sin_addr.s_addr); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
  374|  2.88k|    len = 4;
  375|  2.88k|  }
  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.88k|  auto tozero = (len * 8) - bits; // if set to 22, this will clear 1 byte, as it should
  385|       |
  386|  2.88k|  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.88k|  auto bitsleft = tozero % 8; // 2 bits left to clear
  389|  2.88k|  if (bitsleft == 0) {
  ------------------
  |  Branch (389:7): [True: 2.88k, 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.88k|    return;
  393|  2.88k|  }
  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.88k|  {
  248|  2.88k|    memset(&sin6, 0, sizeof(sin6));
  249|  2.88k|    sin4.sin_family = AF_INET;
  250|  2.88k|    sin4.sin_port = 0;
  251|  2.88k|    if (makeIPv4sockaddr(str, &sin4) != 0) {
  ------------------
  |  Branch (251:9): [True: 0, False: 2.88k]
  ------------------
  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.88k|    if (sin4.sin_port == 0) { // 'str' overrides port!
  ------------------
  |  Branch (257:9): [True: 2.88k, False: 2]
  ------------------
  258|       |      sin4.sin_port = htons(port);
  259|  2.88k|    }
  260|  2.88k|  }
_ZN12ComboAddressC2Ev:
  212|  2.89k|  {
  213|       |    sin4.sin_family = AF_INET;
  214|  2.89k|    sin4.sin_addr.s_addr = 0;
  215|  2.89k|    sin4.sin_port = 0;
  216|  2.89k|    sin6.sin6_scope_id = 0;
  217|  2.89k|    sin6.sin6_flowinfo = 0;
  218|  2.89k|  }
_ZNK12ComboAddress6isIPv4Ev:
  267|  2.88k|  {
  268|       |    return sin4.sin_family == AF_INET;
  269|  2.88k|  }
_ZN7NetmaskC2Ev:
  696|  2.89k|  {
  697|  2.89k|    d_network.sin4.sin_family = 0; // disable this doing anything useful
  698|  2.89k|    d_network.sin4.sin_port = 0; // this guarantees d_network compares identical
  699|  2.89k|  }
_ZN7NetmaskC2ERK12ComboAddressh:
  702|  2.88k|    d_network(network)
  703|  2.88k|  {
  704|  2.88k|    d_network.sin4.sin_port = 0;
  705|  2.88k|    setBits(bits);
  706|  2.88k|  }
_ZN7Netmask7setBitsEh:
  721|  2.88k|  {
  722|  2.88k|    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.88k, False: 0]
  ------------------
  723|       |
  724|  2.88k|    if (d_bits < 32) {
  ------------------
  |  Branch (724:9): [True: 2.88k, False: 0]
  ------------------
  725|  2.88k|      d_mask = ~(0xFFFFFFFF >> d_bits);
  726|  2.88k|    }
  727|      0|    else {
  728|       |      // note that d_mask is unused for IPv6
  729|      0|      d_mask = 0xFFFFFFFF;
  730|      0|    }
  731|       |
  732|  2.88k|    if (isIPv4()) {
  ------------------
  |  Branch (732:9): [True: 2.88k, False: 0]
  ------------------
  733|  2.88k|      d_network.sin4.sin_addr.s_addr = htonl(ntohl(d_network.sin4.sin_addr.s_addr) & d_mask);
  734|  2.88k|    }
  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.88k|  }
_ZNK7Netmask10getNetworkEv:
  862|  2.88k|  {
  863|  2.88k|    return d_network;
  864|  2.88k|  }
_ZNK7Netmask7getBitsEv:
  872|  2.88k|  {
  873|  2.88k|    return d_bits;
  874|  2.88k|  }
_ZNK7Netmask6isIPv4Ev:
  882|  8.64k|  {
  883|       |    return d_network.sin4.sin_family == AF_INET;
  884|  8.64k|  }
_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:
  476|      2|{
  477|      2|  const size_t maxHostNameBufSize = getMaxHostNameSize() + 1;
  478|      2|  std::string hostname;
  479|      2|  hostname.resize(maxHostNameBufSize, 0);
  480|       |
  481|      2|  if (gethostname(hostname.data(), maxHostNameBufSize) == -1) {
  ------------------
  |  Branch (481:7): [True: 0, False: 2]
  ------------------
  482|      0|    return std::nullopt;
  483|      0|  }
  484|       |
  485|      2|  hostname.resize(strlen(hostname.c_str()));
  486|      2|  return std::make_optional(hostname);
  487|      2|}
_Z16makeIPv4sockaddrRKNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEP11sockaddr_in:
  775|  2.88k|{
  776|  2.88k|  std::string str(arg);
  777|  2.88k|  if (str.empty()) {
  ------------------
  |  Branch (777:7): [True: 0, False: 2.88k]
  ------------------
  778|      0|    return -1;
  779|      0|  }
  780|  2.88k|  struct in_addr inp{};
  781|       |
  782|  2.88k|  string::size_type pos = str.find(':');
  783|  2.88k|  if (pos == string::npos) { // no port specified, not touching the port
  ------------------
  |  Branch (783:7): [True: 2.88k, False: 2]
  ------------------
  784|  2.88k|    if (inet_aton(str.c_str(), &inp) != 0) {
  ------------------
  |  Branch (784:9): [True: 2.88k, False: 0]
  ------------------
  785|  2.88k|      ret->sin_addr.s_addr = inp.s_addr;
  786|  2.88k|      return 0;
  787|  2.88k|    }
  788|      0|    return -1;
  789|  2.88k|  }
  790|      2|  if (*(str.c_str() + pos + 1) == 0) { // trailing :
  ------------------
  |  Branch (790:7): [True: 0, False: 2]
  ------------------
  791|      0|    return -1;
  792|      0|  }
  793|       |
  794|      2|  auto* eptr = str.data() + str.size();
  795|      2|  int port = static_cast<int>(strtol(str.c_str() + pos + 1, &eptr, 10));
  796|      2|  if (port < 0 || port > 65535) {
  ------------------
  |  Branch (796:7): [True: 0, False: 2]
  |  Branch (796:19): [True: 0, False: 2]
  ------------------
  797|      0|    return -1;
  798|      0|  }
  799|      2|  if (*eptr != 0) {
  ------------------
  |  Branch (799:7): [True: 0, False: 2]
  ------------------
  800|      0|    return -1;
  801|      0|  }
  802|       |
  803|      2|  ret->sin_port = htons(port);
  804|      2|  if (inet_aton(str.substr(0, pos).c_str(), &inp) != 0) {
  ------------------
  |  Branch (804:7): [True: 2, False: 0]
  ------------------
  805|      2|    ret->sin_addr.s_addr = inp.s_addr;
  806|      2|    return 0;
  807|      2|  }
  808|      0|  return -1;
  809|      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|  const size_t maxHostNameSize = 255;
  468|      0|#if defined(_SC_HOST_NAME_MAX)
  469|      0|  return pdns::sysconf(_SC_HOST_NAME_MAX, maxHostNameSize);
  470|      0|#endif
  471|       |
  472|      0|  return maxHostNameSize;
  473|      2|}

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

_ZN14noinit_adaptorINSt3__19allocatorIhEEEC2Ev:
   22|  11.2k|  noinit_adaptor(): Allocator() { }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhRKhJEEEvPT_OT0_DpOT1_:
   36|  23.2M|  void construct(U* p, V&& v, Args&&... args) {
   37|  23.2M|    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
   38|  23.2M|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE7destroyIhEEvPT_:
   41|  81.5M|  void destroy(U* p) {
   42|  81.5M|    p->~U();
   43|  81.5M|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhRhJEEEvPT_OT0_DpOT1_:
   36|  12.8M|  void construct(U* p, V&& v, Args&&... args) {
   37|  12.8M|    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
   38|  12.8M|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhEEvPT_:
   31|  87.2k|  void construct(U* p) {
   32|  87.2k|    ::new((void*)p) U;
   33|  87.2k|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhhJEEEvPT_OT0_DpOT1_:
   36|  31.7M|  void construct(U* p, V&& v, Args&&... args) {
   37|  31.7M|    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
   38|  31.7M|  }
_ZN14noinit_adaptorINSt3__19allocatorIhEEE9constructIhRKcJEEEvPT_OT0_DpOT1_:
   36|  13.6M|  void construct(U* p, V&& v, Args&&... args) {
   37|  13.6M|    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
   38|  13.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:
   98|      2|{
   99|      2|  std::map<uint16_t, const std::string> ret;
  100|       |
  101|    128|  for (const auto& name : names) {
  ------------------
  |  Branch (101:25): [True: 128, False: 2]
  ------------------
  102|    128|    ret.emplace(name.second, name.first);
  103|    128|  }
  104|      2|  return ret;
  105|      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|   790k|    view(data_, size_)
   34|   790k|  {
   35|   790k|  }
_ZN4pdns5views16UnsignedCharViewC2EPKhm:
   38|  5.39k|    view(reinterpret_cast<const char*>(data_), size_)
   39|  5.39k|  {
   40|  5.39k|  }
_ZNK4pdns5views16UnsignedCharView2atEm:
   44|  6.98M|  {
   45|  6.98M|    return reinterpret_cast<const unsigned char&>(view.at(pos));
   46|  6.98M|  }
_ZNK4pdns5views16UnsignedCharView4sizeEv:
   60|  9.78M|  {
   61|  9.78M|    return view.size();
   62|  9.78M|  }

