2001-12-23 21:36:58 +00:00
|
|
|
/* packet-mrdisc.c 2001 Ronnie Sahlberg <See AUTHORS for email>
|
2001-06-27 20:19:19 +00:00
|
|
|
* Routines for IGMP/MRDISC packet disassembly
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2001-06-27 20:19:19 +00:00
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-06-27 20:19:19 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-06-27 20:19:19 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-06-27 20:19:19 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-06-27 20:19:19 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
MRDISC
|
2002-08-28 21:04:11 +00:00
|
|
|
code
|
2001-06-27 20:19:19 +00:00
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
0x24 x
|
2001-06-27 20:19:19 +00:00
|
|
|
0x25 x
|
|
|
|
0x26 x
|
|
|
|
|
|
|
|
MRDISC : IGMP Multicast Router DISCovery
|
|
|
|
Defined in draft-ietf-idmr-igmp-mrdisc-06.txt
|
|
|
|
TTL==1 and IP.DST==224.0.0.2 for all packets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
2002-02-01 11:01:57 +00:00
|
|
|
#include "packet-igmp.h"
|
2001-06-27 20:19:19 +00:00
|
|
|
#include "packet-mrdisc.h"
|
|
|
|
|
|
|
|
|
|
|
|
static int proto_mrdisc = -1;
|
|
|
|
static int hf_checksum = -1;
|
|
|
|
static int hf_checksum_bad = -1;
|
|
|
|
static int hf_type = -1;
|
|
|
|
static int hf_advint = -1;
|
|
|
|
static int hf_numopts = -1;
|
|
|
|
static int hf_options = -1;
|
|
|
|
static int hf_option = -1;
|
|
|
|
static int hf_option_len = -1;
|
|
|
|
static int hf_qi = -1;
|
|
|
|
static int hf_rv = -1;
|
|
|
|
static int hf_option_bytes = -1;
|
|
|
|
|
|
|
|
static int ett_mrdisc = -1;
|
|
|
|
static int ett_options = -1;
|
|
|
|
|
|
|
|
#define MRDISC_MRA 0x24
|
|
|
|
#define MRDISC_MRS 0x25
|
|
|
|
#define MRDISC_MRT 0x26
|
|
|
|
static const value_string mrdisc_types[] = {
|
|
|
|
{MRDISC_MRA, "Multicast Router Advertisement"},
|
|
|
|
{MRDISC_MRS, "Multicast Router Solicitation"},
|
|
|
|
{MRDISC_MRT, "Multicast Router Termination"},
|
|
|
|
{0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MRDISC_QI 0x01
|
|
|
|
#define MRDISC_RV 0x02
|
|
|
|
static const value_string mrdisc_options[] = {
|
|
|
|
{MRDISC_QI, "Query Interval"},
|
|
|
|
{MRDISC_RV, "Robustness Variable"},
|
|
|
|
{0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
dissect_mrdisc_mra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
|
|
|
|
{
|
|
|
|
guint16 num;
|
|
|
|
|
|
|
|
/* Advertising Interval */
|
2001-07-16 05:16:58 +00:00
|
|
|
proto_tree_add_item(parent_tree, hf_advint, tvb, offset, 1, FALSE);
|
2001-06-27 20:19:19 +00:00
|
|
|
offset += 1;
|
|
|
|
|
|
|
|
/* checksum */
|
2002-02-01 11:01:57 +00:00
|
|
|
igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
|
2001-06-27 20:19:19 +00:00
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
/* skip unused bytes */
|
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
/* number of options */
|
|
|
|
num = tvb_get_ntohs(tvb, offset);
|
|
|
|
proto_tree_add_uint(parent_tree, hf_numopts, tvb,
|
|
|
|
offset, 2, num);
|
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
/* process any options */
|
|
|
|
while (num--) {
|
|
|
|
proto_tree *tree;
|
|
|
|
proto_item *item;
|
|
|
|
guint8 type,len;
|
|
|
|
int old_offset = offset;
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
item = proto_tree_add_item(parent_tree, hf_options,
|
Allow a length of -1 to be specified when adding FT_NONE and FT_PROTOCOL
items to the protocol tree; it's interpreted as "the rest of the data in
the tvbuff". This can be used if
1) the item covers the entire packet or the remaining payload in
the packet
or
2) the item's length won't be known until it's dissected, and
will be then set with "proto_item_set_len()" - if an
exception is thrown in the dissection, it means the item ran
*past* the end of the tvbuff, so saying it runs to the end of
the tvbuff is reasonable.
Convert a number of "proto_tree_add_XXX()" calls using
"tvb_length_remaining()", values derived from the result of
"tvb_length()", or 0 (in the case of items whose length is unknown) to
use -1 instead (using 0 means that if an exception is thrown, selecting
the item highlights nothing; using -1 means it highlights all the data
for that item that's available).
In some places where "tvb_length()" or "tvb_length_remaining()" was used
to determine how large a packet is, use "tvb_reported_length()" or
"tvb_reported_length_remaining()", instead - the first two calls
indicate how much captured data was in the packet, the latter two calls
indicate how large the packet actually was (and the fact that using the
latter could cause BoundsError exceptions to be thrown is a feature - if
such an exception is thrown, the frame really *was* short, and it should
be tagged as such).
Replace some "proto_tree_add_XXX()" calls with equivalent
"proto_tree_add_item()" calls.
Fix some indentation.
svn path=/trunk/; revision=4578
2002-01-20 22:12:39 +00:00
|
|
|
tvb, offset, -1, FALSE);
|
2001-06-27 20:19:19 +00:00
|
|
|
tree = proto_item_add_subtree(item, ett_options);
|
|
|
|
|
|
|
|
type = tvb_get_guint8(tvb, offset);
|
|
|
|
proto_tree_add_uint(tree, hf_option, tvb, offset, 1, type);
|
|
|
|
offset += 1;
|
|
|
|
|
|
|
|
len = tvb_get_guint8(tvb, offset);
|
|
|
|
proto_tree_add_uint(tree, hf_option_len, tvb, offset, 1, len);
|
|
|
|
offset += 1;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MRDISC_QI:
|
|
|
|
if (item) {
|
|
|
|
proto_item_set_text(item,"Option: %s == %d",
|
|
|
|
val_to_str(type, mrdisc_options, "unknown %x"),
|
|
|
|
tvb_get_ntohs(tvb, offset));
|
|
|
|
}
|
|
|
|
|
2005-04-29 03:35:38 +00:00
|
|
|
if (len != 2)
|
|
|
|
THROW(ReportedBoundsError);
|
2001-07-16 05:16:58 +00:00
|
|
|
proto_tree_add_item(tree, hf_qi, tvb, offset, len,
|
|
|
|
FALSE);
|
2001-06-27 20:19:19 +00:00
|
|
|
offset += len;
|
|
|
|
break;
|
|
|
|
case MRDISC_RV:
|
|
|
|
if (item) {
|
|
|
|
proto_item_set_text(item,"Option: %s == %d",
|
|
|
|
val_to_str(type, mrdisc_options, "unknown %x"),
|
|
|
|
tvb_get_ntohs(tvb, offset));
|
|
|
|
}
|
|
|
|
|
2005-04-29 03:35:38 +00:00
|
|
|
if (len != 2)
|
|
|
|
THROW(ReportedBoundsError);
|
2001-07-16 05:16:58 +00:00
|
|
|
proto_tree_add_item(tree, hf_rv, tvb, offset, len,
|
|
|
|
FALSE);
|
2001-06-27 20:19:19 +00:00
|
|
|
offset += len;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (item) {
|
|
|
|
proto_item_set_text(item,"Option: unknown");
|
|
|
|
}
|
|
|
|
|
2001-07-16 05:16:58 +00:00
|
|
|
proto_tree_add_item(tree, hf_option_bytes,
|
|
|
|
tvb, offset, len, FALSE);
|
2001-06-27 20:19:19 +00:00
|
|
|
offset += len;
|
|
|
|
}
|
|
|
|
if (item) {
|
|
|
|
proto_item_set_len(item, offset-old_offset);
|
|
|
|
}
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-06-27 20:19:19 +00:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
dissect_mrdisc_mrst(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
|
|
|
|
{
|
|
|
|
/* skip reserved byte */
|
|
|
|
offset += 1;
|
|
|
|
|
|
|
|
/* checksum */
|
2002-02-01 11:01:57 +00:00
|
|
|
igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
|
2001-06-27 20:19:19 +00:00
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This function is only called from the IGMP dissector */
|
|
|
|
int
|
|
|
|
dissect_mrdisc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
|
|
|
|
{
|
|
|
|
proto_tree *tree;
|
|
|
|
proto_item *item;
|
|
|
|
guint8 type;
|
|
|
|
|
2003-11-16 23:17:27 +00:00
|
|
|
if (!proto_is_protocol_enabled(find_protocol_by_id(proto_mrdisc))) {
|
2001-06-27 20:19:19 +00:00
|
|
|
/* we are not enabled, skip entire packet to be nice
|
|
|
|
to the igmp layer. (so clicking on IGMP will display the data)
|
|
|
|
*/
|
|
|
|
return offset+tvb_length_remaining(tvb, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
item = proto_tree_add_item(parent_tree, proto_mrdisc, tvb, offset, 0, FALSE);
|
|
|
|
tree = proto_item_add_subtree(item, ett_mrdisc);
|
|
|
|
|
|
|
|
|
2009-08-09 07:59:51 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "MRDISC");
|
2009-08-09 08:14:59 +00:00
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
2001-06-27 20:19:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
type = tvb_get_guint8(tvb, offset);
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO)) {
|
2007-10-23 05:50:00 +00:00
|
|
|
col_add_str(pinfo->cinfo, COL_INFO,
|
|
|
|
val_to_str(type, mrdisc_types,
|
2001-06-27 20:19:19 +00:00
|
|
|
"Unknown Type:0x%02x"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* type of command */
|
|
|
|
proto_tree_add_uint(tree, hf_type, tvb, offset, 1, type);
|
|
|
|
offset += 1;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MRDISC_MRA:
|
|
|
|
offset = dissect_mrdisc_mra(tvb, pinfo, tree, offset);
|
|
|
|
break;
|
|
|
|
case MRDISC_MRS:
|
|
|
|
case MRDISC_MRT:
|
|
|
|
/* MRS and MRT packets looks the same */
|
|
|
|
offset = dissect_mrdisc_mrst(tvb, pinfo, tree, offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_mrdisc(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_type,
|
|
|
|
{ "Type", "mrdisc.type", FT_UINT8, BASE_HEX,
|
|
|
|
VALS(mrdisc_types), 0, "MRDISC Packet Type", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_checksum,
|
|
|
|
{ "Checksum", "mrdisc.checksum", FT_UINT16, BASE_HEX,
|
|
|
|
NULL, 0, "MRDISC Checksum", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_checksum_bad,
|
|
|
|
{ "Bad Checksum", "mrdisc.checksum_bad", FT_BOOLEAN, BASE_NONE,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, 0x0, "Bad MRDISC Checksum", HFILL }},
|
2001-06-27 20:19:19 +00:00
|
|
|
|
|
|
|
{ &hf_advint,
|
|
|
|
{ "Advertising Interval", "mrdisc.adv_int", FT_UINT8, BASE_DEC,
|
|
|
|
NULL, 0, "MRDISC Advertising Interval in seconds", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_numopts,
|
|
|
|
{ "Number Of Options", "mrdisc.num_opts", FT_UINT16, BASE_DEC,
|
|
|
|
NULL, 0, "MRDISC Number Of Options", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_options,
|
|
|
|
{ "Options", "mrdisc.options", FT_NONE, BASE_NONE,
|
|
|
|
NULL, 0, "MRDISC Options", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_option,
|
|
|
|
{ "Option", "mrdisc.option", FT_UINT8, BASE_DEC,
|
|
|
|
VALS(mrdisc_options), 0, "MRDISC Option Type", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_option_len,
|
|
|
|
{ "Length", "mrdisc.opt_len", FT_UINT8, BASE_DEC,
|
|
|
|
NULL, 0, "MRDISC Option Length", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_qi,
|
|
|
|
{ "Query Interval", "mrdisc.query_int", FT_UINT16, BASE_DEC,
|
|
|
|
NULL, 0, "MRDISC Query Interval", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_rv,
|
|
|
|
{ "Robustness Variable", "mrdisc.rob_var", FT_UINT16, BASE_DEC,
|
|
|
|
NULL, 0, "MRDISC Robustness Variable", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_option_bytes,
|
|
|
|
{ "Data", "mrdisc.option_data", FT_BYTES, BASE_NONE,
|
|
|
|
NULL, 0, "MRDISC Unknown Option Data", HFILL }},
|
|
|
|
|
|
|
|
};
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_mrdisc,
|
|
|
|
&ett_options,
|
|
|
|
};
|
|
|
|
|
|
|
|
proto_mrdisc = proto_register_protocol("Multicast Router DISCovery protocol",
|
|
|
|
"MRDISC", "mrdisc");
|
|
|
|
proto_register_field_array(proto_mrdisc, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
}
|