2 * Routines for RIPv1 and RIPv2 packet disassembly
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-rip.c,v 1.30 2002/01/24 09:20:51 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
32 #ifdef HAVE_NETINET_IN_H
33 #include <netinet/in.h>
38 #include <epan/packet.h>
40 #define UDP_PORT_RIP 520
45 static const value_string version_vals[] = {
51 static const value_string command_vals[] = {
56 { 5, "Vendor specific (Sun)" },
60 static const value_string family_vals[] = {
65 #define RIP_HEADER_LENGTH 4
66 #define RIP_ENTRY_LENGTH 20
68 static int proto_rip = -1;
69 static int hf_rip_command = -1;
70 static int hf_rip_version = -1;
71 static int hf_rip_routing_domain = -1;
72 static int hf_rip_ip = -1;
73 static int hf_rip_netmask = -1;
74 static int hf_rip_next_hop = -1;
75 static int hf_rip_metric = -1;
76 static int hf_rip_auth = -1;
77 static int hf_rip_auth_passwd = -1;
78 static int hf_rip_family = -1;
79 static int hf_rip_route_tag = -1;
81 static gint ett_rip = -1;
82 static gint ett_rip_vec = -1;
84 static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
86 static void dissect_rip_authentication(tvbuff_t *tvb, int offset,
90 dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
93 proto_tree *rip_tree = NULL;
99 if (check_col(pinfo->cinfo, COL_PROTOCOL))
100 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIP");
101 if (check_col(pinfo->cinfo, COL_INFO))
102 col_clear(pinfo->cinfo, COL_INFO);
104 command = tvb_get_guint8(tvb, 0);
105 version = tvb_get_guint8(tvb, 1);
107 if (check_col(pinfo->cinfo, COL_PROTOCOL))
108 col_add_str(pinfo->cinfo, COL_PROTOCOL,
109 val_to_str(version, version_vals, "RIP"));
110 if (check_col(pinfo->cinfo, COL_INFO))
111 col_add_str(pinfo->cinfo, COL_INFO,
112 val_to_str(command, command_vals, "Unknown command (%u)"));
115 ti = proto_tree_add_item(tree, proto_rip, tvb, 0, -1, FALSE);
116 rip_tree = proto_item_add_subtree(ti, ett_rip);
118 proto_tree_add_uint(rip_tree, hf_rip_command, tvb, 0, 1, command);
119 proto_tree_add_uint(rip_tree, hf_rip_version, tvb, 1, 1, version);
120 if (version == RIPv2)
121 proto_tree_add_uint(rip_tree, hf_rip_routing_domain, tvb, 2, 2,
122 tvb_get_ntohs(tvb, 2));
125 offset = RIP_HEADER_LENGTH;
127 /* zero or more entries */
128 while (tvb_reported_length_remaining(tvb, offset) > 0) {
129 family = tvb_get_ntohs(tvb, offset);
132 dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
135 dissect_rip_authentication(tvb, offset, rip_tree);
138 proto_tree_add_text(rip_tree, tvb, offset,
139 RIP_ENTRY_LENGTH, "Unknown address family %u",
144 offset += RIP_ENTRY_LENGTH;
150 dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
154 proto_tree *rip_vektor_tree;
157 metric = tvb_get_ntohl(tvb, offset+16);
158 ti = proto_tree_add_text(tree, tvb, offset,
159 RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
160 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)), metric);
161 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
164 proto_tree_add_uint(rip_vektor_tree, hf_rip_family, tvb, offset, 2,
165 tvb_get_ntohs(tvb, offset));
166 if (version == RIPv2) {
167 proto_tree_add_uint(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
168 tvb_get_ntohs(tvb, offset+2));
171 proto_tree_add_item(rip_vektor_tree, hf_rip_ip, tvb, offset+4, 4, FALSE);
173 if (version == RIPv2) {
174 proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
176 proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
179 proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
180 offset+16, 4, metric);
184 dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
187 proto_tree *rip_authentication_tree;
190 ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
192 rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
194 authtype = tvb_get_ntohs(tvb, offset + 2);
195 proto_tree_add_uint(rip_authentication_tree, hf_rip_auth, tvb, offset+2, 2,
198 proto_tree_add_item(rip_authentication_tree, hf_rip_auth_passwd,
199 tvb, offset+4, 16, TRUE);
204 proto_register_rip(void)
206 static hf_register_info hf[] = {
208 { "Command", "rip.command", FT_UINT8, BASE_DEC,
209 VALS(command_vals), 0, "What type of RIP Command is this", HFILL }},
212 { "Version", "rip.version", FT_UINT8, BASE_DEC,
213 VALS(version_vals), 0, "Version of the RIP protocol", HFILL }},
216 { "Address Family", "rip.family", FT_UINT16, BASE_DEC,
217 VALS(family_vals), 0, "Address family", HFILL }},
219 { &hf_rip_routing_domain,
220 { "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC,
221 NULL, 0, "RIPv2 Routing Domain", HFILL }},
224 { "IP Address", "rip.ip", FT_IPv4, BASE_NONE,
225 NULL, 0, "IP Address", HFILL}},
228 { "Netmask", "rip.netmask", FT_IPv4, BASE_NONE,
229 NULL, 0, "Netmask", HFILL}},
232 { "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE,
233 NULL, 0, "Next Hop router for this route", HFILL}},
236 { "Metric", "rip.metric", FT_UINT16, BASE_DEC,
237 NULL, 0, "Metric for this route", HFILL }},
240 { "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC,
241 NULL, 0, "Type of authentication", HFILL }},
243 { &hf_rip_auth_passwd,
244 { "Password", "rip.auth.passwd", FT_STRING, BASE_DEC,
245 NULL, 0, "Authentication password", HFILL }},
248 { "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC,
249 NULL, 0, "Route Tag", HFILL }},
252 static gint *ett[] = {
257 proto_rip = proto_register_protocol("Routing Information Protocol",
259 proto_register_field_array(proto_rip, hf, array_length(hf));
260 proto_register_subtree_array(ett, array_length(ett));
264 proto_reg_handoff_rip(void)
266 dissector_handle_t rip_handle;
268 rip_handle = create_dissector_handle(dissect_rip, proto_rip);
269 dissector_add("udp.port", UDP_PORT_RIP, rip_handle);