2 * Routines for MVRP (MRP Multiple VLAN Registration Protocol) dissection
3 * Copyright 2011, Pascal Levesque <plevesque[AT]orthogone.ca>
6 * Based on the code from packet-mrp-mmrp.c (MMRP) from
7 * Johannes Jochen <johannes.jochen[AT]belden.com>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald[AT]wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
16 * The MVRP Protocol specification can be found at the following:
17 * http://standards.ieee.org/about/get/802/802.1.html
23 #include <epan/packet.h>
24 #include <epan/etypes.h>
26 void proto_register_mrp_mvrp(void);
27 void proto_reg_handoff_mrp_mvrp(void);
29 static dissector_handle_t mvrp_handle
;
31 /* MVRP End Mark Sequence */
32 #define MVRP_END_MARK 0x0000
34 /**********************************************************/
35 /* Offsets of fields within an MVRP packet */
36 /**********************************************************/
37 #define MVRP_PROTOCOL_VERSION_OFFSET 0
39 /* Next comes the MVRP Message group */
40 #define MVRP_MESSAGE_GROUP_OFFSET (MVRP_PROTOCOL_VERSION_OFFSET + 1) /* Message is a group of fields */
41 #define MVRP_ATTRIBUTE_TYPE_OFFSET (MVRP_MESSAGE_GROUP_OFFSET)
42 #define MVRP_ATTRIBUTE_LENGTH_OFFSET (MVRP_ATTRIBUTE_TYPE_OFFSET + 1)
44 /* Next comes the MVRP AttributeList group */
45 #define MVRP_ATTRIBUTE_LIST_GROUP_OFFSET (MVRP_ATTRIBUTE_LENGTH_OFFSET + 1) /* AttributeList is a group of fields */
47 /* Next comes the MVRP VectorAttribute group */
48 #define MVRP_VECTOR_ATTRIBUTE_GROUP_OFFSET (MVRP_ATTRIBUTE_LIST_GROUP_OFFSET) /* VectorAttribute is a group of fields */
49 #define MVRP_VECTOR_HEADER_OFFSET (MVRP_VECTOR_ATTRIBUTE_GROUP_OFFSET) /* contains the following two fields */
50 #define MVRP_LEAVE_ALL_EVENT_OFFSET (MVRP_VECTOR_HEADER_OFFSET)
51 #define MVRP_LEAVE_ALL_EVENT_MASK 0xE000
52 #define MVRP_NUMBER_OF_VALUES_OFFSET (MVRP_VECTOR_HEADER_OFFSET)
53 #define MVRP_NUMBER_OF_VALUES_MASK 0x1fff
55 /* Next comes the MVRP FirstValue group */
56 #define MVRP_FIRST_VALUE_GROUP_OFFSET (MVRP_VECTOR_HEADER_OFFSET + 2) /* FirstValue is a group of fields */
58 #define MVRP_VID_THREE_PACKED_OFFSET (MVRP_FIRST_VALUE_GROUP_OFFSET + 2)
60 /**********************************************************/
61 /* Valid field contents */
62 /**********************************************************/
64 /* Attribute Type definitions */
65 #define MVRP_ATTRIBUTE_TYPE_VID 0x01
66 static const value_string attribute_type_vals
[] = {
67 { MVRP_ATTRIBUTE_TYPE_VID
, "VLAN Identifier" },
71 /* Leave All Event definitions */
72 #define MVRP_NULLLEAVEALL 0
73 #define MVRP_LEAVEALL 1
74 static const value_string leave_all_vals
[] = {
75 { MVRP_NULLLEAVEALL
, "Null" },
76 { MVRP_LEAVEALL
, "Leave All" },
80 /* Three Packed Event definitions */
81 static const value_string three_packed_vals
[] = {
91 /**********************************************************/
92 /* Initialize the protocol and registered fields */
93 /**********************************************************/
94 static int proto_mvrp
;
95 static int hf_mvrp_proto_id
;
96 static int hf_mvrp_message
; /* Message is a group of fields */
97 static int hf_mvrp_attribute_type
;
98 static int hf_mvrp_attribute_length
;
99 static int hf_mvrp_attribute_list
; /* AttributeList is a group of fields */
100 static int hf_mvrp_vector_attribute
; /* VectorAttribute is a group of fields */
102 /* The following VectorHeader contains the LeaveAllEvent and NumberOfValues */
103 static int hf_mvrp_vector_header
;
104 static int hf_mvrp_leave_all_event
;
105 static int hf_mvrp_number_of_values
;
106 static int ett_vector_header
;
107 static int * const vector_header_fields
[] = {
108 &hf_mvrp_leave_all_event
,
109 &hf_mvrp_number_of_values
,
113 static int hf_mvrp_first_value
; /* FirstValue is a group of fields */
114 static int hf_mvrp_vid
;
115 static int hf_mvrp_three_packed_event
;
117 static int hf_mvrp_end_mark
;
119 /* Initialize the subtree pointers */
122 static int ett_attr_list
;
123 static int ett_vect_attr
;
124 static int ett_first_value
;
128 /**********************************************************/
129 /* Dissector starts here */
130 /**********************************************************/
132 /* dissect_mvrp_common1 (called from dissect_mvrp)
134 * dissect the following fields which are common to all MVRP attributes:
137 * Attribute List Length
140 dissect_mvrp_common1(proto_tree
*msg_tree
, tvbuff_t
*tvb
, int msg_offset
)
142 proto_tree_add_item(msg_tree
, hf_mvrp_attribute_type
, tvb
,
143 MVRP_ATTRIBUTE_TYPE_OFFSET
+ msg_offset
, 1, ENC_BIG_ENDIAN
);
144 proto_tree_add_item(msg_tree
, hf_mvrp_attribute_length
, tvb
,
145 MVRP_ATTRIBUTE_LENGTH_OFFSET
+ msg_offset
, 1, ENC_BIG_ENDIAN
);
149 /* dissect_mvrp_common2 (called from dissect_mvrp)
151 * dissect the following fields which are common to all MVRP attributes:
153 * Number of Values fields
156 dissect_mvrp_common2(proto_tree
*vect_attr_tree
, tvbuff_t
*tvb
, int msg_offset
)
158 proto_tree_add_bitmask(vect_attr_tree
, tvb
, MVRP_VECTOR_HEADER_OFFSET
+ msg_offset
,
159 hf_mvrp_vector_header
, ett_vector_header
, vector_header_fields
, ENC_BIG_ENDIAN
);
162 /* dissect_mvrp_three_packed_event (called from dissect_mvrp)
164 * dissect one or more ThreePackedEvents
167 dissect_mvrp_three_packed_event(proto_tree
*vect_attr_tree
, tvbuff_t
*tvb
, unsigned offset
, uint16_t number_of_values
)
171 for ( counter
= 0; counter
< number_of_values
; ) {
173 uint8_t three_packed_event
[3];
175 value
= tvb_get_uint8(tvb
, offset
);
176 three_packed_event
[0] = value
/ 36;
177 value
-= 36 * three_packed_event
[0];
178 three_packed_event
[1] = value
/ 6;
179 value
-= 6 * three_packed_event
[1];
180 three_packed_event
[2] = value
;
182 proto_tree_add_uint(vect_attr_tree
, hf_mvrp_three_packed_event
, tvb
, offset
, sizeof(uint8_t),
183 three_packed_event
[0]);
185 if ( counter
< number_of_values
) {
186 proto_tree_add_uint(vect_attr_tree
, hf_mvrp_three_packed_event
, tvb
, offset
, sizeof(uint8_t),
187 three_packed_event
[1]);
190 if ( counter
< number_of_values
) {
191 proto_tree_add_uint(vect_attr_tree
, hf_mvrp_three_packed_event
, tvb
, offset
, sizeof(uint8_t),
192 three_packed_event
[2]);
203 * main dissect function that calls the other functions listed above as necessary
206 dissect_mvrp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
208 /* Set up structures needed to add the protocol subtrees and manage them */
209 proto_item
*ti
, *msg_ti
, *attr_list_ti
, *vect_attr_ti
, *first_value_ti
;
210 proto_tree
*mvrp_tree
, *msg_tree
, *attr_list_tree
, *vect_attr_tree
, *first_value_tree
;
212 /* Make entries in Protocol column and Info column on summary display */
213 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "MRP-MVRP");
215 col_set_str(pinfo
->cinfo
, COL_INFO
, "Multiple VLAN Registration Protocol");
218 uint8_t attribute_type
;
219 uint8_t attribute_length
;
220 uint16_t number_of_values
;
222 unsigned int vect_attr_len
;
223 unsigned int msg_offset
; /* Use when handling multiple messages. This points to current msg being decoded. */
224 unsigned int vect_offset
; /* Use when handling multiple vector attributes. This points to the current vector attribute being decoded. */
226 ti
= proto_tree_add_item(tree
, proto_mvrp
, tvb
, 0, -1, ENC_NA
);
227 mvrp_tree
= proto_item_add_subtree(ti
, ett_mvrp
);
229 proto_tree_add_item(mvrp_tree
, hf_mvrp_proto_id
, tvb
, MVRP_PROTOCOL_VERSION_OFFSET
, 1, ENC_BIG_ENDIAN
);
231 /* MVRP supports multiple MRP Messages per frame. Handle those Messages in
232 * the following while() loop. You will know you are at the end of the list
233 * of messages when the EndMark (0x0000) is encountered instead of an
234 * Attribute Type and Attribute Length (guaranteed to not be 0x0000).
237 while (MVRP_ATTRIBUTE_TYPE_OFFSET
+ msg_offset
< tvb_reported_length(tvb
) && tvb_get_ntohs(tvb
, MVRP_ATTRIBUTE_TYPE_OFFSET
+ msg_offset
) != MVRP_END_MARK
) {
239 attribute_type
= tvb_get_uint8(tvb
, MVRP_ATTRIBUTE_TYPE_OFFSET
+ msg_offset
);
240 attribute_length
= tvb_get_uint8(tvb
, MVRP_ATTRIBUTE_LENGTH_OFFSET
+ msg_offset
);
242 /* MVRP Message is a group of fields
244 * Contains AttributeType (1 byte)
245 * + AttributeLength (1 byte)
246 * + AttributeList (AttributeListLength bytes)
249 msg_ti
= proto_tree_add_item(mvrp_tree
, hf_mvrp_message
, tvb
,
250 MVRP_MESSAGE_GROUP_OFFSET
+ msg_offset
,
252 msg_tree
= proto_item_add_subtree(msg_ti
, ett_msg
);
254 /* Append AttributeType description to the end of the "Message" heading */
255 proto_item_append_text(msg_tree
, ": %s (%d)",
256 val_to_str_const(attribute_type
, attribute_type_vals
, "<Unknown>"),
259 dissect_mvrp_common1(msg_tree
, tvb
, msg_offset
);
261 /* MVRP AttributeList is a group of fields
263 * Contains AttributeListLength bytes of data NOT
265 attr_list_ti
= proto_tree_add_item(msg_tree
, hf_mvrp_attribute_list
, tvb
,
266 MVRP_ATTRIBUTE_LIST_GROUP_OFFSET
+ msg_offset
,
268 attr_list_tree
= proto_item_add_subtree(attr_list_ti
, ett_attr_list
);
271 /* MVRP supports multiple MRP Vector Attributes per Attribute List. Handle those
272 * Vector Attributes in the following while() loop. You will know you are at the
273 * end of the list of Vector Attributes when the EndMark (0x0000) is encountered
274 * instead of a Vector Header (guaranteed to not be 0x0000).
277 while (MVRP_VECTOR_HEADER_OFFSET
+ msg_offset
+ vect_offset
< tvb_reported_length(tvb
) && tvb_get_ntohs(tvb
, MVRP_VECTOR_HEADER_OFFSET
+ msg_offset
+ vect_offset
) != MVRP_END_MARK
) {
278 /* MVRP VectorAttribute is a group of fields
280 * Contains VectorHeader (2 bytes)
281 * + FirstValue (AttributeLength bytes)
282 * + VectorThreePacked (NumberOfValues @ 3/vector bytes)
283 * + VectorFourPacked (NumberOfValues @ 4/vector bytes only for Listener attributes)
286 number_of_values
= tvb_get_ntohs(tvb
, MVRP_NUMBER_OF_VALUES_OFFSET
+ msg_offset
+ vect_offset
)
287 & MVRP_NUMBER_OF_VALUES_MASK
;
289 vect_attr_len
= 2 + attribute_length
+ (number_of_values
+ 2)/3; /* stores 3 values per byte */
291 vect_attr_ti
= proto_tree_add_item(attr_list_tree
, hf_mvrp_vector_attribute
, tvb
,
292 MVRP_VECTOR_ATTRIBUTE_GROUP_OFFSET
+ msg_offset
+ vect_offset
,
293 vect_attr_len
, ENC_NA
);
295 vect_attr_tree
= proto_item_add_subtree(vect_attr_ti
, ett_vect_attr
);
297 dissect_mvrp_common2(vect_attr_tree
, tvb
, msg_offset
+ vect_offset
);
299 if (attribute_type
== MVRP_ATTRIBUTE_TYPE_VID
) {
300 /* MVRP VLAN ID FirstValue is a group of fields
302 * Contains VID (2 bytes)
305 first_value_ti
= proto_tree_add_item(vect_attr_tree
, hf_mvrp_first_value
, tvb
,
306 MVRP_FIRST_VALUE_GROUP_OFFSET
+ msg_offset
+ vect_offset
,
307 attribute_length
, ENC_NA
);
308 first_value_tree
= proto_item_add_subtree(first_value_ti
, ett_first_value
);
310 /* Add VLAN components to First Value tree */
311 proto_tree_add_item(first_value_tree
, hf_mvrp_vid
, tvb
,
312 MVRP_FIRST_VALUE_GROUP_OFFSET
+ msg_offset
+ vect_offset
, 2, ENC_BIG_ENDIAN
);
314 /* Decode three packed events. */
315 offset
= dissect_mvrp_three_packed_event(vect_attr_tree
, tvb
,
316 MVRP_VID_THREE_PACKED_OFFSET
+ msg_offset
+ vect_offset
,
321 vect_offset
+= vect_attr_len
; /* Move to next Vector Attribute, if there is one */
322 } /* Multiple VectorAttribute while() */
324 if (MVRP_VECTOR_HEADER_OFFSET
+ msg_offset
+ vect_offset
< tvb_reported_length(tvb
)) {
325 proto_tree_add_item(attr_list_tree
, hf_mvrp_end_mark
, tvb
, offset
, 2, ENC_BIG_ENDIAN
); /* VectorAttribute EndMark */
328 proto_item_set_len(attr_list_ti
, vect_offset
); /*without an endmark*/
329 msg_offset
+= vect_offset
+ 4; /* + endmark; Move to next Message, if there is one */
330 proto_item_set_len(msg_ti
, vect_offset
+ 2); /*length of message*/
332 } /* Multiple Message while() */
334 if (MVRP_ATTRIBUTE_TYPE_OFFSET
+ msg_offset
< tvb_reported_length(tvb
)) {
335 proto_tree_add_item(mvrp_tree
, hf_mvrp_end_mark
, tvb
, offset
+2, 2, ENC_BIG_ENDIAN
); /* Message EndMark */
338 return tvb_captured_length(tvb
);
342 /* Register the protocol with Wireshark */
344 proto_register_mrp_mvrp(void)
346 static hf_register_info hf
[] = {
348 { "Protocol Version", "mrp-mvrp.protocol_version",
349 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
351 { &hf_mvrp_message
, /* Message is a group of fields */
352 { "Message", "mrp-mvrp.message",
353 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
355 { &hf_mvrp_attribute_type
,
356 { "Attribute Type", "mrp-mvrp.attribute_type",
357 FT_UINT8
, BASE_DEC
, VALS(attribute_type_vals
), 0x0, NULL
, HFILL
}
359 { &hf_mvrp_attribute_length
,
360 { "Attribute Length", "mrp-mvrp.attribute_length",
361 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
363 { &hf_mvrp_attribute_list
, /* AttributeList is a group of fields */
364 { "Attribute List", "mrp-mvrp.attribute_list",
365 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
367 { &hf_mvrp_vector_attribute
, /* VectorAttribute is a group of fields */
368 { "Vector Attribute", "mrp-mvrp.vector_attribute",
369 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
371 { &hf_mvrp_vector_header
,
372 { "Vector Header", "mrp-mvrp.vector_header",
373 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
375 { &hf_mvrp_leave_all_event
,
376 { "Leave All Event", "mrp-mvrp.leave_all_event",
377 FT_UINT16
, BASE_DEC
, VALS(leave_all_vals
), MVRP_LEAVE_ALL_EVENT_MASK
, NULL
, HFILL
}
379 { &hf_mvrp_number_of_values
,
380 { "Number of Values", "mrp-mvrp.number_of_values",
381 FT_UINT16
, BASE_DEC
, NULL
, MVRP_NUMBER_OF_VALUES_MASK
, NULL
, HFILL
}
383 { &hf_mvrp_first_value
, /* FirstValue is a group of fields */
384 { "First Value", "mrp-mvrp.first_value",
385 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
388 { "VLAN ID", "mrp-mvrp.vid",
389 FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
391 { &hf_mvrp_three_packed_event
,
392 { "Attribute Event", "mrp-mvrp.three_packed_event",
393 FT_UINT8
, BASE_DEC
, VALS(three_packed_vals
), 0x0, NULL
, HFILL
}
396 { "End Mark", "mrp-mvrp.end_mark",
397 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
401 /* Setup protocol subtree array */
402 static int *ett
[] = {
411 /* Register the protocol name and description */
412 proto_mvrp
= proto_register_protocol("Multiple VLAN Registration Protocol",
413 "MRP-MVRP", "mrp-mvrp");
415 /* Required function calls to register the header fields and subtrees used */
416 proto_register_field_array(proto_mvrp
, hf
, array_length(hf
));
417 proto_register_subtree_array(ett
, array_length(ett
));
419 /* Register the dissector */
420 mvrp_handle
= register_dissector("mrp-mvrp", dissect_mvrp
, proto_mvrp
);
424 proto_reg_handoff_mrp_mvrp(void)
426 dissector_add_uint("ethertype", ETHERTYPE_MVRP
, mvrp_handle
);
429 * Editor modelines - https://www.wireshark.org/tools/modelines.html
434 * indent-tabs-mode: nil
437 * ex: set shiftwidth=4 tabstop=8 expandtab:
438 * :indentSize=4:tabSize=8:noTabs=true: