diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:15:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:15:43 +0000 |
commit | f5f56e1a1c4d9e9496fcb9d81131066a964ccd23 (patch) | |
tree | 49e44c6f87febed37efb953ab5485aa49f6481a7 /src/lib/dhcpsrv/cfg_mac_source.cc | |
parent | Initial commit. (diff) | |
download | isc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.tar.xz isc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.zip |
Adding upstream version 2.4.1.upstream/2.4.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/dhcpsrv/cfg_mac_source.cc')
-rw-r--r-- | src/lib/dhcpsrv/cfg_mac_source.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/lib/dhcpsrv/cfg_mac_source.cc b/src/lib/dhcpsrv/cfg_mac_source.cc new file mode 100644 index 0000000..7a0db26 --- /dev/null +++ b/src/lib/dhcpsrv/cfg_mac_source.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2014-2015,2017 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 <dhcpsrv/cfg_mac_source.h> +#include <exceptions/exceptions.h> +#include <dhcp/hwaddr.h> + +using namespace isc::data; + +namespace { + +using namespace isc::dhcp; + +struct { + const char * name; + uint32_t type; +} sources[] = { + { "any", HWAddr::HWADDR_SOURCE_ANY }, + { "raw", HWAddr::HWADDR_SOURCE_RAW }, + { "duid", HWAddr::HWADDR_SOURCE_DUID }, + { "ipv6-link-local", HWAddr::HWADDR_SOURCE_IPV6_LINK_LOCAL }, + { "client-link-addr-option", HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION }, + { "rfc6939", HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION }, + { "remote-id", HWAddr::HWADDR_SOURCE_REMOTE_ID }, + { "rfc4649", HWAddr::HWADDR_SOURCE_REMOTE_ID }, + { "subscriber-id", HWAddr::HWADDR_SOURCE_SUBSCRIBER_ID }, + { "rfc4580", HWAddr::HWADDR_SOURCE_SUBSCRIBER_ID }, + { "docsis-cmts", HWAddr::HWADDR_SOURCE_DOCSIS_CMTS }, + { "docsis-modem", HWAddr::HWADDR_SOURCE_DOCSIS_MODEM } +}; + +}; + +namespace isc { +namespace dhcp { + +CfgMACSource::CfgMACSource() { + + // By default, use any hardware source that is available. + mac_sources_.push_back(HWAddr::HWADDR_SOURCE_ANY); +} + +uint32_t CfgMACSource::MACSourceFromText(const std::string& name) { + for (unsigned i = 0; i < sizeof(sources)/sizeof(sources[0]); ++i) { + if (name.compare(sources[i].name) == 0) { + return (sources[i].type); + } + } + + isc_throw(BadValue, "Can't convert '" << name << "' to any known MAC source."); +} + +void CfgMACSource::add(uint32_t source) { + for (CfgMACSources::const_iterator it = mac_sources_.begin(); + it != mac_sources_.end(); ++it) { + if (*it == source) { + isc_throw(InvalidParameter, "mac-source parameter " << source + << "' specified twice."); + } + } + mac_sources_.push_back(source); +} + +ElementPtr CfgMACSource::toElement() const { + ElementPtr result = Element::createList(); + for (CfgMACSources::const_iterator source = mac_sources_.cbegin(); + source != mac_sources_.cend(); ++source) { + std::string name; + for (unsigned i = 0; i < sizeof(sources)/sizeof(sources[0]); ++i) { + if (sources[i].type == *source) { + name = sources[i].name; + break; + } + } + if (name.empty()) { + isc_throw(ToElementError, "invalid MAC source: " << *source); + } + result->add(Element::create(name)); + } + // @todo check if the list is empty (including a new unit test) + return (result); +} + +}; +}; |