summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-msdp.c
blob: 12532eb8011d151bbe602f1e7f1c16e99ea88182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/* packet-msdp.c
 * Routines for Multicast Source Discovery Protocol (MSDP) dissection.
 * RFC 3618
 *
 * Copyright 2001, Heikki Vatiainen <hessu@cs.tut.fi>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/to_str.h>
#include <epan/expert.h>

void proto_register_msdp(void);
void proto_reg_handoff_msdp(void);

/* MSDP (Type-Length-Value) TLV types. The messages are a sequence of TLVs. */
enum { MSDP_SA     = 1,
       MSDP_SA_REQ,
       MSDP_SA_RSP,
       MSDP_KEEP_ALIVE,
       MSDP_NOTIFICATION,  /* draft 10, but not RFC 3618 */

       /* These are only assigned in MSDP spec. Their use is specified
        * elsewhere */
       MSDP_TRACE_IN_PROGRESS,
       MSDP_TRACE_REPLY
};

static const value_string msdp_types[] = {
        { MSDP_SA,                "IPv4 Source-Active"           },
        { MSDP_SA_REQ,            "IPv4 Source-Active Request"   },
        { MSDP_SA_RSP,            "IPv4 Source-Active Response"  },
        { MSDP_KEEP_ALIVE,        "KeepAlive"                    },
        { MSDP_NOTIFICATION,      "Notification"                 },

        { MSDP_TRACE_IN_PROGRESS, "MSDP traceroute in progress"  },
        { MSDP_TRACE_REPLY,       "MSDP traceroute reply"        },
        { 0, NULL },
};


/* Error codes */
enum { MESSAGE_HEADER_ERROR = 1,
       SA_REQUEST_ERROR,
       SA_MESSAGE_SA_RESPONSE_ERROR,
       HOLD_TIMER_EXPIRED,
       FSM_ERROR,
       NOTIFICATION,
       CEASE
};

static const value_string error_vals[] = {
        { MESSAGE_HEADER_ERROR,         "Message Header Error"         },
        { SA_REQUEST_ERROR,             "SA-Request Error"             },
        { SA_MESSAGE_SA_RESPONSE_ERROR, "SA-Message/SA-Response Error" },
        { HOLD_TIMER_EXPIRED,           "Hold Timer Expired"           },
        { FSM_ERROR,                    "Finite State Machine Error"   },
        { NOTIFICATION,                 "Notification"                 },
        { CEASE,                        "Cease"                        },
        { 0, NULL },
};


/* Message Header Error subcodes */
static const value_string hdr_error_vals[] = {
        { 0, "Unspecific"         },
        { 2, "Bad Message Length" },
        { 3, "Bad Message Type"   },
        { 0, NULL },
};

/* SA-Request Error subcodes (the O-bit is always clear) */
static const value_string sa_req_error_vals[] = {
        { 0, "Unspecific"    },
        { 1, "Invalid Group" },
        { 0, NULL },
};

/* SA-Message/SA-Response Error subcodes */
static const value_string sa_msg_error_vals[] = {
        { 0, "Unspecific"                             },
        { 1, "Invalid Entry Count"                    },
        { 2, "Invalid RP Address"                     },
        { 3, "Invalid Group Address"                  },
        { 4, "Invalid Source Address"                 },
        { 5, "Invalid Sprefix Length"                 },
        { 6, "Looping SA (Self is RP)"                },
        { 7, "Unknown Encapsulation"                  },
        { 8, "Administrative Scope Boundary Violated" },
        { 0, NULL },
};

/* Finite State Machine Error subcodes (the O-bit is always clear) */
static const value_string fsm_error_vals[] = {
        { 0, "Unspecific"                        },
        { 1, "Unexpected Message Type FSM Error" },
        { 0, NULL },
};

/*
 * Hold Timer Expired subcodes (the O-bit is always clear):
 * Notification subcodes (the O-bit is always clear):
 * Cease subcodes (the O-bit is always clear):
 *
 * These have only "Unspecific" specified.
 */
static const value_string sa_unspec_error_vals[] = {
        { 0, "Unspecific" },
        { 0, NULL },
};

#define MSDP_PORT  639

