2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 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-igmp.c,v 1.5 2014/11/20 03:05:03 christos Exp $");
27 #define NETDISSECT_REWORKED
32 #include <tcpdump-stdinc.h>
34 #include "interface.h"
35 #include "addrtoname.h"
36 #include "extract.h" /* must come after interface.h */
39 #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
42 static const char tstr
[] = "[|igmp]";
44 /* (following from ipmulti/mrouted/prune.h) */
47 * The packet format for a traceroute request.
50 uint32_t tr_src
; /* traceroute source */
51 uint32_t tr_dst
; /* traceroute destination */
52 uint32_t tr_raddr
; /* traceroute response address */
53 uint32_t tr_rttlqid
; /* response ttl and qid */
56 #define TR_GETTTL(x) (int)(((x) >> 24) & 0xff)
57 #define TR_GETQID(x) ((x) & 0x00ffffff)
60 * Traceroute response format. A traceroute response has a tr_query at the
61 * beginning, followed by one tr_resp for each hop taken.
64 uint32_t tr_qarr
; /* query arrival time */
65 uint32_t tr_inaddr
; /* incoming interface address */
66 uint32_t tr_outaddr
; /* outgoing interface address */
67 uint32_t tr_rmtaddr
; /* parent address in source tree */
68 uint32_t tr_vifin
; /* input packet count on interface */
69 uint32_t tr_vifout
; /* output packet count on interface */
70 uint32_t tr_pktcnt
; /* total incoming packets for src-grp */
71 uint8_t tr_rproto
; /* routing proto deployed on router */
72 uint8_t tr_fttl
; /* ttl required to forward on outvif */
73 uint8_t tr_smask
; /* subnet mask for src addr */
74 uint8_t tr_rflags
; /* forwarding error codes */
77 /* defs within mtrace */
81 /* fields for tr_rflags (forwarding error codes) */
89 #define TR_NO_SPACE 0x81
90 #define TR_OLD_ROUTER 0x82
92 /* fields for tr_rproto (routing protocol) */
93 #define TR_PROTO_DVMRP 1
94 #define TR_PROTO_MOSPF 2
95 #define TR_PROTO_PIM 3
96 #define TR_PROTO_CBT 4
98 /* igmpv3 report types */
99 static const struct tok igmpv3report2str
[] = {
110 print_mtrace(netdissect_options
*ndo
,
111 register const u_char
*bp
, register u_int len
)
113 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
116 if (len
< 8 + sizeof (struct tr_query
)) {
117 ND_PRINT((ndo
, " [invalid len %d]", len
));
120 ND_PRINT((ndo
, "mtrace %u: %s to %s reply-to %s",
121 TR_GETQID(EXTRACT_32BITS(&tr
->tr_rttlqid
)),
122 ipaddr_string(ndo
, &tr
->tr_src
), ipaddr_string(ndo
, &tr
->tr_dst
),
123 ipaddr_string(ndo
, &tr
->tr_raddr
)));
124 if (IN_CLASSD(EXTRACT_32BITS(&tr
->tr_raddr
)))
125 ND_PRINT((ndo
, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr
->tr_rttlqid
))));
128 ND_PRINT((ndo
, "%s", tstr
));
132 print_mresp(netdissect_options
*ndo
,
133 register const u_char
*bp
, register u_int len
)
135 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
138 if (len
< 8 + sizeof (struct tr_query
)) {
139 ND_PRINT((ndo
, " [invalid len %d]", len
));
142 ND_PRINT((ndo
, "mresp %lu: %s to %s reply-to %s",
143 (u_long
)TR_GETQID(EXTRACT_32BITS(&tr
->tr_rttlqid
)),
144 ipaddr_string(ndo
, &tr
->tr_src
), ipaddr_string(ndo
, &tr
->tr_dst
),
145 ipaddr_string(ndo
, &tr
->tr_raddr
)));
146 if (IN_CLASSD(EXTRACT_32BITS(&tr
->tr_raddr
)))
147 ND_PRINT((ndo
, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr
->tr_rttlqid
))));
150 ND_PRINT((ndo
, "%s", tstr
));
154 print_igmpv3_report(netdissect_options
*ndo
,
155 register const u_char
*bp
, register u_int len
)
157 u_int group
, nsrcs
, ngroups
;
160 /* Minimum len is 16, and should be a multiple of 4 */
161 if (len
< 16 || len
& 0x03) {
162 ND_PRINT((ndo
, " [invalid len %d]", len
));
165 ND_TCHECK2(bp
[6], 2);
166 ngroups
= EXTRACT_16BITS(&bp
[6]);
167 ND_PRINT((ndo
, ", %d group record(s)", ngroups
));
168 if (ndo
->ndo_vflag
> 0) {
169 /* Print the group records */
171 for (i
=0; i
<ngroups
; i
++) {
173 ND_PRINT((ndo
, " [invalid number of groups]"));
176 ND_TCHECK2(bp
[group
+4], 4);
177 ND_PRINT((ndo
, " [gaddr %s", ipaddr_string(ndo
, &bp
[group
+4])));
178 ND_PRINT((ndo
, " %s", tok2str(igmpv3report2str
, " [v3-report-#%d]",
180 nsrcs
= EXTRACT_16BITS(&bp
[group
+2]);
181 /* Check the number of sources and print them */
182 if (len
< group
+8+(nsrcs
<<2)) {
183 ND_PRINT((ndo
, " [invalid number of sources %d]", nsrcs
));
186 if (ndo
->ndo_vflag
== 1)
187 ND_PRINT((ndo
, ", %d source(s)", nsrcs
));
189 /* Print the sources */
190 ND_PRINT((ndo
, " {"));
191 for (j
=0; j
<nsrcs
; j
++) {
192 ND_TCHECK2(bp
[group
+8+(j
<<2)], 4);
193 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &bp
[group
+8+(j
<<2)])));
195 ND_PRINT((ndo
, " }"));
197 /* Next group record */
198 group
+= 8 + (nsrcs
<< 2);
199 ND_PRINT((ndo
, "]"));
204 ND_PRINT((ndo
, "%s", tstr
));
208 print_igmpv3_query(netdissect_options
*ndo
,
209 register const u_char
*bp
, register u_int len
)
216 ND_PRINT((ndo
, " v3"));
217 /* Minimum len is 12, and should be a multiple of 4 */
218 if (len
< 12 || len
& 0x03) {
219 ND_PRINT((ndo
, " [invalid len %d]", len
));
227 mrt
= ((mrc
& 0x0f) | 0x10) << (((mrc
& 0x70) >> 4) + 3);
230 ND_PRINT((ndo
, " [max resp time "));
232 ND_PRINT((ndo
, "%.1fs", mrt
* 0.1));
234 relts_print(ndo
, mrt
/ 10);
236 ND_PRINT((ndo
, "]"));
238 ND_TCHECK2(bp
[4], 4);
239 if (EXTRACT_32BITS(&bp
[4]) == 0)
241 ND_PRINT((ndo
, " [gaddr %s", ipaddr_string(ndo
, &bp
[4])));
242 ND_TCHECK2(bp
[10], 2);
243 nsrcs
= EXTRACT_16BITS(&bp
[10]);
245 if (len
< 12 + (nsrcs
<< 2))
246 ND_PRINT((ndo
, " [invalid number of sources]"));
247 else if (ndo
->ndo_vflag
> 1) {
248 ND_PRINT((ndo
, " {"));
249 for (i
=0; i
<nsrcs
; i
++) {
250 ND_TCHECK2(bp
[12+(i
<<2)], 4);
251 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &bp
[12+(i
<<2)])));
253 ND_PRINT((ndo
, " }"));
255 ND_PRINT((ndo
, ", %d source(s)", nsrcs
));
257 ND_PRINT((ndo
, "]"));
260 ND_PRINT((ndo
, "%s", tstr
));
264 igmp_print(netdissect_options
*ndo
,
265 register const u_char
*bp
, register u_int len
)
267 struct cksum_vec vec
[1];
269 if (ndo
->ndo_qflag
) {
270 ND_PRINT((ndo
, "igmp"));
277 ND_PRINT((ndo
, "igmp query"));
279 print_igmpv3_query(ndo
, bp
, len
);
283 ND_PRINT((ndo
, " v2"));
285 ND_PRINT((ndo
, " [max resp time %d]", bp
[1]));
287 ND_PRINT((ndo
, " v1"));
288 ND_TCHECK2(bp
[4], 4);
289 if (EXTRACT_32BITS(&bp
[4]))
290 ND_PRINT((ndo
, " [gaddr %s]", ipaddr_string(ndo
, &bp
[4])));
292 ND_PRINT((ndo
, " [len %d]", len
));
296 ND_TCHECK2(bp
[4], 4);
297 ND_PRINT((ndo
, "igmp v1 report %s", ipaddr_string(ndo
, &bp
[4])));
299 ND_PRINT((ndo
, " [len %d]", len
));
302 ND_TCHECK2(bp
[4], 4);
303 ND_PRINT((ndo
, "igmp v2 report %s", ipaddr_string(ndo
, &bp
[4])));
306 ND_PRINT((ndo
, "igmp v3 report"));
307 print_igmpv3_report(ndo
, bp
, len
);
310 ND_TCHECK2(bp
[4], 4);
311 ND_PRINT((ndo
, "igmp leave %s", ipaddr_string(ndo
, &bp
[4])));
314 ND_PRINT((ndo
, "igmp dvmrp"));
316 ND_PRINT((ndo
, " [len %d]", len
));
318 dvmrp_print(ndo
, bp
, len
);
321 ND_PRINT((ndo
, "igmp pimv1"));
322 pimv1_print(ndo
, bp
, len
);
325 print_mresp(ndo
, bp
, len
);
328 print_mtrace(ndo
, bp
, len
);
331 ND_PRINT((ndo
, "igmp-%d", bp
[0]));
335 if (ndo
->ndo_vflag
&& ND_TTEST2(bp
[0], len
)) {
336 /* Check the IGMP checksum */
339 if (in_cksum(vec
, 1))
340 ND_PRINT((ndo
, " bad igmp cksum %x!", EXTRACT_16BITS(&bp
[2])));
344 ND_PRINT((ndo
, "%s", tstr
));