diff options
author | Tomek Mrugalski <tomasz@isc.org> | 2014-12-23 13:50:20 +0100 |
---|---|---|
committer | Tomek Mrugalski <tomasz@isc.org> | 2014-12-23 13:50:20 +0100 |
commit | 2662ac5f02d36a236c796ecb1174876c0d0cee5c (patch) | |
tree | 6dc2580abd63cea2d01a6e66668407ebdcb94e4a /src/lib/dhcpsrv/cfg_mac_source.cc | |
parent | [3554] MAC Sources description in the User's Guide clarified (diff) | |
download | kea-2662ac5f02d36a236c796ecb1174876c0d0cee5c.tar.xz kea-2662ac5f02d36a236c796ecb1174876c0d0cee5c.zip |
[3554] Changes after review:
- Moved MAC operations to a new CfgMACSource class
- Moved macros to HWaddr class
- Added several unit-tests for MAC sources
- MAC extraction code moved to separate function in Dhcpv6Srv
Diffstat (limited to 'src/lib/dhcpsrv/cfg_mac_source.cc')
-rw-r--r-- | src/lib/dhcpsrv/cfg_mac_source.cc | 59 |
1 files changed, 59 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 0000000000..715820bd07 --- /dev/null +++ b/src/lib/dhcpsrv/cfg_mac_source.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include <config.h> +#include <dhcpsrv/cfg_mac_source.h> +#include <exceptions/exceptions.h> +#include <dhcp/hwaddr.h> + +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) { + + 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", HWAddr::HWADDR_SOURCE_DOCSIS } + }; + + for (int 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."); +} + + +}; +}; |