2 * Routines for RIPv1 and RIPv2 packet disassembly
4 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
6 * $Id: packet-rip.c,v 1.33 2002/08/28 21:00:29 jmayer 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.
31 #include <epan/packet.h>
33 #define UDP_PORT_RIP 520
38 static const value_string version_vals[] = {
44 static const value_string command_vals[] = {
49 { 5, "Vendor specific (Sun)" },
53 #define AFVAL_UNSPEC 0
56 static const value_string family_vals[] = {
57 { AFVAL_UNSPEC, "Unspecified" },
62 #define RIP_HEADER_LENGTH 4
63 #define RIP_ENTRY_LENGTH 20
65 static int proto_rip = -1;
66 static int hf_rip_command = -1;
67 static int hf_rip_version = -1;
68 static int hf_rip_routing_domain = -1;
69 static int hf_rip_ip = -1;
70 static int hf_rip_netmask = -1;
71 static int hf_rip_next_hop = -1;
72 static int hf_rip_metric = -1;
73 static int hf_rip_auth = -1;
74 static int hf_rip_auth_passwd = -1;
75 static int hf_rip_family = -1;
76 static int hf_rip_route_tag = -1;
78 static gint ett_rip = -1;
79 static gint ett_rip_vec = -1;
81 static void dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
83 static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
85 static void dissect_rip_authentication(tvbuff_t *tvb, int offset,
89 dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
92 proto_tree *rip_tree = NULL;
98 if (check_col(pinfo->cinfo, COL_PROTOCOL))
99 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIP");
100 if (check_col(pinfo->cinfo, COL_INFO))
101 col_clear(pinfo->cinfo, COL_INFO);
103 command = tvb_get_guint8(tvb, 0);
104 version = tvb_get_guint8(tvb, 1);
106 if (check_col(pinfo->cinfo, COL_PROTOCOL))
107 col_add_str(pinfo->cinfo, COL_PROTOCOL,
108 val_to_str(version, version_vals, "RIP"));
109 if (check_col(pinfo->cinfo, COL_INFO))
110 col_add_str(pinfo->cinfo, COL_INFO,
111 val_to_str(command, command_vals, "Unknown command (%u)"));
114 ti = proto_tree_add_item(tree, proto_rip, tvb, 0, -1, FALSE);
115 rip_tree = proto_item_add_subtree(ti, ett_rip);
117 proto_tree_add_uint(rip_tree, hf_rip_command, tvb, 0, 1, command);
118 proto_tree_add_uint(rip_tree, hf_rip_version, tvb, 1, 1, version);
119 if (version == RIPv2)
120 proto_tree_add_uint(rip_tree, hf_rip_routing_domain, tvb, 2, 2,
121 tvb_get_ntohs(tvb, 2));
124 offset = RIP_HEADER_LENGTH;
126 /* zero or more entries */
127 while (tvb_reported_length_remaining(tvb, offset) > 0) {
128 family = tvb_get_ntohs(tvb, offset);
130 case AFVAL_UNSPEC: /* Unspecified */
132 * There should be one entry in the request, and a metric
133 * of infinity, meaning "show the entire routing table".
135 dissect_unspec_rip_vektor(tvb, offset, version, rip_tree);
137 case AFVAL_IP: /* IP */
138 dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
141 dissect_rip_authentication(tvb, offset, rip_tree);
144 proto_tree_add_text(rip_tree, tvb, offset,
145 RIP_ENTRY_LENGTH, "Unknown address family %u",
150 offset += RIP_ENTRY_LENGTH;
156 dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
160 proto_tree *rip_vektor_tree;
163 metric = tvb_get_ntohl(tvb, offset+16);
164 ti = proto_tree_add_text(tree, tvb, offset,
165 RIP_ENTRY_LENGTH, "Address not specified, Metric: %u",
167 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
169 proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
170 if (version == RIPv2) {
171 proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
173 proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
175 proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
178 proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
179 offset+16, 4, metric);
183 dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
187 proto_tree *rip_vektor_tree;
190 metric = tvb_get_ntohl(tvb, offset+16);
191 ti = proto_tree_add_text(tree, tvb, offset,
192 RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
193 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)), metric);
194 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
196 proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
197 if (version == RIPv2) {
198 proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
202 proto_tree_add_item(rip_vektor_tree, hf_rip_ip, tvb, offset+4, 4, FALSE);
204 if (version == RIPv2) {
205 proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
207 proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
210 proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
211 offset+16, 4, metric);
215 dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
218 proto_tree *rip_authentication_tree;
221 ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
223 rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
225 authtype = tvb_get_ntohs(tvb, offset + 2);
226 proto_tree_add_uint(rip_authentication_tree, hf_rip_auth, tvb, offset+2, 2,
229 proto_tree_add_item(rip_authentication_tree, hf_rip_auth_passwd,
230 tvb, offset+4, 16, FALSE);
235 proto_register_rip(void)
237 static hf_register_info hf[] = {
239 { "Command", "rip.command", FT_UINT8, BASE_DEC,
240 VALS(command_vals), 0, "What type of RIP Command is this", HFILL }},
243 { "Version", "rip.version", FT_UINT8, BASE_DEC,
244 VALS(version_vals), 0, "Version of the RIP protocol", HFILL }},
247 { "Address Family", "rip.family", FT_UINT16, BASE_DEC,
248 VALS(family_vals), 0, "Address family", HFILL }},
250 { &hf_rip_routing_domain,
251 { "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC,
252 NULL, 0, "RIPv2 Routing Domain", HFILL }},
255 { "IP Address", "rip.ip", FT_IPv4, BASE_NONE,
256 NULL, 0, "IP Address", HFILL}},
259 { "Netmask", "rip.netmask", FT_IPv4, BASE_NONE,
260 NULL, 0, "Netmask", HFILL}},
263 { "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE,
264 NULL, 0, "Next Hop router for this route", HFILL}},
267 { "Metric", "rip.metric", FT_UINT16, BASE_DEC,
268 NULL, 0, "Metric for this route", HFILL }},
271 { "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC,
272 NULL, 0, "Type of authentication", HFILL }},
274 { &hf_rip_auth_passwd,
275 { "Password", "rip.auth.passwd", FT_STRING, BASE_DEC,
276 NULL, 0, "Authentication password", HFILL }},
279 { "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC,
280 NULL, 0, "Route Tag", HFILL }},
283 static gint *ett[] = {
288 proto_rip = proto_register_protocol("Routing Information Protocol",
290 proto_register_field_array(proto_rip, hf, array_length(hf));
291 proto_register_subtree_array(ett, array_length(ett));
295 proto_reg_handoff_rip(void)
297 dissector_handle_t rip_handle;
299 rip_handle = create_dissector_handle(dissect_rip, proto_rip);
300 dissector_add("udp.port", UDP_PORT_RIP, rip_handle);