Kea 2.7.4
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
11#include <algorithm>
12#include <string>
13
14using namespace isc::data;
15
16namespace isc {
17namespace dhcp {
18
20 : identifier_types_() {
21}
22
25 // If this list is modified, please update reservations4-tuning section in
26 // doc/guide/dhcp4-srv.xml
28 cfg->addIdentifierType("hw-address");
29 cfg->addIdentifierType("duid");
30 cfg->addIdentifierType("circuit-id");
31 cfg->addIdentifierType("client-id");
32 return (cfg);
33}
34
37 // If this list is modified, please update reservations6-tuning section in
38 // doc/guide/dhcp6-srv.xml
40 cfg->addIdentifierType("hw-address");
41 cfg->addIdentifierType("duid");
42 return (cfg);
43}
44
45void
46CfgHostOperations::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
56void
58 identifier_types_.clear();
59}
60
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}
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:299
static CfgHostOperationsPtr createConfig6()
Factory function for DHCPv6.
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...
void clearIdentifierTypes()
Removes existing identifier types.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
static CfgHostOperationsPtr createConfig4()
Factory function for DHCPv4.
IdentifierType
Type of the host identifier.
Definition host.h:337
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition host.cc:273
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition host.cc:349
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< CfgHostOperations > CfgHostOperationsPtr
Pointer to the Non-const object.
Defines the logger used by the top-level component of kea-lfc.