option6_addrlst.h 3.5 KB

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