Kea 2.5.5
cfg_db_access.cc
Go to the documentation of this file.
1// Copyright (C) 2016-2023 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>
9#include <dhcpsrv/db_type.h>
11#include <dhcpsrv/host_mgr.h>
13#include <boost/algorithm/string.hpp>
14#include <boost/foreach.hpp>
15#include <boost/lexical_cast.hpp>
16#include <sstream>
17#include <vector>
18
19using namespace isc::data;
20
21namespace isc {
22namespace dhcp {
23
25 : appended_parameters_(), lease_db_access_("type=memfile"),
26 host_db_access_(), ip_reservations_unique_(true),
27 extended_info_tables_enabled_(false) {
28}
29
30std::string
33}
34
35
36std::string
38 if (host_db_access_.empty()) {
39 return ("");
40 } else {
41 return (getAccessString(host_db_access_.front()));
42 }
43}
44
45std::list<std::string>
47 std::list<std::string> ret;
48 for (const std::string& dbaccess : host_db_access_) {
49 if (!dbaccess.empty()) {
50 ret.push_back(getAccessString(dbaccess));
51 }
52 }
53 return (ret);
54}
55
56void
58 // Recreate lease manager without preserving the registered callbacks.
60
61 // Recreate host data source.
63
64 // Restore the host cache.
66 HostMgr::addBackend("type=cache");
67 }
68
69 // Add database backends.
70 std::list<std::string> host_db_access_list = getHostDbAccessStringList();
71 for (std::string& hds : host_db_access_list) {
73 }
74
75 // Check for a host cache.
77
78 // Populate the ip-reservations-unique global setting to HostMgr.
79 // This operation may fail if any of the host backends does not support
80 // the new setting. We throw an exception here to signal configuration
81 // error. The exception does not contain the backend name but the called
82 // function in HostMgr logs a warning message that contains the name of
83 // the backend.
85 isc_throw(InvalidOperation, "unable to configure the server to allow "
86 "non unique IP reservations (ip-reservations-unique=false) "
87 "because some host backends in use do not support this "
88 "setting");
89 }
90}
91
92std::string
93CfgDbAccess::getAccessString(const std::string& access_string) const {
94 std::ostringstream s;
95 s << access_string;
96 // Only append additional parameters if any parameters are specified
97 // in a configuration. For host database, no parameters mean that
98 // database access is disabled and thus we don't want to append any
99 // parameters.
100 if ((s.tellp() != std::streampos(0)) && (!appended_parameters_.empty())) {
101 s << " " << appended_parameters_;
102 }
103
104 return (s.str());
105}
106
107} // end of isc::dhcp namespace
108} // end of isc namespace
A generic exception that is thrown if a function is called in a prohibited way.
bool ip_reservations_unique_
Holds the setting whether IP reservations should be unique or can be non-unique.
std::string getAccessString(const std::string &access_string) const
Returns lease or host database access string.
void createManagers() const
Creates instance of lease manager and host data sources according to the configuration specified.
std::string getHostDbAccessString() const
Retrieves host database access string.
std::list< std::string > host_db_access_
Holds host database access strings.
std::string appended_parameters_
Parameters to be appended to the database access strings.
CfgDbAccess()
Constructor.
std::list< std::string > getHostDbAccessStringList() const
Retrieves host database access string.
void setIPReservationsUnique(const bool unique)
Modifies the setting imposing whether the IP reservations are unique or can be non unique.
Definition: cfg_db_access.h:90
std::string lease_db_access_
Holds lease database access string.
std::string getLeaseDbAccessString() const
Retrieves lease database access string.
static bool registeredFactory(const std::string &db_type)
Check if a host data source factory was registered.
static void create()
Creates new instance of the HostMgr.
Definition: host_mgr.cc:54
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
Definition: host_mgr.cc:59
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
Definition: host_mgr.cc:94
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Definition: host_mgr.cc:116
static void recreate(const std::string &dbaccess, bool preserve_callbacks=true)
Recreate an instance of a lease manager with optionally preserving registered callbacks.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.