Kea 2.7.6
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
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
357
359 std::vector<HAConfig::PeerConfigPtr> peers_;
360
363 std::map<std::string, bool> scopes_;
364
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
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< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
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.