cfg_duid.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Copyright (C) 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. #ifndef CFG_DUID_H
  7. #define CFG_DUID_H
  8. #include <dhcp/duid.h>
  9. #include <boost/shared_ptr.hpp>
  10. #include <stdint.h>
  11. #include <vector>
  12. namespace isc {
  13. namespace dhcp {
  14. /// @brief Holds manual configuration of the server identifier (DUID).
  15. ///
  16. /// The DHCPv6 server uses DHCPv6 Unique Identifier (DUID) to identify itself
  17. /// to the clients. Typically, the server generates the DUID on the first
  18. /// startup and writes it to the persistent storage so as it doesn't change
  19. /// across restarts of the server. RFC3315 and RFC6355 define different DUID
  20. /// types. Kea allows for selecting a type of DUID that the server should
  21. /// generate. It also allows for overriding entire default DUID or parts of
  22. /// it via configuration file. This class holds the DUID configuration
  23. /// specified in the server configuration file.
  24. class CfgDUID {
  25. public:
  26. /// @brief Constructor.
  27. CfgDUID();
  28. /// @brief Returns DUID type.
  29. DUID::DUIDType getType() const {
  30. return (type_);
  31. }
  32. /// @brief Sets DUID type.
  33. void setType(const DUID::DUIDType& type) {
  34. type_ = type;
  35. }
  36. /// @brief Returns identifier.
  37. ///
  38. /// Identifier is a link layer address for the DUID-LLT and DUID-LL. It
  39. /// is also a variable length identifier in DUID-EN. It may be used for
  40. /// all other existing and future DUID types when there is a need to
  41. /// represent some variable length identifier.
  42. ///
  43. /// @return Vector holding an identifier belonging to a particular
  44. /// DUID type.
  45. std::vector<uint8_t> getIdentifier() const {
  46. return (identifier_);
  47. }
  48. /// @brief Sets new identifier as hex string.
  49. ///
  50. /// @param identifier_as_hex String of hexadecimal digits representing
  51. /// variable length identifier within a DUID.
  52. void setIdentifier(const std::string& identifier_as_hex);
  53. /// @brief Returns hardware type for DUID-LLT and DUID-LL.
  54. uint16_t getHType() const {
  55. return (htype_);
  56. }
  57. /// @brief Sets new hardware type for DUID-LLT and DUID-LL.
  58. void setHType(const uint16_t htype) {
  59. htype_ = htype;
  60. }
  61. /// @brief Returns time for the DUID-LLT.
  62. uint32_t getTime() const {
  63. return (time_);
  64. }
  65. /// @brief Sets new time for DUID-LLT.
  66. void setTime(const uint32_t new_time) {
  67. time_ = new_time;
  68. }
  69. /// @brief Returns enterprise id for the DUID-EN.
  70. uint32_t getEnterpriseId() const {
  71. return (enterprise_id_);
  72. }
  73. /// @brief Sets new enterprise id.
  74. ///
  75. /// @param enterprise_id New enterprise id.
  76. void setEnterpriseId(const uint32_t enterprise_id) {
  77. enterprise_id_ = enterprise_id;
  78. }
  79. /// @brief Checks if server identifier should be stored on disk.
  80. ///
  81. /// @return true if the server identifier should be stored on
  82. /// the disk, false otherwise.
  83. bool persist() const {
  84. return (persist_);
  85. }
  86. /// @brief Sets a boolean flag indicating if the server identifier
  87. /// should be stored on the disk (if true) or not (if false).
  88. ///
  89. /// @param persist New value of the flag.
  90. void setPersist(const bool persist) {
  91. persist_ = persist;
  92. }
  93. /// @brief Creates instance of a DUID from the current configuration.
  94. ///
  95. /// @param duid_file_path Absolute path to a DUID file.
  96. /// @return Pointer to an instance of new DUID.
  97. DuidPtr create(const std::string& duid_file_path) const;
  98. private:
  99. /// @brief DUID type.
  100. DUID::DUIDType type_;
  101. /// @brief Variable length identifier in a DUID.
  102. std::vector<uint8_t> identifier_;
  103. /// @brief Hardware type.
  104. uint16_t htype_;
  105. /// @brief Time used for DUID-LLT.
  106. uint32_t time_;
  107. /// @brief Enterprise id used for DUID-EN.
  108. uint32_t enterprise_id_;
  109. /// @brief Boolean flag which indicates if server identifier should
  110. /// be stored on the disk.
  111. bool persist_;
  112. };
  113. /// @name Pointers to the @c CfgDUID objects.
  114. //@{
  115. /// @brief Pointer to the Non-const object.
  116. typedef boost::shared_ptr<CfgDUID> CfgDUIDPtr;
  117. /// @brief Pointer to the const object.
  118. typedef boost::shared_ptr<const CfgDUID> ConstCfgDUIDPtr;
  119. //@}
  120. }
  121. }
  122. #endif // CFG_DUID_H