]>
The Tcpdump Group git mirrors - tcpdump/blob - print-igmp.c
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 #define NETDISSECT_REWORKED
27 #include <tcpdump-stdinc.h>
29 #include "interface.h"
30 #include "addrtoname.h"
31 #include "extract.h" /* must come after interface.h */
34 #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
37 static const char tstr
[] = "[|igmp]";
39 /* (following from ipmulti/mrouted/prune.h) */
42 * The packet format for a traceroute request.
45 u_int32_t tr_src
; /* traceroute source */
46 u_int32_t tr_dst
; /* traceroute destination */
47 u_int32_t tr_raddr
; /* traceroute response address */
48 u_int32_t tr_rttlqid
; /* response ttl and qid */
51 #define TR_GETTTL(x) (int)(((x) >> 24) & 0xff)
52 #define TR_GETQID(x) ((x) & 0x00ffffff)
55 * Traceroute response format. A traceroute response has a tr_query at the
56 * beginning, followed by one tr_resp for each hop taken.
59 u_int32_t tr_qarr
; /* query arrival time */
60 u_int32_t tr_inaddr
; /* incoming interface address */
61 u_int32_t tr_outaddr
; /* outgoing interface address */
62 u_int32_t tr_rmtaddr
; /* parent address in source tree */
63 u_int32_t tr_vifin
; /* input packet count on interface */
64 u_int32_t tr_vifout
; /* output packet count on interface */
65 u_int32_t tr_pktcnt
; /* total incoming packets for src-grp */
66 u_int8_t tr_rproto
; /* routing proto deployed on router */
67 u_int8_t tr_fttl
; /* ttl required to forward on outvif */
68 u_int8_t tr_smask
; /* subnet mask for src addr */
69 u_int8_t tr_rflags
; /* forwarding error codes */
72 /* defs within mtrace */
76 /* fields for tr_rflags (forwarding error codes) */
84 #define TR_NO_SPACE 0x81
85 #define TR_OLD_ROUTER 0x82
87 /* fields for tr_rproto (routing protocol) */
88 #define TR_PROTO_DVMRP 1
89 #define TR_PROTO_MOSPF 2
90 #define TR_PROTO_PIM 3
91 #define TR_PROTO_CBT 4
93 /* igmpv3 report types */
94 static const struct tok igmpv3report2str
[] = {
105 print_mtrace(netdissect_options
*ndo
,
106 register const u_char
*bp
, register u_int len
)
108 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
111 if (len
< 8 + sizeof (struct tr_query
)) {
112 ND_PRINT((ndo
, " [invalid len %d]", len
));
115 ND_PRINT((ndo
, "mtrace %u: %s to %s reply-to %s",
116 TR_GETQID(EXTRACT_32BITS(&tr
->tr_rttlqid
)),
117 ipaddr_string(ndo
, &tr
->tr_src
), ipaddr_string(ndo
, &tr
->tr_dst
),
118 ipaddr_string(ndo
, &tr
->tr_raddr
)));
119 if (IN_CLASSD(EXTRACT_32BITS(&tr
->tr_raddr
)))
120 ND_PRINT((ndo
, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr
->tr_rttlqid
))));
123 ND_PRINT((ndo
, "%s", tstr
));
127 print_mresp(netdissect_options
*ndo
,
128 register const u_char
*bp
, register u_int len
)
130 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
133 if (len
< 8 + sizeof (struct tr_query
)) {
134 ND_PRINT((ndo
, " [invalid len %d]", len
));
137 ND_PRINT((ndo
, "mresp %lu: %s to %s reply-to %s",
138 (u_long
)TR_GETQID(EXTRACT_32BITS(&tr
->tr_rttlqid
)),
139 ipaddr_string(ndo
, &tr
->tr_src
), ipaddr_string(ndo
, &tr
->tr_dst
),
140 ipaddr_string(ndo
, &tr
->tr_raddr
)));
141 if (IN_CLASSD(EXTRACT_32BITS(&tr
->tr_raddr
)))
142 ND_PRINT((ndo
, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr
->tr_rttlqid
))));
145 ND_PRINT((ndo
, "%s", tstr
));
149 print_igmpv3_report(netdissect_options
*ndo
,
150 register const u_char
*bp
, register u_int len
)
152 u_int group
, nsrcs
, ngroups
;
155 /* Minimum len is 16, and should be a multiple of 4 */
156 if (len
< 16 || len
& 0x03) {
157 ND_PRINT((ndo
, " [invalid len %d]", len
));
160 ND_TCHECK2(bp
[6], 2);
161 ngroups
= EXTRACT_16BITS(&bp
[6]);
162 ND_PRINT((ndo
, ", %d group record(s)", ngroups
));
163 if (ndo
->ndo_vflag
> 0) {
164 /* Print the group records */
166 for (i
=0; i
<ngroups
; i
++) {
168 ND_PRINT((ndo
, " [invalid number of groups]"));
171 ND_TCHECK2(bp
[group
+4], 4);
172 ND_PRINT((ndo
, " [gaddr %s", ipaddr_string(ndo
, &bp
[group
+4])));
173 ND_PRINT((ndo
, " %s", tok2str(igmpv3report2str
, " [v3-report-#%d]",
175 nsrcs
= EXTRACT_16BITS(&bp
[group
+2]);
176 /* Check the number of sources and print them */
177 if (len
< group
+8+(nsrcs
<<2)) {
178 ND_PRINT((ndo
, " [invalid number of sources %d]", nsrcs
));
181 if (ndo
->ndo_vflag
== 1)
182 ND_PRINT((ndo
, ", %d source(s)", nsrcs
));
184 /* Print the sources */
185 ND_PRINT((ndo
, " {"));
186 for (j
=0; j
<nsrcs
; j
++) {
187 ND_TCHECK2(bp
[group
+8+(j
<<2)], 4);
188 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &bp
[group
+8+(j
<<2)])));
190 ND_PRINT((ndo
, " }"));
192 /* Next group record */
193 group
+= 8 + (nsrcs
<< 2);
194 ND_PRINT((ndo
, "]"));
199 ND_PRINT((ndo
, "%s", tstr
));
203 print_igmpv3_query(netdissect_options
*ndo
,
204 register const u_char
*bp
, register u_int len
)
211 ND_PRINT((ndo
, " v3"));
212 /* Minimum len is 12, and should be a multiple of 4 */
213 if (len
< 12 || len
& 0x03) {
214 ND_PRINT((ndo
, " [invalid len %d]", len
));
222 mrt
= ((mrc
& 0x0f) | 0x10) << (((mrc
& 0x70) >> 4) + 3);
225 ND_PRINT((ndo
, " [max resp time "));
227 ND_PRINT((ndo
, "%.1fs", mrt
* 0.1));
229 relts_print(ndo
, mrt
/ 10);
231 ND_PRINT((ndo
, "]"));
233 ND_TCHECK2(bp
[4], 4);
234 if (EXTRACT_32BITS(&bp
[4]) == 0)
236 ND_PRINT((ndo
, " [gaddr %s", ipaddr_string(ndo
, &bp
[4])));
237 ND_TCHECK2(bp
[10], 2);
238 nsrcs
= EXTRACT_16BITS(&bp
[10]);
240 if (len
< 12 + (nsrcs
<< 2))
241 ND_PRINT((ndo
, " [invalid number of sources]"));
242 else if (ndo
->ndo_vflag
> 1) {
243 ND_PRINT((ndo
, " {"));
244 for (i
=0; i
<nsrcs
; i
++) {
245 ND_TCHECK2(bp
[12+(i
<<2)], 4);
246 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &bp
[12+(i
<<2)])));
248 ND_PRINT((ndo
, " }"));
250 ND_PRINT((ndo
, ", %d source(s)", nsrcs
));
252 ND_PRINT((ndo
, "]"));
255 ND_PRINT((ndo
, "%s", tstr
));
259 igmp_print(netdissect_options
*ndo
,
260 register const u_char
*bp
, register u_int len
)
262 struct cksum_vec vec
[1];
264 if (ndo
->ndo_qflag
) {
265 ND_PRINT((ndo
, "igmp"));
272 ND_PRINT((ndo
, "igmp query"));
274 print_igmpv3_query(ndo
, bp
, len
);
278 ND_PRINT((ndo
, " v2"));
280 ND_PRINT((ndo
, " [max resp time %d]", bp
[1]));
282 ND_PRINT((ndo
, " v1"));
283 ND_TCHECK2(bp
[4], 4);
284 if (EXTRACT_32BITS(&bp
[4]))
285 ND_PRINT((ndo
, " [gaddr %s]", ipaddr_string(ndo
, &bp
[4])));
287 ND_PRINT((ndo
, " [len %d]", len
));
291 ND_TCHECK2(bp
[4], 4);
292 ND_PRINT((ndo
, "igmp v1 report %s", ipaddr_string(ndo
, &bp
[4])));
294 ND_PRINT((ndo
, " [len %d]", len
));
297 ND_TCHECK2(bp
[4], 4);
298 ND_PRINT((ndo
, "igmp v2 report %s", ipaddr_string(ndo
, &bp
[4])));
301 ND_PRINT((ndo
, "igmp v3 report"));
302 print_igmpv3_report(ndo
, bp
, len
);
305 ND_TCHECK2(bp
[4], 4);
306 ND_PRINT((ndo
, "igmp leave %s", ipaddr_string(ndo
, &bp
[4])));
309 ND_PRINT((ndo
, "igmp dvmrp"));
311 ND_PRINT((ndo
, " [len %d]", len
));
313 dvmrp_print(ndo
, bp
, len
);
316 ND_PRINT((ndo
, "igmp pimv1"));
317 pimv1_print(ndo
, bp
, len
);
320 print_mresp(ndo
, bp
, len
);
323 print_mtrace(ndo
, bp
, len
);
326 ND_PRINT((ndo
, "igmp-%d", bp
[0]));
330 if (ndo
->ndo_vflag
&& ND_TTEST2(bp
[0], len
)) {
331 /* Check the IGMP checksum */
334 if (in_cksum(vec
, 1))
335 ND_PRINT((ndo
, " bad igmp cksum %x!", EXTRACT_16BITS(&bp
[2])));
339 ND_PRINT((ndo
, "%s", tstr
));