2 * Copyright (c) 1995, 1996
3 * The Regents of the University of California. All rights reserved.
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
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.
22 #include <sys/cdefs.h>
24 __RCSID("$NetBSD: print-dvmrp.c,v 1.4 2014/11/20 03:05:03 christos Exp $");
27 #define NETDISSECT_REWORKED
32 #include <tcpdump-stdinc.h>
34 #include "interface.h"
36 #include "addrtoname.h"
39 * DVMRP message types and flag values shamelessly stolen from
42 #define DVMRP_PROBE 1 /* for finding neighbors */
43 #define DVMRP_REPORT 2 /* for reporting some or all routes */
44 #define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */
45 /* of this router's neighbors */
46 #define DVMRP_NEIGHBORS 4 /* response to such a request */
47 #define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */
48 #define DVMRP_NEIGHBORS2 6
49 #define DVMRP_PRUNE 7 /* prune message */
50 #define DVMRP_GRAFT 8 /* graft message */
51 #define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */
54 * 'flags' byte values in DVMRP_NEIGHBORS2 reply.
56 #define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */
57 #define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */
58 #define DVMRP_NF_DOWN 0x10 /* kernel state of interface */
59 #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */
60 #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */
62 static int print_probe(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
63 static int print_report(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
64 static int print_neighbors(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
65 static int print_neighbors2(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
66 static int print_prune(netdissect_options
*, const u_char
*);
67 static int print_graft(netdissect_options
*, const u_char
*);
68 static int print_graft_ack(netdissect_options
*, const u_char
*);
70 static uint32_t target_level
;
73 dvmrp_print(netdissect_options
*ndo
,
74 register const u_char
*bp
, register u_int len
)
76 register const u_char
*ep
;
79 ep
= (const u_char
*)ndo
->ndo_snapend
;
86 /* Skip IGMP header */
93 ND_PRINT((ndo
, " Probe"));
95 if (print_probe(ndo
, bp
, ep
, len
) < 0)
101 ND_PRINT((ndo
, " Report"));
102 if (ndo
->ndo_vflag
> 1) {
103 if (print_report(ndo
, bp
, ep
, len
) < 0)
108 case DVMRP_ASK_NEIGHBORS
:
109 ND_PRINT((ndo
, " Ask-neighbors(old)"));
112 case DVMRP_NEIGHBORS
:
113 ND_PRINT((ndo
, " Neighbors(old)"));
114 if (print_neighbors(ndo
, bp
, ep
, len
) < 0)
118 case DVMRP_ASK_NEIGHBORS2
:
119 ND_PRINT((ndo
, " Ask-neighbors2"));
122 case DVMRP_NEIGHBORS2
:
123 ND_PRINT((ndo
, " Neighbors2"));
125 * extract version and capabilities from IGMP group
129 ND_TCHECK2(bp
[0], 4);
130 target_level
= (bp
[0] << 24) | (bp
[1] << 16) |
131 (bp
[2] << 8) | bp
[3];
133 if (print_neighbors2(ndo
, bp
, ep
, len
) < 0)
138 ND_PRINT((ndo
, " Prune"));
139 if (print_prune(ndo
, bp
) < 0)
144 ND_PRINT((ndo
, " Graft"));
145 if (print_graft(ndo
, bp
) < 0)
149 case DVMRP_GRAFT_ACK
:
150 ND_PRINT((ndo
, " Graft-ACK"));
151 if (print_graft_ack(ndo
, bp
) < 0)
156 ND_PRINT((ndo
, " [type %d]", type
));
162 ND_PRINT((ndo
, "[|dvmrp]"));
167 print_report(netdissect_options
*ndo
,
168 register const u_char
*bp
, register const u_char
*ep
,
171 register uint32_t mask
, origin
;
172 register int metric
, done
;
173 register u_int i
, width
;
177 ND_PRINT((ndo
, " [|]"));
180 ND_TCHECK2(bp
[0], 3);
181 mask
= (uint32_t)0xff << 24 | bp
[0] << 16 | bp
[1] << 8 | bp
[2];
190 ND_PRINT((ndo
, "\n\tMask %s", intoa(htonl(mask
))));
194 if (bp
+ width
+ 1 > ep
) {
195 ND_PRINT((ndo
, " [|]"));
198 if (len
< width
+ 1) {
199 ND_PRINT((ndo
, "\n\t [Truncated Report]"));
203 for (i
= 0; i
< width
; ++i
) {
205 origin
= origin
<< 8 | *bp
++;
212 done
= metric
& 0x80;
214 ND_PRINT((ndo
, "\n\t %s metric %d", intoa(htonl(origin
)),
225 print_probe(netdissect_options
*ndo
,
226 register const u_char
*bp
, register const u_char
*ep
,
229 register uint32_t genid
;
231 ND_TCHECK2(bp
[0], 4);
232 if ((len
< 4) || ((bp
+ 4) > ep
)) {
234 ND_PRINT((ndo
, " [|}"));
237 genid
= (bp
[0] << 24) | (bp
[1] << 16) | (bp
[2] << 8) | bp
[3];
240 ND_PRINT((ndo
, ndo
->ndo_vflag
> 1 ? "\n\t" : " "));
241 ND_PRINT((ndo
, "genid %u", genid
));
242 if (ndo
->ndo_vflag
< 2)
245 while ((len
> 0) && (bp
< ep
)) {
246 ND_TCHECK2(bp
[0], 4);
247 ND_PRINT((ndo
, "\n\tneighbor %s", ipaddr_string(ndo
, bp
)));
256 print_neighbors(netdissect_options
*ndo
,
257 register const u_char
*bp
, register const u_char
*ep
,
261 register u_char metric
;
262 register u_char thresh
;
265 while (len
> 0 && bp
< ep
) {
266 ND_TCHECK2(bp
[0], 7);
273 while (--ncount
>= 0) {
274 ND_TCHECK2(bp
[0], 4);
275 ND_PRINT((ndo
, " [%s ->", ipaddr_string(ndo
, laddr
)));
276 ND_PRINT((ndo
, " %s, (%d/%d)]",
277 ipaddr_string(ndo
, bp
), metric
, thresh
));
288 print_neighbors2(netdissect_options
*ndo
,
289 register const u_char
*bp
, register const u_char
*ep
,
293 register u_char metric
, thresh
, flags
;
296 ND_PRINT((ndo
, " (v %d.%d):",
297 (int)target_level
& 0xff,
298 (int)(target_level
>> 8) & 0xff));
300 while (len
> 0 && bp
< ep
) {
301 ND_TCHECK2(bp
[0], 8);
309 while (--ncount
>= 0 && (len
>= 4) && (bp
+ 4) <= ep
) {
310 ND_PRINT((ndo
, " [%s -> ", ipaddr_string(ndo
, laddr
)));
311 ND_PRINT((ndo
, "%s (%d/%d", ipaddr_string(ndo
, bp
),
313 if (flags
& DVMRP_NF_TUNNEL
)
314 ND_PRINT((ndo
, "/tunnel"));
315 if (flags
& DVMRP_NF_SRCRT
)
316 ND_PRINT((ndo
, "/srcrt"));
317 if (flags
& DVMRP_NF_QUERIER
)
318 ND_PRINT((ndo
, "/querier"));
319 if (flags
& DVMRP_NF_DISABLED
)
320 ND_PRINT((ndo
, "/disabled"));
321 if (flags
& DVMRP_NF_DOWN
)
322 ND_PRINT((ndo
, "/down"));
323 ND_PRINT((ndo
, ")]"));
328 ND_PRINT((ndo
, " [|]"));
338 print_prune(netdissect_options
*ndo
,
339 register const u_char
*bp
)
341 ND_TCHECK2(bp
[0], 12);
342 ND_PRINT((ndo
, " src %s grp %s", ipaddr_string(ndo
, bp
), ipaddr_string(ndo
, bp
+ 4)));
344 ND_PRINT((ndo
, " timer "));
345 relts_print(ndo
, EXTRACT_32BITS(bp
));
352 print_graft(netdissect_options
*ndo
,
353 register const u_char
*bp
)
355 ND_TCHECK2(bp
[0], 8);
356 ND_PRINT((ndo
, " src %s grp %s", ipaddr_string(ndo
, bp
), ipaddr_string(ndo
, bp
+ 4)));
363 print_graft_ack(netdissect_options
*ndo
,
364 register const u_char
*bp
)
366 ND_TCHECK2(bp
[0], 8);
367 ND_PRINT((ndo
, " src %s grp %s", ipaddr_string(ndo
, bp
), ipaddr_string(ndo
, bp
+ 4)));