Ethereal-dev: [Ethereal-dev] Re: Improving filter speed

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: didier <dgautheron@xxxxxxxx>
Date: Mon, 04 Apr 2005 19:25:24 +0000
ronnie sahlberg wrote:
New patch,  faking of fields can be controlled by a #define .

I have checked in a patch for ncp to make it still work even when this
patch is applied.
Ok.
Statistic --> Protocol --> Hierarchy is broken (it was one of the reasons for the protocol add_item done on the caller tree).

And two unrelated patches.
no_col.diff: setting col info is slow.

proto_by_id.diff
again find_proto_by_id is slow.
I make register_field_array return a protocol_t * rather than void.
I've only changed the 'obvious' dissectors.

Didier
Index: gtk/sctp_assoc_analyse.c
===================================================================
--- gtk/sctp_assoc_analyse.c	(revision 14013)
+++ gtk/sctp_assoc_analyse.c	(working copy)
@@ -742,7 +742,7 @@
 
 	edt = epan_dissect_new(TRUE, FALSE);
 	epan_dissect_prime_dfilter(edt, sfcode);
-	epan_dissect_run(edt, &cf->pseudo_header, cf->pd, fdata, &cf->cinfo);
+	epan_dissect_run(edt, &cf->pseudo_header, cf->pd, fdata, NULL);
 	frame_matched = dfilter_apply_edt(sfcode, edt);
 
 	/* if it is not an sctp frame, show the dialog */
Index: gtk/rtp_analysis.c
===================================================================
--- gtk/rtp_analysis.c	(revision 14013)
+++ gtk/rtp_analysis.c	(working copy)
@@ -3549,7 +3549,7 @@
 	}
 	edt = epan_dissect_new(TRUE, FALSE);
 	epan_dissect_prime_dfilter(edt, sfcode);
-	epan_dissect_run(edt, &cf->pseudo_header, cf->pd, fdata, &cf->cinfo);
+	epan_dissect_run(edt, &cf->pseudo_header, cf->pd, fdata, NULL);
 	frame_matched = dfilter_apply_edt(sfcode, edt);
 	
 	/* if it is not an rtp frame, show the rtpstream dialog */
Index: proto_hier_stats.c
===================================================================
--- proto_hier_stats.c	(revision 14013)
+++ proto_hier_stats.c	(working copy)
@@ -145,7 +145,7 @@
 		return FALSE;	/* failure */
 	}
 
-	/* Dissect the frame */
+	/* Dissect the frame   tree  not visible */
 	edt = epan_dissect_new(TRUE, FALSE);
 	epan_dissect_run(edt, &phdr, pd, frame, cinfo);
 
@@ -253,8 +253,9 @@
 				ps->first_time = cur_time;
 				ps->last_time = cur_time;
 			}
