1999-08-04 00:33:11 +00:00
|
|
|
/* packet-rip.c
|
1998-09-16 02:39:15 +00:00
|
|
|
* Routines for RIPv1 and RIPv2 packet disassembly
|
2002-04-04 23:20:33 +00:00
|
|
|
* RFC1058, RFC2453
|
1998-09-16 02:39:15 +00:00
|
|
|
* (c) Copyright Hannes R. Boehm <hannes@boehm.org>
|
|
|
|
*
|
2002-08-28 21:04:11 +00:00
|
|
|
* $Id: packet-rip.c,v 1.33 2002/08/28 21:00:29 jmayer Exp $
|
1998-09-16 03:22:19 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* Ethereal - Network traffic analyzer
|
2001-09-14 06:34:36 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
1998-09-16 02:39:15 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +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
|
|
|
*
|
1998-09-16 02:39:15 +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
|
|
|
*
|
1998-09-16 02:39:15 +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.
|
|
|
|
*/
|
2002-08-28 21:04:11 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-11-17 21:00:40 +00:00
|
|
|
#include <string.h>
|
1999-03-23 03:14:46 +00:00
|
|
|
#include <glib.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2000-04-14 06:17:23 +00:00
|
|
|
#define UDP_PORT_RIP 520
|
|
|
|
|
2000-12-27 12:48:27 +00:00
|
|
|
#define RIPv1 1
|
|
|
|
#define RIPv2 2
|
|
|
|
|
|
|
|
static const value_string version_vals[] = {
|
|
|
|
{ RIPv1, "RIPv1" },
|
|
|
|
{ RIPv2, "RIPv2" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string command_vals[] = {
|
|
|
|
{ 1, "Request" },
|
|
|
|
{ 2, "Response" },
|
|
|
|
{ 3, "Traceon" },
|
|
|
|
{ 4, "Traceoff" },
|
|
|
|
{ 5, "Vendor specific (Sun)" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2002-04-04 23:20:33 +00:00
|
|
|
#define AFVAL_UNSPEC 0
|
|
|
|
#define AFVAL_IP 2
|
|
|
|
|
2001-09-13 08:10:53 +00:00
|
|
|
static const value_string family_vals[] = {
|
2002-04-04 23:20:33 +00:00
|
|
|
{ AFVAL_UNSPEC, "Unspecified" },
|
|
|
|
{ AFVAL_IP, "IP" },
|
|
|
|
{ 0, NULL }
|
2001-09-13 08:10:53 +00:00
|
|
|
};
|
|
|
|
|
2000-12-27 12:48:27 +00:00
|
|
|
#define RIP_HEADER_LENGTH 4
|
|
|
|
#define RIP_ENTRY_LENGTH 20
|
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
static int proto_rip = -1;
|
2001-09-13 08:10:53 +00:00
|
|
|
static int hf_rip_command = -1;
|
|
|
|
static int hf_rip_version = -1;
|
|
|
|
static int hf_rip_routing_domain = -1;
|
|
|
|
static int hf_rip_ip = -1;
|
|
|
|
static int hf_rip_netmask = -1;
|
|
|
|
static int hf_rip_next_hop = -1;
|
|
|
|
static int hf_rip_metric = -1;
|
|
|
|
static int hf_rip_auth = -1;
|
|
|
|
static int hf_rip_auth_passwd = -1;
|
|
|
|
static int hf_rip_family = -1;
|
|
|
|
static int hf_rip_route_tag = -1;
|
1999-07-29 05:47:07 +00:00
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint ett_rip = -1;
|
|
|
|
static gint ett_rip_vec = -1;
|
|
|
|
|
2002-04-04 23:20:33 +00:00
|
|
|
static void dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
|
|
|
|
proto_tree *tree);
|
2000-12-27 12:48:27 +00:00
|
|
|
static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
|
|
|
|
proto_tree *tree);
|
|
|
|
static void dissect_rip_authentication(tvbuff_t *tvb, int offset,
|
|
|
|
proto_tree *tree);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
static void
|
2000-12-27 12:48:27 +00:00
|
|
|
dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
int offset = 0;
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *rip_tree = NULL;
|
2000-12-27 12:48:27 +00:00
|
|
|
proto_item *ti;
|
|
|
|
guint8 command;
|
|
|
|
guint8 version;
|
|
|
|
guint16 family;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIP");
|
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
|
2000-12-27 12:48:27 +00:00
|
|
|
command = tvb_get_guint8(tvb, 0);
|
|
|
|
version = tvb_get_guint8(tvb, 1);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_add_str(pinfo->cinfo, COL_PROTOCOL,
|
2000-12-27 12:48:27 +00:00
|
|
|
val_to_str(version, version_vals, "RIP"));
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_add_str(pinfo->cinfo, COL_INFO,
|
2000-12-27 12:48:27 +00:00
|
|
|
val_to_str(command, command_vals, "Unknown command (%u)"));
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
if (tree) {
|
2002-01-24 09:20:54 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_rip, tvb, 0, -1, FALSE);
|
1999-11-16 11:44:20 +00:00
|
|
|
rip_tree = proto_item_add_subtree(ti, ett_rip);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2001-09-13 08:10:53 +00:00
|
|
|
proto_tree_add_uint(rip_tree, hf_rip_command, tvb, 0, 1, command);
|
|
|
|
proto_tree_add_uint(rip_tree, hf_rip_version, tvb, 1, 1, version);
|
2000-12-27 12:48:27 +00:00
|
|
|
if (version == RIPv2)
|
2001-09-13 08:10:53 +00:00
|
|
|
proto_tree_add_uint(rip_tree, hf_rip_routing_domain, tvb, 2, 2,
|
|
|
|
tvb_get_ntohs(tvb, 2));
|
1998-11-20 09:24:42 +00:00
|
|
|
|
|
|
|
/* skip header */
|
2000-12-27 12:48:27 +00:00
|
|
|
offset = RIP_HEADER_LENGTH;
|
1998-11-20 09:24:42 +00:00
|
|
|
|
|
|
|
/* zero or more entries */
|
2001-09-14 06:34:36 +00:00
|
|
|
while (tvb_reported_length_remaining(tvb, offset) > 0) {
|
2000-12-27 12:48:27 +00:00
|
|
|
family = tvb_get_ntohs(tvb, offset);
|
1998-11-20 09:24:42 +00:00
|
|
|
switch (family) {
|
2002-04-04 23:20:33 +00:00
|
|
|
case AFVAL_UNSPEC: /* Unspecified */
|
|
|
|
/*
|
|
|
|
* There should be one entry in the request, and a metric
|
|
|
|
* of infinity, meaning "show the entire routing table".
|
|
|
|
*/
|
|
|
|
dissect_unspec_rip_vektor(tvb, offset, version, rip_tree);
|
|
|
|
break;
|
|
|
|
case AFVAL_IP: /* IP */
|
2000-12-27 12:48:27 +00:00
|
|
|
dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
|
1998-09-16 02:39:15 +00:00
|
|
|
break;
|
|
|
|
case 0xFFFF:
|
2000-12-27 12:48:27 +00:00
|
|
|
dissect_rip_authentication(tvb, offset, rip_tree);
|
1998-09-16 02:39:15 +00:00
|
|
|
break;
|
1998-11-20 09:24:42 +00:00
|
|
|
default:
|
2000-12-27 12:48:27 +00:00
|
|
|
proto_tree_add_text(rip_tree, tvb, offset,
|
1998-11-20 09:24:42 +00:00
|
|
|
RIP_ENTRY_LENGTH, "Unknown address family %u",
|
|
|
|
family);
|
|
|
|
break;
|
|
|
|
}
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1998-11-20 09:24:42 +00:00
|
|
|
offset += RIP_ENTRY_LENGTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2002-04-04 23:20:33 +00:00
|
|
|
static void
|
|
|
|
dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
|
|
|
|
proto_tree *tree)
|
|
|
|
{
|
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *rip_vektor_tree;
|
|
|
|
guint32 metric;
|
|
|
|
|
|
|
|
metric = tvb_get_ntohl(tvb, offset+16);
|
|
|
|
ti = proto_tree_add_text(tree, tvb, offset,
|
|
|
|
RIP_ENTRY_LENGTH, "Address not specified, Metric: %u",
|
|
|
|
metric);
|
|
|
|
rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
|
|
|
|
|
|
|
|
proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
|
|
|
|
if (version == RIPv2) {
|
|
|
|
proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
|
|
|
|
FALSE);
|
|
|
|
proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
|
|
|
|
FALSE);
|
|
|
|
proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
|
|
|
|
FALSE);
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
|
2002-04-04 23:20:33 +00:00
|
|
|
offset+16, 4, metric);
|
|
|
|
}
|
|
|
|
|
1998-11-20 09:24:42 +00:00
|
|
|
static void
|
2000-12-27 12:48:27 +00:00
|
|
|
dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
|
|
|
|
proto_tree *tree)
|
1998-11-20 09:24:42 +00:00
|
|
|
{
|
2000-12-27 12:48:27 +00:00
|
|
|
proto_item *ti;
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *rip_vektor_tree;
|
2000-12-27 12:48:27 +00:00
|
|
|
guint32 metric;
|
|
|
|
|
|
|
|
metric = tvb_get_ntohl(tvb, offset+16);
|
|
|
|
ti = proto_tree_add_text(tree, tvb, offset,
|
|
|
|
RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
|
2001-09-13 08:10:53 +00:00
|
|
|
ip_to_str(tvb_get_ptr(tvb, offset+4, 4)), metric);
|
2000-12-27 12:48:27 +00:00
|
|
|
rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
|
2001-09-13 08:10:53 +00:00
|
|
|
|
2002-04-04 23:20:33 +00:00
|
|
|
proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
|
2001-09-13 08:10:53 +00:00
|
|
|
if (version == RIPv2) {
|
2002-04-04 23:20:33 +00:00
|
|
|
proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
|
|
|
|
FALSE);
|
2001-09-13 08:10:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proto_tree_add_item(rip_vektor_tree, hf_rip_ip, tvb, offset+4, 4, FALSE);
|
|
|
|
|
2000-12-27 12:48:27 +00:00
|
|
|
if (version == RIPv2) {
|
2001-09-13 08:10:53 +00:00
|
|
|
proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
|
|
|
|
FALSE);
|
|
|
|
proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
|
|
|
|
FALSE);
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
|
2001-09-13 08:10:53 +00:00
|
|
|
offset+16, 4, metric);
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
1998-11-20 09:24:42 +00:00
|
|
|
|
|
|
|
static void
|
2000-12-27 12:48:27 +00:00
|
|
|
dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
|
1998-11-20 09:24:42 +00:00
|
|
|
{
|
2000-12-27 12:48:27 +00:00
|
|
|
proto_item *ti;
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *rip_authentication_tree;
|
1998-11-20 09:24:42 +00:00
|
|
|
guint16 authtype;
|
2000-12-27 12:48:27 +00:00
|
|
|
|
|
|
|
ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
|
|
|
|
"Authentication");
|
|
|
|
rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
|
|
|
|
|
|
|
|
authtype = tvb_get_ntohs(tvb, offset + 2);
|
2001-09-13 08:10:53 +00:00
|
|
|
proto_tree_add_uint(rip_authentication_tree, hf_rip_auth, tvb, offset+2, 2,
|
|
|
|
authtype);
|
2000-12-27 12:48:27 +00:00
|
|
|
if (authtype == 2) {
|
2001-09-13 08:10:53 +00:00
|
|
|
proto_tree_add_item(rip_authentication_tree, hf_rip_auth_passwd,
|
2002-04-04 23:20:33 +00:00
|
|
|
tvb, offset+4, 16, FALSE);
|
2000-12-27 12:48:27 +00:00
|
|
|
}
|
1998-11-20 09:24:42 +00:00
|
|
|
}
|
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
void
|
|
|
|
proto_register_rip(void)
|
|
|
|
{
|
2001-09-13 08:10:53 +00:00
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_rip_command,
|
2001-09-14 06:34:36 +00:00
|
|
|
{ "Command", "rip.command", FT_UINT8, BASE_DEC,
|
2001-09-13 08:10:53 +00:00
|
|
|
VALS(command_vals), 0, "What type of RIP Command is this", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_rip_version,
|
|
|
|
{ "Version", "rip.version", FT_UINT8, BASE_DEC,
|
|
|
|
VALS(version_vals), 0, "Version of the RIP protocol", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_rip_family,
|
|
|
|
{ "Address Family", "rip.family", FT_UINT16, BASE_DEC,
|
|
|
|
VALS(family_vals), 0, "Address family", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_rip_routing_domain,
|
|
|
|
{ "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC,
|
|
|
|
NULL, 0, "RIPv2 Routing Domain", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_rip_ip,
|
|
|
|
{ "IP Address", "rip.ip", FT_IPv4, BASE_NONE,
|
|
|
|
NULL, 0, "IP Address", HFILL}},
|
|
|
|
|
|
|
|
{ &hf_rip_netmask,
|
|
|
|
{ "Netmask", "rip.netmask", FT_IPv4, BASE_NONE,
|
|
|
|
NULL, 0, "Netmask", HFILL}},
|
|
|
|
|
|
|
|
{ &hf_rip_next_hop,
|
|
|
|
{ "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE,
|
|
|
|
NULL, 0, "Next Hop router for this route", HFILL}},
|
|
|
|
|
|
|
|
{ &hf_rip_metric,
|
|
|
|
{ "Metric", "rip.metric", FT_UINT16, BASE_DEC,
|
|
|
|
NULL, 0, "Metric for this route", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_rip_auth,
|
|
|
|
{ "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC,
|
|
|
|
NULL, 0, "Type of authentication", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_rip_auth_passwd,
|
|
|
|
{ "Password", "rip.auth.passwd", FT_STRING, BASE_DEC,
|
|
|
|
NULL, 0, "Authentication password", HFILL }},
|
|
|
|
|
|
|
|
{ &hf_rip_route_tag,
|
|
|
|
{ "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC,
|
|
|
|
NULL, 0, "Route Tag", HFILL }},
|
|
|
|
|
|
|
|
};
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_rip,
|
|
|
|
&ett_rip_vec,
|
|
|
|
};
|
|
|
|
|
|
|
|
proto_rip = proto_register_protocol("Routing Information Protocol",
|
|
|
|
"RIP", "rip");
|
|
|
|
proto_register_field_array(proto_rip, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
1999-07-29 05:47:07 +00:00
|
|
|
}
|
2000-04-14 06:17:23 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_rip(void)
|
|
|
|
{
|
2001-12-03 04:00:26 +00:00
|
|
|
dissector_handle_t rip_handle;
|
|
|
|
|
|
|
|
rip_handle = create_dissector_handle(dissect_rip, proto_rip);
|
|
|
|
dissector_add("udp.port", UDP_PORT_RIP, rip_handle);
|
2000-04-14 06:17:23 +00:00
|
|
|
}
|