/src/pdns/pdns/dnsdistdist/dnsdist-server-pool.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 | | #include <memory> |
24 | | |
25 | | #include "dnsdist-lbpolicies.hh" |
26 | | |
27 | | class DNSDistPacketCache; |
28 | | |
29 | | struct ServerPool |
30 | | { |
31 | | const std::shared_ptr<DNSDistPacketCache> getCache() const |
32 | 0 | { |
33 | 0 | return packetCache; |
34 | 0 | } |
35 | | |
36 | | bool getECS() const |
37 | 0 | { |
38 | 0 | return d_useECS; |
39 | 0 | } |
40 | | |
41 | | /* Note that the pool will do a consistency check, |
42 | | and might decide to override the supplied value |
43 | | if all backends in the pool have the same ECS |
44 | | value and the value differs from the supplied one */ |
45 | | void setECS(bool useECS); |
46 | | |
47 | | bool getZeroScope() const |
48 | 0 | { |
49 | 0 | return d_zeroScope; |
50 | 0 | } |
51 | | |
52 | | /* Note that the pool will do a consistency check, |
53 | | and might decide to override the supplied value |
54 | | if all backends in the pool have the same disable zero scope setting |
55 | | value and the value differs from the supplied one */ |
56 | | void setZeroScope(bool enabled); |
57 | | |
58 | | bool isConsistent() const |
59 | 0 | { |
60 | 0 | return d_isConsistent; |
61 | 0 | } |
62 | | |
63 | | /* sum of outstanding queries for all servers in this pool */ |
64 | | size_t poolLoad() const; |
65 | | size_t countServers(bool upOnly) const; |
66 | | bool hasAtLeastOneServerAvailable() const; |
67 | | bool shouldKeepStaleData() const; |
68 | | const ServerPolicy::NumberedServerVector& getServers() const; |
69 | | void addServer(std::shared_ptr<DownstreamState>& server); |
70 | | void removeServer(std::shared_ptr<DownstreamState>& server); |
71 | | bool isTCPOnly() const |
72 | 0 | { |
73 | 0 | // coverity[missing_lock] |
74 | 0 | return d_tcpOnly; |
75 | 0 | } |
76 | | |
77 | | std::shared_ptr<DNSDistPacketCache> packetCache{nullptr}; |
78 | | std::shared_ptr<ServerPolicy> policy{nullptr}; |
79 | | |
80 | | private: |
81 | | void updateConsistency(); |
82 | | |
83 | | ServerPolicy::NumberedServerVector d_servers; |
84 | | bool d_useECS{false}; |
85 | | bool d_zeroScope{true}; |
86 | | bool d_tcpOnly{false}; |
87 | | bool d_isConsistent{true}; |
88 | | }; |