From 8b0e9c66728f6a39bbe3ada1029e13ad1378013a Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Thu, 21 Jul 2016 10:21:25 -0400 Subject: Follow up for proto_tree_add_checksum. Fill in the "gaps" so that all dissectors that verify checksums have both a status and expert info field. Also address comments from original proto_tree_add_checksum patch that didn't make it. Ping-Bug: 8859 Change-Id: I2e6640108fd6bb218cb959fe9e4ba98a13e43a2f Reviewed-on: https://code.wireshark.org/review/16590 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/dissectors/packet-pim.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'epan/dissectors/packet-pim.c') diff --git a/epan/dissectors/packet-pim.c b/epan/dissectors/packet-pim.c index 1f216e6f54..bc51e92c4c 100644 --- a/epan/dissectors/packet-pim.c +++ b/epan/dissectors/packet-pim.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include "packet-igmp.h" @@ -135,6 +136,7 @@ static int hf_pim_igmp_type = -1; static int hf_pim_df_elect_subtype = -1; static int hf_pim_df_elect_rsvd = -1; static int hf_pim_cksum = -1; +static int hf_pim_cksum_status = -1; static int hf_pim_res_bytes = -1; /* PIM Hello options (RFC 4601, section 4.9.2 and RFC 3973, section 4.7.5) */ static int hf_pim_option = -1; @@ -217,6 +219,9 @@ static gint ett_pim = -1; static gint ett_pim_opts = -1; static gint ett_pim_opt = -1; +static expert_field ei_pim_cksum = EI_INIT; + + static dissector_handle_t ip_handle; static dissector_handle_t ipv6_handle; @@ -353,7 +358,7 @@ dissect_pimv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U pim_ver = PIM_VER(tvb_get_guint8(tvb, offset + 2)); if (pim_ver != 1) { - proto_tree_add_checksum(pim_tree, tvb, offset, hf_pim_cksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); + proto_tree_add_checksum(pim_tree, tvb, offset, hf_pim_cksum, hf_pim_cksum_status, &ei_pim_cksum, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); /* * Not PIMv1; should we bother dissecting the PIM drafts @@ -401,10 +406,11 @@ dissect_pimv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U * truncated, so we can checksum it. */ SET_CKSUM_VEC_TVB(cksum_vec[0], tvb, 0, pim_length); - proto_tree_add_checksum(pim_tree, tvb, offset, hf_pim_cksum, -1, NULL, pinfo, in_cksum(&cksum_vec[0], 1), - ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_IN_CKSUM); + proto_tree_add_checksum(pim_tree, tvb, offset, hf_pim_cksum, hf_pim_cksum_status, &ei_pim_cksum, + pinfo, in_cksum(&cksum_vec[0], 1), ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_IN_CKSUM); } else { - proto_tree_add_checksum(pim_tree, tvb, offset, hf_pim_cksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); + proto_tree_add_checksum(pim_tree, tvb, offset, hf_pim_cksum, hf_pim_cksum_status, &ei_pim_cksum, + pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); } offset += 2; @@ -843,7 +849,8 @@ dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) } if (PIM_VER(pim_typever) != 2) { - proto_tree_add_checksum(pim_tree, tvb, offset+2, hf_pim_cksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); + proto_tree_add_checksum(pim_tree, tvb, offset+2, hf_pim_cksum, hf_pim_cksum_status, &ei_pim_cksum, + pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); /* * We don't know this version, so we don't know how much of the * packet the checksum covers. @@ -885,8 +892,8 @@ dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) switch (pinfo->src.type) { case AT_IPv4: SET_CKSUM_VEC_TVB(cksum_vec[0], tvb, 0, pim_length); - proto_tree_add_checksum(pim_tree, tvb, offset+2, hf_pim_cksum, -1, NULL, pinfo, in_cksum(&cksum_vec[0], 1), - ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_IN_CKSUM); + proto_tree_add_checksum(pim_tree, tvb, offset+2, hf_pim_cksum, hf_pim_cksum_status, &ei_pim_cksum, + pinfo, in_cksum(&cksum_vec[0], 1), ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_IN_CKSUM); break; case AT_IPv6: /* Set up the fields of the pseudo-header. */ @@ -896,8 +903,8 @@ dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) phdr[1] = g_htonl(IP_PROTO_PIM); SET_CKSUM_VEC_PTR(cksum_vec[2], (const guint8 *)&phdr, 8); SET_CKSUM_VEC_TVB(cksum_vec[3], tvb, 0, pim_length); - proto_tree_add_checksum(pim_tree, tvb, offset+2, hf_pim_cksum, -1, NULL, pinfo, in_cksum(&cksum_vec[0], 4), - ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_IN_CKSUM); + proto_tree_add_checksum(pim_tree, tvb, offset+2, hf_pim_cksum, hf_pim_cksum_status, &ei_pim_cksum, + pinfo, in_cksum(&cksum_vec[0], 4), ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_IN_CKSUM); break; default: /* PIM is available for IPv4 and IPv6 right now */ @@ -905,7 +912,8 @@ dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) break; } } else { - proto_tree_add_checksum(pim_tree, tvb, offset+2, hf_pim_cksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); + proto_tree_add_checksum(pim_tree, tvb, offset+2, hf_pim_cksum, hf_pim_cksum_status, &ei_pim_cksum, + pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); } offset += 4; @@ -1446,6 +1454,11 @@ proto_register_pim(void) FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } }, + { &hf_pim_cksum_status, + { "Checksum Status", "pim.cksum.status", + FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0, + NULL, HFILL } + }, { &hf_pim_res_bytes, { "Reserved byte(s)", "pim.res_bytes", FT_BYTES, BASE_NONE, NULL, 0x0, @@ -1833,12 +1846,19 @@ proto_register_pim(void) &ett_pim_opt /* Tree for each option */ }; + static ei_register_info ei[] = { + { &ei_pim_cksum, { "pim.bad_checksum", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }}, + }; + + expert_module_t* expert_pim; module_t *pim_module; proto_pim = proto_register_protocol("Protocol Independent Multicast", "PIM", "pim"); proto_register_field_array(proto_pim, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); + expert_pim = expert_register_protocol(proto_pim); + expert_register_field_array(expert_pim, ei, array_length(ei)); pim_module = prefs_register_protocol(proto_pim, NULL); prefs_register_bool_preference(pim_module, "payload_tree", -- cgit v1.2.3