option6_addrlst.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright (C) 2011-2012, 2014 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_ADDRLST_H
  15. #define OPTION6_ADDRLST_H
  16. #include <asiolink/io_address.h>
  17. #include <dhcp/option.h>
  18. #include <boost/shared_ptr.hpp>
  19. #include <vector>
  20. namespace isc {
  21. namespace dhcp {
  22. /// @brief DHCPv6 Option class for handling list of IPv6 addresses.
  23. ///
  24. /// This class handles a list of IPv6 addresses. An example of such option
  25. /// is dns-servers option. It can also be used to handle single address.
  26. class Option6AddrLst: public Option {
  27. public:
  28. /// a container for (IPv6) addresses
  29. typedef std::vector<isc::asiolink::IOAddress> AddressContainer;
  30. /// @brief Constructor used during option generation.
  31. ///
  32. /// @param type option type
  33. /// @param addrs vector of addresses to be stored
  34. Option6AddrLst(uint16_t type, const AddressContainer& addrs);
  35. /// @brief Simplified constructor for a single address
  36. ///
  37. /// @param type option type
  38. /// @param addr a single address to be stored
  39. Option6AddrLst(uint16_t type, const isc::asiolink::IOAddress& addr);
  40. /// @brief Constructor used for parsing received option
  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. Option6AddrLst(uint16_t type, OptionBufferConstIter begin,
  46. OptionBufferConstIter end);
  47. /// @brief Assembles on-wire form of this option
  48. ///
  49. /// @param buf pointer to packet buffer
  50. void pack(isc::util::OutputBuffer& buf);
  51. /// @brief Parses received data
  52. ///
  53. /// @param begin iterator to first byte of option data
  54. /// @param end iterator to end of option data (first byte after option end)
  55. virtual void unpack(OptionBufferConstIter begin,
  56. OptionBufferConstIter end);
  57. virtual std::string toText(int indent = 0);
  58. /// @brief Sets a single address.
  59. ///
  60. /// @param addr a single address to be added
  61. void setAddress(const isc::asiolink::IOAddress& addr);
  62. /// @brief Sets list of addresses.
  63. ///
  64. /// @param addrs a vector of addresses to be added
  65. void setAddresses(const AddressContainer& addrs);
  66. /// @brief Returns vector with addresses.
  67. ///
  68. /// We return a copy of our list. Although this includes overhead,
  69. /// it also makes this list safe to use after this option object
  70. /// is no longer available. As options are expected to hold only
  71. /// a few (1-3) addresses, the overhead is not that big.
  72. ///
  73. /// @return address container with addresses
  74. AddressContainer getAddresses() const { return addrs_; };
  75. // returns data length (data length + DHCPv4/DHCPv6 option header)
  76. virtual uint16_t len();
  77. protected:
  78. AddressContainer addrs_;
  79. };
  80. /// @brief Pointer to the @c Option6AddrLst object.
  81. typedef boost::shared_ptr<Option6AddrLst> Option6AddrLstPtr;
  82. } // isc::dhcp namespace
  83. } // isc namespace
  84. #endif // OPTION_ADDRLST_H