]>
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.
26 #include <netdissect-stdinc.h>
28 #include "netdissect.h"
29 #include "addrtoname.h"
33 #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
36 static const char tstr
[] = "[|igmp]";
38 /* (following from ipmulti/mrouted/prune.h) */
41 * The packet format for a traceroute request.
44 uint32_t tr_src
; /* traceroute source */
45 uint32_t tr_dst
; /* traceroute destination */
46 uint32_t tr_raddr
; /* traceroute response address */
47 uint32_t tr_rttlqid
; /* response ttl and qid */
50 #define TR_GETTTL(x) (int)(((x) >> 24) & 0xff)
51 #define TR_GETQID(x) ((x) & 0x00ffffff)
54 * Traceroute response format. A traceroute response has a tr_query at the
55 * beginning, followed by one tr_resp for each hop taken.
58 uint32_t tr_qarr
; /* query arrival time */
59 uint32_t tr_inaddr
; /* incoming interface address */
60 uint32_t tr_outaddr
; /* outgoing interface address */
61 uint32_t tr_rmtaddr
; /* parent address in source tree */
62 uint32_t tr_vifin
; /* input packet count on interface */
63 uint32_t tr_vifout
; /* output packet count on interface */
64 uint32_t tr_pktcnt
; /* total incoming packets for src-grp */
65 uint8_t tr_rproto
; /* routing proto deployed on router */
66 uint8_t tr_fttl
; /* ttl required to forward on outvif */
67 uint8_t tr_smask
; /* subnet mask for src addr */
68 uint8_t tr_rflags
; /* forwarding error codes */
71 /* defs within mtrace */
75 /* fields for tr_rflags (forwarding error codes) */
83 #define TR_NO_SPACE 0x81
84 #define TR_OLD_ROUTER 0x82
86 /* fields for tr_rproto (routing protocol) */
87 #define TR_PROTO_DVMRP 1
88 #define TR_PROTO_MOSPF 2
89 #define TR_PROTO_PIM 3
90 #define TR_PROTO_CBT 4
92 /* igmpv3 report types */
93 static const struct tok igmpv3report2str
[] = {
104 print_mtrace(netdissect_options
*ndo
,
105 register const u_char
*bp
, register u_int len
)
107 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
110 if (len
< 8 + sizeof (struct tr_query
)) {
111 ND_PRINT((ndo
, " [invalid len %d]", len
));
114 ND_PRINT((ndo
, "mtrace %u: %s to %s reply-to %s",
115 TR_GETQID(EXTRACT_32BITS(&tr
->tr_rttlqid
)),
116 ipaddr_string(ndo
, &tr
->tr_src
), ipaddr_string(ndo
, &tr
->tr_dst
),
117 ipaddr_string(ndo
, &tr
->tr_raddr
)));
118 if (IN_CLASSD(EXTRACT_32BITS(&tr
->tr_raddr
)))
119 ND_PRINT((ndo
, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr
->tr_rttlqid
))));
122 ND_PRINT((ndo
, "%s", tstr
));
126 print_mresp(netdissect_options
*ndo
,
127 register const u_char
*bp
, register u_int len
)
129 register const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
132 if (len
< 8 + sizeof (struct tr_query
)) {
133 ND_PRINT((ndo
, " [invalid len %d]", len
));
136 ND_PRINT((ndo
, "mresp %lu: %s to %s reply-to %s",
137 (u_long
)TR_GETQID(EXTRACT_32BITS(&tr
->tr_rttlqid
)),
138 ipaddr_string(ndo
, &tr
->tr_src
), ipaddr_string(ndo
, &tr
->tr_dst
),
139 ipaddr_string(ndo
, &tr
->tr_raddr
)));
140 if (IN_CLASSD(EXTRACT_32BITS(&tr
->tr_raddr
)))
141 ND_PRINT((ndo
, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr
->tr_rttlqid
))));
144 ND_PRINT((ndo
, "%s", tstr
));
148 print_igmpv3_report(netdissect_options
*ndo
,
149 register const u_char
*bp
, register u_int len
)
151 u_int group
, nsrcs
, ngroups
;
154 /* Minimum len is 16, and should be a multiple of 4 */
155 if (len
< 16 || len
& 0x03) {
156 ND_PRINT((ndo
, " [invalid len %d]", len
));
159 ND_TCHECK2(bp
[6], 2);
160 ngroups
= EXTRACT_16BITS(&bp
[6]);
161 ND_PRINT((ndo
, ", %d group record(s)", ngroups
));
162 if (ndo
->ndo_vflag
> 0) {
163 /* Print the group records */
165 for (i
=0; i
<ngroups
; i
++) {
167 ND_PRINT((ndo
, " [invalid number of groups]"));
170 ND_TCHECK2(bp
[group
+4], 4);
171 ND_PRINT((ndo
, " [gaddr %s", ipaddr_string(ndo
, &bp
[group
+4])));
172 ND_PRINT((ndo
, " %s", tok2str(igmpv3report2str
, " [v3-report-#%d]",
174 nsrcs
= EXTRACT_16BITS(&bp
[group
+2]);
175 /* Check the number of sources and print them */
176 if (len
< group
+8+(nsrcs
<<2)) {
177 ND_PRINT((ndo
, " [invalid number of sources %d]", nsrcs
));
180 if (ndo
->ndo_vflag
== 1)
181 ND_PRINT((ndo
, ", %d source(s)", nsrcs
));
183 /* Print the sources */
184 ND_PRINT((ndo
, " {"));
185 for (j
=0; j
<nsrcs
; j
++) {
186 ND_TCHECK2(bp
[group
+8+(j
<<2)], 4);
187 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &bp
[group
+8+(j
<<2)])));
189 ND_PRINT((ndo
, " }"));
191 /* Next group record */
192 group
+= 8 + (nsrcs
<< 2);
193 ND_PRINT((ndo
, "]"));
198 ND_PRINT((ndo
, "%s", tstr
));
202 print_igmpv3_query(netdissect_options
*ndo
,
203 register const u_char
*bp
, register u_int len
)
210 ND_PRINT((ndo
, " v3"));
211 /* Minimum len is 12, and should be a multiple of 4 */
212 if (len
< 12 || len
& 0x03) {
213 ND_PRINT((ndo
, " [invalid len %d]", len
));
221 mrt
= ((mrc
& 0x0f) | 0x10) << (((mrc
& 0x70) >> 4) + 3);
224 ND_PRINT((ndo
, " [max resp time "));
226 ND_PRINT((ndo
, "%.1fs", mrt
* 0.1));
228 relts_print(ndo
, mrt
/ 10);
230 ND_PRINT((ndo
, "]"));
232 ND_TCHECK2(bp
[4], 4);
233 if (EXTRACT_32BITS(&bp
[4]) == 0)
235 ND_PRINT((ndo
, " [gaddr %s", ipaddr_string(ndo
, &bp
[4])));
236 ND_TCHECK2(bp
[10], 2);
237 nsrcs
= EXTRACT_16BITS(&bp
[10]);
239 if (len
< 12 + (nsrcs
<< 2))
240 ND_PRINT((ndo
, " [invalid number of sources]"));
241 else if (ndo
->ndo_vflag
> 1) {
242 ND_PRINT((ndo
, " {"));
243 for (i
=0; i
<nsrcs
; i
++) {
244 ND_TCHECK2(bp
[12+(i
<<2)], 4);
245 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &bp
[12+(i
<<2)])));
247 ND_PRINT((ndo
, " }"));
249 ND_PRINT((ndo
, ", %d source(s)", nsrcs
));
251 ND_PRINT((ndo
, "]"));
254 ND_PRINT((ndo
, "%s", tstr
));
258 igmp_print(netdissect_options
*ndo
,
259 register const u_char
*bp
, register u_int len
)
261 struct cksum_vec vec
[1];
263 if (ndo
->ndo_qflag
) {
264 ND_PRINT((ndo
, "igmp"));
271 ND_PRINT((ndo
, "igmp query"));
273 print_igmpv3_query(ndo
, bp
, len
);
277 ND_PRINT((ndo
, " v2"));
279 ND_PRINT((ndo
, " [max resp time %d]", bp
[1]));
281 ND_PRINT((ndo
, " v1"));
282 ND_TCHECK2(bp
[4], 4);
283 if (EXTRACT_32BITS(&bp
[4]))
284 ND_PRINT((ndo
, " [gaddr %s]", ipaddr_string(ndo
, &bp
[4])));
286 ND_PRINT((ndo
, " [len %d]", len
));
290 ND_TCHECK2(bp
[4], 4);
291 ND_PRINT((ndo
, "igmp v1 report %s", ipaddr_string(ndo
, &bp
[4])));
293 ND_PRINT((ndo
, " [len %d]", len
));
296 ND_TCHECK2(bp
[4], 4);
297 ND_PRINT((ndo
, "igmp v2 report %s", ipaddr_string(ndo
, &bp
[4])));
300 ND_PRINT((ndo
, "igmp v3 report"));
301 print_igmpv3_report(ndo
, bp
, len
);
304 ND_TCHECK2(bp
[4], 4);
305 ND_PRINT((ndo
, "igmp leave %s", ipaddr_string(ndo
, &bp
[4])));
308 ND_PRINT((ndo
, "igmp dvmrp"));
310 ND_PRINT((ndo
, " [len %d]", len
));
312 dvmrp_print(ndo
, bp
, len
);
315 ND_PRINT((ndo
, "igmp pimv1"));
316 pimv1_print(ndo
, bp
, len
);
319 print_mresp(ndo
, bp
, len
);
322 print_mtrace(ndo
, bp
, len
);
325 ND_PRINT((ndo
, "igmp-%d", bp
[0]));
329 if (ndo
->ndo_vflag
&& ND_TTEST2(bp
[0], len
)) {
330 /* Check the IGMP checksum */
333 if (in_cksum(vec
, 1))
334 ND_PRINT((ndo
, " bad igmp cksum %x!", EXTRACT_16BITS(&bp
[2])));
338 ND_PRINT((ndo
, "%s", tstr
));