option6_iaaddr.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 Ctor, used for options constructed (during transmission).
  29. ///
  30. /// @param type option type
  31. /// @param addr reference to an address
  32. /// @param preferred address preferred lifetime (in seconds)
  33. /// @param valid address valid lifetime (in seconds)
  34. Option6IAAddr(uint16_t type, const isc::asiolink::IOAddress& addr,
  35. uint32_t preferred, uint32_t valid);
  36. /// @brief ctor, used for received options.
  37. ///
  38. /// @param type option type
  39. /// @param begin iterator to first byte of option data
  40. /// @param end iterator to end of option data (first byte after option end)
  41. Option6IAAddr(uint32_t type, OptionBuffer::const_iterator begin,
  42. OptionBuffer::const_iterator end);
  43. /// @brief Writes option in wire-format.
  44. ///
  45. /// Writes option in wire-format to buf, returns pointer to first unused
  46. /// byte after stored option.
  47. ///
  48. /// @param buf pointer to a buffer
  49. void pack(isc::util::OutputBuffer& buf);
  50. /// @brief Parses received buffer.
  51. ///
  52. /// @param begin iterator to first byte of option data
  53. /// @param end iterator to end of option data (first byte after option end)
  54. virtual void unpack(OptionBufferConstIter begin,
  55. OptionBufferConstIter end);
  56. /// Returns string representation of the option.
  57. ///
  58. /// @param indent number of spaces before printing text
  59. ///
  60. /// @return string with text representation.
  61. virtual std::string
  62. toText(int indent = 0);
  63. /// sets address in this option.
  64. ///
  65. /// @param addr address to be sent in this option
  66. void setAddress(const isc::asiolink::IOAddress& addr) { addr_ = addr; }
  67. /// Sets preferred lifetime (in seconds)
  68. ///
  69. /// @param pref address preferred lifetime (in seconds)
  70. ///
  71. void setPreferred(unsigned int pref) { preferred_=pref; }
  72. /// Sets valid lifetime (in seconds).
  73. ///
  74. /// @param valid address valid lifetime (in seconds)
  75. ///
  76. void setValid(unsigned int valid) { valid_=valid; }
  77. /// Returns address contained within this option.
  78. ///
  79. /// @return address
  80. isc::asiolink::IOAddress
  81. getAddress() const { return addr_; }
  82. /// Returns preferred lifetime of an address.
  83. ///
  84. /// @return preferred lifetime (in seconds)
  85. unsigned int
  86. getPreferred() const { return preferred_; }
  87. /// Returns valid lifetime of an address.
  88. ///
  89. /// @return valid lifetime (in seconds)
  90. unsigned int
  91. getValid() const { return valid_; }
  92. /// returns data length (data length + DHCPv4/DHCPv6 option header)
  93. virtual uint16_t len();
  94. protected:
  95. /// contains an IPv6 address
  96. isc::asiolink::IOAddress addr_;
  97. /// contains preferred-lifetime timer (in seconds)
  98. unsigned int preferred_;
  99. /// contains valid-lifetime timer (in seconds)
  100. unsigned int valid_;
  101. };
  102. } // isc::dhcp namespace
  103. } // isc namespace
  104. #endif // OPTION_IA_H