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

PowerDNS / pdns / 18743945403

23 Oct 2025 09:29AM UTC coverage: 65.845% (+0.02%) from 65.829%
18743945403

Pull #16356

github

web-flow
Merge 8a2027ef1 into efa3637e8
Pull Request #16356: auth 5.0: backport "pdnsutil: fix b2b-migrate to from sql to non-sql"

42073 of 92452 branches covered (45.51%)

Branch coverage included in aggregate %.

128008 of 165855 relevant lines covered (77.18%)

6379935.17 hits per line

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

48.09
/pdns/recursordist/rec-protozero.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 "dnsrecords.hh"
24
#include "rec-protozero.hh"
25
#include <variant>
26

27
void pdns::ProtoZero::RecMessage::addRR(const DNSRecord& record, const std::set<uint16_t>& exportTypes, [[maybe_unused]] std::optional<bool> udr)
28
{
126✔
29
  if (record.d_place != DNSResourceRecord::ANSWER || record.d_class != QClass::IN) {
126!
30
    return;
64✔
31
  }
64✔
32

33
  if (exportTypes.count(record.d_type) == 0) {
62✔
34
    return;
23✔
35
  }
23✔
36

37
  protozero::pbf_writer pbf_rr{d_response, static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::ResponseField::rrs)};
39✔
38

39
  encodeDNSName(pbf_rr, d_rspbuf, static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::name), record.d_name);
39✔
40
  pbf_rr.add_uint32(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::type), record.d_type);
39✔
41
  pbf_rr.add_uint32(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::class_), record.d_class);
39✔
42
  pbf_rr.add_uint32(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::ttl), record.d_ttl);
39✔
43

44
  auto add = [&](const std::string& str) {
39✔
45
    if (size() + str.length() < std::numeric_limits<uint16_t>::max() / 2) {
5!
46
      pbf_rr.add_string(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::rdata), str);
5✔
47
    }
5✔
48
  };
5✔
49

50
  switch (record.d_type) {
39✔
51
  case QType::A: {
33✔
52
    const auto& content = getRR<ARecordContent>(record);
33✔
53
    if (!content) {
33!
54
      return;
×
55
    }
×
56
    ComboAddress data = content->getCA();
33✔
57
    pbf_rr.add_bytes(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::rdata), reinterpret_cast<const char*>(&data.sin4.sin_addr.s_addr), sizeof(data.sin4.sin_addr.s_addr)); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
33✔
58
    break;
33✔
59
  }
33✔
60
  case QType::AAAA: {
1✔
61
    const auto& content = getRR<AAAARecordContent>(record);
1✔
62
    if (!content) {
1!
63
      return;
×
64
    }
×
65
    ComboAddress data = content->getCA();
1✔
66
    pbf_rr.add_bytes(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::rdata), reinterpret_cast<const char*>(&data.sin6.sin6_addr.s6_addr), sizeof(data.sin6.sin6_addr.s6_addr)); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
1✔
67
    break;
1✔
68
  }
1✔
69
  case QType::CNAME: {
1✔
70
    const auto& content = getRR<CNAMERecordContent>(record);
1✔
71
    if (!content) {
1!
72
      return;
×
73
    }
×
74
    add(content->getTarget().toString());
1✔
75
    break;
1✔
76
  }
1✔
77
  case QType::TXT: {
1✔
78
    const auto& content = getRR<TXTRecordContent>(record);
1✔
79
    if (!content) {
1!
80
      return;
×
81
    }
×
82
    add(content->d_text);
1✔
83
    break;
1✔
84
  }
1✔
85
  case QType::NS: {
×
86
    const auto& content = getRR<NSRecordContent>(record);
×
87
    if (!content) {
×
88
      return;
×
89
    }
×
90
    add(content->getNS().toString());
×
91
    break;
×
92
  }
×
93
  case QType::PTR: {
×
94
    const auto& content = getRR<PTRRecordContent>(record);
×
95
    if (!content) {
×
96
      return;
×
97
    }
×
98
    add(content->getContent().toString());
×
99
    break;
×
100
  }
×
101
  case QType::MX: {
1✔
102
    const auto& content = getRR<MXRecordContent>(record);
1✔
103
    if (!content) {
1!
104
      return;
×
105
    }
×
106
    add(content->d_mxname.toString());
1✔
107
    break;
1✔
108
  }
