35#include <tins/macros.h>
37#include <tins/ipv6_address.h>
38#include <tins/pdu_option.h>
39#include <tins/endianness.h>
40#include <tins/small_uint.h>
41#include <tins/hw_address.h>
42#include <tins/small_uint.h>
43#include <tins/icmp_extension.h>
44#include <tins/cxxstd.h>
49class InputMemoryStream;
50class OutputMemoryStream;
80 NEIGHBOUR_SOLICIT = 135,
81 NEIGHBOUR_ADVERT = 136,
83 ROUTER_RENUMBER = 138,
89 MOBILE_PREFIX_SOLICIT = 146,
90 MOBILE_PREFIX_ADVERT = 147,
91 CERT_PATH_SOLICIT = 148,
92 CERT_PATH_ADVERT = 149,
93 MULTICAST_ROUTER_ADVERT = 151,
94 MULTICAST_ROUTER_SOLICIT = 152,
95 MULTICAST_ROUTER_TERMINATE = 153,
96 RPL_CONTROL_MSG = 155,
97 EXTENDED_ECHO_REQUEST = 160,
98 EXTENDED_ECHO_REPLY = 161
131 HANDOVER_ASSIST_INFO,
137 AUTHORITATIVE_BORDER_ROUTER,
172 typedef std::vector<ipaddress_type> addresses_type;
175 addresses_type addresses;
177 addr_list_type(
const addresses_type& addresses = addresses_type())
178 : addresses(addresses) {
179 std::fill(reserved, reserved +
sizeof(reserved),
static_cast<uint8_t
>(0));
200 uint8_t code, status;
203 naack_type(uint8_t code = 0, uint8_t status = 0)
204 : code(code), status(status) {
205 std::fill(reserved, reserved + 4,
static_cast<uint8_t
>(0));
215 typedef std::vector<uint8_t> address_type;
218 address_type address;
227 const address_type& address = address_type())
228 : option_code(option_code), address(address) {
242 : option_code(option_code), address(address.begin(), address.end()) {
255 uint32_t valid_lifetime,
263 uint32_t valid_lifetime = 0,
264 uint32_t preferred_lifetime = 0,
266 : prefix_len(prefix_len), A(A), L(L), valid_lifetime(valid_lifetime),
267 preferred_lifetime(preferred_lifetime), reserved2(0), prefix(prefix) { }
276 typedef std::vector<uint8_t> signature_type;
278 uint8_t key_hash[16];
279 signature_type signature;
299 template <
typename RAIterator,
typename ForwardIterator>
301 : signature(start, end) {
302 std::copy(hash, hash +
sizeof(key_hash), key_hash);
317 template <
typename RAIterator>
320 std::copy(hash, hash +
sizeof(key_hash), key_hash);
329 std::fill(key_hash, key_hash +
sizeof(key_hash),
static_cast<uint8_t
>(0));
339 uint8_t option_code, prefix_len;
343 uint8_t prefix_len = 0,
345 : option_code(option_code), prefix_len(prefix_len), address(address)
357 uint32_t valid_lifetime;
363 uint32_t valid_lifetime = 0,
365 : dist(dist), pref(pref), r(r), valid_lifetime(valid_lifetime),
375 typedef std::vector<uint8_t> prefix_type;
379 uint32_t route_lifetime;
384 uint32_t route_lifetime = 0,
385 const prefix_type& prefix = prefix_type())
386 : prefix_len(prefix_len), pref(pref), route_lifetime(route_lifetime),
396 typedef std::vector<ipaddress_type> servers_type;
399 servers_type servers;
402 const servers_type& servers = servers_type())
403 : lifetime(lifetime), servers(servers) {}
412 typedef std::vector<uint8_t> key_type;
418 const key_type& key = key_type())
419 : AT(AT), key(key) { }
432 const key_type& key = key_type())
442 typedef std::vector<uint8_t> hai_type;
448 const hai_type& hai = hai_type())
449 : option_code(option_code), hai(hai) { }
458 typedef std::vector<uint8_t> mn_type;
464 const mn_type& mn = mn_type())
465 : option_code(option_code), mn(mn) { }
474 typedef std::vector<std::string> domains_type;
477 domains_type domains;
480 const domains_type& domains = domains_type())
481 : lifetime(lifetime), domains(domains) { }
494 : timestamp(timestamp) {
495 std::fill(reserved, reserved +
sizeof(reserved),
static_cast<uint8_t
>(0));
505 uint8_t limit, reserved1;
509 : limit(limit), reserved1(), reserved2() {
524 : reserved(), interval(interval) {
535 typedef std::vector<ipaddress_type> sources_type;
536 typedef std::vector<uint8_t> aux_data_type;
541 void serialize(uint8_t* buffer, uint32_t total_sz)
const;
542 uint32_t size()
const;
546 sources_type sources;
547 aux_data_type aux_data;
553 typedef std::vector<multicast_address_record> multicast_address_records_list;
559 typedef std::vector<ipaddress_type> sources_list;
582 ICMPv6(
const uint8_t* buffer, uint32_t total_sz);
591 return static_cast<Types>(header_.type);
607 return Endian::be_to_host(header_.cksum);
615 return Endian::be_to_host(header_.u_echo.identifier);
623 return Endian::be_to_host(header_.u_echo.sequence);
631 return header_.u_nd_advt.override;
639 return header_.u_nd_advt.solicited;
647 return header_.u_nd_advt.router;
655 return header_.u_nd_ra.hop_limit;
663 return Endian::be_to_host(header_.u_echo.identifier);
671 return header_.u_nd_ra.router_pref;
679 return header_.u_nd_ra.home_agent;
687 return header_.u_nd_ra.other;
695 return header_.u_nd_ra.managed;
703 return Endian::be_to_host(header_.u_nd_ra.router_lifetime);
711 return Endian::be_to_host(reach_time_);
719 return Endian::be_to_host(retrans_timer_);
727 return target_address_;
735 return dest_address_;
746 return multicast_address_;
763 return header_.rfc4884.length;
770 return multicast_records_;
790 return mlqm_.supress;
819 void type(Types new_type);
825 void code(uint8_t new_code);
831 void checksum(uint16_t new_cksum);
837 void identifier(uint16_t new_identifier);
843 void sequence(uint16_t new_sequence);
867 void hop_limit(uint8_t new_hop_limit);
873 void maximum_response_code(uint16_t maximum_response_code);
903 void router_lifetime(uint16_t new_router_lifetime);
909 void target_addr(
const ipaddress_type& new_target_addr);
915 void dest_addr(
const ipaddress_type& new_dest_addr);
924 void multicast_addr(
const ipaddress_type& new_multicast_addr);
930 void reachable_time(uint32_t new_reachable_time);
936 void retransmit_timer(uint32_t new_retrans_timer);
943 void multicast_address_records(
const multicast_address_records_list& records);
950 void sources(
const sources_list& new_sources);
971 void qqic(uint8_t value);
986 return type() == NEIGHBOUR_SOLICIT ||
987 type() == NEIGHBOUR_ADVERT ||
997 return type() == REDIRECT;
1008 void add_option(
const option& option);
1019 internal_add_option(
option);
1020 options_.push_back(std::move(
option));
1033 bool remove_option(OptionTypes type);
1041 uint32_t header_size()
const;
1050 uint32_t trailer_size()
const;
1074 return !extensions_.extensions().empty();
1092 void use_length_field(
bool value);
1101 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
1112 const option* search_option(OptionTypes type)
const;
1118 return new ICMPv6(*
this);
1130 void use_mldv2(
bool value);
1141 void source_link_layer_addr(
const hwaddress_type& addr);
1148 void target_link_layer_addr(
const hwaddress_type& addr);
1155 void prefix_info(prefix_info_type info);
1162 void redirect_header(
const byte_array& data);
1169 void mtu(
const mtu_type& value);
1176 void shortcut_limit(
const shortcut_limit_type& value);
1183 void new_advert_interval(
const new_advert_interval_type& value);
1190 void new_home_agent_info(
const new_ha_info_type& value);
1197 void source_addr_list(
const addr_list_type& value);
1204 void target_addr_list(
const addr_list_type& value);
1211 void rsa_signature(
const rsa_sign_type& value);
1218 void timestamp(
const timestamp_type& value);
1225 void nonce(
const nonce_type& value);
1232 void ip_prefix(
const ip_prefix_type& value);
1239 void link_layer_addr(lladdr_type value);
1246 void naack(
const naack_type& value);
1253 void map(
const map_type& value);
1260 void route_info(
const route_info_type& value);
1267 void recursive_dns_servers(
const recursive_dns_type& value);
1274 void handover_key_request(
const handover_key_req_type& value);
1281 void handover_key_reply(
const handover_key_reply_type& value);
1288 void handover_assist_info(
const handover_assist_info_type& value);
1295 void mobile_node_identifier(
const mobile_node_id_type& value);
1302 void dns_search_list(
const dns_search_list_type& value);
1314 hwaddress_type source_link_layer_addr()
const;
1322 hwaddress_type target_link_layer_addr()
const;
1330 prefix_info_type prefix_info()
const;
1346 mtu_type mtu()
const;
1354 shortcut_limit_type shortcut_limit()
const;
1362 new_advert_interval_type new_advert_interval()
const;
1370 new_ha_info_type new_home_agent_info()
const;
1378 addr_list_type source_addr_list()
const;
1386 addr_list_type target_addr_list()
const;
1394 rsa_sign_type rsa_signature()
const;
1402 timestamp_type timestamp()
const;
1410 nonce_type nonce()
const;
1418 ip_prefix_type ip_prefix()
const;
1426 lladdr_type link_layer_addr()
const;
1435 naack_type naack()
const;
1443 map_type map()
const;
1451 route_info_type route_info()
const;
1459 recursive_dns_type recursive_dns_servers()
const;
1467 handover_key_req_type handover_key_request()
const;
1475 handover_key_reply_type handover_key_reply()
const;
1483 handover_assist_info_type handover_assist_info()
const;
1491 mobile_node_id_type mobile_node_identifier()
const;
1499 dns_search_list_type dns_search_list()
const;
1502 struct icmp6_header {
1508 uint16_t identifier;
1513 #if TINS_IS_LITTLE_ENDIAN
1514 uint32_t reserved:5,
1528 #if TINS_IS_LITTLE_ENDIAN
1541 uint16_t router_lifetime;
1550 uint16_t record_count;
1556 struct multicast_listener_query_message_fields {
1563 void internal_add_option(
const option& option);
1564 void write_serialization(uint8_t* buffer, uint32_t total_sz);
1565 bool has_options()
const;
1566 void write_option(
const option& opt, Memory::OutputMemoryStream& stream);
1567 void parse_options(Memory::InputMemoryStream& stream);
1568 void add_addr_list(uint8_t type,
const addr_list_type& value);
1569 addr_list_type search_addr_list(OptionTypes type)
const;
1570 options_type::const_iterator search_option_iterator(OptionTypes type)
const;
1571 options_type::iterator search_option_iterator(OptionTypes type);
1572 void try_parse_extensions(Memory::InputMemoryStream& stream);
1573 bool are_extensions_allowed()
const;
1574 uint32_t get_adjusted_inner_pdu_size()
const;
1575 uint8_t get_option_padding(uint32_t data_size);
1577 template <
template <
typename>
class Functor>
1578 const option* safe_search_option(OptionTypes opt, uint32_t size)
const {
1579 const option* option = search_option(opt);
1580 if (!option || Functor<uint32_t>()(option->data_size(), size)) {
1581 throw option_not_found();
1586 template <
typename T>
1587 T search_and_convert(OptionTypes type)
const {
1588 const option* opt = search_option(type);
1590 throw option_not_found();
1592 return opt->to<T>();
1595 icmp6_header header_;
1596 ipaddress_type target_address_;
1597 ipaddress_type dest_address_;
1598 ipaddress_type multicast_address_;
1599 options_type options_;
1600 uint32_t options_size_;
1601 uint32_t reach_time_, retrans_timer_;
1602 multicast_address_records_list multicast_records_;
1603 multicast_listener_query_message_fields mlqm_;
1604 sources_list sources_;
1605 ICMPExtensionsStructure extensions_;
Represents a hardware address.
Definition resolve_utils.h:43
Class that represents an ICMP extensions structure.
Definition icmp_extension.h:161
Represents an ICMPv6 PDU.
Definition icmpv6.h:58
void add_option(option &&option)
Adds an ICMPv6 option.
Definition icmpv6.h:1018
const ICMPExtensionsStructure & extensions() const
Getter for the extensions field.
Definition icmpv6.h:1057
const options_type & options() const
Getter for the ICMPv6 options.
Definition icmpv6.h:753
const ipaddress_type & target_addr() const
Getter for the target address field.
Definition icmpv6.h:726
Types type() const
Getter for the type field.
Definition icmpv6.h:590
const multicast_address_records_list & multicast_address_records() const
Getter for the multicast address records field.
Definition icmpv6.h:769
uint8_t hop_limit() const
Getter for the hop limit field.
Definition icmpv6.h:654
uint32_t reachable_time() const
Getter for the reachable_time field.
Definition icmpv6.h:710
PDUOption< uint8_t, ICMPv6 > option
Definition icmpv6.h:155
small_uint< 1 > home_agent() const
Getter for the home_agent field.
Definition icmpv6.h:678
Types
Definition icmpv6.h:68
uint8_t qqic() const
Getter for the Querier's Query Interval Code field.
Definition icmpv6.h:809
const ipaddress_type & multicast_addr() const
Getter for the multicast address field.
Definition icmpv6.h:745
PDUType pdu_type() const
Getter for the PDU's type.
Definition icmpv6.h:978
HWAddress< 6 > hwaddress_type
Definition icmpv6.h:150
uint32_t retransmit_timer() const
Getter for the retransmit_timer field.
Definition icmpv6.h:718
small_uint< 1 > managed() const
Getter for the managed field.
Definition icmpv6.h:694
uint16_t router_lifetime() const
Getter for the router_lifetime field.
Definition icmpv6.h:702
IPv6Address ipaddress_type
Definition icmpv6.h:145
small_uint< 1 > supress() const
Getter for the Suppress Router-Side Processing field.
Definition icmpv6.h:789
small_uint< 1 > solicited() const
Getter for the solicited field.
Definition icmpv6.h:638
bool has_extensions() const
Indicates whether this object contains ICMP extensions.
Definition icmpv6.h:1073
ICMPv6 * clone() const
Definition icmpv6.h:1117
bool has_target_addr() const
Checks whether this ICMPv6 object has a target_addr field.
Definition icmpv6.h:985
uint16_t checksum() const
Getter for the cksum field.
Definition icmpv6.h:606
uint16_t identifier() const
Getter for the identifier field.
Definition icmpv6.h:614
uint8_t length() const
Getter for the length field.
Definition icmpv6.h:762
small_uint< 1 > router() const
Getter for the router field.
Definition icmpv6.h:646
uint16_t sequence() const
Getter for the sequence field.
Definition icmpv6.h:622
OptionTypes
Definition icmpv6.h:104
std::vector< uint16_t > new_ha_info_type
The type used to store the new home agent information option data.
Definition icmpv6.h:166
std::vector< uint8_t > nonce_type
Definition icmpv6.h:188
const sources_list & sources() const
Getter for the multicast address records field.
Definition icmpv6.h:779
uint16_t maximum_response_code() const
Getter for the maximum response code field.
Definition icmpv6.h:662
std::pair< uint16_t, uint32_t > mtu_type
Definition icmpv6.h:193
small_uint< 3 > qrv() const
Getter for the Querier's Robustnes Variable field.
Definition icmpv6.h:799
ICMPExtensionsStructure & extensions()
Getter for the extensions field.
Definition icmpv6.h:1066
std::vector< option > options_type
Definition icmpv6.h:160
small_uint< 1 > other() const
Getter for the other field.
Definition icmpv6.h:686
uint8_t code() const
Getter for the code field.
Definition icmpv6.h:598
bool has_dest_addr() const
Checks whether this ICMPv6 object has a target_addr field.
Definition icmpv6.h:996
small_uint< 2 > router_pref() const
Getter for the router_pref field.
Definition icmpv6.h:670
const ipaddress_type & dest_addr() const
Getter for the destination address field.
Definition icmpv6.h:734
Definition ipv6_address.h:45
Represents a PDU option field.
Definition rsn_information.h:43
Base class for protocol data units.
Definition pdu.h:107
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
Represents a field of n bits.
Definition small_uint.h:52
The Tins namespace.
Definition address_range.h:38
std::vector< uint8_t > byte_array
Definition pdu.h:50
The type used to store the link layer address option data.
Definition icmpv6.h:214
lladdr_type(uint8_t option_code, const hwaddress_type &address)
Constructor taking an option code and hwaddress_type.
Definition icmpv6.h:241
lladdr_type(uint8_t option_code=0, const address_type &address=address_type())
Definition icmpv6.h:226
The type used to store the neighbour advertisement acknowledgement option data.
Definition icmpv6.h:199
rsa_sign_type(RAIterator hash, const signature_type &sign)
Constructs a rsa_sign_type object.
Definition icmpv6.h:318
rsa_sign_type()
Default constructs a rsa_sign_type.
Definition icmpv6.h:328
rsa_sign_type(RAIterator hash, ForwardIterator start, ForwardIterator end)
Constructs a rsa_sign_type object.
Definition icmpv6.h:300