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

PowerDNS / pdns / 18837422702

27 Oct 2025 10:15AM UTC coverage: 73.025% (+0.02%) from 73.004%
18837422702

Pull #16375

github

web-flow
Merge 2f23fc90d into 82ea647b4
Pull Request #16375: dnsdist: Include a Date: response header for rejected HTTP1 requests

38279 of 63122 branches covered (60.64%)

Branch coverage included in aggregate %.

0 of 11 new or added lines in 1 file covered. (0.0%)

10680 existing lines in 98 files now uncovered.

127481 of 163870 relevant lines covered (77.79%)

5384548.9 hits per line

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

99.4
/pdns/burtle.hh
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
#pragma once
24

25
#include <cinttypes>
26

27
inline void burtlemix(uint32_t& a, uint32_t& b, uint32_t& c)
28
{
75,629,167✔
29
  a -= b;
75,629,167✔
30
  a -= c;
75,629,167✔
31
  a ^= (c >> 13);
75,629,167✔
32
  b -= c;
75,629,167✔
33
  b -= a;
75,629,167✔
34
  b ^= (a << 8);
75,629,167✔
35
  c -= a;
75,629,167✔
36
  c -= b;
75,629,167✔
37
  c ^= (b >> 13);
75,629,167✔
38
  a -= b;
75,629,167✔
39
  a -= c;
75,629,167✔
40
  a ^= (c >> 12);
75,629,167✔
41
  b -= c;
75,629,167✔
42
  b -= a;
75,629,167✔
43
  b ^= (a << 16);
75,629,167✔
44
  c -= a;
75,629,167✔
45
  c -= b;
75,629,167✔
46
  c ^= (b >> 5);
75,629,167✔
47
  a -= b;
75,629,167✔
48
  a -= c;
75,629,167✔
49
  a ^= (c >> 3);
75,629,167✔
50
  b -= c;
75,629,167✔
51
  b -= a;
75,629,167✔
52
  b ^= (a << 10);
75,629,167✔
53
  c -= a;
75,629,167✔
54
  c -= b;
75,629,167✔
55
  c ^= (b >> 15);
75,629,167✔
56
}
75,629,167✔
57

58
inline uint32_t burtle(const unsigned char* k, uint32_t length, uint32_t initval)
59
{
10,399,253✔
60
  uint32_t a, b, c, len;
10,399,253✔
61

62
  /* Set up the internal state */
63
  len = length;
10,399,253✔
64
  a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
10,399,253✔
65
  c = initval; /* the previous hash value */
10,399,253✔
66

67
  /*---------------------------------------- handle most of the key */
68
  while (len >= 12) {
10,439,446✔
69
    a += (k[0] + ((uint32_t)k[1] << 8) + ((uint32_t)k[2] << 16) + ((uint32_t)k[3] << 24));
40,193✔
70
    b += (k[4] + ((uint32_t)k[5] << 8) + ((uint32_t)k[6] << 16) + ((uint32_t)k[7] << 24));
40,193✔
71
    c += (k[8] + ((uint32_t)k[9] << 8) + ((uint32_t)k[10] << 16) + ((uint32_t)k[11] << 24));
40,193✔
72
    burtlemix(a, b, c);
40,193✔
73
    k += 12;
40,193✔
74
    len -= 12;
40,193✔
75
  }
40,193✔
76

77
  /*------------------------------------- handle the last 11 bytes */
78
  c += length;
10,399,253✔
79
  switch (len) { /* all the case statements fall through */
10,399,253✔
UNCOV
80
  case 11:
33✔
UNCOV
81
    c += ((uint32_t)k[10] << 24);
33✔
82
    /* fall-through */
83
  case 10:
3,569,573✔
84
    c += ((uint32_t)k[9] << 16);
3,569,573✔
85
    /* fall-through */
86
  case 9:
3,569,584✔
87
    c += ((uint32_t)k[8] << 8);
3,569,584✔
88
    /* the first byte of c is reserved for the length */
89
    /* fall-through */
90
  case 8:
3,569,633✔
91
    b += ((uint32_t)k[7] << 24);
3,569,633✔
92
    /* fall-through */
93
  case 7:
3,571,161✔
94
    b += ((uint32_t)k[6] << 16);
3,571,161✔
95
    /* fall-through */
96
  case 6:
3,571,180✔
97
    b += ((uint32_t)k[5] << 8);
3,571,180✔
98
    /* fall-through */
99
  case 5:
3,571,180!
100
    b += k[4];
3,571,180✔
101
    /* fall-through */
102
  case 4:
7,736,502✔
103
    a += ((uint32_t)k[3] << 24);
7,736,502✔
104
    /* fall-through */
105
  case 3:
7,763,043✔
106
    a += ((uint32_t)k[2] << 16);
7,763,043✔
107
    /* fall-through */
108
  case 2:
7,791,950✔
109
    a += ((uint32_t)k[1] << 8);
7,791,950✔
110
    /* fall-through */
111
  case 1:
10,549,738✔
112
    a += k[0];
10,549,738✔
113
    /* case 0: nothing left to add */
114
  }
10,399,253✔
115
  burtlemix(a, b, c);
10,489,154✔
116
  /*-------------------------------------------- report the result */
117
  return c;
10,489,151✔
118
}
10,399,253✔
119

