2 * Routines for RIPv1 and RIPv2 packet disassembly
4 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
6 * $Id: packet-rip.c,v 1.31 2002/04/04 23:20:33 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
33 #ifdef HAVE_NETINET_IN_H
34 #include <netinet/in.h>
39 #include <epan/packet.h>
41 #define UDP_PORT_RIP 520
46 static const value_string version_vals[] = {
52 static const value_string command_vals[] = {
57 { 5, "Vendor specific (Sun)" },
61 #define AFVAL_UNSPEC 0
64 static const value_string family_vals[] = {
65 { AFVAL_UNSPEC, "Unspecified" },
70 #define RIP_HEADER_LENGTH 4
71 #define RIP_ENTRY_LENGTH 20
73 static int proto_rip = -1;
74 static int hf_rip_command = -1;
75 static int hf_rip_version = -1;
76 static int hf_rip_routing_domain = -1;
77 static int hf_rip_ip = -1;
78 static int hf_rip_netmask = -1;
79 static int hf_rip_next_hop = -1;
80 static int hf_rip_metric = -1;
81 static int hf_rip_auth = -1;
82 static int hf_rip_auth_passwd = -1;
83 static int hf_rip_family = -1;
84 static int hf_rip_route_tag = -1;
86 static gint ett_rip = -1;
87 static gint ett_rip_vec = -1;
89 static void dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
91 static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
93 static void dissect_rip_authentication(tvbuff_t *tvb, int offset,
97 dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
100 proto_tree *rip_tree = NULL;
106 if (check_col(pinfo->cinfo, COL_PROTOCOL))
107 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIP");
108 if (check_col(pinfo->cinfo, COL_INFO))
109 col_clear(pinfo->cinfo, COL_INFO);
111 command = tvb_get_guint8(tvb, 0);
112 version = tvb_get_guint8(tvb, 1);
114 if (check_col(pinfo->cinfo, COL_PROTOCOL))
115 col_add_str(pinfo->cinfo, COL_PROTOCOL,
116 val_to_str(version, version_vals, "RIP"));
117 if (check_col(pinfo->cinfo, COL_INFO))
118 col_add_str(pinfo->cinfo, COL_INFO,
119 val_to_str(command, command_vals, "Unknown command (%u)"));
122 ti = proto_tree_add_item(tree, proto_rip, tvb, 0, -1, FALSE);
123 rip_tree = proto_item_add_subtree(ti, ett_rip);
125 proto_tree_add_uint(rip_tree, hf_rip_command, tvb, 0, 1, command);
126 proto_tree_add_uint(rip_tree, hf_rip_version, tvb, 1, 1, version);
127 if (version == RIPv2)
128 proto_tree_add_uint(rip_tree, hf_rip_routing_domain, tvb, 2, 2,
129 tvb_get_ntohs(tvb, 2));
132 offset = RIP_HEADER_LENGTH;
134 /* zero or more entries */
135 while (tvb_reported_length_remaining(tvb, offset) > 0) {
136 family = tvb_get_ntohs(tvb, offset);
138 case AFVAL_UNSPEC: /* Unspecified */
140 * There should be one entry in the request, and a metric
141 * of infinity, meaning "show the entire routing table".
143 dissect_unspec_rip_vektor(tvb, offset, version, rip_tree);
145 case AFVAL_IP: /* IP */
146 dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
149 dissect_rip_authentication(tvb, offset, rip_tree);
152 proto_tree_add_text(rip_tree, tvb, offset,
153 RIP_ENTRY_LENGTH, "Unknown address family %u",
158 offset += RIP_ENTRY_LENGTH;
164 dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
168 proto_tree *rip_vektor_tree;
171 metric = tvb_get_ntohl(tvb, offset+16);
172 ti = proto_tree_add_text(tree, tvb, offset,
173 RIP_ENTRY_LENGTH, "Address not specified, Metric: %u",
175 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
177 proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
178 if (version == RIPv2) {
179 proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
181 proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
183 proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
186 proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
187 offset+16, 4, metric);
191 dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
195 proto_tree *rip_vektor_tree;
198 metric = tvb_get_ntohl(tvb, offset+16);
199 ti = proto_tree_add_text(tree, tvb, offset,
200 RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
201 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)), metric);
202 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
204 proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
205 if (version == RIPv2) {
206 proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
210 proto_tree_add_item(rip_vektor_tree, hf_rip_ip, tvb, offset+4, 4, FALSE);
212 if (version == RIPv2) {
213 proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
215 proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
218 proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
219 offset+16, 4, metric);
223 dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
226 proto_tree *rip_authentication_tree;
229 ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
231 rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
233 authtype = tvb_get_ntohs(tvb, offset + 2);
234 proto_tree_add_uint(rip_authentication_tree, hf_rip_auth, tvb, offset+2, 2,
237 proto_tree_add_item(rip_authentication_tree, hf_rip_auth_passwd,
238 tvb, offset+4, 16, FALSE);
243 proto_register_rip(void)
245 static hf_register_info hf[] = {
247 { "Command", "rip.command", FT_UINT8, BASE_DEC,
248 VALS(command_vals), 0, "What type of RIP Command is this", HFILL }},
251 { "Version", "rip.version", FT_UINT8, BASE_DEC,
252 VALS(version_vals), 0, "Version of the RIP protocol", HFILL }},
255 { "Address Family", "rip.family", FT_UINT16, BASE_DEC,
256 VALS(family_vals), 0, "Address family", HFILL }},
258 { &hf_rip_routing_domain,
259 { "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC,
260 NULL, 0, "RIPv2 Routing Domain", HFILL }},
263 { "IP Address", "rip.ip", FT_IPv4, BASE_NONE,
264 NULL, 0, "IP Address", HFILL}},
267 { "Netmask", "rip.netmask", FT_IPv4, BASE_NONE,
268 NULL, 0, "Netmask", HFILL}},
271 { "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE,
272 NULL, 0, "Next Hop router for this route", HFILL}},
275 { "Metric", "rip.metric", FT_UINT16, BASE_DEC,
276 NULL, 0, "Metric for this route", HFILL }},
279 { "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC,
280 NULL, 0, "Type of authentication", HFILL }},
282 { &hf_rip_auth_passwd,
283 { "Password", "rip.auth.passwd", FT_STRING, BASE_DEC,
284 NULL, 0, "Authentication password", HFILL }},
287 { "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC,
288 NULL, 0, "Route Tag", HFILL }},
291 static gint *ett[] = {
296 proto_rip = proto_register_protocol("Routing Information Protocol",
298 proto_register_field_array(proto_rip, hf, array_length(hf));
299 proto_register_subtree_array(ett, array_length(ett));
303 proto_reg_handoff_rip(void)
305 dissector_handle_t rip_handle;
307 rip_handle = create_dissector_handle(dissect_rip, proto_rip);
308 dissector_add("udp.port", UDP_PORT_RIP, rip_handle);