cfg_mac_source.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <dhcpsrv/cfg_mac_source.h>
  8. #include <exceptions/exceptions.h>
  9. #include <dhcp/hwaddr.h>
  10. namespace isc {
  11. namespace dhcp {
  12. CfgMACSource::CfgMACSource() {
  13. // By default, use any hardware source that is available.
  14. mac_sources_.push_back(HWAddr::HWADDR_SOURCE_ANY);
  15. }
  16. uint32_t CfgMACSource::MACSourceFromText(const std::string& name) {
  17. struct {
  18. const char * name;
  19. uint32_t type;
  20. } sources[] = {
  21. { "any", HWAddr::HWADDR_SOURCE_ANY },
  22. { "raw", HWAddr::HWADDR_SOURCE_RAW },
  23. { "duid", HWAddr::HWADDR_SOURCE_DUID },
  24. { "ipv6-link-local", HWAddr::HWADDR_SOURCE_IPV6_LINK_LOCAL },
  25. { "client-link-addr-option", HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION },
  26. { "rfc6939", HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION },
  27. { "remote-id", HWAddr::HWADDR_SOURCE_REMOTE_ID },
  28. { "rfc4649", HWAddr::HWADDR_SOURCE_REMOTE_ID },
  29. { "subscriber-id", HWAddr::HWADDR_SOURCE_SUBSCRIBER_ID },
  30. { "rfc4580", HWAddr::HWADDR_SOURCE_SUBSCRIBER_ID },
  31. { "docsis-cmts", HWAddr::HWADDR_SOURCE_DOCSIS_CMTS },
  32. { "docsis-modem", HWAddr::HWADDR_SOURCE_DOCSIS_MODEM }
  33. };
  34. for (int i=0; i < sizeof(sources)/sizeof(sources[0]); ++i) {
  35. if (name.compare(sources[i].name) == 0) {
  36. return (sources[i].type);
  37. }
  38. }
  39. isc_throw(BadValue, "Can't convert '" << name << "' to any known MAC source.");
  40. }
  41. };
  42. };