/* Initialize the protocol and registered fields */
static int proto_msdp = -1;
static int hf_msdp_type = -1;
static int hf_msdp_length = -1;

static int hf_msdp_sa_entry_count = -1;
static int hf_msdp_sa_rp_addr = -1;
static int hf_msdp_sa_reserved = -1;
static int hf_msdp_sa_sprefix_len = -1;
static int hf_msdp_sa_group_addr = -1;
static int hf_msdp_sa_src_addr = -1;

static int hf_msdp_sa_req_res = -1;
static int hf_msdp_sa_req_group = -1;

static int hf_msdp_not_o = -1;
static int hf_msdp_not_error = -1;
static int hf_msdp_not_error_sub = -1;

static int hf_msdp_not_group_address = -1;
static int hf_msdp_not_rp_address = -1;
static int hf_msdp_not_source_address = -1;
static int hf_msdp_not_res = -1;
static int hf_msdp_not_entry_count = -1;
static int hf_msdp_not_sprefix_len = -1;

static int hf_msdp_tlv_contents = -1;
static int hf_msdp_trailing_junk = -1;
static int hf_msdp_unknown_data = -1;

static gint ett_msdp = -1;
static gint ett_msdp_sa_entry = -1;
static gint ett_msdp_sa_enc_data = -1;
static gint ett_msdp_not_data = -1;

static expert_field ei_msdp_tlv_len_too_short = EI_INIT;
static expert_field ei_msdp_tlv_len_too_long = EI_INIT;

static dissector_handle_t msdp_handle;
static dissector_handle_t ip_handle;


static void
dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
    int *offset, int length, proto_item *length_item);
static void
dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
    int *offset, guint16 tlv_len, proto_item *length_item);


static int
// NOLINTNEXTLINE(misc-no-recursion)
dissect_msdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
        proto_item *ti;
        proto_tree *msdp_tree;
        proto_item *length_item;
        int         offset;
        guint32     type;
        guint32     length;


        col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSDP");

        col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(tvb_get_guint8(tvb, 0),
                                                                     msdp_types,
                                                                     "<Unknown MSDP TLV type>"));

        ti = proto_tree_add_item(tree, proto_msdp, tvb, 0, -1, ENC_NA);
        msdp_tree = proto_item_add_subtree(ti, ett_msdp);

        offset = 0;
        increment_dissection_depth(pinfo);
        while (tvb_reported_length_remaining(tvb, offset) != 0) {
                proto_tree_add_item_ret_uint(msdp_tree, hf_msdp_type, tvb, offset, 1, ENC_BIG_ENDIAN, &type);
                length_item = proto_tree_add_item_ret_uint(msdp_tree, hf_msdp_length, tvb, offset + 1, 2, ENC_BIG_ENDIAN, &length);
                if (length < 3) {
                        expert_add_info_format(pinfo, length_item,
                            &ei_msdp_tlv_len_too_short,
                            "TLV length < 3");
                        break;
                }
                offset += 3;
                length -= 3;

                switch (type) {
                case MSDP_SA:
                        dissect_msdp_sa(tvb, pinfo, msdp_tree, &offset,
                                        length, length_item);
                        break;
                case MSDP_SA_REQ:
                        /*
                         * This type is mentioned in the RFC but the format
                         * isn't described.
                         */
                        if (length < 1) {
                                expert_add_info_format(pinfo, length_item,
                                    &ei_msdp_tlv_len_too_short,
                                    "TLV length for IPv4 Source-Active Request < 8");
                                break;
                        }
                        proto_tree_add_item(msdp_tree, hf_msdp_sa_req_res, tvb, offset, 1, ENC_BIG_ENDIAN);
                        offset += 1;
                        length -= 1;
                        if (length < 4) {
                                expert_add_info_format(pinfo, length_item,
                                    &ei_msdp_tlv_len_too_short,
                                    "TLV length for IPv4 Source-Active Request < 8");
                                offset += length;
                                break;
                        }
                        proto_tree_add_item(msdp_tree, hf_msdp_sa_req_group, tvb, offset, 4, ENC_BIG_ENDIAN);
                        offset += 4;
                        length -= 4;
                        if (length > 0) {
                                expert_add_info_format(pinfo, length_item,
                                    &ei_msdp_tlv_len_too_long,
                                    "TLV length for KeepAlive > 8");
                                proto_tree_add_item(tree, hf_msdp_trailing_junk, tvb, offset, length, ENC_NA);
                                offset += length;
                        }
                        break;
                case MSDP_SA_RSP:
                        /*
                         * This type is mentioned in the RFC but the format
                         * isn't described.
                         */
                        dissect_msdp_sa(tvb, pinfo, msdp_tree, &offset,
                                        length, length_item);
                        break;
                case MSDP_KEEP_ALIVE:
                        if (length > 0) {
                                expert_add_info_format(pinfo, length_item,
                                    &ei_msdp_tlv_len_too_long,
                                    "TLV length for KeepAlive > 3");
                                proto_tree_add_item(tree, hf_msdp_trailing_junk, tvb, offset, length, ENC_NA);
                                offset += length;
                        }
                        break;
                case MSDP_NOTIFICATION:
                        /*
                         * This was in draft 10, but is reserved in the
                         * RFC.
                         */
                        dissect_msdp_notification(tvb, pinfo, msdp_tree, &offset, length, length_item);
                        break;
                default:
                        if (length > 0)
                                proto_tree_add_item(msdp_tree, hf_msdp_tlv_contents, tvb, offset, length, ENC_NA);
                        offset += length;
                        break;
                }
        }
        decrement_dissection_depth(pinfo);

        return tvb_captured_length(tvb);
}