-
-			if (!process_frame(frame, &cfile.cinfo, ps)) {
+			
+			/* we don't care about colinfo */
+			if (!process_frame(frame, NULL, ps)) {
 				/*
 				 * Give up, and set "stop_flag" so we
 				 * just abort rather than popping up
Index: epan/proto.c
===================================================================
--- epan/proto.c	(revision 14013)
+++ epan/proto.c	(working copy)
@@ -2592,6 +2715,14 @@
 	return protocol->filter_name;
 }
 
+char *
+proto_get_protocol_filter_name_by_handle(protocol_t *protocol)
+{
+	if (protocol == NULL)
+        	return "";
+	return protocol->filter_name;
+}
+
 gboolean
 proto_is_protocol_enabled(protocol_t *protocol)
 {
@@ -2628,7 +2759,7 @@
 
 /* for use with static arrays only, since we don't allocate our own copies
 of the header_field_info struct contained within the hf_register_info struct */
-void
+protocol_t *
 proto_register_field_array(int parent, hf_register_info *hf, int num_records)
 {
 	int			field_id, i;
@@ -2659,6 +2790,7 @@
 		field_id = proto_register_field_init(&ptr->hfinfo, parent);
 		*ptr->p_id = field_id;
 	}
+	return proto;
 }
 
 static int
Index: epan/proto.h
===================================================================
--- epan/proto.h	(revision 14013)
+++ epan/proto.h	(working copy)
@@ -907,8 +928,10 @@
 /** Register a header_field array.
  @param parent the protocol handle from proto_register_protocol()
  @param hf the hf_register_info array
- @param num_records the number of records in hf */
-extern void
+ @param num_records the number of records in hf 
+ @return the "protocol_t" structure for the given protocol's item number.   
+ */
+extern protocol_t *
 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
 
 /** Register a protocol subtree (ett) array.
@@ -1007,6 +1030,10 @@
  @return its filter name. */
 extern char *proto_get_protocol_filter_name(int proto_id);
 
+/** Get the protocol's filter name, , for the given protocol's "protocol_t".
+ @return its filter name. */
+extern char *proto_get_protocol_filter_name_by_handle(protocol_t *protocol);
+
 /** Enable / Disable protocol of the given item number.
  @param proto_id protocol id (0-indexed)
  @param enabled enable / disable the protocol */
Index: epan/packet.c
===================================================================
--- epan/packet.c	(revision 14013)
+++ epan/packet.c	(working copy)
@@ -462,7 +462,7 @@
 			if (pinfo->layer_names->len > 0)
 				g_string_append(pinfo->layer_names, ":");
 			g_string_append(pinfo->layer_names, 
-			    proto_get_protocol_filter_name(proto_get_id(handle->protocol)));
+			    proto_get_protocol_filter_name_by_handle(handle->protocol));     
 		}
 	}
 
