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.2 2001/07/11 17:56:31 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.
36 #ifdef HAVE_SYS_TYPES_H
37 # include <sys/types.h>
40 #ifdef HAVE_NETINET_IN_H
41 # include <netinet/in.h>
47 /* MSDP message types. The messages are TLV (Type-Length-Value) encoded */
54 /* Theses are only assigned in MSDP spec. Their use is specifed
56 MSDP_TRACE_IN_PROGRESS,
60 static const value_string msdp_types[] = {
61 { MSDP_SA, "IPv4 Source-Active" },
62 { MSDP_SA_REQ, "IPv4 Source-Active Request" },
63 { MSDP_SA_RSP, "IPv4 Source-Active Response" },
64 { MSDP_KEEP_ALIVE, "KeepAlive" },
65 { MSDP_NOTIFICATION, "Notification" },
67 { MSDP_TRACE_IN_PROGRESS, "MSDP traceroute in progresss" },
68 { MSDP_TRACE_REPLY, "MSDP traceroute reply" },
74 enum { MESSAGE_HEADER_ERROR = 1,
76 SA_MESSAGE_SA_RESPONSE_ERROR,
83 static const value_string error_vals[] = {
84 { MESSAGE_HEADER_ERROR, "Message Header Error" },
85 { SA_REQUEST_ERROR, "SA-Request Error" },
86 { SA_MESSAGE_SA_RESPONSE_ERROR, "SA-Message/SA-Response Error" },
87 { HOLD_TIMER_EXPIRED, "Hold Timer Expired" },
88 { FSM_ERROR, "Finite State Machine Error" },
89 { NOTIFICATION, "Notification" },
95 /* Message Header Error subcodes */
96 static const value_string hdr_error_vals[] = {
98 { 2, "Bad Message Length" },
99 { 3, "Bad Message Type" },
103 /* SA-Request Error subcodes (the O-bit is always clear) */
104 static const value_string sa_req_error_vals[] = {
106 { 1, "Invalid Group" },
110 /* SA-Message/SA-Response Error subcodes */
111 static const value_string sa_msg_error_vals[] = {
113 { 1, "Invalid Entry Count" },
114 { 2, "Invalid RP Address" },
115 { 3, "Invalid Group Address" },
116 { 4, "Invalid Source Address" },
117 { 5, "Invalid Sprefix Length" },
118 { 6, "Looping SA (Self is RP)" },
119 { 7, "Unknown Encapsulation" },
120 { 8, "Administrative Scope Boundary Violated" },
124 /* Finite State Machine Error subcodes (the O-bit is always clear) */
125 static const value_string fsm_error_vals[] = {
127 { 1, "Unexpected Message Type FSM Error" },
132 * Hold Timer Expired subcodes (the O-bit is always clear):
133 * Notification subcodes (the O-bit is always clear):
134 * Cease subcodes (the O-bit is always clear):
136 * These have only "Unspecific" specified.
138 static const value_string sa_unspec_error_vals[] = {
144 /* Initialize the protocol and registered fields */
145 static int proto_msdp = -1;
146 static int hf_msdp_type = -1;
147 static int hf_msdp_length = -1;
149 static int hf_msdp_sa_entry_count = -1;
150 static int hf_msdp_sa_rp_addr = -1;
151 static int hf_msdp_sa_reserved = -1;
152 static int hf_msdp_sa_sprefix_len = -1;
153 static int hf_msdp_sa_group_addr = -1;
154 static int hf_msdp_sa_src_addr = -1;
156 static int hf_msdp_sa_req_res = -1;
157 static int hf_msdp_sa_req_group = -1;
159 static int hf_msdp_not_o = -1;
160 static int hf_msdp_not_error = -1;
161 static int hf_msdp_not_error_sub = -1;
163 static int hf_msdp_not_ipv4 = -1;
164 static int hf_msdp_not_res = -1;
165 static int hf_msdp_not_entry_count = -1;
166 static int hf_msdp_not_sprefix_len = -1;
169 static gint ett_msdp = -1;
170 static gint ett_msdp_sa_entry = -1;
171 static gint ett_msdp_sa_enc_data = -1;
172 static gint ett_msdp_not_data = -1;
175 static dissector_handle_t ip_handle;
179 dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset);
181 dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, guint16 tlv_len);
185 dissect_msdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
188 proto_tree *msdp_tree;
191 if (check_col(pinfo->fd, COL_PROTOCOL))
192 col_set_str(pinfo->fd, COL_PROTOCOL, "MSDP");
194 if (check_col(pinfo->fd, COL_INFO))
195 col_set_str(pinfo->fd, COL_INFO, val_to_str(tvb_get_guint8(tvb, 0),
197 "<Unknown MSDP message type>"));
203 ti = proto_tree_add_item(tree, proto_msdp, tvb, 0, tvb_length(tvb), FALSE);
204 msdp_tree = proto_item_add_subtree(ti, ett_msdp);
207 while (tvb_length_remaining(tvb, offset) >= 3) {
208 type = tvb_get_guint8(tvb, offset);
209 length = tvb_get_ntohs(tvb, offset + 1);
212 proto_tree_add_uint(msdp_tree, hf_msdp_type, tvb, offset, 1, type);
213 proto_tree_add_uint(msdp_tree, hf_msdp_length, tvb, offset + 1, 2, length);
219 dissect_msdp_sa(tvb, pinfo, msdp_tree, &offset);
222 proto_tree_add_item(msdp_tree, hf_msdp_sa_req_res, tvb, offset, 1, FALSE);
223 proto_tree_add_item(msdp_tree, hf_msdp_sa_req_group, tvb, offset + 1, 4, FALSE);
226 case MSDP_NOTIFICATION:
227 dissect_msdp_notification(tvb, pinfo, msdp_tree, &offset, length);
231 proto_tree_add_text(msdp_tree, tvb, offset, length - 3, "TLV contents");
232 offset += (length - 3);
237 if (tvb_length_remaining(tvb, offset) > 0)
238 proto_tree_add_text(msdp_tree, tvb, offset,
239 tvb_length_remaining(tvb, offset), "Trailing junk");
245 /* Both Source-Active and Source-Active Response have the same format
246 * with one exception. Encapsulated multicast data is not allowed in
249 static void dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset)
254 entries = tvb_get_guint8(tvb, *offset);
255 proto_tree_add_uint(tree, hf_msdp_sa_entry_count, tvb, *offset, 1, entries);
258 tvb_memcpy(tvb, (guint8 *)&rp_addr, *offset, 4);
259 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;
269 ei = proto_tree_add_text(tree, tvb, *offset, 24, "(S,G) block: %s/%u -> %s",
270 ip_to_str(tvb_get_ptr(tvb, *offset + 8, 4)),
271 tvb_get_guint8(tvb, *offset + 3),
272 ip_to_str(tvb_get_ptr(tvb, *offset + 4, 4)));
273 entry_tree = proto_item_add_subtree(ei, ett_msdp_sa_entry);
275 proto_tree_add_item(entry_tree, hf_msdp_sa_reserved, tvb, *offset, 3, FALSE);
277 proto_tree_add_item(entry_tree, hf_msdp_sa_sprefix_len, tvb, *offset, 1, FALSE);
279 proto_tree_add_item(entry_tree, hf_msdp_sa_group_addr, tvb, *offset, 4, FALSE);
281 proto_tree_add_item(entry_tree, hf_msdp_sa_src_addr, tvb, *offset, 4, FALSE);
286 * Check if an encapsulated multicast IPv4 packet follows
288 if (tvb_length_remaining(tvb, *offset) > 0) {
290 proto_tree *enc_tree;
293 ei = proto_tree_add_text(tree, tvb, *offset, tvb_length_remaining(tvb, *offset),
294 "Encapsulated IPv4 packet: %u bytes",
295 tvb_length_remaining(tvb, *offset));
296 enc_tree = proto_item_add_subtree(ei, ett_msdp_sa_enc_data);
298 next_tvb = tvb_new_subset(tvb, *offset, -1, -1);
299 /* Set the information columns read-only so that they
300 * reflect the MSDP packet rather than the
301 * encapsulated packet.
303 col_set_writable(pinfo->fd, FALSE);
304 call_dissector(ip_handle, next_tvb, pinfo, enc_tree);
306 *offset += tvb_length_remaining(tvb, *offset);
311 /* Note: updates *offset */
312 static void add_notification_data_ipv4addr(tvbuff_t *tvb, proto_tree *tree, int *offset, const char *addrtype)
316 proto_tree_add_item(tree, hf_msdp_not_res, tvb, *offset, 3, FALSE);
318 tvb_memcpy(tvb, (guint8 *)&ipaddr, *offset, 4);
319 proto_tree_add_ipv4_format(tree, hf_msdp_not_ipv4, tvb, *offset, 4, ipaddr,
320 "%s: %s", addrtype, ip_to_str((guint8 *)&ipaddr));
326 static void dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, guint16 tlv_len)
328 guint8 error, error_sub;
329 const value_string *vals;
331 proto_tree_add_item(tree, hf_msdp_not_o, tvb, *offset, 1, FALSE);
332 proto_tree_add_item(tree, hf_msdp_not_error, tvb, *offset, 1, FALSE);
333 error = tvb_get_guint8(tvb, *offset);
334 error &= 0x7F; /* Error is 7-bit field. O-bit is bit 8 */
337 /* Depending on the Error Code, we collect the correct
338 * value_strings for the Error subcode
341 case MESSAGE_HEADER_ERROR:
342 vals = hdr_error_vals;
344 case SA_REQUEST_ERROR:
345 vals = sa_req_error_vals;
347 case SA_MESSAGE_SA_RESPONSE_ERROR:
348 vals = sa_msg_error_vals;
351 vals = fsm_error_vals;
353 case HOLD_TIMER_EXPIRED:
356 vals = sa_unspec_error_vals;
359 vals = sa_unspec_error_vals;
363 error_sub = tvb_get_guint8(tvb, *offset);
364 proto_tree_add_uint_format(tree, hf_msdp_not_error_sub, tvb, *offset, 1,
365 error_sub, "Error subcode: %s (%u)",
366 val_to_str(error_sub, vals, "<Unknown Error subcode>"),
370 /* Do switch again, this time to dissect the data portion
375 case SA_REQUEST_ERROR:
376 add_notification_data_ipv4addr(tvb, tree, offset, "Group address");
378 case SA_MESSAGE_SA_RESPONSE_ERROR:
379 if (error_sub == 0) {
381 } else if (error_sub == 1) {
382 proto_tree_add_item(tree, hf_msdp_not_entry_count, tvb, *offset, 1, FALSE);
385 } else if (error_sub == 2) {
386 add_notification_data_ipv4addr(tvb, tree, offset, "RP address");
388 } else if (error_sub == 3 || error_sub == 8) {
389 add_notification_data_ipv4addr(tvb, tree, offset, "Group address");
391 } else if (error_sub == 4) {
392 add_notification_data_ipv4addr(tvb, tree, offset, "Source address");
394 } else if (error_sub == 5) {
395 proto_tree_add_item(tree, hf_msdp_not_sprefix_len, tvb, *offset, 1, FALSE);
398 } else if (error_sub == 6) {
399 /* No break, causes fall through to next label */
400 } else if (error_sub == 7) {
401 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
402 "Packet with unknown encapsulation: %u bytes",
404 *offset += tlv_len - 5;
407 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
408 "<Unknown data>: %u bytes",
410 *offset += tlv_len - 5;
414 case MESSAGE_HEADER_ERROR:
416 /* Data contains the message that had an error. Even a
417 * broken Notification message causes a Notification
418 * message with Error Code set to Notification to be
421 next_tvb = tvb_new_subset(tvb, *offset, -1, -1);
422 dissect_msdp(next_tvb, pinfo, tree);
425 case HOLD_TIMER_EXPIRED:
427 /* Do nothing. These contain no data */
431 proto_tree_add_text(tree, tvb, *offset, tlv_len - 5,
432 "<Unknown data>: %u bytes",
434 *offset += tlv_len - 5;
442 proto_register_msdp(void)
444 static hf_register_info hf[] = {
446 { "Type", "msdp.type",
447 FT_UINT8, BASE_DEC, VALS(msdp_types), 0,
448 "MSDP TLV type", HFILL }
451 { "Length", "msdp.length",
452 FT_UINT16, BASE_DEC, NULL, 0,
453 "MSDP TLV Length", HFILL }
455 { &hf_msdp_sa_entry_count,
456 { "Entry Count", "msdp.sa.entry_count",
457 FT_UINT8, BASE_DEC, NULL, 0,
458 "MSDP SA Entry Count", HFILL }
460 { &hf_msdp_sa_rp_addr,
461 { "RP Address", "msdp.sa.rp_addr",
463 "Active source's RP address", HFILL }
465 { &hf_msdp_sa_reserved,
466 { "Reserved", "msdp.sa.reserved",
467 FT_UINT24, BASE_HEX, NULL, 0,
468 "Transmitted as zeros and ignored by a receiver", HFILL }
470 { &hf_msdp_sa_sprefix_len,
471 { "Sprefix len", "msdp.sa.sprefix_len",
472 FT_UINT8, BASE_DEC, NULL, 0,
473 "The route prefix length associated with source address", HFILL }
475 { &hf_msdp_sa_group_addr,
476 { "Group Address", "msdp.sa.group_addr",
478 "The group address the active source has sent data to", HFILL }
480 { &hf_msdp_sa_src_addr,
481 { "Source Address", "msdp.sa.src_addr",
483 "The IP address of the active source", HFILL }
485 { &hf_msdp_sa_req_res,
486 { "Reserved", "msdp.sa_req.res",
487 FT_UINT8, BASE_HEX, NULL, 0,
488 "Transmitted as zeros and ignored by a receiver", HFILL }
490 { &hf_msdp_sa_req_group,
491 { "Group Address", "msdp.sa_req.group_addr",
493 "The group address the MSDP peer is requesting", HFILL }
496 { "Open-bit", "msdp.not.o",
497 FT_UINT8, BASE_HEX, NULL, 0x80,
498 "If clear, the connection will be closed", HFILL }
500 { &hf_msdp_not_error,
501 { "Error Code", "msdp.not.error",
502 FT_UINT8, BASE_DEC, VALS(error_vals), 0x7F,
503 "Indicates the type of Notification", HFILL }
505 { &hf_msdp_not_error_sub,
506 { "Error subode", "msdp.not.error_sub",
507 FT_UINT8, BASE_DEC, NULL, 0,
508 "Error subcode", HFILL }
511 { "IPv4 address", "msdp.not.ipv4",
513 "Group/RP/Source address in Notification messages", HFILL }
516 { "Reserved", "msdp.not.res",
517 FT_UINT24, BASE_HEX, NULL, 0,
518 "Reserved field in Notification messages", HFILL }
520 { &hf_msdp_not_entry_count,
521 { "Entry Count", "msdp.not.entry_count",
522 FT_UINT24, BASE_HEX, NULL, 0,
523 "Entry Count in Notification messages", HFILL }
525 { &hf_msdp_not_sprefix_len,
526 { "Sprefix len", "msdp.not.sprefix_len",
527 FT_UINT8, BASE_DEC, NULL, 0,
528 "Source prefix length in Notification messages", HFILL }
532 static gint *ett[] = {
535 &ett_msdp_sa_enc_data,
539 proto_msdp = proto_register_protocol("Multicast Source Discovery Protocol",
542 proto_register_field_array(proto_msdp, hf, array_length(hf));
543 proto_register_subtree_array(ett, array_length(ett));
547 proto_reg_handoff_PROTOABBREV(void)
549 dissector_add("tcp.port", 639, dissect_msdp,
552 ip_handle = find_dissector("ip");