Kea 3.1.1
config_cache.cc
Go to the documentation of this file.
1// Copyright (C) 2023-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#include <config.h>
8
9#include <config_cache.h>
11
12using namespace isc;
13using namespace isc::data;
14using namespace isc::dhcp;
15using namespace isc::util;
16using namespace std;
17
18namespace isc {
19namespace ping_check {
20
23 return (global_config_);
24}
25
26void
28 if (!config) {
29 isc_throw(BadValue, "ConfigCache - global config cannot be empty");
30 }
31
32 global_config_ = config;
33}
34
35bool
37 MultiThreadingLock lock(*mutex_);
38 return (findConfigInternal(subnet_id, config));
39}
40
41bool
42ConfigCache::findConfigInternal(const SubnetID& subnet_id, PingCheckConfigPtr& config) const {
43 auto it = configs_.find(subnet_id);
44 if (it != configs_.end()) {
45 config = it->second;
46 return (true);
47 }
48
50 return (false);
51}
52
56 if (user_context) {
57 ConstElementPtr ping_check_params = user_context->get("ping-check");
58 if (ping_check_params) {
59 // Copy construct from global to start with.
61
62 // Now parse in subnet-specific values. This may throw a DhcpConfigError but
63 // that's OK, dealt with by the caller.
64 try {
65 config->parse(ping_check_params);
66 } catch (...) {
67 throw;
68 }
69 }
70 }
71
72 // Cache the config. We allow empty configs so higher precedence scopes may
73 // override lower precedence scopes.
74 cacheConfig(subnet_id, config);
75 return (config);
76}
77
78void
80 MultiThreadingLock lock(*mutex_);
81 configs_[subnet_id] = config;
82}
83
84void
86 MultiThreadingLock lock(*mutex_);
87 // Discard the contents.
88 configs_.clear();
89
90 // We use modification time to remember the last time we flushed.
92}
93
94size_t
96 MultiThreadingLock lock(*mutex_);
97 return (configs_.size());
98}
99
100boost::posix_time::ptime
105
106} // end of namespace ping_check
107} // end of namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::posix_time::ptime getModificationTime() const
Returns timestamp.
void updateModificationTime()
Sets timestamp to the current time.
void setGlobalConfig(PingCheckConfigPtr &config)
Set the global level configuration.
bool findConfig(const dhcp::SubnetID &subnet_id, PingCheckConfigPtr &config)
Get the config for a given subnet.
PingCheckConfigPtr parseAndCacheConfig(const dhcp::SubnetID &subnet_id, data::ConstElementPtr &user_context)
Parses a config string and caches for the given subnet.
void flush()
Discards the subnet entries in the cache.
PingCheckConfigPtr & getGlobalConfig()
Get the global level configuration.
size_t size()
Get the number of entries in the cache.
void cacheConfig(const dhcp::SubnetID &subnet_id, PingCheckConfigPtr &config)
Adds (or replaces) the config for a given subnet to the cache.
boost::posix_time::ptime getLastFlushTime()
Get the last time the cache was flushed.
Houses the Ping check configuration parameters for a single scope (e.g.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::shared_ptr< PingCheckConfig > PingCheckConfigPtr
Defines a shared pointer to a PingCheckConfig.
Defines the logger used by the top-level component of kea-lfc.
RAII lock object to protect the code in the same scope with a mutex.