option6_addrlst.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_ADDRLST_H_
  15. #define OPTION6_ADDRLST_H_
  16. #include <vector>
  17. #include <asiolink/io_address.h>
  18. #include <dhcp/option.h>
  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. ///
  34. Option6AddrLst(unsigned short type,
  35. const AddressContainer& addrs);
  36. /// @brief Simplified constructor for a single address
  37. ///
  38. /// @param type option type
  39. /// @param addr a single address to be stored
  40. ///
  41. Option6AddrLst(unsigned short type,
  42. const isc::asiolink::IOAddress& addr);
  43. /// @brief Constructor used for parsing received option
  44. ///
  45. /// @param type option type
  46. /// @param buf pointer to packet buffer
  47. /// @param buf_len length of packet buffer
  48. /// @param offset offset to beginning of option data
  49. /// @param len length of option data
  50. ///
  51. Option6AddrLst(unsigned short type, boost::shared_array<uint8_t> buf,
  52. unsigned int buf_len,
  53. unsigned int offset,
  54. unsigned int len);
  55. /// @brief Assembles on-wire form of this option
  56. ///
  57. /// @param buf pointer to packet buffer
  58. /// @param buf_len length of packet buffer
  59. /// @param offset offset to place, where option is to be stored
  60. ///
  61. /// @return offset to the next unused char (just after stored option)
  62. ///
  63. unsigned int
  64. pack(boost::shared_array<uint8_t>& buf, unsigned int buf_len,
  65. unsigned int offset);
  66. /// @brief Parses received data
  67. ///
  68. /// @param buf pointer to packet buffer
  69. /// @param buf_len length of packet buffer
  70. /// @param offset offset to option data
  71. /// @param parse_len specified option data length
  72. ///
  73. /// @return offset to the next unparsed char (just after parsed option)
  74. ///
  75. virtual unsigned int
  76. unpack(const boost::shared_array<uint8_t>& buf,
  77. unsigned int buf_len,
  78. unsigned int offset,
  79. unsigned int parse_len);
  80. virtual std::string toText(int indent = 0);
  81. /// @brief Sets a single address.
  82. ///
  83. /// @param addr a single address to be added
  84. ///
  85. void setAddress(const isc::asiolink::IOAddress& addr);
  86. /// @brief Sets list of addresses.
  87. ///
  88. /// @param addrs a vector of addresses to be added
  89. ///
  90. void setAddresses(const AddressContainer& addrs);
  91. /// @brief Returns vector with addresses.
  92. ///
  93. /// We return a copy of our list. Although this includes overhead,
  94. /// it also makes this list safe to use after this option object
  95. /// is no longer available. As options are expected to hold only
  96. /// a couple (1-3) addresses, the overhead is not that big.
  97. ///
  98. /// @return address container with addresses
  99. AddressContainer
  100. getAddresses() { return addrs_; };
  101. // returns data length (data length + DHCPv4/DHCPv6 option header)
  102. virtual uint16_t len();
  103. protected:
  104. AddressContainer addrs_;
  105. };
  106. } // isc::dhcp namespace
  107. } // isc namespace
  108. #endif /* OPTION_ADDRLST_H_ */