| Kea 3.0.2-git

cfg_host_operations.cc
Go to the documentation of this file.
1// Copyright (C) 2016-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 <exceptions/exceptions.h>
10#include <dhcpsrv/cfg_host_operations.h>
11#include <algorithm>
12#include <string>
13
14 using namespace isc::data;
15
16 namespace isc {
17 namespace dhcp {
18
19 CfgHostOperations::CfgHostOperations()
20 : identifier_types_() {
21}
22
23 CfgHostOperationsPtr
24 CfgHostOperations::createConfig4() {
25 // If this list is modified, please update reservations4-tuning section in
26 // doc/guide/dhcp4-srv.xml
27 CfgHostOperationsPtr cfg(new CfgHostOperations());
28 cfg->addIdentifierType("hw-address");
29 cfg->addIdentifierType("duid");
30 cfg->addIdentifierType("circuit-id");
31 cfg->addIdentifierType("client-id");
32 return (cfg);
33}
34
35 CfgHostOperationsPtr
36 CfgHostOperations::createConfig6() {
37 // If this list is modified, please update reservations6-tuning section in
38 // doc/guide/dhcp6-srv.xml
39 CfgHostOperationsPtr cfg(new CfgHostOperations());
40 cfg->addIdentifierType("hw-address");
41 cfg->addIdentifierType("duid");
42 return (cfg);
43}
44
45 void
46 CfgHostOperations::addIdentifierType(const std::string& identifier_name) {
47 Host::IdentifierType identifier_type = Host::getIdentifierType(identifier_name);
48 if (std::find(identifier_types_.begin(), identifier_types_.end(),
49 identifier_type) != identifier_types_.end()) {
50 isc_throw(isc::BadValue, "duplicate host identifier '"
51 << identifier_name << "'");
52 }
53 identifier_types_.push_back(identifier_type);
54}
55
56 void
57 CfgHostOperations::clearIdentifierTypes() {
58 identifier_types_.clear();
59}
60
61 ElementPtr
62 CfgHostOperations::toElement() const {
63 ElementPtr result = Element::createList();
64 for (auto const& id : identifier_types_) {
65 const std::string& name = Host::getIdentifierName(id);
66 result->add(Element::create(name));
67 }
68 return (result);
69}
70
71}
72}
cfg_host_operations.h
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::data::Element::create
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
isc::data::Element::createList
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:299
isc::dhcp::CfgHostOperations::createConfig6
static CfgHostOperationsPtr createConfig6()
Factory function for DHCPv6.
Definition cfg_host_operations.cc:36
isc::dhcp::CfgHostOperations::addIdentifierType
void addIdentifierType(const std::string &identifier_name)
Adds new identifier type to a collection of identifiers to be used by the server to search for host r...
Definition cfg_host_operations.cc:46
isc::dhcp::CfgHostOperations::clearIdentifierTypes
void clearIdentifierTypes()
Removes existing identifier types.
Definition cfg_host_operations.cc:57
isc::dhcp::CfgHostOperations::toElement
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition cfg_host_operations.cc:62
isc::dhcp::CfgHostOperations::CfgHostOperations
CfgHostOperations()
Constructor.
Definition cfg_host_operations.cc:19
isc::dhcp::CfgHostOperations::createConfig4
static CfgHostOperationsPtr createConfig4()
Factory function for DHCPv4.
Definition cfg_host_operations.cc:24
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition host.h:337
isc::dhcp::Host::getIdentifierType
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition host.cc:273
isc::dhcp::Host::getIdentifierName
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition host.cc:349
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::data
Definition base_stamped_element.cc:12
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::CfgHostOperationsPtr
boost::shared_ptr< CfgHostOperations > CfgHostOperationsPtr
Pointer to the Non-const object.
Definition cfg_host_operations.h:25
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148