summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_host_operations.cc
blob: aec147ff81691d37677b0a91a392dbe0495d58c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <exceptions/exceptions.h>
#include <dhcpsrv/cfg_host_operations.h>
#include <algorithm>

namespace isc {
namespace dhcp {

CfgHostOperations::CfgHostOperations()
    : identifier_types_() {
}

CfgHostOperationsPtr
CfgHostOperations::createConfig4() {
    // If this list is modified, please update reservations4-tuning section in
    // doc/guide/dhcp4-srv.xml
    CfgHostOperationsPtr cfg(new CfgHostOperations());
    cfg->addIdentifierType("hw-address");
    cfg->addIdentifierType("duid");
    cfg->addIdentifierType("circuit-id");
    return (cfg);
}

CfgHostOperationsPtr
CfgHostOperations::createConfig6() {
    // If this list is modified, please update reservations6-tuning section in
    // doc/guide/dhcp6-srv.xml
    CfgHostOperationsPtr cfg(new CfgHostOperations());
    cfg->addIdentifierType("hw-address");
    cfg->addIdentifierType("duid");
    return (cfg);
}

void
CfgHostOperations::addIdentifierType(const std::string& identifier_name) {
    Host::IdentifierType identifier_type = Host::getIdentifierType(identifier_name);
    if (std::find(identifier_types_.begin(), identifier_types_.end(),
                  identifier_type) != identifier_types_.end()) {
        isc_throw(isc::BadValue, "duplicate host identifier '"
                  << identifier_name << "'");
    }
    identifier_types_.push_back(identifier_type);
}

void
CfgHostOperations::clearIdentifierTypes() {
    identifier_types_.clear();
}

}
}