2 * Routines for RIPv1 and RIPv2 packet disassembly
4 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
6 * RFC2082 ( Keyed Message Digest Algorithm )
7 * Emanuele Caratti <wiz@iol.it>
9 * $Id: packet-rip.c,v 1.34 2003/10/18 18:46:37 guy Exp $
11 * Ethereal - Network traffic analyzer
12 * By Gerald Combs <gerald@ethereal.com>
13 * Copyright 1998 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/packet.h>
36 #define UDP_PORT_RIP 520
41 static const value_string version_vals[] = {
47 static const value_string command_vals[] = {
52 { 5, "Vendor specific (Sun)" },
56 #define AFVAL_UNSPEC 0
59 static const value_string family_vals[] = {
60 { AFVAL_UNSPEC, "Unspecified" },
65 #define AUTH_IP_ROUTE 1
66 #define AUTH_PASSWORD 2
67 #define AUTH_KEYED_MSG_DIGEST 3
69 static const value_string rip_auth_type[] = {
70 { AUTH_IP_ROUTE, "IP Route" },
71 { AUTH_PASSWORD, "Simple Password" },
72 { AUTH_KEYED_MSG_DIGEST, "Keyed Message Digest" },
76 #define RIP_HEADER_LENGTH 4
77 #define RIP_ENTRY_LENGTH 20
79 static int proto_rip = -1;
80 static int hf_rip_command = -1;
81 static int hf_rip_version = -1;
82 static int hf_rip_routing_domain = -1;
83 static int hf_rip_ip = -1;
84 static int hf_rip_netmask = -1;
85 static int hf_rip_next_hop = -1;
86 static int hf_rip_metric = -1;
87 static int hf_rip_auth = -1;
88 static int hf_rip_auth_passwd = -1;
89 static int hf_rip_family = -1;
90 static int hf_rip_route_tag = -1;
92 static gint ett_rip = -1;
93 static gint ett_rip_vec = -1;
94 static gint ett_auth_vec = -1;
96 static void dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
98 static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
100 static gint dissect_rip_authentication(tvbuff_t *tvb, int offset,
104 dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
107 proto_tree *rip_tree = NULL;
112 gint trailer_len = 0;
114 if (check_col(pinfo->cinfo, COL_PROTOCOL))
115 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIP");
116 if (check_col(pinfo->cinfo, COL_INFO))
117 col_clear(pinfo->cinfo, COL_INFO);
119 command = tvb_get_guint8(tvb, 0);
120 version = tvb_get_guint8(tvb, 1);
122 if (check_col(pinfo->cinfo, COL_PROTOCOL))
123 col_add_str(pinfo->cinfo, COL_PROTOCOL,
124 val_to_str(version, version_vals, "RIP"));
125 if (check_col(pinfo->cinfo, COL_INFO))
126 col_add_str(pinfo->cinfo, COL_INFO,
127 val_to_str(command, command_vals, "Unknown command (%u)"));
130 ti = proto_tree_add_item(tree, proto_rip, tvb, 0, -1, FALSE);
131 rip_tree = proto_item_add_subtree(ti, ett_rip);
133 proto_tree_add_uint(rip_tree, hf_rip_command, tvb, 0, 1, command);
134 proto_tree_add_uint(rip_tree, hf_rip_version, tvb, 1, 1, version);
135 if (version == RIPv2)
136 proto_tree_add_uint(rip_tree, hf_rip_routing_domain, tvb, 2, 2,
137 tvb_get_ntohs(tvb, 2));
140 offset = RIP_HEADER_LENGTH;
142 /* zero or more entries */
143 while (tvb_reported_length_remaining(tvb, offset) > trailer_len ) {
144 family = tvb_get_ntohs(tvb, offset);
146 case AFVAL_UNSPEC: /* Unspecified */
148 * There should be one entry in the request, and a metric
149 * of infinity, meaning "show the entire routing table".
151 dissect_unspec_rip_vektor(tvb, offset, version, rip_tree);
153 case AFVAL_IP: /* IP */
154 dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
157 if( offset == RIP_HEADER_LENGTH ) {
158 trailer_len=dissect_rip_authentication(tvb, offset, rip_tree);
161 /* Intentional fall through: auth Entry MUST be the first! */
163 proto_tree_add_text(rip_tree, tvb, offset,
164 RIP_ENTRY_LENGTH, "Unknown address family %u",
169 offset += RIP_ENTRY_LENGTH;
175 dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
179 proto_tree *rip_vektor_tree;
182 metric = tvb_get_ntohl(tvb, offset+16);
183 ti = proto_tree_add_text(tree, tvb, offset,
184 RIP_ENTRY_LENGTH, "Address not specified, Metric: %u",
186 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
188 proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
189 if (version == RIPv2) {
190 proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
192 proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
194 proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
197 proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
198 offset+16, 4, metric);
202 dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
206 proto_tree *rip_vektor_tree;
209 metric = tvb_get_ntohl(tvb, offset+16);
210 ti = proto_tree_add_text(tree, tvb, offset,
211 RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
212 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)), metric);
213 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
215 proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
216 if (version == RIPv2) {
217 proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
221 proto_tree_add_item(rip_vektor_tree, hf_rip_ip, tvb, offset+4, 4, FALSE);
223 if (version == RIPv2) {
224 proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
226 proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
229 proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
230 offset+16, 4, metric);
234 rip_bytestring_to_str(const guint8 *ad, guint32 len, char punct) {
235 static gchar *str=NULL;
236 static guint str_len;
240 /* At least one version of Apple's C compiler/linker is buggy, causing
241 a complaint from the linker about the "literal C string section"
242 not ending with '\0' if we initialize a 16-element "char" array with
243 a 16-character string, the fact that initializing such an array with
244 such a string is perfectly legitimate ANSI C nonwithstanding, the 17th
245 '\0' byte in the string nonwithstanding. */
246 static const gchar hex_digits[16] =
247 { '0', '1', '2', '3', '4', '5', '6', '7',
248 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
251 str_len=sizeof(gchar)*len*(punct?3:2);
252 str=g_malloc(str_len);
254 if( str_len < (sizeof(gchar)*len*(punct?3:2)) ) {
256 str_len=sizeof(gchar)*len*(punct?3:2);
257 str=g_malloc(str_len);
267 *--p = hex_digits[octet&0xF];
269 *--p = hex_digits[octet&0xF];
280 dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
283 proto_tree *rip_authentication_tree;
285 guint32 val, digest_off, auth_data_len;
288 authtype = tvb_get_ntohs(tvb, offset + 2);
290 ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
291 "Authentication: %s", val_to_str( authtype, rip_auth_type, "Unknown (%u)" ) );
292 rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
294 proto_tree_add_uint(rip_authentication_tree, hf_rip_auth, tvb, offset+2, 2,
297 switch ( authtype ) {
299 case AUTH_PASSWORD: /* Plain text password */
300 proto_tree_add_item(rip_authentication_tree, hf_rip_auth_passwd,
301 tvb, offset+4, 16, FALSE);
304 case AUTH_KEYED_MSG_DIGEST: /* Keyed MD5 rfc 2082 */
305 digest_off = tvb_get_ntohs( tvb, offset+4 );
306 proto_tree_add_text( rip_authentication_tree, tvb, offset+4, 2,
307 "Digest Offset: %u" , digest_off );
308 val = tvb_get_guint8( tvb, offset+6 );
309 proto_tree_add_text( rip_authentication_tree, tvb, offset+6, 1,
310 "Key ID: %u" , val );
311 auth_data_len = tvb_get_guint8( tvb, offset+7 );
312 proto_tree_add_text( rip_authentication_tree, tvb, offset+7, 1,
313 "Auth Data Len: %u" , auth_data_len );
314 val = tvb_get_ntohl( tvb, offset+8 );
315 proto_tree_add_text( rip_authentication_tree, tvb, offset+8, 4,
316 "Seq num: %u" , val );
317 proto_tree_add_text( rip_authentication_tree, tvb, offset+12, 8,
319 ti = proto_tree_add_text( rip_authentication_tree, tvb, offset-4+digest_off,
320 auth_data_len, "Authentication Data Trailer" );
321 rip_authentication_tree = proto_item_add_subtree(ti, ett_auth_vec );
322 proto_tree_add_text( rip_authentication_tree, tvb, offset-4+digest_off+4,
323 auth_data_len-4, "Authentication Data: %s",
324 rip_bytestring_to_str(
325 tvb_get_ptr( tvb, offset-4+digest_off+4,auth_data_len-4),
326 auth_data_len-4, ' '));
329 return auth_data_len;
333 proto_register_rip(void)
335 static hf_register_info hf[] = {
337 { "Command", "rip.command", FT_UINT8, BASE_DEC,
338 VALS(command_vals), 0, "What type of RIP Command is this", HFILL }},
341 { "Version", "rip.version", FT_UINT8, BASE_DEC,
342 VALS(version_vals), 0, "Version of the RIP protocol", HFILL }},
345 { "Address Family", "rip.family", FT_UINT16, BASE_DEC,
346 VALS(family_vals), 0, "Address family", HFILL }},
348 { &hf_rip_routing_domain,
349 { "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC,
350 NULL, 0, "RIPv2 Routing Domain", HFILL }},
353 { "IP Address", "rip.ip", FT_IPv4, BASE_NONE,
354 NULL, 0, "IP Address", HFILL}},
357 { "Netmask", "rip.netmask", FT_IPv4, BASE_NONE,
358 NULL, 0, "Netmask", HFILL}},
361 { "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE,
362 NULL, 0, "Next Hop router for this route", HFILL}},
365 { "Metric", "rip.metric", FT_UINT16, BASE_DEC,
366 NULL, 0, "Metric for this route", HFILL }},
369 { "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC,
370 VALS(rip_auth_type), 0, "Type of authentication", HFILL }},
372 { &hf_rip_auth_passwd,
373 { "Password", "rip.auth.passwd", FT_STRING, BASE_DEC,
374 NULL, 0, "Authentication password", HFILL }},
377 { "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC,
378 NULL, 0, "Route Tag", HFILL }},
381 static gint *ett[] = {
387 proto_rip = proto_register_protocol("Routing Information Protocol",
389 proto_register_field_array(proto_rip, hf, array_length(hf));
390 proto_register_subtree_array(ett, array_length(ett));
394 proto_reg_handoff_rip(void)
396 dissector_handle_t rip_handle;
398 rip_handle = create_dissector_handle(dissect_rip, proto_rip);
399 dissector_add("udp.port", UDP_PORT_RIP, rip_handle);