Kea: query_filter.h Source File

| Kea 2.2.0

query_filter.h
Go to the documentation of this file.
1// Copyright (C) 2018-2022 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
61 class QueryFilter {
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
192 static bool isHaType(const dhcp::Pkt4Ptr& query4);
193
199 static bool isHaType(const dhcp::Pkt6Ptr& query6);
200
201private:
211 void serveScopeInternal(const std::string& scope_name);
212
222 void serveScopeOnlyInternal(const std::string& scope_name);
223
231 void serveScopesInternal(const std::vector<std::string>& scopes);
232
239 void serveDefaultScopesInternal();
240
250 void serveFailoverScopesInternal();
251
255 void serveNoScopesInternal();
256
264 bool amServingScopeInternal(const std::string& scope_name) const;
265
271 std::set<std::string> getServedScopesInternal() const;
272
287 template<typename QueryPtrType>
288 bool inScopeInternal(const QueryPtrType& query, std::string& scope_class) const;
289
290protected:
291
304 int loadBalance(const dhcp::Pkt4Ptr& query4) const;
305
318 int loadBalance(const dhcp::Pkt6Ptr& query6) const;
319
330 uint8_t loadBalanceHash(const uint8_t* key, const size_t key_len) const;
331
337 void validateScopeName(const std::string& scope_name) const;
338
353 std::string makeScopeClass(const std::string& scope_name) const;
354
356 HAConfigPtr config_;
357
359 std::vector<HAConfig::PeerConfigPtr> peers_;
360
363 std::map<std::string, bool> scopes_;
364
366 int active_servers_;
367
369 boost::scoped_ptr<std::mutex> mutex_;
370};
371
372} // end of namespace isc::ha
373} // end of namespace isc
374
375#endif // QUERY_FILTER_H
isc::ha::QueryFilter
DHCP query filtering class.
Definition: query_filter.h:61
isc::ha::QueryFilter::serveScopes
void serveScopes(const std::vector< std::string > &scopes)
Enables selected scopes.
Definition: query_filter.cc:206
isc::ha::QueryFilter::inScope
bool inScope(const dhcp::Pkt4Ptr &query4, std::string &scope_class) const
Checks if this server should process the DHCPv4 query.
Definition: query_filter.cc:363
isc::ha::QueryFilter::amServingScope
bool amServingScope(const std::string &scope_name) const
Checks if this server instance is configured to process traffic belonging to a particular scope.
Definition: query_filter.cc:313
isc::ha::QueryFilter::makeScopeClass
std::string makeScopeClass(const std::string &scope_name) const
Returns scope class name for the specified scope name.
Definition: query_filter.cc:495
isc::ha::QueryFilter::mutex_
boost::scoped_ptr< std::mutex > mutex_
Mutex to protect the internal state.
Definition: query_filter.h:369
isc::ha::QueryFilter::serveFailoverScopes
void serveFailoverScopes()
Enable scopes required in failover case.
Definition: query_filter.cc:262
isc::ha::QueryFilter::loadBalanceHash
uint8_t loadBalanceHash(const uint8_t *key, const size_t key_len) const
Compute load balancing hash.
Definition: query_filter.cc:472
isc::ha::QueryFilter::validateScopeName
void validateScopeName(const std::string &scope_name) const
Checks if the scope name matches a name of any of the configured servers.
Definition: query_filter.cc:483
isc::ha::QueryFilter::active_servers_
int active_servers_
Number of the active servers in the given HA mode.
Definition: query_filter.h:366
isc::ha::QueryFilter::config_
HAConfigPtr config_
Pointer to the HA configuration.
Definition: query_filter.h:356
isc::ha::QueryFilter::serveScopeOnly
void serveScopeOnly(const std::string &scope_name)
Enable scope and disable all other scopes.
Definition: query_filter.cc:189
isc::ha::QueryFilter::loadBalance
int loadBalance(const dhcp::Pkt4Ptr &query4) const
Performs load balancing of the DHCPv4 queries.
Definition: query_filter.cc:417
isc::ha::QueryFilter::isHaType
static bool isHaType(const dhcp::Pkt4Ptr &query4)
Determines if a DHCPv4 query is a message type HA should process.
Definition: query_filter.cc:350
isc::ha::QueryFilter::serveDefaultScopes
void serveDefaultScopes()
Serve default scopes for the given HA mode.
Definition: query_filter.cc:235
isc::ha::QueryFilter::serveNoScopes
void serveNoScopes()
Disables all scopes.
Definition: query_filter.cc:293
isc::ha::QueryFilter::getServedScopes
std::set< std::string > getServedScopes() const
Returns served scopes.
Definition: query_filter.cc:329
isc::ha::QueryFilter::serveScope
void serveScope(const std::string &scope_name)
Enable scope.
Definition: query_filter.cc:173
isc::ha::QueryFilter::peers_
std::vector< HAConfig::PeerConfigPtr > peers_
Vector of HA peers configurations.
Definition: query_filter.h:359
isc::ha::QueryFilter::scopes_
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:363
isc::ha::QueryFilter::QueryFilter
QueryFilter(const HAConfigPtr &config)
Constructor.
Definition: query_filter.cc:121
ha_config.h
isc::dhcp::Pkt4Ptr
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition: pkt4.h:544
isc::dhcp::Pkt6Ptr
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition: pkt6.h:28
isc::ha::HAConfigPtr
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition: ha_config.h:786
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143
pkt4.h
pkt6.h