option6_iaaddr.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (C) 2011-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 OPTION6_IAADDR_H
  7. #define OPTION6_IAADDR_H
  8. #include <asiolink/io_address.h>
  9. #include <dhcp/option.h>
  10. #include <boost/shared_ptr.hpp>
  11. namespace isc {
  12. namespace dhcp {
  13. class Option6IAAddr;
  14. /// A pointer to the @c isc::dhcp::Option6IAAddr object.
  15. typedef boost::shared_ptr<Option6IAAddr> Option6IAAddrPtr;
  16. class Option6IAAddr: public Option {
  17. public:
  18. /// length of the fixed part of the IAADDR option
  19. static const size_t OPTION6_IAADDR_LEN = 24;
  20. /// @brief Constructor, used for options constructed (during transmission).
  21. ///
  22. /// @throw BadValue if specified addr is not IPv6
  23. ///
  24. /// @param type option type
  25. /// @param addr reference to an address
  26. /// @param preferred address preferred lifetime (in seconds)
  27. /// @param valid address valid lifetime (in seconds)
  28. Option6IAAddr(uint16_t type, const isc::asiolink::IOAddress& addr,
  29. uint32_t preferred, uint32_t valid);
  30. /// @brief Constructor, used for received options.
  31. ///
  32. /// @throw OutOfRange if specified option is truncated
  33. ///
  34. /// @param type option type
  35. /// @param begin iterator to first byte of option data
  36. /// @param end iterator to end of option data (first byte after option end)
  37. Option6IAAddr(uint32_t type, OptionBuffer::const_iterator begin,
  38. OptionBuffer::const_iterator end);
  39. /// @brief Writes option in wire-format.
  40. ///
  41. /// Writes option in wire-format to buf, returns pointer to first unused
  42. /// byte after stored option.
  43. ///
  44. /// @param buf pointer to a buffer
  45. void pack(isc::util::OutputBuffer& buf);
  46. /// @brief Parses received buffer.
  47. ///
  48. /// @param begin iterator to first byte of option data
  49. /// @param end iterator to end of option data (first byte after option end)
  50. virtual void unpack(OptionBufferConstIter begin,
  51. OptionBufferConstIter end);
  52. /// Returns string representation of the option.
  53. ///
  54. /// @param indent number of spaces before printing text
  55. ///
  56. /// @return string with text representation.
  57. virtual std::string
  58. toText(int indent = 0);
  59. /// sets address in this option.
  60. ///
  61. /// @param addr address to be sent in this option
  62. void setAddress(const isc::asiolink::IOAddress& addr) { addr_ = addr; }
  63. /// Sets preferred lifetime (in seconds)
  64. ///
  65. /// @param pref address preferred lifetime (in seconds)
  66. ///
  67. void setPreferred(unsigned int pref) { preferred_=pref; }
  68. /// Sets valid lifetime (in seconds).
  69. ///
  70. /// @param valid address valid lifetime (in seconds)
  71. ///
  72. void setValid(unsigned int valid) { valid_=valid; }
  73. /// Returns address contained within this option.
  74. ///
  75. /// @return address
  76. isc::asiolink::IOAddress
  77. getAddress() const { return addr_; }
  78. /// Returns preferred lifetime of an address.
  79. ///
  80. /// @return preferred lifetime (in seconds)
  81. unsigned int
  82. getPreferred() const { return preferred_; }
  83. /// Returns valid lifetime of an address.
  84. ///
  85. /// @return valid lifetime (in seconds)
  86. unsigned int
  87. getValid() const { return valid_; }
  88. /// returns data length (data length + DHCPv4/DHCPv6 option header)
  89. virtual uint16_t len();
  90. protected:
  91. /// contains an IPv6 address
  92. isc::asiolink::IOAddress addr_;
  93. /// contains preferred-lifetime timer (in seconds)
  94. unsigned int preferred_;
  95. /// contains valid-lifetime timer (in seconds)
  96. unsigned int valid_;
  97. };
  98. } // isc::dhcp namespace
  99. } // isc namespace
  100. #endif // OPTION_IA_H