option6_pdexclude.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright (C) 2016 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_PDEXCLUDE_H
  7. #define OPTION6_PDEXCLUDE_H
  8. #include <asiolink/io_address.h>
  9. #include <dhcp/option.h>
  10. #include <boost/shared_ptr.hpp>
  11. #include <stdint.h>
  12. namespace isc {
  13. namespace dhcp {
  14. /// @brief DHCPv6 option class representing Prefix Exclude Option (RFC 6603).
  15. ///
  16. /// This class represents DHCPv6 Prefix Exclude option (67). This option is
  17. /// carried in the IA Prefix option and it conveys a single prefix which is
  18. /// used by the delegating router to communicate with a requesting router on
  19. /// the requesting router's uplink. This prefix is not used on the
  20. /// requesting router's downlinks (is excluded from other delegated prefixes).
  21. class Option6PDExclude: public Option {
  22. public:
  23. /// @brief Constructor.
  24. ///
  25. /// @param delegated_prefix Delagated prefix.
  26. /// @param delegated_prefix_length Delegated prefix length.
  27. /// @param excluded_prefix Excluded prefix.
  28. /// @param excluded_prefix_length Excluded prefix length.
  29. ///
  30. /// @throw BadValue if prefixes are invalid, if excluded prefix length
  31. /// is not greater than delegated prefix length or if common parts of
  32. /// prefixes does not match.
  33. Option6PDExclude(const isc::asiolink::IOAddress& delegated_prefix,
  34. const uint8_t delegated_prefix_length,
  35. const isc::asiolink::IOAddress& excluded_prefix,
  36. const uint8_t excluded_prefix_length);
  37. /// @brief Constructor, creates option instance from part of the buffer.
  38. ///
  39. /// This constructor is mostly used to parse Prefix Exclude options in the
  40. /// received messages.
  41. ///
  42. /// @param begin Lower bound of the buffer to create option from.
  43. /// @param end Upper bound of the buffer to create option from.
  44. Option6PDExclude(const isc::asiolink::IOAddress& delegated_prefix,
  45. const uint8_t delegated_prefix_length,
  46. OptionBufferConstIter begin, OptionBufferConstIter end);
  47. /// @brief Copies this option and returns a pointer to the copy.
  48. virtual OptionPtr clone() const;
  49. /// @brief Writes option in wire-format to a buffer.
  50. ///
  51. /// Writes option in wire-format to buffer, returns pointer to first unused
  52. /// byte after stored option (that is useful for writing options one after
  53. /// another).
  54. ///
  55. /// The format of the option includes excluded prefix length specified as
  56. /// a number of bits. It also includes IPv6 subnet ID field which is
  57. /// computed from the delegated and excluded prefixes, according to the
  58. /// section 4.2 of RFC 6603.
  59. ///
  60. /// @param [out] buf Pointer to a buffer.
  61. virtual void pack(isc::util::OutputBuffer& buf) const;
  62. /// @brief Parses received buffer.
  63. ///
  64. /// @param begin iterator to first byte of option data
  65. /// @param end iterator to end of option data (first byte after option end)
  66. virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end);
  67. /// @brief Returns length of the complete option (data length + DHCPv6
  68. /// option header)
  69. ///
  70. /// @return length of the option
  71. virtual uint16_t len() const;
  72. /// @brief Returns Prefix Exclude option in textual format.
  73. ///
  74. /// @param ident Number of spaces to be inserted before the text.
  75. virtual std::string toText(int indent = 0) const;
  76. /// @brief Returns delegated prefix.
  77. isc::asiolink::IOAddress getDelegatedPrefix() const {
  78. return (delegated_prefix_);
  79. }
  80. /// @brief Returns delegated prefix length.
  81. uint8_t getDelegatedPrefixLength() const {
  82. return (delegated_prefix_length_);
  83. }
  84. /// @brief Returns excluded prefix.
  85. isc::asiolink::IOAddress getExcludedPrefix() const {
  86. return (excluded_prefix_);
  87. }
  88. /// @brief Returns excluded prefix length.
  89. uint8_t getExcludedPrefixLength() const {
  90. return (excluded_prefix_length_);
  91. }
  92. private:
  93. /// @brief Returns IPv6 subnet ID length in octets.
  94. ///
  95. /// The IPv6 subnet ID length is between 1 and 16 octets.
  96. uint8_t getSubnetIDLength() const;
  97. /// @brief Holds delegated prefix.
  98. isc::asiolink::IOAddress delegated_prefix_;
  99. /// @brief Holds delegated prefix length,
  100. uint8_t delegated_prefix_length_;
  101. /// @brief Holds excluded prefix.
  102. isc::asiolink::IOAddress excluded_prefix_;
  103. /// @brief Holds excluded prefix length.
  104. uint8_t excluded_prefix_length_;
  105. };
  106. /// @brief Pointer to the @ref Option6PDExclude object.
  107. typedef boost::shared_ptr<Option6PDExclude> Option6PDExcludePtr;
  108. } // isc::dhcp namespace
  109. } // isc namespace
  110. #endif // OPTION6_PDEXCLUDE_H