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
|
|
|
|
* (c) Copyright Hannes R. Boehm <hannes@boehm.org>
|
|
|
|
*
|
1999-08-04 00:33:11 +00:00
|
|
|
* $Id: packet-rip.c,v 1.11 1999/08/04 00:33:11 guy Exp $
|
1998-09-16 03:22:19 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* Ethereal - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@zing.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
#include <glib.h>
|
1998-09-16 02:39:15 +00:00
|
|
|
#include "packet.h"
|
|
|
|
#include "packet-rip.h"
|
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
static int proto_rip = -1;
|
|
|
|
|
1998-11-20 09:24:42 +00:00
|
|
|
static void dissect_ip_rip_vektor(guint8 version,
|
1999-03-23 03:14:46 +00:00
|
|
|
const e_rip_vektor *rip_vektor, int offset, proto_tree *tree);
|
1998-11-20 09:24:42 +00:00
|
|
|
static void dissect_rip_authentication(const e_rip_authentication *rip_authentication,
|
1999-03-23 03:14:46 +00:00
|
|
|
int offset, proto_tree *tree);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
void
|
1999-03-23 03:14:46 +00:00
|
|
|
dissect_rip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
|
1999-02-05 00:52:19 +00:00
|
|
|
e_riphdr rip_header;
|
1998-11-20 09:24:42 +00:00
|
|
|
e_rip_entry rip_entry;
|
|
|
|
guint16 family;
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *rip_tree = NULL;
|
|
|
|
proto_item *ti;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
/* we do the range checking of the index when checking wether or not this is a RIP packet */
|
1998-11-20 09:24:42 +00:00
|
|
|
static char *packet_type[8] = { "never used", "Request", "Response",
|
1998-09-16 02:39:15 +00:00
|
|
|
"Traceon", "Traceoff", "Vendor specific (Sun)" };
|
1998-11-20 09:24:42 +00:00
|
|
|
static char *version[3] = { "RIP", "RIPv1", "RIPv2" };
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-02-05 00:52:19 +00:00
|
|
|
/* avoid alignment problem */
|
|
|
|
memcpy(&rip_header, &pd[offset], sizeof(rip_header));
|
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
/* Check if we 've realy got a RIP packet */
|
|
|
|
|
1999-02-05 00:52:19 +00:00
|
|
|
switch(rip_header.version) {
|
1998-09-16 02:39:15 +00:00
|
|
|
case RIPv1:
|
|
|
|
/* the domain field has to be set to zero for RIPv1 */
|
1999-02-05 00:52:19 +00:00
|
|
|
if(!(rip_header.domain == 0)){
|
1998-09-16 02:39:15 +00:00
|
|
|
dissect_data(pd, offset, fd, tree);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* the RIPv2 checks are also made for v1 packets */
|
|
|
|
case RIPv2:
|
|
|
|
/* check wether or not command nr. is between 1-7
|
|
|
|
* (range checking for index of char* packet_type is done at the same time)
|
|
|
|
*/
|
1999-02-05 00:52:19 +00:00
|
|
|
if( !( (rip_header.command > 0) && (rip_header.command <= 7) )){
|
1998-09-16 02:39:15 +00:00
|
|
|
dissect_data(pd, offset, fd, tree);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* we only know RIPv1 and RIPv2 */
|
|
|
|
dissect_data(pd, offset, fd, tree);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-11-17 04:29:13 +00:00
|
|
|
if (check_col(fd, COL_PROTOCOL))
|
1999-02-05 00:52:19 +00:00
|
|
|
col_add_str(fd, COL_PROTOCOL, version[rip_header.version] );
|
1998-11-17 04:29:13 +00:00
|
|
|
if (check_col(fd, COL_INFO))
|
1999-02-05 00:52:19 +00:00
|
|
|
col_add_str(fd, COL_INFO, packet_type[rip_header.command]);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
if (tree) {
|
1999-07-29 05:47:07 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_rip, offset, (fd->cap_len - offset), NULL);
|
1999-07-07 22:52:57 +00:00
|
|
|
rip_tree = proto_item_add_subtree(ti, ETT_RIP);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_tree, offset, 1, "Command: %d (%s)", rip_header.command, packet_type[rip_header.command]);
|
|
|
|
proto_tree_add_text(rip_tree, offset + 1, 1, "Version: %d", rip_header.version);
|
1999-02-05 00:52:19 +00:00
|
|
|
if(rip_header.version == RIPv2)
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_tree, offset + 2 , 2, "Routing Domain: %d", ntohs(rip_header.domain));
|
1998-11-20 09:24:42 +00:00
|
|
|
|
|
|
|
/* skip header */
|
|
|
|
offset += RIP_HEADER_LENGTH;
|
|
|
|
|
|
|
|
/* zero or more entries */
|
|
|
|
|
|
|
|
while((fd->cap_len - offset) >= RIP_ENTRY_LENGTH){
|
|
|
|
memcpy(&rip_entry, &pd[offset], sizeof(rip_entry)); /* avoid alignment problem */
|
|
|
|
family = ntohs(rip_entry.vektor.family);
|
|
|
|
switch (family) {
|
1998-09-16 02:39:15 +00:00
|
|
|
case 2: /* IP */
|
1999-07-07 22:52:57 +00:00
|
|
|
ti = proto_tree_add_text(rip_tree, offset,
|
1998-11-20 09:24:42 +00:00
|
|
|
RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %ld",
|
|
|
|
ip_to_str((guint8 *) &(rip_entry.vektor.ip)),
|
|
|
|
(long)ntohl(rip_entry.vektor.metric));
|
1999-02-05 00:52:19 +00:00
|
|
|
dissect_ip_rip_vektor(rip_header.version, &rip_entry.vektor,
|
1998-11-20 09:24:42 +00:00
|
|
|
offset, ti);
|
1998-09-16 02:39:15 +00:00
|
|
|
break;
|
|
|
|
case 0xFFFF:
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_tree, offset,
|
1999-03-23 03:14:46 +00:00
|
|
|
RIP_ENTRY_LENGTH, "Authentication");
|
1998-11-20 09:24:42 +00:00
|
|
|
dissect_rip_authentication(&rip_entry.authentication,
|
|
|
|
offset, ti);
|
1998-09-16 02:39:15 +00:00
|
|
|
break;
|
1998-11-20 09:24:42 +00:00
|
|
|
default:
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_tree, 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
|
|
|
|
1998-11-20 09:24:42 +00:00
|
|
|
static void
|
|
|
|
dissect_ip_rip_vektor(guint8 version, const e_rip_vektor *rip_vektor,
|
1999-03-23 03:14:46 +00:00
|
|
|
int offset, proto_tree *tree)
|
1998-11-20 09:24:42 +00:00
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *rip_vektor_tree;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
rip_vektor_tree = proto_item_add_subtree(tree, ETT_RIP_VEC);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_vektor_tree, offset, 2, "Address Family ID: IP");
|
1998-11-20 09:24:42 +00:00
|
|
|
if(version == RIPv2)
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_vektor_tree, offset + 2 , 2, "Route Tag: %d",
|
1998-11-20 09:24:42 +00:00
|
|
|
ntohs(rip_vektor->tag));
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_vektor_tree, offset + 4, 4, "IP Address: %s",
|
1998-11-20 09:24:42 +00:00
|
|
|
ip_to_str((guint8 *) &(rip_vektor->ip)));
|
|
|
|
if(version == RIPv2) {
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_vektor_tree, offset + 8 , 4, "Netmask: %s",
|
1998-11-20 09:24:42 +00:00
|
|
|
ip_to_str((guint8 *) &(rip_vektor->mask)));
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_vektor_tree, offset + 12, 4, "Next Hop: %s",
|
1998-11-20 09:24:42 +00:00
|
|
|
ip_to_str((guint8 *) &(rip_vektor->next_hop)));
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_vektor_tree, offset + 16, 4, "Metric: %ld",
|
1998-11-20 09:24:42 +00:00
|
|
|
(long)ntohl(rip_vektor->metric));
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
1998-11-20 09:24:42 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_rip_authentication(const e_rip_authentication *rip_authentication,
|
1999-03-23 03:14:46 +00:00
|
|
|
int offset, proto_tree *tree)
|
1998-11-20 09:24:42 +00:00
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *rip_authentication_tree;
|
1998-11-20 09:24:42 +00:00
|
|
|
guint16 authtype;
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
rip_authentication_tree = proto_item_add_subtree(tree, ETT_RIP_VEC);
|
1998-11-20 09:24:42 +00:00
|
|
|
|
|
|
|
authtype = ntohs(rip_authentication->authtype);
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_authentication_tree, offset + 2, 2,
|
1998-11-20 09:24:42 +00:00
|
|
|
"Authentication type: %u", authtype);
|
|
|
|
if (authtype == 2)
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_tree_add_text(rip_authentication_tree, offset + 4 , 16,
|
1998-11-20 09:24:42 +00:00
|
|
|
"Password: %.16s",
|
|
|
|
rip_authentication->authentication);
|
|
|
|
}
|
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
void
|
|
|
|
proto_register_rip(void)
|
|
|
|
{
|
|
|
|
/* static hf_register_info hf[] = {
|
|
|
|
{ &variable,
|
|
|
|
{ "Name", "rip.abbreviation", TYPE, VALS_POINTER }},
|
|
|
|
};*/
|
|
|
|
|
|
|
|
proto_rip = proto_register_protocol("Routing Information Protocol", "rip");
|
|
|
|
/* proto_register_field_array(proto_rip, hf, array_length(hf));*/
|
|
|
|
}
|