]>
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)
47 /* (following from ipmulti/mrouted/prune.h) */
50 * The packet format for a traceroute request.
53 nd_uint32_t tr_src
; /* traceroute source */
54 nd_uint32_t tr_dst
; /* traceroute destination */
55 nd_uint32_t tr_raddr
; /* traceroute response address */
56 nd_uint8_t tr_rttl
; /* response ttl */
57 nd_uint24_t tr_qid
; /* qid */
61 * Traceroute response format. A traceroute response has a tr_query at the
62 * beginning, followed by one tr_resp for each hop taken.
65 nd_uint32_t tr_qarr
; /* query arrival time */
66 nd_uint32_t tr_inaddr
; /* incoming interface address */
67 nd_uint32_t tr_outaddr
; /* outgoing interface address */
68 nd_uint32_t tr_rmtaddr
; /* parent address in source tree */
69 nd_uint32_t tr_vifin
; /* input packet count on interface */
70 nd_uint32_t tr_vifout
; /* output packet count on interface */
71 nd_uint32_t tr_pktcnt
; /* total incoming packets for src-grp */
72 nd_uint8_t tr_rproto
; /* routing proto deployed on router */
73 nd_uint8_t tr_fttl
; /* ttl required to forward on outvif */
74 nd_uint8_t tr_smask
; /* subnet mask for src addr */
75 nd_uint8_t tr_rflags
; /* forwarding error codes */
78 /* defs within mtrace */
82 /* fields for tr_rflags (forwarding error codes) */
90 #define TR_NO_SPACE 0x81
91 #define TR_OLD_ROUTER 0x82
93 /* fields for tr_rproto (routing protocol) */
94 #define TR_PROTO_DVMRP 1
95 #define TR_PROTO_MOSPF 2
96 #define TR_PROTO_PIM 3
97 #define TR_PROTO_CBT 4
99 /* igmpv3 report types */
100 static const struct tok igmpv3report2str
[] = {
111 print_mtrace(netdissect_options
*ndo
,
112 const u_char
*bp
, u_int len
)
114 const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
117 if (len
< 8 + sizeof (struct tr_query
)) {
118 ND_PRINT(" [invalid len %u]", len
);
121 ND_PRINT("mtrace %u: %s to %s reply-to %s",
122 GET_BE_U_3(tr
->tr_qid
),
123 GET_IPADDR_STRING(tr
->tr_src
), GET_IPADDR_STRING(tr
->tr_dst
),
124 GET_IPADDR_STRING(tr
->tr_raddr
));
125 if (IN_CLASSD(GET_BE_U_4(tr
->tr_raddr
)))
126 ND_PRINT(" with-ttl %u", GET_U_1(tr
->tr_rttl
));
133 print_mresp(netdissect_options
*ndo
,
134 const u_char
*bp
, u_int len
)
136 const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
139 if (len
< 8 + sizeof (struct tr_query
)) {
140 ND_PRINT(" [invalid len %u]", len
);
143 ND_PRINT("mresp %u: %s to %s reply-to %s",
144 GET_BE_U_3(tr
->tr_qid
),
145 GET_IPADDR_STRING(tr
->tr_src
), GET_IPADDR_STRING(tr
->tr_dst
),
146 GET_IPADDR_STRING(tr
->tr_raddr
));
147 if (IN_CLASSD(GET_BE_U_4(tr
->tr_raddr
)))
148 ND_PRINT(" with-ttl %u", GET_U_1(tr
->tr_rttl
));
155 print_igmpv3_report(netdissect_options
*ndo
,
156 const u_char
*bp
, u_int len
)
158 u_int group
, nsrcs
, ngroups
;
161 /* Minimum len is 16, and should be a multiple of 4 */
162 if (len
< 16 || len
& 0x03) {
163 ND_PRINT(" [invalid len %u]", len
);
166 ngroups
= GET_BE_U_2(bp
+ 6);
167 ND_PRINT(", %u 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(" [invalid number of groups]");
176 ND_TCHECK_4(bp
+ (group
+ 4));
177 ND_PRINT(" [gaddr %s", GET_IPADDR_STRING(bp
+ group
+ 4));
178 ND_PRINT(" %s", tok2str(igmpv3report2str
, " [v3-report-#%u]",
179 GET_U_1(bp
+ group
)));
180 nsrcs
= GET_BE_U_2(bp
+ group
+ 2);
181 /* Check the number of sources and print them */
182 if (len
< group
+8+(nsrcs
<<2)) {
183 ND_PRINT(" [invalid number of sources %u]", nsrcs
);
186 if (ndo
->ndo_vflag
== 1)
187 ND_PRINT(", %u source(s)", nsrcs
);
189 /* Print the sources */
191 for (j
=0; j
<nsrcs
; j
++) {
192 ND_TCHECK_4(bp
+ (group
+ 8 + (j
<< 2)));
193 ND_PRINT(" %s", GET_IPADDR_STRING(bp
+ group
+ 8 + (j
<< 2)));
197 /* Next group record */
198 group
+= 8 + (nsrcs
<< 2);
208 print_igmpv3_query(netdissect_options
*ndo
,
209 const u_char
*bp
, u_int len
)
217 /* Minimum len is 12, and should be a multiple of 4 */
218 if (len
< 12 || len
& 0x03) {
219 ND_PRINT(" [invalid len %u]", len
);
222 mrc
= GET_U_1(bp
+ 1);
226 mrt
= ((mrc
& 0x0f) | 0x10) << (((mrc
& 0x70) >> 4) + 3);
229 ND_PRINT(" [max resp time ");
231 ND_PRINT("%.1fs", mrt
* 0.1);
233 unsigned_relts_print(ndo
, mrt
/ 10);
237 if (GET_BE_U_4(bp
+ 4) == 0)
239 ND_PRINT(" [gaddr %s", GET_IPADDR_STRING(bp
+ 4));
240 nsrcs
= GET_BE_U_2(bp
+ 10);
242 if (len
< 12 + (nsrcs
<< 2))
243 ND_PRINT(" [invalid number of sources]");
244 else if (ndo
->ndo_vflag
> 1) {
246 for (i
=0; i
<nsrcs
; i
++) {
247 ND_TCHECK_4(bp
+ (12 + (i
<< 2)));
248 ND_PRINT(" %s", GET_IPADDR_STRING(bp
+ 12 + (i
<< 2)));
252 ND_PRINT(", %u source(s)", nsrcs
);
261 igmp_print(netdissect_options
*ndo
,
262 const u_char
*bp
, u_int len
)
264 struct cksum_vec vec
[1];
266 ndo
->ndo_protocol
= "igmp";
267 if (ndo
->ndo_qflag
) {
272 switch (GET_U_1(bp
)) {
274 ND_PRINT("igmp query");
276 print_igmpv3_query(ndo
, bp
, len
);
278 if (GET_U_1(bp
+ 1)) {
280 if (GET_U_1(bp
+ 1) != 100)
281 ND_PRINT(" [max resp time %u]", GET_U_1(bp
+ 1));
284 if (GET_BE_U_4(bp
+ 4))
285 ND_PRINT(" [gaddr %s]", GET_IPADDR_STRING(bp
+ 4));
287 ND_PRINT(" [len %u]", len
);
291 ND_PRINT("igmp v1 report %s", GET_IPADDR_STRING(bp
+ 4));
293 ND_PRINT(" [len %u]", len
);
296 ND_PRINT("igmp v2 report %s", GET_IPADDR_STRING(bp
+ 4));
299 ND_PRINT("igmp v3 report");
300 print_igmpv3_report(ndo
, bp
, len
);
303 ND_PRINT("igmp leave %s", GET_IPADDR_STRING(bp
+ 4));
306 ND_PRINT("igmp dvmrp");
308 ND_PRINT(" [len %u]", len
);
310 dvmrp_print(ndo
, bp
, len
);
313 ND_PRINT("igmp pimv1");
314 pimv1_print(ndo
, bp
, len
);
317 print_mresp(ndo
, bp
, len
);
320 print_mtrace(ndo
, bp
, len
);
323 ND_PRINT("igmp-%u", GET_U_1(bp
));
327 if (ndo
->ndo_vflag
&& len
>= 4 && ND_TTEST_LEN(bp
, len
)) {
328 /* Check the IGMP checksum */
331 if (in_cksum(vec
, 1))
332 ND_PRINT(" bad igmp cksum %x!", GET_BE_U_2(bp
+ 2));