libtins  4.4
icmpv6.h
1 /*
2  * Copyright (c) 2017, Matias Fontanini
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef TINS_ICMPV6_H
31 #define TINS_ICMPV6_H
32 
33 #include <vector>
34 #include <tins/macros.h>
35 #include <tins/pdu.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>
44 
45 namespace Tins {
46 namespace Memory {
47 
48 class InputMemoryStream;
49 class OutputMemoryStream;
50 
51 } // memory
52 
57 class TINS_API ICMPv6 : public PDU {
58 public:
62  static const PDU::PDUType pdu_flag = PDU::ICMPv6;
63 
67  enum Types {
68  DEST_UNREACHABLE = 1,
69  PACKET_TOOBIG = 2,
70  TIME_EXCEEDED = 3,
71  PARAM_PROBLEM = 4,
72  ECHO_REQUEST = 128,
73  ECHO_REPLY = 129,
74  MGM_QUERY = 130,
75  MGM_REPORT = 131,
76  MGM_REDUCTION = 132,
77  ROUTER_SOLICIT = 133,
78  ROUTER_ADVERT = 134,
79  NEIGHBOUR_SOLICIT = 135,
80  NEIGHBOUR_ADVERT = 136,
81  REDIRECT = 137,
82  ROUTER_RENUMBER = 138,
83  NI_QUERY = 139,
84  NI_REPLY = 140,
85  MLD2_REPORT = 143,
86  DHAAD_REQUEST = 144,
87  DHAAD_REPLY = 145,
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
98  };
99 
103  enum OptionTypes {
104  SOURCE_ADDRESS = 1,
105  TARGET_ADDRESS,
106  PREFIX_INFO,
107  REDIRECT_HEADER,
108  MTU,
109  NBMA_SHORT_LIMIT,
110  ADVERT_INTERVAL,
111  HOME_AGENT_INFO,
112  S_ADDRESS_LIST,
113  T_ADDRESS_LIST,
114  CGA,
115  RSA_SIGN,
116  TIMESTAMP,
117  NONCE,
118  TRUST_ANCHOR,
119  CERTIFICATE,
120  IP_PREFIX,
121  NEW_ROUTER_PREFIX,
122  LINK_ADDRESS,
123  NAACK,
124  MAP = 23,
125  ROUTE_INFO,
126  RECURSIVE_DNS_SERV,
127  RA_FLAGS_EXT,
128  HANDOVER_KEY_REQ,
129  HANDOVER_KEY_REPLY,
130  HANDOVER_ASSIST_INFO,
131  MOBILE_NODE_ID,
132  DNS_SEARCH_LIST,
133  PROXY_SIGNATURE,
134  ADDRESS_REG,
135  SIXLOWPAN_CONTEXT,
136  AUTHORITATIVE_BORDER_ROUTER,
137  CARD_REQUEST = 138,
138  CARD_REPLY
139  };
140 
145 
150 
155 
159  typedef std::vector<option> options_type;
160 
165  typedef std::vector<uint16_t> new_ha_info_type;
166 
170  struct addr_list_type {
171  typedef std::vector<ipaddress_type> addresses_type;
172 
173  uint8_t reserved[6];
174  addresses_type addresses;
175 
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));
179  }
180 
181  static addr_list_type from_option(const option& opt);
182  };
183 
187  typedef std::vector<uint8_t> nonce_type;
188 
192  typedef std::pair<uint16_t, uint32_t> mtu_type;
193 
198  struct naack_type {
199  uint8_t code, status;
200  uint8_t reserved[4];
201 
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));
205  }
206 
207  static naack_type from_option(const option& opt);
208  };
209 
213  struct lladdr_type {
214  typedef std::vector<uint8_t> address_type;
215 
216  uint8_t option_code;
217  address_type address;
218 
225  lladdr_type(uint8_t option_code = 0,
226  const address_type& address = address_type())
227  : option_code(option_code), address(address) {
228 
229  }
230 
240  lladdr_type(uint8_t option_code, const hwaddress_type& address)
241  : option_code(option_code), address(address.begin(), address.end()) {
242 
243  }
244 
245  static lladdr_type from_option(const option& opt);
246  };
247 
252  uint8_t prefix_len;
253  small_uint<1> A, L;
254  uint32_t valid_lifetime,
255  preferred_lifetime,
256  reserved2;
257  ipaddress_type prefix;
258 
259  prefix_info_type(uint8_t prefix_len = 0,
260  small_uint<1> A = 0,
261  small_uint<1> L = 0,
262  uint32_t valid_lifetime = 0,
263  uint32_t preferred_lifetime = 0,
264  const ipaddress_type& prefix = ipaddress_type())
265  : prefix_len(prefix_len), A(A), L(L), valid_lifetime(valid_lifetime),
266  preferred_lifetime(preferred_lifetime), reserved2(0), prefix(prefix) { }
267 
268  static prefix_info_type from_option(const option& opt);
269  };
270 
274  struct rsa_sign_type {
275  typedef std::vector<uint8_t> signature_type;
276 
277  uint8_t key_hash[16];
278  signature_type signature;
279 
298  template <typename RAIterator, typename ForwardIterator>
299  rsa_sign_type(RAIterator hash, ForwardIterator start, ForwardIterator end)
300  : signature(start, end) {
301  std::copy(hash, hash + sizeof(key_hash), key_hash);
302  }
303 
316  template <typename RAIterator>
317  rsa_sign_type(RAIterator hash, const signature_type& sign)
318  : signature(sign) {
319  std::copy(hash, hash + sizeof(key_hash), key_hash);
320  }
321 
328  std::fill(key_hash, key_hash + sizeof(key_hash), static_cast<uint8_t>(0));
329  }
330 
331  static rsa_sign_type from_option(const option& opt);
332  };
333 
337  struct ip_prefix_type {
338  uint8_t option_code, prefix_len;
339  ipaddress_type address;
340 
341  ip_prefix_type(uint8_t option_code = 0,
342  uint8_t prefix_len = 0,
343  const ipaddress_type& address = ipaddress_type())
344  : option_code(option_code), prefix_len(prefix_len), address(address)
345  {}
346 
347  static ip_prefix_type from_option(const option& opt);
348  };
349 
353  struct map_type {
354  small_uint<4> dist, pref;
355  small_uint<1> r;
356  uint32_t valid_lifetime;
357  ipaddress_type address;
358 
359  map_type(small_uint<4> dist = 0,
360  small_uint<4> pref = 0,
361  small_uint<1> r = 0,
362  uint32_t valid_lifetime = 0,
363  const ipaddress_type& address = ipaddress_type())
364  : dist(dist), pref(pref), r(r), valid_lifetime(valid_lifetime),
365  address(address) { }
366 
367  static map_type from_option(const option& opt);
368  };
369 
374  typedef std::vector<uint8_t> prefix_type;
375 
376  uint8_t prefix_len;
377  small_uint<2> pref;
378  uint32_t route_lifetime;
379  prefix_type prefix;
380 
381  route_info_type(uint8_t prefix_len = 0,
382  small_uint<2> pref = 0,
383  uint32_t route_lifetime = 0,
384  const prefix_type& prefix = prefix_type())
385  : prefix_len(prefix_len), pref(pref), route_lifetime(route_lifetime),
386  prefix(prefix) { }
387 
388  static route_info_type from_option(const option& opt);
389  };
390 
395  typedef std::vector<ipaddress_type> servers_type;
396 
397  uint32_t lifetime;
398  servers_type servers;
399 
400  recursive_dns_type(uint32_t lifetime = 0,
401  const servers_type& servers = servers_type())
402  : lifetime(lifetime), servers(servers) {}
403 
404  static recursive_dns_type from_option(const option& opt);
405  };
406 
411  typedef std::vector<uint8_t> key_type;
412 
413  small_uint<4> AT;
414  key_type key;
415 
417  const key_type& key = key_type())
418  : AT(AT), key(key) { }
419 
420  static handover_key_req_type from_option(const option& opt);
421  };
422 
427  uint16_t lifetime;
428 
429  handover_key_reply_type(uint16_t lifetime = 0,
430  small_uint<4> AT = 0,
431  const key_type& key = key_type())
432  : handover_key_req_type(AT, key), lifetime(lifetime) { }
433 
434  static handover_key_reply_type from_option(const option& opt);
435  };
436 
441  typedef std::vector<uint8_t> hai_type;
442 
443  uint8_t option_code;
444  hai_type hai;
445 
446  handover_assist_info_type(uint8_t option_code=0,
447  const hai_type& hai = hai_type())
448  : option_code(option_code), hai(hai) { }
449 
450  static handover_assist_info_type from_option(const option& opt);
451  };
452 
457  typedef std::vector<uint8_t> mn_type;
458 
459  uint8_t option_code;
460  mn_type mn;
461 
462  mobile_node_id_type(uint8_t option_code=0,
463  const mn_type& mn = mn_type())
464  : option_code(option_code), mn(mn) { }
465 
466  static mobile_node_id_type from_option(const option& opt);
467  };
468 
473  typedef std::vector<std::string> domains_type;
474 
475  uint32_t lifetime;
476  domains_type domains;
477 
478  dns_search_list_type(uint32_t lifetime = 0,
479  const domains_type& domains = domains_type())
480  : lifetime(lifetime), domains(domains) { }
481 
482  static dns_search_list_type from_option(const option& opt);
483  };
484 
488  struct timestamp_type {
489  uint8_t reserved[6];
490  uint64_t timestamp;
491 
492  timestamp_type(uint64_t timestamp = 0)
493  : timestamp(timestamp) {
494  std::fill(reserved, reserved + sizeof(reserved), static_cast<uint8_t>(0));
495  }
496 
497  static timestamp_type from_option(const option& opt);
498  };
499 
504  uint8_t limit, reserved1;
505  uint32_t reserved2;
506 
507  shortcut_limit_type(uint8_t limit = 0)
508  : limit(limit), reserved1(), reserved2() {
509 
510  }
511 
512  static shortcut_limit_type from_option(const option& opt);
513  };
514 
519  uint16_t reserved;
520  uint32_t interval;
521 
522  new_advert_interval_type(uint32_t interval = 0)
523  : reserved(), interval(interval) {
524 
525  }
526 
527  static new_advert_interval_type from_option(const option& opt);
528  };
529 
534  typedef std::vector<ipaddress_type> sources_type;
535  typedef std::vector<uint8_t> aux_data_type;
536 
537  multicast_address_record(uint8_t type = 0) : type(type) { }
538 
539  multicast_address_record(const uint8_t* buffer, uint32_t total_sz);
540  void serialize(uint8_t* buffer, uint32_t total_sz) const;
541  uint32_t size() const;
542 
543  uint8_t type;
544  ipaddress_type multicast_address;
545  sources_type sources;
546  aux_data_type aux_data;
547  };
548 
549  /*
550  * The type used to store all multicast address records in a packet
551  */
552  typedef std::vector<multicast_address_record> multicast_address_records_list;
553 
554  /*
555  * The type used to store all source address (from Multicast
556  * Listener Query messages) in a packet
557  */
558  typedef std::vector<ipaddress_type> sources_list;
559 
568  ICMPv6(Types tp = ECHO_REQUEST);
569 
581  ICMPv6(const uint8_t* buffer, uint32_t total_sz);
582 
583  // Getters
584 
589  Types type() const {
590  return static_cast<Types>(header_.type);
591  }
592 
597  uint8_t code() const {
598  return header_.code;
599  }
600 
605  uint16_t checksum() const {
606  return Endian::be_to_host(header_.cksum);
607  }
608 
613  uint16_t identifier() const {
614  return Endian::be_to_host(header_.u_echo.identifier);
615  }
616 
621  uint16_t sequence() const {
622  return Endian::be_to_host(header_.u_echo.sequence);
623  }
624 
629  small_uint<1> override() const {
630  return header_.u_nd_advt.override;
631  }
632 
638  return header_.u_nd_advt.solicited;
639  }
640 
646  return header_.u_nd_advt.router;
647  }
648 
653  uint8_t hop_limit() const {
654  return header_.u_nd_ra.hop_limit;
655  }
656 
661  uint16_t maximum_response_code() const {
662  return Endian::be_to_host(header_.u_echo.identifier);
663  }
664 
670  return header_.u_nd_ra.router_pref;
671  }
672 
678  return header_.u_nd_ra.home_agent;
679  }
680 
686  return header_.u_nd_ra.other;
687  }
688 
694  return header_.u_nd_ra.managed;
695  }
696 
701  uint16_t router_lifetime() const {
702  return Endian::be_to_host(header_.u_nd_ra.router_lifetime);
703  }
704 
709  uint32_t reachable_time() const {
710  return Endian::be_to_host(reach_time_);
711  }
712 
717  uint32_t retransmit_timer() const {
718  return Endian::be_to_host(retrans_timer_);
719  }
720 
725  const ipaddress_type& target_addr() const {
726  return target_address_;
727  }
728 
733  const ipaddress_type& dest_addr() const {
734  return dest_address_;
735  }
736 
745  return multicast_address_;
746  }
747 
752  const options_type& options() const {
753  return options_;
754  }
755 
761  uint8_t length() const {
762  return header_.rfc4884.length;
763  }
764 
768  const multicast_address_records_list& multicast_address_records() const {
769  return multicast_records_;
770  }
771 
778  const sources_list& sources() const {
779  return sources_;
780  }
781 
789  return mlqm_.supress;
790  }
791 
798  small_uint<3> qrv() const {
799  return mlqm_.qrv;
800  }
801 
808  uint8_t qqic() const {
809  return mlqm_.qqic;
810  }
811 
812  // Setters
813 
818  void type(Types new_type);
819 
824  void code(uint8_t new_code);
825 
830  void checksum(uint16_t new_cksum);
831 
836  void identifier(uint16_t new_identifier);
837 
842  void sequence(uint16_t new_sequence);
843 
848  void override(small_uint<1> new_override);
849 
854  void solicited(small_uint<1> new_solicited);
855 
860  void router(small_uint<1> new_router);
861 
866  void hop_limit(uint8_t new_hop_limit);
867 
872  void maximum_response_code(uint16_t maximum_response_code);
873 
878  void router_pref(small_uint<2> new_router_pref);
879 
884  void home_agent(small_uint<1> new_home_agent);
885 
890  void other(small_uint<1> new_other);
891 
896  void managed(small_uint<1> new_managed);
897 
902  void router_lifetime(uint16_t new_router_lifetime);
903 
908  void target_addr(const ipaddress_type& new_target_addr);
909 
914  void dest_addr(const ipaddress_type& new_dest_addr);
915 
923  void multicast_addr(const ipaddress_type& new_multicast_addr);
924 
929  void reachable_time(uint32_t new_reachable_time);
930 
935  void retransmit_timer(uint32_t new_retrans_timer);
936 
942  void multicast_address_records(const multicast_address_records_list& records);
943 
949  void sources(const sources_list& new_sources);
950 
956  void supress(small_uint<1> value);
957 
963  void qrv(small_uint<3> value);
964 
970  void qqic(uint8_t value);
971 
977  PDUType pdu_type() const { return pdu_flag; }
978 
984  bool has_target_addr() const {
985  return type() == NEIGHBOUR_SOLICIT ||
986  type() == NEIGHBOUR_ADVERT ||
987  type() == REDIRECT;
988  }
989 
995  bool has_dest_addr() const {
996  return type() == REDIRECT;
997  }
998 
1007  void add_option(const option& option);
1008 
1009  #if TINS_IS_CXX11
1018  internal_add_option(option);
1019  options_.push_back(std::move(option));
1020  }
1021  #endif
1022 
1032  bool remove_option(OptionTypes type);
1033 
1040  uint32_t header_size() const;
1041 
1049  uint32_t trailer_size() const;
1050 
1057  return extensions_;
1058  }
1059 
1066  return extensions_;
1067  }
1068 
1072  bool has_extensions() const {
1073  return !extensions_.extensions().empty();
1074  }
1075 
1091  void use_length_field(bool value);
1092 
1100  bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
1101 
1111  const option* search_option(OptionTypes type) const;
1112 
1116  ICMPv6* clone() const {
1117  return new ICMPv6(*this);
1118  }
1119 
1129  void use_mldv2(bool value);
1130 
1131  // ****************************************************************
1132  // Option setters
1133  // ****************************************************************
1134 
1140  void source_link_layer_addr(const hwaddress_type& addr);
1141 
1147  void target_link_layer_addr(const hwaddress_type& addr);
1148 
1154  void prefix_info(prefix_info_type info);
1155 
1161  void redirect_header(const byte_array& data);
1162 
1168  void mtu(const mtu_type& value);
1169 
1175  void shortcut_limit(const shortcut_limit_type& value);
1176 
1182  void new_advert_interval(const new_advert_interval_type& value);
1183 
1189  void new_home_agent_info(const new_ha_info_type& value);
1190 
1196  void source_addr_list(const addr_list_type& value);
1197 
1203  void target_addr_list(const addr_list_type& value);
1204 
1210  void rsa_signature(const rsa_sign_type& value);
1211 
1217  void timestamp(const timestamp_type& value);
1218 
1224  void nonce(const nonce_type& value);
1225 
1231  void ip_prefix(const ip_prefix_type& value);
1232 
1238  void link_layer_addr(lladdr_type value);
1239 
1245  void naack(const naack_type& value);
1246 
1252  void map(const map_type& value);
1253 
1259  void route_info(const route_info_type& value);
1260 
1266  void recursive_dns_servers(const recursive_dns_type& value);
1267 
1273  void handover_key_request(const handover_key_req_type& value);
1274 
1280  void handover_key_reply(const handover_key_reply_type& value);
1281 
1287  void handover_assist_info(const handover_assist_info_type& value);
1288 
1294  void mobile_node_identifier(const mobile_node_id_type& value);
1295 
1301  void dns_search_list(const dns_search_list_type& value);
1302 
1303  // ****************************************************************
1304  // Option getters
1305  // ****************************************************************
1306 
1313  hwaddress_type source_link_layer_addr() const;
1314 
1321  hwaddress_type target_link_layer_addr() const;
1322 
1329  prefix_info_type prefix_info() const;
1330 
1337  byte_array redirect_header() const;
1338 
1345  mtu_type mtu() const;
1346 
1353  shortcut_limit_type shortcut_limit() const;
1354 
1361  new_advert_interval_type new_advert_interval() const;
1362 
1369  new_ha_info_type new_home_agent_info() const;
1370 
1377  addr_list_type source_addr_list() const;
1378 
1385  addr_list_type target_addr_list() const;
1386 
1393  rsa_sign_type rsa_signature() const;
1394 
1401  timestamp_type timestamp() const;
1402 
1409  nonce_type nonce() const;
1410 
1417  ip_prefix_type ip_prefix() const;
1418 
1425  lladdr_type link_layer_addr() const;
1426 
1434  naack_type naack() const;
1435 
1442  map_type map() const;
1443 
1450  route_info_type route_info() const;
1451 
1458  recursive_dns_type recursive_dns_servers() const;
1459 
1466  handover_key_req_type handover_key_request() const;
1467 
1474  handover_key_reply_type handover_key_reply() const;
1475 
1482  handover_assist_info_type handover_assist_info() const;
1483 
1490  mobile_node_id_type mobile_node_identifier() const;
1491 
1498  dns_search_list_type dns_search_list() const;
1499 private:
1500  TINS_BEGIN_PACK
1501  struct icmp6_header {
1502  uint8_t type;
1503  uint8_t code;
1504  uint16_t cksum;
1505  union {
1506  struct {
1507  uint16_t identifier;
1508  uint16_t sequence;
1509  } u_echo;
1510 
1511  struct {
1512  #if TINS_IS_LITTLE_ENDIAN
1513  uint32_t reserved:5,
1514  override:1,
1515  solicited:1,
1516  router:1,
1517  reserved2:24;
1518  #else
1519  uint32_t router:1,
1520  solicited:1,
1521  override:1,
1522  reserved:29;
1523  #endif
1524  } u_nd_advt;
1525  struct {
1526  uint8_t hop_limit;
1527  #if TINS_IS_LITTLE_ENDIAN
1528  uint8_t reserved:3,
1529  router_pref:2,
1530  home_agent:1,
1531  other:1,
1532  managed:1;
1533  #else
1534  uint8_t managed:1,
1535  other:1,
1536  home_agent:1,
1537  router_pref:2,
1538  reserved:3;
1539  #endif
1540  uint16_t router_lifetime;
1541  } u_nd_ra;
1542  struct {
1543  uint8_t length;
1544  uint8_t unused[3];
1545  } rfc4884;
1546  // Multicast Listener Report Message (mld2)
1547  struct {
1548  uint16_t reserved;
1549  uint16_t record_count;
1550  } mlrm2;
1551  };
1552  } TINS_END_PACK;
1553 
1554  TINS_BEGIN_PACK
1555  struct multicast_listener_query_message_fields {
1556  uint8_t reserved:4,
1557  supress:1,
1558  qrv:3;
1559  uint8_t qqic;
1560  } TINS_END_PACK;
1561 
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);
1575 
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();
1581  }
1582  return option;
1583  }
1584 
1585  template <typename T>
1586  T search_and_convert(OptionTypes type) const {
1587  const option* opt = search_option(type);
1588  if (!opt) {
1589  throw option_not_found();
1590  }
1591  return opt->to<T>();
1592  }
1593 
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_;
1605  bool use_mldv2_;
1606 };
1607 
1608 } // Tins
1609 
1610 #endif // TINS_ICMPV6_H
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
Definition: icmpv6.h:170
Definition: icmpv6.h:472
Definition: icmpv6.h:410
Definition: icmpv6.h:337
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
Definition: icmpv6.h:353
Definition: icmpv6.h:456
The type used to store the neighbour advertisement acknowledgement option data.
Definition: icmpv6.h:198
Definition: icmpv6.h:251
Definition: icmpv6.h:394
Definition: icmpv6.h:373
Definition: icmpv6.h:274
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
Definition: icmpv6.h:503
Definition: icmpv6.h:488