]> The Tcpdump Group git mirrors - tcpdump/blob - print-msdp.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-msdp.c
1 /*
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 */
18
19 /* \summary: Multicast Source Discovery Protocol (MSDP) printer */
20
21 #include <config.h>
22
23 #include "netdissect-stdinc.h"
24
25 #define ND_LONGJMP_FROM_TCHECK
26 #include "netdissect.h"
27 #include "addrtoname.h"
28 #include "extract.h"
29
30 #define MSDP_TYPE_MAX 7
31
32 void
33 msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
34 {
35 unsigned int type, len;
36
37 ndo->ndo_protocol = "msdp";
38 ND_PRINT(": ");
39 nd_print_protocol(ndo);
40 /* See if we think we're at the beginning of a compound packet */
41 type = GET_U_1(sp);
42 len = GET_BE_U_2(sp + 1);
43 ND_ICHECK_U(len, >, 1500);
44 ND_ICHECK_U(len, <, 3);
45 ND_ICHECK_U(type, ==, 0);
46 ND_ICHECK_U(type, >, MSDP_TYPE_MAX);
47 while (length != 0) {
48 unsigned int entry_count;
49
50 ND_ICHECK_U(length, <, 3);
51 type = GET_U_1(sp);
52 len = GET_BE_U_2(sp + 1);
53 if (len > 1400 || ndo->ndo_vflag)
54 ND_PRINT(" [len %u]", len);
55 ND_ICHECK_U(len, <, 3);
56 ND_ICHECK_U(length, <, len);
57 switch (type) {
58 case 1: /* IPv4 Source-Active */
59 case 3: /* IPv4 Source-Active Response */
60 if (type == 1)
61 ND_PRINT(" SA");
62 else
63 ND_PRINT(" SA-Response");
64
65 /* Entry Count */
66 ND_ICHECK_U(len, <, 4);
67 entry_count = GET_U_1(sp + 3);
68 ND_PRINT(" %u entries", entry_count);
69
70 /* RP Address */
71 ND_ICHECK_U(len, <, 8);
72 /* XXX -print this based on ndo_vflag? */
73 ND_TCHECK_4(sp + 4);
74
75 /* Entries */
76 ND_TCHECK_LEN(sp + 8, entry_count*12);
77
78 if (len > (8 + entry_count*12)) {
79 /* Encapsulated IP packet */
80 ND_PRINT(" [w/data]");
81 if (ndo->ndo_vflag > 1) {
82 ND_PRINT(" ");
83 ip_print(ndo, sp + (8 + entry_count*12),
84 len - (8 + entry_count*12));
85 }
86 }
87 break;
88 case 2:
89 /* draft-ietf-msdp-spec-13 */
90 ND_PRINT(" SA-Request");
91
92 /* Reserved */
93 ND_ICHECK_U(len, <, 4);
94 ND_TCHECK_1(sp + 3);
95
96 /* Group Address */
97 ND_ICHECK_U(len, <, 8);
98 if (len != 8)
99 ND_PRINT("[len=%u] ", len);
100 ND_PRINT(" for %s", GET_IPADDR_STRING(sp + 4));
101 break;
102 case 4:
103 ND_PRINT(" Keepalive");
104 if (len != 3)
105 ND_PRINT("[len=%u] ", len);
106 break;
107 case 5:
108 ND_PRINT(" Notification");
109 break;
110 default:
111 ND_PRINT(" [type=%u len=%u]", type, len);
112 break;
113 }
114 ND_TCHECK_LEN(sp, len);
115 sp += len;
116 length -= len;
117 }
118 return;
119
120 invalid:
121 nd_print_invalid(ndo);
122
123 }