• 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

67.69
/pdns/dns.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
#ifdef HAVE_CONFIG_H
23
#include "config.h"
24
#endif
25
#include "dns.hh"
26
#include "misc.hh"
27
#include "views.hh"
28
#include <stdexcept>
29
#include <iostream>
30
#include <boost/algorithm/string.hpp>
31
#include <boost/assign/list_of.hpp>
32
#include "dnsparser.hh"
33

34
const std::array<std::string, 24> RCode::rcodes_s = {
35
  "No Error",
36
  "Form Error",
37
  "Server Failure",
38
  "Non-Existent domain",
39
  "Not Implemented",
40
  "Query Refused",
41
  "Name Exists when it should not",
42
  "RR Set Exists when it should not",
43
  "RR Set that should exist does not",
44
  "Server Not Authoritative for zone / Not Authorized",
45
  "Name not contained in zone",
46
  "Err#11",
47
  "Err#12",
48
  "Err#13",
49
  "Err#14",
50
  "Err#15",  // Last non-extended RCode
51
  "Bad OPT Version / TSIG Signature Failure",
52
  "Key not recognized",
53
  "Signature out of time window",
54
  "Bad TKEY Mode",
55
  "Duplicate key name",
56
  "Algorithm not supported",
57
  "Bad Truncation",
58
  "Bad/missing Server Cookie"
59
};
60

61
static const std::array<std::string, 10> rcodes_short_s =  {
62
  "noerror",
63
  "formerr",
64
  "servfail",
65
  "nxdomain",
66
  "notimp",
67
  "refused",
68
  "yxdomain",
69
  "yxrrset",
70
  "nxrrset",
71
  "notauth",
72
};
73

74
std::string RCode::to_s(uint8_t rcode) {
8,072✔
75
  if (rcode > 0xF) {
8,072!
76
    return std::string("ErrOutOfRange");
×
77
  }
×
78
  return ERCode::to_s(rcode);
8,072✔
79
}
8,072✔
80

81
std::string RCode::to_short_s(uint8_t rcode) {
720✔
82
  if (rcode >= rcodes_short_s.size()) {
720✔
83
    return "rcode" + std::to_string(rcode);
270✔
84
  }
270✔
85
  return rcodes_short_s.at(rcode);
450✔
86
}
720✔
87

88
std::string ERCode::to_s(uint16_t rcode) {
14,135✔
89
  if (rcode >= RCode::rcodes_s.size()) {
14,135!
90
    return std::string("Err#")+std::to_string(rcode);
×
91
  }
×
92
  return RCode::rcodes_s.at(rcode);
14,135✔
93
}
14,135✔
94

95
std::string Opcode::to_s(uint8_t opcode) {
5✔
96
  static const std::array<std::string, 6> s_opcodes = { "Query", "IQuery", "Status", "3", "Notify", "Update" };
5✔
97

98
  if (opcode >= s_opcodes.size()) {
5!
99
    return std::to_string(opcode);
×
100
  }
×
101

102
  return s_opcodes.at(opcode);
5✔
103
}
5✔
104

105
// goal is to hash based purely on the question name, and turn error into 'default'
106
uint32_t hashQuestion(const uint8_t* packet, uint16_t packet_len, uint32_t init, bool& wasOK)
107
{
303,621✔
108
  if (packet_len < sizeof(dnsheader)) {
303,621!
109
    wasOK = false;
×
110
    return init;
×
111
  }
×
112
  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
113
  pdns::views::UnsignedCharView name(packet + sizeof(dnsheader), packet_len - sizeof(dnsheader));
303,621✔
114
  pdns::views::UnsignedCharView::size_type len = 0;
303,621✔
115

116
  while (len < name.length()) {
914,235✔
117
    uint8_t labellen = name[len++];
914,223✔
118
    if (labellen == 0) {
914,223✔
119
      wasOK = true;
303,609✔
120
      // len is name.length() at max as it was < before the increment
121
      return burtleCI(name.data(), len, init);
303,609✔
122
    }
303,609✔
123
    len += labellen;
610,614✔
124
  }
610,614✔
125
  // We've encountered a label that is too long
126
  wasOK = false;
12✔
127
  return init;
12✔
128
}
303,621✔
129

130
static const std::array<std::string, 4> placeNames = {
131
  "QUESTION",
132
  "ANSWER",
133
  "AUTHORITY",
134
  "ADDITIONAL"
135
};
136

137
std::string DNSResourceRecord::placeString(uint8_t place)
UNCOV
138
{
×
UNCOV
139
  if (place >= placeNames.size()) {
×
140
    return "?";
×
141
  }
×
UNCOV
142
  return placeNames.at(place);
×
UNCOV
143
}
×
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