summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_mac_source.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/dhcpsrv/cfg_mac_source.cc')
-rw-r--r--src/lib/dhcpsrv/cfg_mac_source.cc79
1 files changed, 58 insertions, 21 deletions
diff --git a/src/lib/dhcpsrv/cfg_mac_source.cc b/src/lib/dhcpsrv/cfg_mac_source.cc
index 4307d407c1..7a0db260b3 100644
--- a/src/lib/dhcpsrv/cfg_mac_source.cc
+++ b/src/lib/dhcpsrv/cfg_mac_source.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
+// 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
@@ -9,6 +9,32 @@
#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 {
@@ -19,26 +45,7 @@ CfgMACSource::CfgMACSource() {
}
uint32_t CfgMACSource::MACSourceFromText(const std::string& name) {
-
- 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 }
- };
-
- for (int i=0; i < sizeof(sources)/sizeof(sources[0]); ++i) {
+ for (unsigned i = 0; i < sizeof(sources)/sizeof(sources[0]); ++i) {
if (name.compare(sources[i].name) == 0) {
return (sources[i].type);
}
@@ -47,6 +54,36 @@ uint32_t CfgMACSource::MACSourceFromText(const std::string& name) {
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);
+}
};
};