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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (C) 2015-2024 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 <cc/data.h>
#include <dhcp/duid.h>
#include <dhcpsrv/cfg_duid.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/parsers/duid_config_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <exceptions/exceptions.h>
#include <boost/lexical_cast.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace isc::data;

namespace isc {
namespace dhcp {

void
DUIDConfigParser::parse(const CfgDUIDPtr& cfg,
                        isc::data::ConstElementPtr duid_configuration) {
    if (!cfg) {
        // Sanity check
        isc_throw(DhcpConfigError, "Must provide valid pointer to cfg when parsing duid");
    }

    std::string param;
    try {
        param = "type";
        std::string duid_type = getString(duid_configuration, "type");
        // Map DUID type represented as text into numeric value.
        DUID::DUIDType numeric_type = DUID::DUID_UNKNOWN;
        if (duid_type == "LLT") {
            numeric_type = DUID::DUID_LLT;
        } else if (duid_type == "EN") {
            numeric_type = DUID::DUID_EN;
        } else if (duid_type == "LL") {
            numeric_type = DUID::DUID_LL;
        } else {
            isc_throw(BadValue, "unsupported DUID type '"
                      << duid_type << "'. Expected: LLT, EN or LL");
        }

        cfg->setType(static_cast<DUID::DUIDType>(numeric_type));

        param = "identifier";
        if (duid_configuration->contains(param)) {
            cfg->setIdentifier(getString(duid_configuration, param));
        }

        param = "htype";
        if (duid_configuration->contains(param)) {
            cfg->setHType(getUint16(duid_configuration, param));
        }

        param = "time";
        if (duid_configuration->contains(param)) {
            cfg->setTime(getUint32(duid_configuration, param));
        }

        param = "enterprise-id";
        if (duid_configuration->contains(param)) {
            cfg->setEnterpriseId(getUint32(duid_configuration, param));
        }

        param = "persist";
        if (duid_configuration->contains(param)) {
            cfg->setPersist(getBoolean(duid_configuration, param));
        }

        param = "user-context";
        ConstElementPtr user_context = duid_configuration->get("user-context");
        if (user_context) {
            cfg->setContext(user_context);
        }
    } catch (const DhcpConfigError&) {
        throw;
    } catch (const std::exception& ex) {
        // Append position.
        isc_throw(DhcpConfigError, ex.what() << " ("
                  << getPosition(param, duid_configuration) << ")");
    }

    LOG_WARN(dhcpsrv_logger, DHCPSRV_CFGMGR_CONFIGURE_SERVERID);
}

} // end of namespace isc::dhcp
} // end of namespace isc