Coverage Report

Created: 2026-09-07 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pdns/pdns/dnsdistdist/dnsdist-protocols.hh
Line
Count
Source
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
#pragma once
23
24
#include <array>
25
#include <cstdint>
26
#include <string>
27
28
namespace dnsdist
29
{
30
class Protocol
31
{
32
public:
33
  enum typeenum : uint8_t
34
  {
35
    DoUDP = 0,
36
    DoTCP,
37
    DNSCryptUDP,
38
    DNSCryptTCP,
39
    DoT,
40
    DoH,
41
    DoQ,
42
    DoH3
43
  };
44
45
  Protocol(typeenum protocol = DoUDP) :
46
0
    d_protocol(protocol)
47
0
  {
48
0
    if (protocol >= s_names.size()) {
49
0
      throw std::runtime_error("Unknown protocol: '" + std::to_string(protocol) + "'");
50
0
    }
51
0
  }
52
53
  explicit Protocol(const std::string& protocol);
54
55
  bool operator==(typeenum) const;
56
  bool operator!=(typeenum) const;
57
  bool operator==(const Protocol& rhs) const;
58
  bool operator!=(const Protocol& rhs) const;
59
60
  const std::string& toString() const;
61
  const std::string& toPrettyString() const;
62
  bool isUDP() const;
63
  bool isEncrypted() const;
64
  uint8_t toNumber() const;
65
66
private:
67
  typeenum d_protocol;
68
69
  static constexpr size_t s_numberOfProtocols = 8;
70
  static const std::array<std::string, s_numberOfProtocols> s_names;
71
  static const std::array<std::string, s_numberOfProtocols> s_prettyNames;
72
};
73
}