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