]>
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 /* \summary: Internet Group Management Protocol (IGMP) printer */
29 * draft-asaeda-mboned-mtrace-v2 for the mtrace message
36 #include <netdissect-stdinc.h>
38 #include "netdissect.h"
39 #include "addrtoname.h"
43 #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
46 static const char tstr
[] = "[|igmp]";
48 /* (following from ipmulti/mrouted/prune.h) */
51 * The packet format for a traceroute request.
54 nd_uint32_t tr_src
; /* traceroute source */
55 nd_uint32_t tr_dst
; /* traceroute destination */
56 nd_uint32_t tr_raddr
; /* traceroute response address */
57 nd_uint8_t tr_rttl
; /* response ttl */
58 nd_uint24_t tr_qid
; /* qid */
62 * Traceroute response format. A traceroute response has a tr_query at the
63 * beginning, followed by one tr_resp for each hop taken.
66 uint32_t tr_qarr
; /* query arrival time */
67 uint32_t tr_inaddr
; /* incoming interface address */
68 uint32_t tr_outaddr
; /* outgoing interface address */
69 uint32_t tr_rmtaddr
; /* parent address in source tree */
70 uint32_t tr_vifin
; /* input packet count on interface */
71 uint32_t tr_vifout
; /* output packet count on interface */
72 uint32_t tr_pktcnt
; /* total incoming packets for src-grp */
73 uint8_t tr_rproto
; /* routing proto deployed on router */
74 uint8_t tr_fttl
; /* ttl required to forward on outvif */
75 uint8_t tr_smask
; /* subnet mask for src addr */
76 uint8_t tr_rflags
; /* forwarding error codes */
79 /* defs within mtrace */
83 /* fields for tr_rflags (forwarding error codes) */
91 #define TR_NO_SPACE 0x81
92 #define TR_OLD_ROUTER 0x82
94 /* fields for tr_rproto (routing protocol) */
95 #define TR_PROTO_DVMRP 1
96 #define TR_PROTO_MOSPF 2
97 #define TR_PROTO_PIM 3
98 #define TR_PROTO_CBT 4
100 /* igmpv3 report types */
101 static const struct tok igmpv3report2str
[] = {
112 print_mtrace(netdissect_options
*ndo
,
113 register const u_char
*bp
, register u_int len
)
115 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
118 if (len
< 8 + sizeof (struct tr_query
)) {
119 ND_PRINT((ndo
, " [invalid len %d]", len
));
122 ND_PRINT((ndo
, "mtrace %u: %s to %s reply-to %s",
123 EXTRACT_BE_U_3(tr
->tr_qid
),
124 ipaddr_string(ndo
, tr
->tr_src
), ipaddr_string(ndo
, tr
->tr_dst
),
125 ipaddr_string(ndo
, tr
->tr_raddr
)));
126 if (IN_CLASSD(EXTRACT_BE_U_4(tr
->tr_raddr
)))
127 ND_PRINT((ndo
, " with-ttl %u", EXTRACT_U_1(&tr
->tr_rttl
)));
130 ND_PRINT((ndo
, "%s", tstr
));
134 print_mresp(netdissect_options
*ndo
,
135 register const u_char
*bp
, register u_int len
)
137 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
140 if (len
< 8 + sizeof (struct tr_query
)) {
141 ND_PRINT((ndo
, " [invalid len %d]", len
));
144 ND_PRINT((ndo
, "mresp %u: %s to %s reply-to %s",
145 EXTRACT_BE_U_3(tr
->tr_qid
),
146 ipaddr_string(ndo
, tr
->tr_src
), ipaddr_string(ndo
, tr
->tr_dst
),
147 ipaddr_string(ndo
, tr
->tr_raddr
)));
148 if (IN_CLASSD(EXTRACT_BE_U_4(tr
->tr_raddr
)))
149 ND_PRINT((ndo
, " with-ttl %u", EXTRACT_U_1(&tr
->tr_rttl
)));
152 ND_PRINT((ndo
, "%s", tstr
));
156 print_igmpv3_report(netdissect_options
*ndo
,
157 register const u_char
*bp
, register u_int len
)
159 u_int group
, nsrcs
, ngroups
;
162 /* Minimum len is 16, and should be a multiple of 4 */
163 if (len
< 16 || len
& 0x03) {
164 ND_PRINT((ndo
, " [invalid len %d]", len
));
168 ngroups
= EXTRACT_BE_U_2(bp
+ 6);
169 ND_PRINT((ndo
, ", %d group record(s)", ngroups
));
170 if (ndo
->ndo_vflag
> 0) {
171 /* Print the group records */
173 for (i
=0; i
<ngroups
; i
++) {
175 ND_PRINT((ndo
, " [invalid number of groups]"));
178 ND_TCHECK_4(bp
+ (group
+ 4));
179 ND_PRINT((ndo
, " [gaddr %s", ipaddr_string(ndo
, bp
+ group
+ 4)));
180 ND_PRINT((ndo
, " %s", tok2str(igmpv3report2str
, " [v3-report-#%d]",
181 EXTRACT_U_1(bp
+ group
))));
182 nsrcs
= EXTRACT_BE_U_2(bp
+ group
+ 2);
183 /* Check the number of sources and print them */
184 if (len
< group
+8+(nsrcs
<<2)) {
185 ND_PRINT((ndo
, " [invalid number of sources %d]", nsrcs
));
188 if (ndo
->ndo_vflag
== 1)
189 ND_PRINT((ndo
, ", %d source(s)", nsrcs
));
191 /* Print the sources */
192 ND_PRINT((ndo
, " {"));
193 for (j
=0; j
<nsrcs
; j
++) {
194 ND_TCHECK_4(bp
+ (group
+ 8 + (j
<< 2)));
195 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, bp
+ group
+ 8 + (j
<< 2))));
197 ND_PRINT((ndo
, " }"));
199 /* Next group record */
200 group
+= 8 + (nsrcs
<< 2);
201 ND_PRINT((ndo
, "]"));
206 ND_PRINT((ndo
, "%s", tstr
));
210 print_igmpv3_query(netdissect_options
*ndo
,
211 register const u_char
*bp
, register u_int len
)
218 ND_PRINT((ndo
, " v3"));
219 /* Minimum len is 12, and should be a multiple of 4 */
220 if (len
< 12 || len
& 0x03) {
221 ND_PRINT((ndo
, " [invalid len %d]", len
));
225 mrc
= EXTRACT_U_1(bp
+ 1);
229 mrt
= ((mrc
& 0x0f) | 0x10) << (((mrc
& 0x70) >> 4) + 3);
232 ND_PRINT((ndo
, " [max resp time "));
234 ND_PRINT((ndo
, "%.1fs", mrt
* 0.1));
236 unsigned_relts_print(ndo
, mrt
/ 10);
238 ND_PRINT((ndo
, "]"));
241 if (EXTRACT_BE_U_4(bp
+ 4) == 0)
243 ND_PRINT((ndo
, " [gaddr %s", ipaddr_string(ndo
, bp
+ 4)));
244 ND_TCHECK_2(bp
+ 10);
245 nsrcs
= EXTRACT_BE_U_2(bp
+ 10);
247 if (len
< 12 + (nsrcs
<< 2))
248 ND_PRINT((ndo
, " [invalid number of sources]"));
249 else if (ndo
->ndo_vflag
> 1) {
250 ND_PRINT((ndo
, " {"));
251 for (i
=0; i
<nsrcs
; i
++) {
252 ND_TCHECK_4(bp
+ (12 + (i
<< 2)));
253 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, bp
+ 12 + (i
<< 2))));
255 ND_PRINT((ndo
, " }"));
257 ND_PRINT((ndo
, ", %d source(s)", nsrcs
));
259 ND_PRINT((ndo
, "]"));
262 ND_PRINT((ndo
, "%s", tstr
));
266 igmp_print(netdissect_options
*ndo
,
267 register const u_char
*bp
, register u_int len
)
269 struct cksum_vec vec
[1];
271 if (ndo
->ndo_qflag
) {
272 ND_PRINT((ndo
, "igmp"));
277 switch (EXTRACT_U_1(bp
)) {
279 ND_PRINT((ndo
, "igmp query"));
281 print_igmpv3_query(ndo
, bp
, len
);
284 if (EXTRACT_U_1(bp
+ 1)) {
285 ND_PRINT((ndo
, " v2"));
286 if (EXTRACT_U_1(bp
+ 1) != 100)
287 ND_PRINT((ndo
, " [max resp time %u]", EXTRACT_U_1(bp
+ 1)));
289 ND_PRINT((ndo
, " v1"));
291 if (EXTRACT_BE_U_4(bp
+ 4))
292 ND_PRINT((ndo
, " [gaddr %s]", ipaddr_string(ndo
, bp
+ 4)));
294 ND_PRINT((ndo
, " [len %d]", len
));
299 ND_PRINT((ndo
, "igmp v1 report %s", ipaddr_string(ndo
, bp
+ 4)));
301 ND_PRINT((ndo
, " [len %d]", len
));
305 ND_PRINT((ndo
, "igmp v2 report %s", ipaddr_string(ndo
, bp
+ 4)));
308 ND_PRINT((ndo
, "igmp v3 report"));
309 print_igmpv3_report(ndo
, bp
, len
);
313 ND_PRINT((ndo
, "igmp leave %s", ipaddr_string(ndo
, bp
+ 4)));
316 ND_PRINT((ndo
, "igmp dvmrp"));
318 ND_PRINT((ndo
, " [len %d]", len
));
320 dvmrp_print(ndo
, bp
, len
);
323 ND_PRINT((ndo
, "igmp pimv1"));
324 pimv1_print(ndo
, bp
, len
);
327 print_mresp(ndo
, bp
, len
);
330 print_mtrace(ndo
, bp
, len
);
333 ND_PRINT((ndo
, "igmp-%d", EXTRACT_U_1(bp
)));
337 if (ndo
->ndo_vflag
&& len
>= 4 && ND_TTEST2(bp
[0], len
)) {
338 /* Check the IGMP checksum */
341 if (in_cksum(vec
, 1))
342 ND_PRINT((ndo
, " bad igmp cksum %x!", EXTRACT_BE_U_2(bp
+ 2)));
346 ND_PRINT((ndo
, "%s", tstr
));