option6_iaaddr.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright (C) 2011 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. namespace isc {
  19. namespace dhcp {
  20. class Option6IAAddr: public Option {
  21. public:
  22. /// length of the fixed part of the IAADDR option
  23. static const size_t OPTION6_IAADDR_LEN = 24;
  24. /// @brief ctor, used for options constructed (during transmission)
  25. ///
  26. /// @param type option type
  27. /// @param addr reference to an address
  28. /// @param preferred address preferred lifetime (in seconds)
  29. /// @param valid address valid lifetime (in seconds)
  30. Option6IAAddr(unsigned short type, const isc::asiolink::IOAddress& addr,
  31. unsigned int preferred, unsigned int valid);
  32. /// ctor, used for received options
  33. /// boost::shared_array allows sharing a buffer, but it requires that
  34. /// different instances share pointer to the whole array, not point
  35. /// to different elements in shared array. Therefore we need to share
  36. /// pointer to the whole array and remember offset where data for
  37. /// this option begins
  38. ///
  39. /// @param type option type
  40. /// @param buf pointer to a buffer
  41. /// @param offset offset to first data byte in that buffer
  42. /// @param len data length of this option
  43. Option6IAAddr(unsigned short type, boost::shared_array<uint8_t> buf,
  44. unsigned int buf_len, unsigned int offset, unsigned int len);
  45. /// @brief Writes option in wire-format.
  46. ///
  47. /// Writes option in wire-format to buf, returns pointer to first unused
  48. /// byte after stored option.
  49. ///
  50. /// @param buf pointer to a buffer
  51. /// @param buf_len length of the buffer
  52. /// @param offset offset to place, where option shout be stored
  53. ///
  54. /// @return offset to first unused byte after stored option
  55. unsigned int
  56. pack(boost::shared_array<uint8_t>& buf, unsigned int buf_len,
  57. unsigned int offset);
  58. /// @brief Parses buffer.
  59. ///
  60. /// Parses received buffer, returns offset to the first unused byte after
  61. /// parsed option.
  62. ///
  63. /// @param buf pointer to buffer
  64. /// @param buf_len length of buf
  65. /// @param offset offset, where start parsing option
  66. /// @param parse_len how many bytes should be parsed
  67. ///
  68. /// @return offset after last parsed octet
  69. virtual unsigned int
  70. unpack(const boost::shared_array<uint8_t>& buf,
  71. unsigned int buf_len,
  72. unsigned int offset,
  73. unsigned int parse_len);
  74. /// Returns string representation of the option.
  75. ///
  76. /// @param indent number of spaces before printing text
  77. ///
  78. /// @return string with text representation.
  79. virtual std::string
  80. toText(int indent = 0);
  81. /// sets address in this option.
  82. ///
  83. /// @param addr address to be sent in this option
  84. void setAddress(const isc::asiolink::IOAddress& addr) { addr_ = addr; }
  85. /// Sets preferred lifetime (in seconds)
  86. ///
  87. /// @param pref address preferred lifetime (in seconds)
  88. ///
  89. void setPreferred(unsigned int pref) { preferred_=pref; }
  90. /// Sets valid lifetime (in seconds).
  91. ///
  92. /// @param valid address valid lifetime (in seconds)
  93. ///
  94. void setValid(unsigned int valid) { valid_=valid; }
  95. /// Returns address contained within this option.
  96. ///
  97. /// @return address
  98. isc::asiolink::IOAddress
  99. getAddress() { return addr_; }
  100. /// Returns preferred lifetime of an address.
  101. ///
  102. /// @return preferred lifetime (in seconds)
  103. unsigned int
  104. getPreferred() { return preferred_; }
  105. /// Returns valid lifetime of an address.
  106. ///
  107. /// @return valid lifetime (in seconds)
  108. unsigned int
  109. getValid() { return valid_; }
  110. /// returns data length (data length + DHCPv4/DHCPv6 option header)
  111. virtual unsigned short
  112. len();
  113. protected:
  114. /// contains an IPv6 address
  115. isc::asiolink::IOAddress addr_;
  116. /// contains preferred-lifetime timer (in seconds)
  117. unsigned int preferred_;
  118. /// contains valid-lifetime timer (in seconds)
  119. unsigned int valid_;
  120. };
  121. } // isc::dhcp namespace
  122. } // isc namespace
  123. #endif /* OPTION_IA_H_ */