/epan/dissectors/packet-ipv6.c
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
- /* packet-ipv6.c
- * Routines for IPv6 packet disassembly
- *
- * $Id$
- *
- * Wireshark - Network traffic analyzer
- * By Gerald Combs <gerald@wireshark.org>
- * Copyright 1998 Gerald Combs
- *
- * SHIM6 support added by Matthijs Mekking <matthijs@NLnetLabs.nl>
- *
- * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
- #include "config.h"
- #include <math.h>
- #include <glib.h>
- #include <epan/packet.h>
- #include <epan/expert.h>
- #include <epan/ip_opts.h>
- #include <epan/addr_resolv.h>
- #include <epan/prefs.h>
- #include <epan/reassemble.h>
- #include <epan/ipproto.h>
- #include <epan/ipv6-utils.h>
- #include <epan/etypes.h>
- #include <epan/ppptypes.h>
- #include <epan/aftypes.h>
- #include <epan/nlpid.h>
- #include <epan/arcnet_pids.h>
- #include <epan/in_cksum.h>
- #include <epan/expert.h>
- #include <epan/emem.h>
- #include <epan/tap.h>
- #include "packet-ipsec.h"
- #include "packet-ipv6.h"
- #include "packet-ip.h"
- #ifdef HAVE_GEOIP_V6
- #include <GeoIP.h>
- #include <epan/geoip_db.h>
- #endif /* HAVE_GEOIP_V6 */
- /* Differentiated Services Field. See RFCs 2474, 2597 and 2598. */
- #define IPDSFIELD_DSCP_MASK 0xFC
- #define IPDSFIELD_ECN_MASK 0x03
- #define IPDSFIELD_DSCP_SHIFT 2
- #define IPDSFIELD_DSCP(dsfield) (((dsfield)&IPDSFIELD_DSCP_MASK)>>IPDSFIELD_DSCP_SHIFT)
- #define IPDSFIELD_ECN(dsfield) ((dsfield)&IPDSFIELD_ECN_MASK)
- #define IPDSFIELD_DSCP_DEFAULT 0x00
- #define IPDSFIELD_DSCP_CS1 0x08
- #define IPDSFIELD_DSCP_CS2 0x10
- #define IPDSFIELD_DSCP_CS3 0x18
- #define IPDSFIELD_DSCP_CS4 0x20
- #define IPDSFIELD_DSCP_CS5 0x28
- #define IPDSFIELD_DSCP_CS6 0x30
- #define IPDSFIELD_DSCP_CS7 0x38
- #define IPDSFIELD_DSCP_AF11 0x0A
- #define IPDSFIELD_DSCP_AF12 0x0C
- #define IPDSFIELD_DSCP_AF13 0x0E
- #define IPDSFIELD_DSCP_AF21 0x12
- #define IPDSFIELD_DSCP_AF22 0x14
- #define IPDSFIELD_DSCP_AF23 0x16
- #define IPDSFIELD_DSCP_AF31 0x1A
- #define IPDSFIELD_DSCP_AF32 0x1C
- #define IPDSFIELD_DSCP_AF33 0x1E
- #define IPDSFIELD_DSCP_AF41 0x22
- #define IPDSFIELD_DSCP_AF42 0x24
- #define IPDSFIELD_DSCP_AF43 0x26
- #define IPDSFIELD_DSCP_EF 0x2E
- #define IPDSFIELD_ECT_MASK 0x02
- #define IPDSFIELD_CE_MASK 0x01
- /* RPL Routing header */
- #define IP6RRPL_BITMASK_CMPRI 0xF0000000
- #define IP6RRPL_BITMASK_CMPRE 0x0F000000
- #define IP6RRPL_BITMASK_PAD 0x00F00000
- #define IP6RRPL_BITMASK_RESERVED 0x000FFFFF
- static int ipv6_tap = -1;
- static int proto_ipv6 = -1;
- static int hf_ipv6_version = -1;
- static int hf_ip_version = -1;
- static int hf_ipv6_class = -1;
- static int hf_ipv6_flow = -1;
- static int hf_ipv6_plen = -1;
- static int hf_ipv6_nxt = -1;
- static int hf_ipv6_hlim = -1;
- static int hf_ipv6_src = -1;
- static int hf_ipv6_src_host = -1;
- static int hf_ipv6_src_sa_mac = -1;
- static int hf_ipv6_src_isatap_ipv4 = -1;
- static int hf_ipv6_src_6to4_gateway_ipv4 = -1;
- static int hf_ipv6_src_6to4_sla_id = -1;
- static int hf_ipv6_src_teredo_server_ipv4 = -1;
- static int hf_ipv6_src_teredo_port = -1;
- static int hf_ipv6_src_teredo_client_ipv4 = -1;
- static int hf_ipv6_dst = -1;
- static int hf_ipv6_dst_host = -1;
- static int hf_ipv6_dst_sa_mac = -1;
- static int hf_ipv6_dst_isatap_ipv4 = -1;
- static int hf_ipv6_dst_6to4_gateway_ipv4 = -1;
- static int hf_ipv6_dst_6to4_sla_id = -1;
- static int hf_ipv6_dst_teredo_server_ipv4 = -1;
- static int hf_ipv6_dst_teredo_port = -1;
- static int hf_ipv6_dst_teredo_client_ipv4 = -1;
- static int hf_ipv6_addr = -1;
- static int hf_ipv6_host = -1;
- static int hf_ipv6_sa_mac = -1;
- static int hf_ipv6_isatap_ipv4 = -1;
- static int hf_ipv6_6to4_gateway_ipv4 = -1;
- static int hf_ipv6_6to4_sla_id = -1;
- static int hf_ipv6_teredo_server_ipv4 = -1;
- static int hf_ipv6_teredo_port = -1;
- static int hf_ipv6_teredo_client_ipv4 = -1;
- static int hf_ipv6_opt = -1;
- static int hf_ipv6_opt_type = -1;
- static int hf_ipv6_opt_length = -1;
- static int hf_ipv6_opt_pad1 = -1;
- static int hf_ipv6_opt_padn = -1;
- static int hf_ipv6_opt_tel = -1;
- static int hf_ipv6_opt_rtalert = -1;
- static int hf_ipv6_opt_jumbo = -1;
- static int hf_ipv6_opt_calipso_doi = -1;
- static int hf_ipv6_opt_calipso_cmpt_length = -1;
- static int hf_ipv6_opt_calipso_sens_level = -1;
- static int hf_ipv6_opt_calipso_checksum = -1;
- static int hf_ipv6_opt_calipso_cmpt_bitmap = -1;
- static int hf_ipv6_opt_qs_func = -1;
- static int hf_ipv6_opt_qs_rate = -1;
- static int hf_ipv6_opt_qs_ttl = -1;
- static int hf_ipv6_opt_qs_ttl_diff = -1;
- static int hf_ipv6_opt_qs_unused = -1;
- static int hf_ipv6_opt_qs_nonce = -1;
- static int hf_ipv6_opt_qs_reserved = -1;
- static int hf_ipv6_opt_rpl_flag = -1;
- static int hf_ipv6_opt_rpl_flag_o = -1;
- static int hf_ipv6_opt_rpl_flag_r = -1;
- static int hf_ipv6_opt_rpl_flag_f = -1;
- static int hf_ipv6_opt_rpl_flag_rsv = -1;
- static int hf_ipv6_opt_rpl_instance_id = -1;
- static int hf_ipv6_opt_rpl_senderrank = -1;
- static int hf_ipv6_opt_experimental = -1;
- static int hf_ipv6_opt_unknown = -1;
- static int hf_ipv6_dst_opt = -1;
- static int hf_ipv6_hop_opt = -1;
- static int hf_ipv6_unk_hdr = -1;
- static int hf_ipv6_routing_hdr_opt = -1;
- static int hf_ipv6_routing_hdr_type = -1;
- static int hf_ipv6_routing_hdr_left = -1;
- static int hf_ipv6_routing_hdr_addr = -1;
- static int hf_ipv6_frag_nxt = -1;
- static int hf_ipv6_frag_reserved = -1;
- static int hf_ipv6_frag_offset = -1;
- static int hf_ipv6_frag_reserved_bits = -1;
- static int hf_ipv6_frag_more = -1;
- static int hf_ipv6_frag_id = -1;
- static int hf_ipv6_fragments = -1;
- static int hf_ipv6_fragment = -1;
- static int hf_ipv6_fragment_overlap = -1;
- static int hf_ipv6_fragment_overlap_conflict = -1;
- static int hf_ipv6_fragment_multiple_tails = -1;
- static int hf_ipv6_fragment_too_long_fragment = -1;
- static int hf_ipv6_fragment_error = -1;
- static int hf_ipv6_fragment_count = -1;
- static int hf_ipv6_reassembled_in = -1;
- static int hf_ipv6_reassembled_length = -1;
- static int hf_ipv6_reassembled_data = -1;
- static int hf_ipv6_mipv6_home_address = -1;
- static int hf_ipv6_routing_hdr_rpl_cmprI = -1;
- static int hf_ipv6_routing_hdr_rpl_cmprE = -1;
- static int hf_ipv6_routing_hdr_rpl_pad = -1;
- static int hf_ipv6_routing_hdr_rpl_reserved = -1;
- static int hf_ipv6_routing_hdr_rpl_segments = -1;
- static int hf_ipv6_routing_hdr_rpl_addr = -1;
- static int hf_ipv6_routing_hdr_rpl_fulladdr = -1;
- static int hf_ipv6_shim6 = -1;
- static int hf_ipv6_shim6_nxt = -1;
- static int hf_ipv6_shim6_len = -1;
- static int hf_ipv6_shim6_p = -1;
- /* context tag is 49 bits, cannot be used for filter yet */
- static int hf_ipv6_shim6_ct = -1;
- static int hf_ipv6_shim6_type = -1;
- static int hf_ipv6_shim6_proto = -1;
- static int hf_ipv6_shim6_checksum = -1;
- static int hf_ipv6_shim6_checksum_bad = -1;
- static int hf_ipv6_shim6_checksum_good = -1;
- static int hf_ipv6_shim6_inonce = -1; /* also for request nonce */
- static int hf_ipv6_shim6_rnonce = -1;
- static int hf_ipv6_shim6_precvd = -1;
- static int hf_ipv6_shim6_psent = -1;
- static int hf_ipv6_shim6_psrc = -1;
- static int hf_ipv6_shim6_pdst = -1;
- static int hf_ipv6_shim6_pnonce = -1;
- static int hf_ipv6_shim6_pdata = -1;
- static int hf_ipv6_shim6_sulid = -1;
- static int hf_ipv6_shim6_rulid = -1;
- static int hf_ipv6_shim6_reap = -1;
- static int hf_ipv6_shim6_opt_type = -1;
- static int hf_ipv6_shim6_opt_len = -1;
- static int hf_ipv6_shim6_opt_total_len = -1;
- static int hf_ipv6_shim6_opt_loc_verif_methods = -1;
- static int hf_ipv6_shim6_opt_critical = -1;
- static int hf_ipv6_shim6_opt_loclist = -1;
- static int hf_ipv6_shim6_locator = -1;
- static int hf_ipv6_shim6_loc_flag = -1;
- static int hf_ipv6_shim6_loc_prio = -1;
- static int hf_ipv6_shim6_loc_weight = -1;
- static int hf_ipv6_shim6_opt_locnum = -1;
- static int hf_ipv6_shim6_opt_elemlen = -1;
- static int hf_ipv6_shim6_opt_fii = -1;
- static int hf_ipv6_traffic_class_dscp = -1;
- static int hf_ipv6_traffic_class_ect = -1;
- static int hf_ipv6_traffic_class_ce = -1;
- #ifdef HAVE_GEOIP_V6
- static int hf_geoip_country = -1;
- static int hf_geoip_city = -1;
- static int hf_geoip_org = -1;
- static int hf_geoip_isp = -1;
- static int hf_geoip_asnum = -1;
- static int hf_geoip_lat = -1;
- static int hf_geoip_lon = -1;
- static int hf_geoip_src_country = -1;
- static int hf_geoip_src_city = -1;
- static int hf_geoip_src_org = -1;
- static int hf_geoip_src_isp = -1;
- static int hf_geoip_src_asnum = -1;
- static int hf_geoip_src_lat = -1;
- static int hf_geoip_src_lon = -1;
- static int hf_geoip_dst_country = -1;
- static int hf_geoip_dst_city = -1;
- static int hf_geoip_dst_org = -1;
- static int hf_geoip_dst_isp = -1;
- static int hf_geoip_dst_asnum = -1;
- static int hf_geoip_dst_lat = -1;
- static int hf_geoip_dst_lon = -1;
- #endif /* HAVE_GEOIP_V6 */
- static gint ett_ipv6 = -1;
- static gint ett_ipv6_opt = -1;
- static gint ett_ipv6_opt_flag = -1;
- static gint ett_ipv6_version = -1;
- static gint ett_ipv6_shim6 = -1;
- static gint ett_ipv6_shim6_option = -1;
- static gint ett_ipv6_shim6_locators = -1;
- static gint ett_ipv6_shim6_verif_methods = -1;
- static gint ett_ipv6_shim6_loc_pref = -1;
- static gint ett_ipv6_shim6_probes_sent = -1;
- static gint ett_ipv6_shim6_probe_sent = -1;
- static gint ett_ipv6_shim6_probes_rcvd = -1;
- static gint ett_ipv6_shim6_probe_rcvd = -1;
- static gint ett_ipv6_shim6_cksum = -1;
- static gint ett_ipv6_fragments = -1;
- static gint ett_ipv6_fragment = -1;
- static gint ett_ipv6_traffic_class = -1;
- #ifdef HAVE_GEOIP_V6
- static gint ett_geoip_info = -1;
- #endif /* HAVE_GEOIP_V6 */
- static expert_field ei_ipv6_dst_addr_not_multicast = EI_INIT;
- static expert_field ei_ipv6_src_route_list_mult_inst_same_addr = EI_INIT;
- static expert_field ei_ipv6_src_route_list_src_addr = EI_INIT;
- static expert_field ei_ipv6_src_route_list_dst_addr = EI_INIT;
- static expert_field ei_ipv6_src_route_list_multicast_addr = EI_INIT;
- static expert_field ei_ipv6_cmpri_cmpre_pad = EI_INIT;
- static expert_field ei_ipv6_routing_hdr_rpl_reserved = EI_INIT;
- static expert_field ei_ipv6_opt_tel_invalid_len = EI_INIT;
- static expert_field ei_ipv6_opt_jumbo_invalid_len = EI_INIT;
- static expert_field ei_ipv6_opt_rtalert_invalid_len = EI_INIT;
- static expert_field ei_ipv6_mipv6_home_address_invalid_len = EI_INIT;
- static expert_field ei_ipv6_shim6_opt_elemlen_invalid = EI_INIT;
- static expert_field ei_ipv6_shim6_checksum_bad = EI_INIT;
- static expert_field ei_ipv6_routing_hdr_rpl_segments_ge0 = EI_INIT;
- static const fragment_items ipv6_frag_items = {
- &ett_ipv6_fragment,
- &ett_ipv6_fragments,
- &hf_ipv6_fragments,
- &hf_ipv6_fragment,
- &hf_ipv6_fragment_overlap,
- &hf_ipv6_fragment_overlap_conflict,
- &hf_ipv6_fragment_multiple_tails,
- &hf_ipv6_fragment_too_long_fragment,
- &hf_ipv6_fragment_error,
- &hf_ipv6_fragment_count,
- &hf_ipv6_reassembled_in,
- &hf_ipv6_reassembled_length,
- &hf_ipv6_reassembled_data,
- "IPv6 fragments"
- };
- static dissector_handle_t data_handle;
- static dissector_table_t ip_dissector_table;
- /* Reassemble fragmented datagrams */
- static gboolean ipv6_reassemble = TRUE;
- /* Place IPv6 summary in proto tree */
- static gboolean ipv6_summary_in_tree = TRUE;
- #ifdef HAVE_GEOIP_V6
- /* Look up addresses in GeoIP */
- static gboolean ipv6_use_geoip = TRUE;
- #endif /* HAVE_GEOIP_V6 */
- /* Perform strict RFC adherence checking */
- static gboolean g_ipv6_rpl_srh_strict_rfc_checking = FALSE;
- #ifndef offsetof
- #define offsetof(type, member) ((size_t)(&((type *)0)->member))
- #endif
- /*
- * defragmentation of IPv6
- */
- static reassembly_table ipv6_reassembly_table;
- /* http://www.iana.org/assignments/icmpv6-parameters (last updated 2012-12-22) */
- static const value_string ipv6_opt_vals[] = {
- { IP6OPT_PAD1, "Pad1" },
- { IP6OPT_PADN, "PadN" },
- { IP6OPT_TEL, "Tunnel Encapsulation Limit" },
- { IP6OPT_RTALERT, "Router Alert" },
- { IP6OPT_CALIPSO, "Calipso" },
- { IP6OPT_QUICKSTART, "Quick Start" },
- { IP6OPT_ENDI, "Endpoint Identification" },
- { IP6OPT_EXP_1E, "Experimental (0x1E)" },
- { IP6OPT_EXP_3E, "Experimental (0x3E)" },
- { IP6OPT_EXP_5E, "Experimental (0x5E)" },
- { IP6OPT_RPL, "RPL Option" },
- { IP6OPT_EXP_7E, "Experimental (0x7E)" },
- { IP6OPT_EXP_9E, "Experimental (0x9E)" },
- { IP6OPT_EXP_BE, "Experimental (0xBE)" },
- { IP6OPT_JUMBO, "Jumbo" },
- { IP6OPT_HOME_ADDRESS, "Home Address" },
- { IP6OPT_EXP_DE, "Experimental (0xDE)" },
- { IP6OPT_EXP_FE, "Experimental (0xFE)" },
- { 0, NULL }
- };
- void
- capture_ipv6(const guchar *pd, int offset, int len, packet_counts *ld)
- {
- guint8 nxt;
- int advance;
- if (!BYTES_ARE_IN_FRAME(offset, len, 4+4+16+16)) {
- ld->other++;
- return;
- }
- nxt = pd[offset+6]; /* get the "next header" value */
- offset += 4+4+16+16; /* skip past the IPv6 header */
- again:
- switch (nxt) {
- case IP_PROTO_HOPOPTS:
- case IP_PROTO_ROUTING:
- case IP_PROTO_DSTOPTS:
- if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
- ld->other++;
- return;
- }
- nxt = pd[offset];
- advance = (pd[offset+1] + 1) << 3;
- if (!BYTES_ARE_IN_FRAME(offset, len, advance)) {
- ld->other++;
- return;
- }
- offset += advance;
- goto again;
- case IP_PROTO_FRAGMENT:
- if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
- ld->other++;
- return;
- }
- nxt = pd[offset];
- advance = 8;
- if (!BYTES_ARE_IN_FRAME(offset, len, advance)) {
- ld->other++;
- return;
- }
- offset += advance;
- goto again;
- case IP_PROTO_AH:
- if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
- ld->other++;
- return;
- }
- nxt = pd[offset];
- advance = 8 + ((pd[offset+1] - 1) << 2);
- if (!BYTES_ARE_IN_FRAME(offset, len, advance)) {
- ld->other++;
- return;
- }
- offset += advance;
- goto again;
- case IP_PROTO_SHIM6:
- case IP_PROTO_SHIM6_OLD:
- if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
- ld->other++;
- return;
- }
- nxt = pd[offset];
- advance = (pd[offset+1] + 1) << 3;
- if (!BYTES_ARE_IN_FRAME(offset, len, advance)) {
- ld->other++;
- return;
- }
- offset += advance;
- goto again;
- }
- switch(nxt) {
- case IP_PROTO_SCTP:
- ld->sctp++;
- break;
- case IP_PROTO_TCP:
- ld->tcp++;
- break;
- case IP_PROTO_UDP:
- case IP_PROTO_UDPLITE:
- ld->udp++;
- break;
- case IP_PROTO_ICMP:
- case IP_PROTO_ICMPV6: /* XXX - separate counters? */
- ld->icmp++;
- break;
- case IP_PROTO_OSPF:
- ld->ospf++;
- break;
- case IP_PROTO_GRE:
- ld->gre++;
- break;
- case IP_PROTO_VINES:
- ld->vines++;
- break;
- default:
- ld->other++;
- }
- }
- #ifdef HAVE_GEOIP_V6
- static void
- add_geoip_info_entry(proto_tree *geoip_info_item, tvbuff_t *tvb, gint offset, const struct e_in6_addr *ip, int isdst)
- {
- proto_tree *geoip_info_tree;
- guint num_dbs = geoip_db_num_dbs();
- guint item_cnt = 0;
- guint dbnum;
- geoip_info_tree = proto_item_add_subtree(geoip_info_item, ett_geoip_info);
- for (dbnum = 0; dbnum < num_dbs; dbnum++) {
- const char *geoip_str = geoip_db_lookup_ipv6(dbnum, *ip, NULL);
- int db_type = geoip_db_type(dbnum);
- int geoip_hf, geoip_local_hf;
- switch (db_type) {
- case GEOIP_COUNTRY_EDITION_V6:
- geoip_hf = hf_geoip_country;
- geoip_local_hf = (isdst) ? hf_geoip_dst_country : hf_geoip_src_country;
- break;
- #if NUM_DB_TYPES > 31
- case GEOIP_CITY_EDITION_REV0_V6:
- case GEOIP_CITY_EDITION_REV1_V6:
- geoip_hf = hf_geoip_city;
- geoip_local_hf = (isdst) ? hf_geoip_dst_city : hf_geoip_src_city;
- break;
- case GEOIP_ORG_EDITION_V6:
- geoip_hf = hf_geoip_org;
- geoip_local_hf = (isdst) ? hf_geoip_dst_org : hf_geoip_src_org;
- break;
- case GEOIP_ISP_EDITION_V6:
- geoip_hf = hf_geoip_isp;
- geoip_local_hf = (isdst) ? hf_geoip_dst_isp : hf_geoip_src_isp;
- break;
- case GEOIP_ASNUM_EDITION_V6:
- geoip_hf = hf_geoip_asnum;
- geoip_local_hf = (isdst) ? hf_geoip_dst_asnum : hf_geoip_src_asnum;
- break;
- #endif /* DB_NUM_TYPES */
- case WS_LAT_FAKE_EDITION:
- geoip_hf = hf_geoip_lat;
- geoip_local_hf = (isdst) ? hf_geoip_dst_lat : hf_geoip_src_lat;
- break;
- case WS_LON_FAKE_EDITION:
- geoip_hf = hf_geoip_lon;
- geoip_local_hf = (isdst) ? hf_geoip_dst_lon : hf_geoip_src_lon;
- break;
- default:
- continue;
- break;
- }
- if (geoip_str) {
- proto_item *item;
- if (db_type == WS_LAT_FAKE_EDITION || db_type == WS_LON_FAKE_EDITION) {
- /* Convert latitude, longitude to double. Fix bug #5077 */
- item = proto_tree_add_double_format_value(geoip_info_tree, geoip_local_hf, tvb,
- offset, 16, g_ascii_strtod(geoip_str, NULL), "%s", geoip_str);
- PROTO_ITEM_SET_GENERATED(item);
- item = proto_tree_add_double_format_value(geoip_info_tree, geoip_hf, tvb,
- offset, 16, g_ascii_strtod(geoip_str, NULL), "%s", geoip_str);
- PROTO_ITEM_SET_GENERATED(item);
- PROTO_ITEM_SET_HIDDEN(item);
- } else {
- item = proto_tree_add_unicode_string(geoip_info_tree, geoip_local_hf, tvb,
- offset, 16, geoip_str);
- PROTO_ITEM_SET_GENERATED(item);
- item = proto_tree_add_unicode_string(geoip_info_tree, geoip_hf, tvb,
- offset, 16, geoip_str);
- PROTO_ITEM_SET_GENERATED(item);
- PROTO_ITEM_SET_HIDDEN(item);
- }
- item_cnt++;
- proto_item_append_text(geoip_info_item, "%s%s", plurality(item_cnt, "", ", "), geoip_str);
- }
- }
- if (item_cnt == 0)
- proto_item_append_text(geoip_info_item, "Unknown");
- }
- static void
- add_geoip_info(proto_tree *tree, tvbuff_t *tvb, gint offset, const struct e_in6_addr *src, const struct e_in6_addr *dst)
- {
- guint num_dbs;
- proto_item *geoip_info_item;
- num_dbs = geoip_db_num_dbs();
- if (num_dbs < 1)
- return;
- geoip_info_item = proto_tree_add_text(tree, tvb, offset + IP6H_SRC, 16, "Source GeoIP: ");
- PROTO_ITEM_SET_GENERATED(geoip_info_item);
- add_geoip_info_entry(geoip_info_item, tvb, offset + IP6H_SRC, src, 0);
- geoip_info_item = proto_tree_add_text(tree, tvb, offset + IP6H_DST, 16, "Destination GeoIP: ");
- PROTO_ITEM_SET_GENERATED(geoip_info_item);
- add_geoip_info_entry(geoip_info_item, tvb, offset + IP6H_DST, dst, 1);
- }
- #endif /* HAVE_GEOIP_V6 */
- static void
- ipv6_reassemble_init(void)
- {
- reassembly_table_init(&ipv6_reassembly_table,
- &addresses_reassembly_table_functions);
- }
- enum {
- IPv6_RT_HEADER_SOURCE_ROUTING=0,
- IPv6_RT_HEADER_NIMROD,
- IPv6_RT_HEADER_MobileIP,
- IPv6_RT_HEADER_RPL
- };
- /* Routing Header Types */
- static const value_string routing_header_type[] = {
- { IPv6_RT_HEADER_SOURCE_ROUTING, "IPv6 Source Routing" },
- { IPv6_RT_HEADER_NIMROD, "Nimrod" },
- { IPv6_RT_HEADER_MobileIP, "Mobile IP" },
- { IPv6_RT_HEADER_RPL, "RPL" },
- { 0, NULL }
- };
- static int
- dissect_routing6(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info *pinfo) {
- struct ip6_rthdr rt;
- guint len, seg_left;
- proto_tree *rthdr_tree;
- proto_item *ti;
- guint8 buf[sizeof(struct ip6_rthdr0) + sizeof(struct e_in6_addr) * 23];
- tvb_memcpy(tvb, (guint8 *)&rt, offset, sizeof(rt));
- len = (rt.ip6r_len + 1) << 3;
- /* Assigning seg_left and the if (seg_left) {} blocks of code that follow,
- * along with any expert_add_info() calls, all need to execute when
- * appropriate, regardless of whether the tree is NULL or not. */
- if (1) {
- /* !!! specify length */
- ti = proto_tree_add_uint_format(tree, hf_ipv6_routing_hdr_opt, tvb,
- offset, len, rt.ip6r_type,
- "Routing Header, Type : %s (%u)",
- val_to_str_const(rt.ip6r_type, routing_header_type, "Unknown"),
- rt.ip6r_type);
- rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
- proto_tree_add_text(rthdr_tree, tvb,
- offset + (int)offsetof(struct ip6_rthdr, ip6r_nxt), 1,
- "Next header: %s (%u)", ipprotostr(rt.ip6r_nxt), rt.ip6r_nxt);
- proto_tree_add_text(rthdr_tree, tvb,
- offset + (int)offsetof(struct ip6_rthdr, ip6r_len), 1,
- "Length: %u (%d bytes)", rt.ip6r_len, len);
- proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_type, tvb,
- offset + (int)offsetof(struct ip6_rthdr, ip6r_type), 1, ENC_BIG_ENDIAN);
- proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_left, tvb,
- offset + (int)offsetof(struct ip6_rthdr, ip6r_segleft), 1, ENC_BIG_ENDIAN);
- seg_left = tvb_get_guint8(tvb, offset + (int)offsetof(struct ip6_rthdr, ip6r_segleft));
- if (rt.ip6r_type == IPv6_RT_HEADER_SOURCE_ROUTING && len <= sizeof(buf)) {
- struct e_in6_addr *a;
- int n;
- struct ip6_rthdr0 *rt0;
- tvb_memcpy(tvb, buf, offset, len);
- rt0 = (struct ip6_rthdr0 *)buf;
- for (a = rt0->ip6r0_addr, n = 0;
- a < (struct e_in6_addr *)(buf + len); a++, n++) {
- proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_addr, tvb,
- offset + (int)(offsetof(struct ip6_rthdr0, ip6r0_addr)
- + n * sizeof(struct e_in6_addr)),
- (int)sizeof(struct e_in6_addr), ENC_NA);
- if (seg_left)
- TVB_SET_ADDRESS(&pinfo->dst, AT_IPv6, tvb,
- offset + (int)offsetof(struct ip6_rthdr0, ip6r0_addr) + n * (int)sizeof(struct e_in6_addr), 16);
- }
- }
- if (rt.ip6r_type == IPv6_RT_HEADER_MobileIP) {
- proto_tree_add_item(rthdr_tree, hf_ipv6_mipv6_home_address, tvb,
- offset + 8, 16, ENC_NA);
- if (seg_left)
- TVB_SET_ADDRESS(&pinfo->dst, AT_IPv6, tvb, offset + 8, 16);
- }
- if (rt.ip6r_type == IPv6_RT_HEADER_RPL) {
- guint8 cmprI;
- guint8 cmprE;
- guint8 pad;
- guint32 reserved;
- gint segments;
- /* IPv6 destination address used for elided bytes */
- struct e_in6_addr dstAddr;
- /* IPv6 source address used for strict checking */
- struct e_in6_addr srcAddr;
- offset += 4;
- memcpy((guint8 *)&dstAddr, (guint8 *)pinfo->dst.data, pinfo->dst.len);
- memcpy((guint8 *)&srcAddr, (guint8 *)pinfo->src.data, pinfo->src.len);
- /* from RFC6554: Multicast addresses MUST NOT appear in the IPv6 Destination Address field */
- if(g_ipv6_rpl_srh_strict_rfc_checking && E_IN6_IS_ADDR_MULTICAST(&dstAddr)){
- expert_add_info(pinfo, ti, &ei_ipv6_dst_addr_not_multicast);
- }
- proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_cmprI, tvb, offset, 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_cmprE, tvb, offset, 4, ENC_BIG_ENDIAN);
- proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_pad, tvb, offset, 4, ENC_BIG_ENDIAN);
- cmprI = tvb_get_guint8(tvb, offset) & 0xF0;
- cmprE = tvb_get_guint8(tvb, offset) & 0x0F;
- pad = tvb_get_guint8(tvb, offset + 1) & 0xF0;
- /* Shift bytes over */
- cmprI >>= 4;
- pad >>= 4;
- /* from RFC6554: when CmprI and CmprE are both 0, Pad MUST carry a value of 0 */
- if(g_ipv6_rpl_srh_strict_rfc_checking && (cmprI == 0 && cmprE == 0 && pad != 0)){
- 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);
- }
- proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
- reserved = tvb_get_bits32(tvb, ((offset + 1) * 8) + 4, 20, ENC_BIG_ENDIAN);
- if(g_ipv6_rpl_srh_strict_rfc_checking && reserved != 0){
- expert_add_info_format_text(pinfo, ti, &ei_ipv6_routing_hdr_rpl_reserved, "Reserved field must equal 0 but instead was %d", reserved);
- }
- /* from RFC6554:
- n = (((Hdr Ext Len * 8) - Pad - (16 - CmprE)) / (16 - CmprI)) + 1 */
- segments = (((rt.ip6r_len * 8) - pad - (16 - cmprE)) / (16 - cmprI)) + 1;
- ti = proto_tree_add_int(rthdr_tree, hf_ipv6_routing_hdr_rpl_segments, tvb, offset, 2, segments);
- PROTO_ITEM_SET_GENERATED(ti);
- if (segments < 0) {
- /* This error should always be reported */
- 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);
- } else {
- offset += 4;
- /* We use cmprI for internal (e.g.: not last) address for how many bytes to elide, so actual bytes present = 16-CmprI */
- while(segments > 1) {
- struct e_in6_addr addr;
- proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_addr, tvb, offset, (16-cmprI), ENC_NA);
- /* Display Full Address */
- memcpy((guint8 *)&addr, (guint8 *)&dstAddr, sizeof(dstAddr));
- tvb_memcpy(tvb, (guint8 *)&addr + cmprI, offset, (16-cmprI));
- ti = proto_tree_add_ipv6(rthdr_tree, hf_ipv6_routing_hdr_rpl_fulladdr, tvb, offset, (16-cmprI), (guint8 *)&addr);
- PROTO_ITEM_SET_GENERATED(ti);
- offset += (16-cmprI);
- segments--;
- if(g_ipv6_rpl_srh_strict_rfc_checking){
- /* from RFC6554: */
- /* The SRH MUST NOT specify a path that visits a node more than once. */
- /* To do this, we will just check the current 'addr' against the next addresses */
- gint tempSegments;
- gint tempOffset;
- tempSegments = segments; /* Has already been decremented above */
- tempOffset = offset; /* Has already been moved */
- while(tempSegments > 1) {
- struct e_in6_addr tempAddr;
- memcpy((guint8 *)&tempAddr, (guint8 *)&dstAddr, sizeof(dstAddr));
- tvb_memcpy(tvb, (guint8 *)&tempAddr + cmprI, tempOffset, (16-cmprI));
- /* Compare the addresses */
- if (memcmp(addr.bytes, tempAddr.bytes, 16) == 0) {
- /* Found a later address that is the same */
- expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_mult_inst_same_addr);
- break;
- }
- tempOffset += (16-cmprI);
- tempSegments--;
- }
- if (tempSegments == 1) {
- struct e_in6_addr tempAddr;
- memcpy((guint8 *)&tempAddr, (guint8 *)&dstAddr, sizeof(dstAddr));
- tvb_memcpy(tvb, (guint8 *)&tempAddr + cmprE, tempOffset, (16-cmprE));
- /* Compare the addresses */
- if (memcmp(addr.bytes, tempAddr.bytes, 16) == 0) {
- /* Found a later address that is the same */
- expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_mult_inst_same_addr);
- }
- }
- /* IPv6 Source and Destination addresses of the encapsulating datagram (MUST) not appear in the SRH*/
- if (memcmp(addr.bytes, srcAddr.bytes, 16) == 0) {
- expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_src_addr);
- }
- if (memcmp(addr.bytes, dstAddr.bytes, 16) == 0) {
- expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_dst_addr);
- }
- /* Multicast addresses MUST NOT appear in the in SRH */
- if(E_IN6_IS_ADDR_MULTICAST(&addr)){
- expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
- }
- }
- }
- /* We use cmprE for last address for how many bytes to elide, so actual bytes present = 16-CmprE */
- if (segments == 1) {
- struct e_in6_addr addr;
- proto_tree_add_item(rthdr_tree, hf_ipv6_routing_hdr_rpl_addr, tvb, offset, (16-cmprI), ENC_NA);
- /* Display Full Address */
- memcpy((guint8 *)&addr, (guint8 *)&dstAddr, sizeof(dstAddr));
- tvb_memcpy(tvb, (guint8 *)&addr + cmprE, offset, (16-cmprE));
- ti = proto_tree_add_ipv6(rthdr_tree, hf_ipv6_routing_hdr_rpl_fulladdr, tvb, offset, (16-cmprE), (guint8 *)&addr);
- PROTO_ITEM_SET_GENERATED(ti);
- /* offset += (16-cmprE); */
- if(g_ipv6_rpl_srh_strict_rfc_checking){
- /* IPv6 Source and Destination addresses of the encapsulating datagram (MUST) not appear in the SRH*/
- if (memcmp(addr.bytes, srcAddr.bytes, 16) == 0) {
- expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_src_addr);
- }
- if (memcmp(addr.bytes, dstAddr.bytes, 16) == 0) {
- expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_dst_addr);
- }
- /* Multicast addresses MUST NOT appear in the in SRH */
- if(E_IN6_IS_ADDR_MULTICAST(&addr)){
- expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
- }
- }
- }
- }
- }
- }
- return len;
- }
- static int
- dissect_frag6(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
- guint16 *offlg, guint32 *ident) {
- struct ip6_frag frag;
- int len;
- proto_item *ti;
- proto_tree *rthdr_tree;
- tvb_memcpy(tvb, (guint8 *)&frag, offset, sizeof(frag));
- len = sizeof(frag);
- frag.ip6f_offlg = g_ntohs(frag.ip6f_offlg);
- frag.ip6f_ident = g_ntohl(frag.ip6f_ident);
- *offlg = frag.ip6f_offlg;
- *ident = frag.ip6f_ident;
- col_add_fstr(pinfo->cinfo, COL_INFO,
- "IPv6 fragment (nxt=%s (%u) off=%u id=0x%x)",
- ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
- (frag.ip6f_offlg & IP6F_OFF_MASK) >> IP6F_OFF_SHIFT, frag.ip6f_ident);
- if (tree) {
- ti = proto_tree_add_text(tree, tvb, offset, len,
- "Fragmentation Header");
- rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
- proto_tree_add_item(rthdr_tree, hf_ipv6_frag_nxt, tvb,
- offset + (int)offsetof(struct ip6_frag, ip6f_nxt), 1,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(rthdr_tree, hf_ipv6_frag_reserved, tvb,
- offset + (int)offsetof(struct ip6_frag, ip6f_reserved), 1,
- ENC_BIG_ENDIAN);
- proto_tree_add_item(rthdr_tree, hf_ipv6_frag_offset, tvb,
- offset + (int)offsetof(struct ip6_frag, ip6f_offlg), 2, ENC_BIG_ENDIAN);
- proto_tree_add_item(rthdr_tree, hf_ipv6_frag_reserved_bits, tvb,
- offset + (int)offsetof(struct ip6_frag, ip6f_offlg), 2, ENC_BIG_ENDIAN);
- proto_tree_add_item(rthdr_tree, hf_ipv6_frag_more, tvb,
- offset + (int)offsetof(struct ip6_frag, ip6f_offlg), 2, ENC_BIG_ENDIAN);
- proto_tree_add_item(rthdr_tree, hf_ipv6_frag_id, tvb,
- offset + (int)offsetof(struct ip6_frag, ip6f_ident), 4, ENC_BIG_ENDIAN);
- }
- return len;
- }
- static const value_string rtalertvals[] = {
- { IP6OPT_RTALERT_MLD, "MLD" },
- { IP6OPT_RTALERT_RSVP, "RSVP" },
- { IP6OPT_RTALERT_ACTNET, "Active Network" },
- { 0, NULL }
- };
- static int
- dissect_unknown_option(tvbuff_t *tvb, int offset, proto_tree *tree)
- {
- int len;
- proto_tree *unkopt_tree;
- proto_item *ti, *ti_len;
- len = (tvb_get_guint8(tvb, offset + 1) + 1) << 3;
- if (tree) {
- /* !!! specify length */
- ti = proto_tree_add_item(tree, hf_ipv6_unk_hdr, tvb, offset, len, ENC_NA);
- unkopt_tree = proto_item_add_subtree(ti, ett_ipv6);
- proto_tree_add_item(unkopt_tree, hf_ipv6_nxt, tvb, offset, 1, ENC_NA);
- offset += 1;
- ti_len = proto_tree_add_item(unkopt_tree, hf_ipv6_opt_length, tvb, offset, 1, ENC_NA);
- proto_item_append_text(ti_len, " (%d byte%s)", len, plurality(len, "", "s"));
- /* offset += 1; */
- }
- return len;
- }
- static int
- dissect_opts(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info * pinfo, const int hf_option_item)
- {
- int len;
- int offset_end;
- proto_tree *dstopt_tree, *opt_tree;
- proto_item *ti, *ti_len, *ti_opt, *ti_opt_len;
- guint8 opt_len, opt_type;
- len = (tvb_get_guint8(tvb, offset + 1) + 1) << 3;
- offset_end = offset + len;
- if (tree) {
- /* !!! specify length */
- ti = proto_tree_add_item(tree, hf_option_item, tvb, offset, len, ENC_NA);
- dstopt_tree = proto_item_add_subtree(ti, ett_ipv6);
- proto_tree_add_item(dstopt_tree, hf_ipv6_nxt, tvb, offset, 1, ENC_NA);
- offset += 1;
- ti_len = proto_tree_add_item(dstopt_tree, hf_ipv6_opt_length, tvb, offset, 1, ENC_NA);
- proto_item_append_text(ti_len, " (%d byte%s)", len, plurality(len, "", "s"));
- offset += 1;
- while (offset_end > offset) {
- /* there are more options */
- /* IPv6 Option */
- ti_opt = proto_tree_add_item(dstopt_tree, hf_ipv6_opt, tvb, offset, 1, ENC_NA);
- opt_tree = proto_item_add_subtree(ti_opt, ett_ipv6_opt);
- /* Option type */
- proto_tree_add_item(opt_tree, hf_ipv6_opt_type, tvb, offset, 1, ENC_BIG_ENDIAN);
- opt_type = tvb_get_guint8(tvb, offset);
- /* Add option name to option root label */
- proto_item_append_text(ti_opt, " (%s", val_to_str(opt_type, ipv6_opt_vals, "Unknown %d"));
- /* The Pad1 option is a special case, and contains no data. */
- if (opt_type == IP6OPT_PAD1) {
- proto_tree_add_item(opt_tree, hf_ipv6_opt_pad1, tvb, offset, 1, ENC_NA);
- offset += 1;
- proto_item_append_text(ti_opt, ")");
- continue;
- }
- offset += 1;
- /* Option length */
- ti_opt_len = proto_tree_add_item(opt_tree, hf_ipv6_opt_length, tvb, offset, 1, ENC_BIG_ENDIAN);
- opt_len = tvb_get_guint8(tvb, offset);
- proto_item_set_len(ti_opt, opt_len + 2);
- offset += 1;
- switch (opt_type) {
- case IP6OPT_PADN:
- /* RFC 2460 states :
- * "The PadN option is used to insert two or more octets of
- * padding into the Options area of a header. For N octets of
- * padding, the Opt Data Len field contains the value N-2, and
- * the Option Data consists of N-2 zero-valued octets."
- */
- proto_tree_add_item(opt_tree, hf_ipv6_opt_padn, tvb,
- offset, opt_len, ENC_NA);
- offset += opt_len;
- break;
- case IP6OPT_TEL:
- if (opt_len != 1) {
- expert_add_info_format_text(pinfo, ti_opt_len, &ei_ipv6_opt_tel_invalid_len,
- "Tunnel Encapsulation Limit: Invalid length (%u bytes)", opt_len);
- }
- proto_tree_add_item(opt_tree, hf_ipv6_opt_tel, tvb,
- offset, 1, ENC_BIG_ENDIAN);
- offset += 1;
- break;
- case IP6OPT_JUMBO:
- if (opt_len != 4) {
- expert_add_info_format_text(pinfo, ti_opt_len, &ei_ipv6_opt_jumbo_invalid_len,
- "Jumbo payload: Invalid length (%u bytes)", opt_len);
- }
- proto_tree_add_item(opt_tree, hf_ipv6_opt_jumbo, tvb,
- offset, 4, ENC_BIG_ENDIAN);
- offset += 4;
- break;
- case IP6OPT_RTALERT:
- {
- if (opt_len != 2) {
- expert_add_info_format_text(pinfo, ti_opt_len, &ei_ipv6_opt_rtalert_invalid_len,
- "Router alert: Invalid Length (%u bytes)",
- opt_len + 2);
- }
- proto_tree_add_item(opt_tree, hf_ipv6_opt_rtalert, tvb,
- offset, 2, ENC_BIG_ENDIAN);
- offset += 2;
- break;
- }
- case IP6OPT_HOME_ADDRESS:
- if (opt_len != 16) {
- expert_add_info_format_text(pinfo, ti_opt_len, &ei_ipv6_mipv6_home_address_invalid_len,
- "Home Address: Invalid length (%u bytes)", opt_len);
- }
- proto_tree_add_item(opt_tree, hf_ipv6_mipv6_home_address, tvb,
- offset, 16, ENC_NA);
- TVB_SET_ADDRESS(&pinfo->src, AT_IPv6, tvb, offset, 16);
- offset += 16;
- break;
- case IP6OPT_CALIPSO:
- {
- guint8 cmpt_length;
- proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_doi, tvb,
- offset, 4, ENC_BIG_ENDIAN);
- offset += 4;
- proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_cmpt_length, tvb,
- offset, 1, ENC_BIG_ENDIAN);
- cmpt_length = tvb_get_guint8(tvb, offset);
- offset += 1;
- proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_sens_level, tvb,
- offset, 1, ENC_BIG_ENDIAN);
- offset += 1;
- /* Need to add Check Checksum..*/
- proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_checksum, tvb,
- offset, 2, ENC_BIG_ENDIAN);
- offset += 2;
- proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_cmpt_bitmap, tvb,
- offset, cmpt_length, ENC_NA);
- offset += cmpt_length;
- break;
- }
- case IP6OPT_QUICKSTART:
- {
- guint8 command = tvb_get_guint8(tvb, offset);
- guint8 function = command >> 4;
- guint8 rate = command & QS_RATE_MASK;
- guint8 ttl_diff;
- proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_func, tvb, offset, 1, ENC_NA);
- if (function == QS_RATE_REQUEST) {
- proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_rate, tvb, offset, 1, ENC_NA);
- offset += 1;
- proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_ttl, tvb, offset, 1, ENC_NA);
- ttl_diff = (pinfo->ip_ttl - tvb_get_guint8(tvb, offset) % 256);
- offset += 1;
- ti = proto_tree_add_uint_format_value(opt_tree, hf_ipv6_opt_qs_ttl_diff,
- tvb, offset, 1, ttl_diff,
- "%u", ttl_diff);
- PROTO_ITEM_SET_GENERATED(ti);
- proto_item_append_text(ti_opt, ", %s, QS TTL %u, QS TTL diff %u",
- val_to_str_ext(rate, &qs_rate_vals_ext, "Unknown (%u)"),
- tvb_get_guint8(tvb, offset), ttl_diff);
- offset += 1;
- proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_nonce, tvb, offset, 4, ENC_NA);
- proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_reserved, tvb, offset, 4, ENC_NA);
- offset += 4;
- } else if (function == QS_RATE_REPORT) {
- proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_rate, tvb, offset, 1, ENC_NA);
- offset += 1;
- proto_item_append_text(ti_opt, ", %s",
- val_to_str_ext(rate, &qs_rate_vals_ext, "Unknown (%u)"));
- proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_unused, tvb, offset, 1, ENC_NA);
- offset += 1;
- proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_nonce, tvb, offset, 4, ENC_NA);
- proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_reserved, tvb, offset, 4, ENC_NA);
- offset += 4;
- }
- }
- break;
- case IP6OPT_RPL:
- {
- proto_tree *flag_tree;
- proto_item *ti_flag;
- ti_flag = proto_tree_add_item(opt_tree, hf_ipv6_opt_rpl_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
- flag_tree = proto_item_add_subtree(ti_flag, ett_ipv6_opt_flag);
- proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_flag_o, tvb, offset, 1, ENC_BIG_ENDIAN);
- proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_flag_r, tvb, offset, 1, ENC_BIG_ENDIAN);
- proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_flag_f, tvb, offset, 1, ENC_BIG_ENDIAN);
- proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_flag_rsv, tvb, offset, 1, ENC_BIG_ENDIAN);
- offset +=1;
- proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_instance_id, tvb, offset, 1, ENC_BIG_ENDIAN);
- offset +=1;
- proto_tree_add_item(flag_tree, hf_ipv6_opt_rpl_senderrank, tvb, offset, 2, ENC_BIG_ENDIAN);
- offset +=2;
- /* TODO: Add dissector of sub TLV */
- }
- break;
- case IP6OPT_EXP_1E:
- case IP6OPT_EXP_3E:
- case IP6OPT_EXP_5E:
- case IP6OPT_EXP_7E:
- case IP6OPT_EXP_9E:
- case IP6OPT_EXP_BE:
- case IP6OPT_EXP_DE:
- case IP6OPT_EXP_FE:
- proto_tree_add_item(opt_tree, hf_ipv6_opt_experimental, tvb,
- offset, opt_len, ENC_NA);
- offset += opt_len;
- break;
- default:
- proto_tree_add_item(opt_tree, hf_ipv6_opt_unknown, tvb,
- offset, opt_len, ENC_NA);
- offset += opt_len;
- break;
- }
- /* Close the ) to option root label */
- proto_item_append_text(ti_opt, ")");
- }
- }
- return len;
- }
- static int
- dissect_hopopts(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info * pinfo)
- {
- return dissect_opts(tvb, offset, tree, pinfo, hf_ipv6_hop_opt);
- }
- static int
- dissect_dstopts(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info * pinfo)
- {
- return dissect_opts(tvb, offset, tree, pinfo, hf_ipv6_dst_opt);
- }
- /* START SHIM6 PART */
- static guint16 shim_checksum(const guint8 *ptr, int len)
- {
- vec_t cksum_vec[1];
- cksum_vec[0].ptr = ptr;
- cksum_vec[0].len = len;
- return in_cksum(&cksum_vec[0], 1);
- }
- static int
- dissect_shim_hex(tvbuff_t *tvb, int offset, int len, const char *itemname, guint8 bitmask, proto_tree *tree)
- {
- proto_item *ti;
- int count;
- gint p;
- p = offset;
- ti = proto_tree_add_text(tree, tvb, offset, len, "%s", itemname);
- proto_item_append_text(ti, " 0x%02x", tvb_get_guint8(tvb, p) & bitmask);
- for (count=1; count<len; count++)
- proto_item_append_text(ti, "%02x", tvb_get_guint8(tvb, p+count));
- return len;
- }
- static const value_string shimoptvals[] = {
- { SHIM6_OPT_RESPVAL, "Responder Validator Option" },
- { SHIM6_OPT_LOCLIST, "Locator List Option" },
- { SHIM6_OPT_LOCPREF, "Locator Preferences Option" },
- { SHIM6_OPT_CGAPDM, "CGA Parameter Data Structure Option" },
- { SHIM6_OPT_CGASIG, "CGA Signature Option" },
- { SHIM6_OPT_ULIDPAIR, "ULID Pair Option" },
- { SHIM6_OPT_FII, "Forked Instance Identifier Option" },
- { 0, NULL }
- };
- static const value_string shimverifmethods[] = {
- { SHIM6_VERIF_HBA, "HBA" },
- { SHIM6_VERIF_CGA, "CGA" },
- { 0, NULL }
- };
- static const value_string shimflags[] _U_ = {
- { SHIM6_FLAG_BROKEN, "BROKEN" },
- { SHIM6_FLAG_TEMPORARY, "TEMPORARY" },
- { 0, NULL }
- };
- static const value_string shimreapstates[] = {
- { SHIM6_REAP_OPERATIONAL, "Operational" },
- { SHIM6_REAP_EXPLORING, "Exploring" },
- { SHIM6_REAP_INBOUNDOK, "InboundOK" },
- { 0, NULL }
- };
- static const value_string shim6_protocol[] = {
- { 0, "SHIM6" },
- { 1, "HIP" },
- { 0, NULL }
- };
- static void
- dissect_shim6_opt_loclist(proto_tree * opt_tree, tvbuff_t * tvb, gint *offset)
- {
- proto_item * it;
- proto_tree * subtree;
- guint count;
- guint optlen;
- int p = *offset;
- proto_tree_add_item(opt_tree, hf_ipv6_shim6_opt_loclist, tvb, p, 4, ENC_BIG_ENDIAN);
- p += 4;
- optlen = tvb_get_guint8(tvb, p);
- proto_tree_add_item(opt_tree, hf_ipv6_shim6_opt_locnum, tvb, p, 1, ENC_BIG_ENDIAN);
- p++;
- /* Verification Methods */
- it = proto_tree_add_text(opt_tree, tvb, p, optlen,
- "Locator Verification Methods");
- subtree = proto_item_add_subtree(it, ett_ipv6_shim6_verif_methods);
- for (count=0; count < optlen; count++)
- proto_tree_add_item(subtree, hf_ipv6_shim6_opt_loc_verif_methods, tvb,
- p+count, 1, ENC_BIG_ENDIAN);
- p += optlen;
- /* Padding, included in length field */
- if ((7 - optlen % 8) > 0) {
- proto_tree_add_text(opt_tree, tvb, p, (7 - optlen % 8), "Padding");
- p += (7 - optlen % 8);
- }
- /* Locators */
- it = proto_tree_add_text(opt_tree, tvb, p, 16 * optlen, "Locators");
- subtree = proto_item_add_subtree(it, ett_ipv6_shim6_locators);
- for (count=0; count < optlen; count++) {
- proto_tree_add_item(subtree, hf_ipv6_shim6_locator, tvb, p, 16, ENC_NA);
- p += 16;
- }
- *offset = p;
- }
- static void
- dissect_shim6_opt_loc_pref(proto_tree * opt_tree, tvbuff_t * tvb, gint *offset, gint len, packet_info *pinfo)
- {
- proto_tree * subtree;
- proto_item * it;
- gint p;
- gint optlen;
- gint count;
- p = *offset;
- proto_tree_add_item(opt_tree, hf_ipv6_shim6_opt_loclist, tvb, p, 4, ENC_BIG_ENDIAN);
- p += 4;
- optlen = tvb_get_guint8(tvb, p);
- proto_tree_add_item(opt_tree, hf_ipv6_shim6_opt_elemlen, tvb, p, 1, ENC_BIG_ENDIAN);
- if (optlen < 1 || optlen > 3) {
- proto_tree_add_expert_format(opt_tree, pinfo, &ei_ipv6_shim6_opt_elemlen_invalid, tvb, p, 1,
- "Invalid element length: %u", optlen);
- return;
- }
- p++;
- /* Locator Preferences */
- count = 1;
- while (p < len) {
- it = proto_tree_add_text(opt_tree, tvb, p, optlen, "Locator Preferences %u", count);
- subtree = proto_item_add_subtree(it, ett_ipv6_shim6_loc_pref);
- /* Flags */
- if (optlen >= 1)
- proto_tree_add_item(subtree, hf_ipv6_shim6_loc_flag, tvb, p, 1, ENC_BIG_ENDIAN);
- /* Priority */
- if (opt…
Large files files are truncated, but you can click here to view the full file