/* Both Source-Active and Source-Active Response have the same format
 * with one exception. Encapsulated multicast data is not allowed in
 * SA Response.
 */
static void dissect_msdp_sa(tvbuff_t *tvb, packet_info *pinfo,
    proto_tree *tree, int *offset, int length, proto_item *length_item)
{
        guint32 entries;

        if (length < 1) {
                expert_add_info_format(pinfo, length_item,
                    &ei_msdp_tlv_len_too_short,
                    "TLV length for IPv4 Source-Active or Source-Active Response < 5");
                return;
        }
        proto_tree_add_item_ret_uint(tree, hf_msdp_sa_entry_count, tvb, *offset, 1, ENC_BIG_ENDIAN, &entries);
        *offset += 1;
        length -= 1;

        if (length < 4) {
                expert_add_info_format(pinfo, length_item,
                    &ei_msdp_tlv_len_too_short,
                    "TLV length for IPv4 Source-Active or Source-Active Response < 5");
                *offset += length;
                return;
        }
        proto_tree_add_item(tree, hf_msdp_sa_rp_addr, tvb, *offset, 4, ENC_BIG_ENDIAN);
        *offset += 4;
        length -= 4;

        /* Put each of the (S,G) entries in their own subtree.
         * This is probably visually better.
         */
        while (entries-- > 0) {
                proto_tree *entry_tree;

                if (length < 12) {
                        expert_add_info_format(pinfo, length_item,
                            &ei_msdp_tlv_len_too_short,
                            "TLV length for IPv4 Source-Active or Source-Active Response too short");
                        *offset += length;
                        return;
                }
                entry_tree = proto_tree_add_subtree_format(tree, tvb, *offset, 12, ett_msdp_sa_entry, NULL,
                                         "(S,G) block: %s/%u -> %s",
                                         tvb_ip_to_str(pinfo->pool, tvb, *offset + 8),
                                         tvb_get_guint8(tvb, *offset + 3),
                                         tvb_ip_to_str(pinfo->pool, tvb, *offset + 4));

                proto_tree_add_item(entry_tree, hf_msdp_sa_reserved, tvb, *offset, 3, ENC_BIG_ENDIAN);
                *offset += 3;
                length -= 3;
                proto_tree_add_item(entry_tree, hf_msdp_sa_sprefix_len, tvb, *offset, 1, ENC_BIG_ENDIAN);
                *offset += 1;
                length -= 1;
                proto_tree_add_item(entry_tree, hf_msdp_sa_group_addr, tvb, *offset, 4, ENC_BIG_ENDIAN);
                *offset += 4;
                length -= 4;
                proto_tree_add_item(entry_tree, hf_msdp_sa_src_addr, tvb, *offset, 4, ENC_BIG_ENDIAN);
                *offset += 4;
                length -= 4;
        }

        /*
         * Check if an encapsulated multicast IPv4 packet follows
         */
        if (length > 0) {
                proto_tree *enc_tree;
                gint reported_length;
                tvbuff_t *next_tvb;

                enc_tree = proto_tree_add_subtree_format(tree, tvb, *offset, length,
                                         ett_msdp_sa_enc_data, NULL, "Encapsulated IPv4 packet: %u bytes",
                                         length);

                reported_length = tvb_reported_length_remaining(tvb, *offset);
                DISSECTOR_ASSERT(reported_length >= 0);
                if (reported_length > length)
                        reported_length = length;

                next_tvb = tvb_new_subset_length(tvb, *offset, reported_length);
                /* Set the protocol and information columns read-only so
                 * that they reflect the MSDP packet rather than the
                 * encapsulated packet.
                 */
                col_set_writable(pinfo->cinfo, COL_PROTOCOL, FALSE);
                col_set_writable(pinfo->cinfo, COL_INFO, FALSE);
                call_dissector(ip_handle, next_tvb, pinfo, enc_tree);
        }
        *offset += length;

        return;
}

