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.
38 #include <epan/packet.h>
39 #include <epan/emem.h>
41 /* MSDP message types. The messages are TLV (Type-Length-Value) encoded */
48 /* Theses are only assigned in MSDP spec. Their use is specifed
50 MSDP_TRACE_IN_PROGRESS,
54 static const value_string msdp_types[] = {
55 { MSDP_SA, "IPv4 Source-Active" },
56 { MSDP_SA_REQ, "IPv4 Source-Active Request" },
57 { MSDP_SA_RSP, "IPv4 Source-Active Response" },
58 { MSDP_KEEP_ALIVE, "KeepAlive" },
59 { MSDP_NOTIFICATION, "Notification" },
61 { MSDP_TRACE_IN_PROGRESS, "MSDP traceroute in progress" },
62 { MSDP_TRACE_REPLY, "MSDP traceroute reply" },
68 enum { MESSAGE_HEADER_ERROR = 1,
70 SA_MESSAGE_SA_RESPONSE_ERROR,
77 static const value_string error_vals[] = {
78 { MESSAGE_HEADER_ERROR, "Message Header Error" },
79 { SA_REQUEST_ERROR, "SA-Request Error" },
80 { SA_MESSAGE_SA_RESPONSE_ERROR, "SA-Message/SA-Response Error" },
81 { HOLD_TIMER_EXPIRED, "Hold Timer Expired" },
82 { FSM_ERROR, "Finite State Machine Error" },
83 { NOTIFICATION, "Notification" },
89 /* Message Header Error subcodes */
90 static const value_string hdr_error_vals[] = {
92 { 2, "Bad Message Length" },
93 { 3, "Bad Message Type" },
97 /* SA-Request Error subcodes (the O-bit is always clear) */
98 static const value_string sa_req_error_vals[] = {
100 { 1, "Invalid Group" },
104 /* SA-Message/SA-Response Error subcodes */
105 static const value_string sa_msg_error_vals[] = {
107 { 1, "Invalid Entry Count" },
108 { 2, "Invalid RP Address" },
109 { 3, "Invalid Group Address" },
110 { 4, "Invalid Source Address" },
111 { 5, "Invalid Sprefix Length" },
112 { 6, "Looping SA (Self is RP)" },
113 { 7, "Unknown Encapsulation" },
114 { 8, "Administrative Scope Boundary Violated" },
118 /* Finite State Machine Error subcodes (the O-bit is always clear) */
119 static const value_string fsm_error_vals[] = {
121 { 1, "Unexpected Message Type FSM Error" },
126 * Hold Timer Expired subcodes (the O-bit is always clear):
127 * Notification subcodes (the O-bit is always clear):
128 * Cease subcodes (the O-bit is always clear):
130 * These have only "Unspecific" specified.
132 static const value_string sa_unspec_error_vals[] = {
138 /* Initialize the protocol and registered fields */
139 static int proto_msdp = -1;
140 static int hf_msdp_type = -1;
141 static int hf_msdp_length = -1;
143 static int hf_msdp_sa_entry_count = -1;
144 static int hf_msdp_sa_rp_addr = -1;
145 static int hf_msdp_sa_reserved = -1;
146 static int hf_msdp_sa_sprefix_len = -1;
147 static int hf_msdp_sa_group_addr = -1;
148 static int hf_msdp_sa_src_addr = -1;
150 static int hf_msdp_sa_req_res = -1;
151 static int hf_msdp_sa_req_group = -1;
153 static int hf_msdp_not_o = -1;
154 static int hf_msdp_not_error = -1;
155 static int hf_msdp_not_error_sub = -1;
157 static int hf_msdp_not_ipv4 = -1;
158 static int hf_msdp_not_res = -1;
159 static int hf_msdp_not_entry_count = -1;
160 static int hf_msdp_not_sprefix_len = -1;
163 static gint ett_msdp = -1;
164 static gint ett_msdp_sa_entry = -1;
165 static gint ett_msdp_sa_enc_data = -1;
166 static gint ett_msdp_not_data = -1;
169 static dissector_handle_t ip_handle;
173 dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
174 int *offset, int len);
176 dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, guint16 tlv_len);
180 dissect_msdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
183 proto_tree *msdp_tree;
186 if (check_col(pinfo->cinfo, COL_PROTOCOL))
187 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSDP");
189 if (check_col(pinfo->cinfo, COL_INFO))
190 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(tvb_get_guint8(tvb, 0),
192 "<Unknown MSDP message type>"));
198 ti = proto_tree_add_item(tree, proto_msdp, tvb, 0, -1, FALSE);
199 msdp_tree = proto_item_add_subtree(ti, ett_msdp);
202 while (tvb_reported_length_remaining(tvb, offset) >= 3) {
203 type = tvb_get_guint8(tvb, offset);
204 length = tvb_get_ntohs(tvb, offset + 1);
207 proto_tree_add_uint(msdp_tree, hf_msdp_type, tvb, offset, 1, type);
208 proto_tree_add_uint(msdp_tree, hf_msdp_length, tvb, offset + 1, 2, length);
215 dissect_msdp_sa(tvb, pinfo, msdp_tree, &offset,
219 proto_tree_add_item(msdp_tree, hf_msdp_sa_req_res, tvb, offset, 1, FALSE);
220 proto_tree_add_item(msdp_tree, hf_msdp_sa_req_group, tvb, offset + 1, 4, FALSE);
223 case MSDP_NOTIFICATION:
224 dissect_msdp_notification(tvb, pinfo, msdp_tree, &offset, length);
228 proto_tree_add_text(msdp_tree, tvb, offset, length, "TLV contents");
234 if (tvb_length_remaining(tvb, offset) > 0)
235 proto_tree_add_text(msdp_tree, tvb, offset,
236 -1, "Trailing junk");
242 /* Both Source-Active and Source-Active Response have the same format
243 * with one exception. Encapsulated multicast data is not allowed in
246 static void dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo,
247 proto_tree *tree, int *offset, int length)
253 entries = tvb_get_guint8(tvb, *offset);
254 proto_tree_add_uint(tree, hf_msdp_sa_entry_count, tvb, *offset, 1, entries);
263 proto_tree_add_item(tree, hf_msdp_sa_rp_addr, tvb, *offset, 4, FALSE);
267 /* Put each of the (S,G) entries in their own subtree.
268 * This is probably visually better.
270 while (entries-- > 0) {
272 proto_tree *entry_tree;
279 ei = proto_tree_add_text(tree, tvb, *offset, 12, "(S,G) block: %s/%u -> %s",
280 ip_to_str(tvb_get_ptr(tvb, *offset + 8, 4)),
281 tvb_get_guint8(tvb, *offset + 3),
282 ip_to_str(tvb_get_ptr(tvb, *offset + 4, 4)));
283 entry_tree = proto_item_add_subtree(ei, ett_msdp_sa_entry);
285 proto_tree_add_item(entry_tree, hf_msdp_sa_reserved, tvb, *offset, 3, FALSE);
288 proto_tree_add_item(entry_tree, hf_msdp_sa_sprefix_len, tvb, *offset, 1, FALSE);
291 proto_tree_add_item(entry_tree, hf_msdp_sa_group_addr, tvb, *offset, 4, FALSE);
294 proto_tree_add_item(entry_tree, hf_msdp_sa_src_addr, tvb, *offset, 4, FALSE);
300 * Check if an encapsulated multicast IPv4 packet follows
304 proto_tree *enc_tree;
305 gint available_length, reported_length;
308 ei = proto_tree_add_text(tree, tvb, *offset, length,
309 "Encapsulated IPv4 packet: %u bytes",
311 enc_tree = proto_item_add_subtree(ei, ett_msdp_sa_enc_data);
313 available_length = tvb_length_remaining(tvb, *offset);
314 reported_length = tvb_reported_length_remaining(tvb, *offset);
315 DISSECTOR_ASSERT(available_length >= 0);
316 DISSECTOR_ASSERT(reported_length >= 0);
317 if (available_length > reported_length)
318 available_length = reported_length;
319 if (available_length > length)
320 available_length = length;
321 if (reported_length > length)
322 reported_length = length;
324 next_tvb = tvb_new_subset(tvb, *offset, available_length,
326 /* Set the information columns read-only so that they
327 * reflect the MSDP packet rather than the
328 * encapsulated packet.
330 col_set_writable(pinfo->cinfo, FALSE);
331 call_dissector(ip_handle, next_tvb, pinfo, enc_tree);
338 /* Note: updates *offset */
339 static void add_notification_data_ipv4addr(tvbuff_t *tvb, proto_tree *tree, int *offset, const char *addrtype)
343 proto_tree_add_item(tree, hf_msdp_not_res, tvb, *offset, 3, FALSE);
345 ipaddr = tvb_get_ipv4(tvb, *offset);
346 proto_tree_add_ipv4_format(tree, hf_msdp_not_ipv4, tvb, *offset, 4, ipaddr,
347 "%s: %s", addrtype, ip_to_str((guint8 *)&ipaddr));
353 static void dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, guint16 tlv_len)
355 guint8 error, error_sub;
356 const value_string *vals;
358 proto_tree_add_item(tree, hf_msdp_not_o, tvb, *offset, 1, FALSE);
359 proto_tree_add_item(tree, hf_msdp_not_error, tvb, *offset, 1, FALSE);
360 error = tvb_get_guint8(tvb, *offset);
361 error &= 0x7F; /* Error is 7-bit field. O-bit is bit 8 */
364 /* Depending on the Error Code, we collect the correct
365 * value_strings for the Error subcode
368 case MESSAGE_HEADER_ERROR:
369 vals = hdr_error_vals;
371 case SA_REQUEST_ERROR:
372 vals = sa_req_error_vals;
374 case SA_MESSAGE_SA_RESPONSE_ERROR:
375 vals = sa_msg_error_vals;
378 vals = fsm_error_vals;
380 case HOLD_TIMER_EXPIRED:
383 vals = sa_unspec_error_vals;
386 vals = sa_unspec_error_vals;
390 error_sub = tvb_get_guint8(tvb, *offset);
391 proto_tree_add_uint_format(tree, hf_msdp_not_error_sub, tvb, *offset, 1,
392 error_sub, "Error subcode: %s (%u)",
393 val_to_str(error_sub, vals, "<Unknown Error subcode>"),
397 /* Do switch again, this time to dissect the data portion
402 case SA_REQUEST_ERROR:
403 add_notification_data_ipv4addr(tvb, tree, offset, "Group address");
405 case SA_MESSAGE_SA_RESPONSE_ERROR:
406 if (error_sub == 0) {
408 } else if (error_sub == 1) {
409 proto_tree_add_item(tree, hf_msdp_not_entry_count, tvb, *offset, 1, FALSE);
412 } else if (error_sub == 2) {
413 add_notification_data_ipv4addr(tvb, tree, offset, "RP address");
415 } else if (error_sub == 3 || error_sub == 8) {
416 add_notification_data_ipv4addr(tvb, tree, offset, "Group address");
418 } else if (error_sub == 4) {
419 add_notification_data_ipv4addr(tvb, tree, offset, "Source address");
421 } else if (error_sub == 5) {
422 proto_tree_add_item(tree, hf_msdp_not_sprefix_len, tvb, *offset, 1, FALSE);
425 } else if (error_sub == 6) {
426 /* No break, causes fall through to next label */
427 } else if (error_sub == 7) {
428 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
429 "Packet with unknown encapsulation: %u bytes",
431 *offset += tlv_len - 5;
434 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
435 "<Unknown data>: %u bytes",
437 *offset += tlv_len - 5;
441 case MESSAGE_HEADER_ERROR:
443 /* Data contains the message that had an error. Even a
444 * broken Notification message causes a Notification
445 * message with Error Code set to Notification to be
448 next_tvb = tvb_new_subset(tvb, *offset, -1, -1);
449 dissect_msdp(next_tvb, pinfo, tree);
452 case HOLD_TIMER_EXPIRED:
454 /* Do nothing. These contain no data */
458 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
459 "<Unknown data>: %u bytes",
461 *offset += tlv_len - 5;
469 proto_register_msdp(void)
471 static hf_register_info hf[] = {
473 { "Type", "msdp.type",
474 FT_UINT8, BASE_DEC, VALS(msdp_types), 0,
475 "MSDP TLV type", HFILL }
478 { "Length", "msdp.length",
479 FT_UINT16, BASE_DEC, NULL, 0,
480 "MSDP TLV Length", HFILL }
482 { &hf_msdp_sa_entry_count,
483 { "Entry Count", "msdp.sa.entry_count",
484 FT_UINT8, BASE_DEC, NULL, 0,
485 "MSDP SA Entry Count", HFILL }
487 { &hf_msdp_sa_rp_addr,
488 { "RP Address", "msdp.sa.rp_addr",
490 "Active source's RP address", HFILL }
492 { &hf_msdp_sa_reserved,
493 { "Reserved", "msdp.sa.reserved",
494 FT_UINT24, BASE_HEX, NULL, 0,
495 "Transmitted as zeros and ignored by a receiver", HFILL }
497 { &hf_msdp_sa_sprefix_len,
498 { "Sprefix len", "msdp.sa.sprefix_len",
499 FT_UINT8, BASE_DEC, NULL, 0,
500 "The route prefix length associated with source address", HFILL }
502 { &hf_msdp_sa_group_addr,
503 { "Group Address", "msdp.sa.group_addr",
505 "The group address the active source has sent data to", HFILL }
507 { &hf_msdp_sa_src_addr,
508 { "Source Address", "msdp.sa.src_addr",
510 "The IP address of the active source", HFILL }
512 { &hf_msdp_sa_req_res,
513 { "Reserved", "msdp.sa_req.res",
514 FT_UINT8, BASE_HEX, NULL, 0,
515 "Transmitted as zeros and ignored by a receiver", HFILL }
517 { &hf_msdp_sa_req_group,
518 { "Group Address", "msdp.sa_req.group_addr",
520 "The group address the MSDP peer is requesting", HFILL }
523 { "Open-bit", "msdp.not.o",
524 FT_UINT8, BASE_HEX, NULL, 0x80,
525 "If clear, the connection will be closed", HFILL }
527 { &hf_msdp_not_error,
528 { "Error Code", "msdp.not.error",
529 FT_UINT8, BASE_DEC, VALS(error_vals), 0x7F,
530 "Indicates the type of Notification", HFILL }
532 { &hf_msdp_not_error_sub,
533 { "Error subode", "msdp.not.error_sub",
534 FT_UINT8, BASE_DEC, NULL, 0,
535 "Error subcode", HFILL }
538 { "IPv4 address", "msdp.not.ipv4",
540 "Group/RP/Source address in Notification messages", HFILL }
543 { "Reserved", "msdp.not.res",
544 FT_UINT24, BASE_HEX, NULL, 0,
545 "Reserved field in Notification messages", HFILL }
547 { &hf_msdp_not_entry_count,
548 { "Entry Count", "msdp.not.entry_count",
549 FT_UINT24, BASE_HEX, NULL, 0,
550 "Entry Count in Notification messages", HFILL }
552 { &hf_msdp_not_sprefix_len,
553 { "Sprefix len", "msdp.not.sprefix_len",
554 FT_UINT8, BASE_DEC, NULL, 0,
555 "Source prefix length in Notification messages", HFILL }
559 static gint *ett[] = {
562 &ett_msdp_sa_enc_data,
566 proto_msdp = proto_register_protocol("Multicast Source Discovery Protocol",
569 proto_register_field_array(proto_msdp, hf, array_length(hf));
570 proto_register_subtree_array(ett, array_length(ett));
574 proto_reg_handoff_msdp(void)
576 dissector_handle_t msdp_handle;
578 msdp_handle = create_dissector_handle(dissect_msdp, proto_msdp);
579 dissector_add("tcp.port", 639, msdp_handle);
581 ip_handle = find_dissector("ip");