cfg_mac_source.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright (C) 2014-2015,2017 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. #ifndef CFG_MAC_SOURCE_H
  7. #define CFG_MAC_SOURCE_H
  8. #include <cc/cfg_to_element.h>
  9. #include <stdint.h>
  10. #include <vector>
  11. #include <string>
  12. namespace isc {
  13. namespace dhcp {
  14. /// @brief Container for defined MAC/hardware address sources
  15. typedef std::vector<uint32_t> CfgMACSources;
  16. /// @brief Wrapper class that holds MAC/hardware address sources
  17. ///
  18. /// It's a simple wrapper around a vector of uint32_t, with each entry
  19. /// holding one MAC source.
  20. class CfgMACSource : public isc::data::CfgToElement {
  21. public:
  22. /// @brief Default constructor.
  23. ///
  24. /// Sets source to 'any'.
  25. CfgMACSource();
  26. /// @brief Attempts to convert known hardware address sources to uint32_t
  27. ///
  28. /// Supported strings are: \li any => 0xffffffff
  29. /// \li raw => 0x00000001
  30. /// \li duid => 0x00000002
  31. /// \li ipv6-link-local 0x00000004
  32. /// \li client-link-addr-option, rfc6939 => 0x00000008
  33. /// \li remote-id, rfc4649 => 0x00000010
  34. /// \li subscriber-id, rfc4580 => 0x00000020
  35. /// \li docsis => 0x00000040
  36. ///
  37. /// For specific constants, see @ref isc::dhcp::HWAddr class.
  38. ///
  39. /// @throw BadValue if specified string is unknown
  40. /// @return bitmask version of a given method
  41. static uint32_t MACSourceFromText(const std::string& name);
  42. /// @brief Adds additional MAC/hardware address acquisition.
  43. ///
  44. /// @param source MAC source (see constants in Pkt::HWADDR_SOURCE_*)
  45. ///
  46. /// Specified source is being added to the mac_sources_ array.
  47. /// @throw InvalidParameter if such a source is already defined.
  48. void add(uint32_t source);
  49. /// @brief Provides access to the configure MAC/Hardware address sources.
  50. ///
  51. /// @note The const reference returned is only valid as long as the
  52. /// object that returned it.
  53. const CfgMACSources& get() const {
  54. return mac_sources_;
  55. }
  56. /// @brief Removes any configured MAC/Hardware address sources.
  57. void clear() {
  58. mac_sources_.clear();
  59. }
  60. /// @brief Unparse a configuration object
  61. ///
  62. /// @return a pointer to unparsed configuration
  63. virtual isc::data::ElementPtr toElement() const;
  64. protected:
  65. /// @brief Actual MAC sources storage
  66. CfgMACSources mac_sources_;
  67. };
  68. };
  69. };
  70. #endif