aboutsummaryrefslogtreecommitdiffstats
path: root/epan/packet.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-04-11 19:53:48 -0700
committerGuy Harris <guy@alum.mit.edu>2017-04-12 04:31:19 +0000
commitc0792555392f234ab96917e784d365b5de053836 (patch)
tree02c053696f2fbd0a6b05ae239b5460d1c551a64f /epan/packet.c
parentaa9a0b3bf831395dc1cfbaea7f467faed952dbf9 (diff)
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 <guy@alum.mit.edu>
Diffstat (limited to 'epan/packet.c')
-rw-r--r--epan/packet.c84
1 files changed, 68 insertions, 16 deletions
diff --git a/epan/packet.c b/epan/packet.c
index de0a84854a..4a3b5cbd64 100644
--- a/epan/packet.c
+++ b/epan/packet.c
@@ -127,8 +127,24 @@ static GHashTable *depend_dissector_lists = NULL;
* the final cleanup. */
static GSList *postseq_cleanup_routines;
-static GPtrArray* post_dissectors = NULL;
-static guint num_of_postdissectors = 0;
+/*
+ * Post-dissector information - handle for the dissector and a list
+ * of hfids for the fields the post-dissector wants.
+ */
+typedef struct {
+ dissector_handle_t handle;
+ GArray *wanted_fields;
+} postdissector;
+
+/*
+ * Array of all postdissectors.
+ */
+static GArray *postdissectors = NULL;
+
+/*
+ * i-th element of that array.
+ */
+#define POSTDISSECTORS(i) g_array_index(postdissectors, postdissector, i)
static void
destroy_depend_dissector_list(void *data)
@@ -248,8 +264,8 @@ packet_cleanup(void)
g_hash_table_destroy(heuristic_short_names);
g_slist_foreach(shutdown_routines, &call_routine, NULL);
g_slist_free(shutdown_routines);
- if (post_dissectors)
- g_ptr_array_free(post_dissectors, TRUE);
+ if (postdissectors)
+ g_array_free(postdissectors, TRUE);
}
/*
@@ -3252,20 +3268,43 @@ dissector_dump_dissector_tables(void)
void
register_postdissector(dissector_handle_t handle)
{
- if (!post_dissectors)
- post_dissectors = g_ptr_array_new();
+ postdissector p;
- g_ptr_array_add(post_dissectors, handle);
- num_of_postdissectors++;
+ if (!postdissectors)
+ postdissectors = g_array_sized_new(FALSE, FALSE, (guint)sizeof(postdissector), 1);
+
+ p.handle = handle;
+ p.wanted_fields = NULL;
+ postdissectors = g_array_append_val(postdissectors, p);
+}
+
+void
+set_postdissector_wanted_fields(dissector_handle_t handle, GArray *wanted_fields)
+{
+ guint i;
+
+ if (!postdissectors) return;
+
+ for (i = 0; i < postdissectors->len; i++) {
+ if (POSTDISSECTORS(i).handle == handle) {
+ POSTDISSECTORS(i).wanted_fields = wanted_fields;
+ break;
+ }
+ }
}
void
deregister_postdissector(dissector_handle_t handle)
{
- if (!post_dissectors) return;
+ guint i;
+
+ if (!postdissectors) return;
- if (g_ptr_array_remove(post_dissectors, handle)) {
- num_of_postdissectors--;
+ for (i = 0; i < postdissectors->len; i++) {
+ if (POSTDISSECTORS(i).handle == handle) {
+ postdissectors = g_array_remove_index_fast(postdissectors, i);
+ break;
+ }
}
}
@@ -3275,8 +3314,8 @@ have_postdissector(void)
guint i;
dissector_handle_t handle;
- for(i = 0; i < num_of_postdissectors; i++) {
- handle = (dissector_handle_t) g_ptr_array_index(post_dissectors,i);
+ for (i = 0; i < postdissectors->len; i++) {
+ handle = POSTDISSECTORS(i).handle;
if (handle->protocol != NULL
&& proto_is_protocol_enabled(handle->protocol)) {
@@ -3292,12 +3331,25 @@ call_all_postdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
guint i;
- for(i = 0; i < num_of_postdissectors; i++) {
- call_dissector_only((dissector_handle_t) g_ptr_array_index(post_dissectors,i),
- tvb,pinfo,tree, NULL);
+ for (i = 0; i < postdissectors->len; i++) {
+ call_dissector_only(POSTDISSECTORS(i).handle,
+ tvb, pinfo, tree, NULL);
}
}
+gboolean
+postdissectors_want_fields(void)
+{
+ guint i;
+
+ for (i = 0; i < postdissectors->len; i++) {
+ if (POSTDISSECTORS(i).wanted_fields != NULL &&
+ POSTDISSECTORS(i).wanted_fields->len != 0)
+ return TRUE;
+ }
+ return FALSE;
+}
+
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*