From 52064a51e139c9de54745c825f169b1f5c153c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Sat, 11 Dec 2021 15:35:05 +0000 Subject: [PATCH] Netlink psample: Convert to normal proto tree API --- epan/dissectors/packet-netlink-psample.c | 200 ++++++++++++----------- 1 file changed, 106 insertions(+), 94 deletions(-) diff --git a/epan/dissectors/packet-netlink-psample.c b/epan/dissectors/packet-netlink-psample.c index e5f2633ff4..26aa1a92fb 100644 --- a/epan/dissectors/packet-netlink-psample.c +++ b/epan/dissectors/packet-netlink-psample.c @@ -65,7 +65,21 @@ static int proto_netlink_psample = -1; static dissector_handle_t netlink_psample_handle; static dissector_table_t sll_ltype_table; -static header_field_info *hfi_netlink_psample = NULL; +static int hf_psample_attrs = -1; +static int hf_psample_commands = -1; +static int hf_psample_group_refcount = -1; +static int hf_psample_group_seq = -1; +static int hf_psample_iifindex = -1; +static int hf_psample_latency = -1; +static int hf_psample_oifindex = -1; +static int hf_psample_origsize = -1; +static int hf_psample_out_tc = -1; +static int hf_psample_out_tc_occ = -1; +static int hf_psample_proto = -1; +static int hf_psample_sample_group = -1; +static int hf_psample_sample_rate = -1; +static int hf_psample_timestamp = -1; +static int hf_psample_tunnel = -1; static gint ett_psample = -1; static gint ett_psample_attrs = -1; @@ -101,66 +115,6 @@ static const value_string ws_psample_attrs_vals[] = { static value_string_ext ws_psample_attrs_vals_ext = VALUE_STRING_EXT_INIT(ws_psample_attrs_vals); -static header_field_info hfi_psample_commands = - { "Command", "netlink.psample.cmd", FT_UINT8, BASE_DEC | BASE_EXT_STRING, - &ws_psample_commands_vals_ext, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_attrs = - { "Attribute type", "netlink.psample.attr_type", FT_UINT16, BASE_DEC | BASE_EXT_STRING, - &ws_psample_attrs_vals_ext, NLA_TYPE_MASK, NULL, HFILL }; - -static header_field_info hfi_psample_iifindex = - { "Input interface index", "netlink.psample.iifindex", FT_UINT16, BASE_HEX, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_oifindex = - { "Output interface index", "netlink.psample.oifindex", FT_UINT16, BASE_HEX, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_origsize = - { "Original size", "netlink.psample.origsize", FT_UINT32, BASE_HEX, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_sample_group = - { "Sample group", "netlink.psample.sample_group", FT_UINT32, BASE_DEC, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_group_seq = - { "Group sequence number", "netlink.psample.group_seq_num", FT_UINT32, BASE_DEC, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_sample_rate = - { "Sample rate", "netlink.psample.sample_rate", FT_UINT32, BASE_DEC, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_tunnel = - { "Tunnel", "netlink.psample.tunnel", FT_UINT32, BASE_HEX, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_group_refcount = - { "Group reference count", "netlink.psample.group_refcount", FT_UINT32, BASE_HEX, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_out_tc = - { "Output traffic class", "netlink.psample.out_tc", FT_UINT16, BASE_DEC, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_out_tc_occ = - { "Output traffic class occupancy", "netlink.psample.out_tc_occ", FT_UINT64, BASE_DEC, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_latency = - { "Latency", "netlink.psample.latency", FT_UINT64, BASE_DEC, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_timestamp = - { "Timestamp", "netlink.psample.timestamp", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, - NULL, 0x00, NULL, HFILL }; - -static header_field_info hfi_psample_proto = - { "Protocol", "netlink.psample.proto", FT_UINT16, BASE_HEX, - NULL, 0x00, NULL, HFILL }; - static int dissect_psample_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int nla_type, int offset, int len) { @@ -173,27 +127,27 @@ dissect_psample_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_ switch (type) { case WS_PSAMPLE_ATTR_IIFINDEX: - proto_tree_add_item_ret_uint(tree, hfi_psample_iifindex.id, tvb, offset, len, nl_data->encoding, &value); + proto_tree_add_item_ret_uint(tree, hf_psample_iifindex, tvb, offset, len, nl_data->encoding, &value); proto_item_append_text(tree, ": %u", value); return 1; case WS_PSAMPLE_ATTR_OIFINDEX: - proto_tree_add_item_ret_uint(tree, hfi_psample_oifindex.id, tvb, offset, len, nl_data->encoding, &value); + proto_tree_add_item_ret_uint(tree, hf_psample_oifindex, tvb, offset, len, nl_data->encoding, &value); proto_item_append_text(tree, ": %u", value); return 1; case WS_PSAMPLE_ATTR_ORIGSIZE: - proto_tree_add_item_ret_uint(tree, hfi_psample_origsize.id, tvb, offset, len, nl_data->encoding, &value); + proto_tree_add_item_ret_uint(tree, hf_psample_origsize, tvb, offset, len, nl_data->encoding, &value); proto_item_append_text(tree, ": %u", value); return 1; case WS_PSAMPLE_ATTR_SAMPLE_GROUP: - proto_tree_add_item_ret_uint(tree, hfi_psample_sample_group.id, tvb, offset, len, nl_data->encoding, &value); + proto_tree_add_item_ret_uint(tree, hf_psample_sample_group, tvb, offset, len, nl_data->encoding, &value); proto_item_append_text(tree, ": %u", value); return 1; case WS_PSAMPLE_ATTR_GROUP_SEQ: - proto_tree_add_item_ret_uint(tree, hfi_psample_group_seq.id, tvb, offset, len, nl_data->encoding, &value); + proto_tree_add_item_ret_uint(tree, hf_psample_group_seq, tvb, offset, len, nl_data->encoding, &value); proto_item_append_text(tree, ": %u", value); return 1; case WS_PSAMPLE_ATTR_SAMPLE_RATE: - proto_tree_add_item_ret_uint(tree, hfi_psample_sample_rate.id, tvb, offset, len, nl_data->encoding, &value); + proto_tree_add_item_ret_uint(tree, hf_psample_sample_rate, tvb, offset, len, nl_data->encoding, &value); proto_item_append_text(tree, ": %u", value); return 1; case WS_PSAMPLE_ATTR_DATA: @@ -202,29 +156,29 @@ dissect_psample_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_ call_data_dissector(next_tvb, info->pinfo, tree); return 1; case WS_PSAMPLE_ATTR_GROUP_REFCOUNT: - proto_tree_add_item_ret_uint(tree, hfi_psample_group_refcount.id, tvb, offset, len, nl_data->encoding, &value); + proto_tree_add_item_ret_uint(tree, hf_psample_group_refcount, tvb, offset, len, nl_data->encoding, &value); proto_item_append_text(tree, ": %u", value); return 1; case WS_PSAMPLE_ATTR_TUNNEL: /* Currently there is no support for tunnel dissection. */ return 0; case WS_PSAMPLE_ATTR_OUT_TC: - proto_tree_add_item_ret_uint(tree, hfi_psample_out_tc.id, tvb, offset, len, nl_data->encoding, &value); + proto_tree_add_item_ret_uint(tree, hf_psample_out_tc, tvb, offset, len, nl_data->encoding, &value); proto_item_append_text(tree, ": %u", value); return 1; case WS_PSAMPLE_ATTR_OUT_TC_OCC: - proto_tree_add_item_ret_uint64(tree, hfi_psample_out_tc_occ.id, tvb, offset, len, nl_data->encoding, &value64); + proto_tree_add_item_ret_uint64(tree, hf_psample_out_tc_occ, tvb, offset, len, nl_data->encoding, &value64); proto_item_append_text(tree, ": %"G_GUINT64_FORMAT, value64); return 1; case WS_PSAMPLE_ATTR_LATENCY: - proto_tree_add_item_ret_uint64(tree, hfi_psample_latency.id, tvb, offset, len, nl_data->encoding, &value64); + proto_tree_add_item_ret_uint64(tree, hf_psample_latency, tvb, offset, len, nl_data->encoding, &value64); proto_item_append_text(tree, ": %"G_GUINT64_FORMAT, value64); return 1; case WS_PSAMPLE_ATTR_TIMESTAMP: timestamp = tvb_get_guint64(tvb, offset, nl_data->encoding); ts_nstime.secs = timestamp / 1000000000; ts_nstime.nsecs = timestamp % 1000000000; - proto_tree_add_time(tree, hfi_psample_timestamp.id, tvb, offset, 8, &ts_nstime); + proto_tree_add_time(tree, hf_psample_timestamp, tvb, offset, 8, &ts_nstime); return 1; case WS_PSAMPLE_ATTR_PROTO: info->protocol = tvb_get_guint16(tvb, offset, nl_data->encoding); @@ -234,7 +188,7 @@ dissect_psample_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_ */ if (info->protocol >= 1536 || info->protocol == LINUX_SLL_P_802_2) info->protocol = LINUX_SLL_P_ETHERNET; - proto_tree_add_item(tree, hfi_psample_proto.id, tvb, offset, len, nl_data->encoding); + proto_tree_add_item(tree, hf_psample_proto, tvb, offset, len, nl_data->encoding); return 1; default: return 0; @@ -256,7 +210,7 @@ dissect_netlink_psample(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi col_clear(pinfo->cinfo, COL_INFO); /* Generic netlink header */ - offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, hfi_psample_commands.id); + offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, hf_psample_commands); /* Not all commands have a payload */ if (!tvb_reported_length_remaining(tvb, offset)) @@ -269,7 +223,7 @@ dissect_netlink_psample(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi info.pinfo = pinfo; info.protocol = 0; - offset = dissect_netlink_attributes_to_end(tvb, hfi_psample_attrs.id, ett_psample_attrs, &info, genl_info->nl_data, nlmsg_tree, offset, dissect_psample_attrs); + offset = dissect_netlink_attributes_to_end(tvb, hf_psample_attrs, ett_psample_attrs, &info, genl_info->nl_data, nlmsg_tree, offset, dissect_psample_attrs); return offset; } @@ -277,22 +231,82 @@ dissect_netlink_psample(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi void proto_register_netlink_psample(void) { - static header_field_info *hfi[] = { - &hfi_psample_commands, - &hfi_psample_attrs, - &hfi_psample_iifindex, - &hfi_psample_oifindex, - &hfi_psample_origsize, - &hfi_psample_sample_group, - &hfi_psample_group_seq, - &hfi_psample_sample_rate, - &hfi_psample_tunnel, - &hfi_psample_group_refcount, - &hfi_psample_out_tc, - &hfi_psample_out_tc_occ, - &hfi_psample_latency, - &hfi_psample_timestamp, - &hfi_psample_proto, + static hf_register_info hf[] = { + { &hf_psample_commands, + { "Command", "netlink.psample.cmd", + FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ws_psample_commands_vals_ext, 0x00, + NULL, HFILL } + }, + { &hf_psample_attrs, + { "Attribute type", "netlink.psample.attr_type", + FT_UINT16, BASE_DEC | BASE_EXT_STRING, &ws_psample_attrs_vals_ext, NLA_TYPE_MASK, + NULL, HFILL } + }, + { &hf_psample_iifindex, + { "Input interface index", "netlink.psample.iifindex", + FT_UINT16, BASE_HEX, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_oifindex, + { "Output interface index", "netlink.psample.oifindex", + FT_UINT16, BASE_HEX, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_origsize, + { "Original size", "netlink.psample.origsize", + FT_UINT32, BASE_HEX, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_sample_group, + { "Sample group", "netlink.psample.sample_group", + FT_UINT32, BASE_DEC, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_group_seq, + { "Group sequence number", "netlink.psample.group_seq_num", + FT_UINT32, BASE_DEC, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_sample_rate, + { "Sample rate", "netlink.psample.sample_rate", + FT_UINT32, BASE_DEC, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_tunnel, + { "Tunnel", "netlink.psample.tunnel", + FT_UINT32, BASE_HEX, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_group_refcount, + { "Group reference count", "netlink.psample.group_refcount", + FT_UINT32, BASE_HEX, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_out_tc, + { "Output traffic class", "netlink.psample.out_tc", + FT_UINT16, BASE_DEC, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_out_tc_occ, + { "Output traffic class occupancy", "netlink.psample.out_tc_occ", + FT_UINT64, BASE_DEC, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_latency, + { "Latency", "netlink.psample.latency", + FT_UINT64, BASE_DEC, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_timestamp, + { "Timestamp", "netlink.psample.timestamp", + FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00, + NULL, HFILL } + }, + { &hf_psample_proto, + { "Protocol", "netlink.psample.proto", + FT_UINT16, BASE_HEX, NULL, 0x00, + NULL, HFILL } + }, }; static gint *ett[] = { @@ -301,9 +315,7 @@ proto_register_netlink_psample(void) }; proto_netlink_psample = proto_register_protocol("Linux psample protocol", "psample", "psample"); - hfi_netlink_psample = proto_registrar_get_nth(proto_netlink_psample); - - proto_register_fields_manual(proto_netlink_psample, hfi, array_length(hfi)); + proto_register_field_array(proto_netlink_psample, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); netlink_psample_handle = create_dissector_handle(dissect_netlink_psample, proto_netlink_psample);