]> The Tcpdump Group git mirrors - tcpdump/blob - print-dvmrp.c
don't pass on src & dst MAC adresses to the isoclns decoder as MAC adresses
[tcpdump] / print-dvmrp.c
1 /*
2 * Copyright (c) 1995, 1996
3 * The Regents of the University of California. 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 distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.24 2002-09-05 21:25:40 guy Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <tcpdump-stdinc.h>
32
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdlib.h>
36
37 #include "interface.h"
38 #include "extract.h"
39 #include "addrtoname.h"
40
41 /*
42 * DVMRP message types and flag values shamelessly stolen from
43 * mrouted/dvmrp.h.
44 */
45 #define DVMRP_PROBE 1 /* for finding neighbors */
46 #define DVMRP_REPORT 2 /* for reporting some or all routes */
47 #define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */
48 /* of this router's neighbors */
49 #define DVMRP_NEIGHBORS 4 /* response to such a request */
50 #define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */
51 #define DVMRP_NEIGHBORS2 6
52 #define DVMRP_PRUNE 7 /* prune message */
53 #define DVMRP_GRAFT 8 /* graft message */
54 #define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */
55
56 /*
57 * 'flags' byte values in DVMRP_NEIGHBORS2 reply.
58 */
59 #define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */
60 #define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */
61 #define DVMRP_NF_DOWN 0x10 /* kernel state of interface */
62 #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */
63 #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */
64
65 static void print_probe(const u_char *, const u_char *, u_int);
66 static void print_report(const u_char *, const u_char *, u_int);
67 static void print_neighbors(const u_char *, const u_char *, u_int);
68 static void print_neighbors2(const u_char *, const u_char *, u_int);
69 static void print_prune(const u_char *);
70 static void print_graft(const u_char *);
71 static void print_graft_ack(const u_char *);
72
73 static u_int32_t target_level;
74
75 void
76 dvmrp_print(register const u_char *bp, register u_int len)
77 {
78 register const u_char *ep;
79 register u_char type;
80
81 ep = (const u_char *)snapend;
82 if (bp >= ep)
83 return;
84
85 type = bp[1];
86
87 /* Skip IGMP header */
88 bp += 8;
89 len -= 8;
90
91 switch (type) {
92
93 case DVMRP_PROBE:
94 printf(" Probe");
95 if (vflag)
96 print_probe(bp, ep, len);
97 break;
98
99 case DVMRP_REPORT:
100 printf(" Report");
101 if (vflag > 1)
102 print_report(bp, ep, len);
103 break;
104
105 case DVMRP_ASK_NEIGHBORS:
106 printf(" Ask-neighbors(old)");
107 break;
108
109 case DVMRP_NEIGHBORS:
110 printf(" Neighbors(old)");
111 print_neighbors(bp, ep, len);
112 break;
113
114 case DVMRP_ASK_NEIGHBORS2:
115 printf(" Ask-neighbors2");
116 break;
117
118 case DVMRP_NEIGHBORS2:
119 printf(" Neighbors2");
120 /*
121 * extract version and capabilities from IGMP group
122 * address field
123 */
124 bp -= 4;
125 target_level = (bp[0] << 24) | (bp[1] << 16) |
126 (bp[2] << 8) | bp[3];
127 bp += 4;
128 print_neighbors2(bp, ep, len);
129 break;
130
131 case DVMRP_PRUNE:
132 printf(" Prune");
133 print_prune(bp);
134 break;
135
136 case DVMRP_GRAFT:
137 printf(" Graft");
138 print_graft(bp);
139 break;
140
141 case DVMRP_GRAFT_ACK:
142 printf(" Graft-ACK");
143 print_graft_ack(bp);
144 break;
145
146 default:
147 printf(" [type %d]", type);
148 break;
149 }
150 }
151
152 static void
153 print_report(register const u_char *bp, register const u_char *ep,
154 register u_int len)
155 {
156 register u_int32_t mask, origin;
157 register int metric, done;
158 register u_int i, width;
159
160 while (len > 0) {
161 if (len < 3) {
162 printf(" [|]");
163 return;
164 }
165 mask = (u_int32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2];
166 width = 1;
167 if (bp[0])
168 width = 2;
169 if (bp[1])
170 width = 3;
171 if (bp[2])
172 width = 4;
173
174 printf("\n\tMask %s", intoa(htonl(mask)));
175 bp += 3;
176 len -= 3;
177 do {
178 if (bp + width + 1 > ep) {
179 printf(" [|]");
180 return;
181 }
182 if (len < width + 1) {
183 printf("\n\t [Truncated Report]");
184 return;
185 }
186 origin = 0;
187 for (i = 0; i < width; ++i)
188 origin = origin << 8 | *bp++;
189 for ( ; i < 4; ++i)
190 origin <<= 8;
191
192 metric = *bp++;
193 done = metric & 0x80;
194 metric &= 0x7f;
195 printf("\n\t %s metric %d", intoa(htonl(origin)),
196 metric);
197 len -= width + 1;
198 } while (!done);
199 }
200 }
201
202 static void
203 print_probe(register const u_char *bp, register const u_char *ep,
204 register u_int len)
205 {
206 register u_int32_t genid;
207
208 TCHECK2(bp[0], 4);
209 if ((len < 4) || ((bp + 4) > ep)) {
210 /* { (ctags) */
211 printf(" [|}");
212 return;
213 }
214 genid = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3];
215 bp += 4;
216 len -= 4;
217 if (vflag > 1)
218 printf("\n\t");
219 else
220 printf(" ");
221 printf("genid %u", genid);
222 if (vflag < 2)
223 return;
224
225 while ((len > 0) && (bp < ep)) {
226 TCHECK2(bp[0], 4);
227 printf("\n\tneighbor %s", ipaddr_string(bp));
228 bp += 4; len -= 4;
229 }
230 return;
231 trunc:
232 (void)printf("[|dvmrp]");
233 }
234
235 static void
236 print_neighbors(register const u_char *bp, register const u_char *ep,
237 register u_int len)
238 {
239 const u_char *laddr;
240 register u_char metric;
241 register u_char thresh;
242 register int ncount;
243
244 while (len > 0 && bp < ep) {
245 TCHECK2(bp[0], 7);
246 laddr = bp;
247 bp += 4;
248 metric = *bp++;
249 thresh = *bp++;
250 ncount = *bp++;
251 len -= 7;
252 while (--ncount >= 0) {
253 TCHECK2(bp[0], 4);
254 printf(" [%s ->", ipaddr_string(laddr));
255 printf(" %s, (%d/%d)]",
256 ipaddr_string(bp), metric, thresh);
257 bp += 4;
258 len -= 4;
259 }
260 }
261 return;
262 trunc:
263 (void)printf("[|dvmrp]");
264 }
265
266 static void
267 print_neighbors2(register const u_char *bp, register const u_char *ep,
268 register u_int len)
269 {
270 const u_char *laddr;
271 register u_char metric, thresh, flags;
272 register int ncount;
273
274 printf(" (v %d.%d):",
275 (int)target_level & 0xff,
276 (int)(target_level >> 8) & 0xff);
277
278 while (len > 0 && bp < ep) {
279 TCHECK2(bp[0], 8);
280 laddr = bp;
281 bp += 4;
282 metric = *bp++;
283 thresh = *bp++;
284 flags = *bp++;
285 ncount = *bp++;
286 len -= 8;
287 while (--ncount >= 0 && (len >= 4) && (bp + 4) <= ep) {
288 printf(" [%s -> ", ipaddr_string(laddr));
289 printf("%s (%d/%d", ipaddr_string(bp),
290 metric, thresh);
291 if (flags & DVMRP_NF_TUNNEL)
292 printf("/tunnel");
293 if (flags & DVMRP_NF_SRCRT)
294 printf("/srcrt");
295 if (flags & DVMRP_NF_QUERIER)
296 printf("/querier");
297 if (flags & DVMRP_NF_DISABLED)
298 printf("/disabled");
299 if (flags & DVMRP_NF_DOWN)
300 printf("/down");
301 printf(")]");
302 bp += 4;
303 len -= 4;
304 }
305 if (ncount != -1) {
306 printf(" [|]");
307 return;
308 }
309 }
310 return;
311 trunc:
312 (void)printf("[|dvmrp]");
313 }
314
315 static void
316 print_prune(register const u_char *bp)
317 {
318 TCHECK2(bp[0], 12);
319 printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
320 bp += 8;
321 (void)printf(" timer ");
322 relts_print(EXTRACT_32BITS(bp));
323 return;
324 trunc:
325 (void)printf("[|dvmrp]");
326 }
327
328 static void
329 print_graft(register const u_char *bp)
330 {
331 TCHECK2(bp[0], 8);
332 printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
333 return;
334 trunc:
335 (void)printf("[|dvmrp]");
336 }
337
338 static void
339 print_graft_ack(register const u_char *bp)
340 {
341 TCHECK2(bp[0], 8);
342 printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4));
343 return;
344 trunc:
345 (void)printf("[|dvmrp]");
346 }