option6_iaaddr.h 4.3 KB

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