]>
The Tcpdump Group git mirrors - tcpdump/blob - print-dvmrp.c
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.
26 #include <tcpdump-stdinc.h>
28 #include "netdissect.h"
30 #include "addrtoname.h"
33 * DVMRP message types and flag values shamelessly stolen from
36 #define DVMRP_PROBE 1 /* for finding neighbors */
37 #define DVMRP_REPORT 2 /* for reporting some or all routes */
38 #define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */
39 /* of this router's neighbors */
40 #define DVMRP_NEIGHBORS 4 /* response to such a request */
41 #define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */
42 #define DVMRP_NEIGHBORS2 6
43 #define DVMRP_PRUNE 7 /* prune message */
44 #define DVMRP_GRAFT 8 /* graft message */
45 #define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */
48 * 'flags' byte values in DVMRP_NEIGHBORS2 reply.
50 #define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */
51 #define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */
52 #define DVMRP_NF_DOWN 0x10 /* kernel state of interface */
53 #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */
54 #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */
56 static int print_probe(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
57 static int print_report(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
58 static int print_neighbors(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
59 static int print_neighbors2(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
60 static int print_prune(netdissect_options
*, const u_char
*);
61 static int print_graft(netdissect_options
*, const u_char
*);
62 static int print_graft_ack(netdissect_options
*, const u_char
*);
64 static uint32_t target_level
;
67 dvmrp_print(netdissect_options
*ndo
,
68 register const u_char
*bp
, register u_int len
)
70 register const u_char
*ep
;
73 ep
= (const u_char
*)ndo
->ndo_snapend
;
80 /* Skip IGMP header */
87 ND_PRINT((ndo
, " Probe"));
89 if (print_probe(ndo
, bp
, ep
, len
) < 0)
95 ND_PRINT((ndo
, " Report"));
96 if (ndo
->ndo_vflag
> 1) {
97 if (print_report(ndo
, bp
, ep
, len
) < 0)
102 case DVMRP_ASK_NEIGHBORS
:
103 ND_PRINT((ndo
, " Ask-neighbors(old)"));
106 case DVMRP_NEIGHBORS
:
107 ND_PRINT((ndo
, " Neighbors(old)"));
108 if (print_neighbors(ndo
, bp
, ep
, len
) < 0)
112 case DVMRP_ASK_NEIGHBORS2
:
113 ND_PRINT((ndo
, " Ask-neighbors2"));
116 case DVMRP_NEIGHBORS2
:
117 ND_PRINT((ndo
, " Neighbors2"));
119 * extract version and capabilities from IGMP group
123 ND_TCHECK2(bp
[0], 4);
124 target_level
= (bp
[0] << 24) | (bp
[1] << 16) |
125 (bp
[2] << 8) | bp
[3];
127 if (print_neighbors2(ndo
, bp
, ep
, len
) < 0)
132 ND_PRINT((ndo
, " Prune"));
133 if (print_prune(ndo
, bp
) < 0)
138 ND_PRINT((ndo
, " Graft"));
139 if (print_graft(ndo
, bp
) < 0)
143 case DVMRP_GRAFT_ACK
:
144 ND_PRINT((ndo
, " Graft-ACK"));
145 if (print_graft_ack(ndo
, bp
) < 0)
150 ND_PRINT((ndo
, " [type %d]", type
));
156 ND_PRINT((ndo
, "[|dvmrp]"));
161 print_report(netdissect_options
*ndo
,
162 register const u_char
*bp
, register const u_char
*ep
,
165 register uint32_t mask
, origin
;
166 register int metric
, done
;
167 register u_int i
, width
;
171 ND_PRINT((ndo
, " [|]"));
174 ND_TCHECK2(bp
[0], 3);
175 mask
= (uint32_t)0xff << 24 | bp
[0] << 16 | bp
[1] << 8 | bp
[2];
184 ND_PRINT((ndo
, "\n\tMask %s", intoa(htonl(mask
))));
188 if (bp
+ width
+ 1 > ep
) {
189 ND_PRINT((ndo
, " [|]"));
192 if (len
< width
+ 1) {
193 ND_PRINT((ndo
, "\n\t [Truncated Report]"));
197 for (i
= 0; i
< width
; ++i
) {
199 origin
= origin
<< 8 | *bp
++;
206 done
= metric
& 0x80;
208 ND_PRINT((ndo
, "\n\t %s metric %d", intoa(htonl(origin
)),
219 print_probe(netdissect_options
*ndo
,
220 register const u_char
*bp
, register const u_char
*ep
,
223 register uint32_t genid
;
225 ND_TCHECK2(bp
[0], 4);
226 if ((len
< 4) || ((bp
+ 4) > ep
)) {
228 ND_PRINT((ndo
, " [|}"));
231 genid
= (bp
[0] << 24) | (bp
[1] << 16) | (bp
[2] << 8) | bp
[3];
234 ND_PRINT((ndo
, ndo
->ndo_vflag
> 1 ? "\n\t" : " "));
235 ND_PRINT((ndo
, "genid %u", genid
));
236 if (ndo
->ndo_vflag
< 2)
239 while ((len
> 0) && (bp
< ep
)) {
240 ND_TCHECK2(bp
[0], 4);
241 ND_PRINT((ndo
, "\n\tneighbor %s", ipaddr_string(ndo
, bp
)));
250 print_neighbors(netdissect_options
*ndo
,
251 register const u_char
*bp
, register const u_char
*ep
,
255 register u_char metric
;
256 register u_char thresh
;
259 while (len
> 0 && bp
< ep
) {
260 ND_TCHECK2(bp
[0], 7);
267 while (--ncount
>= 0) {
268 ND_TCHECK2(bp
[0], 4);
269 ND_PRINT((ndo
, " [%s ->", ipaddr_string(ndo
, laddr
)));
270 ND_PRINT((ndo
, " %s, (%d/%d)]",
271 ipaddr_string(ndo
, bp
), metric
, thresh
));
282 print_neighbors2(netdissect_options
*ndo
,
283 register const u_char
*bp
, register const u_char
*ep
,
287 register u_char metric
, thresh
, flags
;
290 ND_PRINT((ndo
, " (v %d.%d):",
291 (int)target_level
& 0xff,
292 (int)(target_level
>> 8) & 0xff));
294 while (len
> 0 && bp
< ep
) {
295 ND_TCHECK2(bp
[0], 8);
303 while (--ncount
>= 0 && (len
>= 4) && (bp
+ 4) <= ep
) {
304 ND_PRINT((ndo
, " [%s -> ", ipaddr_string(ndo
, laddr
)));
305 ND_PRINT((ndo
, "%s (%d/%d", ipaddr_string(ndo
, bp
),
307 if (flags
& DVMRP_NF_TUNNEL
)
308 ND_PRINT((ndo
, "/tunnel"));
309 if (flags
& DVMRP_NF_SRCRT
)
310 ND_PRINT((ndo
, "/srcrt"));
311 if (flags
& DVMRP_NF_QUERIER
)
312 ND_PRINT((ndo
, "/querier"));
313 if (flags
& DVMRP_NF_DISABLED
)
314 ND_PRINT((ndo
, "/disabled"));
315 if (flags
& DVMRP_NF_DOWN
)
316 ND_PRINT((ndo
, "/down"));
317 ND_PRINT((ndo
, ")]"));
322 ND_PRINT((ndo
, " [|]"));
332 print_prune(netdissect_options
*ndo
,
333 register const u_char
*bp
)
335 ND_TCHECK2(bp
[0], 12);
336 ND_PRINT((ndo
, " src %s grp %s", ipaddr_string(ndo
, bp
), ipaddr_string(ndo
, bp
+ 4)));
338 ND_PRINT((ndo
, " timer "));
339 relts_print(ndo
, EXTRACT_32BITS(bp
));
346 print_graft(netdissect_options
*ndo
,
347 register const u_char
*bp
)
349 ND_TCHECK2(bp
[0], 8);
350 ND_PRINT((ndo
, " src %s grp %s", ipaddr_string(ndo
, bp
), ipaddr_string(ndo
, bp
+ 4)));
357 print_graft_ack(netdissect_options
*ndo
,
358 register const u_char
*bp
)
360 ND_TCHECK2(bp
[0], 8);
361 ND_PRINT((ndo
, " src %s grp %s", ipaddr_string(ndo
, bp
), ipaddr_string(ndo
, bp
+ 4)));