4 * Copyright (c) 1995, 1996
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include <sys/cdefs.h>
27 static const char rcsid
[] _U_
=
28 "@(#) Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.27 2003/11/19 09:42:04 guy Exp (LBL)";
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
38 #include <tcpdump-stdinc.h>
44 #include "interface.h"
46 #include "addrtoname.h"
49 * DVMRP message types and flag values shamelessly stolen from
52 #define DVMRP_PROBE 1 /* for finding neighbors */
53 #define DVMRP_REPORT 2 /* for reporting some or all routes */
54 #define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */
55 /* of this router's neighbors */
56 #define DVMRP_NEIGHBORS 4 /* response to such a request */
57 #define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */
58 #define DVMRP_NEIGHBORS2 6
59 #define DVMRP_PRUNE 7 /* prune message */
60 #define DVMRP_GRAFT 8 /* graft message */
61 #define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */
64 * 'flags' byte values in DVMRP_NEIGHBORS2 reply.
66 #define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */
67 #define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */
68 #define DVMRP_NF_DOWN 0x10 /* kernel state of interface */
69 #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */
70 #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */
72 static int print_probe(const u_char
*, const u_char
*, u_int
);
73 static int print_report(const u_char
*, const u_char
*, u_int
);
74 static int print_neighbors(const u_char
*, const u_char
*, u_int
);
75 static int print_neighbors2(const u_char
*, const u_char
*, u_int
);
76 static int print_prune(const u_char
*);
77 static int print_graft(const u_char
*);
78 static int print_graft_ack(const u_char
*);
80 static u_int32_t target_level
;
83 dvmrp_print(register const u_char
*bp
, register u_int len
)
85 register const u_char
*ep
;
88 ep
= (const u_char
*)snapend
;
95 /* Skip IGMP header */
104 if (print_probe(bp
, ep
, len
) < 0)
112 if (print_report(bp
, ep
, len
) < 0)
117 case DVMRP_ASK_NEIGHBORS
:
118 printf(" Ask-neighbors(old)");
121 case DVMRP_NEIGHBORS
:
122 printf(" Neighbors(old)");
123 if (print_neighbors(bp
, ep
, len
) < 0)
127 case DVMRP_ASK_NEIGHBORS2
:
128 printf(" Ask-neighbors2");
131 case DVMRP_NEIGHBORS2
:
132 printf(" Neighbors2");
134 * extract version and capabilities from IGMP group
139 target_level
= (bp
[0] << 24) | (bp
[1] << 16) |
140 (bp
[2] << 8) | bp
[3];
142 if (print_neighbors2(bp
, ep
, len
) < 0)
148 if (print_prune(bp
) < 0)
154 if (print_graft(bp
) < 0)
158 case DVMRP_GRAFT_ACK
:
159 printf(" Graft-ACK");
160 if (print_graft_ack(bp
) < 0)
165 printf(" [type %d]", type
);
176 print_report(register const u_char
*bp
, register const u_char
*ep
,
179 register u_int32_t mask
, origin
;
180 register int metric
, done
;
181 register u_int i
, width
;
189 mask
= (u_int32_t
)0xff << 24 | bp
[0] << 16 | bp
[1] << 8 | bp
[2];
198 printf("\n\tMask %s", intoa(htonl(mask
)));
202 if (bp
+ width
+ 1 > ep
) {
206 if (len
< width
+ 1) {
207 printf("\n\t [Truncated Report]");
211 for (i
= 0; i
< width
; ++i
) {
213 origin
= origin
<< 8 | *bp
++;
220 done
= metric
& 0x80;
222 printf("\n\t %s metric %d", intoa(htonl(origin
)),
233 print_probe(register const u_char
*bp
, register const u_char
*ep
,
236 register u_int32_t genid
;
239 if ((len
< 4) || ((bp
+ 4) > ep
)) {
244 genid
= (bp
[0] << 24) | (bp
[1] << 16) | (bp
[2] << 8) | bp
[3];
251 printf("genid %u", genid
);
255 while ((len
> 0) && (bp
< ep
)) {
257 printf("\n\tneighbor %s", ipaddr_string(bp
));
266 print_neighbors(register const u_char
*bp
, register const u_char
*ep
,
270 register u_char metric
;
271 register u_char thresh
;
274 while (len
> 0 && bp
< ep
) {
282 while (--ncount
>= 0) {
284 printf(" [%s ->", ipaddr_string(laddr
));
285 printf(" %s, (%d/%d)]",
286 ipaddr_string(bp
), metric
, thresh
);
297 print_neighbors2(register const u_char
*bp
, register const u_char
*ep
,
301 register u_char metric
, thresh
, flags
;
304 printf(" (v %d.%d):",
305 (int)target_level
& 0xff,
306 (int)(target_level
>> 8) & 0xff);
308 while (len
> 0 && bp
< ep
) {
317 while (--ncount
>= 0 && (len
>= 4) && (bp
+ 4) <= ep
) {
318 printf(" [%s -> ", ipaddr_string(laddr
));
319 printf("%s (%d/%d", ipaddr_string(bp
),
321 if (flags
& DVMRP_NF_TUNNEL
)
323 if (flags
& DVMRP_NF_SRCRT
)
325 if (flags
& DVMRP_NF_QUERIER
)
327 if (flags
& DVMRP_NF_DISABLED
)
329 if (flags
& DVMRP_NF_DOWN
)
346 print_prune(register const u_char
*bp
)
349 printf(" src %s grp %s", ipaddr_string(bp
), ipaddr_string(bp
+ 4));
351 (void)printf(" timer ");
352 relts_print(EXTRACT_32BITS(bp
));
359 print_graft(register const u_char
*bp
)
362 printf(" src %s grp %s", ipaddr_string(bp
), ipaddr_string(bp
+ 4));
369 print_graft_ack(register const u_char
*bp
)
372 printf(" src %s grp %s", ipaddr_string(bp
), ipaddr_string(bp
+ 4));