From 87cf82e0561555493917eb8d5acb593ad73214d9 Mon Sep 17 00:00:00 2001 From: Bill Meier Date: Tue, 6 Mar 2012 16:58:09 +0000 Subject: Use tvb_new_subset_remaining() rather than tvb_new_subset(); #include not req'd (in a few cases); Minor reformating & whitespace cleanup. svn path=/trunk/; revision=41374 --- epan/dissectors/packet-gmrp.c | 531 +++++++++++++++++++++--------------------- 1 file changed, 266 insertions(+), 265 deletions(-) (limited to 'epan/dissectors/packet-gmrp.c') diff --git a/epan/dissectors/packet-gmrp.c b/epan/dissectors/packet-gmrp.c index 906861f58c..b9bd860e28 100644 --- a/epan/dissectors/packet-gmrp.c +++ b/epan/dissectors/packet-gmrp.c @@ -56,24 +56,24 @@ static gint ett_gmrp_attribute = -1;*/ static dissector_handle_t data_handle; /* Constant definitions */ -#define GARP_DEFAULT_PROTOCOL_ID 0x0001 -#define GARP_END_OF_MARK 0x00 +#define GARP_DEFAULT_PROTOCOL_ID 0x0001 +#define GARP_END_OF_MARK 0x00 -#define GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP 0x01 -#define GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT 0x02 +#define GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP 0x01 +#define GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT 0x02 -#define GMRP_SERVICE_REQUIREMENT_FORWARD_ALL 0x00 -#define GMRP_SERVICE_REQUIREMENT_FORWARD_ALL_UNREGISTERED 0x01 +#define GMRP_SERVICE_REQUIREMENT_FORWARD_ALL 0x00 +#define GMRP_SERVICE_REQUIREMENT_FORWARD_ALL_UNREGISTERED 0x01 static const value_string attribute_type_vals[] = { - { GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP ,"Group Membership" }, - { GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT ,"Service Requirement" }, - { 0, NULL } + { GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP ,"Group Membership" }, + { GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT ,"Service Requirement" }, + { 0, NULL } }; /* The length of GMRP LeaveAll attribute should be 2 octets (one for length * and the other for event) */ -#define GMRP_LENGTH_LEAVEALL (sizeof(guint8)+sizeof(guint8)) +#define GMRP_LENGTH_LEAVEALL (sizeof(guint8)+sizeof(guint8)) /* The length of GMRP attribute other than LeaveAll should be: * @@ -82,28 +82,28 @@ static const value_string attribute_type_vals[] = { * 3 bytes for Service Requirement (1 for length, 1 for event, 1 for attribute value) * */ -#define GMRP_GROUP_MEMBERSHIP_NON_LEAVEALL (sizeof(guint8)+sizeof(guint8)+(6*sizeof(guint8))) -#define GMRP_SERVICE_REQUIREMENT_NON_LEAVEALL (sizeof(guint8)+sizeof(guint8)+sizeof(guint8)) +#define GMRP_GROUP_MEMBERSHIP_NON_LEAVEALL (sizeof(guint8)+sizeof(guint8)+(6*sizeof(guint8))) +#define GMRP_SERVICE_REQUIREMENT_NON_LEAVEALL (sizeof(guint8)+sizeof(guint8)+sizeof(guint8)) /* Packet offset definitions */ -#define GARP_PROTOCOL_ID 0 +#define GARP_PROTOCOL_ID 0 /* Event definitions */ -#define GMRP_EVENT_LEAVEALL 0 -#define GMRP_EVENT_JOINEMPTY 1 -#define GMRP_EVENT_JOININ 2 -#define GMRP_EVENT_LEAVEEMPTY 3 -#define GMRP_EVENT_LEAVEIN 4 -#define GMRP_EVENT_EMPTY 5 +#define GMRP_EVENT_LEAVEALL 0 +#define GMRP_EVENT_JOINEMPTY 1 +#define GMRP_EVENT_JOININ 2 +#define GMRP_EVENT_LEAVEEMPTY 3 +#define GMRP_EVENT_LEAVEIN 4 +#define GMRP_EVENT_EMPTY 5 static const value_string event_vals[] = { - { GMRP_EVENT_LEAVEALL, "Leave All" }, - { GMRP_EVENT_JOINEMPTY, "Join Empty" }, - { GMRP_EVENT_JOININ, "Join In" }, - { GMRP_EVENT_LEAVEEMPTY, "Leave Empty" }, - { GMRP_EVENT_LEAVEIN, "Leave In" }, - { GMRP_EVENT_EMPTY, "Empty" }, - { 0, NULL } + { GMRP_EVENT_LEAVEALL, "Leave All" }, + { GMRP_EVENT_JOINEMPTY, "Join Empty" }, + { GMRP_EVENT_JOININ, "Join In" }, + { GMRP_EVENT_LEAVEEMPTY, "Leave Empty" }, + { GMRP_EVENT_LEAVEIN, "Leave In" }, + { GMRP_EVENT_EMPTY, "Empty" }, + { 0, NULL } }; @@ -115,7 +115,7 @@ dissect_gmrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree *gmrp_tree; guint16 protocol_id; guint8 octet; - guint8 attribute_type; + guint8 attribute_type; int msg_index, attr_index, offset = 0, length = tvb_reported_length(tvb); col_set_str(pinfo->cinfo, COL_PROTOCOL, "GMRP"); @@ -124,212 +124,213 @@ dissect_gmrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if (tree) { - ti = proto_tree_add_item(tree, proto_gmrp, tvb, 0, length, ENC_NA); - - gmrp_tree = proto_item_add_subtree(ti, ett_gmrp); - - /* Read in GARP protocol ID */ - protocol_id = tvb_get_ntohs(tvb, GARP_PROTOCOL_ID); - - proto_tree_add_uint_format(gmrp_tree, hf_gmrp_proto_id, tvb, - GARP_PROTOCOL_ID, sizeof(guint16), - protocol_id, - "Protocol Identifier: 0x%04x (%s)", - protocol_id, - protocol_id == GARP_DEFAULT_PROTOCOL_ID ? - "GARP Multicast Registration Protocol" : - "Unknown Protocol"); - - /* Currently only one protocol ID is supported */ - if (protocol_id != GARP_DEFAULT_PROTOCOL_ID) - { - proto_tree_add_text(gmrp_tree, tvb, GARP_PROTOCOL_ID, sizeof(guint16), - " (Warning: this version of Wireshark only knows about protocol id = 1)"); - call_dissector(data_handle, - tvb_new_subset(tvb, GARP_PROTOCOL_ID + sizeof(guint16), -1, -1), - pinfo, tree); - return; - } - - offset += sizeof(guint16); - length -= sizeof(guint16); - - msg_index = 0; - - /* Begin to parse GARP messages */ - while (length) - { - proto_item *msg_item; - int msg_start = offset; - - /* Read in attribute type. */ - attribute_type = octet = tvb_get_guint8(tvb, offset); - - /* Check for end of mark */ - if (octet == GARP_END_OF_MARK) - { - /* End of GARP PDU */ - if (msg_index) - { - proto_tree_add_text(gmrp_tree, tvb, offset, sizeof(guint8), - "End of pdu"); - break; - } - else - { - call_dissector(data_handle, - tvb_new_subset_remaining(tvb, offset), - pinfo, tree); - return; - } - } - - offset += sizeof(guint8); - length -= sizeof(guint8); - - msg_item = proto_tree_add_text(gmrp_tree, tvb, msg_start, -1, - "Message %d", msg_index + 1); - - proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_type, tvb, - msg_start, sizeof(guint8), octet); - - /* GMRP supports Group Membership and Service Requirement as attribute types */ - if ( (octet != GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP) && (octet != GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT) ) - { - call_dissector(data_handle, - tvb_new_subset_remaining(tvb, offset), pinfo, - tree); - return; - } - - attr_index = 0; - - while (length) - { - int attr_start = offset; - proto_item *attr_item; - - /* Read in attribute length. */ - octet = tvb_get_guint8(tvb, offset); - - /* Check for end of mark */ - if (octet == GARP_END_OF_MARK) - { - /* If at least one message has been already read, - * check for another end of mark. - */ - if (attr_index) - { - proto_tree_add_text(gmrp_tree, tvb, offset, - sizeof(guint8), " End of mark"); - - offset += sizeof(guint8); - length -= sizeof(guint8); - - proto_item_set_len(msg_item, offset - msg_start); - break; - } - else - { - call_dissector(data_handle, - tvb_new_subset_remaining(tvb, offset), - pinfo, tree); - return; - } - } - else - { - guint8 event; - - offset += sizeof(guint8); - length -= sizeof(guint8); - - attr_item = proto_tree_add_text(gmrp_tree, tvb, - attr_start, -1, " Attribute %d", attr_index + 1); - - proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_length, - tvb, attr_start, sizeof(guint8), octet); - - /* Read in attribute event */ - event = tvb_get_guint8(tvb, offset); - - proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_event, - tvb, offset, sizeof(guint8), event); - - offset += sizeof(guint8); - length -= sizeof(guint8); - - switch (event) { - - case GMRP_EVENT_LEAVEALL: - if (octet != GMRP_LENGTH_LEAVEALL) - { - call_dissector(data_handle, - tvb_new_subset_remaining(tvb, offset), - pinfo, tree); - return; - } - break; - - case GMRP_EVENT_JOINEMPTY: - case GMRP_EVENT_JOININ: - case GMRP_EVENT_LEAVEEMPTY: - case GMRP_EVENT_LEAVEIN: - case GMRP_EVENT_EMPTY: - if ( (octet != GMRP_GROUP_MEMBERSHIP_NON_LEAVEALL) && (octet != GMRP_SERVICE_REQUIREMENT_NON_LEAVEALL) ) - { - call_dissector(data_handle, - tvb_new_subset_remaining(tvb, offset), - pinfo, tree); - return; - } - - /* Show attribute value */ - - if ( GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP == attribute_type ) - { - /* Group Membership */ - proto_tree_add_item(gmrp_tree, hf_gmrp_attribute_value_group_membership, - tvb, offset, (6*sizeof(guint8)), ENC_NA); - - offset += 6*sizeof(guint8); - length -= 6*sizeof(guint8); - } - else - if ( GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT == attribute_type ) - { - /* Service Requirement */ - proto_tree_add_item(gmrp_tree, hf_gmrp_attribute_value_service_requirement, - tvb, offset, sizeof(guint8), ENC_BIG_ENDIAN); - - offset += sizeof(guint8); - length -= sizeof(guint8); - } - else - { - call_dissector(data_handle, - tvb_new_subset_remaining(tvb, offset), - pinfo, tree); - return; - } - - break; - - default: - call_dissector(data_handle, - tvb_new_subset_remaining(tvb, offset), - pinfo, tree); - return; - } - } - - proto_item_set_len(attr_item, offset - attr_start); - - attr_index++; - } - - msg_index++; - } + ti = proto_tree_add_item(tree, proto_gmrp, tvb, 0, -1, ENC_NA); + + gmrp_tree = proto_item_add_subtree(ti, ett_gmrp); + + /* Read in GARP protocol ID */ + protocol_id = tvb_get_ntohs(tvb, GARP_PROTOCOL_ID); + + proto_tree_add_uint_format(gmrp_tree, hf_gmrp_proto_id, tvb, + GARP_PROTOCOL_ID, sizeof(guint16), + protocol_id, + "Protocol Identifier: 0x%04x (%s)", + protocol_id, + protocol_id == GARP_DEFAULT_PROTOCOL_ID ? + "GARP Multicast Registration Protocol" : + "Unknown Protocol"); + + /* Currently only one protocol ID is supported */ + if (protocol_id != GARP_DEFAULT_PROTOCOL_ID) + { + proto_tree_add_text(gmrp_tree, tvb, GARP_PROTOCOL_ID, sizeof(guint16), + " (Warning: this version of Wireshark only knows about protocol id = 1)"); + call_dissector(data_handle, + tvb_new_subset_remaining(tvb, GARP_PROTOCOL_ID + sizeof(guint16)), + pinfo, tree); + return; + } + + offset += sizeof(guint16); + length -= sizeof(guint16); + + msg_index = 0; + + /* Begin to parse GARP messages */ + while (length) + { + proto_item *msg_item; + int msg_start = offset; + + /* Read in attribute type. */ + attribute_type = octet = tvb_get_guint8(tvb, offset); + + /* Check for end of mark */ + if (octet == GARP_END_OF_MARK) + { + /* End of GARP PDU */ + if (msg_index) + { + proto_tree_add_text(gmrp_tree, tvb, offset, sizeof(guint8), + "End of pdu"); + break; + } + else + { + call_dissector(data_handle, + tvb_new_subset_remaining(tvb, offset), + pinfo, tree); + return; + } + } + + offset += sizeof(guint8); + length -= sizeof(guint8); + + msg_item = proto_tree_add_text(gmrp_tree, tvb, msg_start, -1, + "Message %d", msg_index + 1); + + proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_type, tvb, + msg_start, sizeof(guint8), octet); + + /* GMRP supports Group Membership and Service Requirement as attribute types */ + if ( (octet != GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP) && (octet != GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT) ) + { + call_dissector(data_handle, + tvb_new_subset_remaining(tvb, offset), pinfo, + tree); + return; + } + + attr_index = 0; + + while (length) + { + int attr_start = offset; + proto_item *attr_item; + + /* Read in attribute length. */ + octet = tvb_get_guint8(tvb, offset); + + /* Check for end of mark */ + if (octet == GARP_END_OF_MARK) + { + /* If at least one message has been already read, + * check for another end of mark. + */ + if (attr_index) + { + proto_tree_add_text(gmrp_tree, tvb, offset, + sizeof(guint8), " End of mark"); + + offset += sizeof(guint8); + length -= sizeof(guint8); + + proto_item_set_len(msg_item, offset - msg_start); + break; + } + else + { + call_dissector(data_handle, + tvb_new_subset_remaining(tvb, offset), + pinfo, tree); + return; + } + } + else + { + guint8 event; + + offset += sizeof(guint8); + length -= sizeof(guint8); + + attr_item = proto_tree_add_text(gmrp_tree, tvb, + attr_start, -1, " Attribute %d", attr_index + 1); + + proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_length, + tvb, attr_start, sizeof(guint8), octet); + + /* Read in attribute event */ + event = tvb_get_guint8(tvb, offset); + + proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_event, + tvb, offset, sizeof(guint8), event); + + offset += sizeof(guint8); + length -= sizeof(guint8); + + switch (event) { + + case GMRP_EVENT_LEAVEALL: + if (octet != GMRP_LENGTH_LEAVEALL) + { + call_dissector(data_handle, + tvb_new_subset_remaining(tvb, offset), + pinfo, tree); + return; + } + break; + + case GMRP_EVENT_JOINEMPTY: + case GMRP_EVENT_JOININ: + case GMRP_EVENT_LEAVEEMPTY: + case GMRP_EVENT_LEAVEIN: + case GMRP_EVENT_EMPTY: + if ( (octet != GMRP_GROUP_MEMBERSHIP_NON_LEAVEALL) && + (octet != GMRP_SERVICE_REQUIREMENT_NON_LEAVEALL) ) + { + call_dissector(data_handle, + tvb_new_subset_remaining(tvb, offset), + pinfo, tree); + return; + } + + /* Show attribute value */ + + if ( GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP == attribute_type ) + { + /* Group Membership */ + proto_tree_add_item(gmrp_tree, hf_gmrp_attribute_value_group_membership, + tvb, offset, (6*sizeof(guint8)), ENC_NA); + + offset += 6*sizeof(guint8); + length -= 6*sizeof(guint8); + } + else + if ( GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT == attribute_type ) + { + /* Service Requirement */ + proto_tree_add_item(gmrp_tree, hf_gmrp_attribute_value_service_requirement, + tvb, offset, sizeof(guint8), ENC_BIG_ENDIAN); + + offset += sizeof(guint8); + length -= sizeof(guint8); + } + else + { + call_dissector(data_handle, + tvb_new_subset_remaining(tvb, offset), + pinfo, tree); + return; + } + + break; + + default: + call_dissector(data_handle, + tvb_new_subset_remaining(tvb, offset), + pinfo, tree); + return; + } + } + + proto_item_set_len(attr_item, offset - attr_start); + + attr_index++; + } + + msg_index++; + } } } @@ -340,41 +341,41 @@ void proto_register_gmrp(void) { static hf_register_info hf[] = { - { &hf_gmrp_proto_id, - { "Protocol ID", "gmrp.protocol_id", - FT_UINT16, BASE_HEX, NULL, 0x0, - NULL , HFILL } - }, - { &hf_gmrp_attribute_type, - { "Type", "gmrp.attribute_type", - FT_UINT8, BASE_HEX, VALS(attribute_type_vals), 0x0, - NULL , HFILL } - }, - { &hf_gmrp_attribute_length, - { "Length", "gmrp.attribute_length", - FT_UINT8, BASE_DEC, NULL, 0x0, - NULL , HFILL } - }, - { &hf_gmrp_attribute_event, - { "Event", "gmrp.attribute_event", - FT_UINT8, BASE_DEC, VALS(event_vals), 0x0, - NULL , HFILL } - }, - { &hf_gmrp_attribute_value_group_membership, - { "Value", "gmrp.attribute_value_group_membership", - FT_ETHER, BASE_NONE, NULL, 0x0, - NULL , HFILL } - }, - { &hf_gmrp_attribute_value_service_requirement, - { "Value", "gmrp.attribute_value_service_requirement", - FT_UINT8, BASE_HEX, NULL, 0x0, - NULL , HFILL } - } + { &hf_gmrp_proto_id, + { "Protocol ID", "gmrp.protocol_id", + FT_UINT16, BASE_HEX, NULL, 0x0, + NULL , HFILL } + }, + { &hf_gmrp_attribute_type, + { "Type", "gmrp.attribute_type", + FT_UINT8, BASE_HEX, VALS(attribute_type_vals), 0x0, + NULL , HFILL } + }, + { &hf_gmrp_attribute_length, + { "Length", "gmrp.attribute_length", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL , HFILL } + }, + { &hf_gmrp_attribute_event, + { "Event", "gmrp.attribute_event", + FT_UINT8, BASE_DEC, VALS(event_vals), 0x0, + NULL , HFILL } + }, + { &hf_gmrp_attribute_value_group_membership, + { "Value", "gmrp.attribute_value_group_membership", + FT_ETHER, BASE_NONE, NULL, 0x0, + NULL , HFILL } + }, + { &hf_gmrp_attribute_value_service_requirement, + { "Value", "gmrp.attribute_value_service_requirement", + FT_UINT8, BASE_HEX, NULL, 0x0, + NULL , HFILL } + } }; static gint *ett[] = { - &ett_gmrp + &ett_gmrp }; /* Register the protocol name and description for GMRP */ @@ -391,5 +392,5 @@ proto_register_gmrp(void) void proto_reg_handoff_gmrp(void){ - data_handle = find_dissector("data"); + data_handle = find_dissector("data"); } -- cgit v1.2.3