Kea  2.1.7-git
cfg_host_operations.cc
Go to the documentation of this file.
1 // Copyright (C) 2016-2017 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 
14 using namespace isc::data;
15 
16 namespace isc {
17 namespace dhcp {
18 
19 CfgHostOperations::CfgHostOperations()
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 
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
58  identifier_types_.clear();
59 }
60 
63  ElementPtr result = Element::createList();
64  for (IdentifierTypes::const_iterator id = identifier_types_.begin();
65  id != identifier_types_.end(); ++id) {
66  const std::string& name = Host::getIdentifierName(*id);
67  result->add(Element::create(name));
68  }
69  return (result);
70 }
71 
72 }
73 }
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...
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
static CfgHostOperationsPtr createConfig4()
Factory function for DHCPv4.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition: host.cc:293
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static CfgHostOperationsPtr createConfig6()
Factory function for DHCPv6.
Defines the logger used by the top-level component of kea-lfc.
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition: host.cc:217
void clearIdentifierTypes()
Removes existing identifier types.
IdentifierType
Type of the host identifier.
Definition: host.h:307
boost::shared_ptr< CfgHostOperations > CfgHostOperationsPtr
Pointer to the Non-const object.