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