RIP: Convert to old proto API

Related with #17774.
This commit is contained in:
João Valverde 2021-12-08 16:37:17 +00:00 committed by Wireshark GitLab Utility
parent 2fafa27759
commit 0080335d24
1 changed files with 128 additions and 120 deletions

View File

@ -12,9 +12,6 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#define NEW_PROTO_TREE_API
#include "config.h"
#include <epan/packet.h>
@ -73,77 +70,25 @@ static gboolean pref_display_routing_domain = FALSE;
static dissector_handle_t rip_handle;
static header_field_info *hfi_rip = NULL;
static int proto_rip = -1;
#define RIP_HFI_INIT HFI_INIT(proto_rip)
static header_field_info hfi_rip_command RIP_HFI_INIT = {
"Command", "rip.command", FT_UINT8, BASE_DEC,
VALS(command_vals), 0, "What type of RIP Command is this", HFILL };
static header_field_info hfi_rip_version RIP_HFI_INIT = {
"Version", "rip.version", FT_UINT8, BASE_DEC,
VALS(version_vals), 0, "Version of the RIP protocol", HFILL };
static header_field_info hfi_rip_routing_domain RIP_HFI_INIT = {
"Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC,
NULL, 0, "RIPv2 Routing Domain", HFILL };
static header_field_info hfi_rip_ip RIP_HFI_INIT = {
"IP Address", "rip.ip", FT_IPv4, BASE_NONE,
NULL, 0, NULL, HFILL};
static header_field_info hfi_rip_netmask RIP_HFI_INIT = {
"Netmask", "rip.netmask", FT_IPv4, BASE_NETMASK,
NULL, 0, NULL, HFILL};
static header_field_info hfi_rip_next_hop RIP_HFI_INIT = {
"Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE,
NULL, 0, "Next Hop router for this route", HFILL};
static header_field_info hfi_rip_metric RIP_HFI_INIT = {
"Metric", "rip.metric", FT_UINT16, BASE_DEC,
NULL, 0, "Metric for this route", HFILL };
static header_field_info hfi_rip_auth RIP_HFI_INIT = {
"Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC,
VALS(rip_auth_type), 0, "Type of authentication", HFILL };
static header_field_info hfi_rip_auth_passwd RIP_HFI_INIT = {
"Password", "rip.auth.passwd", FT_STRING, BASE_NONE,
NULL, 0, "Authentication password", HFILL };
static header_field_info hfi_rip_family RIP_HFI_INIT = {
"Address Family", "rip.family", FT_UINT16, BASE_DEC,
VALS(family_vals), 0, NULL, HFILL };
static header_field_info hfi_rip_route_tag RIP_HFI_INIT = {
"Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC,
NULL, 0, NULL, HFILL };
static header_field_info hfi_rip_zero_padding RIP_HFI_INIT = {
"Zero adding", "rip.zero_padding", FT_STRING, BASE_NONE,
NULL, 0, "Authentication password", HFILL };
static header_field_info hfi_rip_digest_offset RIP_HFI_INIT = {
"Digest Offset", "rip.digest_offset", FT_UINT16, BASE_DEC,
NULL, 0, NULL, HFILL };
static header_field_info hfi_rip_key_id RIP_HFI_INIT = {
"Key ID", "rip.key_id", FT_UINT8, BASE_DEC,
NULL, 0, NULL, HFILL };
static header_field_info hfi_rip_auth_data_len RIP_HFI_INIT = {
"Auth Data Len", "rip.auth_data_len", FT_UINT8, BASE_DEC,
NULL, 0, NULL, HFILL };
static header_field_info hfi_rip_auth_seq_num RIP_HFI_INIT = {
"Seq num", "rip.seq_num", FT_UINT32, BASE_DEC,
NULL, 0, NULL, HFILL };
static header_field_info hfi_rip_authentication_data RIP_HFI_INIT = {
"Authentication Data", "rip.authentication_data", FT_BYTES, BASE_NONE,
NULL, 0, NULL, HFILL };
static int hf_rip_auth = -1;
static int hf_rip_auth_data_len = -1;
static int hf_rip_auth_passwd = -1;
static int hf_rip_auth_seq_num = -1;
static int hf_rip_authentication_data = -1;
static int hf_rip_command = -1;
static int hf_rip_digest_offset = -1;
static int hf_rip_family = -1;
static int hf_rip_ip = -1;
static int hf_rip_key_id = -1;
static int hf_rip_metric = -1;
static int hf_rip_netmask = -1;
static int hf_rip_next_hop = -1;
static int hf_rip_route_tag = -1;
static int hf_rip_routing_domain = -1;
static int hf_rip_version = -1;
static int hf_rip_zero_padding = -1;
static gint ett_rip = -1;
static gint ett_rip_vec = -1;
@ -181,13 +126,13 @@ dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
col_add_str(pinfo->cinfo, COL_INFO,
val_to_str(command, command_vals, "Unknown command (%u)"));
ti = proto_tree_add_item(tree, hfi_rip, tvb, 0, -1, ENC_NA);
ti = proto_tree_add_item(tree, proto_rip, tvb, 0, -1, ENC_NA);
rip_tree = proto_item_add_subtree(ti, ett_rip);
proto_tree_add_uint(rip_tree, &hfi_rip_command, tvb, 0, 1, command);
proto_tree_add_uint(rip_tree, &hfi_rip_version, tvb, 1, 1, version);
proto_tree_add_uint(rip_tree, hf_rip_command, tvb, 0, 1, command);
proto_tree_add_uint(rip_tree, hf_rip_version, tvb, 1, 1, version);
if (version == RIPv2 && pref_display_routing_domain == TRUE)
proto_tree_add_item(rip_tree, &hfi_rip_routing_domain, tvb, 2, 2,
proto_tree_add_item(rip_tree, hf_rip_routing_domain, tvb, 2, 2,
ENC_BIG_ENDIAN);
/* skip header */
@ -239,16 +184,16 @@ dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
RIP_ENTRY_LENGTH, ett_rip_vec, NULL, "Address not specified, Metric: %u",
metric);
proto_tree_add_item(rip_vektor_tree, &hfi_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN);
if (version == RIPv2) {
proto_tree_add_item(rip_vektor_tree, &hfi_rip_route_tag, tvb, offset+2, 2,
proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
ENC_BIG_ENDIAN);
proto_tree_add_item(rip_vektor_tree, &hfi_rip_netmask, tvb, offset+8, 4,
proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
ENC_BIG_ENDIAN);
proto_tree_add_item(rip_vektor_tree, &hfi_rip_next_hop, tvb, offset+12, 4,
proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
ENC_BIG_ENDIAN);
}
proto_tree_add_uint(rip_vektor_tree, &hfi_rip_metric, tvb,
proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
offset+16, 4, metric);
}
@ -264,21 +209,21 @@ dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
RIP_ENTRY_LENGTH, ett_rip_vec, NULL, "IP Address: %s, Metric: %u",
tvb_ip_to_str(wmem_packet_scope(), tvb, offset+4), metric);
proto_tree_add_item(rip_vektor_tree, &hfi_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN);
if (version == RIPv2) {
proto_tree_add_item(rip_vektor_tree, &hfi_rip_route_tag, tvb, offset+2, 2,
proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
ENC_BIG_ENDIAN);
}
proto_tree_add_item(rip_vektor_tree, &hfi_rip_ip, tvb, offset+4, 4, ENC_BIG_ENDIAN);
proto_tree_add_item(rip_vektor_tree, hf_rip_ip, tvb, offset+4, 4, ENC_BIG_ENDIAN);
if (version == RIPv2) {
proto_tree_add_item(rip_vektor_tree, &hfi_rip_netmask, tvb, offset+8, 4,
proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
ENC_BIG_ENDIAN);
proto_tree_add_item(rip_vektor_tree, &hfi_rip_next_hop, tvb, offset+12, 4,
proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
ENC_BIG_ENDIAN);
}
proto_tree_add_uint(rip_vektor_tree, &hfi_rip_metric, tvb,
proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
offset+16, 4, metric);
}
@ -295,27 +240,27 @@ dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
rip_authentication_tree = proto_tree_add_subtree_format(tree, tvb, offset, RIP_ENTRY_LENGTH,
ett_rip_vec, NULL, "Authentication: %s", val_to_str( authtype, rip_auth_type, "Unknown (%u)" ) );
proto_tree_add_uint(rip_authentication_tree, &hfi_rip_auth, tvb, offset+2, 2,
proto_tree_add_uint(rip_authentication_tree, hf_rip_auth, tvb, offset+2, 2,
authtype);
switch ( authtype ) {
case AUTH_PASSWORD: /* Plain text password */
proto_tree_add_item(rip_authentication_tree, &hfi_rip_auth_passwd,
proto_tree_add_item(rip_authentication_tree, hf_rip_auth_passwd,
tvb, offset+4, 16, ENC_ASCII|ENC_NA);
break;
case AUTH_KEYED_MSG_DIGEST: /* Keyed MD5 rfc 2082 */
digest_off = tvb_get_ntohs( tvb, offset+4 );
proto_tree_add_item( rip_authentication_tree, &hfi_rip_digest_offset, tvb, offset+4, 2, ENC_BIG_ENDIAN);
proto_tree_add_item( rip_authentication_tree, &hfi_rip_key_id, tvb, offset+6, 1, ENC_NA);
proto_tree_add_item( rip_authentication_tree, hf_rip_digest_offset, tvb, offset+4, 2, ENC_BIG_ENDIAN);
proto_tree_add_item( rip_authentication_tree, hf_rip_key_id, tvb, offset+6, 1, ENC_NA);
auth_data_len = tvb_get_guint8( tvb, offset+7 );
proto_tree_add_item( rip_authentication_tree, &hfi_rip_auth_data_len, tvb, offset+7, 1, ENC_NA);
proto_tree_add_item( rip_authentication_tree, &hfi_rip_auth_seq_num, tvb, offset+8, 4, ENC_BIG_ENDIAN);
proto_tree_add_item( rip_authentication_tree, &hfi_rip_zero_padding, tvb, offset+12, 8, ENC_NA);
proto_tree_add_item( rip_authentication_tree, hf_rip_auth_data_len, tvb, offset+7, 1, ENC_NA);
proto_tree_add_item( rip_authentication_tree, hf_rip_auth_seq_num, tvb, offset+8, 4, ENC_BIG_ENDIAN);
proto_tree_add_item( rip_authentication_tree, hf_rip_zero_padding, tvb, offset+12, 8, ENC_NA);
rip_authentication_tree = proto_tree_add_subtree( rip_authentication_tree, tvb, offset-4+digest_off,
MD5_AUTH_DATA_LEN+4, ett_auth_vec, NULL, "Authentication Data Trailer" );
proto_tree_add_item( rip_authentication_tree, &hfi_rip_authentication_data, tvb, offset-4+digest_off+4,
proto_tree_add_item( rip_authentication_tree, hf_rip_authentication_data, tvb, offset-4+digest_off+4,
MD5_AUTH_DATA_LEN, ENC_NA);
break;
}
@ -325,27 +270,93 @@ dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
void
proto_register_rip(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_rip_command,
&hfi_rip_version,
&hfi_rip_routing_domain,
&hfi_rip_ip,
&hfi_rip_netmask,
&hfi_rip_next_hop,
&hfi_rip_metric,
&hfi_rip_auth,
&hfi_rip_auth_passwd,
&hfi_rip_family,
&hfi_rip_route_tag,
&hfi_rip_zero_padding,
&hfi_rip_digest_offset,
&hfi_rip_key_id,
&hfi_rip_auth_data_len,
&hfi_rip_auth_seq_num,
&hfi_rip_authentication_data,
static hf_register_info hf[] = {
{ &hf_rip_command,
{ "Command", "rip.command",
FT_UINT8, BASE_DEC, VALS(command_vals), 0,
"What type of RIP Command is this", HFILL }
},
{ &hf_rip_version,
{ "Version", "rip.version",
FT_UINT8, BASE_DEC, VALS(version_vals), 0,
"Version of the RIP protocol", HFILL }
},
{ &hf_rip_routing_domain,
{ "Routing Domain", "rip.routing_domain",
FT_UINT16, BASE_DEC, NULL, 0,
"RIPv2 Routing Domain", HFILL }
},
{ &hf_rip_ip,
{ "IP Address", "rip.ip",
FT_IPv4, BASE_NONE, NULL, 0,
NULL, HFILL }
},
{ &hf_rip_netmask,
{ "Netmask", "rip.netmask",
FT_IPv4, BASE_NETMASK, NULL, 0,
NULL, HFILL }
},
{ &hf_rip_next_hop,
{ "Next Hop", "rip.next_hop",
FT_IPv4, BASE_NONE, NULL, 0,
"Next Hop router for this route", HFILL }
},
{ &hf_rip_metric,
{ "Metric", "rip.metric",
FT_UINT16, BASE_DEC, NULL, 0,
"Metric for this route", HFILL }
},
{ &hf_rip_auth,
{ "Authentication type", "rip.auth.type",
FT_UINT16, BASE_DEC, VALS(rip_auth_type), 0,
"Type of authentication", HFILL }
},
{ &hf_rip_auth_passwd,
{ "Password", "rip.auth.passwd",
FT_STRING, BASE_NONE, NULL, 0,
"Authentication password", HFILL }
},
{ &hf_rip_family,
{ "Address Family", "rip.family",
FT_UINT16, BASE_DEC, VALS(family_vals), 0,
NULL, HFILL }
},
{ &hf_rip_route_tag,
{ "Route Tag", "rip.route_tag",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_rip_zero_padding,
{ "Zero adding", "rip.zero_padding",
FT_STRING, BASE_NONE, NULL, 0,
"Authentication password", HFILL }
},
{ &hf_rip_digest_offset,
{ "Digest Offset", "rip.digest_offset",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_rip_key_id,
{ "Key ID", "rip.key_id",
FT_UINT8, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_rip_auth_data_len,
{ "Auth Data Len", "rip.auth_data_len",
FT_UINT8, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_rip_auth_seq_num,
{ "Seq num", "rip.seq_num",
FT_UINT32, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_rip_authentication_data,
{ "Authentication Data", "rip.authentication_data",
FT_BYTES, BASE_NONE, NULL, 0,
NULL, HFILL }
},
};
#endif /* HAVE_HFI_SECTION_INIT */
static gint *ett[] = {
&ett_rip,
@ -359,12 +370,9 @@ proto_register_rip(void)
expert_module_t* expert_rip;
module_t *rip_module;
int proto_rip;
proto_rip = proto_register_protocol("Routing Information Protocol", "RIP", "rip");
hfi_rip = proto_registrar_get_nth(proto_rip);
proto_register_fields(proto_rip, hfi, array_length(hfi));
proto_register_field_array(proto_rip, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
expert_rip = expert_register_protocol(proto_rip);
expert_register_field_array(expert_rip, ei, array_length(ei));