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>
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
78 #define MD5_AUTH_DATA_LEN 16
80 static int proto_rip = -1;
81 static int hf_rip_command = -1;
82 static int hf_rip_version = -1;
83 static int hf_rip_routing_domain = -1;
84 static int hf_rip_ip = -1;
85 static int hf_rip_netmask = -1;
86 static int hf_rip_next_hop = -1;
87 static int hf_rip_metric = -1;
88 static int hf_rip_auth = -1;
89 static int hf_rip_auth_passwd = -1;
90 static int hf_rip_family = -1;
91 static int hf_rip_route_tag = -1;
93 static gint ett_rip = -1;
94 static gint ett_rip_vec = -1;
95 static gint ett_auth_vec = -1;
97 static void dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
99 static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
101 static gint dissect_rip_authentication(tvbuff_t *tvb, int offset,
105 dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
108 proto_tree *rip_tree = NULL;
113 gint trailer_len = 0;
114 gboolean is_md5_auth = FALSE;
116 if (check_col(pinfo->cinfo, COL_PROTOCOL))
117 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIP");
118 if (check_col(pinfo->cinfo, COL_INFO))
119 col_clear(pinfo->cinfo, COL_INFO);
121 command = tvb_get_guint8(tvb, 0);
122 version = tvb_get_guint8(tvb, 1);
124 if (check_col(pinfo->cinfo, COL_PROTOCOL))
125 col_add_str(pinfo->cinfo, COL_PROTOCOL,
126 val_to_str(version, version_vals, "RIP"));
127 if (check_col(pinfo->cinfo, COL_INFO))
128 col_add_str(pinfo->cinfo, COL_INFO,
129 val_to_str(command, command_vals, "Unknown command (%u)"));
132 ti = proto_tree_add_item(tree, proto_rip, tvb, 0, -1, FALSE);
133 rip_tree = proto_item_add_subtree(ti, ett_rip);
135 proto_tree_add_uint(rip_tree, hf_rip_command, tvb, 0, 1, command);
136 proto_tree_add_uint(rip_tree, hf_rip_version, tvb, 1, 1, version);
137 if (version == RIPv2)
138 proto_tree_add_uint(rip_tree, hf_rip_routing_domain, tvb, 2, 2,
139 tvb_get_ntohs(tvb, 2));
142 offset = RIP_HEADER_LENGTH;
144 /* zero or more entries */
145 while (tvb_reported_length_remaining(tvb, offset) > trailer_len ) {
146 family = tvb_get_ntohs(tvb, offset);
148 case AFVAL_UNSPEC: /* Unspecified */
150 * There should be one entry in the request, and a metric
151 * of infinity, meaning "show the entire routing table".
153 dissect_unspec_rip_vektor(tvb, offset, version, rip_tree);
155 case AFVAL_IP: /* IP */
156 dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
159 if( offset == RIP_HEADER_LENGTH ) {
160 trailer_len=dissect_rip_authentication(tvb, offset, rip_tree);
164 if(is_md5_auth && tvb_reported_length_remaining(tvb, offset) == 20)
166 /* Intentional fall through: auth Entry MUST be the first! */
168 proto_tree_add_text(rip_tree, tvb, offset,
169 RIP_ENTRY_LENGTH, "Unknown address family %u",
174 offset += RIP_ENTRY_LENGTH;
180 dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
184 proto_tree *rip_vektor_tree;
187 metric = tvb_get_ntohl(tvb, offset+16);
188 ti = proto_tree_add_text(tree, tvb, offset,
189 RIP_ENTRY_LENGTH, "Address not specified, Metric: %u",
191 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
193 proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
194 if (version == RIPv2) {
195 proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
197 proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
199 proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
202 proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
203 offset+16, 4, metric);
207 dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
211 proto_tree *rip_vektor_tree;
214 metric = tvb_get_ntohl(tvb, offset+16);
215 ti = proto_tree_add_text(tree, tvb, offset,
216 RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
217 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)), metric);
218 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
220 proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
221 if (version == RIPv2) {
222 proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
226 proto_tree_add_item(rip_vektor_tree, hf_rip_ip, tvb, offset+4, 4, FALSE);
228 if (version == RIPv2) {
229 proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
231 proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
234 proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
235 offset+16, 4, metric);
239 rip_bytestring_to_str(const guint8 *ad, guint32 len, char punct) {
240 static gchar *str=NULL;
241 static guint str_len;
245 /* At least one version of Apple's C compiler/linker is buggy, causing
246 a complaint from the linker about the "literal C string section"
247 not ending with '\0' if we initialize a 16-element "char" array with
248 a 16-character string, the fact that initializing such an array with
249 such a string is perfectly legitimate ANSI C nonwithstanding, the 17th
250 '\0' byte in the string nonwithstanding. */
251 static const gchar hex_digits[16] =
252 { '0', '1', '2', '3', '4', '5', '6', '7',
253 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
256 str_len=sizeof(gchar)*len*(punct?3:2);
257 str=g_malloc(str_len);
259 if( str_len < (sizeof(gchar)*len*(punct?3:2)) ) {
261 str_len=sizeof(gchar)*len*(punct?3:2);
262 str=g_malloc(str_len);
272 *--p = hex_digits[octet&0xF];
274 *--p = hex_digits[octet&0xF];
285 dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
288 proto_tree *rip_authentication_tree;
290 guint32 val, digest_off, auth_data_len;
293 authtype = tvb_get_ntohs(tvb, offset + 2);
295 ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
296 "Authentication: %s", val_to_str( authtype, rip_auth_type, "Unknown (%u)" ) );
297 rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
299 proto_tree_add_uint(rip_authentication_tree, hf_rip_auth, tvb, offset+2, 2,
302 switch ( authtype ) {
304 case AUTH_PASSWORD: /* Plain text password */
305 proto_tree_add_item(rip_authentication_tree, hf_rip_auth_passwd,
306 tvb, offset+4, 16, FALSE);
309 case AUTH_KEYED_MSG_DIGEST: /* Keyed MD5 rfc 2082 */
310 digest_off = tvb_get_ntohs( tvb, offset+4 );
311 proto_tree_add_text( rip_authentication_tree, tvb, offset+4, 2,
312 "Digest Offset: %u" , digest_off );
313 val = tvb_get_guint8( tvb, offset+6 );
314 proto_tree_add_text( rip_authentication_tree, tvb, offset+6, 1,
315 "Key ID: %u" , val );
316 auth_data_len = tvb_get_guint8( tvb, offset+7 );
317 proto_tree_add_text( rip_authentication_tree, tvb, offset+7, 1,
318 "Auth Data Len: %u" , auth_data_len );
319 val = tvb_get_ntohl( tvb, offset+8 );
320 proto_tree_add_text( rip_authentication_tree, tvb, offset+8, 4,
321 "Seq num: %u" , val );
322 proto_tree_add_text( rip_authentication_tree, tvb, offset+12, 8,
324 ti = proto_tree_add_text( rip_authentication_tree, tvb, offset-4+digest_off,
325 MD5_AUTH_DATA_LEN+4, "Authentication Data Trailer" );
326 rip_authentication_tree = proto_item_add_subtree(ti, ett_auth_vec );
327 proto_tree_add_text( rip_authentication_tree, tvb, offset-4+digest_off+4,
328 MD5_AUTH_DATA_LEN, "Authentication Data: %s",
329 rip_bytestring_to_str(
330 tvb_get_ptr( tvb, offset-4+digest_off+4,MD5_AUTH_DATA_LEN),
331 MD5_AUTH_DATA_LEN, ' '));
334 return auth_data_len;
338 proto_register_rip(void)
340 static hf_register_info hf[] = {
342 { "Command", "rip.command", FT_UINT8, BASE_DEC,
343 VALS(command_vals), 0, "What type of RIP Command is this", HFILL }},
346 { "Version", "rip.version", FT_UINT8, BASE_DEC,
347 VALS(version_vals), 0, "Version of the RIP protocol", HFILL }},
350 { "Address Family", "rip.family", FT_UINT16, BASE_DEC,
351 VALS(family_vals), 0, "Address family", HFILL }},
353 { &hf_rip_routing_domain,
354 { "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC,
355 NULL, 0, "RIPv2 Routing Domain", HFILL }},
358 { "IP Address", "rip.ip", FT_IPv4, BASE_NONE,
359 NULL, 0, "IP Address", HFILL}},
362 { "Netmask", "rip.netmask", FT_IPv4, BASE_NONE,
363 NULL, 0, "Netmask", HFILL}},
366 { "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE,
367 NULL, 0, "Next Hop router for this route", HFILL}},
370 { "Metric", "rip.metric", FT_UINT16, BASE_DEC,
371 NULL, 0, "Metric for this route", HFILL }},
374 { "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC,
375 VALS(rip_auth_type), 0, "Type of authentication", HFILL }},
377 { &hf_rip_auth_passwd,
378 { "Password", "rip.auth.passwd", FT_STRING, BASE_DEC,
379 NULL, 0, "Authentication password", HFILL }},
382 { "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC,
383 NULL, 0, "Route Tag", HFILL }},
386 static gint *ett[] = {
392 proto_rip = proto_register_protocol("Routing Information Protocol",
394 proto_register_field_array(proto_rip, hf, array_length(hf));
395 proto_register_subtree_array(ett, array_length(ett));
399 proto_reg_handoff_rip(void)
401 dissector_handle_t rip_handle;
403 rip_handle = create_dissector_handle(dissect_rip, proto_rip);
404 dissector_add("udp.port", UDP_PORT_RIP, rip_handle);