Kea  1.9.9-git
query_filter.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef QUERY_FILTER_H
8 #define QUERY_FILTER_H
9 
10 #include <ha_config.h>
11 #include <dhcp/pkt4.h>
12 #include <dhcp/pkt6.h>
13 
14 #include <boost/scoped_ptr.hpp>
15 
16 #include <cstdint>
17 #include <map>
18 #include <mutex>
19 #include <set>
20 #include <string>
21 #include <vector>
22 
23 namespace isc {
24 namespace ha {
25 
61 class QueryFilter {
62 public:
63 
82  explicit QueryFilter(const HAConfigPtr& config);
83 
91  void serveScope(const std::string& scope_name);
92 
100  void serveScopeOnly(const std::string& scope_name);
101 
107  void serveScopes(const std::vector<std::string>& scopes);
108 
113  void serveDefaultScopes();
114 
122  void serveFailoverScopes();
123 
125  void serveNoScopes();
126 
132  bool amServingScope(const std::string& scope_name) const;
133 
137  std::set<std::string> getServedScopes() const;
138 
153  bool inScope(const dhcp::Pkt4Ptr& query4, std::string& scope_class) const;
154 
169  bool inScope(const dhcp::Pkt6Ptr& query6, std::string& scope_class) const;
170 
171 private:
181  void serveScopeInternal(const std::string& scope_name);
182 
192  void serveScopeOnlyInternal(const std::string& scope_name);
193 
201  void serveScopesInternal(const std::vector<std::string>& scopes);
202 
209  void serveDefaultScopesInternal();
210 
220  void serveFailoverScopesInternal();
221 
225  void serveNoScopesInternal();
226 
234  bool amServingScopeInternal(const std::string& scope_name) const;
235 
241  std::set<std::string> getServedScopesInternal() const;
242 
257  template<typename QueryPtrType>
258  bool inScopeInternal(const QueryPtrType& query, std::string& scope_class) const;
259 
260 protected:
261 
274  int loadBalance(const dhcp::Pkt4Ptr& query4) const;
275 
288  int loadBalance(const dhcp::Pkt6Ptr& query6) const;
289 
300  uint8_t loadBalanceHash(const uint8_t* key, const size_t key_len) const;
301 
307  void validateScopeName(const std::string& scope_name) const;
308 
323  std::string makeScopeClass(const std::string& scope_name) const;
324 
327 
329  std::vector<HAConfig::PeerConfigPtr> peers_;
330 
333  std::map<std::string, bool> scopes_;
334 
337 
339  boost::scoped_ptr<std::mutex> mutex_;
340 };
341 
342 } // end of namespace isc::ha
343 } // end of namespace isc
344 
345 #endif // QUERY_FILTER_H
void serveScope(const std::string &scope_name)
Enable scope.
void serveNoScopes()
Disables all scopes.
bool inScope(const dhcp::Pkt4Ptr &query4, std::string &scope_class) const
Checks if this server should process the DHCPv4 query.
std::string makeScopeClass(const std::string &scope_name) const
Returns scope class name for the specified scope name.
QueryFilter(const HAConfigPtr &config)
Constructor.
Definition: query_filter.cc:55
std::set< std::string > getServedScopes() const
Returns served scopes.
int loadBalance(const dhcp::Pkt4Ptr &query4) const
Performs load balancing of the DHCPv4 queries.
std::vector< HAConfig::PeerConfigPtr > peers_
Vector of HA peers configurations.
Definition: query_filter.h:329
void serveDefaultScopes()
Serve default scopes for the given HA mode.
DHCP query filtering class.
Definition: query_filter.h:61
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition: pkt6.h:28
std::map< std::string, bool > scopes_
Holds mapping of the scope names to the flag which indicates if the scopes are enabled or disabled...
Definition: query_filter.h:333
void serveScopes(const std::vector< std::string > &scopes)
Enables selected scopes.
boost::scoped_ptr< std::mutex > mutex_
Mutex to protect the internal state.
Definition: query_filter.h:339
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition: pkt4.h:544
bool amServingScope(const std::string &scope_name) const
Checks if this server instance is configured to process traffic belonging to a particular scope...
void validateScopeName(const std::string &scope_name) const
Checks if the scope name matches a name of any of the configured servers.
void serveFailoverScopes()
Enable scopes required in failover case.
Defines the logger used by the top-level component of kea-dhcp-ddns.
uint8_t loadBalanceHash(const uint8_t *key, const size_t key_len) const
Compute load balancing hash.
HAConfigPtr config_
Pointer to the HA configuration.
Definition: query_filter.h:326
void serveScopeOnly(const std::string &scope_name)
Enable scope and disable all other scopes.
int active_servers_
Number of the active servers in the given HA mode.
Definition: query_filter.h:336
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition: ha_config.h:760