/* Note: updates *offset */
static void add_notification_data_ipv4addr(tvbuff_t *tvb, proto_tree *tree, int *offset, int hf_addr)
{
        proto_tree_add_item(tree, hf_msdp_not_res, tvb, *offset, 3, ENC_BIG_ENDIAN);
        *offset += 3;
        proto_tree_add_item(tree, hf_addr, tvb, *offset, 4, ENC_BIG_ENDIAN);
        *offset += 4;

        return;
}

// NOLINTNEXTLINE(misc-no-recursion)
static void dissect_msdp_notification(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, guint16 tlv_len, proto_item *length_item)
{
        guint8              error, error_sub;
        const value_string *vals;
        gint reported_length;
        tvbuff_t *next_tvb;

        if (tlv_len < 1) {
                expert_add_info_format(pinfo, length_item,
                    &ei_msdp_tlv_len_too_short,
                    "TLV length for Notification < 4");
                return;
        }
        proto_tree_add_item(tree, hf_msdp_not_o, tvb, *offset, 1, ENC_BIG_ENDIAN);
        proto_tree_add_item(tree, hf_msdp_not_error, tvb, *offset, 1, ENC_BIG_ENDIAN);
        error = tvb_get_guint8(tvb, *offset);
        error &= 0x7F;             /* Error is 7-bit field. O-bit is bit 8 */
        *offset += 1;
        tlv_len -= 1;

        /* Depending on the Error Code, we collect the correct
         * value_strings for the Error subcode
         */
        switch (error) {
        case MESSAGE_HEADER_ERROR:
                vals = hdr_error_vals;
                break;
        case SA_REQUEST_ERROR:
                vals = sa_req_error_vals;
                break;
        case SA_MESSAGE_SA_RESPONSE_ERROR:
                vals = sa_msg_error_vals;
                break;
        case FSM_ERROR:
                vals = fsm_error_vals;
                break;
        case HOLD_TIMER_EXPIRED:
        case NOTIFICATION:
        case CEASE:
                vals = sa_unspec_error_vals;
                break;
        default:
                vals = sa_unspec_error_vals;
                break;
        }

        if (tlv_len < 1) {
                expert_add_info_format(pinfo, length_item,
                    &ei_msdp_tlv_len_too_short,
                    "TLV length for Notification < 5");
                return;
        }
        error_sub = tvb_get_guint8(tvb, *offset);
        proto_tree_add_uint_format_value(tree, hf_msdp_not_error_sub, tvb, *offset, 1,
                                   error_sub, "%s (%u)",
                                   val_to_str_const(error_sub, vals, "<Unknown Error subcode>"),
                                   error_sub);
        *offset += 1;
        tlv_len -= 1;

        /* Do switch again, this time to dissect the data portion
         * correctly. Ugly.
         */
        switch (error) {
        case SA_REQUEST_ERROR:
                if (tlv_len < 7) {
                        expert_add_info_format(pinfo, length_item,
                            &ei_msdp_tlv_len_too_short,
                            "TLV length for Notification SA-Request Error < 12");
                        *offset += tlv_len;
                        return;
                }
                add_notification_data_ipv4addr(tvb, tree, offset, hf_msdp_not_group_address);
                tlv_len -= 7;
                break;
        case SA_MESSAGE_SA_RESPONSE_ERROR:
                if (error_sub == 0) {
                        break;
                } else if (error_sub == 1) {
                        if (tlv_len < 1) {
                                expert_add_info_format(pinfo, length_item,
                                    &ei_msdp_tlv_len_too_short,
                                    "TLV length for Notification SA-Response Invalid Entry Count Error < 6");
                                return;
                        }
                        proto_tree_add_item(tree, hf_msdp_not_entry_count, tvb, *offset, 1, ENC_BIG_ENDIAN);
                        *offset += 1;
                        tlv_len -= 1;
                        break;
                } else if (error_sub == 2) {
                        if (tlv_len < 7) {
                                expert_add_info_format(pinfo, length_item,
                                    &ei_msdp_tlv_len_too_short,
                                    "TLV length for Notification SA-Response Invalid RP Address Error < 12");
                                *offset += tlv_len;
                                return;
                        }
                        add_notification_data_ipv4addr(tvb, tree, offset, hf_msdp_not_rp_address);
                        tlv_len -= 7;
                        break;
                } else if (error_sub == 3 || error_sub == 8) {
                        if (tlv_len < 7) {
                                expert_add_info_format(pinfo, length_item,
                                    &ei_msdp_tlv_len_too_short,
                                    "TLV length for Notification SA-Response %s Error < 12",
                                    (error_sub == 3) ? "Invalid Group Address"
                                                     : "Administrative Scope Boundary Violated");
                                *offset += tlv_len;
                                return;
                        }
                        add_notification_data_ipv4addr(tvb, tree, offset, hf_msdp_not_group_address);
                        tlv_len -= 7;
                        break;
                } else if (error_sub == 4) {
                        if (tlv_len < 7) {
                                expert_add_info_format(pinfo, length_item,
                                    &ei_msdp_tlv_len_too_short,
                                    "TLV length for Notification SA-Response Invalid Source Address Error < 12");
                                *offset += tlv_len;
                                return;
                        }
                        add_notification_data_ipv4addr(tvb, tree, offset, hf_msdp_not_source_address);
                        tlv_len -= 7;
                        break;
                } else if (error_sub == 5) {
                        if (tlv_len < 1) {
                                expert_add_info_format(pinfo, length_item,
                                    &ei_msdp_tlv_len_too_short,
                                    "TLV length for Notification SA-Response Invalid Sprefix Length Error < 6");
                                return;
                        }
                        proto_tree_add_item(tree, hf_msdp_not_sprefix_len, tvb, *offset, 1, ENC_BIG_ENDIAN);
                        *offset += 1;
                        tlv_len -= 1;
                        break;
                } else if (error_sub == 6) {
                        if (tlv_len > 0) {
                                reported_length = tvb_reported_length_remaining(tvb, *offset);
                                DISSECTOR_ASSERT(reported_length >= 0);
                                if (reported_length > tlv_len)
                                        reported_length = tlv_len;
                                next_tvb = tvb_new_subset_length(tvb, *offset, reported_length);
                                dissect_msdp(next_tvb, pinfo, tree, NULL);
                        }
                        *offset += tlv_len;
                        tlv_len = 0;
                } else if (error_sub == 7) {
                        if (tlv_len > 0) {
                                reported_length = tvb_reported_length_remaining(tvb, *offset);
                                DISSECTOR_ASSERT(reported_length >= 0);
                                if (reported_length > tlv_len)
                                        reported_length = tlv_len;
                                next_tvb = tvb_new_subset_length(tvb, *offset, reported_length);
                                dissect_msdp(next_tvb, pinfo, tree, NULL);
                        }
                        *offset += tlv_len;
                        tlv_len = 0;
                        break;
                } else {
                        if (tlv_len > 0)
                                proto_tree_add_item(tree, hf_msdp_unknown_data, tvb, *offset, tlv_len, ENC_NA);
                        *offset += tlv_len;
                        tlv_len = 0;
                        break;
                }
                break;
        case MESSAGE_HEADER_ERROR:
        case NOTIFICATION:
                /* Data contains the message that had an error. Even a
                 * broken Notification message causes a Notification
                 * message with Error Code set to Notification to be
                 * sent back.
                 */
                if (tlv_len > 0) {
                        reported_length = tvb_reported_length_remaining(tvb, *offset);
                        DISSECTOR_ASSERT(reported_length >= 0);
                        if (reported_length > tlv_len)
                                reported_length = tlv_len;
                        next_tvb = tvb_new_subset_length(tvb, *offset, reported_length);
                        dissect_msdp(next_tvb, pinfo, tree, NULL);
                }
                *offset += tlv_len;
                tlv_len = 0;
                break;
        case FSM_ERROR:
        case HOLD_TIMER_EXPIRED:
        case CEASE:
                /* Do nothing. These contain no data */
                break;
        default:
                if (tlv_len > 0)
                        proto_tree_add_item(tree, hf_msdp_unknown_data, tvb, *offset, tlv_len, ENC_NA);
                *offset += tlv_len;
                tlv_len = 0;
                break;
        }
        if (tlv_len != 0) {
                expert_add_info_format(pinfo, length_item,
                    &ei_msdp_tlv_len_too_long,
                    "TLV length too long");
                proto_tree_add_item(tree, hf_msdp_trailing_junk, tvb, *offset, tlv_len, ENC_NA);
                *offset += tlv_len;
        }

        return;
}

