2 * Routines for GVRP (GARP VLAN Registration Protocol) dissection
3 * Copyright 2000, Kevin Shi <techishi@ms22.hinet.net>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
15 #include <epan/expert.h>
17 void proto_register_gvrp(void);
19 /* Initialize the protocol and registered fields */
20 static int proto_gvrp
;
21 static int hf_gvrp_proto_id
;
22 static int hf_gvrp_attribute_type
;
23 static int hf_gvrp_attribute_length
;
24 static int hf_gvrp_attribute_event
;
25 static int hf_gvrp_attribute_value
;
26 static int hf_gvrp_end_of_mark
;
28 /* Initialize the subtree pointers */
30 static int ett_gvrp_message
;
31 static int ett_gvrp_attribute
;
33 static expert_field ei_gvrp_proto_id
;
35 /* Constant definitions */
36 #define GARP_DEFAULT_PROTOCOL_ID 0x0001
37 #define GARP_END_OF_MARK 0x00
39 #define GVRP_ATTRIBUTE_TYPE 0x01
41 static const value_string attribute_type_vals
[] = {
42 { GVRP_ATTRIBUTE_TYPE
, "VID" },
46 /* The length of GVRP LeaveAll attribute should be 2 octets (one for length
47 * and the other for event) */
48 #define GVRP_LENGTH_LEAVEALL (int)(sizeof(uint8_t)+sizeof(uint8_t))
50 /* The length of GVRP attribute other than LeaveAll should be 4 octets (one
51 * for length, one for event, and the last two for VID value).
53 #define GVRP_LENGTH_NON_LEAVEALL (int)(sizeof(uint8_t)+sizeof(uint8_t)+sizeof(uint16_t))
55 /* Packet offset definitions */
56 #define GARP_PROTOCOL_ID 0
58 /* Event definitions */
59 #define GVRP_EVENT_LEAVEALL 0
60 #define GVRP_EVENT_JOINEMPTY 1
61 #define GVRP_EVENT_JOININ 2
62 #define GVRP_EVENT_LEAVEEMPTY 3
63 #define GVRP_EVENT_LEAVEIN 4
64 #define GVRP_EVENT_EMPTY 5
66 static const value_string event_vals
[] = {
67 { GVRP_EVENT_LEAVEALL
, "Leave All" },
68 { GVRP_EVENT_JOINEMPTY
, "Join Empty" },
69 { GVRP_EVENT_JOININ
, "Join In" },
70 { GVRP_EVENT_LEAVEEMPTY
, "Leave Empty" },
71 { GVRP_EVENT_LEAVEIN
, "Leave In" },
72 { GVRP_EVENT_EMPTY
, "Empty" },
76 /* Code to actually dissect the packets */
78 dissect_gvrp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
80 proto_item
*ti
, *id_item
;
81 proto_tree
*gvrp_tree
, *msg_tree
, *attr_tree
;
87 int length
= tvb_reported_length(tvb
);
89 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "GVRP");
91 col_set_str(pinfo
->cinfo
, COL_INFO
, "GVRP");
93 ti
= proto_tree_add_item(tree
, proto_gvrp
, tvb
, 0, length
, ENC_NA
);
94 gvrp_tree
= proto_item_add_subtree(ti
, ett_gvrp
);
96 /* Read in GARP protocol ID */
97 protocol_id
= tvb_get_ntohs(tvb
, GARP_PROTOCOL_ID
);
99 id_item
= proto_tree_add_uint_format_value(gvrp_tree
, hf_gvrp_proto_id
, tvb
,
104 protocol_id
== GARP_DEFAULT_PROTOCOL_ID
?
105 "GARP VLAN Registration Protocol" :
108 /* Currently only one protocol ID is supported */
109 if (protocol_id
!= GARP_DEFAULT_PROTOCOL_ID
)
111 expert_add_info(pinfo
, id_item
, &ei_gvrp_proto_id
);
112 call_data_dissector(tvb_new_subset_remaining(tvb
, GARP_PROTOCOL_ID
+ 2),
114 return tvb_captured_length(tvb
);
122 /* Begin to parse GARP messages */
125 proto_item
*msg_item
;
126 int msg_start
= offset
;
128 /* Read in attribute type. */
129 octet
= tvb_get_uint8(tvb
, offset
);
131 /* Check for end of mark */
132 if (octet
== GARP_END_OF_MARK
)
134 /* End of GARP PDU */
137 proto_tree_add_item(gvrp_tree
, hf_gvrp_end_of_mark
, tvb
, offset
, 1, ENC_NA
);
142 call_data_dissector(tvb_new_subset_remaining(tvb
, offset
), pinfo
, tree
);
143 return tvb_captured_length(tvb
);
150 msg_tree
= proto_tree_add_subtree_format(gvrp_tree
, tvb
, msg_start
, -1, ett_gvrp_message
, &msg_item
,
151 "Message %d", msg_index
+ 1);
153 proto_tree_add_uint(msg_tree
, hf_gvrp_attribute_type
, tvb
,
154 msg_start
, 1, octet
);
156 /* GVRP only supports one attribute type. */
157 if (octet
!= GVRP_ATTRIBUTE_TYPE
)
159 call_data_dissector(tvb_new_subset_remaining(tvb
, offset
),
161 return tvb_captured_length(tvb
);
168 int attr_start
= offset
;
169 proto_item
*attr_item
;
171 /* Read in attribute length. */
172 octet
= tvb_get_uint8(tvb
, offset
);
174 /* Check for end of mark */
175 if (octet
== GARP_END_OF_MARK
)
177 /* If at least one message has been already read,
178 * check for another end of mark.
182 proto_tree_add_item(msg_tree
, hf_gvrp_end_of_mark
, tvb
, offset
, 1, ENC_NA
);
187 proto_item_set_len(msg_item
, offset
- msg_start
);
192 call_data_dissector(tvb_new_subset_remaining(tvb
, offset
), pinfo
, tree
);
193 return tvb_captured_length(tvb
);
203 attr_tree
= proto_tree_add_subtree_format(msg_tree
, tvb
, attr_start
, -1,
204 ett_gvrp_attribute
, &attr_item
, "Attribute %d", attr_index
+ 1);
206 proto_tree_add_uint(attr_tree
, hf_gvrp_attribute_length
,
207 tvb
, attr_start
, 1, octet
);
209 /* Read in attribute event */
210 event
= tvb_get_uint8(tvb
, offset
);
212 proto_tree_add_uint(attr_tree
, hf_gvrp_attribute_event
,
213 tvb
, offset
, 1, event
);
220 case GVRP_EVENT_LEAVEALL
:
221 if (octet
!= GVRP_LENGTH_LEAVEALL
)
223 call_data_dissector(tvb_new_subset_remaining(tvb
, offset
), pinfo
,
225 return tvb_captured_length(tvb
);
229 case GVRP_EVENT_JOINEMPTY
:
230 case GVRP_EVENT_JOININ
:
231 case GVRP_EVENT_LEAVEEMPTY
:
232 case GVRP_EVENT_LEAVEIN
:
233 case GVRP_EVENT_EMPTY
:
234 if (octet
!= GVRP_LENGTH_NON_LEAVEALL
)
236 call_data_dissector(tvb_new_subset_remaining(tvb
, offset
),pinfo
,
238 return tvb_captured_length(tvb
);
241 /* Show attribute value */
242 proto_tree_add_item(attr_tree
, hf_gvrp_attribute_value
,
243 tvb
, offset
, 2, ENC_BIG_ENDIAN
);
250 call_data_dissector(tvb_new_subset_remaining(tvb
, offset
), pinfo
, tree
);
251 return tvb_captured_length(tvb
);
255 proto_item_set_len(attr_item
, offset
- attr_start
);
262 return tvb_captured_length(tvb
);
266 /* Register the protocol with Wireshark */
268 proto_register_gvrp(void)
270 static hf_register_info hf
[] = {
272 { "Protocol Identifier", "gvrp.protocol_id",
273 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
276 { &hf_gvrp_attribute_type
,
277 { "Type", "gvrp.attribute_type",
278 FT_UINT8
, BASE_HEX
, VALS(attribute_type_vals
), 0x0,
281 { &hf_gvrp_attribute_length
,
282 { "Length", "gvrp.attribute_length",
283 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
286 { &hf_gvrp_attribute_event
,
287 { "Event", "gvrp.attribute_event",
288 FT_UINT8
, BASE_DEC
, VALS(event_vals
), 0x0,
291 { &hf_gvrp_attribute_value
,
292 { "Value", "gvrp.attribute_value",
293 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
296 { &hf_gvrp_end_of_mark
,
297 { "End of Mark", "gvrp.end_of_mark",
298 FT_NONE
, BASE_NONE
, NULL
, 0x0,
303 static ei_register_info ei
[] = {
304 { &ei_gvrp_proto_id
, { "gvrp.protocol_id.unknown", PI_PROTOCOL
, PI_WARN
, "Warning: this version of Wireshark only knows about protocol id = 1", EXPFILL
}},
307 expert_module_t
* expert_gvrp
;
309 static int *ett
[] = {
316 /* Register the protocol name and description for GVRP */
317 proto_gvrp
= proto_register_protocol("GARP VLAN Registration Protocol", "GVRP", "gvrp");
319 /* Required function calls to register the header fields and subtrees
321 proto_register_field_array(proto_gvrp
, hf
, array_length(hf
));
322 proto_register_subtree_array(ett
, array_length(ett
));
323 expert_gvrp
= expert_register_protocol(proto_gvrp
);
324 expert_register_field_array(expert_gvrp
, ei
, array_length(ei
));
326 register_dissector("gvrp", dissect_gvrp
, proto_gvrp
);
331 * Editor modelines - https://www.wireshark.org/tools/modelines.html
336 * indent-tabs-mode: nil
339 * vi: set shiftwidth=4 tabstop=8 expandtab:
340 * :indentSize=4:tabSize=8:noTabs=true: