34 #include <tins/macros.h>
36 #include <tins/ipv6_address.h>
37 #include <tins/pdu_option.h>
38 #include <tins/endianness.h>
39 #include <tins/small_uint.h>
40 #include <tins/hw_address.h>
41 #include <tins/small_uint.h>
42 #include <tins/icmp_extension.h>
43 #include <tins/cxxstd.h>
48 class InputMemoryStream;
49 class OutputMemoryStream;
79 NEIGHBOUR_SOLICIT = 135,
80 NEIGHBOUR_ADVERT = 136,
82 ROUTER_RENUMBER = 138,
88 MOBILE_PREFIX_SOLICIT = 146,
89 MOBILE_PREFIX_ADVERT = 147,
90 CERT_PATH_SOLICIT = 148,
91 CERT_PATH_ADVERT = 149,
92 MULTICAST_ROUTER_ADVERT = 151,
93 MULTICAST_ROUTER_SOLICIT = 152,
94 MULTICAST_ROUTER_TERMINATE = 153,
95 RPL_CONTROL_MSG = 155,
96 EXTENDED_ECHO_REQUEST = 160,
97 EXTENDED_ECHO_REPLY = 161
130 HANDOVER_ASSIST_INFO,
136 AUTHORITATIVE_BORDER_ROUTER,
171 typedef std::vector<ipaddress_type> addresses_type;
174 addresses_type addresses;
176 addr_list_type(
const addresses_type& addresses = addresses_type())
177 : addresses(addresses) {
178 std::fill(reserved, reserved +
sizeof(reserved),
static_cast<uint8_t
>(0));
199 uint8_t code, status;
202 naack_type(uint8_t code = 0, uint8_t status = 0)
203 : code(code), status(status) {
204 std::fill(reserved, reserved + 4,
static_cast<uint8_t
>(0));
214 typedef std::vector<uint8_t> address_type;
217 address_type address;
226 const address_type& address = address_type())
227 : option_code(option_code), address(address) {
241 : option_code(option_code), address(address.begin(), address.end()) {
254 uint32_t valid_lifetime,
262 uint32_t valid_lifetime = 0,
263 uint32_t preferred_lifetime = 0,
265 : prefix_len(prefix_len), A(A), L(L), valid_lifetime(valid_lifetime),
266 preferred_lifetime(preferred_lifetime), reserved2(0), prefix(prefix) { }
275 typedef std::vector<uint8_t> signature_type;
277 uint8_t key_hash[16];
278 signature_type signature;
298 template <
typename RAIterator,
typename ForwardIterator>
300 : signature(start, end) {
301 std::copy(hash, hash +
sizeof(key_hash), key_hash);
316 template <
typename RAIterator>
319 std::copy(hash, hash +
sizeof(key_hash), key_hash);
328 std::fill(key_hash, key_hash +
sizeof(key_hash),
static_cast<uint8_t
>(0));
338 uint8_t option_code, prefix_len;
342 uint8_t prefix_len = 0,
344 : option_code(option_code), prefix_len(prefix_len), address(address)
356 uint32_t valid_lifetime;
362 uint32_t valid_lifetime = 0,
364 : dist(dist), pref(pref), r(r), valid_lifetime(valid_lifetime),
374 typedef std::vector<uint8_t> prefix_type;
378 uint32_t route_lifetime;
383 uint32_t route_lifetime = 0,
384 const prefix_type& prefix = prefix_type())
385 : prefix_len(prefix_len), pref(pref), route_lifetime(route_lifetime),
395 typedef std::vector<ipaddress_type> servers_type;
398 servers_type servers;
401 const servers_type& servers = servers_type())
402 : lifetime(lifetime), servers(servers) {}
411 typedef std::vector<uint8_t> key_type;
417 const key_type& key = key_type())
418 : AT(AT), key(key) { }
431 const key_type& key = key_type())
441 typedef std::vector<uint8_t> hai_type;
447 const hai_type& hai = hai_type())
448 : option_code(option_code), hai(hai) { }
457 typedef std::vector<uint8_t> mn_type;
463 const mn_type& mn = mn_type())
464 : option_code(option_code), mn(mn) { }
473 typedef std::vector<std::string> domains_type;
476 domains_type domains;
479 const domains_type& domains = domains_type())
480 : lifetime(lifetime), domains(domains) { }
493 : timestamp(timestamp) {
494 std::fill(reserved, reserved +
sizeof(reserved),
static_cast<uint8_t
>(0));
504 uint8_t limit, reserved1;
508 : limit(limit), reserved1(), reserved2() {
523 : reserved(), interval(interval) {
534 typedef std::vector<ipaddress_type> sources_type;
535 typedef std::vector<uint8_t> aux_data_type;
540 void serialize(uint8_t* buffer, uint32_t total_sz)
const;
541 uint32_t size()
const;
545 sources_type sources;
546 aux_data_type aux_data;
552 typedef std::vector<multicast_address_record> multicast_address_records_list;
558 typedef std::vector<ipaddress_type> sources_list;
581 ICMPv6(
const uint8_t* buffer, uint32_t total_sz);
590 return static_cast<Types>(header_.type);
606 return Endian::be_to_host(header_.cksum);
614 return Endian::be_to_host(header_.u_echo.identifier);
622 return Endian::be_to_host(header_.u_echo.sequence);
630 return header_.u_nd_advt.override;
638 return header_.u_nd_advt.solicited;
646 return header_.u_nd_advt.router;
654 return header_.u_nd_ra.hop_limit;
662 return Endian::be_to_host(header_.u_echo.identifier);
670 return header_.u_nd_ra.router_pref;
678 return header_.u_nd_ra.home_agent;
686 return header_.u_nd_ra.other;
694 return header_.u_nd_ra.managed;
702 return Endian::be_to_host(header_.u_nd_ra.router_lifetime);
710 return Endian::be_to_host(reach_time_);
718 return Endian::be_to_host(retrans_timer_);
726 return target_address_;
734 return dest_address_;
745 return multicast_address_;
762 return header_.rfc4884.length;
769 return multicast_records_;
789 return mlqm_.supress;
818 void type(Types new_type);
824 void code(uint8_t new_code);
830 void checksum(uint16_t new_cksum);
836 void identifier(uint16_t new_identifier);
842 void sequence(uint16_t new_sequence);
866 void hop_limit(uint8_t new_hop_limit);
872 void maximum_response_code(uint16_t maximum_response_code);
902 void router_lifetime(uint16_t new_router_lifetime);
908 void target_addr(
const ipaddress_type& new_target_addr);
914 void dest_addr(
const ipaddress_type& new_dest_addr);
923 void multicast_addr(
const ipaddress_type& new_multicast_addr);
929 void reachable_time(uint32_t new_reachable_time);
935 void retransmit_timer(uint32_t new_retrans_timer);
942 void multicast_address_records(
const multicast_address_records_list& records);
949 void sources(
const sources_list& new_sources);
970 void qqic(uint8_t value);
985 return type() == NEIGHBOUR_SOLICIT ||
986 type() == NEIGHBOUR_ADVERT ||
996 return type() == REDIRECT;
1007 void add_option(
const option& option);
1018 internal_add_option(
option);
1019 options_.push_back(std::move(
option));
1032 bool remove_option(OptionTypes type);
1040 uint32_t header_size()
const;
1049 uint32_t trailer_size()
const;
1073 return !extensions_.extensions().empty();
1091 void use_length_field(
bool value);
1100 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
1111 const option* search_option(OptionTypes type)
const;
1117 return new ICMPv6(*
this);
1129 void use_mldv2(
bool value);
1140 void source_link_layer_addr(
const hwaddress_type& addr);
1147 void target_link_layer_addr(
const hwaddress_type& addr);
1154 void prefix_info(prefix_info_type info);
1161 void redirect_header(
const byte_array& data);
1168 void mtu(
const mtu_type& value);
1175 void shortcut_limit(
const shortcut_limit_type& value);
1182 void new_advert_interval(
const new_advert_interval_type& value);
1189 void new_home_agent_info(
const new_ha_info_type& value);
1196 void source_addr_list(
const addr_list_type& value);
1203 void target_addr_list(
const addr_list_type& value);
1210 void rsa_signature(
const rsa_sign_type& value);
1217 void timestamp(
const timestamp_type& value);
1224 void nonce(
const nonce_type& value);
1231 void ip_prefix(
const ip_prefix_type& value);
1238 void link_layer_addr(lladdr_type value);
1245 void naack(
const naack_type& value);
1252 void map(
const map_type& value);
1259 void route_info(
const route_info_type& value);
1266 void recursive_dns_servers(
const recursive_dns_type& value);
1273 void handover_key_request(
const handover_key_req_type& value);
1280 void handover_key_reply(
const handover_key_reply_type& value);
1287 void handover_assist_info(
const handover_assist_info_type& value);
1294 void mobile_node_identifier(
const mobile_node_id_type& value);
1301 void dns_search_list(
const dns_search_list_type& value);
1313 hwaddress_type source_link_layer_addr()
const;
1321 hwaddress_type target_link_layer_addr()
const;
1329 prefix_info_type prefix_info()
const;
1345 mtu_type mtu()
const;
1353 shortcut_limit_type shortcut_limit()
const;
1361 new_advert_interval_type new_advert_interval()
const;
1369 new_ha_info_type new_home_agent_info()
const;
1377 addr_list_type source_addr_list()
const;
1385 addr_list_type target_addr_list()
const;
1393 rsa_sign_type rsa_signature()
const;
1401 timestamp_type timestamp()
const;
1409 nonce_type nonce()
const;
1417 ip_prefix_type ip_prefix()
const;
1425 lladdr_type link_layer_addr()
const;
1434 naack_type naack()
const;
1442 map_type map()
const;
1450 route_info_type route_info()
const;
1458 recursive_dns_type recursive_dns_servers()
const;
1466 handover_key_req_type handover_key_request()
const;
1474 handover_key_reply_type handover_key_reply()
const;
1482 handover_assist_info_type handover_assist_info()
const;
1490 mobile_node_id_type mobile_node_identifier()
const;
1498 dns_search_list_type dns_search_list()
const;
1501 struct icmp6_header {
1507 uint16_t identifier;
1512 #if TINS_IS_LITTLE_ENDIAN
1513 uint32_t reserved:5,
1527 #if TINS_IS_LITTLE_ENDIAN
1540 uint16_t router_lifetime;
1549 uint16_t record_count;
1555 struct multicast_listener_query_message_fields {
1562 void internal_add_option(
const option& option);
1563 void write_serialization(uint8_t* buffer, uint32_t total_sz);
1564 bool has_options()
const;
1565 void write_option(
const option& opt, Memory::OutputMemoryStream& stream);
1566 void parse_options(Memory::InputMemoryStream& stream);
1567 void add_addr_list(uint8_t type,
const addr_list_type& value);
1568 addr_list_type search_addr_list(OptionTypes type)
const;
1569 options_type::const_iterator search_option_iterator(OptionTypes type)
const;
1570 options_type::iterator search_option_iterator(OptionTypes type);
1571 void try_parse_extensions(Memory::InputMemoryStream& stream);
1572 bool are_extensions_allowed()
const;
1573 uint32_t get_adjusted_inner_pdu_size()
const;
1574 uint8_t get_option_padding(uint32_t data_size);
1576 template <
template <
typename>
class Functor>
1577 const option* safe_search_option(OptionTypes opt, uint32_t size)
const {
1578 const option* option = search_option(opt);
1579 if (!option || Functor<uint32_t>()(option->data_size(), size)) {
1580 throw option_not_found();
1585 template <
typename T>
1586 T search_and_convert(OptionTypes type)
const {
1587 const option* opt = search_option(type);
1589 throw option_not_found();
1591 return opt->to<T>();
1594 icmp6_header header_;
1595 ipaddress_type target_address_;
1596 ipaddress_type dest_address_;
1597 ipaddress_type multicast_address_;
1598 options_type options_;
1599 uint32_t options_size_;
1600 uint32_t reach_time_, retrans_timer_;
1601 multicast_address_records_list multicast_records_;
1602 multicast_listener_query_message_fields mlqm_;
1603 sources_list sources_;
1604 ICMPExtensionsStructure extensions_;
Class that represents an ICMP extensions structure.
Definition: icmp_extension.h:161
Represents an ICMPv6 PDU.
Definition: icmpv6.h:57
const ipaddress_type & dest_addr() const
Getter for the destination address field.
Definition: icmpv6.h:733
void add_option(option &&option)
Adds an ICMPv6 option.
Definition: icmpv6.h:1017
small_uint< 1 > solicited() const
Getter for the solicited field.
Definition: icmpv6.h:637
IPv6Address ipaddress_type
Definition: icmpv6.h:144
PDUOption< uint8_t, ICMPv6 > option
Definition: icmpv6.h:154
small_uint< 1 > home_agent() const
Getter for the home_agent field.
Definition: icmpv6.h:677
Types type() const
Getter for the type field.
Definition: icmpv6.h:589
HWAddress< 6 > hwaddress_type
Definition: icmpv6.h:149
small_uint< 2 > router_pref() const
Getter for the router_pref field.
Definition: icmpv6.h:669
small_uint< 1 > managed() const
Getter for the managed field.
Definition: icmpv6.h:693
uint8_t hop_limit() const
Getter for the hop limit field.
Definition: icmpv6.h:653
uint32_t reachable_time() const
Getter for the reachable_time field.
Definition: icmpv6.h:709
std::vector< uint16_t > new_ha_info_type
The type used to store the new home agent information option data.
Definition: icmpv6.h:165
small_uint< 1 > router() const
Getter for the router field.
Definition: icmpv6.h:645
Types
Definition: icmpv6.h:67
uint8_t qqic() const
Getter for the Querier's Query Interval Code field.
Definition: icmpv6.h:808
const ICMPExtensionsStructure & extensions() const
Getter for the extensions field.
Definition: icmpv6.h:1056
PDUType pdu_type() const
Getter for the PDU's type.
Definition: icmpv6.h:977
uint32_t retransmit_timer() const
Getter for the retransmit_timer field.
Definition: icmpv6.h:717
uint16_t router_lifetime() const
Getter for the router_lifetime field.
Definition: icmpv6.h:701
ICMPv6 * clone() const
Definition: icmpv6.h:1116
bool has_extensions() const
Indicates whether this object contains ICMP extensions.
Definition: icmpv6.h:1072
std::vector< option > options_type
Definition: icmpv6.h:159
bool has_target_addr() const
Checks whether this ICMPv6 object has a target_addr field.
Definition: icmpv6.h:984
small_uint< 1 > supress() const
Getter for the Suppress Router-Side Processing field.
Definition: icmpv6.h:788
uint16_t checksum() const
Getter for the cksum field.
Definition: icmpv6.h:605
uint16_t identifier() const
Getter for the identifier field.
Definition: icmpv6.h:613
uint8_t length() const
Getter for the length field.
Definition: icmpv6.h:761
uint16_t sequence() const
Getter for the sequence field.
Definition: icmpv6.h:621
small_uint< 3 > qrv() const
Getter for the Querier's Robustnes Variable field.
Definition: icmpv6.h:798
const multicast_address_records_list & multicast_address_records() const
Getter for the multicast address records field.
Definition: icmpv6.h:768
OptionTypes
Definition: icmpv6.h:103
const ipaddress_type & multicast_addr() const
Getter for the multicast address field.
Definition: icmpv6.h:744
std::pair< uint16_t, uint32_t > mtu_type
Definition: icmpv6.h:192
ICMPExtensionsStructure & extensions()
Getter for the extensions field.
Definition: icmpv6.h:1065
const options_type & options() const
Getter for the ICMPv6 options.
Definition: icmpv6.h:752
small_uint< 1 > other() const
Getter for the other field.
Definition: icmpv6.h:685
const ipaddress_type & target_addr() const
Getter for the target address field.
Definition: icmpv6.h:725
uint16_t maximum_response_code() const
Getter for the maximum response code field.
Definition: icmpv6.h:661
std::vector< uint8_t > nonce_type
Definition: icmpv6.h:187
const sources_list & sources() const
Getter for the multicast address records field.
Definition: icmpv6.h:778
uint8_t code() const
Getter for the code field.
Definition: icmpv6.h:597
bool has_dest_addr() const
Checks whether this ICMPv6 object has a target_addr field.
Definition: icmpv6.h:995
Definition: ipv6_address.h:45
Represents a PDU option field.
Definition: pdu_option.h:201
Base class for protocol data units.
Definition: pdu.h:107
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
The Tins namespace.
Definition: address_range.h:38
std::vector< uint8_t > byte_array
Definition: pdu.h:45
The type used to store the link layer address option data.
Definition: icmpv6.h:213
lladdr_type(uint8_t option_code, const hwaddress_type &address)
Constructor taking an option code and hwaddress_type.
Definition: icmpv6.h:240
lladdr_type(uint8_t option_code=0, const address_type &address=address_type())
Definition: icmpv6.h:225
The type used to store the neighbour advertisement acknowledgement option data.
Definition: icmpv6.h:198
rsa_sign_type(RAIterator hash, const signature_type &sign)
Constructs a rsa_sign_type object.
Definition: icmpv6.h:317
rsa_sign_type()
Default constructs a rsa_sign_type.
Definition: icmpv6.h:327
rsa_sign_type(RAIterator hash, ForwardIterator start, ForwardIterator end)
Constructs a rsa_sign_type object.
Definition: icmpv6.h:299