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

PowerDNS / pdns / 15920880335

26 Jun 2025 03:30PM UTC coverage: 61.923% (-3.7%) from 65.652%
15920880335

push

github

web-flow
Merge pull request #15669 from miodvallat/serial_keyer

Increase zone serial number after zone key operations

38311 of 91850 branches covered (41.71%)

Branch coverage included in aggregate %.

27 of 29 new or added lines in 1 file covered. (93.1%)

6308 existing lines in 78 files now uncovered.

120482 of 164587 relevant lines covered (73.2%)

5965233.22 hits per line

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

0.0
/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)
UNCOV
28
{
×
UNCOV
29
  if (record.d_place != DNSResourceRecord::ANSWER || record.d_class != QClass::IN) {
×
UNCOV
30
    return;
×
UNCOV
31
  }
×
32

UNCOV
33
  if (exportTypes.count(record.d_type) == 0) {
×
UNCOV
34
    return;
×
UNCOV
35
  }
×
36

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

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

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

UNCOV
50
  switch (record.d_type) {
×
UNCOV
51
  case QType::A: {
×
UNCOV
52
    const auto& content = getRR<ARecordContent>(record);
×
UNCOV
53
    if (!content) {
×
54
      return;
×
55
    }
×
UNCOV
56
    ComboAddress data = content->getCA();
×
UNCOV
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
×
UNCOV
58
    break;
×
UNCOV
59
  }
×
UNCOV
60
  case QType::AAAA: {
×
UNCOV
61
    const auto& content = getRR<AAAARecordContent>(record);
×
UNCOV
62
    if (!content) {
×
63
      return;
×
64
    }
×
UNCOV
65
    ComboAddress data = content->getCA();
×
UNCOV
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
×
UNCOV
67
    break;
×
UNCOV
68
  }
×
UNCOV
69
  case QType::CNAME: {
×
UNCOV
70
    const auto& content = getRR<CNAMERecordContent>(record);
×
UNCOV
71
    if (!content) {
×
72
      return;
×
73
    }
×
UNCOV
74
    add(content->getTarget().toString());
×
UNCOV
75
    break;
×
UNCOV
76
  }
×
UNCOV
77
  case QType::TXT: {
×
UNCOV
78
    const auto& content = getRR<TXTRecordContent>(record);
×
UNCOV
79
    if (!content) {
×
80
      return;
×
81
    }
×
UNCOV
82
    add(content->d_text);
×
UNCOV
83
    break;
×
UNCOV
84
  }
×
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
  }
×
UNCOV
101
  case QType::MX: {
×
UNCOV
102
    const auto& content = getRR<MXRecordContent>(record);
×
UNCOV
103
    if (!content) {
×
104
      return;
×
105
    }
×
UNCOV
106
    add(content->d_mxname.toString());
×
UNCOV
107
    break;
×
UNCOV
108
  }
×
UNCOV
109
  case QType::SPF: {
×
UNCOV
110
    const auto& content = getRR<SPFRecordContent>(record);
×
UNCOV
111
    if (!content) {
×
112
      return;
×
113
    }
×
UNCOV
114
    add(content->getText());
×
UNCOV
115
    break;
×
UNCOV
116
  }
×
UNCOV
117
  case QType::SRV: {
×
UNCOV
118
    const auto& content = getRR<SRVRecordContent>(record);
×
UNCOV
119
    if (!content) {
×
120
      return;
×
121
    }
×
UNCOV
122
    add(content->d_target.toString());
×
UNCOV
123
    break;
×
UNCOV
124
  }
×
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;
×
UNCOV
151
  }
×
UNCOV
152
#ifdef NOD_ENABLED
×
UNCOV
153
  if (udr) {
×
UNCOV
154
    pbf_rr.add_bool(static_cast<protozero::pbf_tag_type>(pdns::ProtoZero::Message::RRField::udr), *udr);
×
UNCOV
155
    pbf_rr.commit();
×
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.
UNCOV
159
    offsets.push_back(d_rspbuf.length() - 1);
×
UNCOV
160
  }
×
UNCOV
161
#endif
×
UNCOV
162
}
×
163

164
#ifdef NOD_ENABLED
165
void pdns::ProtoZero::RecMessage::clearUDR(std::string& str)
UNCOV
166
{
×
UNCOV
167
  for (auto offset : offsets) {
×
UNCOV
168
    str.at(offset) = 0;
×
UNCOV
169
  }
×
UNCOV
170
}
×
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