35 #include <tins/macros.h> 36 #include <tins/endianness.h> 37 #include <tins/small_uint.h> 38 #include <tins/ipv6_address.h> 39 #include <tins/pdu_option.h> 44 class OutputMemoryStream;
116 INFORMATION_REFRESH_TIME,
146 ERP_LOCAL_DOMAIN_NAME,
158 KRB_DEFAULT_REALM_NAME,
182 typedef std::vector<uint8_t> options_type;
185 options_type options;
187 ia_na_type(uint32_t
id = 0, uint32_t t1 = 0, uint32_t t2 = 0,
188 const options_type& options = options_type())
189 : id(
id), t1(t1), t2(t2), options(options) {}
191 static ia_na_type from_option(
const option& opt);
199 typedef std::vector<uint8_t> options_type;
202 options_type options;
205 const options_type& options = options_type())
206 : id(
id), options(options) {}
208 static ia_ta_type from_option(
const option& opt);
215 typedef std::vector<uint8_t> options_type;
217 ipaddress_type address;
218 uint32_t preferred_lifetime, valid_lifetime;
219 options_type options;
222 uint32_t preferred_lifetime = 0, uint32_t valid_lifetime = 0,
223 const options_type& options = options_type())
224 : address(address), preferred_lifetime(preferred_lifetime),
225 valid_lifetime(valid_lifetime), options(options) {}
234 typedef std::vector<uint8_t> auth_info_type;
236 uint8_t protocol, algorithm, rdm;
237 uint64_t replay_detection;
238 auth_info_type auth_info;
241 uint8_t rdm = 0, uint64_t replay_detection = 0,
242 const auth_info_type& auth_info = auth_info_type())
243 : protocol(protocol), algorithm(algorithm), rdm(rdm),
244 replay_detection(replay_detection), auth_info(auth_info) {}
257 : code(code), message(message) { }
266 typedef std::vector<uint8_t> data_type;
268 uint32_t enterprise_number;
272 const data_type& data = data_type())
273 : enterprise_number(enterprise_number), data(data) { }
289 typedef std::vector<class_option_data_type> data_type;
302 typedef std::vector<class_option_data_type> class_data_type;
304 uint32_t enterprise_number;
305 class_data_type vendor_class_data;
308 const class_data_type& vendor_class_data = class_data_type())
309 : enterprise_number(enterprise_number),
310 vendor_class_data(vendor_class_data) { }
320 static const uint16_t duid_id = 1;
321 typedef std::vector<uint8_t> lladdress_type;
325 lladdress_type lladdress;
327 duid_llt(uint16_t hw_type = 0, uint32_t time = 0,
328 const lladdress_type& lladdress = lladdress_type())
329 : hw_type(hw_type), time(time), lladdress(lladdress) {}
333 static duid_llt from_bytes(
const uint8_t* buffer, uint32_t total_sz);
340 static const uint16_t duid_id = 2;
341 typedef std::vector<uint8_t> identifier_type;
343 uint32_t enterprise_number;
344 identifier_type identifier;
346 duid_en(uint32_t enterprise_number = 0,
347 const identifier_type& identifier = identifier_type())
348 : enterprise_number(enterprise_number), identifier(identifier) {}
352 static duid_en from_bytes(
const uint8_t* buffer, uint32_t total_sz);
359 static const uint16_t duid_id = 3;
360 typedef std::vector<uint8_t> lladdress_type;
363 lladdress_type lladdress;
366 const lladdress_type& lladdress = lladdress_type())
367 : hw_type(hw_type), lladdress(lladdress) {}
371 static duid_ll from_bytes(
const uint8_t* buffer, uint32_t total_sz);
384 duid_type(uint16_t
id = 0,
const data_type& data = data_type())
385 : id(
id), data(data) {}
388 : id(duid_llt::duid_id), data(identifier.serialize()) {}
391 : id(duid_en::duid_id), data(identifier.serialize()) {}
394 : id(duid_ll::duid_id), data(identifier.serialize()) {}
396 static duid_type from_option(
const option& opt);
420 static metadata extract_metadata(
const uint8_t *buffer, uint32_t total_sz);
437 DHCPv6(
const uint8_t* buffer, uint32_t total_sz);
456 return header_data_[1];
465 return (header_data_[1] << 16) | (header_data_[2] << 8) | header_data_[3];
508 void hop_count(uint8_t count);
522 void peer_address(
const ipaddress_type& addr);
529 void link_address(
const ipaddress_type& addr);
565 option_request_type option_request()
const;
573 uint8_t preference()
const;
581 uint16_t elapsed_time()
const;
589 relay_msg_type relay_message()
const;
605 ipaddress_type server_unicast()
const;
621 bool has_rapid_commit()
const;
653 interface_id_type interface_id()
const;
661 uint8_t reconfigure_msg()
const;
669 bool has_reconfigure_accept()
const;
717 void option_request(
const option_request_type& value);
724 void preference(uint8_t value);
731 void elapsed_time(uint16_t value);
738 void relay_message(
const relay_msg_type& value);
752 void server_unicast(
const ipaddress_type& value);
792 void interface_id(
const interface_id_type& value);
799 void reconfigure_msg(uint8_t value);
804 void reconfigure_accept();
825 bool is_relay_message()
const;
835 void add_option(
const option& opt);
857 const option* search_option(
OptionTypes type)
const;
866 uint32_t header_size()
const;
875 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
892 void write_serialization(uint8_t* buffer, uint32_t total_sz);
893 void write_option(
const option& option, Memory::OutputMemoryStream& stream)
const;
894 options_type::const_iterator search_option_iterator(
OptionTypes type)
const;
895 options_type::iterator search_option_iterator(
OptionTypes type);
897 template <
template <
typename>
class Functor>
898 const option* safe_search_option(
OptionTypes opt, uint32_t size)
const {
899 const option* option = search_option(opt);
900 if (!option || Functor<uint32_t>()(option->
data_size(), size)) {
908 const option* option = search_option(opt);
912 return option->
to<T>();
915 uint8_t header_data_[4];
916 uint32_t options_size_;
917 ipaddress_type link_addr_, peer_addr_;
918 options_type options_;
923 #endif // TINS_DHCPV6_H PDUOption< uint16_t, DHCPv6 > option
Definition: dhcpv6.h:57
std::vector< option > options_type
Definition: dhcpv6.h:165
DHCPv6 * clone() const
Definition: dhcpv6.h:888
std::vector< uint16_t > option_request_type
Definition: dhcpv6.h:402
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
PDUType pdu_type() const
Getter for the PDU's type.
Definition: dhcpv6.h:881
const ipaddress_type & link_address() const
Getter for the link address field.
Definition: dhcpv6.h:482
std::vector< uint8_t > interface_id_type
Definition: dhcpv6.h:412
MessageType msg_type() const
Getter for the message type field.
Definition: dhcpv6.h:446
Represents a PDU option field.
Definition: pdu_option.h:201
small_uint< 24 > transaction_id() const
Getter for the transaction id field.
Definition: dhcpv6.h:464
IPv6Address ipaddress_type
Definition: dhcpv6.h:170
std::vector< uint8_t > class_option_data_type
Definition: dhcpv6.h:282
Represents a DHCPv6 PDU.
Definition: dhcpv6.h:52
The Tins namespace.
Definition: address_range.h:38
const options_type & options() const
Getter for the DHCPv6 options.
Definition: dhcpv6.h:491
T to() const
Constructs a T from this PDUOption.
Definition: pdu_option.h:389
uint8_t hop_count() const
Getter for the hop count field.
Definition: dhcpv6.h:455
const ipaddress_type & peer_address() const
Getter for the peer address field.
Definition: dhcpv6.h:473
Definition: ipv6_address.h:45
OptionTypes
Definition: dhcpv6.h:85
byte_array serialization_type
Definition: pdu.h:112
size_t data_size() const
Retrieves the length of this option's data.
Definition: pdu_option.h:361
Base class for protocol data units.
Definition: pdu.h:107
Exception thrown when an option is not found.
Definition: exceptions.h:56
MessageType
Definition: dhcpv6.h:62
std::vector< uint8_t > relay_msg_type
Definition: dhcpv6.h:407