From c0792555392f234ab96917e784d365b5de053836 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 11 Apr 2017 19:53:48 -0700 Subject: Add an API to let a postdissector specify fields whose values it needs. Currently, this is only used to determine whether a protocol tree needs to be built on the first pass or not - if there are postdissectors that need fields, it does - but eventually we should be able to use it to prime the dissection to deliver those fields in cases where we don't need the *entire* protocol tree (rather than using a hack such as cooking up a fake tap with a fake filter to do that). Update MATE and TRANSUM to use it. Clean up code to check whether we need a protocol tree, and add comments before that code indicating, in each case, what the criteria are. The array of postdissectors includes a length, so we don't need to separately keep track of the number of postdissectors. Clean up indentation while we're at it. Change-Id: I71d4025848206d144bc54cc82941089a50e80ab7 Reviewed-on: https://code.wireshark.org/review/21029 Reviewed-by: Guy Harris --- tfshark.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 15 deletions(-) (limited to 'tfshark.c') diff --git a/tfshark.c b/tfshark.c index 2dcd57385f..28c2c42ab5 100644 --- a/tfshark.c +++ b/tfshark.c @@ -1331,12 +1331,18 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) cf->frames = new_frame_data_sequence(); if (do_dissection) { - gboolean create_proto_tree = FALSE; + gboolean create_proto_tree; - /* If we're going to be applying a filter, we'll need to - create a protocol tree against which to apply the filter. */ - if (cf->rfcode) - create_proto_tree = TRUE; + /* + * Determine whether we need to create a protocol tree. + * We do if: + * + * we're going to apply a read filter; + * + * a postdissector wants field values on the first pass. + */ + create_proto_tree = + (cf->rfcode != NULL || postdissectors_want_fields()); /* We're not going to display the protocol tree on this pass, so it's not going to be "visible". */ @@ -1379,11 +1385,22 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) if (do_dissection) { gboolean create_proto_tree; - if (cf->dfcode || print_details || filtering_tap_listeners || - (tap_flags & TL_REQUIRES_PROTO_TREE) || have_custom_cols(&cf->cinfo)) - create_proto_tree = TRUE; - else - create_proto_tree = FALSE; + /* + * Determine whether we need to create a protocol tree. + * We do if: + * + * we're going to apply a display filter; + * + * we're going to print the protocol tree; + * + * one of the tap listeners requires a protocol tree; + * + * we have custom columns (which require field values, which + * currently requires that we build a protocol tree). + */ + create_proto_tree = + (cf->dfcode || print_details || filtering_tap_listeners || + (tap_flags & TL_REQUIRES_PROTO_TREE) || have_custom_cols(&cf->cinfo)); /* The protocol tree will be "visible", i.e., printed, only if we're printing packet details, which is true if we're printing stuff @@ -1418,11 +1435,29 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) if (do_dissection) { gboolean create_proto_tree; - if (cf->rfcode || cf->dfcode || print_details || filtering_tap_listeners || - (tap_flags & TL_REQUIRES_PROTO_TREE) || have_custom_cols(&cf->cinfo)) - create_proto_tree = TRUE; - else - create_proto_tree = FALSE; + /* + * Determine whether we need to create a protocol tree. + * We do if: + * + * we're going to apply a read filter; + * + * we're going to apply a display filter; + * + * we're going to print the protocol tree; + * + * one of the tap listeners is going to apply a filter; + * + * one of the tap listeners requires a protocol tree; + * + * a postdissector wants field values on the first pass; + * + * we have custom columns (which require field values, which + * currently requires that we build a protocol tree). + */ + create_proto_tree = + (cf->rfcode || cf->dfcode || print_details || filtering_tap_listeners || + (tap_flags & TL_REQUIRES_PROTO_TREE) || postdissectors_want_fields() || + have_custom_cols(&cf->cinfo)); /* The protocol tree will be "visible", i.e., printed, only if we're printing packet details, which is true if we're printing stuff -- cgit v1.2.3