/src/kea/src/lib/dhcp/option6_iaaddr.h
Line | Count | Source |
1 | | // Copyright (C) 2011-2022 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_IAADDR_H |
8 | | #define OPTION6_IAADDR_H |
9 | | |
10 | | #include <asiolink/io_address.h> |
11 | | #include <dhcp/option.h> |
12 | | #include <boost/shared_ptr.hpp> |
13 | | |
14 | | namespace isc { |
15 | | namespace dhcp { |
16 | | |
17 | | class Option6IAAddr; |
18 | | |
19 | | /// A pointer to the @c isc::dhcp::Option6IAAddr object. |
20 | | typedef boost::shared_ptr<Option6IAAddr> Option6IAAddrPtr; |
21 | | |
22 | | class Option6IAAddr: public Option { |
23 | | |
24 | | public: |
25 | | /// length of the fixed part of the IAADDR option |
26 | | static const size_t OPTION6_IAADDR_LEN = 24; |
27 | | |
28 | | /// @brief Constructor, used for options constructed (during transmission). |
29 | | /// |
30 | | /// @throw BadValue if specified addr is not IPv6 |
31 | | /// |
32 | | /// @param type option type |
33 | | /// @param addr reference to an address |
34 | | /// @param preferred address preferred lifetime (in seconds) |
35 | | /// @param valid address valid lifetime (in seconds) |
36 | | Option6IAAddr(uint16_t type, const isc::asiolink::IOAddress& addr, |
37 | | uint32_t preferred, uint32_t valid); |
38 | | |
39 | | /// @brief Constructor, used for received options. |
40 | | /// |
41 | | /// @throw OutOfRange if specified option is truncated |
42 | | /// |
43 | | /// @param type option type |
44 | | /// @param begin iterator to first byte of option data |
45 | | /// @param end iterator to end of option data (first byte after option end) |
46 | | Option6IAAddr(uint32_t type, OptionBuffer::const_iterator begin, |
47 | | OptionBuffer::const_iterator end); |
48 | | |
49 | | /// @brief Copies this option and returns a pointer to the copy. |
50 | | virtual OptionPtr clone() const; |
51 | | |
52 | | /// @brief Writes option in wire-format. |
53 | | /// |
54 | | /// Writes option in wire-format to buf, returns pointer to first unused |
55 | | /// byte after stored option. |
56 | | /// |
57 | | /// @param buf pointer to a buffer |
58 | | /// @param check if set to false, allows options larger than 255 for v4 |
59 | | void pack(isc::util::OutputBuffer& buf, bool check = true) const; |
60 | | |
61 | | /// @brief Parses received buffer. |
62 | | /// |
63 | | /// @param begin iterator to first byte of option data |
64 | | /// @param end iterator to end of option data (first byte after option end) |
65 | | virtual void unpack(OptionBufferConstIter begin, |
66 | | OptionBufferConstIter end); |
67 | | |
68 | | /// Returns string representation of the option. |
69 | | /// |
70 | | /// @param indent number of spaces before printing text |
71 | | /// |
72 | | /// @return string with text representation. |
73 | | virtual std::string |
74 | | toText(int indent = 0) const; |
75 | | |
76 | | |
77 | | /// sets address in this option. |
78 | | /// |
79 | | /// @param addr address to be sent in this option |
80 | 0 | void setAddress(const isc::asiolink::IOAddress& addr) { addr_ = addr; } |
81 | | |
82 | | /// Sets preferred lifetime (in seconds) |
83 | | /// |
84 | | /// @param pref address preferred lifetime (in seconds) |
85 | | /// |
86 | 0 | void setPreferred(unsigned int pref) { preferred_=pref; } |
87 | | |
88 | | /// Sets valid lifetime (in seconds). |
89 | | /// |
90 | | /// @param valid address valid lifetime (in seconds) |
91 | | /// |
92 | 0 | void setValid(unsigned int valid) { valid_=valid; } |
93 | | |
94 | | /// Returns address contained within this option. |
95 | | /// |
96 | | /// @return address |
97 | | isc::asiolink::IOAddress |
98 | 0 | getAddress() const { return addr_; } |
99 | | |
100 | | /// Returns preferred lifetime of an address. |
101 | | /// |
102 | | /// @return preferred lifetime (in seconds) |
103 | | unsigned int |
104 | 0 | getPreferred() const { return preferred_; } |
105 | | |
106 | | /// Returns valid lifetime of an address. |
107 | | /// |
108 | | /// @return valid lifetime (in seconds) |
109 | | unsigned int |
110 | 0 | getValid() const { return valid_; } |
111 | | |
112 | | /// returns data length (data length + DHCPv4/DHCPv6 option header) |
113 | | virtual uint16_t len() const; |
114 | | |
115 | | protected: |
116 | | /// contains an IPv6 address |
117 | | isc::asiolink::IOAddress addr_; |
118 | | |
119 | | /// contains preferred-lifetime timer (in seconds) |
120 | | unsigned int preferred_; |
121 | | |
122 | | /// contains valid-lifetime timer (in seconds) |
123 | | unsigned int valid_; |
124 | | }; |
125 | | |
126 | | } // isc::dhcp namespace |
127 | | } // isc namespace |
128 | | |
129 | | #endif // OPTION_IA_H |