Kea 2.5.9
lease_sync_filter.cc
Go to the documentation of this file.
1// Copyright (C) 2023-2024 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#include <config.h>
8
9#include <dhcpsrv/cfgmgr.h>
10#include <ha_config.h>
11#include <lease_sync_filter.h>
12
13using namespace isc::data;
14using namespace isc::dhcp;
15
16namespace isc {
17namespace ha {
18
20 : server_type_(server_type), config_(config), subnet_ids_() {
21}
22
23void
25 subnet_ids_.clear();
26 if (server_type_ == HAServerType::DHCPv4) {
27 for (auto const& subnet : *CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll()) {
28 conditionallyApplySubnetFilter(subnet);
29 }
30 } else {
31 for (auto const& subnet : *CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll()) {
32 conditionallyApplySubnetFilter(subnet);
33 }
34 }
35}
36
37bool
39 return (subnet_ids_.empty() || subnet_ids_.count(lease->subnet_id_));
40}
41
42void
43LeaseSyncFilter::conditionallyApplySubnetFilter(const SubnetPtr& subnet) {
44 try {
45 auto server_name = HAConfig::getSubnetServerName(subnet);
46 if (!server_name.empty()) {
47 for (auto const& peer : config_->getAllServersConfig()) {
48 if (peer.first == server_name) {
49 subnet_ids_.insert(subnet->getID());
50 return;
51 }
52 }
53 }
54 } catch (...) {
55 // Don't add ID when there was no way to fetch
56 // the server name.
57 }
58}
59
60} // end of namespace isc::ha
61} // end of namespace isc
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition: cfgmgr.cc:25
static std::string getSubnetServerName(const dhcp::SubnetPtr &subnet)
Convenience function extracting a value of the ha-server-name parameter from a subnet context.
Definition: ha_config.cc:524
void apply()
Applies filtering rules based on the current server configuration.
LeaseSyncFilter(const HAServerType &server_type, const HAConfigPtr &config)
Constructor.
bool shouldSync(const dhcp::LeasePtr &lease) const
Checks if the lease should be accepted or discarded.
boost::shared_ptr< Subnet > SubnetPtr
A generic pointer to either Subnet4 or Subnet6 object.
Definition: subnet.h:489
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition: lease.h:25
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
Definition: ha_config.h:37
HAServerType
Lists possible server types for which HA service is created.
Defines the logger used by the top-level component of kea-lfc.