]>
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
34 #include "netdissect-stdinc.h"
36 #include "netdissect.h"
37 #include "addrtoname.h"
41 #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
45 /* (following from ipmulti/mrouted/prune.h) */
48 * The packet format for a traceroute request.
51 nd_uint32_t tr_src
; /* traceroute source */
52 nd_uint32_t tr_dst
; /* traceroute destination */
53 nd_uint32_t tr_raddr
; /* traceroute response address */
54 nd_uint8_t tr_rttl
; /* response ttl */
55 nd_uint24_t tr_qid
; /* qid */
59 * Traceroute response format. A traceroute response has a tr_query at the
60 * beginning, followed by one tr_resp for each hop taken.
63 nd_uint32_t tr_qarr
; /* query arrival time */
64 nd_uint32_t tr_inaddr
; /* incoming interface address */
65 nd_uint32_t tr_outaddr
; /* outgoing interface address */
66 nd_uint32_t tr_rmtaddr
; /* parent address in source tree */
67 nd_uint32_t tr_vifin
; /* input packet count on interface */
68 nd_uint32_t tr_vifout
; /* output packet count on interface */
69 nd_uint32_t tr_pktcnt
; /* total incoming packets for src-grp */
70 nd_uint8_t tr_rproto
; /* routing proto deployed on router */
71 nd_uint8_t tr_fttl
; /* ttl required to forward on outvif */
72 nd_uint8_t tr_smask
; /* subnet mask for src addr */
73 nd_uint8_t tr_rflags
; /* forwarding error codes */
76 /* defs within mtrace */
80 /* fields for tr_rflags (forwarding error codes) */
88 #define TR_NO_SPACE 0x81
89 #define TR_OLD_ROUTER 0x82
91 /* fields for tr_rproto (routing protocol) */
92 #define TR_PROTO_DVMRP 1
93 #define TR_PROTO_MOSPF 2
94 #define TR_PROTO_PIM 3
95 #define TR_PROTO_CBT 4
97 /* igmpv3 report types */
98 static const struct tok igmpv3report2str
[] = {
109 print_mtrace(netdissect_options
*ndo
,
110 const char *typename
,
111 const u_char
*bp
, u_int len
)
113 const struct tr_query
*tr
= (const struct tr_query
*)(bp
+ 8);
115 if (len
< 8 + sizeof (struct tr_query
)) {
116 ND_PRINT(" [invalid len %u]", len
);
119 ND_PRINT("%s %u: %s to %s reply-to %s",
121 GET_BE_U_3(tr
->tr_qid
),
122 GET_IPADDR_STRING(tr
->tr_src
), GET_IPADDR_STRING(tr
->tr_dst
),
123 GET_IPADDR_STRING(tr
->tr_raddr
));
124 if (IN_CLASSD(GET_BE_U_4(tr
->tr_raddr
)))
125 ND_PRINT(" with-ttl %u", GET_U_1(tr
->tr_rttl
));
129 print_igmpv3_report(netdissect_options
*ndo
,
130 const u_char
*bp
, u_int len
)
132 u_int group
, nsrcs
, ngroups
;
135 /* Minimum len is 16, and should be a multiple of 4 */
136 if (len
< 16 || len
& 0x03) {
137 ND_PRINT(" [invalid len %u]", len
);
140 ngroups
= GET_BE_U_2(bp
+ 6);
141 ND_PRINT(", %u group record(s)", ngroups
);
142 if (ndo
->ndo_vflag
> 0) {
143 /* Print the group records */
145 for (i
=0; i
<ngroups
; i
++) {
147 ND_PRINT(" [invalid number of groups]");
150 ND_PRINT(" [gaddr %s", GET_IPADDR_STRING(bp
+ group
+ 4));
151 ND_PRINT(" %s", tok2str(igmpv3report2str
, " [v3-report-#%u]",
152 GET_U_1(bp
+ group
)));
153 nsrcs
= GET_BE_U_2(bp
+ group
+ 2);
154 /* Check the number of sources and print them */
155 if (len
< group
+8+(nsrcs
<<2)) {
156 ND_PRINT(" [invalid number of sources %u]", nsrcs
);
159 if (ndo
->ndo_vflag
== 1)
160 ND_PRINT(", %u source(s)", nsrcs
);
162 /* Print the sources */
164 for (j
=0; j
<nsrcs
; j
++) {
165 ND_PRINT(" %s", GET_IPADDR_STRING(bp
+ group
+ 8 + (j
<< 2)));
169 /* Next group record */
170 group
+= 8 + (nsrcs
<< 2);
177 print_igmpv3_query(netdissect_options
*ndo
,
178 const u_char
*bp
, u_int len
)
186 /* Minimum len is 12, and should be a multiple of 4 */
187 if (len
< 12 || len
& 0x03) {
188 ND_PRINT(" [invalid len %u]", len
);
191 mrc
= GET_U_1(bp
+ 1);
195 mrt
= ((mrc
& 0x0f) | 0x10) << (((mrc
& 0x70) >> 4) + 3);
198 ND_PRINT(" [max resp time ");
200 ND_PRINT("%.1fs", mrt
* 0.1);
202 unsigned_relts_print(ndo
, mrt
/ 10);
206 if (GET_BE_U_4(bp
+ 4) == 0)
208 ND_PRINT(" [gaddr %s", GET_IPADDR_STRING(bp
+ 4));
209 nsrcs
= GET_BE_U_2(bp
+ 10);
211 if (len
< 12 + (nsrcs
<< 2))
212 ND_PRINT(" [invalid number of sources]");
213 else if (ndo
->ndo_vflag
> 1) {
215 for (i
=0; i
<nsrcs
; i
++) {
216 ND_PRINT(" %s", GET_IPADDR_STRING(bp
+ 12 + (i
<< 2)));
220 ND_PRINT(", %u source(s)", nsrcs
);
226 igmp_print(netdissect_options
*ndo
,
227 const u_char
*bp
, u_int len
)
229 struct cksum_vec vec
[1];
231 ndo
->ndo_protocol
= "igmp";
232 if (ndo
->ndo_qflag
) {
237 switch (GET_U_1(bp
)) {
239 ND_PRINT("igmp query");
241 print_igmpv3_query(ndo
, bp
, len
);
243 if (GET_U_1(bp
+ 1)) {
245 if (GET_U_1(bp
+ 1) != 100)
246 ND_PRINT(" [max resp time %u]", GET_U_1(bp
+ 1));
249 if (GET_BE_U_4(bp
+ 4))
250 ND_PRINT(" [gaddr %s]", GET_IPADDR_STRING(bp
+ 4));
252 ND_PRINT(" [len %u]", len
);
256 ND_PRINT("igmp v1 report %s", GET_IPADDR_STRING(bp
+ 4));
258 ND_PRINT(" [len %u]", len
);
261 ND_PRINT("igmp v2 report %s", GET_IPADDR_STRING(bp
+ 4));
264 ND_PRINT("igmp v3 report");
265 print_igmpv3_report(ndo
, bp
, len
);
268 ND_PRINT("igmp leave %s", GET_IPADDR_STRING(bp
+ 4));
271 ND_PRINT("igmp dvmrp");
273 ND_PRINT(" [len %u]", len
);
275 dvmrp_print(ndo
, bp
, len
);
278 ND_PRINT("igmp pimv1");
279 pimv1_print(ndo
, bp
, len
);
282 print_mtrace(ndo
, "mresp", bp
, len
);
285 print_mtrace(ndo
, "mtrace", bp
, len
);
288 ND_PRINT("igmp-%u", GET_U_1(bp
));
292 if (ndo
->ndo_vflag
&& len
>= 4 && ND_TTEST_LEN(bp
, len
)) {
293 /* Check the IGMP checksum */
296 if (in_cksum(vec
, 1))
297 ND_PRINT(" bad igmp cksum %x!", GET_BE_U_2(bp
+ 2));