1✔
109
  case QType::SPF: {
1✔
110
    const auto& content = getRR<SPFRecordContent>(record);
1✔
111
    if (!content) {
1!
112
      return;
×
113
    }
×
114
    add(content->getText());
1✔
115
    break;
1✔
116
  }
1✔
117
  case QType::SRV: {
1✔
118
    const auto& content = getRR<SRVRecordContent>(record);
1✔
119
    if (!content) {
1!
120
      return;
×
121
    }
×
122
    add(content->d_target.toString());
1✔
123
    break;
1✔
124
  }
1✔
125
  case QType::SVCB: {
×
126
    const auto& content = getRR<SVCBRecordContent>(record);
×
127
    if (!content) {
×
128
      return;
×
129
    }
×
130
    add(content->getZoneRepresentation());
×
131
    break;
×
132
  }
×
133
  case QType::HTTPS: {
×
134
    const auto& content = getRR<HTTPSRecordContent>(record);
×
135
    if (!content) {
×
136
      return;
×
137
    }
×
138
    add(content->getZoneRepresentation());
×
139
    break;
×
140
  }
×
141
  case QType::NAPTR: {
×
142
    const auto& content = getRR<NAPTRRecordContent>(record);
×
143
    if (!content) {
×
144
      return;
×
145
    }
×
146
    add(content->getZoneRepresentation());
×
147
    break;
×
148
  }
×
149
  default:
×
150
    break;
×
151
  }
39✔
152
#ifdef NOD_ENABLED
39✔
153
  if (udr) {
39✔
154
    pbf_rr.add_bool(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::udr), *udr);
35✔
155
    pbf_rr.commit();
35✔
156

157
    // Save the offset of the byte containing the just added bool. We can do this since
158
    // we know a bit about how protobuf's encoding works.
159
    offsets.push_back(d_rspbuf.length() - 1);
35✔
160
  }
35✔
161
#endif
39✔
162
}
39✔
163

164
#ifdef NOD_ENABLED
165
void pdns::ProtoZero::RecMessage::clearUDR(std::string& str)
166
{
28✔
167
  for (auto offset : offsets) {
33✔
168
    str.at(offset) = 0;
33✔
169
  }
33✔
170
}
28✔
171
#endif
172

173
void pdns::ProtoZero::RecMessage::addEvents(const RecEventTrace& trace)
174
{
×
175
  for (const auto& event : trace.getEvents()) {
×
176
    protozero::pbf_writer pbf_trace{d_message, static_cast<protozero::pbf_tag_type>(Field::trace)};
×
177
    pbf_trace.add_int64(static_cast<protozero::pbf_tag_type>(Event::ts), event.d_ts);
×
178
    pbf_trace.add_uint32(static_cast<protozero::pbf_tag_type>(Event::event), event.d_event);
×
179
    pbf_trace.add_bool(static_cast<protozero::pbf_tag_type>(Event::start), event.d_start);
×
180

181
    const auto& value = event.d_value;
×
182
    if (std::holds_alternative<std::nullopt_t>(value)) {
×
183
    }
×
184
    else if (std::holds_alternative<bool>(value)) {
×
185
      pbf_trace.add_bool(static_cast<protozero::pbf_tag_type>(Event::boolVal), std::get<bool>(value));
×
186
    }
×
187
    else if (std::holds_alternative<int64_t>(value)) {
×
188
      pbf_trace.add_int64(static_cast<protozero::pbf_tag_type>(Event::intVal), std::get<int64_t>(value));
×
189
    }
×
190
    else if (std::holds_alternative<std::string>(value)) {
×
191
      pbf_trace.add_string(static_cast<protozero::pbf_tag_type>(Event::stringVal), std::get<std::string>(value));
×
192
    }
×
193
    else if (std::holds_alternative<PacketBuffer>(value)) {
×
194
      const auto& packetBuffer = std::get<PacketBuffer>(value);
×
195
      pbf_trace.add_bytes(static_cast<protozero::pbf_tag_type>(Event::bytesVal), reinterpret_cast<const char*>(packetBuffer.data()), packetBuffer.size()); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
×
196
    }
×
197
    if (!event.d_custom.empty()) {
×
198
      pbf_trace.add_string(static_cast<protozero::pbf_tag_type>(Event::custom), event.d_custom);
×
199
    }
×
200
  }
×
201
}
×
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