print-igmp.c revision 1.1.1.4 1 1.1 christos /*
2 1.1 christos * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
3 1.1 christos * The Regents of the University of California. All rights reserved.
4 1.1 christos *
5 1.1 christos * Redistribution and use in source and binary forms, with or without
6 1.1 christos * modification, are permitted provided that: (1) source code distributions
7 1.1 christos * retain the above copyright notice and this paragraph in its entirety, (2)
8 1.1 christos * distributions including binary code include the above copyright notice and
9 1.1 christos * this paragraph in its entirety in the documentation or other materials
10 1.1 christos * provided with the distribution, and (3) all advertising materials mentioning
11 1.1 christos * features or use of this software display the following acknowledgement:
12 1.1 christos * ``This product includes software developed by the University of California,
13 1.1 christos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 1.1 christos * the University nor the names of its contributors may be used to endorse
15 1.1 christos * or promote products derived from this software without specific prior
16 1.1 christos * written permission.
17 1.1 christos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 1.1 christos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 1.1 christos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 1.1 christos */
21 1.1 christos
22 1.1.1.4 christos #define NETDISSECT_REWORKED
23 1.1 christos #ifdef HAVE_CONFIG_H
24 1.1 christos #include "config.h"
25 1.1 christos #endif
26 1.1 christos
27 1.1 christos #include <tcpdump-stdinc.h>
28 1.1 christos
29 1.1 christos #include "interface.h"
30 1.1 christos #include "addrtoname.h"
31 1.1 christos #include "extract.h" /* must come after interface.h */
32 1.1 christos
33 1.1 christos #ifndef IN_CLASSD
34 1.1 christos #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
35 1.1 christos #endif
36 1.1 christos
37 1.1.1.4 christos static const char tstr[] = "[|igmp]";
38 1.1.1.4 christos
39 1.1 christos /* (following from ipmulti/mrouted/prune.h) */
40 1.1 christos
41 1.1 christos /*
42 1.1 christos * The packet format for a traceroute request.
43 1.1 christos */
44 1.1 christos struct tr_query {
45 1.1.1.4 christos uint32_t tr_src; /* traceroute source */
46 1.1.1.4 christos uint32_t tr_dst; /* traceroute destination */
47 1.1.1.4 christos uint32_t tr_raddr; /* traceroute response address */
48 1.1.1.4 christos uint32_t tr_rttlqid; /* response ttl and qid */
49 1.1 christos };
50 1.1 christos
51 1.1 christos #define TR_GETTTL(x) (int)(((x) >> 24) & 0xff)
52 1.1 christos #define TR_GETQID(x) ((x) & 0x00ffffff)
53 1.1 christos
54 1.1 christos /*
55 1.1 christos * Traceroute response format. A traceroute response has a tr_query at the
56 1.1 christos * beginning, followed by one tr_resp for each hop taken.
57 1.1 christos */
58 1.1 christos struct tr_resp {
59 1.1.1.4 christos uint32_t tr_qarr; /* query arrival time */
60 1.1.1.4 christos uint32_t tr_inaddr; /* incoming interface address */
61 1.1.1.4 christos uint32_t tr_outaddr; /* outgoing interface address */
62 1.1.1.4 christos uint32_t tr_rmtaddr; /* parent address in source tree */
63 1.1.1.4 christos uint32_t tr_vifin; /* input packet count on interface */
64 1.1.1.4 christos uint32_t tr_vifout; /* output packet count on interface */
65 1.1.1.4 christos uint32_t tr_pktcnt; /* total incoming packets for src-grp */
66 1.1.1.4 christos uint8_t tr_rproto; /* routing proto deployed on router */
67 1.1.1.4 christos uint8_t tr_fttl; /* ttl required to forward on outvif */
68 1.1.1.4 christos uint8_t tr_smask; /* subnet mask for src addr */
69 1.1.1.4 christos uint8_t tr_rflags; /* forwarding error codes */
70 1.1 christos };
71 1.1 christos
72 1.1 christos /* defs within mtrace */
73 1.1 christos #define TR_QUERY 1
74 1.1 christos #define TR_RESP 2
75 1.1 christos
76 1.1 christos /* fields for tr_rflags (forwarding error codes) */
77 1.1 christos #define TR_NO_ERR 0
78 1.1 christos #define TR_WRONG_IF 1
79 1.1 christos #define TR_PRUNED 2
80 1.1 christos #define TR_OPRUNED 3
81 1.1 christos #define TR_SCOPED 4
82 1.1 christos #define TR_NO_RTE 5
83 1.1 christos #define TR_NO_FWD 7
84 1.1 christos #define TR_NO_SPACE 0x81
85 1.1 christos #define TR_OLD_ROUTER 0x82
86 1.1 christos
87 1.1 christos /* fields for tr_rproto (routing protocol) */
88 1.1 christos #define TR_PROTO_DVMRP 1
89 1.1 christos #define TR_PROTO_MOSPF 2
90 1.1 christos #define TR_PROTO_PIM 3
91 1.1 christos #define TR_PROTO_CBT 4
92 1.1 christos
93 1.1 christos /* igmpv3 report types */
94 1.1.1.3 christos static const struct tok igmpv3report2str[] = {
95 1.1 christos { 1, "is_in" },
96 1.1 christos { 2, "is_ex" },
97 1.1 christos { 3, "to_in" },
98 1.1 christos { 4, "to_ex" },
99 1.1 christos { 5, "allow" },
100 1.1 christos { 6, "block" },
101 1.1 christos { 0, NULL }
102 1.1 christos };
103 1.1 christos
104 1.1 christos static void
105 1.1.1.4 christos print_mtrace(netdissect_options *ndo,
106 1.1.1.4 christos register const u_char *bp, register u_int len)
107 1.1 christos {
108 1.1 christos register const struct tr_query *tr = (const struct tr_query *)(bp + 8);
109 1.1 christos
110 1.1.1.4 christos ND_TCHECK(*tr);
111 1.1 christos if (len < 8 + sizeof (struct tr_query)) {
112 1.1.1.4 christos ND_PRINT((ndo, " [invalid len %d]", len));
113 1.1 christos return;
114 1.1 christos }
115 1.1.1.4 christos ND_PRINT((ndo, "mtrace %u: %s to %s reply-to %s",
116 1.1 christos TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)),
117 1.1.1.4 christos ipaddr_string(ndo, &tr->tr_src), ipaddr_string(ndo, &tr->tr_dst),
118 1.1.1.4 christos ipaddr_string(ndo, &tr->tr_raddr)));
119 1.1 christos if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr)))
120 1.1.1.4 christos ND_PRINT((ndo, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid))));
121 1.1 christos return;
122 1.1 christos trunc:
123 1.1.1.4 christos ND_PRINT((ndo, "%s", tstr));
124 1.1 christos }
125 1.1 christos
126 1.1 christos static void
127 1.1.1.4 christos print_mresp(netdissect_options *ndo,
128 1.1.1.4 christos register const u_char *bp, register u_int len)
129 1.1 christos {
130 1.1 christos register const struct tr_query *tr = (const struct tr_query *)(bp + 8);
131 1.1 christos
132 1.1.1.4 christos ND_TCHECK(*tr);
133 1.1 christos if (len < 8 + sizeof (struct tr_query)) {
134 1.1.1.4 christos ND_PRINT((ndo, " [invalid len %d]", len));
135 1.1 christos return;
136 1.1 christos }
137 1.1.1.4 christos ND_PRINT((ndo, "mresp %lu: %s to %s reply-to %s",
138 1.1 christos (u_long)TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)),
139 1.1.1.4 christos ipaddr_string(ndo, &tr->tr_src), ipaddr_string(ndo, &tr->tr_dst),
140 1.1.1.4 christos ipaddr_string(ndo, &tr->tr_raddr)));
141 1.1 christos if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr)))
142 1.1.1.4 christos ND_PRINT((ndo, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid))));
143 1.1 christos return;
144 1.1 christos trunc:
145 1.1.1.4 christos ND_PRINT((ndo, "%s", tstr));
146 1.1 christos }
147 1.1 christos
148 1.1 christos static void
149 1.1.1.4 christos print_igmpv3_report(netdissect_options *ndo,
150 1.1.1.4 christos register const u_char *bp, register u_int len)
151 1.1 christos {
152 1.1 christos u_int group, nsrcs, ngroups;
153 1.1 christos register u_int i, j;
154 1.1 christos
155 1.1 christos /* Minimum len is 16, and should be a multiple of 4 */
156 1.1 christos if (len < 16 || len & 0x03) {
157 1.1.1.4 christos ND_PRINT((ndo, " [invalid len %d]", len));
158 1.1 christos return;
159 1.1 christos }
160 1.1.1.4 christos ND_TCHECK2(bp[6], 2);
161 1.1 christos ngroups = EXTRACT_16BITS(&bp[6]);
162 1.1.1.4 christos ND_PRINT((ndo, ", %d group record(s)", ngroups));
163 1.1.1.4 christos if (ndo->ndo_vflag > 0) {
164 1.1 christos /* Print the group records */
165 1.1 christos group = 8;
166 1.1 christos for (i=0; i<ngroups; i++) {
167 1.1 christos if (len < group+8) {
168 1.1.1.4 christos ND_PRINT((ndo, " [invalid number of groups]"));
169 1.1 christos return;
170 1.1 christos }
171 1.1.1.4 christos ND_TCHECK2(bp[group+4], 4);
172 1.1.1.4 christos ND_PRINT((ndo, " [gaddr %s", ipaddr_string(ndo, &bp[group+4])));
173 1.1.1.4 christos ND_PRINT((ndo, " %s", tok2str(igmpv3report2str, " [v3-report-#%d]",
174 1.1.1.4 christos bp[group])));
175 1.1 christos nsrcs = EXTRACT_16BITS(&bp[group+2]);
176 1.1 christos /* Check the number of sources and print them */
177 1.1 christos if (len < group+8+(nsrcs<<2)) {
178 1.1.1.4 christos ND_PRINT((ndo, " [invalid number of sources %d]", nsrcs));
179 1.1 christos return;
180 1.1 christos }
181 1.1.1.4 christos if (ndo->ndo_vflag == 1)
182 1.1.1.4 christos ND_PRINT((ndo, ", %d source(s)", nsrcs));
183 1.1 christos else {
184 1.1 christos /* Print the sources */
185 1.1.1.4 christos ND_PRINT((ndo, " {"));
186 1.1 christos for (j=0; j<nsrcs; j++) {
187 1.1.1.4 christos ND_TCHECK2(bp[group+8+(j<<2)], 4);
188 1.1.1.4 christos ND_PRINT((ndo, " %s", ipaddr_string(ndo, &bp[group+8+(j<<2)])));
189 1.1 christos }
190 1.1.1.4 christos ND_PRINT((ndo, " }"));
191 1.1 christos }
192 1.1 christos /* Next group record */
193 1.1 christos group += 8 + (nsrcs << 2);
194 1.1.1.4 christos ND_PRINT((ndo, "]"));
195 1.1 christos }
196 1.1 christos }
197 1.1 christos return;
198 1.1 christos trunc:
199 1.1.1.4 christos ND_PRINT((ndo, "%s", tstr));
200 1.1 christos }
201 1.1 christos
202 1.1 christos static void
203 1.1.1.4 christos print_igmpv3_query(netdissect_options *ndo,
204 1.1.1.4 christos register const u_char *bp, register u_int len)
205 1.1 christos {
206 1.1 christos u_int mrc;
207 1.1 christos int mrt;
208 1.1 christos u_int nsrcs;
209 1.1 christos register u_int i;
210 1.1 christos
211 1.1.1.4 christos ND_PRINT((ndo, " v3"));
212 1.1 christos /* Minimum len is 12, and should be a multiple of 4 */
213 1.1 christos if (len < 12 || len & 0x03) {
214 1.1.1.4 christos ND_PRINT((ndo, " [invalid len %d]", len));
215 1.1 christos return;
216 1.1 christos }
217 1.1.1.4 christos ND_TCHECK(bp[1]);
218 1.1 christos mrc = bp[1];
219 1.1 christos if (mrc < 128) {
220 1.1 christos mrt = mrc;
221 1.1 christos } else {
222 1.1 christos mrt = ((mrc & 0x0f) | 0x10) << (((mrc & 0x70) >> 4) + 3);
223 1.1 christos }
224 1.1 christos if (mrc != 100) {
225 1.1.1.4 christos ND_PRINT((ndo, " [max resp time "));
226 1.1.1.2 christos if (mrt < 600) {
227 1.1.1.4 christos ND_PRINT((ndo, "%.1fs", mrt * 0.1));
228 1.1.1.2 christos } else {
229 1.1.1.4 christos relts_print(ndo, mrt / 10);
230 1.1.1.2 christos }
231 1.1.1.4 christos ND_PRINT((ndo, "]"));
232 1.1 christos }
233 1.1.1.4 christos ND_TCHECK2(bp[4], 4);
234 1.1 christos if (EXTRACT_32BITS(&bp[4]) == 0)
235 1.1 christos return;
236 1.1.1.4 christos ND_PRINT((ndo, " [gaddr %s", ipaddr_string(ndo, &bp[4])));
237 1.1.1.4 christos ND_TCHECK2(bp[10], 2);
238 1.1 christos nsrcs = EXTRACT_16BITS(&bp[10]);
239 1.1 christos if (nsrcs > 0) {
240 1.1 christos if (len < 12 + (nsrcs << 2))
241 1.1.1.4 christos ND_PRINT((ndo, " [invalid number of sources]"));
242 1.1.1.4 christos else if (ndo->ndo_vflag > 1) {
243 1.1.1.4 christos ND_PRINT((ndo, " {"));
244 1.1 christos for (i=0; i<nsrcs; i++) {
245 1.1.1.4 christos ND_TCHECK2(bp[12+(i<<2)], 4);
246 1.1.1.4 christos ND_PRINT((ndo, " %s", ipaddr_string(ndo, &bp[12+(i<<2)])));
247 1.1 christos }
248 1.1.1.4 christos ND_PRINT((ndo, " }"));
249 1.1 christos } else
250 1.1.1.4 christos ND_PRINT((ndo, ", %d source(s)", nsrcs));
251 1.1 christos }
252 1.1.1.4 christos ND_PRINT((ndo, "]"));
253 1.1 christos return;
254 1.1 christos trunc:
255 1.1.1.4 christos ND_PRINT((ndo, "%s", tstr));
256 1.1 christos }
257 1.1 christos
258 1.1 christos void
259 1.1.1.4 christos igmp_print(netdissect_options *ndo,
260 1.1.1.4 christos register const u_char *bp, register u_int len)
261 1.1 christos {
262 1.1.1.2 christos struct cksum_vec vec[1];
263 1.1.1.2 christos
264 1.1.1.4 christos if (ndo->ndo_qflag) {
265 1.1.1.4 christos ND_PRINT((ndo, "igmp"));
266 1.1 christos return;
267 1.1 christos }
268 1.1 christos
269 1.1.1.4 christos ND_TCHECK(bp[0]);
270 1.1 christos switch (bp[0]) {
271 1.1 christos case 0x11:
272 1.1.1.4 christos ND_PRINT((ndo, "igmp query"));
273 1.1 christos if (len >= 12)
274 1.1.1.4 christos print_igmpv3_query(ndo, bp, len);
275 1.1 christos else {
276 1.1.1.4 christos ND_TCHECK(bp[1]);
277 1.1 christos if (bp[1]) {
278 1.1.1.4 christos ND_PRINT((ndo, " v2"));
279 1.1 christos if (bp[1] != 100)
280 1.1.1.4 christos ND_PRINT((ndo, " [max resp time %d]", bp[1]));
281 1.1 christos } else
282 1.1.1.4 christos ND_PRINT((ndo, " v1"));
283 1.1.1.4 christos ND_TCHECK2(bp[4], 4);
284 1.1 christos if (EXTRACT_32BITS(&bp[4]))
285 1.1.1.4 christos ND_PRINT((ndo, " [gaddr %s]", ipaddr_string(ndo, &bp[4])));
286 1.1 christos if (len != 8)
287 1.1.1.4 christos ND_PRINT((ndo, " [len %d]", len));
288 1.1 christos }
289 1.1 christos break;
290 1.1 christos case 0x12:
291 1.1.1.4 christos ND_TCHECK2(bp[4], 4);
292 1.1.1.4 christos ND_PRINT((ndo, "igmp v1 report %s", ipaddr_string(ndo, &bp[4])));
293 1.1 christos if (len != 8)
294 1.1.1.4 christos ND_PRINT((ndo, " [len %d]", len));
295 1.1 christos break;
296 1.1 christos case 0x16:
297 1.1.1.4 christos ND_TCHECK2(bp[4], 4);
298 1.1.1.4 christos ND_PRINT((ndo, "igmp v2 report %s", ipaddr_string(ndo, &bp[4])));
299 1.1 christos break;
300 1.1 christos case 0x22:
301 1.1.1.4 christos ND_PRINT((ndo, "igmp v3 report"));
302 1.1.1.4 christos print_igmpv3_report(ndo, bp, len);
303 1.1 christos break;
304 1.1 christos case 0x17:
305 1.1.1.4 christos ND_TCHECK2(bp[4], 4);
306 1.1.1.4 christos ND_PRINT((ndo, "igmp leave %s", ipaddr_string(ndo, &bp[4])));
307 1.1 christos break;
308 1.1 christos case 0x13:
309 1.1.1.4 christos ND_PRINT((ndo, "igmp dvmrp"));
310 1.1 christos if (len < 8)
311 1.1.1.4 christos ND_PRINT((ndo, " [len %d]", len));
312 1.1 christos else
313 1.1.1.4 christos dvmrp_print(ndo, bp, len);
314 1.1 christos break;
315 1.1 christos case 0x14:
316 1.1.1.4 christos ND_PRINT((ndo, "igmp pimv1"));
317 1.1.1.4 christos pimv1_print(ndo, bp, len);
318 1.1 christos break;
319 1.1 christos case 0x1e:
320 1.1.1.4 christos print_mresp(ndo, bp, len);
321 1.1 christos break;
322 1.1 christos case 0x1f:
323 1.1.1.4 christos print_mtrace(ndo, bp, len);
324 1.1 christos break;
325 1.1 christos default:
326 1.1.1.4 christos ND_PRINT((ndo, "igmp-%d", bp[0]));
327 1.1 christos break;
328 1.1 christos }
329 1.1 christos
330 1.1.1.4 christos if (ndo->ndo_vflag && ND_TTEST2(bp[0], len)) {
331 1.1 christos /* Check the IGMP checksum */
332 1.1.1.2 christos vec[0].ptr = bp;
333 1.1.1.2 christos vec[0].len = len;
334 1.1.1.2 christos if (in_cksum(vec, 1))
335 1.1.1.4 christos ND_PRINT((ndo, " bad igmp cksum %x!", EXTRACT_16BITS(&bp[2])));
336 1.1 christos }
337 1.1 christos return;
338 1.1 christos trunc:
339 1.1.1.4 christos ND_PRINT((ndo, "%s", tstr));
340 1.1 christos }
341