120
inline uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t initval)
121
{
36,400,875✔
122
  uint32_t a, b, c, len;
36,400,875✔
123

124
  /* Set up the internal state */
125
  len = length;
36,400,875✔
126
  a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
36,400,875✔
127
  c = initval; /* the previous hash value */
36,400,875✔
128

129
  /*---------------------------------------- handle most of the key */
130
  while (len >= 12) {
65,149,210✔
131
    a += (dns_tolower(k[0]) + ((uint32_t)dns_tolower(k[1]) << 8) + ((uint32_t)dns_tolower(k[2]) << 16) + ((uint32_t)dns_tolower(k[3]) << 24));
28,748,335✔
132
    b += (dns_tolower(k[4]) + ((uint32_t)dns_tolower(k[5]) << 8) + ((uint32_t)dns_tolower(k[6]) << 16) + ((uint32_t)dns_tolower(k[7]) << 24));
28,748,335✔
133
    c += (dns_tolower(k[8]) + ((uint32_t)dns_tolower(k[9]) << 8) + ((uint32_t)dns_tolower(k[10]) << 16) + ((uint32_t)dns_tolower(k[11]) << 24));
28,748,335✔
134
    burtlemix(a, b, c);
28,748,335✔
135
    k += 12;
28,748,335✔
136
    len -= 12;
28,748,335✔
137
  }
28,748,335✔
138

139
  /*------------------------------------- handle the last 11 bytes */
140
  c += length;
36,400,875✔
141
  switch (len) { /* all the case statements fall through */
36,400,875✔
142
  case 11:
6,663,862✔
143
    c += ((uint32_t)dns_tolower(k[10]) << 24);
6,663,862✔
144
    /* fall-through */
145
  case 10:
8,273,348✔
146
    c += ((uint32_t)dns_tolower(k[9]) << 16);
8,273,348✔
147
    /* fall-through */
148
  case 9:
9,048,314✔
149
    c += ((uint32_t)dns_tolower(k[8]) << 8);
9,048,314✔
150
    /* the first byte of c is reserved for the length */
151
    /* fall-through */
152
  case 8:
10,550,276✔
153
    b += ((uint32_t)dns_tolower(k[7]) << 24);
10,550,276✔
154
    /* fall-through */
155
  case 7:
10,973,474✔
156
    b += ((uint32_t)dns_tolower(k[6]) << 16);
10,973,474✔
157
    /* fall-through */
158
  case 6:
11,348,159✔
159
    b += ((uint32_t)dns_tolower(k[5]) << 8);
11,348,159✔
160
    /* fall-through */
161
  case 5:
11,817,990✔
162
    b += dns_tolower(k[4]);
11,817,990✔
163
    /* fall-through */
164
  case 4:
15,993,540✔
165
    a += ((uint32_t)dns_tolower(k[3]) << 24);
15,993,540✔
166
    /* fall-through */
167
  case 3:
18,334,821✔
168
    a += ((uint32_t)dns_tolower(k[2]) << 16);
18,334,821✔
169
    /* fall-through */
170
  case 2:
25,591,198✔
171
    a += ((uint32_t)dns_tolower(k[1]) << 8);
25,591,198✔
172
    /* fall-through */
173
  case 1:
31,483,688✔
174
    a += dns_tolower(k[0]);
31,483,688✔
175
    /* case 0: nothing left to add */
176
  }
36,400,875✔
177
  burtlemix(a, b, c);
36,465,280✔
178
  /*-------------------------------------------- report the result */
179
  return c;
36,452,136✔
180
}
36,400,875✔
181

182
template <typename T>
183
inline uint32_t burtleCI(const T& k, uint32_t initval)
184
{
32,520,516✔
185
  return burtleCI(reinterpret_cast<const unsigned char*>(k.data()), k.length(), initval); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): can't static_cast because of sign difference
32,520,516✔
186
}
32,520,516✔
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