From 6472876ab34d2aa016e0b2afa0348d45ce551c86 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 29 Sep 2004 00:06:36 +0000 Subject: Move the tap infrastructure to the epan directory. svn path=/trunk/; revision=12128 --- Makefile.common | 1 - epan/Makefile.common | 3 +- epan/dissectors/packet-ansi_a.c | 2 +- epan/dissectors/packet-ansi_map.c | 2 +- epan/dissectors/packet-bootp.c | 2 +- epan/dissectors/packet-dcerpc.c | 2 +- epan/dissectors/packet-eth.c | 2 +- epan/dissectors/packet-fc.c | 2 +- epan/dissectors/packet-fddi.c | 2 +- epan/dissectors/packet-frame.c | 2 +- epan/dissectors/packet-gsm_a.c | 2 +- epan/dissectors/packet-gsm_map.c | 2 +- epan/dissectors/packet-gsm_ss.c | 2 +- epan/dissectors/packet-h225.c | 2 +- epan/dissectors/packet-http.c | 2 +- epan/dissectors/packet-ip.c | 2 +- epan/dissectors/packet-ipx.c | 2 +- epan/dissectors/packet-ldap.c | 2 +- epan/dissectors/packet-mtp3.c | 2 +- epan/dissectors/packet-rpc.c | 2 +- epan/dissectors/packet-rtp.c | 2 +- epan/dissectors/packet-sctp.c | 2 +- epan/dissectors/packet-sip.c | 2 +- epan/dissectors/packet-smb-sidsnooping.c | 2 +- epan/dissectors/packet-smb.c | 2 +- epan/dissectors/packet-tcp.c | 2 +- epan/dissectors/packet-teredo.c | 2 +- epan/dissectors/packet-tr.c | 2 +- epan/dissectors/packet-udp.c | 2 +- epan/dissectors/packet-wsp.c | 2 +- epan/epan.c | 2 +- epan/plugins.c | 2 +- epan/tap.c | 432 +++++++++++++++++++++++++++++++ epan/tap.h | 54 ++++ file.c | 2 +- gtk/ansi_a_stat.c | 2 +- gtk/ansi_map_stat.c | 2 +- gtk/bootp_stat.c | 2 +- gtk/conversations_eth.c | 2 +- gtk/conversations_fc.c | 2 +- gtk/conversations_fddi.c | 2 +- gtk/conversations_ip.c | 2 +- gtk/conversations_ipx.c | 2 +- gtk/conversations_table.c | 2 +- gtk/conversations_tcpip.c | 2 +- gtk/conversations_tr.c | 2 +- gtk/conversations_udpip.c | 2 +- gtk/dcerpc_stat.c | 2 +- gtk/fc_stat.c | 2 +- gtk/gsm_a_stat.c | 2 +- gtk/gsm_map_stat.c | 2 +- gtk/gsm_map_summary.c | 2 +- gtk/h225_counter.c | 2 +- gtk/h225_ras_srt.c | 2 +- gtk/hostlist_eth.c | 2 +- gtk/hostlist_fc.c | 2 +- gtk/hostlist_fddi.c | 2 +- gtk/hostlist_ip.c | 2 +- gtk/hostlist_ipx.c | 2 +- gtk/hostlist_table.c | 2 +- gtk/hostlist_tcpip.c | 2 +- gtk/hostlist_tr.c | 2 +- gtk/hostlist_udpip.c | 2 +- gtk/http_stat.c | 2 +- gtk/io_stat.c | 2 +- gtk/isup_stat.c | 2 +- gtk/ldap_stat.c | 2 +- gtk/main.c | 2 +- gtk/menu.c | 5 +- gtk/mgcp_stat.c | 2 +- gtk/mtp3_stat.c | 2 +- gtk/mtp3_summary.c | 2 +- gtk/rpc_progs.c | 2 +- gtk/rpc_stat.c | 2 +- gtk/rtp_analysis.c | 2 +- gtk/rtp_stream.c | 2 +- gtk/sctp_stat.c | 2 +- gtk/sip_stat.c | 2 +- gtk/smb_stat.c | 2 +- gtk/wsp_stat.c | 2 +- plugins/mgcp/packet-mgcp.c | 2 +- plugins/plugin_api.h | 2 +- plugins/plugin_api_list.c | 2 +- tap-ansi_astat.c | 2 +- tap-bootpstat.c | 2 +- tap-dcerpcstat.c | 2 +- tap-gsm_astat.c | 2 +- tap-h225counter.c | 2 +- tap-h225rassrt.c | 2 +- tap-httpstat.c | 2 +- tap-iostat.c | 2 +- tap-iousers.c | 2 +- tap-mgcpstat.c | 2 +- tap-protocolinfo.c | 2 +- tap-protohierstat.c | 2 +- tap-rpcprogs.c | 2 +- tap-rpcstat.c | 2 +- tap-sipstat.c | 2 +- tap-smbsids.c | 2 +- tap-smbstat.c | 2 +- tap-wspstat.c | 2 +- tap.c | 432 ------------------------------- tap.h | 54 ---- tethereal.c | 2 +- 104 files changed, 588 insertions(+), 587 deletions(-) create mode 100644 epan/tap.c create mode 100644 epan/tap.h delete mode 100644 tap.c delete mode 100644 tap.h diff --git a/Makefile.common b/Makefile.common index 0c43779fbf..cd18cf1d34 100644 --- a/Makefile.common +++ b/Makefile.common @@ -56,7 +56,6 @@ DISSECTOR_SUPPORT_INCLUDES = \ sctpppids.h \ smb.h \ t35.h \ - tap.h \ x264_prt_id.h \ xmlstub.h diff --git a/epan/Makefile.common b/epan/Makefile.common index 994de14fdf..fcc409c07b 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -55,6 +55,7 @@ LIBETHEREAL_SRC = \ sha1.c \ sna-utils.c \ strutil.c \ + tap.c \ timestamp.c \ to_str.c \ tvbuff.c \ @@ -104,6 +105,7 @@ LIBETHEREAL_INCLUDES = \ slab.h \ sna-utils.h \ strutil.h \ + tap.h \ timestamp.h \ to_str.h \ tvbuff.h \ @@ -122,6 +124,5 @@ DISSECTOR_SUPPORT_SRC = \ ../reassemble.c \ ../req_resp_hdrs.c \ ../t35.c \ - ../tap.c \ ../xmlstub.c diff --git a/epan/dissectors/packet-ansi_a.c b/epan/dissectors/packet-ansi_a.c index 1d16dc539e..93d65c33c3 100644 --- a/epan/dissectors/packet-ansi_a.c +++ b/epan/dissectors/packet-ansi_a.c @@ -41,7 +41,7 @@ #include "epan/packet.h" #include -#include "tap.h" +#include #include "packet-bssap.h" #include "packet-ansi_a.h" diff --git a/epan/dissectors/packet-ansi_map.c b/epan/dissectors/packet-ansi_map.c index 3cc58ede94..ad5928a32e 100644 --- a/epan/dissectors/packet-ansi_map.c +++ b/epan/dissectors/packet-ansi_map.c @@ -111,7 +111,7 @@ #include "epan/packet.h" #include "asn1.h" -#include "tap.h" +#include #include "packet-ansi_a.h" #include "packet-ansi_map.h" diff --git a/epan/dissectors/packet-bootp.c b/epan/dissectors/packet-bootp.c index 5b9e3e6093..1fbcd3c738 100644 --- a/epan/dissectors/packet-bootp.c +++ b/epan/dissectors/packet-bootp.c @@ -51,7 +51,7 @@ #include "packet-dns.h" /* for get_dns_name() */ #include -#include "tap.h" +#include static int bootp_dhcp_tap = -1; static int proto_bootp = -1; diff --git a/epan/dissectors/packet-dcerpc.c b/epan/dissectors/packet-dcerpc.c index 8faf2cc931..dd6f0a3cf4 100644 --- a/epan/dissectors/packet-dcerpc.c +++ b/epan/dissectors/packet-dcerpc.c @@ -37,7 +37,7 @@ #include #include #include "reassemble.h" -#include "tap.h" +#include #include #include diff --git a/epan/dissectors/packet-eth.c b/epan/dissectors/packet-eth.c index 8147c7ea12..5d0f617ae5 100644 --- a/epan/dissectors/packet-eth.c +++ b/epan/dissectors/packet-eth.c @@ -37,7 +37,7 @@ #include "packet-isl.h" #include "packet-llc.h" #include -#include "tap.h" +#include /* Interpret capture file as FW1 monitor file */ static gboolean eth_interpret_as_fw1_monitor = FALSE; diff --git a/epan/dissectors/packet-fc.c b/epan/dissectors/packet-fc.c index 8285b6072e..fe25f3cc29 100644 --- a/epan/dissectors/packet-fc.c +++ b/epan/dissectors/packet-fc.c @@ -56,7 +56,7 @@ #include "packet-fc.h" #include "packet-fclctl.h" #include "packet-fcbls.h" -#include "tap.h" +#include #define FC_HEADER_SIZE 24 #define FC_RCTL_EISL 0x50 diff --git a/epan/dissectors/packet-fddi.c b/epan/dissectors/packet-fddi.c index b9ca93c508..9eb1de0664 100644 --- a/epan/dissectors/packet-fddi.c +++ b/epan/dissectors/packet-fddi.c @@ -36,7 +36,7 @@ #include #include "packet-fddi.h" #include "packet-llc.h" -#include "tap.h" +#include #include diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index 45221d7b5a..0a1e40e71f 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -33,7 +33,7 @@ #include #include "packet-frame.h" #include -#include "tap.h" +#include int proto_frame = -1; int hf_frame_arrival_time = -1; diff --git a/epan/dissectors/packet-gsm_a.c b/epan/dissectors/packet-gsm_a.c index 7ee33fd642..e6d2d07075 100644 --- a/epan/dissectors/packet-gsm_a.c +++ b/epan/dissectors/packet-gsm_a.c @@ -70,7 +70,7 @@ #include "epan/packet.h" #include -#include "tap.h" +#include #include "asn1.h" #include "packet-tcap.h" diff --git a/epan/dissectors/packet-gsm_map.c b/epan/dissectors/packet-gsm_map.c index aa357c7227..182a8ac4f8 100644 --- a/epan/dissectors/packet-gsm_map.c +++ b/epan/dissectors/packet-gsm_map.c @@ -43,7 +43,7 @@ #include #include "epan/packet.h" -#include "tap.h" +#include #include "asn1.h" #include "packet-tcap.h" diff --git a/epan/dissectors/packet-gsm_ss.c b/epan/dissectors/packet-gsm_ss.c index 01963aa756..2be9f7aef5 100644 --- a/epan/dissectors/packet-gsm_ss.c +++ b/epan/dissectors/packet-gsm_ss.c @@ -55,7 +55,7 @@ #include #include "epan/packet.h" -#include "tap.h" +#include #include "asn1.h" #include "packet-tcap.h" diff --git a/epan/dissectors/packet-h225.c b/epan/dissectors/packet-h225.c index 590a93a3c7..6f018d7523 100644 --- a/epan/dissectors/packet-h225.c +++ b/epan/dissectors/packet-h225.c @@ -37,7 +37,7 @@ #include #include -#include "tap.h" +#include #include "packet-tpkt.h" #include "packet-per.h" #include "packet-h225.h" diff --git a/epan/dissectors/packet-http.c b/epan/dissectors/packet-http.c index 7d502d2c9b..3233ae07cc 100644 --- a/epan/dissectors/packet-http.c +++ b/epan/dissectors/packet-http.c @@ -53,7 +53,7 @@ typedef enum _http_type { HTTP_OTHERS } http_type_t; -#include "tap.h" +#include static int http_tap = -1; diff --git a/epan/dissectors/packet-ip.c b/epan/dissectors/packet-ip.c index 9cb368abed..7bb95d8da1 100644 --- a/epan/dissectors/packet-ip.c +++ b/epan/dissectors/packet-ip.c @@ -50,7 +50,7 @@ #include "packet-ipsec.h" #include #include "nlpid.h" -#include "tap.h" +#include static int ip_tap = -1; diff --git a/epan/dissectors/packet-ipx.c b/epan/dissectors/packet-ipx.c index 4332eac66c..db3fabeec5 100644 --- a/epan/dissectors/packet-ipx.c +++ b/epan/dissectors/packet-ipx.c @@ -43,7 +43,7 @@ #include "aftypes.h" #include "arcnet_pids.h" #include -#include "tap.h" +#include static int ipx_tap = -1; diff --git a/epan/dissectors/packet-ldap.c b/epan/dissectors/packet-ldap.c index 476e21d7d6..ceac5ca335 100644 --- a/epan/dissectors/packet-ldap.c +++ b/epan/dissectors/packet-ldap.c @@ -76,7 +76,7 @@ #include #include #include "packet-frame.h" -#include "tap.h" +#include #include "packet-ber.h" #include "packet-ldap.h" diff --git a/epan/dissectors/packet-mtp3.c b/epan/dissectors/packet-mtp3.c index 86f2fb542a..c4061c2040 100644 --- a/epan/dissectors/packet-mtp3.c +++ b/epan/dissectors/packet-mtp3.c @@ -44,7 +44,7 @@ #endif #include -#include "tap.h" +#include #include /* Initialize the protocol and registered fields */ diff --git a/epan/dissectors/packet-rpc.c b/epan/dissectors/packet-rpc.c index a904ad38b6..151bde4e04 100644 --- a/epan/dissectors/packet-rpc.c +++ b/epan/dissectors/packet-rpc.c @@ -42,7 +42,7 @@ #include "reassemble.h" #include "rpc_defrag.h" #include "packet-nfs.h" -#include "tap.h" +#include /* * See: diff --git a/epan/dissectors/packet-rtp.c b/epan/dissectors/packet-rtp.c index c6952c5865..6dd725636e 100644 --- a/epan/dissectors/packet-rtp.c +++ b/epan/dissectors/packet-rtp.c @@ -64,7 +64,7 @@ #include "packet-rtp.h" #include "rtp_pt.h" #include -#include "tap.h" +#include #include diff --git a/epan/dissectors/packet-sctp.c b/epan/dissectors/packet-sctp.c index ba959a002b..632b758639 100644 --- a/epan/dissectors/packet-sctp.c +++ b/epan/dissectors/packet-sctp.c @@ -48,7 +48,7 @@ #include #include #include -#include "tap.h" +#include #include "ipproto.h" #include "packet-sctp.h" #include "sctpppids.h" diff --git a/epan/dissectors/packet-sip.c b/epan/dissectors/packet-sip.c index 9fd487f1d9..a3c315ca09 100644 --- a/epan/dissectors/packet-sip.c +++ b/epan/dissectors/packet-sip.c @@ -56,7 +56,7 @@ #include #include "packet-sip.h" -#include "tap.h" +#include #define TCP_PORT_SIP 5060 #define UDP_PORT_SIP 5060 diff --git a/epan/dissectors/packet-smb-sidsnooping.c b/epan/dissectors/packet-smb-sidsnooping.c index 84cdb8125e..0ee0d4f999 100644 --- a/epan/dissectors/packet-smb-sidsnooping.c +++ b/epan/dissectors/packet-smb-sidsnooping.c @@ -32,7 +32,7 @@ #include "epan/packet_info.h" #include "epan/epan_dissect.h" #include "epan/proto.h" -#include "tap.h" +#include #include "packet-dcerpc.h" #include "packet-dcerpc-nt.h" #include "register.h" diff --git a/epan/dissectors/packet-smb.c b/epan/dissectors/packet-smb.c index 5626603cb3..b788790769 100644 --- a/epan/dissectors/packet-smb.c +++ b/epan/dissectors/packet-smb.c @@ -42,7 +42,7 @@ #include #include #include "reassemble.h" -#include "tap.h" +#include #include "packet-ipx.h" #include "packet-windows-common.h" diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c index 3a229b40b1..bd6470aded 100644 --- a/epan/dissectors/packet-tcp.c +++ b/epan/dissectors/packet-tcp.c @@ -43,7 +43,7 @@ #include #include #include "reassemble.h" -#include "tap.h" +#include static int tcp_tap = -1; diff --git a/epan/dissectors/packet-teredo.c b/epan/dissectors/packet-teredo.c index 052f970489..56c97abb63 100644 --- a/epan/dissectors/packet-teredo.c +++ b/epan/dissectors/packet-teredo.c @@ -42,7 +42,7 @@ #include #include "packet-ip.h" -#include "tap.h" +#include #define UDP_PORT_TEREDO 3544 diff --git a/epan/dissectors/packet-tr.c b/epan/dissectors/packet-tr.c index d47c12e385..1668cea4bb 100644 --- a/epan/dissectors/packet-tr.c +++ b/epan/dissectors/packet-tr.c @@ -34,7 +34,7 @@ #include "packet-tr.h" #include "packet-llc.h" #include -#include "tap.h" +#include static int proto_tr = -1; static int hf_tr_dst = -1; diff --git a/epan/dissectors/packet-udp.c b/epan/dissectors/packet-udp.c index 209048fdd7..a737d7e57b 100644 --- a/epan/dissectors/packet-udp.c +++ b/epan/dissectors/packet-udp.c @@ -44,7 +44,7 @@ #include "packet-ip.h" #include -#include "tap.h" +#include static int udp_tap = -1; diff --git a/epan/dissectors/packet-wsp.c b/epan/dissectors/packet-wsp.c index e05bc1874c..13c5a9d2ed 100644 --- a/epan/dissectors/packet-wsp.c +++ b/epan/dissectors/packet-wsp.c @@ -82,7 +82,7 @@ #endif /* Statistics (see doc/README.tapping) */ -#include "tap.h" +#include static int wsp_tap = -1; diff --git a/epan/epan.c b/epan/epan.c index 8331113361..e623d418dc 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -19,7 +19,7 @@ #include "except.h" #include "packet.h" #include "column-utils.h" -#include "../tap.h" +#include "tap.h" #include "addr_resolv.h" static void (*report_failure_func)(const char *, va_list); diff --git a/epan/plugins.c b/epan/plugins.c index 1e9f9c9575..79a4306fe1 100644 --- a/epan/plugins.c +++ b/epan/plugins.c @@ -66,7 +66,7 @@ #include #include #include -#include "tap.h" +#include #include "asn1.h" #include #include diff --git a/epan/tap.c b/epan/tap.c new file mode 100644 index 0000000000..e73ab58a6f --- /dev/null +++ b/epan/tap.c @@ -0,0 +1,432 @@ +/* tap.c + * packet tap interface 2002 Ronnie Sahlberg + * + * $Id$ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#ifdef HAVE_SYS_TYPES_H +# include +#endif + +#ifdef HAVE_NETINET_IN_H +# include +#endif + +#include +#include "epan/packet_info.h" +#include "epan/dfilter/dfilter.h" +#include + +static gboolean tapping_is_active=FALSE; +int num_tap_filters=0; + +typedef struct _tap_dissector_t { + struct _tap_dissector_t *next; + char *name; +} tap_dissector_t; +static tap_dissector_t *tap_dissector_list=NULL; + +/* + * This is the list of free and used packets queued for a tap. + * It is implemented here explicitely instead of using GLib objects + * in order to be as fast as possible as we need to build and tear down the + * queued list at least once for each packet we see, thus we must be able + * to build and tear it down as fast as possible. + */ +typedef struct _tap_packet_t { + struct _tap_packet_t *next; + int tap_id; + packet_info *pinfo; + void *tap_specific_data; +} tap_packet_t; +static tap_packet_t *tap_packet_list_free=NULL; +static tap_packet_t *tap_packet_list_queue=NULL; +#define TAP_PACKET_QUEUE_LEN 100 + + +typedef struct _tap_listener_t { + struct _tap_listener_t *next; + int tap_id; + int needs_redraw; + dfilter_t *code; + void *tapdata; + tap_reset_cb reset; + tap_packet_cb packet; + tap_draw_cb draw; +} tap_listener_t; +static volatile tap_listener_t *tap_listener_queue=NULL; + +/* ********************************************************************** + * Init routine only called from epan at application startup + * ********************************************************************** */ +/* This function is called once when ethereal starts up and is used + to init any data structures we may need later. +*/ +void +tap_init(void) +{ + int i; + tap_packet_t *tpt; + + for(i=0;inext=tap_packet_list_free; + tap_packet_list_free=tpt; + } + tap_packet_list_queue=NULL; + + return; +} + + + +/* ********************************************************************** + * Functions called from dissector when made tappable + * ********************************************************************** */ +/* the following two functions are used from dissectors to + 1, register the ability to tap packets from this subdissector + 2, push packets encountered by the subdissector to anyone tapping +*/ + +/* This function registers that a dissector has the packet tap ability + available. The name parameter is the name of this tap and extensions can + use open_tap(char *name,... to specify that it wants to receive packets/ + events from this tap. + + This function is only to be called once, when the dissector initializes. + + The return value from this call is later used as a parameter to the + tap_packet(unsinged int *tap_id,... + call so that the tap subsystem knows to which tap point this tapped + packet is associated. +*/ +int +register_tap(char *name) +{ + tap_dissector_t *td, *tdl; + int i; + + td=g_malloc(sizeof(tap_dissector_t)); + td->next=NULL; + td->name = g_strdup(name); + + if(!tap_dissector_list){ + tap_dissector_list=td; + i=1; + } else { + for(i=2,tdl=tap_dissector_list;tdl->next;i++,tdl=tdl->next) + ; + tdl->next=td; + } + return i; +} + + +/* Everytime the dissector has finished dissecting a packet (and all + subdissectors have returned) and if the dissector has been made "tappable" + it will push some data to everyone tapping this layer by a call + to tap_queue_packet(). + The first parameter is the tap_id returned by the register_tap() + call for this dissector (so the tap system can keep track of who it came + from and who is listening to it) + The second is the packet_info structure which many tap readers will find + interesting. + The third argument is specific to each tap point or NULL if no additional + data is available to this tap. A tap point in say IP will probably want to + push the IP header structure here. Same thing for TCP and ONCRPC. + + The pinfo and the specific pointer are what is supplied to every listener + in the read_callback() call made to every one currently listening to this + tap. + + The tap reader is responsible to know how to parse any structure pointed + to by the tap specific data pointer. +*/ +void +tap_queue_packet(int tap_id, packet_info *pinfo, void *tap_specific_data) +{ + tap_packet_t *tpt; + + if(!tapping_is_active){ + return; + } + + /* get a free tap_packet structure, this is CHEAP */ + tpt=tap_packet_list_free; + tap_packet_list_free=tpt->next; + tpt->next=tap_packet_list_queue; + tap_packet_list_queue=tpt; + + tpt->tap_id=tap_id; + tpt->pinfo=pinfo; + tpt->tap_specific_data=tap_specific_data; + +} + + + + + +/* ********************************************************************** + * Functions used by file.c to drive the tap subsystem + * ********************************************************************** */ +/* This function is used to delete/initialize the tap queue and prime an + epan_dissect_t with all the filters for tap listeners. + To free the tap queue, we just prepend the used queue to the free queue. +*/ +void +tap_queue_init(epan_dissect_t *edt) +{ + tap_packet_t *tpt; + tap_listener_t *tl; + + /* nothing to do, just return */ + if(!tap_listener_queue){ + return; + } + + tapping_is_active=TRUE; + tpt=tap_packet_list_queue; + if(tpt){ + for(;tpt->next;tpt=tpt->next) + ; + + tpt->next=tap_packet_list_free; + tap_packet_list_free=tap_packet_list_queue; + tap_packet_list_queue=NULL; + } + + /* loop over all tap listeners and build the list of all + interesting hf_fields */ + for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ + if(tl->code){ + epan_dissect_prime_dfilter(edt, tl->code); + } + } +} + +/* this function is called after a packet has been fully dissected to push the tapped + data to all extensions that has callbacks registered. +*/ +void +tap_push_tapped_queue(epan_dissect_t *edt) +{ + tap_packet_t *tp; + tap_listener_t *tl; + + /* nothing to do, just return */ + if(!tapping_is_active){ + return; + } + + tapping_is_active=FALSE; + + /* nothing to do, just return */ + if(!tap_packet_list_queue){ + return; + } + + /* loop over all tap listeners and call the listener callback + for all packets that match the filter. */ + for(tp=tap_packet_list_queue;tp;tp=tp->next){ + for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ + if(tp->tap_id==tl->tap_id){ + int passed=TRUE; + if(tl->code){ + passed=dfilter_apply_edt(tl->code, edt); + } + if(passed && tl->packet){ + tl->needs_redraw|=tl->packet(tl->tapdata, tp->pinfo, edt, tp->tap_specific_data); + } + } + } + } +} + +/* This function is called when we need to reset all tap listeners, for example + when we open/start a new capture or if we need to rescan the packet list. +*/ +void +reset_tap_listeners(void) +{ + tap_listener_t *tl; + + for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ + if(tl->reset){ + tl->reset(tl->tapdata); + } + tl->needs_redraw=1; + } + +} + + +/* This function is called when we need to redraw all tap listeners, for example + when we open/start a new capture or if we need to rescan the packet list. + this one should be called from a low priority thread say once every 3 seconds + + If draw_all is true, redraw all aplications regardless if they have + changed or not. +*/ +void +draw_tap_listeners(gboolean draw_all) +{ + tap_listener_t *tl; + + for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ + if(tl->needs_redraw || draw_all){ + if(tl->draw){ + tl->draw(tl->tapdata); + } + } + tl->needs_redraw=0; + } +} + + + +/* ********************************************************************** + * Functions used by tap to + * 1, register that a really simple extension is available for use by + * ethereal. + * 2, start tapping from a subdissector + * 3, close an already open tap + * ********************************************************************** */ +/* this function will return the tap_id for the specific protocol tap + or 0 if no such tap was found. + */ +int +find_tap_id(char *name) +{ + tap_dissector_t *td; + int i; + + for(i=1,td=tap_dissector_list;td;i++,td=td->next) { + if(!strcmp(td->name,name)){ + return i; + } + } + return 0; +} + +/* this function attaches the tap_listener to the named tap. + * function returns : + * NULL: ok. + * non-NULL: error, return value points to GString containing error + * message. + */ +GString * +register_tap_listener(char *tapname, void *tapdata, char *fstring, tap_reset_cb reset, tap_packet_cb packet, tap_draw_cb draw) +{ + tap_listener_t *tl; + int tap_id; + GString *error_string; + + tap_id=find_tap_id(tapname); + if(!tap_id){ + error_string = g_string_new(""); + g_string_sprintf(error_string, "Tap %s not found", tapname); + return error_string; + } + + tl=g_malloc(sizeof(tap_listener_t)); + tl->code=NULL; + tl->needs_redraw=1; + if(fstring){ + if(!dfilter_compile(fstring, &tl->code)){ + error_string = g_string_new(""); + g_string_sprintf(error_string, + "Filter \"%s\" is invalid - %s", + fstring, dfilter_error_msg); + g_free(tl); + return error_string; + } else { + num_tap_filters++; + } + } + + tl->tap_id=tap_id; + tl->tapdata=tapdata; + tl->reset=reset; + tl->packet=packet; + tl->draw=draw; + tl->next=(tap_listener_t *)tap_listener_queue; + + tap_listener_queue=tl; + + return NULL; +} + +/* this function removes a tap listener + */ +void +remove_tap_listener(void *tapdata) +{ + tap_listener_t *tl=NULL,*tl2; + + if(!tap_listener_queue){ + return; + } + + if(tap_listener_queue->tapdata==tapdata){ + tl=(tap_listener_t *)tap_listener_queue; + tap_listener_queue=tap_listener_queue->next; + } else { + for(tl2=(tap_listener_t *)tap_listener_queue;tl2->next;tl2=tl2->next){ + if(tl2->next->tapdata==tapdata){ + tl=tl2->next; + tl2->next=tl2->next->next; + break; + } + + } + } + + if(tl){ + if(tl->code){ + dfilter_free(tl->code); + num_tap_filters--; + } + g_free(tl); + } + + return; +} + +/* + * Return TRUE if we have tap listeners, FALSE otherwise. + * Checking "num_tap_filters" isn't the right way to check whether we need + * to do any dissection in order to run taps, as not all taps necessarily + * have filters, and "num_tap_filters" is the number of tap filters, not + * the number of tap listeners; it's only the right way to check whether + * we need to build a protocol tree when doing dissection. + */ +gboolean +have_tap_listeners(void) +{ + return tap_listener_queue != NULL; +} diff --git a/epan/tap.h b/epan/tap.h new file mode 100644 index 0000000000..491ed3cae5 --- /dev/null +++ b/epan/tap.h @@ -0,0 +1,54 @@ +/* tap.h + * packet tap interface 2002 Ronnie Sahlberg + * + * $Id$ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _TAP_H_ +#define _TAP_H_ + +#include "epan/epan.h" + +/* With MSVC and a libethereal.dll, we need a + * special declaration of num_tap_filters. + */ +ETH_VAR_IMPORT int num_tap_filters; + +typedef void (*tap_reset_cb)(void *tapdata); +typedef int (*tap_packet_cb)(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, void *data); +typedef void (*tap_draw_cb)(void *tapdata); + + +extern void tap_init(void); +extern int register_tap(char *name); +extern int find_tap_id(char *name); +extern void tap_queue_packet(int tap_id, packet_info *pinfo, void *tap_specific_data); +extern void tap_queue_init(epan_dissect_t *edt); +extern void tap_push_tapped_queue(epan_dissect_t *edt); +extern void reset_tap_listeners(void); +extern void draw_tap_listeners(gboolean draw_all); +extern GString *register_tap_listener(char *tapname, void *tapdata, + char *fstring, tap_reset_cb tap_reset, tap_packet_cb tap_packet, + tap_draw_cb tap_draw); +extern void remove_tap_listener(void *tapdata); +extern gboolean have_tap_listeners(void); + +#endif diff --git a/file.c b/file.c index 7dd9643e37..5d5bf9784f 100644 --- a/file.c +++ b/file.c @@ -85,7 +85,7 @@ #include #include "globals.h" #include -#include "tap.h" +#include #include "tap_dfilter_dlg.h" #include diff --git a/gtk/ansi_a_stat.c b/gtk/ansi_a_stat.c index d28f5e2272..6cc9feeef9 100644 --- a/gtk/ansi_a_stat.c +++ b/gtk/ansi_a_stat.c @@ -45,7 +45,7 @@ #include "image/clist_descend.xpm" #include "simple_dialog.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include #include diff --git a/gtk/ansi_map_stat.c b/gtk/ansi_map_stat.c index 43e852894f..e8714019b2 100644 --- a/gtk/ansi_map_stat.c +++ b/gtk/ansi_map_stat.c @@ -45,7 +45,7 @@ #include "image/clist_descend.xpm" #include "simple_dialog.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include "../globals.h" #include "filter_dlg.h" diff --git a/gtk/bootp_stat.c b/gtk/bootp_stat.c index 6af60e1b8f..a6df442882 100644 --- a/gtk/bootp_stat.c +++ b/gtk/bootp_stat.c @@ -37,7 +37,7 @@ #include "simple_dialog.h" #include "ui_util.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include "../globals.h" #include "compat_macros.h" diff --git a/gtk/conversations_eth.c b/gtk/conversations_eth.c index 568bdcf83f..681b64657e 100644 --- a/gtk/conversations_eth.c +++ b/gtk/conversations_eth.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "conversations_table.h" #include diff --git a/gtk/conversations_fc.c b/gtk/conversations_fc.c index 82f479f13e..b584197063 100644 --- a/gtk/conversations_fc.c +++ b/gtk/conversations_fc.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "conversations_table.h" #include diff --git a/gtk/conversations_fddi.c b/gtk/conversations_fddi.c index 8bf8a6f1c3..be6222652d 100644 --- a/gtk/conversations_fddi.c +++ b/gtk/conversations_fddi.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "conversations_table.h" #include diff --git a/gtk/conversations_ip.c b/gtk/conversations_ip.c index ef487a1015..5a94f97f59 100644 --- a/gtk/conversations_ip.c +++ b/gtk/conversations_ip.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "conversations_table.h" #include diff --git a/gtk/conversations_ipx.c b/gtk/conversations_ipx.c index e623fdebd1..4b90e2a3a2 100644 --- a/gtk/conversations_ipx.c +++ b/gtk/conversations_ipx.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "conversations_table.h" #include diff --git a/gtk/conversations_table.c b/gtk/conversations_table.c index ebd61d1463..325f19c470 100644 --- a/gtk/conversations_table.c +++ b/gtk/conversations_table.c @@ -46,7 +46,7 @@ #include "image/clist_descend.xpm" #include "simple_dialog.h" #include "globals.h" -#include "tap.h" +#include #include "gtk/find_dlg.h" #include "color.h" #include "gtk/color_dlg.h" diff --git a/gtk/conversations_tcpip.c b/gtk/conversations_tcpip.c index c8a37f7c28..de201e87ef 100644 --- a/gtk/conversations_tcpip.c +++ b/gtk/conversations_tcpip.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "conversations_table.h" #include diff --git a/gtk/conversations_tr.c b/gtk/conversations_tr.c index d05f3ef581..c01807fcbc 100644 --- a/gtk/conversations_tr.c +++ b/gtk/conversations_tr.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "conversations_table.h" #include diff --git a/gtk/conversations_udpip.c b/gtk/conversations_udpip.c index 601abebb56..5a695c0e1f 100644 --- a/gtk/conversations_udpip.c +++ b/gtk/conversations_udpip.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "conversations_table.h" #include diff --git a/gtk/dcerpc_stat.c b/gtk/dcerpc_stat.c index 729d0287e5..e9a532c37b 100644 --- a/gtk/dcerpc_stat.c +++ b/gtk/dcerpc_stat.c @@ -44,7 +44,7 @@ #include "simple_dialog.h" #include "dlg_utils.h" #include "ui_util.h" -#include "tap.h" +#include #include "../register.h" #include #include "../globals.h" diff --git a/gtk/fc_stat.c b/gtk/fc_stat.c index edc06c706a..13d9c94046 100644 --- a/gtk/fc_stat.c +++ b/gtk/fc_stat.c @@ -39,7 +39,7 @@ #include #include "tap_menu.h" -#include "../tap.h" +#include #include #include "../register.h" #include "../timestats.h" diff --git a/gtk/gsm_a_stat.c b/gtk/gsm_a_stat.c index e02da74d73..37f90a8af5 100644 --- a/gtk/gsm_a_stat.c +++ b/gtk/gsm_a_stat.c @@ -45,7 +45,7 @@ #include "image/clist_descend.xpm" #include "simple_dialog.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include #include diff --git a/gtk/gsm_map_stat.c b/gtk/gsm_map_stat.c index d68083622d..b8a0e4df74 100644 --- a/gtk/gsm_map_stat.c +++ b/gtk/gsm_map_stat.c @@ -46,7 +46,7 @@ #include "simple_dialog.h" #include "dlg_utils.h" #include "ui_util.h" -#include "tap.h" +#include #include "../register.h" #include "../globals.h" #include "filter_dlg.h" diff --git a/gtk/gsm_map_summary.c b/gtk/gsm_map_summary.c index e8c913b85d..b70f5650af 100644 --- a/gtk/gsm_map_summary.c +++ b/gtk/gsm_map_summary.c @@ -43,7 +43,7 @@ #include "dlg_utils.h" #include "ui_util.h" #include "compat_macros.h" -#include "tap.h" +#include #include #include "gsm_map_stat.h" diff --git a/gtk/h225_counter.c b/gtk/h225_counter.c index e393120edd..5fd792a2af 100644 --- a/gtk/h225_counter.c +++ b/gtk/h225_counter.c @@ -40,7 +40,7 @@ #include #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include #include "gtk_stat_util.h" diff --git a/gtk/h225_ras_srt.c b/gtk/h225_ras_srt.c index a82aee1725..a0fea7ad38 100644 --- a/gtk/h225_ras_srt.c +++ b/gtk/h225_ras_srt.c @@ -40,7 +40,7 @@ #include #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include #include "../timestats.h" diff --git a/gtk/hostlist_eth.c b/gtk/hostlist_eth.c index 330a7ca2f4..814645c5b5 100644 --- a/gtk/hostlist_eth.c +++ b/gtk/hostlist_eth.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "hostlist_table.h" #include diff --git a/gtk/hostlist_fc.c b/gtk/hostlist_fc.c index 30cef350e1..e3b4c44687 100644 --- a/gtk/hostlist_fc.c +++ b/gtk/hostlist_fc.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "hostlist_table.h" #include diff --git a/gtk/hostlist_fddi.c b/gtk/hostlist_fddi.c index 63c23b6598..0ca976dd5d 100644 --- a/gtk/hostlist_fddi.c +++ b/gtk/hostlist_fddi.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "hostlist_table.h" #include diff --git a/gtk/hostlist_ip.c b/gtk/hostlist_ip.c index 32544c4f2b..0f95fcce51 100644 --- a/gtk/hostlist_ip.c +++ b/gtk/hostlist_ip.c @@ -36,7 +36,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "hostlist_table.h" #include diff --git a/gtk/hostlist_ipx.c b/gtk/hostlist_ipx.c index 12be5b2aa3..a59a85d5f0 100644 --- a/gtk/hostlist_ipx.c +++ b/gtk/hostlist_ipx.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "hostlist_table.h" #include diff --git a/gtk/hostlist_table.c b/gtk/hostlist_table.c index 4d9903afeb..84e3cc4589 100644 --- a/gtk/hostlist_table.c +++ b/gtk/hostlist_table.c @@ -41,7 +41,7 @@ #include "image/clist_descend.xpm" #include "simple_dialog.h" #include "globals.h" -#include "tap.h" +#include #include "gtk/find_dlg.h" #include "color.h" #include "gtk/color_dlg.h" diff --git a/gtk/hostlist_tcpip.c b/gtk/hostlist_tcpip.c index 1b75b93fd6..0490866667 100644 --- a/gtk/hostlist_tcpip.c +++ b/gtk/hostlist_tcpip.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "hostlist_table.h" #include diff --git a/gtk/hostlist_tr.c b/gtk/hostlist_tr.c index e0cd79d62a..3109521fef 100644 --- a/gtk/hostlist_tr.c +++ b/gtk/hostlist_tr.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "hostlist_table.h" #include diff --git a/gtk/hostlist_udpip.c b/gtk/hostlist_udpip.c index 5574ad20c3..b7c048051e 100644 --- a/gtk/hostlist_udpip.c +++ b/gtk/hostlist_udpip.c @@ -34,7 +34,7 @@ #include #include "epan/packet.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "hostlist_table.h" #include diff --git a/gtk/http_stat.c b/gtk/http_stat.c index 982c928095..32ad427fd0 100644 --- a/gtk/http_stat.c +++ b/gtk/http_stat.c @@ -37,7 +37,7 @@ #include "simple_dialog.h" #include "ui_util.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include #include "../globals.h" diff --git a/gtk/io_stat.c b/gtk/io_stat.c index 2329062d89..2518492a28 100644 --- a/gtk/io_stat.c +++ b/gtk/io_stat.c @@ -43,7 +43,7 @@ #include "gtkglobals.h" #include "ui_util.h" #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "alert_box.h" #include "simple_dialog.h" diff --git a/gtk/isup_stat.c b/gtk/isup_stat.c index 37f8a26805..286fb9532b 100644 --- a/gtk/isup_stat.c +++ b/gtk/isup_stat.c @@ -45,7 +45,7 @@ #include "image/clist_descend.xpm" #include "simple_dialog.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include "../globals.h" #include "filter_dlg.h" diff --git a/gtk/ldap_stat.c b/gtk/ldap_stat.c index e5f4621404..c63497cb6f 100644 --- a/gtk/ldap_stat.c +++ b/gtk/ldap_stat.c @@ -39,7 +39,7 @@ #include #include "tap_menu.h" -#include "../tap.h" +#include #include #include "../register.h" #include "../timestats.h" diff --git a/gtk/main.c b/gtk/main.c index b4771686e7..f9b6ed8e2b 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -96,7 +96,7 @@ #include "prefs-int.h" #include "ringbuffer.h" #include "../ui_util.h" /* beware: ui_util.h exists twice! */ -#include "tap.h" +#include #include "util.h" #include "clopts_common.h" #include "version_info.h" diff --git a/gtk/menu.c b/gtk/menu.c index 4bcd04647d..03a860d1c1 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -36,6 +36,9 @@ #include #include #include +#include +#include + #include "about_dlg.h" #include "capture_dlg.h" #include "color_dlg.h" @@ -61,7 +64,6 @@ #include "toolbar.h" #include "gtkglobals.h" #include "register.h" -#include "../tap.h" #include "../menu.h" #include "../ipproto.h" #include "packet_list.h" @@ -72,7 +74,6 @@ #include "conversations_table.h" #include "hostlist_table.h" #include "simple_dialog.h" -#include GtkWidget *popup_menu_object; diff --git a/gtk/mgcp_stat.c b/gtk/mgcp_stat.c index 247ee317ca..699e9ebc4e 100644 --- a/gtk/mgcp_stat.c +++ b/gtk/mgcp_stat.c @@ -40,7 +40,7 @@ #include #include "tap_menu.h" -#include "../tap.h" +#include #include "../register.h" #include "../plugins/mgcp/packet-mgcp.h" #include "../timestats.h" diff --git a/gtk/mtp3_stat.c b/gtk/mtp3_stat.c index f2596346bf..ad74801651 100644 --- a/gtk/mtp3_stat.c +++ b/gtk/mtp3_stat.c @@ -45,7 +45,7 @@ #include "image/clist_descend.xpm" #include "simple_dialog.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include "../globals.h" #include "filter_dlg.h" diff --git a/gtk/mtp3_summary.c b/gtk/mtp3_summary.c index 1716ef1029..5bdbd73a21 100644 --- a/gtk/mtp3_summary.c +++ b/gtk/mtp3_summary.c @@ -46,7 +46,7 @@ #include "dlg_utils.h" #include "ui_util.h" #include "compat_macros.h" -#include "tap.h" +#include #include #include "mtp3_stat.h" diff --git a/gtk/rpc_progs.c b/gtk/rpc_progs.c index d24996c405..2474f6bcff 100644 --- a/gtk/rpc_progs.c +++ b/gtk/rpc_progs.c @@ -38,7 +38,7 @@ #include #include "tap_menu.h" -#include "tap.h" +#include #include "../register.h" #include #include "../globals.h" diff --git a/gtk/rpc_stat.c b/gtk/rpc_stat.c index bf64e48939..31f58edd23 100644 --- a/gtk/rpc_stat.c +++ b/gtk/rpc_stat.c @@ -41,7 +41,7 @@ #include "simple_dialog.h" #include "ui_util.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include #include "../globals.h" diff --git a/gtk/rtp_analysis.c b/gtk/rtp_analysis.c index cddea86e6f..431db1c4a5 100644 --- a/gtk/rtp_analysis.c +++ b/gtk/rtp_analysis.c @@ -48,7 +48,7 @@ #include #include "util.h" -#include "tap.h" +#include #include "register.h" #include #include "g711.h" diff --git a/gtk/rtp_stream.c b/gtk/rtp_stream.c index eb7365deeb..96ed9a2b7d 100644 --- a/gtk/rtp_stream.c +++ b/gtk/rtp_stream.c @@ -34,7 +34,7 @@ #include "globals.h" -#include "tap.h" +#include #include "register.h" #include diff --git a/gtk/sctp_stat.c b/gtk/sctp_stat.c index 831b0554ba..52dfbed234 100644 --- a/gtk/sctp_stat.c +++ b/gtk/sctp_stat.c @@ -31,7 +31,7 @@ #include "simple_dialog.h" /* Both is used for error handling */ #include "globals.h" #include "epan/packet_info.h" /* Needed for packet_info */ -#include "tap.h" /* Needed for register_tap_listener */ +#include /* Needed for register_tap_listener */ #include "tap_menu.h" #include "dlg_utils.h" #include "compat_macros.h" diff --git a/gtk/sip_stat.c b/gtk/sip_stat.c index a50e57a566..efd2e9a5cd 100644 --- a/gtk/sip_stat.c +++ b/gtk/sip_stat.c @@ -38,7 +38,7 @@ #include "simple_dialog.h" #include "ui_util.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include #include "../globals.h" diff --git a/gtk/smb_stat.c b/gtk/smb_stat.c index f193494f91..c9197e32cf 100644 --- a/gtk/smb_stat.c +++ b/gtk/smb_stat.c @@ -39,7 +39,7 @@ #include #include "tap_menu.h" -#include "../tap.h" +#include #include "../smb.h" #include "../register.h" #include "../timestats.h" diff --git a/gtk/wsp_stat.c b/gtk/wsp_stat.c index 4a30dbc65f..45868c3235 100644 --- a/gtk/wsp_stat.c +++ b/gtk/wsp_stat.c @@ -38,7 +38,7 @@ #include "simple_dialog.h" #include "ui_util.h" #include "dlg_utils.h" -#include "tap.h" +#include #include "../register.h" #include "../globals.h" #include "compat_macros.h" diff --git a/plugins/mgcp/packet-mgcp.c b/plugins/mgcp/packet-mgcp.c index 1efdd2df54..154b68b5ac 100644 --- a/plugins/mgcp/packet-mgcp.c +++ b/plugins/mgcp/packet-mgcp.c @@ -53,8 +53,8 @@ #include #include #include +#include #include "packet-mgcp.h" -#include "../../tap.h" #ifndef HAVE_WIN32_LIBETHEREAL_LIB #include "plugins/plugin_api_defs.h" diff --git a/plugins/plugin_api.h b/plugins/plugin_api.h index 90f1694e4a..c2e651138b 100644 --- a/plugins/plugin_api.h +++ b/plugins/plugin_api.h @@ -52,7 +52,7 @@ #include #include #include -#include "tap.h" +#include #include "asn1.h" #include #include diff --git a/plugins/plugin_api_list.c b/plugins/plugin_api_list.c index 80bb9a7c33..5e5d356190 100644 --- a/plugins/plugin_api_list.c +++ b/plugins/plugin_api_list.c @@ -41,7 +41,7 @@ #include #include #include -#include "tap.h" +#include #include "asn1.h" #include #include diff --git a/tap-ansi_astat.c b/tap-ansi_astat.c index 6f6f9d1fb6..4c5d847efb 100644 --- a/tap-ansi_astat.c +++ b/tap-ansi_astat.c @@ -45,7 +45,7 @@ #include #include "epan/packet_info.h" #include "epan/value_string.h" -#include "tap.h" +#include #include #include #include "register.h" diff --git a/tap-bootpstat.c b/tap-bootpstat.c index 5b3b05c278..da2a2e29a3 100644 --- a/tap-bootpstat.c +++ b/tap-bootpstat.c @@ -29,7 +29,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include "register.h" #include diff --git a/tap-dcerpcstat.c b/tap-dcerpcstat.c index 2a9993b104..1b824dc89f 100644 --- a/tap-dcerpcstat.c +++ b/tap-dcerpcstat.c @@ -34,7 +34,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include #include "register.h" diff --git a/tap-gsm_astat.c b/tap-gsm_astat.c index 25e83cbe02..07bc874571 100644 --- a/tap-gsm_astat.c +++ b/tap-gsm_astat.c @@ -45,7 +45,7 @@ #include #include "epan/packet_info.h" #include "epan/value_string.h" -#include "tap.h" +#include #include #include #include "register.h" diff --git a/tap-h225counter.c b/tap-h225counter.c index 878cf591c4..2c8c44fc48 100644 --- a/tap-h225counter.c +++ b/tap-h225counter.c @@ -39,7 +39,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include "epan/value_string.h" #include "register.h" #include diff --git a/tap-h225rassrt.c b/tap-h225rassrt.c index f908e780b9..998f00c063 100644 --- a/tap-h225rassrt.c +++ b/tap-h225rassrt.c @@ -35,7 +35,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include "epan/value_string.h" #include "register.h" #include diff --git a/tap-httpstat.c b/tap-httpstat.c index 57ac1b67db..3e537d7fd5 100644 --- a/tap-httpstat.c +++ b/tap-httpstat.c @@ -31,7 +31,7 @@ #include "epan/packet_info.h" #include "epan/value_string.h" -#include "tap.h" +#include #include "register.h" #include diff --git a/tap-iostat.c b/tap-iostat.c index d36faa05c4..da84b631f6 100644 --- a/tap-iostat.c +++ b/tap-iostat.c @@ -35,7 +35,7 @@ #include #include "epan/epan_dissect.h" #include "epan/packet_info.h" -#include "tap.h" +#include #include "register.h" diff --git a/tap-iousers.c b/tap-iousers.c index 2b33458012..b63100ff6f 100644 --- a/tap-iousers.c +++ b/tap-iousers.c @@ -36,7 +36,7 @@ #include #include #include -#include "tap.h" +#include #include "register.h" #include #include diff --git a/tap-mgcpstat.c b/tap-mgcpstat.c index a7905ed03e..f6853db127 100644 --- a/tap-mgcpstat.c +++ b/tap-mgcpstat.c @@ -34,7 +34,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include "epan/value_string.h" #include "register.h" #include "plugins/mgcp/packet-mgcp.h" diff --git a/tap-protocolinfo.c b/tap-protocolinfo.c index 229e59575f..1e1483caa8 100644 --- a/tap-protocolinfo.c +++ b/tap-protocolinfo.c @@ -38,7 +38,7 @@ #include "epan/epan_dissect.h" #include "epan/column-utils.h" #include "epan/proto.h" -#include "tap.h" +#include #include "register.h" typedef struct _pci_t { diff --git a/tap-protohierstat.c b/tap-protohierstat.c index d6966676b1..bc074c4c37 100644 --- a/tap-protohierstat.c +++ b/tap-protohierstat.c @@ -38,7 +38,7 @@ #include "epan/packet_info.h" #include "epan/epan_dissect.h" #include "epan/proto.h" -#include "tap.h" +#include #include "register.h" typedef struct _phs_t { diff --git a/tap-rpcprogs.c b/tap-rpcprogs.c index 3c7b488420..2d0129cafb 100644 --- a/tap-rpcprogs.c +++ b/tap-rpcprogs.c @@ -38,7 +38,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include #include "register.h" diff --git a/tap-rpcstat.c b/tap-rpcstat.c index 337fdcabd1..61471d7dc8 100644 --- a/tap-rpcstat.c +++ b/tap-rpcstat.c @@ -44,7 +44,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include #include "register.h" diff --git a/tap-sipstat.c b/tap-sipstat.c index 791c7b1fc5..ac9cd316f5 100644 --- a/tap-sipstat.c +++ b/tap-sipstat.c @@ -35,7 +35,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include "epan/value_string.h" #include "register.h" #include diff --git a/tap-smbsids.c b/tap-smbsids.c index 4543676d3a..2d0cdf3d0e 100644 --- a/tap-smbsids.c +++ b/tap-smbsids.c @@ -40,7 +40,7 @@ #include "epan/packet_info.h" #include #include "register.h" -#include "tap.h" +#include #include "epan/value_string.h" #include "smb.h" diff --git a/tap-smbstat.c b/tap-smbstat.c index 4c0efe62bc..4c6b4ef4a4 100644 --- a/tap-smbstat.c +++ b/tap-smbstat.c @@ -38,7 +38,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include "epan/value_string.h" #include "smb.h" #include "register.h" diff --git a/tap-wspstat.c b/tap-wspstat.c index a43a165ac6..b12255c8b4 100644 --- a/tap-wspstat.c +++ b/tap-wspstat.c @@ -43,7 +43,7 @@ #include #include "epan/packet_info.h" -#include "tap.h" +#include #include "register.h" #include "epan/value_string.h" #include diff --git a/tap.c b/tap.c deleted file mode 100644 index fb9d0bf994..0000000000 --- a/tap.c +++ /dev/null @@ -1,432 +0,0 @@ -/* tap.c - * packet tap interface 2002 Ronnie Sahlberg - * - * $Id$ - * - * Ethereal - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include - -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#ifdef HAVE_NETINET_IN_H -# include -#endif - -#include -#include "epan/packet_info.h" -#include "epan/dfilter/dfilter.h" -#include "tap.h" - -static gboolean tapping_is_active=FALSE; -int num_tap_filters=0; - -typedef struct _tap_dissector_t { - struct _tap_dissector_t *next; - char *name; -} tap_dissector_t; -static tap_dissector_t *tap_dissector_list=NULL; - -/* - * This is the list of free and used packets queued for a tap. - * It is implemented here explicitely instead of using GLib objects - * in order to be as fast as possible as we need to build and tear down the - * queued list at least once for each packet we see, thus we must be able - * to build and tear it down as fast as possible. - */ -typedef struct _tap_packet_t { - struct _tap_packet_t *next; - int tap_id; - packet_info *pinfo; - void *tap_specific_data; -} tap_packet_t; -static tap_packet_t *tap_packet_list_free=NULL; -static tap_packet_t *tap_packet_list_queue=NULL; -#define TAP_PACKET_QUEUE_LEN 100 - - -typedef struct _tap_listener_t { - struct _tap_listener_t *next; - int tap_id; - int needs_redraw; - dfilter_t *code; - void *tapdata; - tap_reset_cb reset; - tap_packet_cb packet; - tap_draw_cb draw; -} tap_listener_t; -static volatile tap_listener_t *tap_listener_queue=NULL; - -/* ********************************************************************** - * Init routine only called from epan at application startup - * ********************************************************************** */ -/* This function is called once when ethereal starts up and is used - to init any data structures we may need later. -*/ -void -tap_init(void) -{ - int i; - tap_packet_t *tpt; - - for(i=0;inext=tap_packet_list_free; - tap_packet_list_free=tpt; - } - tap_packet_list_queue=NULL; - - return; -} - - - -/* ********************************************************************** - * Functions called from dissector when made tappable - * ********************************************************************** */ -/* the following two functions are used from dissectors to - 1, register the ability to tap packets from this subdissector - 2, push packets encountered by the subdissector to anyone tapping -*/ - -/* This function registers that a dissector has the packet tap ability - available. The name parameter is the name of this tap and extensions can - use open_tap(char *name,... to specify that it wants to receive packets/ - events from this tap. - - This function is only to be called once, when the dissector initializes. - - The return value from this call is later used as a parameter to the - tap_packet(unsinged int *tap_id,... - call so that the tap subsystem knows to which tap point this tapped - packet is associated. -*/ -int -register_tap(char *name) -{ - tap_dissector_t *td, *tdl; - int i; - - td=g_malloc(sizeof(tap_dissector_t)); - td->next=NULL; - td->name = g_strdup(name); - - if(!tap_dissector_list){ - tap_dissector_list=td; - i=1; - } else { - for(i=2,tdl=tap_dissector_list;tdl->next;i++,tdl=tdl->next) - ; - tdl->next=td; - } - return i; -} - - -/* Everytime the dissector has finished dissecting a packet (and all - subdissectors have returned) and if the dissector has been made "tappable" - it will push some data to everyone tapping this layer by a call - to tap_queue_packet(). - The first parameter is the tap_id returned by the register_tap() - call for this dissector (so the tap system can keep track of who it came - from and who is listening to it) - The second is the packet_info structure which many tap readers will find - interesting. - The third argument is specific to each tap point or NULL if no additional - data is available to this tap. A tap point in say IP will probably want to - push the IP header structure here. Same thing for TCP and ONCRPC. - - The pinfo and the specific pointer are what is supplied to every listener - in the read_callback() call made to every one currently listening to this - tap. - - The tap reader is responsible to know how to parse any structure pointed - to by the tap specific data pointer. -*/ -void -tap_queue_packet(int tap_id, packet_info *pinfo, void *tap_specific_data) -{ - tap_packet_t *tpt; - - if(!tapping_is_active){ - return; - } - - /* get a free tap_packet structure, this is CHEAP */ - tpt=tap_packet_list_free; - tap_packet_list_free=tpt->next; - tpt->next=tap_packet_list_queue; - tap_packet_list_queue=tpt; - - tpt->tap_id=tap_id; - tpt->pinfo=pinfo; - tpt->tap_specific_data=tap_specific_data; - -} - - - - - -/* ********************************************************************** - * Functions used by file.c to drive the tap subsystem - * ********************************************************************** */ -/* This function is used to delete/initialize the tap queue and prime an - epan_dissect_t with all the filters for tap listeners. - To free the tap queue, we just prepend the used queue to the free queue. -*/ -void -tap_queue_init(epan_dissect_t *edt) -{ - tap_packet_t *tpt; - tap_listener_t *tl; - - /* nothing to do, just return */ - if(!tap_listener_queue){ - return; - } - - tapping_is_active=TRUE; - tpt=tap_packet_list_queue; - if(tpt){ - for(;tpt->next;tpt=tpt->next) - ; - - tpt->next=tap_packet_list_free; - tap_packet_list_free=tap_packet_list_queue; - tap_packet_list_queue=NULL; - } - - /* loop over all tap listeners and build the list of all - interesting hf_fields */ - for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ - if(tl->code){ - epan_dissect_prime_dfilter(edt, tl->code); - } - } -} - -/* this function is called after a packet has been fully dissected to push the tapped - data to all extensions that has callbacks registered. -*/ -void -tap_push_tapped_queue(epan_dissect_t *edt) -{ - tap_packet_t *tp; - tap_listener_t *tl; - - /* nothing to do, just return */ - if(!tapping_is_active){ - return; - } - - tapping_is_active=FALSE; - - /* nothing to do, just return */ - if(!tap_packet_list_queue){ - return; - } - - /* loop over all tap listeners and call the listener callback - for all packets that match the filter. */ - for(tp=tap_packet_list_queue;tp;tp=tp->next){ - for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ - if(tp->tap_id==tl->tap_id){ - int passed=TRUE; - if(tl->code){ - passed=dfilter_apply_edt(tl->code, edt); - } - if(passed && tl->packet){ - tl->needs_redraw|=tl->packet(tl->tapdata, tp->pinfo, edt, tp->tap_specific_data); - } - } - } - } -} - -/* This function is called when we need to reset all tap listeners, for example - when we open/start a new capture or if we need to rescan the packet list. -*/ -void -reset_tap_listeners(void) -{ - tap_listener_t *tl; - - for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ - if(tl->reset){ - tl->reset(tl->tapdata); - } - tl->needs_redraw=1; - } - -} - - -/* This function is called when we need to redraw all tap listeners, for example - when we open/start a new capture or if we need to rescan the packet list. - this one should be called from a low priority thread say once every 3 seconds - - If draw_all is true, redraw all aplications regardless if they have - changed or not. -*/ -void -draw_tap_listeners(gboolean draw_all) -{ - tap_listener_t *tl; - - for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ - if(tl->needs_redraw || draw_all){ - if(tl->draw){ - tl->draw(tl->tapdata); - } - } - tl->needs_redraw=0; - } -} - - - -/* ********************************************************************** - * Functions used by tap to - * 1, register that a really simple extension is available for use by - * ethereal. - * 2, start tapping from a subdissector - * 3, close an already open tap - * ********************************************************************** */ -/* this function will return the tap_id for the specific protocol tap - or 0 if no such tap was found. - */ -int -find_tap_id(char *name) -{ - tap_dissector_t *td; - int i; - - for(i=1,td=tap_dissector_list;td;i++,td=td->next) { - if(!strcmp(td->name,name)){ - return i; - } - } - return 0; -} - -/* this function attaches the tap_listener to the named tap. - * function returns : - * NULL: ok. - * non-NULL: error, return value points to GString containing error - * message. - */ -GString * -register_tap_listener(char *tapname, void *tapdata, char *fstring, tap_reset_cb reset, tap_packet_cb packet, tap_draw_cb draw) -{ - tap_listener_t *tl; - int tap_id; - GString *error_string; - - tap_id=find_tap_id(tapname); - if(!tap_id){ - error_string = g_string_new(""); - g_string_sprintf(error_string, "Tap %s not found", tapname); - return error_string; - } - - tl=g_malloc(sizeof(tap_listener_t)); - tl->code=NULL; - tl->needs_redraw=1; - if(fstring){ - if(!dfilter_compile(fstring, &tl->code)){ - error_string = g_string_new(""); - g_string_sprintf(error_string, - "Filter \"%s\" is invalid - %s", - fstring, dfilter_error_msg); - g_free(tl); - return error_string; - } else { - num_tap_filters++; - } - } - - tl->tap_id=tap_id; - tl->tapdata=tapdata; - tl->reset=reset; - tl->packet=packet; - tl->draw=draw; - tl->next=(tap_listener_t *)tap_listener_queue; - - tap_listener_queue=tl; - - return NULL; -} - -/* this function removes a tap listener - */ -void -remove_tap_listener(void *tapdata) -{ - tap_listener_t *tl=NULL,*tl2; - - if(!tap_listener_queue){ - return; - } - - if(tap_listener_queue->tapdata==tapdata){ - tl=(tap_listener_t *)tap_listener_queue; - tap_listener_queue=tap_listener_queue->next; - } else { - for(tl2=(tap_listener_t *)tap_listener_queue;tl2->next;tl2=tl2->next){ - if(tl2->next->tapdata==tapdata){ - tl=tl2->next; - tl2->next=tl2->next->next; - break; - } - - } - } - - if(tl){ - if(tl->code){ - dfilter_free(tl->code); - num_tap_filters--; - } - g_free(tl); - } - - return; -} - -/* - * Return TRUE if we have tap listeners, FALSE otherwise. - * Checking "num_tap_filters" isn't the right way to check whether we need - * to do any dissection in order to run taps, as not all taps necessarily - * have filters, and "num_tap_filters" is the number of tap filters, not - * the number of tap listeners; it's only the right way to check whether - * we need to build a protocol tree when doing dissection. - */ -gboolean -have_tap_listeners(void) -{ - return tap_listener_queue != NULL; -} diff --git a/tap.h b/tap.h deleted file mode 100644 index 491ed3cae5..0000000000 --- a/tap.h +++ /dev/null @@ -1,54 +0,0 @@ -/* tap.h - * packet tap interface 2002 Ronnie Sahlberg - * - * $Id$ - * - * Ethereal - Network traffic analyzer - * By Gerald Combs - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef _TAP_H_ -#define _TAP_H_ - -#include "epan/epan.h" - -/* With MSVC and a libethereal.dll, we need a - * special declaration of num_tap_filters. - */ -ETH_VAR_IMPORT int num_tap_filters; - -typedef void (*tap_reset_cb)(void *tapdata); -typedef int (*tap_packet_cb)(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, void *data); -typedef void (*tap_draw_cb)(void *tapdata); - - -extern void tap_init(void); -extern int register_tap(char *name); -extern int find_tap_id(char *name); -extern void tap_queue_packet(int tap_id, packet_info *pinfo, void *tap_specific_data); -extern void tap_queue_init(epan_dissect_t *edt); -extern void tap_push_tapped_queue(epan_dissect_t *edt); -extern void reset_tap_listeners(void); -extern void draw_tap_listeners(gboolean draw_all); -extern GString *register_tap_listener(char *tapname, void *tapdata, - char *fstring, tap_reset_cb tap_reset, tap_packet_cb tap_packet, - tap_draw_cb tap_draw); -extern void remove_tap_listener(void *tapdata); -extern gboolean have_tap_listeners(void); - -#endif diff --git a/tethereal.c b/tethereal.c index 3567ce6876..7af7592da1 100644 --- a/tethereal.c +++ b/tethereal.c @@ -100,7 +100,7 @@ #include "capture_stop_conditions.h" #include "ringbuffer.h" #include -#include "tap.h" +#include #include #ifdef HAVE_LIBPCAP -- cgit v1.2.3