1 /* packet-mrdisc.c 2001 Ronnie Sahlberg <See AUTHORS for email>
2 * Routines for IGMP/MRDISC packet disassembly
4 * $Id: packet-mrdisc.c,v 1.9 2002/08/28 21:00:22 jmayer Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 MRDISC : IGMP Multicast Router DISCovery
35 Defined in draft-ietf-idmr-igmp-mrdisc-06.txt
36 TTL==1 and IP.DST==224.0.0.2 for all packets.
47 #include <epan/packet.h>
48 #include "packet-igmp.h"
49 #include "packet-mrdisc.h"
52 static int proto_mrdisc = -1;
53 static int hf_checksum = -1;
54 static int hf_checksum_bad = -1;
55 static int hf_type = -1;
56 static int hf_advint = -1;
57 static int hf_numopts = -1;
58 static int hf_options = -1;
59 static int hf_option = -1;
60 static int hf_option_len = -1;
61 static int hf_qi = -1;
62 static int hf_rv = -1;
63 static int hf_option_bytes = -1;
65 static int ett_mrdisc = -1;
66 static int ett_options = -1;
68 #define MRDISC_MRA 0x24
69 #define MRDISC_MRS 0x25
70 #define MRDISC_MRT 0x26
71 static const value_string mrdisc_types[] = {
72 {MRDISC_MRA, "Multicast Router Advertisement"},
73 {MRDISC_MRS, "Multicast Router Solicitation"},
74 {MRDISC_MRT, "Multicast Router Termination"},
78 #define MRDISC_QI 0x01
79 #define MRDISC_RV 0x02
80 static const value_string mrdisc_options[] = {
81 {MRDISC_QI, "Query Interval"},
82 {MRDISC_RV, "Robustness Variable"},
88 dissect_mrdisc_mra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
92 /* Advertising Interval */
93 proto_tree_add_item(parent_tree, hf_advint, tvb, offset, 1, FALSE);
97 igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
100 /* skip unused bytes */
103 /* number of options */
104 num = tvb_get_ntohs(tvb, offset);
105 proto_tree_add_uint(parent_tree, hf_numopts, tvb,
109 /* process any options */
114 int old_offset = offset;
116 item = proto_tree_add_item(parent_tree, hf_options,
117 tvb, offset, -1, FALSE);
118 tree = proto_item_add_subtree(item, ett_options);
120 type = tvb_get_guint8(tvb, offset);
121 proto_tree_add_uint(tree, hf_option, tvb, offset, 1, type);
124 len = tvb_get_guint8(tvb, offset);
125 proto_tree_add_uint(tree, hf_option_len, tvb, offset, 1, len);
131 proto_item_set_text(item,"Option: %s == %d",
132 val_to_str(type, mrdisc_options, "unknown %x"),
133 tvb_get_ntohs(tvb, offset));
136 proto_tree_add_item(tree, hf_qi, tvb, offset, len,
142 proto_item_set_text(item,"Option: %s == %d",
143 val_to_str(type, mrdisc_options, "unknown %x"),
144 tvb_get_ntohs(tvb, offset));
147 proto_tree_add_item(tree, hf_rv, tvb, offset, len,
153 proto_item_set_text(item,"Option: unknown");
156 proto_tree_add_item(tree, hf_option_bytes,
157 tvb, offset, len, FALSE);
161 proto_item_set_len(item, offset-old_offset);
170 dissect_mrdisc_mrst(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
172 /* skip reserved byte */
176 igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
183 /* This function is only called from the IGMP dissector */
185 dissect_mrdisc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
191 if (!proto_is_protocol_enabled(proto_mrdisc)) {
192 /* we are not enabled, skip entire packet to be nice
193 to the igmp layer. (so clicking on IGMP will display the data)
195 return offset+tvb_length_remaining(tvb, offset);
198 item = proto_tree_add_item(parent_tree, proto_mrdisc, tvb, offset, 0, FALSE);
199 tree = proto_item_add_subtree(item, ett_mrdisc);
202 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
203 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MRDISC");
205 if (check_col(pinfo->cinfo, COL_INFO)) {
206 col_clear(pinfo->cinfo, COL_INFO);
210 type = tvb_get_guint8(tvb, offset);
211 if (check_col(pinfo->cinfo, COL_INFO)) {
212 col_add_fstr(pinfo->cinfo, COL_INFO,
213 "%s",val_to_str(type, mrdisc_types,
214 "Unknown Type:0x%02x"));
217 /* type of command */
218 proto_tree_add_uint(tree, hf_type, tvb, offset, 1, type);
223 offset = dissect_mrdisc_mra(tvb, pinfo, tree, offset);
227 /* MRS and MRT packets looks the same */
228 offset = dissect_mrdisc_mrst(tvb, pinfo, tree, offset);
236 proto_register_mrdisc(void)
238 static hf_register_info hf[] = {
240 { "Type", "mrdisc.type", FT_UINT8, BASE_HEX,
241 VALS(mrdisc_types), 0, "MRDISC Packet Type", HFILL }},
244 { "Checksum", "mrdisc.checksum", FT_UINT16, BASE_HEX,
245 NULL, 0, "MRDISC Checksum", HFILL }},
248 { "Bad Checksum", "mrdisc.checksum_bad", FT_BOOLEAN, BASE_NONE,
249 NULL, 0, "Bad MRDISC Checksum", HFILL }},
252 { "Advertising Interval", "mrdisc.adv_int", FT_UINT8, BASE_DEC,
253 NULL, 0, "MRDISC Advertising Interval in seconds", HFILL }},
256 { "Number Of Options", "mrdisc.num_opts", FT_UINT16, BASE_DEC,
257 NULL, 0, "MRDISC Number Of Options", HFILL }},
260 { "Options", "mrdisc.options", FT_NONE, BASE_NONE,
261 NULL, 0, "MRDISC Options", HFILL }},
264 { "Option", "mrdisc.option", FT_UINT8, BASE_DEC,
265 VALS(mrdisc_options), 0, "MRDISC Option Type", HFILL }},
268 { "Length", "mrdisc.opt_len", FT_UINT8, BASE_DEC,
269 NULL, 0, "MRDISC Option Length", HFILL }},
272 { "Query Interval", "mrdisc.query_int", FT_UINT16, BASE_DEC,
273 NULL, 0, "MRDISC Query Interval", HFILL }},
276 { "Robustness Variable", "mrdisc.rob_var", FT_UINT16, BASE_DEC,
277 NULL, 0, "MRDISC Robustness Variable", HFILL }},
280 { "Data", "mrdisc.option_data", FT_BYTES, BASE_NONE,
281 NULL, 0, "MRDISC Unknown Option Data", HFILL }},
284 static gint *ett[] = {
289 proto_mrdisc = proto_register_protocol("Multicast Router DISCovery protocol",
291 proto_register_field_array(proto_mrdisc, hf, array_length(hf));
292 proto_register_subtree_array(ett, array_length(ett));