2 * Routines for Multicast Source Discovery Protocol (MSDP) dissection.
3 * draft-ietf-msdp-spec-10.txt
5 * Copyright 2001, Heikki Vatiainen <hessu@cs.tut.fi>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
38 /* MSDP message types. The messages are TLV (Type-Length-Value) encoded */
45 /* Theses are only assigned in MSDP spec. Their use is specifed
47 MSDP_TRACE_IN_PROGRESS,
51 static const value_string msdp_types[] = {
52 { MSDP_SA, "IPv4 Source-Active" },
53 { MSDP_SA_REQ, "IPv4 Source-Active Request" },
54 { MSDP_SA_RSP, "IPv4 Source-Active Response" },
55 { MSDP_KEEP_ALIVE, "KeepAlive" },
56 { MSDP_NOTIFICATION, "Notification" },
58 { MSDP_TRACE_IN_PROGRESS, "MSDP traceroute in progress" },
59 { MSDP_TRACE_REPLY, "MSDP traceroute reply" },
65 enum { MESSAGE_HEADER_ERROR = 1,
67 SA_MESSAGE_SA_RESPONSE_ERROR,
74 static const value_string error_vals[] = {
75 { MESSAGE_HEADER_ERROR, "Message Header Error" },
76 { SA_REQUEST_ERROR, "SA-Request Error" },
77 { SA_MESSAGE_SA_RESPONSE_ERROR, "SA-Message/SA-Response Error" },
78 { HOLD_TIMER_EXPIRED, "Hold Timer Expired" },
79 { FSM_ERROR, "Finite State Machine Error" },
80 { NOTIFICATION, "Notification" },
86 /* Message Header Error subcodes */
87 static const value_string hdr_error_vals[] = {
89 { 2, "Bad Message Length" },
90 { 3, "Bad Message Type" },
94 /* SA-Request Error subcodes (the O-bit is always clear) */
95 static const value_string sa_req_error_vals[] = {
97 { 1, "Invalid Group" },
101 /* SA-Message/SA-Response Error subcodes */
102 static const value_string sa_msg_error_vals[] = {
104 { 1, "Invalid Entry Count" },
105 { 2, "Invalid RP Address" },
106 { 3, "Invalid Group Address" },
107 { 4, "Invalid Source Address" },
108 { 5, "Invalid Sprefix Length" },
109 { 6, "Looping SA (Self is RP)" },
110 { 7, "Unknown Encapsulation" },
111 { 8, "Administrative Scope Boundary Violated" },
115 /* Finite State Machine Error subcodes (the O-bit is always clear) */
116 static const value_string fsm_error_vals[] = {
118 { 1, "Unexpected Message Type FSM Error" },
123 * Hold Timer Expired subcodes (the O-bit is always clear):
124 * Notification subcodes (the O-bit is always clear):
125 * Cease subcodes (the O-bit is always clear):
127 * These have only "Unspecific" specified.
129 static const value_string sa_unspec_error_vals[] = {
135 /* Initialize the protocol and registered fields */
136 static int proto_msdp = -1;
137 static int hf_msdp_type = -1;
138 static int hf_msdp_length = -1;
140 static int hf_msdp_sa_entry_count = -1;
141 static int hf_msdp_sa_rp_addr = -1;
142 static int hf_msdp_sa_reserved = -1;
143 static int hf_msdp_sa_sprefix_len = -1;
144 static int hf_msdp_sa_group_addr = -1;
145 static int hf_msdp_sa_src_addr = -1;
147 static int hf_msdp_sa_req_res = -1;
148 static int hf_msdp_sa_req_group = -1;
150 static int hf_msdp_not_o = -1;
151 static int hf_msdp_not_error = -1;
152 static int hf_msdp_not_error_sub = -1;
154 static int hf_msdp_not_ipv4 = -1;
155 static int hf_msdp_not_res = -1;
156 static int hf_msdp_not_entry_count = -1;
157 static int hf_msdp_not_sprefix_len = -1;
160 static gint ett_msdp = -1;
161 static gint ett_msdp_sa_entry = -1;
162 static gint ett_msdp_sa_enc_data = -1;
163 static gint ett_msdp_not_data = -1;
166 static dissector_handle_t ip_handle;
170 dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
171 int *offset, int len);
173 dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, guint16 tlv_len);
177 dissect_msdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
180 proto_tree *msdp_tree;
183 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSDP");
185 if (check_col(pinfo->cinfo, COL_INFO))
186 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(tvb_get_guint8(tvb, 0),
188 "<Unknown MSDP message type>"));
194 ti = proto_tree_add_item(tree, proto_msdp, tvb, 0, -1, FALSE);
195 msdp_tree = proto_item_add_subtree(ti, ett_msdp);
198 while (tvb_reported_length_remaining(tvb, offset) >= 3) {
199 type = tvb_get_guint8(tvb, offset);
200 length = tvb_get_ntohs(tvb, offset + 1);
203 proto_tree_add_uint(msdp_tree, hf_msdp_type, tvb, offset, 1, type);
204 proto_tree_add_uint(msdp_tree, hf_msdp_length, tvb, offset + 1, 2, length);
211 dissect_msdp_sa(tvb, pinfo, msdp_tree, &offset,
215 proto_tree_add_item(msdp_tree, hf_msdp_sa_req_res, tvb, offset, 1, FALSE);
216 proto_tree_add_item(msdp_tree, hf_msdp_sa_req_group, tvb, offset + 1, 4, FALSE);
219 case MSDP_NOTIFICATION:
220 dissect_msdp_notification(tvb, pinfo, msdp_tree, &offset, length);
224 proto_tree_add_text(msdp_tree, tvb, offset, length, "TLV contents");
230 if (tvb_length_remaining(tvb, offset) > 0)
231 proto_tree_add_text(msdp_tree, tvb, offset,
232 -1, "Trailing junk");
238 /* Both Source-Active and Source-Active Response have the same format
239 * with one exception. Encapsulated multicast data is not allowed in
242 static void dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo,
243 proto_tree *tree, int *offset, int length)
249 entries = tvb_get_guint8(tvb, *offset);
250 proto_tree_add_uint(tree, hf_msdp_sa_entry_count, tvb, *offset, 1, entries);
258 proto_tree_add_item(tree, hf_msdp_sa_rp_addr, tvb, *offset, 4, FALSE);
262 /* Put each of the (S,G) entries in their own subtree.
263 * This is probably visually better.
265 while (entries-- > 0) {
267 proto_tree *entry_tree;
273 ei = proto_tree_add_text(tree, tvb, *offset, 12, "(S,G) block: %s/%u -> %s",
274 ip_to_str(tvb_get_ptr(tvb, *offset + 8, 4)),
275 tvb_get_guint8(tvb, *offset + 3),
276 ip_to_str(tvb_get_ptr(tvb, *offset + 4, 4)));
277 entry_tree = proto_item_add_subtree(ei, ett_msdp_sa_entry);
279 proto_tree_add_item(entry_tree, hf_msdp_sa_reserved, tvb, *offset, 3, FALSE);
282 proto_tree_add_item(entry_tree, hf_msdp_sa_sprefix_len, tvb, *offset, 1, FALSE);
285 proto_tree_add_item(entry_tree, hf_msdp_sa_group_addr, tvb, *offset, 4, FALSE);
288 proto_tree_add_item(entry_tree, hf_msdp_sa_src_addr, tvb, *offset, 4, FALSE);
294 * Check if an encapsulated multicast IPv4 packet follows
298 proto_tree *enc_tree;
299 gint available_length, reported_length;
302 ei = proto_tree_add_text(tree, tvb, *offset, length,
303 "Encapsulated IPv4 packet: %u bytes",
305 enc_tree = proto_item_add_subtree(ei, ett_msdp_sa_enc_data);
307 available_length = tvb_length_remaining(tvb, *offset);
308 reported_length = tvb_reported_length_remaining(tvb, *offset);
309 DISSECTOR_ASSERT(available_length >= 0);
310 DISSECTOR_ASSERT(reported_length >= 0);
311 if (available_length > reported_length)
312 available_length = reported_length;
313 if (available_length > length)
314 available_length = length;
315 if (reported_length > length)
316 reported_length = length;
318 next_tvb = tvb_new_subset(tvb, *offset, available_length,
320 /* Set the information columns read-only so that they
321 * reflect the MSDP packet rather than the
322 * encapsulated packet.
324 col_set_writable(pinfo->cinfo, FALSE);
325 call_dissector(ip_handle, next_tvb, pinfo, enc_tree);
332 /* Note: updates *offset */
333 static void add_notification_data_ipv4addr(tvbuff_t *tvb, proto_tree *tree, int *offset, const char *addrtype)
337 proto_tree_add_item(tree, hf_msdp_not_res, tvb, *offset, 3, FALSE);
339 ipaddr = tvb_get_ipv4(tvb, *offset);
340 proto_tree_add_ipv4_format(tree, hf_msdp_not_ipv4, tvb, *offset, 4, ipaddr,
341 "%s: %s", addrtype, ip_to_str((guint8 *)&ipaddr));
347 static void dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, guint16 tlv_len)
349 guint8 error, error_sub;
350 const value_string *vals;
352 proto_tree_add_item(tree, hf_msdp_not_o, tvb, *offset, 1, FALSE);
353 proto_tree_add_item(tree, hf_msdp_not_error, tvb, *offset, 1, FALSE);
354 error = tvb_get_guint8(tvb, *offset);
355 error &= 0x7F; /* Error is 7-bit field. O-bit is bit 8 */
358 /* Depending on the Error Code, we collect the correct
359 * value_strings for the Error subcode
362 case MESSAGE_HEADER_ERROR:
363 vals = hdr_error_vals;
365 case SA_REQUEST_ERROR:
366 vals = sa_req_error_vals;
368 case SA_MESSAGE_SA_RESPONSE_ERROR:
369 vals = sa_msg_error_vals;
372 vals = fsm_error_vals;
374 case HOLD_TIMER_EXPIRED:
377 vals = sa_unspec_error_vals;
380 vals = sa_unspec_error_vals;
384 error_sub = tvb_get_guint8(tvb, *offset);
385 proto_tree_add_uint_format(tree, hf_msdp_not_error_sub, tvb, *offset, 1,
386 error_sub, "Error subcode: %s (%u)",
387 val_to_str(error_sub, vals, "<Unknown Error subcode>"),
391 /* Do switch again, this time to dissect the data portion
396 case SA_REQUEST_ERROR:
397 add_notification_data_ipv4addr(tvb, tree, offset, "Group address");
399 case SA_MESSAGE_SA_RESPONSE_ERROR:
400 if (error_sub == 0) {
402 } else if (error_sub == 1) {
403 proto_tree_add_item(tree, hf_msdp_not_entry_count, tvb, *offset, 1, FALSE);
406 } else if (error_sub == 2) {
407 add_notification_data_ipv4addr(tvb, tree, offset, "RP address");
409 } else if (error_sub == 3 || error_sub == 8) {
410 add_notification_data_ipv4addr(tvb, tree, offset, "Group address");
412 } else if (error_sub == 4) {
413 add_notification_data_ipv4addr(tvb, tree, offset, "Source address");
415 } else if (error_sub == 5) {
416 proto_tree_add_item(tree, hf_msdp_not_sprefix_len, tvb, *offset, 1, FALSE);
419 } else if (error_sub == 6) {
420 /* No break, causes fall through to next label */
421 } else if (error_sub == 7) {
422 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
423 "Packet with unknown encapsulation: %u bytes",
425 *offset += tlv_len - 5;
428 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
429 "<Unknown data>: %u bytes",
431 *offset += tlv_len - 5;
435 case MESSAGE_HEADER_ERROR:
437 /* Data contains the message that had an error. Even a
438 * broken Notification message causes a Notification
439 * message with Error Code set to Notification to be
442 next_tvb = tvb_new_subset_remaining(tvb, *offset);
443 dissect_msdp(next_tvb, pinfo, tree);
446 case HOLD_TIMER_EXPIRED:
448 /* Do nothing. These contain no data */
452 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
453 "<Unknown data>: %u bytes",
455 *offset += tlv_len - 5;
463 proto_register_msdp(void)
465 static hf_register_info hf[] = {
467 { "Type", "msdp.type",
468 FT_UINT8, BASE_DEC, VALS(msdp_types), 0,
469 "MSDP TLV type", HFILL }
472 { "Length", "msdp.length",
473 FT_UINT16, BASE_DEC, NULL, 0,
474 "MSDP TLV Length", HFILL }
476 { &hf_msdp_sa_entry_count,
477 { "Entry Count", "msdp.sa.entry_count",
478 FT_UINT8, BASE_DEC, NULL, 0,
479 "MSDP SA Entry Count", HFILL }
481 { &hf_msdp_sa_rp_addr,
482 { "RP Address", "msdp.sa.rp_addr",
483 FT_IPv4, BASE_NONE, NULL, 0,
484 "Active source's RP address", HFILL }
486 { &hf_msdp_sa_reserved,
487 { "Reserved", "msdp.sa.reserved",
488 FT_UINT24, BASE_HEX, NULL, 0,
489 "Transmitted as zeros and ignored by a receiver", HFILL }
491 { &hf_msdp_sa_sprefix_len,
492 { "Sprefix len", "msdp.sa.sprefix_len",
493 FT_UINT8, BASE_DEC, NULL, 0,
494 "The route prefix length associated with source address", HFILL }
496 { &hf_msdp_sa_group_addr,
497 { "Group Address", "msdp.sa.group_addr",
498 FT_IPv4, BASE_NONE, NULL, 0,
499 "The group address the active source has sent data to", HFILL }
501 { &hf_msdp_sa_src_addr,
502 { "Source Address", "msdp.sa.src_addr",
503 FT_IPv4, BASE_NONE, NULL, 0,
504 "The IP address of the active source", HFILL }
506 { &hf_msdp_sa_req_res,
507 { "Reserved", "msdp.sa_req.res",
508 FT_UINT8, BASE_HEX, NULL, 0,
509 "Transmitted as zeros and ignored by a receiver", HFILL }
511 { &hf_msdp_sa_req_group,
512 { "Group Address", "msdp.sa_req.group_addr",
513 FT_IPv4, BASE_NONE, NULL, 0,
514 "The group address the MSDP peer is requesting", HFILL }
517 { "Open-bit", "msdp.not.o",
518 FT_UINT8, BASE_HEX, NULL, 0x80,
519 "If clear, the connection will be closed", HFILL }
521 { &hf_msdp_not_error,
522 { "Error Code", "msdp.not.error",
523 FT_UINT8, BASE_DEC, VALS(error_vals), 0x7F,
524 "Indicates the type of Notification", HFILL }
526 { &hf_msdp_not_error_sub,
527 { "Error subode", "msdp.not.error_sub",
528 FT_UINT8, BASE_DEC, NULL, 0,
529 "Error subcode", HFILL }
532 { "IPv4 address", "msdp.not.ipv4",
533 FT_IPv4, BASE_NONE, NULL, 0,
534 "Group/RP/Source address in Notification messages", HFILL }
537 { "Reserved", "msdp.not.res",
538 FT_UINT24, BASE_HEX, NULL, 0,
539 "Reserved field in Notification messages", HFILL }
541 { &hf_msdp_not_entry_count,
542 { "Entry Count", "msdp.not.entry_count",
543 FT_UINT24, BASE_HEX, NULL, 0,
544 "Entry Count in Notification messages", HFILL }
546 { &hf_msdp_not_sprefix_len,
547 { "Sprefix len", "msdp.not.sprefix_len",
548 FT_UINT8, BASE_DEC, NULL, 0,
549 "Source prefix length in Notification messages", HFILL }
553 static gint *ett[] = {
556 &ett_msdp_sa_enc_data,
560 proto_msdp = proto_register_protocol("Multicast Source Discovery Protocol",
563 proto_register_field_array(proto_msdp, hf, array_length(hf));
564 proto_register_subtree_array(ett, array_length(ett));
568 proto_reg_handoff_msdp(void)
570 dissector_handle_t msdp_handle;
572 msdp_handle = create_dissector_handle(dissect_msdp, proto_msdp);
573 dissector_add_uint("tcp.port", 639, msdp_handle);
575 ip_handle = find_dissector("ip");