option6_iaprefix.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright (C) 2013 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_IAPREFIX_H
  15. #define OPTION6_IAPREFIX_H
  16. #include <asiolink/io_address.h>
  17. #include <dhcp/option6_iaaddr.h>
  18. #include <dhcp/option.h>
  19. namespace isc {
  20. namespace dhcp {
  21. /// @brief Class that represents IAPREFIX option in DHCPv6
  22. ///
  23. /// It is based on a similar class that handles addresses. There are major
  24. /// differences, though. The fields are in different order. There is also
  25. /// additional prefix length field.
  26. ///
  27. /// It should be noted that to get a full prefix (2 values: base prefix, and
  28. /// a prefix length) 2 methods are used: getAddress() and getLength(). Although
  29. /// using getAddress() to obtain base prefix is somewhat counter-intuitive at
  30. /// first, it becomes obvious when one realizes that an address is a special
  31. /// case of a prefix with /128. It makes everyone's like much easier, because
  32. /// the base prefix doubles as a regular address in many cases, e.g. when
  33. /// searching for a lease.
  34. class Option6IAPrefix : public Option6IAAddr {
  35. public:
  36. /// length of the fixed part of the IAPREFIX option
  37. static const size_t OPTION6_IAPREFIX_LEN = 25;
  38. /// @brief Constructor, used for options constructed (during transmission).
  39. ///
  40. /// @param type option type
  41. /// @param addr reference to an address
  42. /// @param prefix_length length (1-128)
  43. /// @param preferred address preferred lifetime (in seconds)
  44. /// @param valid address valid lifetime (in seconds)
  45. Option6IAPrefix(uint16_t type, const isc::asiolink::IOAddress& addr,
  46. uint8_t prefix_length, uint32_t preferred, uint32_t valid);
  47. /// @brief Constructor, used for received options.
  48. ///
  49. /// @throw OutOfRange if buffer is too short
  50. ///
  51. /// @param type option type
  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. Option6IAPrefix(uint32_t type, OptionBuffer::const_iterator begin,
  55. OptionBuffer::const_iterator end);
  56. /// @brief Writes option in wire-format.
  57. ///
  58. /// Writes option in wire-format to buf, returns pointer to first unused
  59. /// byte after stored option.
  60. ///
  61. /// @throw BadValue if the address is not IPv6
  62. ///
  63. /// @param buf pointer to a buffer
  64. void pack(isc::util::OutputBuffer& buf);
  65. /// @brief Parses received buffer.
  66. ///
  67. /// @throw OutOfRange when buffer is shorter than 25 bytes
  68. ///
  69. /// @param begin iterator to first byte of option data
  70. /// @param end iterator to end of option data (first byte after option end)
  71. virtual void unpack(OptionBufferConstIter begin,
  72. OptionBufferConstIter end);
  73. /// Returns string representation of the option.
  74. ///
  75. /// @param indent number of spaces before printing text
  76. ///
  77. /// @return string with text representation.
  78. virtual std::string toText(int indent = 0);
  79. /// sets address in this option.
  80. ///
  81. /// @param prefix prefix to be sent in this option
  82. /// @param length prefix length
  83. void setPrefix(const isc::asiolink::IOAddress& prefix,
  84. uint8_t length) { addr_ = prefix; prefix_len_ = length; }
  85. uint8_t getLength() const { return prefix_len_; }
  86. /// returns data length (data length + DHCPv4/DHCPv6 option header)
  87. virtual uint16_t len();
  88. protected:
  89. uint8_t prefix_len_;
  90. };
  91. } // isc::dhcp namespace
  92. } // isc namespace
  93. #endif // OPTION_IA_H