void
proto_register_msdp(void)
{
        static hf_register_info hf[] = {
                { &hf_msdp_type,
                        { "Type",           "msdp.type",
                        FT_UINT8, BASE_DEC, VALS(msdp_types), 0,
                        "MSDP TLV type", HFILL }
                },
                { &hf_msdp_length,
                        { "Length",           "msdp.length",
                        FT_UINT16, BASE_DEC, NULL, 0,
                        "MSDP TLV Length", HFILL }
                },
                { &hf_msdp_sa_entry_count,
                        { "Entry Count",           "msdp.sa.entry_count",
                        FT_UINT8, BASE_DEC, NULL, 0,
                        "MSDP SA Entry Count", HFILL }
                },
                { &hf_msdp_sa_rp_addr,
                        { "RP Address",           "msdp.sa.rp_addr",
                        FT_IPv4, BASE_NONE, NULL, 0,
                        "Active source's RP address", HFILL }
                },
                { &hf_msdp_sa_reserved,
                        { "Reserved",           "msdp.sa.reserved",
                        FT_UINT24, BASE_HEX, NULL, 0,
                        "Transmitted as zeros and ignored by a receiver", HFILL }
                },
                { &hf_msdp_sa_sprefix_len,
                        { "Sprefix len",           "msdp.sa.sprefix_len",
                        FT_UINT8, BASE_DEC, NULL, 0,
                        "The route prefix length associated with source address", HFILL }
                },
                { &hf_msdp_sa_group_addr,
                        { "Group Address",           "msdp.sa.group_addr",
                        FT_IPv4, BASE_NONE, NULL, 0,
                        "The group address the active source has sent data to", HFILL }
                },
                { &hf_msdp_sa_src_addr,
                        { "Source Address",           "msdp.sa.src_addr",
                        FT_IPv4, BASE_NONE, NULL, 0,
                        "The IP address of the active source", HFILL }
                },
                { &hf_msdp_sa_req_res,
                        { "Reserved",           "msdp.sa_req.res",
                        FT_UINT8, BASE_HEX, NULL, 0,
                        "Transmitted as zeros and ignored by a receiver", HFILL }
                },
                { &hf_msdp_sa_req_group,
                        { "Group Address",           "msdp.sa_req.group_addr",
                        FT_IPv4, BASE_NONE, NULL, 0,
                        "The group address the MSDP peer is requesting", HFILL }
                },
                { &hf_msdp_not_o,
                        { "Open-bit",           "msdp.not.o",
                        FT_UINT8, BASE_HEX, NULL, 0x80,
                        "If clear, the connection will be closed", HFILL }
                },
                { &hf_msdp_not_error,
                        { "Error Code",           "msdp.not.error",
                        FT_UINT8, BASE_DEC, VALS(error_vals), 0x7F,
                        "Indicates the type of Notification", HFILL }
                },
                { &hf_msdp_not_error_sub,
                        { "Error subcode",           "msdp.not.error_sub",
                        FT_UINT8, BASE_DEC, NULL, 0,
                        NULL, HFILL }
                },
                { &hf_msdp_not_group_address,
                        { "Group address",           "msdp.not.group_address",
                        FT_IPv4, BASE_NONE, NULL, 0,
                        "Group address in Notification messages", HFILL }
                },
                { &hf_msdp_not_rp_address,
                        { "RP address",           "msdp.not.rp_address",
                        FT_IPv4, BASE_NONE, NULL, 0,
                        "RP address in Notification messages", HFILL }
                },
                { &hf_msdp_not_source_address,
                        { "Source address",           "msdp.not.source_address",
                        FT_IPv4, BASE_NONE, NULL, 0,
                        "Source address in Notification messages", HFILL }
                },
                { &hf_msdp_not_res,
                        { "Reserved",           "msdp.not.res",
                        FT_UINT24, BASE_HEX, NULL, 0,
                        "Reserved field in Notification messages", HFILL }
                },
                { &hf_msdp_not_entry_count,
                        { "Entry Count",           "msdp.not.entry_count",
                        FT_UINT24, BASE_HEX, NULL, 0,
                        "Entry Count in Notification messages", HFILL }
                },
                { &hf_msdp_not_sprefix_len,
                        { "Sprefix len",           "msdp.not.sprefix_len",
                        FT_UINT8, BASE_DEC, NULL, 0,
                        "Source prefix length in Notification messages", HFILL }
                },
                { &hf_msdp_tlv_contents,
                        { "TLV contents",           "msdp.tlv_contents",
                        FT_BYTES, BASE_NONE, NULL, 0,
                        NULL, HFILL }
                },
                { &hf_msdp_trailing_junk,
                        { "Trailing junk",           "msdp.trailing_junk",
                        FT_BYTES, BASE_NONE, NULL, 0,
                        NULL, HFILL }
                },
                { &hf_msdp_unknown_data,
                        { "Unknown data",           "msdp.unknown_data",
                        FT_BYTES, BASE_NONE, NULL, 0,
                        NULL, HFILL }
                },
        };

        static gint *ett[] = {
                &ett_msdp,
                &ett_msdp_sa_entry,
                &ett_msdp_sa_enc_data,
                &ett_msdp_not_data,
        };

        static ei_register_info ei[] = {
                { &ei_msdp_tlv_len_too_long,
                    { "msdp.tlv_len.too_long", PI_PROTOCOL, PI_WARN,
                      "TLV length too long", EXPFILL }
                },
                { &ei_msdp_tlv_len_too_short,
                    { "msdp.tlv_len.too_short", PI_MALFORMED, PI_ERROR,
                      "TLV length too short", EXPFILL }
                },
        };

        expert_module_t *expert_msdp;

        proto_msdp = proto_register_protocol("Multicast Source Discovery Protocol",
            "MSDP", "msdp");
        msdp_handle = register_dissector("msdp", dissect_msdp, proto_msdp);

        proto_register_field_array(proto_msdp, hf, array_length(hf));
        proto_register_subtree_array(ett, array_length(ett));
        expert_msdp = expert_register_protocol(proto_msdp);
        expert_register_field_array(expert_msdp, ei, array_length(ei));
}

void
proto_reg_handoff_msdp(void)
{
        dissector_add_uint_with_preference("tcp.port", MSDP_PORT, msdp_handle);

        ip_handle = find_dissector_add_dependency("ip", proto_msdp);
}

/*
 * Editor modelines
 *
 * Local Variables:
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=8 tabstop=8 expandtab:
 * :indentSize=8:tabSize=8:noTabs=true:
 */