2 * Routines for GVRP (GARP VLAN Registration Protocol) dissection
3 * Copyright 2000, Kevin Shi <techishi@ms22.hinet.net>
5 * $Id: packet-gvrp.c,v 1.6 2001/06/18 02:17:46 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
44 #ifdef NEED_SNPRINTF_H
45 # include "snprintf.h"
51 /* Initialize the protocol and registered fields */
52 static int proto_gvrp = -1;
53 static int hf_gvrp_proto_id = -1;
54 static int hf_gvrp_attribute_type = -1;
55 static int hf_gvrp_attribute_length = -1;
56 static int hf_gvrp_attribute_event = -1;
57 static int hf_gvrp_attribute_value = -1;
58 /*static int hf_gvrp_end_of_mark = -1;*/
60 /* Initialize the subtree pointers */
61 static gint ett_gvrp = -1;
62 /*static gint ett_gvrp_message = -1;
63 static gint ett_gvrp_attribute_list = -1;
64 static gint ett_gvrp_attribute = -1;*/
66 /* Constant definitions */
67 #define GARP_DEFAULT_PROTOCOL_ID 0x0001
68 #define GARP_END_OF_MARK 0x00
70 #define GVRP_ATTRIBUTE_TYPE 0x01
72 static const value_string attribute_type_vals[] = {
73 { GVRP_ATTRIBUTE_TYPE, "VID" },
77 /* The length of GVRP LeaveAll attribute should be 2 octets (one for length
78 * and the other for event) */
79 #define GVRP_LENGTH_LEAVEALL (sizeof(guint8)+sizeof(guint8))
81 /* The length of GVRP attribute other than LeaveAll should be 4 octets (one
82 * for length, one for event, and the last two for VID value).
84 #define GVRP_LENGTH_NON_LEAVEALL (sizeof(guint8)+sizeof(guint8)+sizeof(guint16))
86 /* Packet offset definitions */
87 #define GARP_PROTOCOL_ID 0
89 /* Event definitions */
90 #define GVRP_EVENT_LEAVEALL 0
91 #define GVRP_EVENT_JOINEMPTY 1
92 #define GVRP_EVENT_JOININ 2
93 #define GVRP_EVENT_LEAVEEMPTY 3
94 #define GVRP_EVENT_LEAVEIN 4
95 #define GVRP_EVENT_EMPTY 5
97 static const value_string event_vals[] = {
98 { GVRP_EVENT_LEAVEALL, "Leave All" },
99 { GVRP_EVENT_JOINEMPTY, "Join Empty" },
100 { GVRP_EVENT_JOININ, "Join In" },
101 { GVRP_EVENT_LEAVEEMPTY, "Leave Empty" },
102 { GVRP_EVENT_LEAVEIN, "Leave In" },
103 { GVRP_EVENT_EMPTY, "Empty" },
107 /* Code to actually dissect the packets */
109 dissect_gvrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
112 proto_tree *gvrp_tree;
115 int msg_index, attr_index, offset = 0, length = tvb_reported_length(tvb);
117 if (check_col(pinfo->fd, COL_PROTOCOL))
118 col_set_str(pinfo->fd, COL_PROTOCOL, "GVRP");
120 if (check_col(pinfo->fd, COL_INFO))
121 col_set_str(pinfo->fd, COL_INFO, "GVRP");
125 ti = proto_tree_add_item(tree, proto_gvrp, tvb, 0, length, FALSE);
127 gvrp_tree = proto_item_add_subtree(ti, ett_gvrp);
129 /* Read in GARP protocol ID */
130 protocol_id = tvb_get_ntohs(tvb, GARP_PROTOCOL_ID);
132 proto_tree_add_uint_format(gvrp_tree, hf_gvrp_proto_id, tvb,
133 GARP_PROTOCOL_ID, sizeof(guint16),
135 "Protocol Identifier: 0x%04x (%s)",
137 protocol_id == GARP_DEFAULT_PROTOCOL_ID ?
138 "GARP VLAN Registration Protocol" :
141 /* Currently only one protocol ID is supported */
142 if (protocol_id != GARP_DEFAULT_PROTOCOL_ID)
144 proto_tree_add_text(gvrp_tree, tvb, GARP_PROTOCOL_ID, sizeof(guint16),
145 " (Warning: this version of Ethereal only knows about protocol id = 1)");
146 dissect_data(tvb, GARP_PROTOCOL_ID + sizeof(guint16), pinfo, tree);
150 offset += sizeof(guint16);
151 length -= sizeof(guint16);
155 /* Begin to parse GARP messages */
158 proto_item *msg_item;
159 int msg_start = offset;
161 /* Read in attribute type. */
162 octet = tvb_get_guint8(tvb, offset);
164 /* Check for end of mark */
165 if (octet == GARP_END_OF_MARK)
167 /* End of GARP PDU */
170 proto_tree_add_text(gvrp_tree, tvb, offset, sizeof(guint8),
176 dissect_data(tvb, offset, pinfo, tree);
181 offset += sizeof(guint8);
182 length -= sizeof(guint8);
184 msg_item = proto_tree_add_text(gvrp_tree, tvb, msg_start, 0,
185 "Message %d", msg_index + 1);
187 proto_tree_add_uint(gvrp_tree, hf_gvrp_attribute_type, tvb,
188 msg_start, sizeof(guint8), octet);
190 /* GVRP only supports one attribute type. */
191 if (octet != GVRP_ATTRIBUTE_TYPE)
193 dissect_data(tvb, offset, pinfo, tree);
201 int attr_start = offset;
202 proto_item *attr_item;
204 /* Read in attribute length. */
205 octet = tvb_get_guint8(tvb, offset);
207 /* Check for end of mark */
208 if (octet == GARP_END_OF_MARK)
210 /* If at least one message has been already read,
211 * check for another end of mark.
215 proto_tree_add_text(gvrp_tree, tvb, offset,
216 sizeof(guint8), " End of mark");
218 offset += sizeof(guint8);
219 length -= sizeof(guint8);
221 proto_item_set_len(msg_item, offset - msg_start);
226 dissect_data(tvb, offset, pinfo, tree);
234 offset += sizeof(guint8);
235 length -= sizeof(guint8);
237 attr_item = proto_tree_add_text(gvrp_tree, tvb,
238 attr_start, 0, " Attribute %d", attr_index + 1);
240 proto_tree_add_uint(gvrp_tree, hf_gvrp_attribute_length,
241 tvb, attr_start, sizeof(guint8), octet);
243 /* Read in attribute event */
244 event = tvb_get_guint8(tvb, offset);
246 proto_tree_add_uint(gvrp_tree, hf_gvrp_attribute_event,
247 tvb, offset, sizeof(guint8), event);
249 offset += sizeof(guint8);
250 length -= sizeof(guint8);
254 case GVRP_EVENT_LEAVEALL:
255 if (octet != GVRP_LENGTH_LEAVEALL)
257 dissect_data(tvb, offset, pinfo, tree);
262 case GVRP_EVENT_JOINEMPTY:
263 case GVRP_EVENT_JOININ:
264 case GVRP_EVENT_LEAVEEMPTY:
265 case GVRP_EVENT_LEAVEIN:
266 case GVRP_EVENT_EMPTY:
267 if (octet != GVRP_LENGTH_NON_LEAVEALL)
269 dissect_data(tvb, offset, pinfo, tree);
273 /* Show attribute value */
274 proto_tree_add_item(gvrp_tree, hf_gvrp_attribute_value,
275 tvb, offset, sizeof(guint16), FALSE);
277 offset += sizeof(guint16);
278 length -= sizeof(guint16);
282 dissect_data(tvb, offset, pinfo, tree);
287 proto_item_set_len(attr_item, offset - attr_start);
298 /* Register the protocol with Ethereal */
300 proto_register_gvrp(void)
302 static hf_register_info hf[] = {
304 { "Protocol ID", "garp.protocol_id",
305 FT_UINT16, BASE_HEX, NULL, 0x0,
308 { &hf_gvrp_attribute_type,
309 { "Type", "garp.attribute_type",
310 FT_UINT8, BASE_HEX, VALS(attribute_type_vals), 0x0,
313 { &hf_gvrp_attribute_length,
314 { "Length", "garp.attribute_length",
315 FT_UINT8, BASE_DEC, NULL, 0x0,
318 { &hf_gvrp_attribute_event,
319 { "Event", "garp.attribute_event",
320 FT_UINT8, BASE_DEC, VALS(event_vals), 0x0,
323 { &hf_gvrp_attribute_value,
324 { "Value", "garp.attribute_value",
325 FT_UINT16, BASE_DEC, NULL, 0x0,
330 static gint *ett[] = {
334 /* Register the protocol name and description for GVRP */
335 proto_gvrp = proto_register_protocol("GARP VLAN Registration Protocol",
338 /* Required function calls to register the header fields and subtrees
340 proto_register_field_array(proto_gvrp, hf, array_length(hf));
341 proto_register_subtree_array(ett, array_length(ett));
343 register_dissector("gvrp", dissect_gvrp, proto_gvrp);