@@ -1518,7 +1518,7 @@
 			if (pinfo->layer_names->len > 0)
 				g_string_append(pinfo->layer_names, ":");
 			g_string_append(pinfo->layer_names,
-			    proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol)));
+			    proto_get_protocol_filter_name_by_handle(dtbl_entry->protocol));
 		}
 
 		if ((*dtbl_entry->dissector)(tvb, pinfo, tree)) {
Index: epan/dissectors/packet-msnip.c
===================================================================
--- epan/dissectors/packet-msnip.c	(revision 14013)
+++ epan/dissectors/packet-msnip.c	(working copy)
@@ -49,6 +49,7 @@
 
 
 static int proto_msnip = -1;
+static protocol_t *proto_msnip_ptr;
 static int hf_checksum = -1;
 static int hf_checksum_bad = -1;
 static int hf_type = -1;
@@ -222,7 +223,7 @@
 	proto_item *item;
 	guint8 type;
 
-	if (!proto_is_protocol_enabled(find_protocol_by_id(proto_msnip))) {
+	if (!proto_is_protocol_enabled(proto_msnip_ptr)) {
 		/* we are not enabled, skip entire packet to be nice
 		   to the igmp layer. (so clicking on IGMP will display the data)
 		 */
@@ -328,7 +329,7 @@
 
 	proto_msnip = proto_register_protocol("MSNIP: Multicast Source Notification of Interest Protocol",
 	    "MSNIP", "msnip");
-	proto_register_field_array(proto_msnip, hf, array_length(hf));
+	proto_msnip_ptr = proto_register_field_array(proto_msnip, hf, array_length(hf));
 	proto_register_subtree_array(ett, array_length(ett));
 }
 
Index: epan/dissectors/packet-clnp.c
===================================================================
--- epan/dissectors/packet-clnp.c	(revision 14013)
+++ epan/dissectors/packet-clnp.c	(working copy)
@@ -71,6 +71,7 @@
 static int hf_clnp_reassembled_in = -1;
 
 static int  proto_cotp         = -1;
+static protocol_t *proto_cotp_ptr;
 static gint ett_cotp           = -1;
 static gint ett_cotp_segments  = -1;
 static gint ett_cotp_segment   = -1;
@@ -1697,7 +1698,7 @@
   gboolean is_cltp = FALSE;
   gboolean subdissector_found = FALSE;
 
-  if (!proto_is_protocol_enabled(find_protocol_by_id(proto_cotp)))
+  if (!proto_is_protocol_enabled(proto_cotp_ptr))
     return FALSE;	/* COTP has been disabled */
   /* XXX - what about CLTP? */
 
@@ -2373,7 +2374,7 @@
   module_t *cotp_module;
 
   proto_cotp = proto_register_protocol(PROTO_STRING_COTP, "COTP", "cotp");
-  proto_register_field_array(proto_cotp, hf, array_length(hf));
+  proto_cotp_ptr = proto_register_field_array(proto_cotp, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
   cotp_module = prefs_register_protocol(proto_cotp, NULL);
 
Index: epan/dissectors/packet-igap.c
===================================================================
--- epan/dissectors/packet-igap.c	(revision 14013)
+++ epan/dissectors/packet-igap.c	(working copy)
@@ -54,6 +54,7 @@
 
 
 static int proto_igap      = -1;
+static protocol_t *proto_igap_ptr;
 static int hf_type         = -1;
 static int hf_max_resp     = -1;
 static int hf_checksum     = -1;
@@ -136,7 +137,7 @@
     guint8 type, tsecs, subtype, asize, msize;
     guchar account[ACCOUNT_SIZE+1], message[MESSAGE_SIZE+1];
 
-    if (!proto_is_protocol_enabled(find_protocol_by_id(proto_igap))) {
+    if (!proto_is_protocol_enabled(proto_igap_ptr)) {
 	/* we are not enabled, skip entire packet to be nice
 	   to the igmp layer. (so clicking on IGMP will display the data)
 	   */
@@ -325,6 +326,6 @@
     proto_igap = proto_register_protocol
 	("Internet Group membership Authentication Protocol",
 	 "IGAP", "igap");
-    proto_register_field_array(proto_igap, hf, array_length(hf));
+    proto_igap_ptr = proto_register_field_array(proto_igap, hf, array_length(hf));
     proto_register_subtree_array(ett, array_length(ett));
 }
Index: epan/dissectors/packet-pim.c
===================================================================
--- epan/dissectors/packet-pim.c	(revision 14013)
+++ epan/dissectors/packet-pim.c	(working copy)
@@ -49,6 +49,7 @@
 };
 
 static int proto_pim = -1;
+static protocol_t *proto_pim_ptr;
 static int hf_pim_version = -1;
 static int hf_pim_type = -1;
 static int hf_pim_code = -1;
@@ -113,7 +114,7 @@
     proto_tree *pimopt_tree = NULL;
     proto_item *tiopt;
 
-    if (!proto_is_protocol_enabled(find_protocol_by_id(proto_pim))) {
+    if (!proto_is_protocol_enabled(proto_pim_ptr)) {
 	/*
 	 * We are not enabled; skip entire packet to be nice to the
 	 * IGMP layer (so clicking on IGMP will display the data).
@@ -1190,7 +1191,7 @@
 
     proto_pim = proto_register_protocol("Protocol Independent Multicast",
 	"PIM", "pim");
-    proto_register_field_array(proto_pim, hf, array_length(hf));
+    proto_pim_ptr = proto_register_field_array(proto_pim, hf, array_length(hf));
     proto_register_subtree_array(ett, array_length(ett));
 }
 
Index: epan/dissectors/packet-tpkt.c
===================================================================
--- epan/dissectors/packet-tpkt.c	(revision 14013)
+++ epan/dissectors/packet-tpkt.c	(working copy)
@@ -373,8 +373,7 @@
 	module_t *tpkt_module;
 
 	proto_tpkt = proto_register_protocol("TPKT", "TPKT", "tpkt");
-	proto_tpkt_ptr = find_protocol_by_id(proto_tpkt);
-	proto_register_field_array(proto_tpkt, hf, array_length(hf));
+	proto_tpkt_ptr = proto_register_field_array(proto_tpkt, hf, array_length(hf));
 	proto_register_subtree_array(ett, array_length(ett));
 
 	tpkt_module = prefs_register_protocol(proto_tpkt, NULL);
Index: epan/dissectors/packet-mrdisc.c
===================================================================
--- epan/dissectors/packet-mrdisc.c	(revision 14013)
+++ epan/dissectors/packet-mrdisc.c	(working copy)
@@ -50,6 +50,7 @@
 
 
 static int proto_mrdisc = -1;
+static protocol_t *proto_mrdisc_ptr;
 static int hf_checksum = -1;
 static int hf_checksum_bad = -1;
 static int hf_type = -1;
@@ -188,7 +189,7 @@
 	proto_item *item;
 	guint8 type;
 
-	if (!proto_is_protocol_enabled(find_protocol_by_id(proto_mrdisc))) {
+	if (!proto_is_protocol_enabled(proto_mrdisc_ptr)) {
 		/* we are not enabled, skip entire packet to be nice
 		   to the igmp layer. (so clicking on IGMP will display the data)
 		 */
@@ -288,6 +289,6 @@
 
 	proto_mrdisc = proto_register_protocol("Multicast Router DISCovery protocol",
 	    "MRDISC", "mrdisc");
-	proto_register_field_array(proto_mrdisc, hf, array_length(hf));
+	proto_mrdisc_ptr = proto_register_field_array(proto_mrdisc, hf, array_length(hf));
 	proto_register_subtree_array(ett, array_length(ett));
 }
Index: epan/dissectors/packet-atalk.c
===================================================================
--- epan/dissectors/packet-atalk.c	(revision 14013)
+++ epan/dissectors/packet-atalk.c	(working copy)
@@ -60,6 +60,8 @@
 static int hf_llap_type = -1;
 
 static int proto_ddp = -1;
+static protocol_t *proto_ddp_ptr;
+
 static int hf_ddp_hopcount = -1;
 static int hf_ddp_len = -1;
 static int hf_ddp_checksum = -1;
@@ -1701,7 +1703,7 @@
   switch (type) {
 
   case 0x01:
-    if (proto_is_protocol_enabled(find_protocol_by_id(proto_ddp))) {
+    if (proto_is_protocol_enabled(proto_ddp_ptr)) {
       pinfo->current_proto = "DDP";
       dissect_ddp_short(new_tvb, pinfo, dnode, snode, tree);
       return;
@@ -2228,7 +2230,7 @@
   proto_register_field_array(proto_llap, hf_llap, array_length(hf_llap));
 
   proto_ddp = proto_register_protocol("Datagram Delivery Protocol", "DDP", "ddp");
-  proto_register_field_array(proto_ddp, hf_ddp, array_length(hf_ddp));
+  proto_ddp_ptr = proto_register_field_array(proto_ddp, hf_ddp, array_length(hf_ddp));
 
   proto_nbp = proto_register_protocol("Name Binding Protocol", "NBP", "nbp");
   proto_register_field_array(proto_nbp, hf_nbp, array_length(hf_nbp));
Index: epan/dissectors/packet-smb-mailslot.c
===================================================================
--- epan/dissectors/packet-smb-mailslot.c	(revision 14013)
+++ epan/dissectors/packet-smb-mailslot.c	(working copy)
@@ -40,6 +40,7 @@
 #include "packet-smb-pipe.h"
 
 static int proto_smb_msp = -1;
+static protocol_t *proto_smb_msp_ptr;
 static int hf_opcode = -1;
 static int hf_priority = -1;
 static int hf_class = -1;
@@ -94,7 +95,7 @@
 	int             offset = 0;
 	int             len;
 
-	if (!proto_is_protocol_enabled(find_protocol_by_id(proto_smb_msp))) {
+	if (!proto_is_protocol_enabled(proto_smb_msp_ptr)) {
 		return FALSE;
 	}
 	pinfo->current_proto = "SMB Mailslot";
@@ -255,7 +256,7 @@
 	proto_smb_msp = proto_register_protocol(
 		"SMB MailSlot Protocol", "SMB Mailslot", "mailslot");
 
-	proto_register_field_array(proto_smb_msp, hf, array_length(hf));
+	proto_smb_msp_ptr = proto_register_field_array(proto_smb_msp, hf, array_length(hf));
 	proto_register_subtree_array(ett, array_length(ett));
 }
 
Index: epan/dissectors/packet-dvmrp.c
===================================================================
--- epan/dissectors/packet-dvmrp.c	(revision 14013)
+++ epan/dissectors/packet-dvmrp.c	(working copy)
@@ -65,6 +65,7 @@
 #include "packet-dvmrp.h"
 
 static int proto_dvmrp = -1;
+static protocol_t *proto_dvmrp_ptr;
 static int hf_version = -1;
 static int hf_type = -1;
 static int hf_code_v1 = -1;
@@ -621,7 +622,7 @@
 	proto_tree *tree;
 	proto_item *item;
 
-	if (!proto_is_protocol_enabled(find_protocol_by_id(proto_dvmrp))) {
+	if (!proto_is_protocol_enabled(proto_dvmrp_ptr)) {
 		/* we are not enabled, skip entire packet to be nice
 		   to the igmp layer. (so clicking on IGMP will display the data)
 		 */
@@ -796,6 +797,6 @@
 
 	proto_dvmrp = proto_register_protocol("Distance Vector Multicast Routing Protocol",
 	    "DVMRP", "dvmrp");
-	proto_register_field_array(proto_dvmrp, hf, array_length(hf));
+	proto_dvmrp_ptr = proto_register_field_array(proto_dvmrp, hf, array_length(hf));
 	proto_register_subtree_array(ett, array_length(ett));
 }
Index: epan/dissectors/packet-smb-pipe.c
===================================================================
--- epan/dissectors/packet-smb-pipe.c	(revision 14013)
+++ epan/dissectors/packet-smb-pipe.c	(working copy)
@@ -51,6 +51,7 @@
 #include <epan/reassemble.h>
 
 static int proto_smb_pipe = -1;
+static protocol_t *proto_smb_pipe_ptr;
 static int hf_pipe_function = -1;
 static int hf_pipe_priority = -1;
 static int hf_pipe_peek_available = -1;
@@ -92,6 +93,7 @@
 };
 
 static int proto_smb_lanman = -1;
+static protocol_t *proto_smb_lanman_ptr;
 static int hf_function_code = -1;
 static int hf_param_desc = -1;
 static int hf_return_desc = -1;
@@ -2624,7 +2626,7 @@
 	proto_item *data_item;
 	proto_tree *data_tree;
 
-	if (!proto_is_protocol_enabled(find_protocol_by_id(proto_smb_lanman)))
+	if (!proto_is_protocol_enabled(proto_smb_lanman_ptr))
 		return FALSE;
 	if (smb_info->request && p_tvb == NULL) {
 		/*
@@ -3220,7 +3222,7 @@
 
 	proto_smb_lanman = proto_register_protocol(
 		"Microsoft Windows Lanman Remote API Protocol", "LANMAN", "lanman");
-	proto_register_field_array(proto_smb_lanman, hf, array_length(hf));
+	proto_smb_lanman_ptr = proto_register_field_array(proto_smb_lanman, hf, array_length(hf));
 	proto_register_subtree_array(ett, array_length(ett));
 }
 
@@ -3519,7 +3521,7 @@
 	int fid = -1;
 	guint16 info_level;
 
-	if (!proto_is_protocol_enabled(find_protocol_by_id(proto_smb_pipe)))
+	if (!proto_is_protocol_enabled(proto_smb_pipe_ptr))
 		return FALSE;
 	pinfo->current_proto = "SMB Pipe";
 
@@ -3916,8 +3918,7 @@
 
 	proto_smb_pipe = proto_register_protocol(
 		"SMB Pipe Protocol", "SMB Pipe", "pipe");
-
-	proto_register_field_array(proto_smb_pipe, hf, array_length(hf));
+	proto_smb_pipe_ptr = proto_register_field_array(proto_smb_pipe, hf, array_length(hf));
 	proto_register_subtree_array(ett, array_length(ett));
 }