• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 19741624072

27 Nov 2025 03:45PM UTC coverage: 73.086% (+0.02%) from 73.065%
19741624072

Pull #16570

github

web-flow
Merge 08a2cdb1d into f94a3f63f
Pull Request #16570: rec: rewrite all unwrap calls in web.rs

38523 of 63408 branches covered (60.75%)

Branch coverage included in aggregate %.

128044 of 164496 relevant lines covered (77.84%)

6531485.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.4
/pdns/dnsdistdist/dnsdist-idstate.cc
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22

23
#include "dnsdist-idstate.hh"
24
#include "dnsdist-doh-common.hh"
25
#include "doh3.hh"
26
#include "doq.hh"
27
#include <string>
28
#include <string_view>
29

30
InternalQueryState InternalQueryState::partialCloneForXFR() const
31
{
455✔
32
  /* for XFR responses we cannot move the state from the query
33
     because we usually have more than one response packet per query,
34
     so we need to do a partial clone.
35
  */
36
  InternalQueryState ids;
455✔
37
  ids.qtype = qtype;
455✔
38
  ids.qclass = qclass;
455✔
39
  ids.qname = qname;
455✔
40
  ids.poolName = poolName;
455✔
41
  ids.queryRealTime = queryRealTime;
455✔
42
  ids.protocol = protocol;
455✔
43
  ids.subnet = subnet;
455✔
44
  ids.origRemote = origRemote;
455✔
45
  ids.origDest = origDest;
455✔
46
  ids.hopRemote = hopRemote;
455✔
47
  ids.hopLocal = hopLocal;
455✔
48
  if (qTag) {
455!
49
    ids.qTag = std::make_unique<QTag>(*qTag);
×
50
  }
×
51
  if (d_protoBufData) {
455!
52
    ids.d_protoBufData = std::make_unique<InternalQueryState::ProtoBufData>(*d_protoBufData);
×
53
  }
×
54
  ids.cs = cs;
455✔
55
  /* in case we want to support XFR over DoH, or the stream ID becomes used for QUIC */
56
  ids.d_streamID = d_streamID;
455✔
57
#if !defined(DISABLE_PROTOBUF)
449✔
58
  ids.d_rawProtobufContent = d_rawProtobufContent;
449✔
59
#endif
449✔
60
  return ids;
455✔
61
}
455✔
62

63
void InternalQueryState::sendDelayedProtobufMessages() const
64
{
5,410✔
65
#ifndef DISABLE_PROTOBUF
5,410✔
66
  static thread_local string otPBBuf;
5,410✔
67
  otPBBuf.clear();
5,410✔
68
  if (tracingEnabled) {
5,410✔
69
    pdns::ProtoZero::Message msg{otPBBuf};
14✔
70
    msg.setOpenTelemetryData(d_OTTracer->getOTProtobuf());
14✔
71
  }
14✔
72

73
  for (auto const& msg_logger : delayedResponseMsgs) {
5,410✔
74
    // TODO: we should probably do something with the return value of queueData
75
    if (!tracingEnabled) {
4!
76
      msg_logger.second->queueData(msg_logger.first);
77
      continue;
78
    }
79
    // Protobuf wireformat allows us to simply append the second "message"
80
    // that only contains the OTTrace data as a single bytes field
81
    msg_logger.second->queueData(msg_logger.first + otPBBuf);
4✔
82
  }
4✔
83
#endif
5,410✔
84
}
5,410✔
85

86
std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const SpanID& parentSpanID)
87
{
8,307✔
88
  std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
8,307✔
89
#ifndef DISABLE_PROTOBUF
8,307✔
90
  // getTracer returns a Tracer when tracing is globally enabled
91
  // tracingEnabled tells us whether or not tracing is enabled for this query
92
  // Should tracing be disabled, *but* we have not processed query rules, we will still return a closer if tracing is globally enabled
93
  if (auto tracer = getTracer(); tracer != nullptr && (tracingEnabled || !rulesAppliedToQuery)) {
8,307✔
94
    ret = std::optional<pdns::trace::dnsdist::Tracer::Closer>(d_OTTracer->openSpan(std::string(name), parentSpanID));
132✔
95
  }
132✔
96
#endif
8,307✔
97
  return ret;
8,307✔
98
}
8,307✔
99

100
std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const std::string_view& parentSpanName)
101
{
13,187✔
102
  std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
13,187✔
103
#ifndef DISABLE_PROTOBUF
13,187✔
104
  if (auto tracer = getTracer(); tracer != nullptr) {
13,187✔
105
    auto parentSpanID = d_OTTracer->getLastSpanIDForName(std::string(parentSpanName));
50✔
106
    return getCloser(name, parentSpanID);
50✔
107
  }
50✔
108
#endif
13,137✔
109
  return ret;
13,137✔
110
}
13,187✔
111

112
std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getCloser([[maybe_unused]] const std::string_view& name)
113
{
22,366✔
114
  std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
22,366✔
115
#ifndef DISABLE_PROTOBUF
22,366✔
116
  if (auto tracer = getTracer(); tracer != nullptr) {
22,366✔
117
    return getCloser(std::string(name), d_OTTracer->getLastSpanID());
70✔
118
  }
70✔
119
#endif
22,296✔
120
  return ret;
22,296✔
121
}
22,366✔
122

123
std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName)
124
{
8,243✔
125
  std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
8,243✔
126
#ifndef DISABLE_PROTOBUF
8,243✔
127
  static const std::string prefix = "Rule: ";
8,243✔
128
  // getTracer returns a Tracer when tracing is globally enabled
129
  // tracingEnabled tells us whether or not tracing is enabled for this query
130
  // Should tracing be disabled, *but* we have not processed query rules, we will still return a closer if tracing is globally enabled
131
  if (auto tracer = getTracer(); tracer != nullptr && (tracingEnabled || !rulesAppliedToQuery)) {
8,243✔
132
    auto parentSpanID = d_OTTracer->getLastSpanIDForName(std::string(parentSpanName));
32✔
133
    auto name = prefix + std::string(ruleName);
32✔
134
    ret = std::optional<pdns::trace::dnsdist::Tracer::Closer>(d_OTTracer->openSpan(name, parentSpanID));
32✔
135
  }
32✔
136
#endif
8,243✔
137
  return ret;
8,243✔
138
}
8,243✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc