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 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>
39 #ifdef HAVE_NETINET_IN_H
40 # include <netinet/in.h>
45 #ifdef NEED_SNPRINTF_H
46 # include "snprintf.h"
49 #include <epan/packet.h>
52 /* Initialize the protocol and registered fields */
53 static int proto_gmrp = -1;
54 static int hf_gmrp_proto_id = -1;
55 static int hf_gmrp_attribute_type = -1;
56 static int hf_gmrp_attribute_length = -1;
57 static int hf_gmrp_attribute_event = -1;
58 static int hf_gmrp_attribute_value_group_membership = -1;
59 static int hf_gmrp_attribute_value_service_requirement = -1;
60 /*static int hf_gmrp_end_of_mark = -1;*/
62 /* Initialize the subtree pointers */
63 static gint ett_gmrp = -1;
64 /*static gint ett_gmrp_message = -1;
65 static gint ett_gmrp_attribute_list = -1;
66 static gint ett_gmrp_attribute = -1;*/
68 static dissector_handle_t data_handle;
70 /* Constant definitions */
71 #define GARP_DEFAULT_PROTOCOL_ID 0x0001
72 #define GARP_END_OF_MARK 0x00
74 #define GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP 0x01
75 #define GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT 0x02
77 #define GMRP_SERVICE_REQUIREMENT_FORWARD_ALL 0x00
78 #define GMRP_SERVICE_REQUIREMENT_FORWARD_ALL_UNREGISTERED 0x01
80 static const value_string attribute_type_vals[] = {
81 { GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP ,"Group Membership" },
82 { GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT ,"Service Requirement" },
86 /* The length of GMRP LeaveAll attribute should be 2 octets (one for length
87 * and the other for event) */
88 #define GMRP_LENGTH_LEAVEALL (sizeof(guint8)+sizeof(guint8))
90 /* The length of GMRP attribute other than LeaveAll should be:
92 * 8 bytes for Group Membership (1 for length, 1 for event and 6 for mac address to register)
94 * 3 bytes for Service Requirement (1 for length, 1 for event, 1 for attribute value)
97 #define GMRP_GROUP_MEMBERSHIP_NON_LEAVEALL (sizeof(guint8)+sizeof(guint8)+(6*sizeof(guint8)))
98 #define GMRP_SERVICE_REQUIREMENT_NON_LEAVEALL (sizeof(guint8)+sizeof(guint8)+sizeof(guint8))
100 /* Packet offset definitions */
101 #define GARP_PROTOCOL_ID 0
103 /* Event definitions */
104 #define GMRP_EVENT_LEAVEALL 0
105 #define GMRP_EVENT_JOINEMPTY 1
106 #define GMRP_EVENT_JOININ 2
107 #define GMRP_EVENT_LEAVEEMPTY 3
108 #define GMRP_EVENT_LEAVEIN 4
109 #define GMRP_EVENT_EMPTY 5
111 static const value_string event_vals[] = {
112 { GMRP_EVENT_LEAVEALL, "Leave All" },
113 { GMRP_EVENT_JOINEMPTY, "Join Empty" },
114 { GMRP_EVENT_JOININ, "Join In" },
115 { GMRP_EVENT_LEAVEEMPTY, "Leave Empty" },
116 { GMRP_EVENT_LEAVEIN, "Leave In" },
117 { GMRP_EVENT_EMPTY, "Empty" },
122 /* Code to actually dissect the packets */
124 dissect_gmrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
127 proto_tree *gmrp_tree;
130 guint8 attribute_type;
131 int msg_index, attr_index, offset = 0, length = tvb_reported_length(tvb);
133 if (check_col(pinfo->cinfo, COL_PROTOCOL))
134 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GMRP");
136 if (check_col(pinfo->cinfo, COL_INFO))
137 col_set_str(pinfo->cinfo, COL_INFO, "GMRP");
141 ti = proto_tree_add_item(tree, proto_gmrp, tvb, 0, length, FALSE);
143 gmrp_tree = proto_item_add_subtree(ti, ett_gmrp);
145 /* Read in GARP protocol ID */
146 protocol_id = tvb_get_ntohs(tvb, GARP_PROTOCOL_ID);
148 proto_tree_add_uint_format(gmrp_tree, hf_gmrp_proto_id, tvb,
149 GARP_PROTOCOL_ID, sizeof(guint16),
151 "Protocol Identifier: 0x%04x (%s)",
153 protocol_id == GARP_DEFAULT_PROTOCOL_ID ?
154 "GARP Multicast Registration Protocol" :
157 /* Currently only one protocol ID is supported */
158 if (protocol_id != GARP_DEFAULT_PROTOCOL_ID)
160 proto_tree_add_text(gmrp_tree, tvb, GARP_PROTOCOL_ID, sizeof(guint16),
161 " (Warning: this version of Ethereal only knows about protocol id = 1)");
162 call_dissector(data_handle,tvb_new_subset(tvb, GARP_PROTOCOL_ID + sizeof(guint16), -1,tvb_reported_length_remaining(tvb,GARP_PROTOCOL_ID + sizeof(guint16))),pinfo, tree);
166 offset += sizeof(guint16);
167 length -= sizeof(guint16);
171 /* Begin to parse GARP messages */
174 proto_item *msg_item;
175 int msg_start = offset;
177 /* Read in attribute type. */
178 attribute_type = octet = tvb_get_guint8(tvb, offset);
180 /* Check for end of mark */
181 if (octet == GARP_END_OF_MARK)
183 /* End of GARP PDU */
186 proto_tree_add_text(gmrp_tree, tvb, offset, sizeof(guint8),
192 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, tree);
197 offset += sizeof(guint8);
198 length -= sizeof(guint8);
200 msg_item = proto_tree_add_text(gmrp_tree, tvb, msg_start, -1,
201 "Message %d", msg_index + 1);
203 proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_type, tvb,
204 msg_start, sizeof(guint8), octet);
206 /* GMRP supports Group Membership and Service Requirement as attribute types */
207 if ( (octet != GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP) && (octet != GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT) )
209 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, tree);
217 int attr_start = offset;
218 proto_item *attr_item;
220 /* Read in attribute length. */
221 octet = tvb_get_guint8(tvb, offset);
223 /* Check for end of mark */
224 if (octet == GARP_END_OF_MARK)
226 /* If at least one message has been already read,
227 * check for another end of mark.
231 proto_tree_add_text(gmrp_tree, tvb, offset,
232 sizeof(guint8), " End of mark");
234 offset += sizeof(guint8);
235 length -= sizeof(guint8);
237 proto_item_set_len(msg_item, offset - msg_start);
242 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, tree);
250 offset += sizeof(guint8);
251 length -= sizeof(guint8);
253 attr_item = proto_tree_add_text(gmrp_tree, tvb,
254 attr_start, -1, " Attribute %d", attr_index + 1);
256 proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_length,
257 tvb, attr_start, sizeof(guint8), octet);
259 /* Read in attribute event */
260 event = tvb_get_guint8(tvb, offset);
262 proto_tree_add_uint(gmrp_tree, hf_gmrp_attribute_event,
263 tvb, offset, sizeof(guint8), event);
265 offset += sizeof(guint8);
266 length -= sizeof(guint8);
270 case GMRP_EVENT_LEAVEALL:
271 if (octet != GMRP_LENGTH_LEAVEALL)
273 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, tree);
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,tvb_new_subset(tvb, offset, -1,tvb_reported_length_remaining(tvb,offset)),pinfo, tree);
289 /* Show attribute value */
291 if ( GMRP_ATTRIBUTE_TYPE_GROUP_MEMBERSHIP == attribute_type )
293 /* Group Membership */
294 proto_tree_add_item(gmrp_tree, hf_gmrp_attribute_value_group_membership,
295 tvb, offset, (6*sizeof(guint8)), FALSE);
297 offset += 6*sizeof(guint8);
298 length -= 6*sizeof(guint8);
301 if ( GMRP_ATTRIBUTE_TYPE_SERVICE_REQUIREMENT == attribute_type )
303 /* Service Requirement */
304 proto_tree_add_item(gmrp_tree, hf_gmrp_attribute_value_service_requirement,
305 tvb, offset, sizeof(guint8), FALSE);
307 offset += sizeof(guint8);
308 length -= sizeof(guint8);
312 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, tree);
319 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, tree);
324 proto_item_set_len(attr_item, offset - attr_start);
336 /* Register the protocol with Ethereal */
338 proto_register_gmrp(void)
340 static hf_register_info hf[] = {
342 { "Protocol ID", "garp.protocol_id",
343 FT_UINT16, BASE_HEX, NULL, 0x0,
346 { &hf_gmrp_attribute_type,
347 { "Type", "garp.attribute_type",
348 FT_UINT8, BASE_HEX, VALS(attribute_type_vals), 0x0,
351 { &hf_gmrp_attribute_length,
352 { "Length", "garp.attribute_length",
353 FT_UINT8, BASE_DEC, NULL, 0x0,
356 { &hf_gmrp_attribute_event,
357 { "Event", "garp.attribute_event",
358 FT_UINT8, BASE_DEC, VALS(event_vals), 0x0,
361 { &hf_gmrp_attribute_value_group_membership,
362 { "Value", "garp.attribute_value_group_membership",
363 FT_ETHER, BASE_HEX, NULL, 0x0,
366 { &hf_gmrp_attribute_value_service_requirement,
367 { "Value", "garp.attribute_value_service_requirement",
368 FT_UINT8, BASE_HEX, NULL, 0x0,
374 static gint *ett[] = {
378 /* Register the protocol name and description for GMRP */
379 proto_gmrp = proto_register_protocol("GARP Multicast Registration Protocol", "GMRP", "gmrp");
381 /* Required function calls to register the header fields and subtrees
383 proto_register_field_array(proto_gmrp, hf, array_length(hf));
384 proto_register_subtree_array(ett, array_length(ett));
386 register_dissector("gmrp", dissect_gmrp, proto_gmrp);
391 proto_reg_handoff_gmrp(void){
392 data_handle = find_dissector("data");