]> The Tcpdump Group git mirrors - tcpdump/blob - print-dvmrp.c
OpenFlow 1.0: Simplify of10_vendor_message_print().
[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 /* \summary: Distance Vector Multicast Routing Protocol printer */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "netdissect-stdinc.h"
29
30 #include "netdissect.h"
31 #include "extract.h"
32 #include "addrtoname.h"
33
34 /*
35 * See: RFC 1075 and draft-ietf-idmr-dvmrp-v3
36 *
37 * DVMRP message types and flag values shamelessly stolen from
38 * mrouted/dvmrp.h.
39 */
40 #define DVMRP_PROBE 1 /* for finding neighbors */
41 #define DVMRP_REPORT 2 /* for reporting some or all routes */
42 #define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */
43 /* of this router's neighbors */
44 #define DVMRP_NEIGHBORS 4 /* response to such a request */
45 #define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */
46 #define DVMRP_NEIGHBORS2 6
47 #define DVMRP_PRUNE 7 /* prune message */
48 #define DVMRP_GRAFT 8 /* graft message */
49 #define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */
50
51 /*
52 * 'flags' byte values in DVMRP_NEIGHBORS2 reply.
53 */
54 #define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */
55 #define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */
56 #define DVMRP_NF_DOWN 0x10 /* kernel state of interface */
57 #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */
58 #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */
59
60 static int print_probe(netdissect_options *, const u_char *, const u_char *, u_int);
61 static int print_report(netdissect_options *, const u_char *, const u_char *, u_int);
62 static int print_neighbors(netdissect_options *, const u_char *, const u_char *, u_int);
63 static int print_neighbors2(netdissect_options *, const u_char *, const u_char *, u_int, uint8_t, uint8_t);
64 static int print_prune(netdissect_options *, const u_char *);
65 static int print_graft(netdissect_options *, const u_char *);
66 static int print_graft_ack(netdissect_options *, const u_char *);
67
68 void
69 dvmrp_print(netdissect_options *ndo,
70 const u_char *bp, u_int len)
71 {
72 const u_char *ep;
73 u_char type;
74 uint8_t major_version, minor_version;
75
76 ndo->ndo_protocol = "dvmrp";
77 ep = ndo->ndo_snapend;
78 if (bp >= ep)
79 return;
80
81 type = GET_U_1(bp + 1);
82
83 /* Skip IGMP header */
84 bp += 8;
85 len -= 8;
86
87 switch (type) {
88
89 case DVMRP_PROBE:
90 ND_PRINT(" Probe");
91 if (ndo->ndo_vflag) {
92 if (print_probe(ndo, bp, ep, len) < 0)
93 goto trunc;
94 }
95 break;
96
97 case DVMRP_REPORT:
98 ND_PRINT(" Report");
99 if (ndo->ndo_vflag > 1) {
100 if (print_report(ndo, bp, ep, len) < 0)
101 goto trunc;
102 }
103 break;
104
105 case DVMRP_ASK_NEIGHBORS:
106 ND_PRINT(" Ask-neighbors(old)");
107 break;
108
109 case DVMRP_NEIGHBORS:
110 ND_PRINT(" Neighbors(old)");
111 if (print_neighbors(ndo, bp, ep, len) < 0)
112 goto trunc;
113 break;
114
115 case DVMRP_ASK_NEIGHBORS2:
116 ND_PRINT(" Ask-neighbors2");
117 break;
118
119 case DVMRP_NEIGHBORS2:
120 ND_PRINT(" Neighbors2");
121 /*
122 * extract version from IGMP group address field
123 */
124 bp -= 4;
125 major_version = GET_U_1(bp + 3);
126 minor_version = GET_U_1(bp + 2);
127 bp += 4;
128 if (print_neighbors2(ndo, bp, ep, len, major_version,
129 minor_version) < 0)
130 goto trunc;
131 break;
132
133 case DVMRP_PRUNE:
134 ND_PRINT(" Prune");
135 if (print_prune(ndo, bp) < 0)
136 goto trunc;
137 break;
138
139 case DVMRP_GRAFT:
140 ND_PRINT(" Graft");
141 if (print_graft(ndo, bp) < 0)
142 goto trunc;
143 break;
144
145 case DVMRP_GRAFT_ACK:
146 ND_PRINT(" Graft-ACK");
147 if (print_graft_ack(ndo, bp) < 0)
148 goto trunc;
149 break;
150
151 default:
152 ND_PRINT(" [type %u]", type);
153 break;
154 }
155 return;
156
157 trunc:
158 nd_print_trunc(ndo);
159 }
160
161 static int
162 print_report(netdissect_options *ndo,
163 const u_char *bp, const u_char *ep,
164 u_int len)
165 {
166 uint32_t mask, origin;
167 u_int metric, done;
168 u_int i, width;
169
170 while (len > 0) {
171 if (len < 3) {
172 ND_PRINT(" [|]");
173 return (0);
174 }
175 mask = (uint32_t)0xff << 24 | GET_U_1(bp) << 16 |
176 GET_U_1(bp + 1) << 8 | GET_U_1(bp + 2);
177 width = 1;
178 if (GET_U_1(bp))
179 width = 2;
180 if (GET_U_1(bp + 1))
181 width = 3;
182 if (GET_U_1(bp + 2))
183 width = 4;
184
185 ND_PRINT("\n\tMask %s", intoa(htonl(mask)));
186 bp += 3;
187 len -= 3;
188 do {
189 if (bp + width + 1 > ep) {
190 ND_PRINT(" [|]");
191 return (0);
192 }
193 if (len < width + 1) {
194 ND_PRINT("\n\t [Truncated Report]");
195 return (0);
196 }
197 origin = 0;
198 for (i = 0; i < width; ++i) {
199 origin = origin << 8 | GET_U_1(bp);
200 bp++;
201 }
202 for ( ; i < 4; ++i)
203 origin <<= 8;
204
205 metric = GET_U_1(bp);
206 bp++;
207 done = metric & 0x80;
208 metric &= 0x7f;
209 ND_PRINT("\n\t %s metric %u", intoa(htonl(origin)),
210 metric);
211 len -= width + 1;
212 } while (!done);
213 }
214 return (0);
215 }
216
217 static int
218 print_probe(netdissect_options *ndo,
219 const u_char *bp, const u_char *ep,
220 u_int len)
221 {
222 uint32_t genid;
223
224 ND_TCHECK_4(bp);
225 if ((len < 4) || ((bp + 4) > ep)) {
226 ND_PRINT(" [|}");
227 return (0);
228 }
229 genid = GET_BE_U_4(bp);
230 bp += 4;
231 len -= 4;
232 ND_PRINT(ndo->ndo_vflag > 1 ? "\n\t" : " ");
233 ND_PRINT("genid %u", genid);
234 if (ndo->ndo_vflag < 2)
235 return (0);
236
237 while ((len > 0) && (bp < ep)) {
238 ND_PRINT("\n\tneighbor %s", GET_IPADDR_STRING(bp));
239 bp += 4; len -= 4;
240 }
241 return (0);
242 trunc:
243 return (-1);
244 }
245
246 static int
247 print_neighbors(netdissect_options *ndo,
248 const u_char *bp, const u_char *ep,
249 u_int len)
250 {
251 const u_char *laddr;
252 u_char metric;
253 u_char thresh;
254 int ncount;
255
256 while (len > 0 && bp < ep) {
257 ND_TCHECK_7(bp);
258 laddr = bp;
259 bp += 4;
260 metric = GET_U_1(bp);
261 bp++;
262 thresh = GET_U_1(bp);
263 bp++;
264 ncount = GET_U_1(bp);
265 bp++;
266 len -= 7;
267 while (--ncount >= 0) {
268 ND_PRINT(" [%s ->", GET_IPADDR_STRING(laddr));
269 ND_PRINT(" %s, (%u/%u)]",
270 GET_IPADDR_STRING(bp), metric, thresh);
271 bp += 4;
272 len -= 4;
273 }
274 }
275 return (0);
276 trunc:
277 return (-1);
278 }
279
280 static int
281 print_neighbors2(netdissect_options *ndo,
282 const u_char *bp, const u_char *ep,
283 u_int len, uint8_t major_version,
284 uint8_t minor_version)
285 {
286 const u_char *laddr;
287 u_char metric, thresh, flags;
288 int ncount;
289
290 ND_PRINT(" (v %u.%u):", major_version, minor_version);
291
292 while (len > 0 && bp < ep) {
293 ND_TCHECK_8(bp);
294 laddr = bp;
295 bp += 4;
296 metric = GET_U_1(bp);
297 bp++;
298 thresh = GET_U_1(bp);
299 bp++;
300 flags = GET_U_1(bp);
301 bp++;
302 ncount = GET_U_1(bp);
303 bp++;
304 len -= 8;
305 while (--ncount >= 0 && (len >= 4) && (bp + 4) <= ep) {
306 ND_PRINT(" [%s -> ", GET_IPADDR_STRING(laddr));
307 ND_PRINT("%s (%u/%u", GET_IPADDR_STRING(bp),
308 metric, thresh);
309 if (flags & DVMRP_NF_TUNNEL)
310 ND_PRINT("/tunnel");
311 if (flags & DVMRP_NF_SRCRT)
312 ND_PRINT("/srcrt");
313 if (flags & DVMRP_NF_QUERIER)
314 ND_PRINT("/querier");
315 if (flags & DVMRP_NF_DISABLED)
316 ND_PRINT("/disabled");
317 if (flags & DVMRP_NF_DOWN)
318 ND_PRINT("/down");
319 ND_PRINT(")]");
320 bp += 4;
321 len -= 4;
322 }
323 if (ncount != -1) {
324 ND_PRINT(" [|]");
325 return (0);
326 }
327 }
328 return (0);
329 trunc:
330 return (-1);
331 }
332
333 static int
334 print_prune(netdissect_options *ndo,
335 const u_char *bp)
336 {
337 ND_PRINT(" src %s grp %s", GET_IPADDR_STRING(bp), GET_IPADDR_STRING(bp + 4));
338 bp += 8;
339 ND_PRINT(" timer ");
340 unsigned_relts_print(ndo, GET_BE_U_4(bp));
341 return (0);
342 }
343
344 static int
345 print_graft(netdissect_options *ndo,
346 const u_char *bp)
347 {
348 ND_PRINT(" src %s grp %s", GET_IPADDR_STRING(bp), GET_IPADDR_STRING(bp + 4));
349 return (0);
350 }
351
352 static int
353 print_graft_ack(netdissect_options *ndo,
354 const u_char *bp)
355 {
356 ND_PRINT(" src %s grp %s", GET_IPADDR_STRING(bp), GET_IPADDR_STRING(bp + 4));
357 return (0);
358 }