]> The Tcpdump Group git mirrors - tcpdump/blob - print-msdp.c
CMake: Fix the comment about versions. [skip ci]
[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 #define ND_LONGJMP_FROM_TCHECK
24 #include "netdissect-stdinc.h"
25
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 if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
44 goto trunc; /* not really truncated, but still not decodable */
45 while (length != 0) {
46 unsigned int entry_count;
47
48 if (length < 3)
49 goto trunc;
50 type = GET_U_1(sp);
51 len = GET_BE_U_2(sp + 1);
52 if (len > 1400 || ndo->ndo_vflag)
53 ND_PRINT(" [len %u]", len);
54 if (len < 3)
55 goto trunc;
56 if (length < len)
57 goto trunc;
58 switch (type) {
59 case 1: /* IPv4 Source-Active */
60 case 3: /* IPv4 Source-Active Response */
61 if (type == 1)
62 ND_PRINT(" SA");
63 else
64 ND_PRINT(" SA-Response");
65
66 /* Entry Count */
67 if (len < 4)
68 goto trunc;
69 entry_count = GET_U_1(sp + 3);
70 ND_PRINT(" %u entries", entry_count);
71
72 /* RP Address */
73 if (len < 8)
74 goto trunc;
75 /* XXX -print this based on ndo_vflag? */
76 ND_TCHECK_LEN(sp + 4, 4);
77
78 /* Entries */
79 ND_TCHECK_LEN(sp + 8, entry_count*12);
80
81 if (len > (8 + entry_count*12)) {
82 /* Encapsulated IP packet */
83 ND_PRINT(" [w/data]");
84 if (ndo->ndo_vflag > 1) {
85 ND_PRINT(" ");
86 ip_print(ndo, sp + (8 + entry_count*12),
87 len - (8 + entry_count*12));
88 }
89 }
90 break;
91 case 2:
92 /* draft-ietf-msdp-spec-13 */
93 ND_PRINT(" SA-Request");
94
95 /* Reserved */
96 if (len < 4)
97 goto trunc;
98 ND_TCHECK_1(sp + 3);
99
100 /* Group Address */
101 if (len < 8)
102 goto trunc;
103 if (len != 8)
104 ND_PRINT("[len=%u] ", len);
105 ND_PRINT(" for %s", GET_IPADDR_STRING(sp + 4));
106 break;
107 case 4:
108 ND_PRINT(" Keepalive");
109 if (len != 3)
110 ND_PRINT("[len=%u] ", len);
111 break;
112 case 5:
113 ND_PRINT(" Notification");
114 break;
115 default:
116 ND_PRINT(" [type=%u len=%u]", type, len);
117 break;
118 }
119 ND_TCHECK_LEN(sp, len);
120 sp += len;
121 length -= len;
122 }
123 return;
124 trunc:
125 nd_print_trunc(ndo);
126 }