cfg_mac_source.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef CFG_MAC_SOURCE_H
  15. #define CFG_MAC_SOURCE_H
  16. #include <stdint.h>
  17. #include <vector>
  18. #include <string>
  19. namespace isc {
  20. namespace dhcp {
  21. /// @brief Container for defined MAC/hardware address sources
  22. typedef std::vector<uint32_t> CfgMACSources;
  23. /// @brief Wrapper class that holds MAC/hardware address sources
  24. ///
  25. /// It's a simple wrapper around a vector of uint32_t, with each entry
  26. /// holding one MAC source.
  27. class CfgMACSource {
  28. public:
  29. /// @brief Default constructor.
  30. ///
  31. /// Sets source to 'any'.
  32. CfgMACSource();
  33. /// @brief Attempts to convert known hardware address sources to uint32_t
  34. ///
  35. /// Supported strings are: \li any => 0xffffffff
  36. /// \li raw => 0x00000001
  37. /// \li duid => 0x00000002
  38. /// \li ipv6-link-local 0x00000004
  39. /// \li client-link-addr-option, rfc6939 => 0x00000008
  40. /// \li remote-id, rfc4649 => 0x00000010
  41. /// \li subscriber-id, rfc4580 => 0x00000020
  42. /// \li docsis => 0x00000040
  43. ///
  44. /// For specific constants, see @ref isc::dhcp::HWAddr class.
  45. ///
  46. /// @throw BadValue if specified string is unknown
  47. /// @return bitmask version of a given method
  48. static uint32_t MACSourceFromText(const std::string& name);
  49. /// @brief Adds additional MAC/hardware address aquisition.
  50. ///
  51. /// @param source MAC source (see constants in Pkt::HWADDR_SOURCE_*)
  52. ///
  53. /// Specified source is being added to the mac_sources_ array.
  54. /// @todo implement add(string) version of this method.
  55. void add(uint32_t source) {
  56. mac_sources_.push_back(source);
  57. }
  58. /// @brief Provides access to the configure MAC/Hardware address sources.
  59. ///
  60. /// @note The const reference returned is only valid as long as the
  61. /// object that returned it.
  62. const CfgMACSources& get() const {
  63. return mac_sources_;
  64. }
  65. /// @brief Removes any configured MAC/Hardware address sources.
  66. void clear() {
  67. mac_sources_.clear();
  68. }
  69. protected:
  70. /// @brief Actual MAC sources storage
  71. CfgMACSources mac_sources_;
  72. };
  73. };
  74. };
  75. #endif