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>
7 * $Id: packet-msdp.c,v 1.8 2003/01/20 06:24:37 guy Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
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>
40 /* MSDP message types. The messages are TLV (Type-Length-Value) encoded */
47 /* Theses are only assigned in MSDP spec. Their use is specifed
49 MSDP_TRACE_IN_PROGRESS,
53 static const value_string msdp_types[] = {
54 { MSDP_SA, "IPv4 Source-Active" },
55 { MSDP_SA_REQ, "IPv4 Source-Active Request" },
56 { MSDP_SA_RSP, "IPv4 Source-Active Response" },
57 { MSDP_KEEP_ALIVE, "KeepAlive" },
58 { MSDP_NOTIFICATION, "Notification" },
60 { MSDP_TRACE_IN_PROGRESS, "MSDP traceroute in progresss" },
61 { MSDP_TRACE_REPLY, "MSDP traceroute reply" },
67 enum { MESSAGE_HEADER_ERROR = 1,
69 SA_MESSAGE_SA_RESPONSE_ERROR,
76 static const value_string error_vals[] = {
77 { MESSAGE_HEADER_ERROR, "Message Header Error" },
78 { SA_REQUEST_ERROR, "SA-Request Error" },
79 { SA_MESSAGE_SA_RESPONSE_ERROR, "SA-Message/SA-Response Error" },
80 { HOLD_TIMER_EXPIRED, "Hold Timer Expired" },
81 { FSM_ERROR, "Finite State Machine Error" },
82 { NOTIFICATION, "Notification" },
88 /* Message Header Error subcodes */
89 static const value_string hdr_error_vals[] = {
91 { 2, "Bad Message Length" },
92 { 3, "Bad Message Type" },
96 /* SA-Request Error subcodes (the O-bit is always clear) */
97 static const value_string sa_req_error_vals[] = {
99 { 1, "Invalid Group" },
103 /* SA-Message/SA-Response Error subcodes */
104 static const value_string sa_msg_error_vals[] = {
106 { 1, "Invalid Entry Count" },
107 { 2, "Invalid RP Address" },
108 { 3, "Invalid Group Address" },
109 { 4, "Invalid Source Address" },
110 { 5, "Invalid Sprefix Length" },
111 { 6, "Looping SA (Self is RP)" },
112 { 7, "Unknown Encapsulation" },
113 { 8, "Administrative Scope Boundary Violated" },
117 /* Finite State Machine Error subcodes (the O-bit is always clear) */
118 static const value_string fsm_error_vals[] = {
120 { 1, "Unexpected Message Type FSM Error" },
125 * Hold Timer Expired subcodes (the O-bit is always clear):
126 * Notification subcodes (the O-bit is always clear):
127 * Cease subcodes (the O-bit is always clear):
129 * These have only "Unspecific" specified.
131 static const value_string sa_unspec_error_vals[] = {
137 /* Initialize the protocol and registered fields */
138 static int proto_msdp = -1;
139 static int hf_msdp_type = -1;
140 static int hf_msdp_length = -1;
142 static int hf_msdp_sa_entry_count = -1;
143 static int hf_msdp_sa_rp_addr = -1;
144 static int hf_msdp_sa_reserved = -1;
145 static int hf_msdp_sa_sprefix_len = -1;
146 static int hf_msdp_sa_group_addr = -1;
147 static int hf_msdp_sa_src_addr = -1;
149 static int hf_msdp_sa_req_res = -1;
150 static int hf_msdp_sa_req_group = -1;
152 static int hf_msdp_not_o = -1;
153 static int hf_msdp_not_error = -1;
154 static int hf_msdp_not_error_sub = -1;
156 static int hf_msdp_not_ipv4 = -1;
157 static int hf_msdp_not_res = -1;
158 static int hf_msdp_not_entry_count = -1;
159 static int hf_msdp_not_sprefix_len = -1;
162 static gint ett_msdp = -1;
163 static gint ett_msdp_sa_entry = -1;
164 static gint ett_msdp_sa_enc_data = -1;
165 static gint ett_msdp_not_data = -1;
168 static dissector_handle_t ip_handle;
172 dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
173 int *offset, int len);
175 dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, guint16 tlv_len);
179 dissect_msdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
182 proto_tree *msdp_tree;
185 if (check_col(pinfo->cinfo, COL_PROTOCOL))
186 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSDP");
188 if (check_col(pinfo->cinfo, COL_INFO))
189 col_set_str(pinfo->cinfo, COL_INFO, val_to_str(tvb_get_guint8(tvb, 0),
191 "<Unknown MSDP message type>"));
197 ti = proto_tree_add_item(tree, proto_msdp, tvb, 0, -1, FALSE);
198 msdp_tree = proto_item_add_subtree(ti, ett_msdp);
201 while (tvb_reported_length_remaining(tvb, offset) >= 3) {
202 type = tvb_get_guint8(tvb, offset);
203 length = tvb_get_ntohs(tvb, offset + 1);
206 proto_tree_add_uint(msdp_tree, hf_msdp_type, tvb, offset, 1, type);
207 proto_tree_add_uint(msdp_tree, hf_msdp_length, tvb, offset + 1, 2, length);
214 dissect_msdp_sa(tvb, pinfo, msdp_tree, &offset,
218 proto_tree_add_item(msdp_tree, hf_msdp_sa_req_res, tvb, offset, 1, FALSE);
219 proto_tree_add_item(msdp_tree, hf_msdp_sa_req_group, tvb, offset + 1, 4, FALSE);
222 case MSDP_NOTIFICATION:
223 dissect_msdp_notification(tvb, pinfo, msdp_tree, &offset, length);
227 proto_tree_add_text(msdp_tree, tvb, offset, length, "TLV contents");
233 if (tvb_length_remaining(tvb, offset) > 0)
234 proto_tree_add_text(msdp_tree, tvb, offset,
235 -1, "Trailing junk");
241 /* Both Source-Active and Source-Active Response have the same format
242 * with one exception. Encapsulated multicast data is not allowed in
245 static void dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo,
246 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 tvb_memcpy(tvb, (guint8 *)&rp_addr, *offset, 4);
264 proto_tree_add_item(tree, hf_msdp_sa_rp_addr, tvb, *offset, 4, FALSE);
268 /* Put each of the (S,G) entries in their own subtree.
269 * This is probably visually better.
271 while (entries-- > 0) {
273 proto_tree *entry_tree;
280 ei = proto_tree_add_text(tree, tvb, *offset, 12, "(S,G) block: %s/%u -> %s",
281 ip_to_str(tvb_get_ptr(tvb, *offset + 8, 4)),
282 tvb_get_guint8(tvb, *offset + 3),
283 ip_to_str(tvb_get_ptr(tvb, *offset + 4, 4)));
284 entry_tree = proto_item_add_subtree(ei, ett_msdp_sa_entry);
286 proto_tree_add_item(entry_tree, hf_msdp_sa_reserved, tvb, *offset, 3, FALSE);
289 proto_tree_add_item(entry_tree, hf_msdp_sa_sprefix_len, tvb, *offset, 1, FALSE);
292 proto_tree_add_item(entry_tree, hf_msdp_sa_group_addr, tvb, *offset, 4, FALSE);
295 proto_tree_add_item(entry_tree, hf_msdp_sa_src_addr, tvb, *offset, 4, FALSE);
301 * Check if an encapsulated multicast IPv4 packet follows
305 proto_tree *enc_tree;
306 gint available_length, reported_length;
309 ei = proto_tree_add_text(tree, tvb, *offset, length,
310 "Encapsulated IPv4 packet: %u bytes",
312 enc_tree = proto_item_add_subtree(ei, ett_msdp_sa_enc_data);
314 available_length = tvb_length_remaining(tvb, *offset);
315 reported_length = tvb_reported_length_remaining(tvb, *offset);
316 g_assert(available_length >= 0);
317 g_assert(reported_length >= 0);
318 if (available_length > reported_length)
319 available_length = reported_length;
320 if (available_length > length)
321 available_length = length;
322 if (reported_length > length)
323 reported_length = length;
325 next_tvb = tvb_new_subset(tvb, *offset, available_length,
327 /* Set the information columns read-only so that they
328 * reflect the MSDP packet rather than the
329 * encapsulated packet.
331 col_set_writable(pinfo->cinfo, FALSE);
332 call_dissector(ip_handle, next_tvb, pinfo, enc_tree);
339 /* Note: updates *offset */
340 static void add_notification_data_ipv4addr(tvbuff_t *tvb, proto_tree *tree, int *offset, const char *addrtype)
344 proto_tree_add_item(tree, hf_msdp_not_res, tvb, *offset, 3, FALSE);
346 tvb_memcpy(tvb, (guint8 *)&ipaddr, *offset, 4);
347 proto_tree_add_ipv4_format(tree, hf_msdp_not_ipv4, tvb, *offset, 4, ipaddr,
348 "%s: %s", addrtype, ip_to_str((guint8 *)&ipaddr));
354 static void dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, guint16 tlv_len)
356 guint8 error, error_sub;
357 const value_string *vals;
359 proto_tree_add_item(tree, hf_msdp_not_o, tvb, *offset, 1, FALSE);
360 proto_tree_add_item(tree, hf_msdp_not_error, tvb, *offset, 1, FALSE);
361 error = tvb_get_guint8(tvb, *offset);
362 error &= 0x7F; /* Error is 7-bit field. O-bit is bit 8 */
365 /* Depending on the Error Code, we collect the correct
366 * value_strings for the Error subcode
369 case MESSAGE_HEADER_ERROR:
370 vals = hdr_error_vals;
372 case SA_REQUEST_ERROR:
373 vals = sa_req_error_vals;
375 case SA_MESSAGE_SA_RESPONSE_ERROR:
376 vals = sa_msg_error_vals;
379 vals = fsm_error_vals;
381 case HOLD_TIMER_EXPIRED:
384 vals = sa_unspec_error_vals;
387 vals = sa_unspec_error_vals;
391 error_sub = tvb_get_guint8(tvb, *offset);
392 proto_tree_add_uint_format(tree, hf_msdp_not_error_sub, tvb, *offset, 1,
393 error_sub, "Error subcode: %s (%u)",
394 val_to_str(error_sub, vals, "<Unknown Error subcode>"),
398 /* Do switch again, this time to dissect the data portion
403 case SA_REQUEST_ERROR:
404 add_notification_data_ipv4addr(tvb, tree, offset, "Group address");
406 case SA_MESSAGE_SA_RESPONSE_ERROR:
407 if (error_sub == 0) {
409 } else if (error_sub == 1) {
410 proto_tree_add_item(tree, hf_msdp_not_entry_count, tvb, *offset, 1, FALSE);
413 } else if (error_sub == 2) {
414 add_notification_data_ipv4addr(tvb, tree, offset, "RP address");
416 } else if (error_sub == 3 || error_sub == 8) {
417 add_notification_data_ipv4addr(tvb, tree, offset, "Group address");
419 } else if (error_sub == 4) {
420 add_notification_data_ipv4addr(tvb, tree, offset, "Source address");
422 } else if (error_sub == 5) {
423 proto_tree_add_item(tree, hf_msdp_not_sprefix_len, tvb, *offset, 1, FALSE);
426 } else if (error_sub == 6) {
427 /* No break, causes fall through to next label */
428 } else if (error_sub == 7) {
429 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
430 "Packet with unknown encapsulation: %u bytes",
432 *offset += tlv_len - 5;
435 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
436 "<Unknown data>: %u bytes",
438 *offset += tlv_len - 5;
442 case MESSAGE_HEADER_ERROR:
444 /* Data contains the message that had an error. Even a
445 * broken Notification message causes a Notification
446 * message with Error Code set to Notification to be
449 next_tvb = tvb_new_subset(tvb, *offset, -1, -1);
450 dissect_msdp(next_tvb, pinfo, tree);
453 case HOLD_TIMER_EXPIRED:
455 /* Do nothing. These contain no data */
459 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
460 "<Unknown data>: %u bytes",
462 *offset += tlv_len - 5;
470 proto_register_msdp(void)
472 static hf_register_info hf[] = {
474 { "Type", "msdp.type",
475 FT_UINT8, BASE_DEC, VALS(msdp_types), 0,
476 "MSDP TLV type", HFILL }
479 { "Length", "msdp.length",
480 FT_UINT16, BASE_DEC, NULL, 0,
481 "MSDP TLV Length", HFILL }
483 { &hf_msdp_sa_entry_count,
484 { "Entry Count", "msdp.sa.entry_count",
485 FT_UINT8, BASE_DEC, NULL, 0,
486 "MSDP SA Entry Count", HFILL }
488 { &hf_msdp_sa_rp_addr,
489 { "RP Address", "msdp.sa.rp_addr",
491 "Active source's RP address", HFILL }
493 { &hf_msdp_sa_reserved,
494 { "Reserved", "msdp.sa.reserved",
495 FT_UINT24, BASE_HEX, NULL, 0,
496 "Transmitted as zeros and ignored by a receiver", HFILL }
498 { &hf_msdp_sa_sprefix_len,
499 { "Sprefix len", "msdp.sa.sprefix_len",
500 FT_UINT8, BASE_DEC, NULL, 0,
501 "The route prefix length associated with source address", HFILL }
503 { &hf_msdp_sa_group_addr,
504 { "Group Address", "msdp.sa.group_addr",
506 "The group address the active source has sent data to", HFILL }
508 { &hf_msdp_sa_src_addr,
509 { "Source Address", "msdp.sa.src_addr",
511 "The IP address of the active source", HFILL }
513 { &hf_msdp_sa_req_res,
514 { "Reserved", "msdp.sa_req.res",
515 FT_UINT8, BASE_HEX, NULL, 0,
516 "Transmitted as zeros and ignored by a receiver", HFILL }
518 { &hf_msdp_sa_req_group,
519 { "Group Address", "msdp.sa_req.group_addr",
521 "The group address the MSDP peer is requesting", HFILL }
524 { "Open-bit", "msdp.not.o",
525 FT_UINT8, BASE_HEX, NULL, 0x80,
526 "If clear, the connection will be closed", HFILL }
528 { &hf_msdp_not_error,
529 { "Error Code", "msdp.not.error",
530 FT_UINT8, BASE_DEC, VALS(error_vals), 0x7F,
531 "Indicates the type of Notification", HFILL }
533 { &hf_msdp_not_error_sub,
534 { "Error subode", "msdp.not.error_sub",
535 FT_UINT8, BASE_DEC, NULL, 0,
536 "Error subcode", HFILL }
539 { "IPv4 address", "msdp.not.ipv4",
541 "Group/RP/Source address in Notification messages", HFILL }
544 { "Reserved", "msdp.not.res",
545 FT_UINT24, BASE_HEX, NULL, 0,
546 "Reserved field in Notification messages", HFILL }
548 { &hf_msdp_not_entry_count,
549 { "Entry Count", "msdp.not.entry_count",
550 FT_UINT24, BASE_HEX, NULL, 0,
551 "Entry Count in Notification messages", HFILL }
553 { &hf_msdp_not_sprefix_len,
554 { "Sprefix len", "msdp.not.sprefix_len",
555 FT_UINT8, BASE_DEC, NULL, 0,
556 "Source prefix length in Notification messages", HFILL }
560 static gint *ett[] = {
563 &ett_msdp_sa_enc_data,
567 proto_msdp = proto_register_protocol("Multicast Source Discovery Protocol",
570 proto_register_field_array(proto_msdp, hf, array_length(hf));
571 proto_register_subtree_array(ett, array_length(ett));
575 proto_reg_handoff_msdp(void)
577 dissector_handle_t msdp_handle;
579 msdp_handle = create_dissector_handle(dissect_msdp, proto_msdp);
580 dissector_add("tcp.port", 639, msdp_handle);
582 ip_handle = find_dissector("ip");