Kea 2.7.8
query_filter.h
Go to the documentation of this file.
1// Copyright (C) 2018-2025 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
23namespace isc {
24namespace ha {
25
62public:
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
161 bool inScope(const dhcp::Pkt4Ptr& query4, std::string& scope_class) const;
162
185 bool inScope(const dhcp::Pkt6Ptr& query6, std::string& scope_class) const;
186
200 bool inScope(const dhcp::Lease4Ptr& lease4) const;
201
215 bool inScope(const dhcp::Lease6Ptr& lease6) const;
216
222 static bool isHaType(const dhcp::Pkt4Ptr& query4);
223
229 static bool isHaType(const dhcp::Pkt6Ptr& query6);
230
231private:
241 void serveScopeInternal(const std::string& scope_name);
242
252 void serveScopeOnlyInternal(const std::string& scope_name);
253
261 void serveScopesInternal(const std::vector<std::string>& scopes);
262
269 void serveDefaultScopesInternal();
270
280 void serveFailoverScopesInternal();
281
285 void serveNoScopesInternal();
286
294 bool amServingScopeInternal(const std::string& scope_name) const;
295
301 std::set<std::string> getServedScopesInternal() const;
302
317 template<typename QueryPtrType>
318 bool queryInScopeInternal(const QueryPtrType& query, std::string& scope_class) const;
319
330 template<typename LeasePtrType>
331 bool leaseInScopeInternal(const LeasePtrType& lease) const;
332
333protected:
334
347 int loadBalance(const dhcp::Pkt4Ptr& query4) const;
348
361 int loadBalance(const dhcp::Pkt6Ptr& query6) const;
362
375 int loadBalance(const dhcp::Lease4Ptr& lease4) const;
376
389 int loadBalance(const dhcp::Lease6Ptr& lease6) const;
390
401 uint8_t loadBalanceHash(const uint8_t* key, const size_t key_len) const;
402
408 void validateScopeName(const std::string& scope_name) const;
409
424 std::string makeScopeClass(const std::string& scope_name) const;
425
428
430 std::vector<HAConfig::PeerConfigPtr> peers_;
431
434 std::map<std::string, bool> scopes_;
435
438
440 boost::scoped_ptr<std::mutex> mutex_;
441};
442
443} // end of namespace isc::ha
444} // end of namespace isc
445
446#endif // QUERY_FILTER_H
DHCP query filtering class.
void serveScopes(const std::vector< std::string > &scopes)
Enables selected scopes.
bool inScope(const dhcp::Pkt4Ptr &query4, std::string &scope_class) const
Checks if this server should process the DHCPv4 query.
bool amServingScope(const std::string &scope_name) const
Checks if this server instance is configured to process traffic belonging to a particular scope.
std::string makeScopeClass(const std::string &scope_name) const
Returns scope class name for the specified scope name.
boost::scoped_ptr< std::mutex > mutex_
Mutex to protect the internal state.
void serveFailoverScopes()
Enable scopes required in failover case.
uint8_t loadBalanceHash(const uint8_t *key, const size_t key_len) const
Compute load balancing hash.
void validateScopeName(const std::string &scope_name) const
Checks if the scope name matches a name of any of the configured servers.
int active_servers_
Number of the active servers in the given HA mode.
HAConfigPtr config_
Pointer to the HA configuration.
void serveScopeOnly(const std::string &scope_name)
Enable scope and disable all other scopes.
int loadBalance(const dhcp::Pkt4Ptr &query4) const
Performs load balancing of the DHCPv4 queries.
static bool isHaType(const dhcp::Pkt4Ptr &query4)
Determines if a DHCPv4 query is a message type HA should process.
void serveDefaultScopes()
Serve default scopes for the given HA mode.
void serveNoScopes()
Disables all scopes.
std::set< std::string > getServedScopes() const
Returns served scopes.
void serveScope(const std::string &scope_name)
Enable scope.
std::vector< HAConfig::PeerConfigPtr > peers_
Vector of HA peers configurations.
std::map< std::string, bool > scopes_
Holds mapping of the scope names to the flag which indicates if the scopes are enabled or disabled.
QueryFilter(const HAConfigPtr &config)
Constructor.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:555
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition lease.h:528
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition lease.h:315
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition ha_config.h:37
Defines the logger used by the top-level component of kea-lfc.