PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/epan/dissectors/packet-ipv6.c

https://github.com/labx-technologies-llc/wireshark
C | 2899 lines | 2426 code | 305 blank | 168 comment | 169 complexity | 2808ed312cbe5e2ce39bfb3744b7a63c MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /* packet-ipv6.c
  2. * Routines for IPv6 packet disassembly
  3. *
  4. * $Id$
  5. *
  6. * Wireshark - Network traffic analyzer
  7. * By Gerald Combs <gerald@wireshark.org>
  8. * Copyright 1998 Gerald Combs
  9. *
  10. * SHIM6 support added by Matthijs Mekking <matthijs@NLnetLabs.nl>
  11. *
  12. * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  27. */
  28. #include "config.h"
  29. #include <math.h>
  30. #include <glib.h>
  31. #include <epan/packet.h>
  32. #include <epan/expert.h>
  33. #include <epan/ip_opts.h>
  34. #include <epan/addr_resolv.h>
  35. #include <epan/prefs.h>
  36. #include <epan/reassemble.h>
  37. #include <epan/ipproto.h>
  38. #include <epan/ipv6-utils.h>
  39. #include <epan/etypes.h>
  40. #include <epan/ppptypes.h>
  41. #include <epan/aftypes.h>
  42. #include <epan/nlpid.h>
  43. #include <epan/arcnet_pids.h>
  44. #include <epan/in_cksum.h>
  45. #include <epan/expert.h>
  46. #include <epan/emem.h>
  47. #include <epan/tap.h>
  48. #include "packet-ipsec.h"
  49. #include "packet-ipv6.h"
  50. #include "packet-ip.h"
  51. #ifdef HAVE_GEOIP_V6
  52. #include <GeoIP.h>
  53. #include <epan/geoip_db.h>
  54. #endif /* HAVE_GEOIP_V6 */
  55. /* Differentiated Services Field. See RFCs 2474, 2597 and 2598. */
  56. #define IPDSFIELD_DSCP_MASK 0xFC
  57. #define IPDSFIELD_ECN_MASK 0x03
  58. #define IPDSFIELD_DSCP_SHIFT 2
  59. #define IPDSFIELD_DSCP(dsfield) (((dsfield)&IPDSFIELD_DSCP_MASK)>>IPDSFIELD_DSCP_SHIFT)
  60. #define IPDSFIELD_ECN(dsfield) ((dsfield)&IPDSFIELD_ECN_MASK)
  61. #define IPDSFIELD_DSCP_DEFAULT 0x00
  62. #define IPDSFIELD_DSCP_CS1 0x08
  63. #define IPDSFIELD_DSCP_CS2 0x10
  64. #define IPDSFIELD_DSCP_CS3 0x18
  65. #define IPDSFIELD_DSCP_CS4 0x20
  66. #define IPDSFIELD_DSCP_CS5 0x28
  67. #define IPDSFIELD_DSCP_CS6 0x30
  68. #define IPDSFIELD_DSCP_CS7 0x38
  69. #define IPDSFIELD_DSCP_AF11 0x0A
  70. #define IPDSFIELD_DSCP_AF12 0x0C
  71. #define IPDSFIELD_DSCP_AF13 0x0E
  72. #define IPDSFIELD_DSCP_AF21 0x12
  73. #define IPDSFIELD_DSCP_AF22 0x14
  74. #define IPDSFIELD_DSCP_AF23 0x16
  75. #define IPDSFIELD_DSCP_AF31 0x1A
  76. #define IPDSFIELD_DSCP_AF32 0x1C
  77. #define IPDSFIELD_DSCP_AF33 0x1E
  78. #define IPDSFIELD_DSCP_AF41 0x22
  79. #define IPDSFIELD_DSCP_AF42 0x24
  80. #define IPDSFIELD_DSCP_AF43 0x26
  81. #define IPDSFIELD_DSCP_EF 0x2E
  82. #define IPDSFIELD_ECT_MASK 0x02
  83. #define IPDSFIELD_CE_MASK 0x01
  84. /* RPL Routing header */
  85. #define IP6RRPL_BITMASK_CMPRI 0xF0000000
  86. #define IP6RRPL_BITMASK_CMPRE 0x0F000000
  87. #define IP6RRPL_BITMASK_PAD 0x00F00000
  88. #define IP6RRPL_BITMASK_RESERVED 0x000FFFFF
  89. static int ipv6_tap = -1;
  90. static int proto_ipv6 = -1;
  91. static int hf_ipv6_version = -1;
  92. static int hf_ip_version = -1;
  93. static int hf_ipv6_class = -1;
  94. static int hf_ipv6_flow = -1;
  95. static int hf_ipv6_plen = -1;
  96. static int hf_ipv6_nxt = -1;
  97. static int hf_ipv6_hlim = -1;
  98. static int hf_ipv6_src = -1;
  99. static int hf_ipv6_src_host = -1;
  100. static int hf_ipv6_src_sa_mac = -1;
  101. static int hf_ipv6_src_isatap_ipv4 = -1;
  102. static int hf_ipv6_src_6to4_gateway_ipv4 = -1;
  103. static int hf_ipv6_src_6to4_sla_id = -1;
  104. static int hf_ipv6_src_teredo_server_ipv4 = -1;
  105. static int hf_ipv6_src_teredo_port = -1;
  106. static int hf_ipv6_src_teredo_client_ipv4 = -1;
  107. static int hf_ipv6_dst = -1;
  108. static int hf_ipv6_dst_host = -1;
  109. static int hf_ipv6_dst_sa_mac = -1;
  110. static int hf_ipv6_dst_isatap_ipv4 = -1;
  111. static int hf_ipv6_dst_6to4_gateway_ipv4 = -1;
  112. static int hf_ipv6_dst_6to4_sla_id = -1;
  113. static int hf_ipv6_dst_teredo_server_ipv4 = -1;
  114. static int hf_ipv6_dst_teredo_port = -1;
  115. static int hf_ipv6_dst_teredo_client_ipv4 = -1;
  116. static int hf_ipv6_addr = -1;
  117. static int hf_ipv6_host = -1;
  118. static int hf_ipv6_sa_mac = -1;
  119. static int hf_ipv6_isatap_ipv4 = -1;
  120. static int hf_ipv6_6to4_gateway_ipv4 = -1;
  121. static int hf_ipv6_6to4_sla_id = -1;
  122. static int hf_ipv6_teredo_server_ipv4 = -1;
  123. static int hf_ipv6_teredo_port = -1;
  124. static int hf_ipv6_teredo_client_ipv4 = -1;
  125. static int hf_ipv6_opt = -1;
  126. static int hf_ipv6_opt_type = -1;
  127. static int hf_ipv6_opt_length = -1;
  128. static int hf_ipv6_opt_pad1 = -1;
  129. static int hf_ipv6_opt_padn = -1;
  130. static int hf_ipv6_opt_tel = -1;
  131. static int hf_ipv6_opt_rtalert = -1;
  132. static int hf_ipv6_opt_jumbo = -1;
  133. static int hf_ipv6_opt_calipso_doi = -1;
  134. static int hf_ipv6_opt_calipso_cmpt_length = -1;
  135. static int hf_ipv6_opt_calipso_sens_level = -1;
  136. static int hf_ipv6_opt_calipso_checksum = -1;
  137. static int hf_ipv6_opt_calipso_cmpt_bitmap = -1;
  138. static int hf_ipv6_opt_qs_func = -1;
  139. static int hf_ipv6_opt_qs_rate = -1;
  140. static int hf_ipv6_opt_qs_ttl = -1;
  141. static int hf_ipv6_opt_qs_ttl_diff = -1;
  142. static int hf_ipv6_opt_qs_unused = -1;
  143. static int hf_ipv6_opt_qs_nonce = -1;
  144. static int hf_ipv6_opt_qs_reserved = -1;
  145. static int hf_ipv6_opt_rpl_flag = -1;
  146. static int hf_ipv6_opt_rpl_flag_o = -1;
  147. static int hf_ipv6_opt_rpl_flag_r = -1;
  148. static int hf_ipv6_opt_rpl_flag_f = -1;
  149. static int hf_ipv6_opt_rpl_flag_rsv = -1;
  150. static int hf_ipv6_opt_rpl_instance_id = -1;
  151. static int hf_ipv6_opt_rpl_senderrank = -1;
  152. static int hf_ipv6_opt_experimental = -1;
  153. static int hf_ipv6_opt_unknown = -1;
  154. static int hf_ipv6_dst_opt = -1;
  155. static int hf_ipv6_hop_opt = -1;
  156. static int hf_ipv6_unk_hdr = -1;
  157. static int hf_ipv6_routing_hdr_opt = -1;
  158. static int hf_ipv6_routing_hdr_type = -1;
  159. static int hf_ipv6_routing_hdr_left = -1;
  160. static int hf_ipv6_routing_hdr_addr = -1;
  161. static int hf_ipv6_frag_nxt = -1;
  162. static int hf_ipv6_frag_reserved = -1;
  163. static int hf_ipv6_frag_offset = -1;
  164. static int hf_ipv6_frag_reserved_bits = -1;
  165. static int hf_ipv6_frag_more = -1;
  166. static int hf_ipv6_frag_id = -1;
  167. static int hf_ipv6_fragments = -1;
  168. static int hf_ipv6_fragment = -1;
  169. static int hf_ipv6_fragment_overlap = -1;
  170. static int hf_ipv6_fragment_overlap_conflict = -1;
  171. static int hf_ipv6_fragment_multiple_tails = -1;
  172. static int hf_ipv6_fragment_too_long_fragment = -1;
  173. static int hf_ipv6_fragment_error = -1;
  174. static int hf_ipv6_fragment_count = -1;
  175. static int hf_ipv6_reassembled_in = -1;
  176. static int hf_ipv6_reassembled_length = -1;
  177. static int hf_ipv6_reassembled_data = -1;
  178. static int hf_ipv6_mipv6_home_address = -1;
  179. static int hf_ipv6_routing_hdr_rpl_cmprI = -1;
  180. static int hf_ipv6_routing_hdr_rpl_cmprE = -1;
  181. static int hf_ipv6_routing_hdr_rpl_pad = -1;
  182. static int hf_ipv6_routing_hdr_rpl_reserved = -1;
  183. static int hf_ipv6_routing_hdr_rpl_segments = -1;
  184. static int hf_ipv6_routing_hdr_rpl_addr = -1;
  185. static int hf_ipv6_routing_hdr_rpl_fulladdr = -1;
  186. static int hf_ipv6_shim6 = -1;
  187. static int hf_ipv6_shim6_nxt = -1;
  188. static int hf_ipv6_shim6_len = -1;
  189. static int hf_ipv6_shim6_p = -1;
  190. /* context tag is 49 bits, cannot be used for filter yet */
  191. static int hf_ipv6_shim6_ct = -1;
  192. static int hf_ipv6_shim6_type = -1;
  193. static int hf_ipv6_shim6_proto = -1;
  194. static int hf_ipv6_shim6_checksum = -1;
  195. static int hf_ipv6_shim6_checksum_bad = -1;
  196. static int hf_ipv6_shim6_checksum_good = -1;
  197. static int hf_ipv6_shim6_inonce = -1; /* also for request nonce */
  198. static int hf_ipv6_shim6_rnonce = -1;
  199. static int hf_ipv6_shim6_precvd = -1;
  200. static int hf_ipv6_shim6_psent = -1;
  201. static int hf_ipv6_shim6_psrc = -1;
  202. static int hf_ipv6_shim6_pdst = -1;
  203. static int hf_ipv6_shim6_pnonce = -1;
  204. static int hf_ipv6_shim6_pdata = -1;
  205. static int hf_ipv6_shim6_sulid = -1;
  206. static int hf_ipv6_shim6_rulid = -1;
  207. static int hf_ipv6_shim6_reap = -1;
  208. static int hf_ipv6_shim6_opt_type = -1;
  209. static int hf_ipv6_shim6_opt_len = -1;
  210. static int hf_ipv6_shim6_opt_total_len = -1;
  211. static int hf_ipv6_shim6_opt_loc_verif_methods = -1;
  212. static int hf_ipv6_shim6_opt_critical = -1;
  213. static int hf_ipv6_shim6_opt_loclist = -1;
  214. static int hf_ipv6_shim6_locator = -1;
  215. static int hf_ipv6_shim6_loc_flag = -1;
  216. static int hf_ipv6_shim6_loc_prio = -1;
  217. static int hf_ipv6_shim6_loc_weight = -1;
  218. static int hf_ipv6_shim6_opt_locnum = -1;
  219. static int hf_ipv6_shim6_opt_elemlen = -1;
  220. static int hf_ipv6_shim6_opt_fii = -1;
  221. static int hf_ipv6_traffic_class_dscp = -1;
  222. static int hf_ipv6_traffic_class_ect = -1;
  223. static int hf_ipv6_traffic_class_ce = -1;
  224. #ifdef HAVE_GEOIP_V6
  225. static int hf_geoip_country = -1;
  226. static int hf_geoip_city = -1;
  227. static int hf_geoip_org = -1;
  228. static int hf_geoip_isp = -1;
  229. static int hf_geoip_asnum = -1;
  230. static int hf_geoip_lat = -1;
  231. static int hf_geoip_lon = -1;
  232. static int hf_geoip_src_country = -1;
  233. static int hf_geoip_src_city = -1;
  234. static int hf_geoip_src_org = -1;
  235. static int hf_geoip_src_isp = -1;
  236. static int hf_geoip_src_asnum = -1;
  237. static int hf_geoip_src_lat = -1;
  238. static int hf_geoip_src_lon = -1;
  239. static int hf_geoip_dst_country = -1;
  240. static int hf_geoip_dst_city = -1;
  241. static int hf_geoip_dst_org = -1;
  242. static int hf_geoip_dst_isp = -1;
  243. static int hf_geoip_dst_asnum = -1;
  244. static int hf_geoip_dst_lat = -1;
  245. static int hf_geoip_dst_lon = -1;
  246. #endif /* HAVE_GEOIP_V6 */
  247. static gint ett_ipv6 = -1;
  248. static gint ett_ipv6_opt = -1;
  249. static gint ett_ipv6_opt_flag = -1;
  250. static gint ett_ipv6_version = -1;
  251. static gint ett_ipv6_shim6 = -1;
  252. static gint ett_ipv6_shim6_option = -1;
  253. static gint ett_ipv6_shim6_locators = -1;
  254. static gint ett_ipv6_shim6_verif_methods = -1;
  255. static gint ett_ipv6_shim6_loc_pref = -1;
  256. static gint ett_ipv6_shim6_probes_sent = -1;
  257. static gint ett_ipv6_shim6_probe_sent = -1;
  258. static gint ett_ipv6_shim6_probes_rcvd = -1;
  259. static gint ett_ipv6_shim6_probe_rcvd = -1;
  260. static gint ett_ipv6_shim6_cksum = -1;
  261. static gint ett_ipv6_fragments = -1;
  262. static gint ett_ipv6_fragment = -1;
  263. static gint ett_ipv6_traffic_class = -1;
  264. #ifdef HAVE_GEOIP_V6
  265. static gint ett_geoip_info = -1;
  266. #endif /* HAVE_GEOIP_V6 */
  267. static expert_field ei_ipv6_dst_addr_not_multicast = EI_INIT;
  268. static expert_field ei_ipv6_src_route_list_mult_inst_same_addr = EI_INIT;
  269. static expert_field ei_ipv6_src_route_list_src_addr = EI_INIT;
  270. static expert_field ei_ipv6_src_route_list_dst_addr = EI_INIT;
  271. static expert_field ei_ipv6_src_route_list_multicast_addr = EI_INIT;
  272. static expert_field ei_ipv6_cmpri_cmpre_pad = EI_INIT;
  273. static expert_field ei_ipv6_routing_hdr_rpl_reserved = EI_INIT;
  274. static expert_field ei_ipv6_opt_tel_invalid_len = EI_INIT;
  275. static expert_field ei_ipv6_opt_jumbo_invalid_len = EI_INIT;
  276. static expert_field ei_ipv6_opt_rtalert_invalid_len = EI_INIT;
  277. static expert_field ei_ipv6_mipv6_home_address_invalid_len = EI_INIT;
  278. static expert_field ei_ipv6_shim6_opt_elemlen_invalid = EI_INIT;
  279. static expert_field ei_ipv6_shim6_checksum_bad = EI_INIT;
  280. static expert_field ei_ipv6_routing_hdr_rpl_segments_ge0 = EI_INIT;
  281. static const fragment_items ipv6_frag_items = {
  282. &ett_ipv6_fragment,
  283. &ett_ipv6_fragments,
  284. &hf_ipv6_fragments,
  285. &hf_ipv6_fragment,
  286. &hf_ipv6_fragment_overlap,
  287. &hf_ipv6_fragment_overlap_conflict,
  288. &hf_ipv6_fragment_multiple_tails,
  289. &hf_ipv6_fragment_too_long_fragment,
  290. &hf_ipv6_fragment_error,
  291. &hf_ipv6_fragment_count,
  292. &hf_ipv6_reassembled_in,
  293. &hf_ipv6_reassembled_length,
  294. &hf_ipv6_reassembled_data,
  295. "IPv6 fragments"
  296. };
  297. static dissector_handle_t data_handle;
  298. static dissector_table_t ip_dissector_table;
  299. /* Reassemble fragmented datagrams */
  300. static gboolean ipv6_reassemble = TRUE;
  301. /* Place IPv6 summary in proto tree */
  302. static gboolean ipv6_summary_in_tree = TRUE;
  303. #ifdef HAVE_GEOIP_V6
  304. /* Look up addresses in GeoIP */
  305. static gboolean ipv6_use_geoip = TRUE;
  306. #endif /* HAVE_GEOIP_V6 */
  307. /* Perform strict RFC adherence checking */
  308. static gboolean g_ipv6_rpl_srh_strict_rfc_checking = FALSE;
  309. #ifndef offsetof
  310. #define offsetof(type, member) ((size_t)(&((type *)0)->member))
  311. #endif
  312. /*
  313. * defragmentation of IPv6
  314. */
  315. static reassembly_table ipv6_reassembly_table;
  316. /* http://www.iana.org/assignments/icmpv6-parameters (last updated 2012-12-22) */
  317. static const value_string ipv6_opt_vals[] = {
  318. { IP6OPT_PAD1, "Pad1" },
  319. { IP6OPT_PADN, "PadN" },
  320. { IP6OPT_TEL, "Tunnel Encapsulation Limit" },
  321. { IP6OPT_RTALERT, "Router Alert" },
  322. { IP6OPT_CALIPSO, "Calipso" },
  323. { IP6OPT_QUICKSTART, "Quick Start" },
  324. { IP6OPT_ENDI, "Endpoint Identification" },
  325. { IP6OPT_EXP_1E, "Experimental (0x1E)" },
  326. { IP6OPT_EXP_3E, "Experimental (0x3E)" },
  327. { IP6OPT_EXP_5E, "Experimental (0x5E)" },
  328. { IP6OPT_RPL, "RPL Option" },
  329. { IP6OPT_EXP_7E, "Experimental (0x7E)" },
  330. { IP6OPT_EXP_9E, "Experimental (0x9E)" },
  331. { IP6OPT_EXP_BE, "Experimental (0xBE)" },
  332. { IP6OPT_JUMBO, "Jumbo" },
  333. { IP6OPT_HOME_ADDRESS, "Home Address" },
  334. { IP6OPT_EXP_DE, "Experimental (0xDE)" },
  335. { IP6OPT_EXP_FE, "Experimental (0xFE)" },
  336. { 0, NULL }
  337. };
  338. void
  339. capture_ipv6(const guchar *pd, int offset, int len, packet_counts *ld)
  340. {
  341. guint8 nxt;
  342. int advance;
  343. if (!BYTES_ARE_IN_FRAME(offset, len, 4+4+16+16)) {
  344. ld->other++;
  345. return;
  346. }
  347. nxt = pd[offset+6]; /* get the "next header" value */
  348. offset += 4+4+16+16; /* skip past the IPv6 header */
  349. again:
  350. switch (nxt) {
  351. case IP_PROTO_HOPOPTS:
  352. case IP_PROTO_ROUTING:
  353. case IP_PROTO_DSTOPTS:
  354. if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
  355. ld->other++;
  356. return;
  357. }
  358. nxt = pd[offset];
  359. advance = (pd[offset+1] + 1) << 3;
  360. if (!BYTES_ARE_IN_FRAME(offset, len, advance)) {
  361. ld->other++;
  362. return;
  363. }
  364. offset += advance;
  365. goto again;
  366. case IP_PROTO_FRAGMENT:
  367. if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
  368. ld->other++;
  369. return;
  370. }
  371. nxt = pd[offset];
  372. advance = 8;
  373. if (!BYTES_ARE_IN_FRAME(offset, len, advance)) {
  374. ld->other++;
  375. return;
  376. }
  377. offset += advance;
  378. goto again;
  379. case IP_PROTO_AH:
  380. if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
  381. ld->other++;
  382. return;
  383. }
  384. nxt = pd[offset];
  385. advance = 8 + ((pd[offset+1] - 1) << 2);
  386. if (!BYTES_ARE_IN_FRAME(offset, len, advance)) {
  387. ld->other++;
  388. return;
  389. }
  390. offset += advance;
  391. goto again;
  392. case IP_PROTO_SHIM6:
  393. case IP_PROTO_SHIM6_OLD:
  394. if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
  395. ld->other++;
  396. return;
  397. }
  398. nxt = pd[offset];
  399. advance = (pd[offset+1] + 1) << 3;
  400. if (!BYTES_ARE_IN_FRAME(offset, len, advance)) {
  401. ld->other++;
  402. return;
  403. }
  404. offset += advance;
  405. goto again;
  406. }
  407. switch(nxt) {
  408. case IP_PROTO_SCTP:
  409. ld->sctp++;
  410. break;
  411. case IP_PROTO_TCP:
  412. ld->tcp++;
  413. break;
  414. case IP_PROTO_UDP:
  415. case IP_PROTO_UDPLITE:
  416. ld->udp++;
  417. break;
  418. case IP_PROTO_ICMP:
  419. case IP_PROTO_ICMPV6: /* XXX - separate counters? */
  420. ld->icmp++;
  421. break;
  422. case IP_PROTO_OSPF:
  423. ld->ospf++;
  424. break;
  425. case IP_PROTO_GRE:
  426. ld->gre++;
  427. break;
  428. case IP_PROTO_VINES:
  429. ld->vines++;
  430. break;
  431. default:
  432. ld->other++;
  433. }
  434. }
  435. #ifdef HAVE_GEOIP_V6
  436. static void
  437. add_geoip_info_entry(proto_tree *geoip_info_item, tvbuff_t *tvb, gint offset, const struct e_in6_addr *ip, int isdst)
  438. {
  439. proto_tree *geoip_info_tree;
  440. guint num_dbs = geoip_db_num_dbs();
  441. guint item_cnt = 0;
  442. guint dbnum;
  443. geoip_info_tree = proto_item_add_subtree(geoip_info_item, ett_geoip_info);
  444. for (dbnum = 0; dbnum < num_dbs; dbnum++) {
  445. const char *geoip_str = geoip_db_lookup_ipv6(dbnum, *ip, NULL);
  446. int db_type = geoip_db_type(dbnum);
  447. int geoip_hf, geoip_local_hf;
  448. switch (db_type) {
  449. case GEOIP_COUNTRY_EDITION_V6:
  450. geoip_hf = hf_geoip_country;
  451. geoip_local_hf = (isdst) ? hf_geoip_dst_country : hf_geoip_src_country;
  452. break;
  453. #if NUM_DB_TYPES > 31
  454. case GEOIP_CITY_EDITION_REV0_V6:
  455. case GEOIP_CITY_EDITION_REV1_V6:
  456. geoip_hf = hf_geoip_city;
  457. geoip_local_hf = (isdst) ? hf_geoip_dst_city : hf_geoip_src_city;
  458. break;
  459. case GEOIP_ORG_EDITION_V6:
  460. geoip_hf = hf_geoip_org;
  461. geoip_local_hf = (isdst) ? hf_geoip_dst_org : hf_geoip_src_org;
  462. break;
  463. case GEOIP_ISP_EDITION_V6:
  464. geoip_hf = hf_geoip_isp;
  465. geoip_local_hf = (isdst) ? hf_geoip_dst_isp : hf_geoip_src_isp;
  466. break;
  467. case GEOIP_ASNUM_EDITION_V6:
  468. geoip_hf = hf_geoip_asnum;
  469. geoip_local_hf = (isdst) ? hf_geoip_dst_asnum : hf_geoip_src_asnum;
  470. break;
  471. #endif /* DB_NUM_TYPES */
  472. case WS_LAT_FAKE_EDITION:
  473. geoip_hf = hf_geoip_lat;
  474. geoip_local_hf = (isdst) ? hf_geoip_dst_lat : hf_geoip_src_lat;
  475. break;
  476. case WS_LON_FAKE_EDITION:
  477. geoip_hf = hf_geoip_lon;
  478. geoip_local_hf = (isdst) ? hf_geoip_dst_lon : hf_geoip_src_lon;
  479. break;
  480. default:
  481. continue;
  482. break;
  483. }
  484. if (geoip_str) {
  485. proto_item *item;
  486. if (db_type == WS_LAT_FAKE_EDITION || db_type == WS_LON_FAKE_EDITION) {
  487. /* Convert latitude, longitude to double. Fix bug #5077 */
  488. item = proto_tree_add_double_format_value(geoip_info_tree, geoip_local_hf, tvb,
  489. offset, 16, g_ascii_strtod(geoip_str, NULL), "%s", geoip_str);
  490. PROTO_ITEM_SET_GENERATED(item);
  491. item = proto_tree_add_double_format_value(geoip_info_tree, geoip_hf, tvb,
  492. offset, 16, g_ascii_strtod(geoip_str, NULL), "%s", geoip_str);
  493. PROTO_ITEM_SET_GENERATED(item);
  494. PROTO_ITEM_SET_HIDDEN(item);
  495. } else {
  496. item = proto_tree_add_unicode_string(geoip_info_tree, geoip_local_hf, tvb,
  497. offset, 16, geoip_str);
  498. PROTO_ITEM_SET_GENERATED(item);
  499. item = proto_tree_add_unicode_string(geoip_info_tree, geoip_hf, tvb,
  500. offset, 16, geoip_str);
  501. PROTO_ITEM_SET_GENERATED(item);
  502. PROTO_ITEM_SET_HIDDEN(item);
  503. }
  504. item_cnt++;
  505. proto_item_append_text(geoip_info_item, "%s%s", plurality(item_cnt, "", ", "), geoip_str);
  506. }
  507. }
  508. if (item_cnt == 0)
  509. proto_item_append_text(geoip_info_item, "Unknown");
  510. }
  511. static void
  512. add_geoip_info(proto_tree *tree, tvbuff_t *tvb, gint offset, const struct e_in6_addr *src, const struct e_in6_addr *dst)
  513. {
  514. guint num_dbs;
  515. proto_item *geoip_info_item;
  516. num_dbs = geoip_db_num_dbs();
  517. if (num_dbs < 1)
  518. return;
  519. geoip_info_item = proto_tree_add_text(tree, tvb, offset + IP6H_SRC, 16, "Source GeoIP: ");
  520. PROTO_ITEM_SET_GENERATED(geoip_info_item);
  521. add_geoip_info_entry(geoip_info_item, tvb, offset + IP6H_SRC, src, 0);
  522. geoip_info_item = proto_tree_add_text(tree, tvb, offset + IP6H_DST, 16, "Destination GeoIP: ");
  523. PROTO_ITEM_SET_GENERATED(geoip_info_item);
  524. add_geoip_info_entry(geoip_info_item, tvb, offset + IP6H_DST, dst, 1);
  525. }
  526. #endif /* HAVE_GEOIP_V6 */
  527. static void
  528. ipv6_reassemble_init(void)
  529. {
  530. reassembly_table_init(&ipv6_reassembly_table,
  531. &addresses_reassembly_table_functions);
  532. }
  533. enum {
  534. IPv6_RT_HEADER_SOURCE_ROUTING=0,
  535. IPv6_RT_HEADER_NIMROD,
  536. IPv6_RT_HEADER_MobileIP,
  537. IPv6_RT_HEADER_RPL
  538. };
  539. /* Routing Header Types */
  540. static const value_string routing_header_type[] = {
  541. { IPv6_RT_HEADER_SOURCE_ROUTING, "IPv6 Source Routing" },
  542. { IPv6_RT_HEADER_NIMROD, "Nimrod" },
  543. { IPv6_RT_HEADER_MobileIP, "Mobile IP" },
  544. { IPv6_RT_HEADER_RPL, "RPL" },
  545. { 0, NULL }
  546. };
  547. static int
  548. dissect_routing6(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info *pinfo) {
  549. struct ip6_rthdr rt;
  550. guint len, seg_left;
  551. proto_tree *rthdr_tree;
  552. proto_item *ti;
  553. guint8 buf[sizeof(struct ip6_rthdr0) + sizeof(struct e_in6_addr) * 23];
  554. tvb_memcpy(tvb, (guint8 *)&rt, offset, sizeof(rt));
  555. len = (rt.ip6r_len + 1) << 3;
  556. /* Assigning seg_left and the if (seg_left) {} blocks of code that follow,
  557. * along with any expert_add_info() calls, all need to execute when
  558. * appropriate, regardless of whether the tree is NULL or not. */
  559. if (1) {
  560. /* !!! specify length */
  561. ti = proto_tree_add_uint_format(tree, hf_ipv6_routing_hdr_opt, tvb,
  562. offset, len, rt.ip6r_type,
  563. "Routing Header, Type : %s (%u)",
  564. val_to_str_const(rt.ip6r_type, routing_header_type, "Unknown"),
  565. rt.ip6r_type);
  566. rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
  567. proto_tree_add_text(rthdr_tree, tvb,
  568. offset + (int)offsetof(struct ip6_rthdr, ip6r_nxt), 1,
  569. "Next header: %s (%u)", ipprotostr(rt.ip6r_nxt), rt.ip6r_nxt);
  570. proto_tree_add_text(rthdr_tree, tvb,
  571. offset + (int)offsetof(struct ip6_rthdr, ip6r_len), 1,
  572. "Length: %u (%d bytes)", rt.ip6r_len, len);
  573. proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_type, tvb,
  574. offset + (int)offsetof(struct ip6_rthdr, ip6r_type), 1, ENC_BIG_ENDIAN);
  575. proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_left, tvb,
  576. offset + (int)offsetof(struct ip6_rthdr, ip6r_segleft), 1, ENC_BIG_ENDIAN);
  577. seg_left = tvb_get_guint8(tvb, offset + (int)offsetof(struct ip6_rthdr, ip6r_segleft));
  578. if (rt.ip6r_type == IPv6_RT_HEADER_SOURCE_ROUTING && len <= sizeof(buf)) {
  579. struct e_in6_addr *a;
  580. int n;
  581. struct ip6_rthdr0 *rt0;
  582. tvb_memcpy(tvb, buf, offset, len);
  583. rt0 = (struct ip6_rthdr0 *)buf;
  584. for (a = rt0->ip6r0_addr, n = 0;
  585. a < (struct e_in6_addr *)(buf + len); a++, n++) {
  586. proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_addr, tvb,
  587. offset + (int)(offsetof(struct ip6_rthdr0, ip6r0_addr)
  588. + n * sizeof(struct e_in6_addr)),
  589. (int)sizeof(struct e_in6_addr), ENC_NA);
  590. if (seg_left)
  591. TVB_SET_ADDRESS(&pinfo->dst, AT_IPv6, tvb,
  592. offset + (int)offsetof(struct ip6_rthdr0, ip6r0_addr) + n * (int)sizeof(struct e_in6_addr), 16);
  593. }
  594. }
  595. if (rt.ip6r_type == IPv6_RT_HEADER_MobileIP) {
  596. proto_tree_add_item(rthdr_tree, hf_ipv6_mipv6_home_address, tvb,
  597. offset + 8, 16, ENC_NA);
  598. if (seg_left)
  599. TVB_SET_ADDRESS(&pinfo->dst, AT_IPv6, tvb, offset + 8, 16);
  600. }
  601. if (rt.ip6r_type == IPv6_RT_HEADER_RPL) {
  602. guint8 cmprI;
  603. guint8 cmprE;
  604. guint8 pad;
  605. guint32 reserved;
  606. gint segments;
  607. /* IPv6 destination address used for elided bytes */
  608. struct e_in6_addr dstAddr;
  609. /* IPv6 source address used for strict checking */
  610. struct e_in6_addr srcAddr;
  611. offset += 4;
  612. memcpy((guint8 *)&dstAddr, (guint8 *)pinfo->dst.data, pinfo->dst.len);
  613. memcpy((guint8 *)&srcAddr, (guint8 *)pinfo->src.data, pinfo->src.len);
  614. /* from RFC6554: Multicast addresses MUST NOT appear in the IPv6 Destination Address field */
  615. if(g_ipv6_rpl_srh_strict_rfc_checking && E_IN6_IS_ADDR_MULTICAST(&dstAddr)){
  616. expert_add_info(pinfo, ti, &ei_ipv6_dst_addr_not_multicast);
  617. }
  618. proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_cmprI, tvb, offset, 4, ENC_BIG_ENDIAN);
  619. proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_cmprE, tvb, offset, 4, ENC_BIG_ENDIAN);
  620. proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_pad, tvb, offset, 4, ENC_BIG_ENDIAN);
  621. cmprI = tvb_get_guint8(tvb, offset) & 0xF0;
  622. cmprE = tvb_get_guint8(tvb, offset) & 0x0F;
  623. pad = tvb_get_guint8(tvb, offset + 1) & 0xF0;
  624. /* Shift bytes over */
  625. cmprI >>= 4;
  626. pad >>= 4;
  627. /* from RFC6554: when CmprI and CmprE are both 0, Pad MUST carry a value of 0 */
  628. if(g_ipv6_rpl_srh_strict_rfc_checking && (cmprI == 0 && cmprE == 0 && pad != 0)){
  629. expert_add_info_format_text(pinfo, ti, &ei_ipv6_cmpri_cmpre_pad, "When cmprI equals 0 and cmprE equals 0, pad MUST equal 0 but instead was %d", pad);
  630. }
  631. proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
  632. reserved = tvb_get_bits32(tvb, ((offset + 1) * 8) + 4, 20, ENC_BIG_ENDIAN);
  633. if(g_ipv6_rpl_srh_strict_rfc_checking && reserved != 0){
  634. expert_add_info_format_text(pinfo, ti, &ei_ipv6_routing_hdr_rpl_reserved, "Reserved field must equal 0 but instead was %d", reserved);
  635. }
  636. /* from RFC6554:
  637. n = (((Hdr Ext Len * 8) - Pad - (16 - CmprE)) / (16 - CmprI)) + 1 */
  638. segments = (((rt.ip6r_len * 8) - pad - (16 - cmprE)) / (16 - cmprI)) + 1;
  639. ti = proto_tree_add_int(rthdr_tree, hf_ipv6_routing_hdr_rpl_segments, tvb, offset, 2, segments);
  640. PROTO_ITEM_SET_GENERATED(ti);
  641. if (segments < 0) {
  642. /* This error should always be reported */
  643. expert_add_info_format_text(pinfo, ti, &ei_ipv6_routing_hdr_rpl_segments_ge0, "Calculated total segments must be greater than or equal to 0, instead was %d", segments);
  644. } else {
  645. offset += 4;
  646. /* We use cmprI for internal (e.g.: not last) address for how many bytes to elide, so actual bytes present = 16-CmprI */
  647. while(segments > 1) {
  648. struct e_in6_addr addr;
  649. proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_addr, tvb, offset, (16-cmprI), ENC_NA);
  650. /* Display Full Address */
  651. memcpy((guint8 *)&addr, (guint8 *)&dstAddr, sizeof(dstAddr));
  652. tvb_memcpy(tvb, (guint8 *)&addr + cmprI, offset, (16-cmprI));
  653. ti = proto_tree_add_ipv6(rthdr_tree, hf_ipv6_routing_hdr_rpl_fulladdr, tvb, offset, (16-cmprI), (guint8 *)&addr);
  654. PROTO_ITEM_SET_GENERATED(ti);
  655. offset += (16-cmprI);
  656. segments--;
  657. if(g_ipv6_rpl_srh_strict_rfc_checking){
  658. /* from RFC6554: */
  659. /* The SRH MUST NOT specify a path that visits a node more than once. */
  660. /* To do this, we will just check the current 'addr' against the next addresses */
  661. gint tempSegments;
  662. gint tempOffset;
  663. tempSegments = segments; /* Has already been decremented above */
  664. tempOffset = offset; /* Has already been moved */
  665. while(tempSegments > 1) {
  666. struct e_in6_addr tempAddr;
  667. memcpy((guint8 *)&tempAddr, (guint8 *)&dstAddr, sizeof(dstAddr));
  668. tvb_memcpy(tvb, (guint8 *)&tempAddr + cmprI, tempOffset, (16-cmprI));
  669. /* Compare the addresses */
  670. if (memcmp(addr.bytes, tempAddr.bytes, 16) == 0) {
  671. /* Found a later address that is the same */
  672. expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_mult_inst_same_addr);
  673. break;
  674. }
  675. tempOffset += (16-cmprI);
  676. tempSegments--;
  677. }
  678. if (tempSegments == 1) {
  679. struct e_in6_addr tempAddr;
  680. memcpy((guint8 *)&tempAddr, (guint8 *)&dstAddr, sizeof(dstAddr));
  681. tvb_memcpy(tvb, (guint8 *)&tempAddr + cmprE, tempOffset, (16-cmprE));
  682. /* Compare the addresses */
  683. if (memcmp(addr.bytes, tempAddr.bytes, 16) == 0) {
  684. /* Found a later address that is the same */
  685. expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_mult_inst_same_addr);
  686. }
  687. }
  688. /* IPv6 Source and Destination addresses of the encapsulating datagram (MUST) not appear in the SRH*/
  689. if (memcmp(addr.bytes, srcAddr.bytes, 16) == 0) {
  690. expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_src_addr);
  691. }
  692. if (memcmp(addr.bytes, dstAddr.bytes, 16) == 0) {
  693. expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_dst_addr);
  694. }
  695. /* Multicast addresses MUST NOT appear in the in SRH */
  696. if(E_IN6_IS_ADDR_MULTICAST(&addr)){
  697. expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
  698. }
  699. }
  700. }
  701. /* We use cmprE for last address for how many bytes to elide, so actual bytes present = 16-CmprE */
  702. if (segments == 1) {
  703. struct e_in6_addr addr;
  704. proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_addr, tvb, offset, (16-cmprI), ENC_NA);
  705. /* Display Full Address */
  706. memcpy((guint8 *)&addr, (guint8 *)&dstAddr, sizeof(dstAddr));
  707. tvb_memcpy(tvb, (guint8 *)&addr + cmprE, offset, (16-cmprE));
  708. ti = proto_tree_add_ipv6(rthdr_tree, hf_ipv6_routing_hdr_rpl_fulladdr, tvb, offset, (16-cmprE), (guint8 *)&addr);
  709. PROTO_ITEM_SET_GENERATED(ti);
  710. /* offset += (16-cmprE); */
  711. if(g_ipv6_rpl_srh_strict_rfc_checking){
  712. /* IPv6 Source and Destination addresses of the encapsulating datagram (MUST) not appear in the SRH*/
  713. if (memcmp(addr.bytes, srcAddr.bytes, 16) == 0) {
  714. expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_src_addr);
  715. }
  716. if (memcmp(addr.bytes, dstAddr.bytes, 16) == 0) {
  717. expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_dst_addr);
  718. }
  719. /* Multicast addresses MUST NOT appear in the in SRH */
  720. if(E_IN6_IS_ADDR_MULTICAST(&addr)){
  721. expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
  722. }
  723. }
  724. }
  725. }
  726. }
  727. }
  728. return len;
  729. }
  730. static int
  731. dissect_frag6(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
  732. guint16 *offlg, guint32 *ident) {
  733. struct ip6_frag frag;
  734. int len;
  735. proto_item *ti;
  736. proto_tree *rthdr_tree;
  737. tvb_memcpy(tvb, (guint8 *)&frag, offset, sizeof(frag));
  738. len = sizeof(frag);
  739. frag.ip6f_offlg = g_ntohs(frag.ip6f_offlg);
  740. frag.ip6f_ident = g_ntohl(frag.ip6f_ident);
  741. *offlg = frag.ip6f_offlg;
  742. *ident = frag.ip6f_ident;
  743. col_add_fstr(pinfo->cinfo, COL_INFO,
  744. "IPv6 fragment (nxt=%s (%u) off=%u id=0x%x)",
  745. ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
  746. (frag.ip6f_offlg & IP6F_OFF_MASK) >> IP6F_OFF_SHIFT, frag.ip6f_ident);
  747. if (tree) {
  748. ti = proto_tree_add_text(tree, tvb, offset, len,
  749. "Fragmentation Header");
  750. rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
  751. proto_tree_add_item(rthdr_tree, hf_ipv6_frag_nxt, tvb,
  752. offset + (int)offsetof(struct ip6_frag, ip6f_nxt), 1,
  753. ENC_BIG_ENDIAN);
  754. proto_tree_add_item(rthdr_tree, hf_ipv6_frag_reserved, tvb,
  755. offset + (int)offsetof(struct ip6_frag, ip6f_reserved), 1,
  756. ENC_BIG_ENDIAN);
  757. proto_tree_add_item(rthdr_tree, hf_ipv6_frag_offset, tvb,
  758. offset + (int)offsetof(struct ip6_frag, ip6f_offlg), 2, ENC_BIG_ENDIAN);
  759. proto_tree_add_item(rthdr_tree, hf_ipv6_frag_reserved_bits, tvb,
  760. offset + (int)offsetof(struct ip6_frag, ip6f_offlg), 2, ENC_BIG_ENDIAN);
  761. proto_tree_add_item(rthdr_tree, hf_ipv6_frag_more, tvb,
  762. offset + (int)offsetof(struct ip6_frag, ip6f_offlg), 2, ENC_BIG_ENDIAN);
  763. proto_tree_add_item(rthdr_tree, hf_ipv6_frag_id, tvb,
  764. offset + (int)offsetof(struct ip6_frag, ip6f_ident), 4, ENC_BIG_ENDIAN);
  765. }
  766. return len;
  767. }
  768. static const value_string rtalertvals[] = {
  769. { IP6OPT_RTALERT_MLD, "MLD" },
  770. { IP6OPT_RTALERT_RSVP, "RSVP" },
  771. { IP6OPT_RTALERT_ACTNET, "Active Network" },
  772. { 0, NULL }
  773. };
  774. static int
  775. dissect_unknown_option(tvbuff_t *tvb, int offset, proto_tree *tree)
  776. {
  777. int len;
  778. proto_tree *unkopt_tree;
  779. proto_item *ti, *ti_len;
  780. len = (tvb_get_guint8(tvb, offset + 1) + 1) << 3;
  781. if (tree) {
  782. /* !!! specify length */
  783. ti = proto_tree_add_item(tree, hf_ipv6_unk_hdr, tvb, offset, len, ENC_NA);
  784. unkopt_tree = proto_item_add_subtree(ti, ett_ipv6);
  785. proto_tree_add_item(unkopt_tree, hf_ipv6_nxt, tvb, offset, 1, ENC_NA);
  786. offset += 1;
  787. ti_len = proto_tree_add_item(unkopt_tree, hf_ipv6_opt_length, tvb, offset, 1, ENC_NA);
  788. proto_item_append_text(ti_len, " (%d byte%s)", len, plurality(len, "", "s"));
  789. /* offset += 1; */
  790. }
  791. return len;
  792. }
  793. static int
  794. dissect_opts(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info * pinfo, const int hf_option_item)
  795. {
  796. int len;
  797. int offset_end;
  798. proto_tree *dstopt_tree, *opt_tree;
  799. proto_item *ti, *ti_len, *ti_opt, *ti_opt_len;
  800. guint8 opt_len, opt_type;
  801. len = (tvb_get_guint8(tvb, offset + 1) + 1) << 3;
  802. offset_end = offset + len;
  803. if (tree) {
  804. /* !!! specify length */
  805. ti = proto_tree_add_item(tree, hf_option_item, tvb, offset, len, ENC_NA);
  806. dstopt_tree = proto_item_add_subtree(ti, ett_ipv6);
  807. proto_tree_add_item(dstopt_tree, hf_ipv6_nxt, tvb, offset, 1, ENC_NA);
  808. offset += 1;
  809. ti_len = proto_tree_add_item(dstopt_tree, hf_ipv6_opt_length, tvb, offset, 1, ENC_NA);
  810. proto_item_append_text(ti_len, " (%d byte%s)", len, plurality(len, "", "s"));
  811. offset += 1;
  812. while (offset_end > offset) {
  813. /* there are more options */
  814. /* IPv6 Option */
  815. ti_opt = proto_tree_add_item(dstopt_tree, hf_ipv6_opt, tvb, offset, 1, ENC_NA);
  816. opt_tree = proto_item_add_subtree(ti_opt, ett_ipv6_opt);
  817. /* Option type */
  818. proto_tree_add_item(opt_tree, hf_ipv6_opt_type, tvb, offset, 1, ENC_BIG_ENDIAN);
  819. opt_type = tvb_get_guint8(tvb, offset);
  820. /* Add option name to option root label */
  821. proto_item_append_text(ti_opt, " (%s", val_to_str(opt_type, ipv6_opt_vals, "Unknown %d"));
  822. /* The Pad1 option is a special case, and contains no data. */
  823. if (opt_type == IP6OPT_PAD1) {
  824. proto_tree_add_item(opt_tree, hf_ipv6_opt_pad1, tvb, offset, 1, ENC_NA);
  825. offset += 1;
  826. proto_item_append_text(ti_opt, ")");
  827. continue;
  828. }
  829. offset += 1;
  830. /* Option length */
  831. ti_opt_len = proto_tree_add_item(opt_tree, hf_ipv6_opt_length, tvb, offset, 1, ENC_BIG_ENDIAN);
  832. opt_len = tvb_get_guint8(tvb, offset);
  833. proto_item_set_len(ti_opt, opt_len + 2);
  834. offset += 1;
  835. switch (opt_type) {
  836. case IP6OPT_PADN:
  837. /* RFC 2460 states :
  838. * "The PadN option is used to insert two or more octets of
  839. * padding into the Options area of a header. For N octets of
  840. * padding, the Opt Data Len field contains the value N-2, and
  841. * the Option Data consists of N-2 zero-valued octets."
  842. */
  843. proto_tree_add_item(opt_tree, hf_ipv6_opt_padn, tvb,
  844. offset, opt_len, ENC_NA);
  845. offset += opt_len;
  846. break;
  847. case IP6OPT_TEL:
  848. if (opt_len != 1) {
  849. expert_add_info_format_text(pinfo, ti_opt_len, &ei_ipv6_opt_tel_invalid_len,
  850. "Tunnel Encapsulation Limit: Invalid length (%u bytes)", opt_len);
  851. }
  852. proto_tree_add_item(opt_tree, hf_ipv6_opt_tel, tvb,
  853. offset, 1, ENC_BIG_ENDIAN);
  854. offset += 1;
  855. break;
  856. case IP6OPT_JUMBO:
  857. if (opt_len != 4) {
  858. expert_add_info_format_text(pinfo, ti_opt_len, &ei_ipv6_opt_jumbo_invalid_len,
  859. "Jumbo payload: Invalid length (%u bytes)", opt_len);
  860. }
  861. proto_tree_add_item(opt_tree, hf_ipv6_opt_jumbo, tvb,
  862. offset, 4, ENC_BIG_ENDIAN);
  863. offset += 4;
  864. break;
  865. case IP6OPT_RTALERT:
  866. {
  867. if (opt_len != 2) {
  868. expert_add_info_format_text(pinfo, ti_opt_len, &ei_ipv6_opt_rtalert_invalid_len,
  869. "Router alert: Invalid Length (%u bytes)",
  870. opt_len + 2);
  871. }
  872. proto_tree_add_item(opt_tree, hf_ipv6_opt_rtalert, tvb,
  873. offset, 2, ENC_BIG_ENDIAN);
  874. offset += 2;
  875. break;
  876. }
  877. case IP6OPT_HOME_ADDRESS:
  878. if (opt_len != 16) {
  879. expert_add_info_format_text(pinfo, ti_opt_len, &ei_ipv6_mipv6_home_address_invalid_len,
  880. "Home Address: Invalid length (%u bytes)", opt_len);
  881. }
  882. proto_tree_add_item(opt_tree, hf_ipv6_mipv6_home_address, tvb,
  883. offset, 16, ENC_NA);
  884. TVB_SET_ADDRESS(&pinfo->src, AT_IPv6, tvb, offset, 16);
  885. offset += 16;
  886. break;
  887. case IP6OPT_CALIPSO:
  888. {
  889. guint8 cmpt_length;
  890. proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_doi, tvb,
  891. offset, 4, ENC_BIG_ENDIAN);
  892. offset += 4;
  893. proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_cmpt_length, tvb,
  894. offset, 1, ENC_BIG_ENDIAN);
  895. cmpt_length = tvb_get_guint8(tvb, offset);
  896. offset += 1;
  897. proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_sens_level, tvb,
  898. offset, 1, ENC_BIG_ENDIAN);
  899. offset += 1;
  900. /* Need to add Check Checksum..*/
  901. proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_checksum, tvb,
  902. offset, 2, ENC_BIG_ENDIAN);
  903. offset += 2;
  904. proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_cmpt_bitmap, tvb,
  905. offset, cmpt_length, ENC_NA);
  906. offset += cmpt_length;
  907. break;
  908. }
  909. case IP6OPT_QUICKSTART:
  910. {
  911. guint8 command = tvb_get_guint8(tvb, offset);
  912. guint8 function = command >> 4;
  913. guint8 rate = command & QS_RATE_MASK;
  914. guint8 ttl_diff;
  915. proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_func, tvb, offset, 1, ENC_NA);
  916. if (function == QS_RATE_REQUEST) {
  917. proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_rate, tvb, offset, 1, ENC_NA);
  918. offset += 1;
  919. proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_ttl, tvb, offset, 1, ENC_NA);
  920. ttl_diff = (pinfo->ip_ttl - tvb_get_guint8(tvb, offset) % 256);
  921. offset += 1;
  922. ti = proto_tree_add_uint_format_value(opt_tree, hf_ipv6_opt_qs_ttl_diff,
  923. tvb, offset, 1, ttl_diff,
  924. "%u", ttl_diff);
  925. PROTO_ITEM_SET_GENERATED(ti);
  926. proto_item_append_text(ti_opt, ", %s, QS TTL %u, QS TTL diff %u",
  927. val_to_str_ext(rate, &qs_rate_vals_ext, "Unknown (%u)"),
  928. tvb_get_guint8(tvb, offset), ttl_diff);
  929. offset += 1;
  930. proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_nonce, tvb, offset, 4, ENC_NA);
  931. proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_reserved, tvb, offset, 4, ENC_NA);
  932. offset += 4;
  933. } else if (function == QS_RATE_REPORT) {
  934. proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_rate, tvb, offset, 1, ENC_NA);
  935. offset += 1;
  936. proto_item_append_text(ti_opt, ", %s",
  937. val_to_str_ext(rate, &qs_rate_vals_ext, "Unknown (%u)"));
  938. proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_unused, tvb, offset, 1, ENC_NA);
  939. offset += 1;
  940. proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_nonce, tvb, offset, 4, ENC_NA);
  941. proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_reserved, tvb, offset, 4, ENC_NA);
  942. offset += 4;
  943. }
  944. }
  945. break;
  946. case IP6OPT_RPL:
  947. {
  948. proto_tree *flag_tree;
  949. proto_item *ti_flag;
  950. ti_flag = proto_tree_add_item(opt_tree, hf_ipv6_opt_rpl_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
  951. flag_tree = proto_item_add_subtree(ti_flag, ett_ipv6_opt_flag);
  952. proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_flag_o, tvb, offset, 1, ENC_BIG_ENDIAN);
  953. proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_flag_r, tvb, offset, 1, ENC_BIG_ENDIAN);
  954. proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_flag_f, tvb, offset, 1, ENC_BIG_ENDIAN);
  955. proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_flag_rsv, tvb, offset, 1, ENC_BIG_ENDIAN);
  956. offset +=1;
  957. proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_instance_id, tvb, offset, 1, ENC_BIG_ENDIAN);
  958. offset +=1;
  959. proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_senderrank, tvb, offset, 2, ENC_BIG_ENDIAN);
  960. offset +=2;
  961. /* TODO: Add dissector of sub TLV */
  962. }
  963. break;
  964. case IP6OPT_EXP_1E:
  965. case IP6OPT_EXP_3E:
  966. case IP6OPT_EXP_5E:
  967. case IP6OPT_EXP_7E:
  968. case IP6OPT_EXP_9E:
  969. case IP6OPT_EXP_BE:
  970. case IP6OPT_EXP_DE:
  971. case IP6OPT_EXP_FE:
  972. proto_tree_add_item(opt_tree, hf_ipv6_opt_experimental, tvb,
  973. offset, opt_len, ENC_NA);
  974. offset += opt_len;
  975. break;
  976. default:
  977. proto_tree_add_item(opt_tree, hf_ipv6_opt_unknown, tvb,
  978. offset, opt_len, ENC_NA);
  979. offset += opt_len;
  980. break;
  981. }
  982. /* Close the ) to option root label */
  983. proto_item_append_text(ti_opt, ")");
  984. }
  985. }
  986. return len;
  987. }
  988. static int
  989. dissect_hopopts(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info * pinfo)
  990. {
  991. return dissect_opts(tvb, offset, tree, pinfo, hf_ipv6_hop_opt);
  992. }
  993. static int
  994. dissect_dstopts(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info * pinfo)
  995. {
  996. return dissect_opts(tvb, offset, tree, pinfo, hf_ipv6_dst_opt);
  997. }
  998. /* START SHIM6 PART */
  999. static guint16 shim_checksum(const guint8 *ptr, int len)
  1000. {
  1001. vec_t cksum_vec[1];
  1002. cksum_vec[0].ptr = ptr;
  1003. cksum_vec[0].len = len;
  1004. return in_cksum(&cksum_vec[0], 1);
  1005. }
  1006. static int
  1007. dissect_shim_hex(tvbuff_t *tvb, int offset, int len, const char *itemname, guint8 bitmask, proto_tree *tree)
  1008. {
  1009. proto_item *ti;
  1010. int count;
  1011. gint p;
  1012. p = offset;
  1013. ti = proto_tree_add_text(tree, tvb, offset, len, "%s", itemname);
  1014. proto_item_append_text(ti, " 0x%02x", tvb_get_guint8(tvb, p) & bitmask);
  1015. for (count=1; count<len; count++)
  1016. proto_item_append_text(ti, "%02x", tvb_get_guint8(tvb, p+count));
  1017. return len;
  1018. }
  1019. static const value_string shimoptvals[] = {
  1020. { SHIM6_OPT_RESPVAL, "Responder Validator Option" },
  1021. { SHIM6_OPT_LOCLIST, "Locator List Option" },
  1022. { SHIM6_OPT_LOCPREF, "Locator Preferences Option" },
  1023. { SHIM6_OPT_CGAPDM, "CGA Parameter Data Structure Option" },
  1024. { SHIM6_OPT_CGASIG, "CGA Signature Option" },
  1025. { SHIM6_OPT_ULIDPAIR, "ULID Pair Option" },
  1026. { SHIM6_OPT_FII, "Forked Instance Identifier Option" },
  1027. { 0, NULL }
  1028. };
  1029. static const value_string shimverifmethods[] = {
  1030. { SHIM6_VERIF_HBA, "HBA" },
  1031. { SHIM6_VERIF_CGA, "CGA" },
  1032. { 0, NULL }
  1033. };
  1034. static const value_string shimflags[] _U_ = {
  1035. { SHIM6_FLAG_BROKEN, "BROKEN" },
  1036. { SHIM6_FLAG_TEMPORARY, "TEMPORARY" },
  1037. { 0, NULL }
  1038. };
  1039. static const value_string shimreapstates[] = {
  1040. { SHIM6_REAP_OPERATIONAL, "Operational" },
  1041. { SHIM6_REAP_EXPLORING, "Exploring" },
  1042. { SHIM6_REAP_INBOUNDOK, "InboundOK" },
  1043. { 0, NULL }
  1044. };
  1045. static const value_string shim6_protocol[] = {
  1046. { 0, "SHIM6" },
  1047. { 1, "HIP" },
  1048. { 0, NULL }
  1049. };
  1050. static void
  1051. dissect_shim6_opt_loclist(proto_tree * opt_tree, tvbuff_t * tvb, gint *offset)
  1052. {
  1053. proto_item * it;
  1054. proto_tree * subtree;
  1055. guint count;
  1056. guint optlen;
  1057. int p = *offset;
  1058. proto_tree_add_item(opt_tree, hf_ipv6_shim6_opt_loclist, tvb, p, 4, ENC_BIG_ENDIAN);
  1059. p += 4;
  1060. optlen = tvb_get_guint8(tvb, p);
  1061. proto_tree_add_item(opt_tree, hf_ipv6_shim6_opt_locnum, tvb, p, 1, ENC_BIG_ENDIAN);
  1062. p++;
  1063. /* Verification Methods */
  1064. it = proto_tree_add_text(opt_tree, tvb, p, optlen,
  1065. "Locator Verification Methods");
  1066. subtree = proto_item_add_subtree(it, ett_ipv6_shim6_verif_methods);
  1067. for (count=0; count < optlen; count++)
  1068. proto_tree_add_item(subtree, hf_ipv6_shim6_opt_loc_verif_methods, tvb,
  1069. p+count, 1, ENC_BIG_ENDIAN);
  1070. p += optlen;
  1071. /* Padding, included in length field */
  1072. if ((7 - optlen % 8) > 0) {
  1073. proto_tree_add_text(opt_tree, tvb, p, (7 - optlen % 8), "Padding");
  1074. p += (7 - optlen % 8);
  1075. }
  1076. /* Locators */
  1077. it = proto_tree_add_text(opt_tree, tvb, p, 16 * optlen, "Locators");
  1078. subtree = proto_item_add_subtree(it, ett_ipv6_shim6_locators);
  1079. for (count=0; count < optlen; count++) {
  1080. proto_tree_add_item(subtree, hf_ipv6_shim6_locator, tvb, p, 16, ENC_NA);
  1081. p += 16;
  1082. }
  1083. *offset = p;
  1084. }
  1085. static void
  1086. dissect_shim6_opt_loc_pref(proto_tree * opt_tree, tvbuff_t * tvb, gint *offset, gint len, packet_info *pinfo)
  1087. {
  1088. proto_tree * subtree;
  1089. proto_item * it;
  1090. gint p;
  1091. gint optlen;
  1092. gint count;
  1093. p = *offset;
  1094. proto_tree_add_item(opt_tree, hf_ipv6_shim6_opt_loclist, tvb, p, 4, ENC_BIG_ENDIAN);
  1095. p += 4;
  1096. optlen = tvb_get_guint8(tvb, p);
  1097. proto_tree_add_item(opt_tree, hf_ipv6_shim6_opt_elemlen, tvb, p, 1, ENC_BIG_ENDIAN);
  1098. if (optlen < 1 || optlen > 3) {
  1099. proto_tree_add_expert_format(opt_tree, pinfo, &ei_ipv6_shim6_opt_elemlen_invalid, tvb, p, 1,
  1100. "Invalid element length: %u", optlen);
  1101. return;
  1102. }
  1103. p++;
  1104. /* Locator Preferences */
  1105. count = 1;
  1106. while (p < len) {
  1107. it = proto_tree_add_text(opt_tree, tvb, p, optlen, "Locator Preferences %u", count);
  1108. subtree = proto_item_add_subtree(it, ett_ipv6_shim6_loc_pref);
  1109. /* Flags */
  1110. if (optlen >= 1)
  1111. proto_tree_add_item(subtree, hf_ipv6_shim6_loc_flag, tvb, p, 1, ENC_BIG_ENDIAN);
  1112. /* Priority */
  1113. if (opt

Large files files are truncated, but you can click here to view the full file