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 * SPDX-License-Identifier: GPL-2.0-or-later
16 #define NEW_PROTO_TREE_API
20 #include <epan/packet.h>
21 #include <epan/expert.h>
22 #include <epan/prefs.h>
23 #include <epan/to_str.h>
25 #define UDP_PORT_RIP 520
30 void proto_register_rip(void);
31 void proto_reg_handoff_rip(void);
33 static const value_string version_vals[] = {
39 static const value_string command_vals[] = {
44 { 5, "Vendor specific (Sun)" },
48 #define AFVAL_UNSPEC 0
51 static const value_string family_vals[] = {
52 { AFVAL_UNSPEC, "Unspecified" },
57 #define AUTH_IP_ROUTE 1
58 #define AUTH_PASSWORD 2
59 #define AUTH_KEYED_MSG_DIGEST 3
61 static const value_string rip_auth_type[] = {
62 { AUTH_IP_ROUTE, "IP Route" },
63 { AUTH_PASSWORD, "Simple Password" },
64 { AUTH_KEYED_MSG_DIGEST, "Keyed Message Digest" },
68 #define RIP_HEADER_LENGTH 4
69 #define RIP_ENTRY_LENGTH 20
70 #define MD5_AUTH_DATA_LEN 16
72 static gboolean pref_display_routing_domain = FALSE;
74 static dissector_handle_t rip_handle;
76 static header_field_info *hfi_rip = NULL;
78 #define RIP_HFI_INIT HFI_INIT(proto_rip)
80 static header_field_info hfi_rip_command RIP_HFI_INIT = {
81 "Command", "rip.command", FT_UINT8, BASE_DEC,
82 VALS(command_vals), 0, "What type of RIP Command is this", HFILL };
84 static header_field_info hfi_rip_version RIP_HFI_INIT = {
85 "Version", "rip.version", FT_UINT8, BASE_DEC,
86 VALS(version_vals), 0, "Version of the RIP protocol", HFILL };
88 static header_field_info hfi_rip_routing_domain RIP_HFI_INIT = {
89 "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC,
90 NULL, 0, "RIPv2 Routing Domain", HFILL };
92 static header_field_info hfi_rip_ip RIP_HFI_INIT = {
93 "IP Address", "rip.ip", FT_IPv4, BASE_NONE,
94 NULL, 0, NULL, HFILL};
96 static header_field_info hfi_rip_netmask RIP_HFI_INIT = {
97 "Netmask", "rip.netmask", FT_IPv4, BASE_NETMASK,
98 NULL, 0, NULL, HFILL};
100 static header_field_info hfi_rip_next_hop RIP_HFI_INIT = {
101 "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE,
102 NULL, 0, "Next Hop router for this route", HFILL};
104 static header_field_info hfi_rip_metric RIP_HFI_INIT = {
105 "Metric", "rip.metric", FT_UINT16, BASE_DEC,
106 NULL, 0, "Metric for this route", HFILL };
108 static header_field_info hfi_rip_auth RIP_HFI_INIT = {
109 "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC,
110 VALS(rip_auth_type), 0, "Type of authentication", HFILL };
112 static header_field_info hfi_rip_auth_passwd RIP_HFI_INIT = {
113 "Password", "rip.auth.passwd", FT_STRING, BASE_NONE,
114 NULL, 0, "Authentication password", HFILL };
116 static header_field_info hfi_rip_family RIP_HFI_INIT = {
117 "Address Family", "rip.family", FT_UINT16, BASE_DEC,
118 VALS(family_vals), 0, NULL, HFILL };
120 static header_field_info hfi_rip_route_tag RIP_HFI_INIT = {
121 "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC,
122 NULL, 0, NULL, HFILL };
124 static header_field_info hfi_rip_zero_padding RIP_HFI_INIT = {
125 "Zero adding", "rip.zero_padding", FT_STRING, BASE_NONE,
126 NULL, 0, "Authentication password", HFILL };
128 static header_field_info hfi_rip_digest_offset RIP_HFI_INIT = {
129 "Digest Offset", "rip.digest_offset", FT_UINT16, BASE_DEC,
130 NULL, 0, NULL, HFILL };
132 static header_field_info hfi_rip_key_id RIP_HFI_INIT = {
133 "Key ID", "rip.key_id", FT_UINT8, BASE_DEC,
134 NULL, 0, NULL, HFILL };
136 static header_field_info hfi_rip_auth_data_len RIP_HFI_INIT = {
137 "Auth Data Len", "rip.auth_data_len", FT_UINT8, BASE_DEC,
138 NULL, 0, NULL, HFILL };
140 static header_field_info hfi_rip_auth_seq_num RIP_HFI_INIT = {
141 "Seq num", "rip.seq_num", FT_UINT32, BASE_DEC,
142 NULL, 0, NULL, HFILL };
144 static header_field_info hfi_rip_authentication_data RIP_HFI_INIT = {
145 "Authentication Data", "rip.authentication_data", FT_BYTES, BASE_NONE,
146 NULL, 0, NULL, HFILL };
148 static gint ett_rip = -1;
149 static gint ett_rip_vec = -1;
150 static gint ett_auth_vec = -1;
152 static expert_field ei_rip_unknown_address_family = EI_INIT;
154 static void dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
156 static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
158 static gint dissect_rip_authentication(tvbuff_t *tvb, int offset,
162 dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
165 proto_tree *rip_tree = NULL;
170 gint trailer_len = 0;
171 gboolean is_md5_auth = FALSE;
173 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIP");
174 col_clear(pinfo->cinfo, COL_INFO);
176 command = tvb_get_guint8(tvb, 0);
177 version = tvb_get_guint8(tvb, 1);
179 col_set_str(pinfo->cinfo, COL_PROTOCOL,
180 val_to_str_const(version, version_vals, "RIP"));
181 col_add_str(pinfo->cinfo, COL_INFO,
182 val_to_str(command, command_vals, "Unknown command (%u)"));
184 ti = proto_tree_add_item(tree, hfi_rip, tvb, 0, -1, ENC_NA);
185 rip_tree = proto_item_add_subtree(ti, ett_rip);
187 proto_tree_add_uint(rip_tree, &hfi_rip_command, tvb, 0, 1, command);
188 proto_tree_add_uint(rip_tree, &hfi_rip_version, tvb, 1, 1, version);
189 if (version == RIPv2 && pref_display_routing_domain == TRUE)
190 proto_tree_add_item(rip_tree, &hfi_rip_routing_domain, tvb, 2, 2,
194 offset = RIP_HEADER_LENGTH;
196 /* zero or more entries */
197 while (tvb_reported_length_remaining(tvb, offset) > trailer_len ) {
198 family = tvb_get_ntohs(tvb, offset);
200 case AFVAL_UNSPEC: /* Unspecified */
202 * There should be one entry in the request, and a metric
203 * of infinity, meaning "show the entire routing table".
205 dissect_unspec_rip_vektor(tvb, offset, version, rip_tree);
207 case AFVAL_IP: /* IP */
208 dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
211 if( offset == RIP_HEADER_LENGTH ) {
212 trailer_len=dissect_rip_authentication(tvb, offset, rip_tree);
216 if(is_md5_auth && tvb_reported_length_remaining(tvb, offset) == 20)
218 /* Intentional fall through */ /* auth Entry MUST be the first! */
220 proto_tree_add_expert_format(rip_tree, pinfo, &ei_rip_unknown_address_family, tvb, offset,
221 RIP_ENTRY_LENGTH, "Unknown address family %u", family);
225 offset += RIP_ENTRY_LENGTH;
227 return tvb_captured_length(tvb);
231 dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
234 proto_tree *rip_vektor_tree;
237 metric = tvb_get_ntohl(tvb, offset+16);
238 rip_vektor_tree = proto_tree_add_subtree_format(tree, tvb, offset,
239 RIP_ENTRY_LENGTH, ett_rip_vec, NULL, "Address not specified, Metric: %u",
242 proto_tree_add_item(rip_vektor_tree, &hfi_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN);
243 if (version == RIPv2) {
244 proto_tree_add_item(rip_vektor_tree, &hfi_rip_route_tag, tvb, offset+2, 2,
246 proto_tree_add_item(rip_vektor_tree, &hfi_rip_netmask, tvb, offset+8, 4,
248 proto_tree_add_item(rip_vektor_tree, &hfi_rip_next_hop, tvb, offset+12, 4,
251 proto_tree_add_uint(rip_vektor_tree, &hfi_rip_metric, tvb,
252 offset+16, 4, metric);
256 dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
259 proto_tree *rip_vektor_tree;
262 metric = tvb_get_ntohl(tvb, offset+16);
263 rip_vektor_tree = proto_tree_add_subtree_format(tree, tvb, offset,
264 RIP_ENTRY_LENGTH, ett_rip_vec, NULL, "IP Address: %s, Metric: %u",
265 tvb_ip_to_str(tvb, offset+4), metric);
267 proto_tree_add_item(rip_vektor_tree, &hfi_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN);
268 if (version == RIPv2) {
269 proto_tree_add_item(rip_vektor_tree, &hfi_rip_route_tag, tvb, offset+2, 2,
273 proto_tree_add_item(rip_vektor_tree, &hfi_rip_ip, tvb, offset+4, 4, ENC_BIG_ENDIAN);
275 if (version == RIPv2) {
276 proto_tree_add_item(rip_vektor_tree, &hfi_rip_netmask, tvb, offset+8, 4,
278 proto_tree_add_item(rip_vektor_tree, &hfi_rip_next_hop, tvb, offset+12, 4,
281 proto_tree_add_uint(rip_vektor_tree, &hfi_rip_metric, tvb,
282 offset+16, 4, metric);
286 dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
288 proto_tree *rip_authentication_tree;
290 guint32 digest_off, auth_data_len;
293 authtype = tvb_get_ntohs(tvb, offset + 2);
295 rip_authentication_tree = proto_tree_add_subtree_format(tree, tvb, offset, RIP_ENTRY_LENGTH,
296 ett_rip_vec, NULL, "Authentication: %s", val_to_str( authtype, rip_auth_type, "Unknown (%u)" ) );
298 proto_tree_add_uint(rip_authentication_tree, &hfi_rip_auth, tvb, offset+2, 2,
301 switch ( authtype ) {
303 case AUTH_PASSWORD: /* Plain text password */
304 proto_tree_add_item(rip_authentication_tree, &hfi_rip_auth_passwd,
305 tvb, offset+4, 16, ENC_ASCII|ENC_NA);
308 case AUTH_KEYED_MSG_DIGEST: /* Keyed MD5 rfc 2082 */
309 digest_off = tvb_get_ntohs( tvb, offset+4 );
310 proto_tree_add_item( rip_authentication_tree, &hfi_rip_digest_offset, tvb, offset+4, 2, ENC_BIG_ENDIAN);
311 proto_tree_add_item( rip_authentication_tree, &hfi_rip_key_id, tvb, offset+6, 1, ENC_NA);
312 auth_data_len = tvb_get_guint8( tvb, offset+7 );
313 proto_tree_add_item( rip_authentication_tree, &hfi_rip_auth_data_len, tvb, offset+7, 1, ENC_NA);
314 proto_tree_add_item( rip_authentication_tree, &hfi_rip_auth_seq_num, tvb, offset+8, 4, ENC_BIG_ENDIAN);
315 proto_tree_add_item( rip_authentication_tree, &hfi_rip_zero_padding, tvb, offset+12, 8, ENC_NA);
316 rip_authentication_tree = proto_tree_add_subtree( rip_authentication_tree, tvb, offset-4+digest_off,
317 MD5_AUTH_DATA_LEN+4, ett_auth_vec, NULL, "Authentication Data Trailer" );
318 proto_tree_add_item( rip_authentication_tree, &hfi_rip_authentication_data, tvb, offset-4+digest_off+4,
319 MD5_AUTH_DATA_LEN, ENC_NA);
322 return auth_data_len;
326 proto_register_rip(void)
328 #ifndef HAVE_HFI_SECTION_INIT
329 static header_field_info *hfi[] = {
332 &hfi_rip_routing_domain,
338 &hfi_rip_auth_passwd,
341 &hfi_rip_zero_padding,
342 &hfi_rip_digest_offset,
344 &hfi_rip_auth_data_len,
345 &hfi_rip_auth_seq_num,
346 &hfi_rip_authentication_data,
348 #endif /* HAVE_HFI_SECTION_INIT */
350 static gint *ett[] = {
356 static ei_register_info ei[] = {
357 { &ei_rip_unknown_address_family, { "rip.unknown_address_family", PI_PROTOCOL, PI_WARN, "Unknown address family", EXPFILL }},
360 expert_module_t* expert_rip;
361 module_t *rip_module;
364 proto_rip = proto_register_protocol("Routing Information Protocol", "RIP", "rip");
365 hfi_rip = proto_registrar_get_nth(proto_rip);
367 proto_register_fields(proto_rip, hfi, array_length(hfi));
368 proto_register_subtree_array(ett, array_length(ett));
369 expert_rip = expert_register_protocol(proto_rip);
370 expert_register_field_array(expert_rip, ei, array_length(ei));
372 rip_module = prefs_register_protocol(proto_rip, NULL);
374 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);
376 rip_handle = create_dissector_handle(dissect_rip, proto_rip);
380 proto_reg_handoff_rip(void)
382 dissector_add_uint_with_preference("udp.port", UDP_PORT_RIP, rip_handle);
386 * Editor modelines - http://www.wireshark.org/tools/modelines.html
391 * indent-tabs-mode: nil
394 * vi: set shiftwidth=4 tabstop=8 expandtab:
395 * :indentSize=4:tabSize=8:noTabs=true: