2 * Routines for RIPv1 and RIPv2 packet disassembly
3 * RFC1058 (STD 34), RFC1388, RFC1723, RFC2453 (STD 56)
4 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
6 * RFC2082 ( Keyed Message Digest Algorithm )
7 * Emanuele Caratti <wiz@iol.it>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #define NEW_PROTO_TREE_API
33 #include <epan/packet.h>
34 #include <epan/emem.h>
35 #include <epan/prefs.h>
36 #include <epan/to_str.h>
38 #define UDP_PORT_RIP 520
43 void proto_register_rip(void);
45 static const value_string version_vals[] = {
51 static const value_string command_vals[] = {
56 { 5, "Vendor specific (Sun)" },
60 #define AFVAL_UNSPEC 0
63 static const value_string family_vals[] = {
64 { AFVAL_UNSPEC, "Unspecified" },
69 #define AUTH_IP_ROUTE 1
70 #define AUTH_PASSWORD 2
71 #define AUTH_KEYED_MSG_DIGEST 3
73 static const value_string rip_auth_type[] = {
74 { AUTH_IP_ROUTE, "IP Route" },
75 { AUTH_PASSWORD, "Simple Password" },
76 { AUTH_KEYED_MSG_DIGEST, "Keyed Message Digest" },
80 #define RIP_HEADER_LENGTH 4
81 #define RIP_ENTRY_LENGTH 20
82 #define MD5_AUTH_DATA_LEN 16
84 static gboolean pref_display_routing_domain = FALSE;
86 void proto_reg_handoff_rip(void);
89 static dissector_handle_t rip_handle;
91 static header_field_info *hfi_rip = NULL;
93 #define RIP_HFI_INIT HFI_INIT(proto_rip)
95 static header_field_info hfi_rip_command RIP_HFI_INIT =
96 { "Command", "rip.command", FT_UINT8, BASE_DEC,
97 VALS(command_vals), 0, "What type of RIP Command is this", HFILL };
99 static header_field_info hfi_rip_version RIP_HFI_INIT =
100 { "Version", "rip.version", FT_UINT8, BASE_DEC,
101 VALS(version_vals), 0, "Version of the RIP protocol", HFILL };
103 static header_field_info hfi_rip_routing_domain RIP_HFI_INIT =
104 { "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC,
105 NULL, 0, "RIPv2 Routing Domain", HFILL };
107 static header_field_info hfi_rip_ip RIP_HFI_INIT =
108 { "IP Address", "rip.ip", FT_IPv4, BASE_NONE,
109 NULL, 0, NULL, HFILL};
111 static header_field_info hfi_rip_netmask RIP_HFI_INIT =
112 { "Netmask", "rip.netmask", FT_IPv4, BASE_NONE,
113 NULL, 0, NULL, HFILL};
115 static header_field_info hfi_rip_next_hop RIP_HFI_INIT =
116 { "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE,
117 NULL, 0, "Next Hop router for this route", HFILL};
119 static header_field_info hfi_rip_metric RIP_HFI_INIT =
120 { "Metric", "rip.metric", FT_UINT16, BASE_DEC,
121 NULL, 0, "Metric for this route", HFILL };
123 static header_field_info hfi_rip_auth RIP_HFI_INIT =
124 { "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC,
125 VALS(rip_auth_type), 0, "Type of authentication", HFILL };
127 static header_field_info hfi_rip_auth_passwd RIP_HFI_INIT =
128 { "Password", "rip.auth.passwd", FT_STRING, BASE_NONE,
129 NULL, 0, "Authentication password", HFILL };
131 static header_field_info hfi_rip_family RIP_HFI_INIT =
132 { "Address Family", "rip.family", FT_UINT16, BASE_DEC,
133 VALS(family_vals), 0, NULL, HFILL };
135 static header_field_info hfi_rip_route_tag RIP_HFI_INIT =
136 { "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC,
137 NULL, 0, NULL, HFILL };
139 static gint ett_rip = -1;
140 static gint ett_rip_vec = -1;
141 static gint ett_auth_vec = -1;
143 static void dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
145 static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
147 static gint dissect_rip_authentication(tvbuff_t *tvb, int offset,
151 dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
154 proto_tree *rip_tree = NULL;
159 gint trailer_len = 0;
160 gboolean is_md5_auth = FALSE;
162 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIP");
163 col_clear(pinfo->cinfo, COL_INFO);
165 command = tvb_get_guint8(tvb, 0);
166 version = tvb_get_guint8(tvb, 1);
168 col_set_str(pinfo->cinfo, COL_PROTOCOL,
169 val_to_str_const(version, version_vals, "RIP"));
170 col_add_str(pinfo->cinfo, COL_INFO,
171 val_to_str(command, command_vals, "Unknown command (%u)"));
174 ti = proto_tree_add_item(tree, hfi_rip, tvb, 0, -1, ENC_NA);
175 rip_tree = proto_item_add_subtree(ti, ett_rip);
177 proto_tree_add_uint(rip_tree, &hfi_rip_command, tvb, 0, 1, command);
178 proto_tree_add_uint(rip_tree, &hfi_rip_version, tvb, 1, 1, version);
179 if (version == RIPv2 && pref_display_routing_domain == TRUE)
180 proto_tree_add_uint(rip_tree, &hfi_rip_routing_domain, tvb, 2, 2,
181 tvb_get_ntohs(tvb, 2));
184 offset = RIP_HEADER_LENGTH;
186 /* zero or more entries */
187 while (tvb_reported_length_remaining(tvb, offset) > trailer_len ) {
188 family = tvb_get_ntohs(tvb, offset);
190 case AFVAL_UNSPEC: /* Unspecified */
192 * There should be one entry in the request, and a metric
193 * of infinity, meaning "show the entire routing table".
195 dissect_unspec_rip_vektor(tvb, offset, version, rip_tree);
197 case AFVAL_IP: /* IP */
198 dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
201 if( offset == RIP_HEADER_LENGTH ) {
202 trailer_len=dissect_rip_authentication(tvb, offset, rip_tree);
206 if(is_md5_auth && tvb_reported_length_remaining(tvb, offset) == 20)
208 /* Intentional fall through: auth Entry MUST be the first! */
210 proto_tree_add_text(rip_tree, tvb, offset,
211 RIP_ENTRY_LENGTH, "Unknown address family %u",
216 offset += RIP_ENTRY_LENGTH;
222 dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
226 proto_tree *rip_vektor_tree;
229 metric = tvb_get_ntohl(tvb, offset+16);
230 ti = proto_tree_add_text(tree, tvb, offset,
231 RIP_ENTRY_LENGTH, "Address not specified, Metric: %u",
233 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
235 proto_tree_add_item(rip_vektor_tree, &hfi_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN);
236 if (version == RIPv2) {
237 proto_tree_add_item(rip_vektor_tree, &hfi_rip_route_tag, tvb, offset+2, 2,
239 proto_tree_add_item(rip_vektor_tree, &hfi_rip_netmask, tvb, offset+8, 4,
241 proto_tree_add_item(rip_vektor_tree, &hfi_rip_next_hop, tvb, offset+12, 4,
244 proto_tree_add_uint(rip_vektor_tree, &hfi_rip_metric, tvb,
245 offset+16, 4, metric);
249 dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
253 proto_tree *rip_vektor_tree;
256 metric = tvb_get_ntohl(tvb, offset+16);
257 ti = proto_tree_add_text(tree, tvb, offset,
258 RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
259 tvb_ip_to_str(tvb, offset+4), metric);
260 rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
262 proto_tree_add_item(rip_vektor_tree, &hfi_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN);
263 if (version == RIPv2) {
264 proto_tree_add_item(rip_vektor_tree, &hfi_rip_route_tag, tvb, offset+2, 2,
268 proto_tree_add_item(rip_vektor_tree, &hfi_rip_ip, tvb, offset+4, 4, ENC_BIG_ENDIAN);
270 if (version == RIPv2) {
271 proto_tree_add_item(rip_vektor_tree, &hfi_rip_netmask, tvb, offset+8, 4,
273 proto_tree_add_item(rip_vektor_tree, &hfi_rip_next_hop, tvb, offset+12, 4,
276 proto_tree_add_uint(rip_vektor_tree, &hfi_rip_metric, tvb,
277 offset+16, 4, metric);
281 dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
284 proto_tree *rip_authentication_tree;
286 guint32 val, digest_off, auth_data_len;
289 authtype = tvb_get_ntohs(tvb, offset + 2);
291 ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
292 "Authentication: %s", val_to_str( authtype, rip_auth_type, "Unknown (%u)" ) );
293 rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
295 proto_tree_add_uint(rip_authentication_tree, &hfi_rip_auth, tvb, offset+2, 2,
298 switch ( authtype ) {
300 case AUTH_PASSWORD: /* Plain text password */
301 proto_tree_add_item(rip_authentication_tree, &hfi_rip_auth_passwd,
302 tvb, offset+4, 16, ENC_ASCII|ENC_NA);
305 case AUTH_KEYED_MSG_DIGEST: /* Keyed MD5 rfc 2082 */
306 digest_off = tvb_get_ntohs( tvb, offset+4 );
307 proto_tree_add_text( rip_authentication_tree, tvb, offset+4, 2,
308 "Digest Offset: %u" , digest_off );
309 val = tvb_get_guint8( tvb, offset+6 );
310 proto_tree_add_text( rip_authentication_tree, tvb, offset+6, 1,
311 "Key ID: %u" , val );
312 auth_data_len = tvb_get_guint8( tvb, offset+7 );
313 proto_tree_add_text( rip_authentication_tree, tvb, offset+7, 1,
314 "Auth Data Len: %u" , auth_data_len );
315 val = tvb_get_ntohl( tvb, offset+8 );
316 proto_tree_add_text( rip_authentication_tree, tvb, offset+8, 4,
317 "Seq num: %u" , val );
318 proto_tree_add_text( rip_authentication_tree, tvb, offset+12, 8,
320 ti = proto_tree_add_text( rip_authentication_tree, tvb, offset-4+digest_off,
321 MD5_AUTH_DATA_LEN+4, "Authentication Data Trailer" );
322 rip_authentication_tree = proto_item_add_subtree(ti, ett_auth_vec );
323 proto_tree_add_text( rip_authentication_tree, tvb, offset-4+digest_off+4,
324 MD5_AUTH_DATA_LEN, "Authentication Data: %s",
325 tvb_bytes_to_ep_str_punct(tvb, offset-4+digest_off+4,
326 MD5_AUTH_DATA_LEN, ' '));
329 return auth_data_len;
333 proto_register_rip(void)
335 #ifndef HAVE_HFI_SECTION_INIT
336 static header_field_info *hfi[] = {
340 &hfi_rip_routing_domain,
346 &hfi_rip_auth_passwd,
349 #endif /* HAVE_HFI_SECTION_INIT */
351 static gint *ett[] = {
357 module_t *rip_module;
360 proto_rip = proto_register_protocol("Routing Information Protocol",
362 hfi_rip = proto_registrar_get_nth(proto_rip);
364 proto_register_fields(proto_rip, hfi, array_length(hfi));
365 proto_register_subtree_array(ett, array_length(ett));
367 rip_module = prefs_register_protocol(proto_rip, proto_reg_handoff_rip);
369 prefs_register_bool_preference(rip_module, "display_routing_domain", "Display Routing Domain field", "Display the third and forth bytes of the RIPv2 header as the Routing Domain field (introduced in RFC 1388 [January 1993] and obsolete as of RFC 1723 [November 1994])", &pref_display_routing_domain);
371 rip_handle = create_dissector_handle(dissect_rip, proto_rip);
375 proto_reg_handoff_rip(void)
377 dissector_add_uint("udp.port", UDP_PORT_RIP, rip_handle);