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,
128 HANDOVER_ASSIST_INFO,
134 AUTHORITATIVE_BORDER_ROUTER,
169 typedef std::vector<ipaddress_type> addresses_type;
172 addresses_type addresses;
174 addr_list_type(
const addresses_type& addresses = addresses_type())
175 : addresses(addresses) {
176 std::fill(reserved, reserved +
sizeof(reserved), 0);
197 uint8_t code, status;
200 naack_type(uint8_t code = 0, uint8_t status = 0)
201 : code(code), status(status) {
202 std::fill(reserved, reserved + 4, 0);
205 static naack_type from_option(
const option& opt);
212 typedef std::vector<uint8_t> address_type;
215 address_type address;
224 const address_type& address = address_type())
225 : option_code(option_code), address(address) {
239 : option_code(option_code), address(address.begin(), address.end()) {
252 uint32_t valid_lifetime,
255 ipaddress_type prefix;
260 uint32_t valid_lifetime = 0,
261 uint32_t preferred_lifetime = 0,
262 const ipaddress_type& prefix = ipaddress_type())
263 : prefix_len(prefix_len), A(A), L(L), valid_lifetime(valid_lifetime),
264 preferred_lifetime(preferred_lifetime), reserved2(0), prefix(prefix) { }
273 typedef std::vector<uint8_t> signature_type;
275 uint8_t key_hash[16];
276 signature_type signature;
296 template <
typename RAIterator,
typename ForwardIterator>
298 : signature(start, end) {
299 std::copy(hash, hash +
sizeof(key_hash), key_hash);
314 template <
typename RAIterator>
317 std::copy(hash, hash +
sizeof(key_hash), key_hash);
326 std::fill(key_hash, key_hash +
sizeof(key_hash), 0);
336 uint8_t option_code, prefix_len;
337 ipaddress_type address;
340 uint8_t prefix_len = 0,
341 const ipaddress_type& address = ipaddress_type())
342 : option_code(option_code), prefix_len(prefix_len), address(address)
354 uint32_t valid_lifetime;
355 ipaddress_type address;
360 uint32_t valid_lifetime = 0,
361 const ipaddress_type& address = ipaddress_type())
362 : dist(dist), pref(pref), r(r), valid_lifetime(valid_lifetime),
365 static map_type from_option(
const option& opt);
372 typedef std::vector<uint8_t> prefix_type;
376 uint32_t route_lifetime;
381 uint32_t route_lifetime = 0,
382 const prefix_type& prefix = prefix_type())
383 : prefix_len(prefix_len), pref(pref), route_lifetime(route_lifetime),
393 typedef std::vector<ipaddress_type> servers_type;
396 servers_type servers;
399 const servers_type& servers = servers_type())
400 : lifetime(lifetime), servers(servers) {}
409 typedef std::vector<uint8_t> key_type;
415 const key_type& key = key_type())
416 : AT(AT), key(key) { }
429 const key_type& key = key_type())
439 typedef std::vector<uint8_t> hai_type;
445 const hai_type& hai = hai_type())
446 : option_code(option_code), hai(hai) { }
455 typedef std::vector<uint8_t> mn_type;
461 const mn_type& mn = mn_type())
462 : option_code(option_code), mn(mn) { }
471 typedef std::vector<std::string> domains_type;
474 domains_type domains;
477 const domains_type& domains = domains_type())
478 : lifetime(lifetime), domains(domains) { }
491 : timestamp(timestamp) {
492 std::fill(reserved, reserved +
sizeof(reserved), 0);
502 uint8_t limit, reserved1;
506 : limit(limit), reserved1(), reserved2() {
521 : reserved(), interval(interval) {
532 typedef std::vector<ipaddress_type> sources_type;
533 typedef std::vector<uint8_t> aux_data_type;
538 void serialize(uint8_t* buffer, uint32_t total_sz)
const;
539 uint32_t size()
const;
542 ipaddress_type multicast_address;
543 sources_type sources;
544 aux_data_type aux_data;
550 typedef std::vector<multicast_address_record> multicast_address_records_list;
556 typedef std::vector<ipaddress_type> sources_list;
579 ICMPv6(
const uint8_t* buffer, uint32_t total_sz);
588 return static_cast<Types>(header_.type);
604 return Endian::be_to_host(header_.cksum);
612 return Endian::be_to_host(header_.u_echo.identifier);
620 return Endian::be_to_host(header_.u_echo.sequence);
628 return header_.u_nd_advt.override;
636 return header_.u_nd_advt.solicited;
644 return header_.u_nd_advt.router;
652 return header_.u_nd_ra.hop_limit;
660 return Endian::be_to_host(header_.u_echo.identifier);
668 return header_.u_nd_ra.router_pref;
676 return header_.u_nd_ra.home_agent;
684 return header_.u_nd_ra.other;
692 return header_.u_nd_ra.managed;
700 return Endian::be_to_host(header_.u_nd_ra.router_lifetime);
708 return Endian::be_to_host(reach_time_);
716 return Endian::be_to_host(retrans_timer_);
724 return target_address_;
732 return dest_address_;
743 return multicast_address_;
760 return header_.rfc4884.length;
767 return multicast_records_;
787 return mlqm_.supress;
816 void type(
Types new_type);
822 void code(uint8_t new_code);
828 void checksum(uint16_t new_cksum);
834 void identifier(uint16_t new_identifier);
840 void sequence(uint16_t new_sequence);
864 void hop_limit(uint8_t new_hop_limit);
870 void maximum_response_code(uint16_t maximum_response_code);
900 void router_lifetime(uint16_t new_router_lifetime);
906 void target_addr(
const ipaddress_type& new_target_addr);
912 void dest_addr(
const ipaddress_type& new_dest_addr);
921 void multicast_addr(
const ipaddress_type& new_multicast_addr);
927 void reachable_time(uint32_t new_reachable_time);
933 void retransmit_timer(uint32_t new_retrans_timer);
940 void multicast_address_records(
const multicast_address_records_list& records);
947 void sources(
const sources_list& new_sources);
968 void qqic(uint8_t value);
983 return type() == NEIGHBOUR_SOLICIT ||
984 type() == NEIGHBOUR_ADVERT ||
994 return type() == REDIRECT;
1005 void add_option(
const option& option);
1016 internal_add_option(option);
1017 options_.push_back(std::move(option));
1038 uint32_t header_size()
const;
1047 uint32_t trailer_size()
const;
1071 return !extensions_.extensions().empty();
1089 void use_length_field(
bool value);
1098 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
1109 const option* search_option(
OptionTypes type)
const;
1115 return new ICMPv6(*
this);
1127 void use_mldv2(
bool value);
1138 void source_link_layer_addr(
const hwaddress_type& addr);
1145 void target_link_layer_addr(
const hwaddress_type& addr);
1159 void redirect_header(
const byte_array& data);
1166 void mtu(
const mtu_type& value);
1187 void new_home_agent_info(
const new_ha_info_type& value);
1222 void nonce(
const nonce_type& value);
1311 hwaddress_type source_link_layer_addr()
const;
1319 hwaddress_type target_link_layer_addr()
const;
1343 mtu_type mtu()
const;
1367 new_ha_info_type new_home_agent_info()
const;
1407 nonce_type nonce()
const;
1499 struct icmp6_header {
1505 uint16_t identifier;
1510 #if TINS_IS_LITTLE_ENDIAN 1511 uint32_t reserved:5,
1525 #if TINS_IS_LITTLE_ENDIAN 1538 uint16_t router_lifetime;
1547 uint16_t record_count;
1553 struct multicast_listener_query_message_fields {
1560 void internal_add_option(
const option& option);
1561 void write_serialization(uint8_t* buffer, uint32_t total_sz);
1562 bool has_options()
const;
1563 void write_option(
const option& opt, Memory::OutputMemoryStream& stream);
1564 void parse_options(Memory::InputMemoryStream& stream);
1567 options_type::const_iterator search_option_iterator(
OptionTypes type)
const;
1568 options_type::iterator search_option_iterator(
OptionTypes type);
1569 void try_parse_extensions(Memory::InputMemoryStream& stream);
1570 bool are_extensions_allowed()
const;
1571 uint32_t get_adjusted_inner_pdu_size()
const;
1572 uint8_t get_option_padding(uint32_t data_size);
1574 template <
template <
typename>
class Functor>
1575 const option* safe_search_option(
OptionTypes opt, uint32_t size)
const {
1576 const option* option = search_option(opt);
1577 if (!option || Functor<uint32_t>()(option->
data_size(), size)) {
1583 template <
typename T>
1585 const option* opt = search_option(type);
1589 return opt->
to<T>();
1592 icmp6_header header_;
1593 ipaddress_type target_address_;
1594 ipaddress_type dest_address_;
1595 ipaddress_type multicast_address_;
1596 options_type options_;
1597 uint32_t options_size_;
1598 uint32_t reach_time_, retrans_timer_;
1599 multicast_address_records_list multicast_records_;
1600 multicast_listener_query_message_fields mlqm_;
1601 sources_list sources_;
1608 #endif // TINS_ICMPV6_H
rsa_sign_type(RAIterator hash, const signature_type &sign)
Constructs a rsa_sign_type object.
Definition: icmpv6.h:315
uint16_t identifier() const
Getter for the identifier field.
Definition: icmpv6.h:611
PDUType pdu_type() const
Getter for the PDU's type.
Definition: icmpv6.h:975
const sources_list & sources() const
Getter for the multicast address records field.
Definition: icmpv6.h:776
rsa_sign_type()
Default constructs a rsa_sign_type.
Definition: icmpv6.h:325
uint32_t reachable_time() const
Getter for the reachable_time field.
Definition: icmpv6.h:707
OptionTypes
Definition: icmpv6.h:101
std::vector< uint8_t > byte_array
Definition: pdu.h:45
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
std::vector< uint16_t > new_ha_info_type
The type used to store the new home agent information option data.
Definition: icmpv6.h:163
uint32_t retransmit_timer() const
Getter for the retransmit_timer field.
Definition: icmpv6.h:715
small_uint< 2 > router_pref() const
Getter for the router_pref field.
Definition: icmpv6.h:667
bool has_target_addr() const
Checks whether this ICMPv6 object has a target_addr field.
Definition: icmpv6.h:982
Types type() const
Getter for the type field.
Definition: icmpv6.h:587
bool has_dest_addr() const
Checks whether this ICMPv6 object has a target_addr field.
Definition: icmpv6.h:993
const ipaddress_type & target_addr() const
Getter for the target address field.
Definition: icmpv6.h:723
Represents a PDU option field.
Definition: pdu_option.h:201
small_uint< 1 > managed() const
Getter for the managed field.
Definition: icmpv6.h:691
std::pair< uint16_t, uint32_t > mtu_type
Definition: icmpv6.h:190
Types
Definition: icmpv6.h:67
std::vector< uint8_t > nonce_type
Definition: icmpv6.h:185
uint16_t checksum() const
Getter for the cksum field.
Definition: icmpv6.h:603
std::vector< option > options_type
Definition: icmpv6.h:157
Represents an ICMPv6 PDU.
Definition: icmpv6.h:57
small_uint< 1 > supress() const
Getter for the Suppress Router-Side Processing field.
Definition: icmpv6.h:786
const multicast_address_records_list & multicast_address_records() const
Getter for the multicast address records field.
Definition: icmpv6.h:766
The type used to store the neighbour advertisement acknowledgement option data.
Definition: icmpv6.h:196
uint16_t sequence() const
Getter for the sequence field.
Definition: icmpv6.h:619
const ipaddress_type & multicast_addr() const
Getter for the multicast address field.
Definition: icmpv6.h:742
rsa_sign_type(RAIterator hash, ForwardIterator start, ForwardIterator end)
Constructs a rsa_sign_type object.
Definition: icmpv6.h:297
The Tins namespace.
Definition: address_range.h:38
T to() const
Constructs a T from this PDUOption.
Definition: pdu_option.h:389
uint16_t router_lifetime() const
Getter for the router_lifetime field.
Definition: icmpv6.h:699
small_uint< 3 > qrv() const
Getter for the Querier's Robustnes Variable field.
Definition: icmpv6.h:796
void add_option(option &&option)
Adds an ICMPv6 option.
Definition: icmpv6.h:1015
ICMPExtensionsStructure & extensions()
Getter for the extensions field.
Definition: icmpv6.h:1063
uint8_t length() const
Getter for the length field.
Definition: icmpv6.h:759
small_uint< 1 > other() const
Getter for the other field.
Definition: icmpv6.h:683
HWAddress< 6 > hwaddress_type
Definition: icmpv6.h:147
lladdr_type(uint8_t option_code=0, const address_type &address=address_type())
Definition: icmpv6.h:223
const options_type & options() const
Getter for the ICMPv6 options.
Definition: icmpv6.h:750
small_uint< 1 > router() const
Getter for the router field.
Definition: icmpv6.h:643
const ipaddress_type & dest_addr() const
Getter for the destination address field.
Definition: icmpv6.h:731
Definition: ipv6_address.h:45
const ICMPExtensionsStructure & extensions() const
Getter for the extensions field.
Definition: icmpv6.h:1054
PDUOption< uint8_t, ICMPv6 > option
Definition: icmpv6.h:152
Class that represents an ICMP extensions structure.
Definition: icmp_extension.h:161
IPv6Address ipaddress_type
Definition: icmpv6.h:142
size_t data_size() const
Retrieves the length of this option's data.
Definition: pdu_option.h:361
bool has_extensions() const
Indicates whether this object contains ICMP extensions.
Definition: icmpv6.h:1070
The type used to store the link layer address option data.
Definition: icmpv6.h:211
small_uint< 1 > home_agent() const
Getter for the home_agent field.
Definition: icmpv6.h:675
Base class for protocol data units.
Definition: pdu.h:107
uint16_t maximum_response_code() const
Getter for the maximum response code field.
Definition: icmpv6.h:659
Exception thrown when an option is not found.
Definition: exceptions.h:56
uint8_t hop_limit() const
Getter for the hop limit field.
Definition: icmpv6.h:651
small_uint< 1 > solicited() const
Getter for the solicited field.
Definition: icmpv6.h:635
lladdr_type(uint8_t option_code, const hwaddress_type &address)
Constructor taking an option code and hwaddress_type.
Definition: icmpv6.h:238
ICMPv6 * clone() const
Definition: icmpv6.h:1114
uint8_t qqic() const
Getter for the Querier's Query Interval Code field.
Definition: icmpv6.h:806
uint8_t code() const
Getter for the code field.
Definition: icmpv6.h:595