blob: 50bafb0ae090bf60a5d95587abe24bf51437eab5 [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (c) 2001 William C. Fenner.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code
7 * distributions retain the above copyright notice and this paragraph
8 * in its entirety, and (2) distributions including binary code include
9 * the above copyright notice and this paragraph in its entirety in
10 * the documentation or other materials provided with the distribution.
11 * The name of William C. Fenner may not be used to endorse or
12 * promote products derived from this software without specific prior
13 * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
15 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16 * FOR A PARTICULAR PURPOSE.
17 */
The Android Open Source Project2949f582009-03-03 19:30:46 -080018
Elliott Hughese2e3bd12017-05-15 10:59:29 -070019/* \summary: Multicast Source Discovery Protocol (MSDP) printer */
20
The Android Open Source Project2949f582009-03-03 19:30:46 -080021#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
Elliott Hughese2e3bd12017-05-15 10:59:29 -070025#include <netdissect-stdinc.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080026
Elliott Hughese2e3bd12017-05-15 10:59:29 -070027#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080028#include "addrtoname.h"
29#include "extract.h"
30
31#define MSDP_TYPE_MAX 7
32
33void
Elliott Hughes892a68b2015-10-19 14:43:53 -070034msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -080035{
36 unsigned int type, len;
37
Elliott Hughes892a68b2015-10-19 14:43:53 -070038 ND_TCHECK2(*sp, 3);
The Android Open Source Project2949f582009-03-03 19:30:46 -080039 /* See if we think we're at the beginning of a compound packet */
40 type = *sp;
41 len = EXTRACT_16BITS(sp + 1);
42 if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
43 goto trunc; /* not really truncated, but still not decodable */
Elliott Hughes892a68b2015-10-19 14:43:53 -070044 ND_PRINT((ndo, " msdp:"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080045 while (length > 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -070046 ND_TCHECK2(*sp, 3);
The Android Open Source Project2949f582009-03-03 19:30:46 -080047 type = *sp;
48 len = EXTRACT_16BITS(sp + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -070049 if (len > 1400 || ndo->ndo_vflag)
50 ND_PRINT((ndo, " [len %u]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -080051 if (len < 3)
52 goto trunc;
53 sp += 3;
54 length -= 3;
55 switch (type) {
56 case 1: /* IPv4 Source-Active */
57 case 3: /* IPv4 Source-Active Response */
58 if (type == 1)
Elliott Hughes892a68b2015-10-19 14:43:53 -070059 ND_PRINT((ndo, " SA"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080060 else
Elliott Hughes892a68b2015-10-19 14:43:53 -070061 ND_PRINT((ndo, " SA-Response"));
62 ND_TCHECK(*sp);
63 ND_PRINT((ndo, " %u entries", *sp));
The Android Open Source Project2949f582009-03-03 19:30:46 -080064 if ((u_int)((*sp * 12) + 8) < len) {
Elliott Hughes892a68b2015-10-19 14:43:53 -070065 ND_PRINT((ndo, " [w/data]"));
66 if (ndo->ndo_vflag > 1) {
67 ND_PRINT((ndo, " "));
68 ip_print(ndo, sp + *sp * 12 + 8 - 3,
The Android Open Source Project2949f582009-03-03 19:30:46 -080069 len - (*sp * 12 + 8));
70 }
71 }
72 break;
73 case 2:
Elliott Hughes892a68b2015-10-19 14:43:53 -070074 ND_PRINT((ndo, " SA-Request"));
75 ND_TCHECK2(*sp, 5);
76 ND_PRINT((ndo, " for %s", ipaddr_string(ndo, sp + 1)));
The Android Open Source Project2949f582009-03-03 19:30:46 -080077 break;
78 case 4:
Elliott Hughes892a68b2015-10-19 14:43:53 -070079 ND_PRINT((ndo, " Keepalive"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080080 if (len != 3)
Elliott Hughes892a68b2015-10-19 14:43:53 -070081 ND_PRINT((ndo, "[len=%d] ", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -080082 break;
83 case 5:
Elliott Hughes892a68b2015-10-19 14:43:53 -070084 ND_PRINT((ndo, " Notification"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080085 break;
86 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -070087 ND_PRINT((ndo, " [type=%d len=%d]", type, len));
The Android Open Source Project2949f582009-03-03 19:30:46 -080088 break;
89 }
90 sp += (len - 3);
91 length -= (len - 3);
92 }
93 return;
94trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -070095 ND_PRINT((ndo, " [|msdp]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -080096}
97
98/*
99 * Local Variables:
100 * c-style: whitesmith
101 * c-basic-offset: 8
102 * End:
103 */