2 * Routines for GMRP (GARP Multicast Registration Protocol) dissection
3 * Copyright 2001, Markus Seehofer <mseehofe@nt.hirschmann.de>
5 * Based on the code from packet-gvrp.c (GVRP) from
6 * Kevin Shi <techishi@ms22.hinet.net> Copyright 2000
8 * $Id: packet-gmrp.c,v 1.10 2002/08/28 21:00:13 jmayer Exp $
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
12 * Copyright 1998 Gerald Combs
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 #include <epan/packet.h>
42 /* Initialize the protocol and registered fields */
43 static int proto_gmrp = -1;
44 static int hf_gmrp_proto_id = -1;
45 static int hf_gmrp_attribute_type = -1;
46 static int hf_gmrp_attribute_length = -1;
47 static int hf_gmrp_attribute_event = -1;
48 static int hf_gmrp_attribute_value_group_membership = -1;
49 static int hf_gmrp_attribute_value_service_requirement = -1;
50 /*static int hf_gmrp_end_of_mark = -1;*/
52 /* Initialize the subtree pointers */
53 static gint ett_gmrp = -1;
54 /*static gint ett_gmrp_message = -1;
55 static gint ett_gmrp_attribute_list = -1;
56 static gint ett_gmrp_attribute = -1;*/
58 static dissector_handle_t data_handle;
60 /* Constant definitions */
61 #define GARP_DEFAULT_PROTOCOL_ID 0x0001
62 #define GARP_END_OF_MARK 0x00
64 #define GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP 0x01
65 #define GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT 0x02
67 #define GMRP_SERVICE_REQUIREMENT_FORWARD_ALL 0x00
68 #define GMRP_SERVICE_REQUIREMENT_FORWARD_ALL_UNREGISTERED 0x01
70 static const value_string attribute_type_vals[] = {
71 { GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP ,"Group Membership" },
72 { GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT ,"Service Requirement" },
76 /* The length of GMRP LeaveAll attribute should be 2 octets (one for length
77 * and the other for event) */
78 #define GMRP_LENGTH_LEAVEALL (sizeof(guint8)+sizeof(guint8))
80 /* The length of GMRP attribute other than LeaveAll should be:
82 * 8 bytes for Group Membership (1 for length, 1 for event and 6 for mac address to register)
84 * 3 bytes for Service Requirement (1 for length, 1 for event, 1 for attribute value)
87 #define GMRP_GROUP_MEMBERSHIP_NON_LEAVEALL (sizeof(guint8)+sizeof(guint8)+(6*sizeof(guint8)))
88 #define GMRP_SERVICE_REQUIREMENT_NON_LEAVEALL (sizeof(guint8)+sizeof(guint8)+sizeof(guint8))
90 /* Packet offset definitions */
91 #define GARP_PROTOCOL_ID 0
93 /* Event definitions */
94 #define GMRP_EVENT_LEAVEALL 0
95 #define GMRP_EVENT_JOINEMPTY 1
96 #define GMRP_EVENT_JOININ 2
97 #define GMRP_EVENT_LEAVEEMPTY 3
98 #define GMRP_EVENT_LEAVEIN 4
99 #define GMRP_EVENT_EMPTY 5
101 static const value_string event_vals[] = {
102 { GMRP_EVENT_LEAVEALL, "Leave All" },
103 { GMRP_EVENT_JOINEMPTY, "Join Empty" },
104 { GMRP_EVENT_JOININ, "Join In" },
105 { GMRP_EVENT_LEAVEEMPTY, "Leave Empty" },
106 { GMRP_EVENT_LEAVEIN, "Leave In" },
107 { GMRP_EVENT_EMPTY, "Empty" },
112 /* Code to actually dissect the packets */
114 dissect_gmrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
117 proto_tree *gmrp_tree;
120 guint8 attribute_type;
121 int msg_index, attr_index, offset = 0, length = tvb_reported_length(tvb);
123 if (check_col(pinfo->cinfo, COL_PROTOCOL))
124 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GMRP");
126 if (check_col(pinfo->cinfo, COL_INFO))
127 col_set_str(pinfo->cinfo, COL_INFO, "GMRP");
131 ti = proto_tree_add_item(tree, proto_gmrp, tvb, 0, length, FALSE);
133 gmrp_tree = proto_item_add_subtree(ti, ett_gmrp);
135 /* Read in GARP protocol ID */
136 protocol_id = tvb_get_ntohs(tvb, GARP_PROTOCOL_ID);
138 proto_tree_add_uint_format(gmrp_tree, hf_gmrp_proto_id, tvb,
139 GARP_PROTOCOL_ID, sizeof(guint16),
141 "Protocol Identifier: 0x%04x (%s)",
143 protocol_id == GARP_DEFAULT_PROTOCOL_ID ?
144 "GARP Multicast Registration Protocol" :
147 /* Currently only one protocol ID is supported */
148 if (protocol_id != GARP_DEFAULT_PROTOCOL_ID)
150 proto_tree_add_text(gmrp_tree, tvb, GARP_PROTOCOL_ID, sizeof(guint16),
151 " (Warning: this version of Ethereal only knows about protocol id = 1)");
152 call_dissector(data_handle,
153 tvb_new_subset(tvb, GARP_PROTOCOL_ID + sizeof(guint16), -1, -1),
158 offset += sizeof(guint16);
159 length -= sizeof(guint16);
163 /* Begin to parse GARP messages */
166 proto_item *msg_item;
167 int msg_start = offset;
169 /* Read in attribute type. */
170 attribute_type = octet = tvb_get_guint8(tvb, offset);
172 /* Check for end of mark */
173 if (octet == GARP_END_OF_MARK)
175 /* End of GARP PDU */
178 proto_tree_add_text(gmrp_tree, tvb, offset, sizeof(guint8),
184 call_dissector(data_handle,
185 tvb_new_subset(tvb, offset, -1, -1),
191 offset += sizeof(guint8);
192 length -= sizeof(guint8);
194 msg_item = proto_tree_add_text(gmrp_tree, tvb, msg_start, -1,
195 "Message %d", msg_index + 1);
197 proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_type, tvb,
198 msg_start, sizeof(guint8), octet);
200 /* GMRP supports Group Membership and Service Requirement as attribute types */
201 if ( (octet != GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP) && (octet != GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT) )
203 call_dissector(data_handle,
204 tvb_new_subset(tvb, offset, -1, -1), pinfo,
213 int attr_start = offset;
214 proto_item *attr_item;
216 /* Read in attribute length. */
217 octet = tvb_get_guint8(tvb, offset);
219 /* Check for end of mark */
220 if (octet == GARP_END_OF_MARK)
222 /* If at least one message has been already read,
223 * check for another end of mark.
227 proto_tree_add_text(gmrp_tree, tvb, offset,
228 sizeof(guint8), " End of mark");
230 offset += sizeof(guint8);
231 length -= sizeof(guint8);
233 proto_item_set_len(msg_item, offset - msg_start);
238 call_dissector(data_handle,
239 tvb_new_subset(tvb, offset, -1, -1),
248 offset += sizeof(guint8);
249 length -= sizeof(guint8);
251 attr_item = proto_tree_add_text(gmrp_tree, tvb,
252 attr_start, -1, " Attribute %d", attr_index + 1);
254 proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_length,
255 tvb, attr_start, sizeof(guint8), octet);
257 /* Read in attribute event */
258 event = tvb_get_guint8(tvb, offset);
260 proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_event,
261 tvb, offset, sizeof(guint8), event);
263 offset += sizeof(guint8);
264 length -= sizeof(guint8);
268 case GMRP_EVENT_LEAVEALL:
269 if (octet != GMRP_LENGTH_LEAVEALL)
271 call_dissector(data_handle,
272 tvb_new_subset(tvb, offset, -1, -1),
278 case GMRP_EVENT_JOINEMPTY:
279 case GMRP_EVENT_JOININ:
280 case GMRP_EVENT_LEAVEEMPTY:
281 case GMRP_EVENT_LEAVEIN:
282 case GMRP_EVENT_EMPTY:
283 if ( (octet != GMRP_GROUP_MEMBERSHIP_NON_LEAVEALL) && (octet != GMRP_SERVICE_REQUIREMENT_NON_LEAVEALL) )
285 call_dissector(data_handle,
286 tvb_new_subset(tvb, offset, -1, -1),
291 /* Show attribute value */
293 if ( GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP == attribute_type )
295 /* Group Membership */
296 proto_tree_add_item(gmrp_tree, hf_gmrp_attribute_value_group_membership,
297 tvb, offset, (6*sizeof(guint8)), FALSE);
299 offset += 6*sizeof(guint8);
300 length -= 6*sizeof(guint8);
303 if ( GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT == attribute_type )
305 /* Service Requirement */
306 proto_tree_add_item(gmrp_tree, hf_gmrp_attribute_value_service_requirement,
307 tvb, offset, sizeof(guint8), FALSE);
309 offset += sizeof(guint8);
310 length -= sizeof(guint8);
314 call_dissector(data_handle,
315 tvb_new_subset(tvb, offset, -1, -1),
323 call_dissector(data_handle,
324 tvb_new_subset(tvb, offset, -1, -1),
330 proto_item_set_len(attr_item, offset - attr_start);
342 /* Register the protocol with Ethereal */
344 proto_register_gmrp(void)
346 static hf_register_info hf[] = {
348 { "Protocol ID", "garp.protocol_id",
349 FT_UINT16, BASE_HEX, NULL, 0x0,
352 { &hf_gmrp_attribute_type,
353 { "Type", "garp.attribute_type",
354 FT_UINT8, BASE_HEX, VALS(attribute_type_vals), 0x0,
357 { &hf_gmrp_attribute_length,
358 { "Length", "garp.attribute_length",
359 FT_UINT8, BASE_DEC, NULL, 0x0,
362 { &hf_gmrp_attribute_event,
363 { "Event", "garp.attribute_event",
364 FT_UINT8, BASE_DEC, VALS(event_vals), 0x0,
367 { &hf_gmrp_attribute_value_group_membership,
368 { "Value", "garp.attribute_value_group_membership",
369 FT_ETHER, BASE_HEX, NULL, 0x0,
372 { &hf_gmrp_attribute_value_service_requirement,
373 { "Value", "garp.attribute_value_service_requirement",
374 FT_UINT8, BASE_HEX, NULL, 0x0,
380 static gint *ett[] = {
384 /* Register the protocol name and description for GMRP */
385 proto_gmrp = proto_register_protocol("GARP Multicast Registration Protocol", "GMRP", "gmrp");
387 /* Required function calls to register the header fields and subtrees
389 proto_register_field_array(proto_gmrp, hf, array_length(hf));
390 proto_register_subtree_array(ett, array_length(ett));
392 register_dissector("gmrp", dissect_gmrp, proto_gmrp);
397 proto_reg_handoff_gmrp(void){
398 data_handle = find_dissector("data");