2002-09-04 09:40:29 +00:00
|
|
|
/* tap.c
|
|
|
|
* packet tap interface 2002 Ronnie Sahlberg
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2002-09-04 09:40:29 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2002-09-04 09:40:29 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2011-03-31 14:30:38 +00:00
|
|
|
*
|
2002-09-04 09:40:29 +00:00
|
|
|
* 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.
|
2011-03-31 14:30:38 +00:00
|
|
|
*
|
2002-09-04 09:40:29 +00:00
|
|
|
* 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.
|
2011-03-31 14:30:38 +00:00
|
|
|
*
|
2002-09-04 09:40:29 +00:00
|
|
|
* 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 <stdio.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
2009-08-21 20:51:13 +00:00
|
|
|
#include <epan/packet_info.h>
|
|
|
|
#include <epan/dfilter/dfilter.h>
|
2004-09-29 00:06:36 +00:00
|
|
|
#include <epan/tap.h>
|
2002-09-04 09:40:29 +00:00
|
|
|
|
2002-10-17 02:11:20 +00:00
|
|
|
static gboolean tapping_is_active=FALSE;
|
2002-09-04 09:40:29 +00:00
|
|
|
|
|
|
|
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.
|
2011-03-31 14:30:38 +00:00
|
|
|
* It is implemented here explicitly instead of using GLib objects
|
2002-09-04 09:40:29 +00:00
|
|
|
* in order to be as fast as possible as we need to build and tear down the
|
2011-03-31 14:30:38 +00:00
|
|
|
* queued list at least once for each packet we see and thus we must be able
|
2002-09-04 09:40:29 +00:00
|
|
|
* to build and tear it down as fast as possible.
|
|
|
|
*/
|
|
|
|
typedef struct _tap_packet_t {
|
|
|
|
int tap_id;
|
|
|
|
packet_info *pinfo;
|
2004-12-30 02:10:24 +00:00
|
|
|
const void *tap_specific_data;
|
2002-09-04 09:40:29 +00:00
|
|
|
} tap_packet_t;
|
|
|
|
|
2005-04-01 20:55:33 +00:00
|
|
|
#define TAP_PACKET_QUEUE_LEN 100
|
|
|
|
static tap_packet_t tap_packet_array[TAP_PACKET_QUEUE_LEN];
|
|
|
|
static guint tap_packet_index;
|
2002-09-04 09:40:29 +00:00
|
|
|
|
|
|
|
typedef struct _tap_listener_t {
|
|
|
|
struct _tap_listener_t *next;
|
|
|
|
int tap_id;
|
2009-06-05 22:42:47 +00:00
|
|
|
gboolean needs_redraw;
|
|
|
|
guint flags;
|
2002-09-04 09:40:29 +00:00
|
|
|
dfilter_t *code;
|
|
|
|
void *tapdata;
|
2002-10-31 22:16:01 +00:00
|
|
|
tap_reset_cb reset;
|
|
|
|
tap_packet_cb packet;
|
|
|
|
tap_draw_cb draw;
|
2002-09-04 09:40:29 +00:00
|
|
|
} tap_listener_t;
|
2002-09-05 06:46:38 +00:00
|
|
|
static volatile tap_listener_t *tap_listener_queue=NULL;
|
2002-09-04 09:40:29 +00:00
|
|
|
|
|
|
|
/* **********************************************************************
|
|
|
|
* Init routine only called from epan at application startup
|
|
|
|
* ********************************************************************** */
|
2006-05-21 05:12:17 +00:00
|
|
|
/* This function is called once when wireshark starts up and is used
|
2002-09-04 09:40:29 +00:00
|
|
|
to init any data structures we may need later.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
tap_init(void)
|
|
|
|
{
|
2005-04-01 20:55:33 +00:00
|
|
|
tap_packet_index=0;
|
2002-09-04 09:40:29 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* **********************************************************************
|
|
|
|
* Functions called from dissector when made tappable
|
|
|
|
* ********************************************************************** */
|
|
|
|
/* the following two functions are used from dissectors to
|
2011-03-31 14:30:38 +00:00
|
|
|
1. register the ability to tap packets from this subdissector
|
|
|
|
2. push packets encountered by the subdissector to anyone tapping
|
2002-09-04 09:40:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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
|
2010-08-03 16:06:48 +00:00
|
|
|
tap_packet(unsigned int *tap_id,...
|
2002-09-04 09:40:29 +00:00
|
|
|
call so that the tap subsystem knows to which tap point this tapped
|
|
|
|
packet is associated.
|
2011-03-31 14:30:38 +00:00
|
|
|
*/
|
2002-09-04 09:40:29 +00:00
|
|
|
int
|
2005-07-21 17:21:48 +00:00
|
|
|
register_tap(const char *name)
|
2002-09-04 09:40:29 +00:00
|
|
|
{
|
|
|
|
tap_dissector_t *td, *tdl;
|
2008-08-21 06:28:16 +00:00
|
|
|
int i, tap_id;
|
|
|
|
|
|
|
|
if(tap_dissector_list){
|
|
|
|
tap_id=find_tap_id(name);
|
|
|
|
if (tap_id)
|
|
|
|
return tap_id;
|
|
|
|
}
|
2002-09-04 09:40:29 +00:00
|
|
|
|
2002-10-14 19:45:08 +00:00
|
|
|
td=g_malloc(sizeof(tap_dissector_t));
|
2002-09-04 09:40:29 +00:00
|
|
|
td->next=NULL;
|
2002-10-14 19:45:08 +00:00
|
|
|
td->name = g_strdup(name);
|
2002-09-04 09:40:29 +00:00
|
|
|
|
|
|
|
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
|
2002-11-28 20:28:30 +00:00
|
|
|
to tap_queue_packet().
|
2002-09-04 09:40:29 +00:00
|
|
|
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.
|
2011-03-31 14:30:38 +00:00
|
|
|
The third argument is specific to each tap point or NULL if no additional
|
2002-09-04 09:40:29 +00:00
|
|
|
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.
|
2011-03-31 14:30:38 +00:00
|
|
|
|
2002-09-04 09:40:29 +00:00
|
|
|
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.
|
2011-03-31 14:30:38 +00:00
|
|
|
|
|
|
|
The tap reader is responsible to know how to parse any structure pointed
|
2002-09-04 09:40:29 +00:00
|
|
|
to by the tap specific data pointer.
|
|
|
|
*/
|
2011-03-31 14:30:38 +00:00
|
|
|
void
|
2004-12-30 02:10:24 +00:00
|
|
|
tap_queue_packet(int tap_id, packet_info *pinfo, const void *tap_specific_data)
|
2002-09-04 09:40:29 +00:00
|
|
|
{
|
|
|
|
tap_packet_t *tpt;
|
|
|
|
|
|
|
|
if(!tapping_is_active){
|
|
|
|
return;
|
|
|
|
}
|
2006-12-11 02:58:38 +00:00
|
|
|
/*
|
|
|
|
* XXX - should we allocate this with an ep_allocator,
|
|
|
|
* rather than having a fixed maximum number of entries?
|
|
|
|
*/
|
|
|
|
if(tap_packet_index >= TAP_PACKET_QUEUE_LEN){
|
|
|
|
g_warning("Too many taps queued");
|
|
|
|
return;
|
|
|
|
}
|
2002-09-04 09:40:29 +00:00
|
|
|
|
2005-04-01 20:55:33 +00:00
|
|
|
tpt=&tap_packet_array[tap_packet_index];
|
2002-09-04 09:40:29 +00:00
|
|
|
tpt->tap_id=tap_id;
|
|
|
|
tpt->pinfo=pinfo;
|
|
|
|
tpt->tap_specific_data=tap_specific_data;
|
2005-04-01 20:55:33 +00:00
|
|
|
tap_packet_index++;
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* **********************************************************************
|
|
|
|
* Functions used by file.c to drive the tap subsystem
|
|
|
|
* ********************************************************************** */
|
2009-10-02 19:55:43 +00:00
|
|
|
|
|
|
|
void tap_build_interesting (epan_dissect_t *edt)
|
|
|
|
{
|
|
|
|
tap_listener_t *tl;
|
|
|
|
|
|
|
|
/* nothing to do, just return */
|
|
|
|
if(!tap_listener_queue){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-17 02:11:20 +00:00
|
|
|
/* 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.
|
2002-09-04 09:40:29 +00:00
|
|
|
*/
|
|
|
|
void
|
2002-10-17 02:11:20 +00:00
|
|
|
tap_queue_init(epan_dissect_t *edt)
|
2002-09-04 09:40:29 +00:00
|
|
|
{
|
2002-10-17 02:11:20 +00:00
|
|
|
/* nothing to do, just return */
|
|
|
|
if(!tap_listener_queue){
|
2002-09-04 09:40:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-10-17 02:11:20 +00:00
|
|
|
tapping_is_active=TRUE;
|
2002-09-04 09:40:29 +00:00
|
|
|
|
2005-04-01 20:55:33 +00:00
|
|
|
tap_packet_index=0;
|
2002-09-04 09:40:29 +00:00
|
|
|
|
2009-10-02 19:55:43 +00:00
|
|
|
tap_build_interesting (edt);
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this function is called after a packet has been fully dissected to push the tapped
|
|
|
|
data to all extensions that has callbacks registered.
|
|
|
|
*/
|
2011-03-31 14:30:38 +00:00
|
|
|
void
|
2002-10-17 02:11:20 +00:00
|
|
|
tap_push_tapped_queue(epan_dissect_t *edt)
|
2002-09-04 09:40:29 +00:00
|
|
|
{
|
|
|
|
tap_packet_t *tp;
|
|
|
|
tap_listener_t *tl;
|
2005-04-01 20:55:33 +00:00
|
|
|
guint i;
|
2002-09-14 07:42:52 +00:00
|
|
|
|
2002-10-17 02:11:20 +00:00
|
|
|
/* nothing to do, just return */
|
|
|
|
if(!tapping_is_active){
|
|
|
|
return;
|
2002-09-14 07:42:52 +00:00
|
|
|
}
|
|
|
|
|
2002-10-17 02:11:20 +00:00
|
|
|
tapping_is_active=FALSE;
|
|
|
|
|
|
|
|
/* nothing to do, just return */
|
2005-04-01 20:55:33 +00:00
|
|
|
if(!tap_packet_index){
|
2002-10-17 02:11:20 +00:00
|
|
|
return;
|
2005-04-01 20:55:33 +00:00
|
|
|
}
|
2002-09-14 07:42:52 +00:00
|
|
|
|
|
|
|
/* loop over all tap listeners and call the listener callback
|
|
|
|
for all packets that match the filter. */
|
2005-04-01 20:55:33 +00:00
|
|
|
for(i=0;i<tap_packet_index;i++){
|
2002-09-05 06:46:38 +00:00
|
|
|
for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){
|
2005-04-01 20:55:33 +00:00
|
|
|
tp=&tap_packet_array[i];
|
2002-09-04 09:40:29 +00:00
|
|
|
if(tp->tap_id==tl->tap_id){
|
2009-06-05 22:42:47 +00:00
|
|
|
gboolean passed=TRUE;
|
2002-09-04 09:40:29 +00:00
|
|
|
if(tl->code){
|
|
|
|
passed=dfilter_apply_edt(tl->code, edt);
|
|
|
|
}
|
|
|
|
if(passed && tl->packet){
|
2002-10-23 23:12:38 +00:00
|
|
|
tl->needs_redraw|=tl->packet(tl->tapdata, tp->pinfo, edt, tp->tap_specific_data);
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-07 13:12:39 +00:00
|
|
|
|
|
|
|
/* This function can be used by a dissector to fetch any tapped data before
|
|
|
|
* returning.
|
|
|
|
* This can be useful if one wants to extract the data inside dissector BEFORE
|
2011-03-31 14:30:38 +00:00
|
|
|
* it exists as an alternative to the callbacks that are all called AFTER the
|
2005-12-07 13:12:39 +00:00
|
|
|
* dissection has completed.
|
|
|
|
*
|
|
|
|
* Example: SMB2 uses this mechanism to extract the data tapped from NTLMSSP
|
|
|
|
* containing the account and domain names before exiting.
|
|
|
|
* Note that the SMB2 tap listener specifies all three callbacks as NULL.
|
|
|
|
*
|
|
|
|
* Beware: when using this mechanism to extract the tapped data you can not
|
|
|
|
* use "filters" and should specify the "filter" as NULL when registering
|
|
|
|
* the tap listener.
|
|
|
|
*/
|
2011-03-31 14:30:38 +00:00
|
|
|
const void *
|
2005-12-07 13:12:39 +00:00
|
|
|
fetch_tapped_data(int tap_id, int idx)
|
|
|
|
{
|
|
|
|
tap_packet_t *tp;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* nothing to do, just return */
|
|
|
|
if(!tapping_is_active){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nothing to do, just return */
|
|
|
|
if(!tap_packet_index){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop over all tapped packets and return the one with index idx */
|
|
|
|
for(i=0;i<tap_packet_index;i++){
|
|
|
|
tp=&tap_packet_array[i];
|
|
|
|
if(tp->tap_id==tap_id){
|
|
|
|
if(!idx--){
|
|
|
|
return tp->tap_specific_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-04 09:40:29 +00:00
|
|
|
/* 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;
|
|
|
|
|
2002-09-05 06:46:38 +00:00
|
|
|
for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){
|
2002-09-04 09:40:29 +00:00
|
|
|
if(tl->reset){
|
|
|
|
tl->reset(tl->tapdata);
|
|
|
|
}
|
2009-06-05 22:42:47 +00:00
|
|
|
tl->needs_redraw=TRUE;
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
2002-09-05 06:46:38 +00:00
|
|
|
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
|
|
|
|
2002-09-05 06:46:38 +00:00
|
|
|
|
2002-09-04 09:40:29 +00:00
|
|
|
/* 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.
|
2011-03-31 14:30:38 +00:00
|
|
|
It 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
|
2002-09-04 09:40:29 +00:00
|
|
|
changed or not.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
draw_tap_listeners(gboolean draw_all)
|
|
|
|
{
|
|
|
|
tap_listener_t *tl;
|
|
|
|
|
2002-09-05 06:46:38 +00:00
|
|
|
for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){
|
2002-09-04 09:40:29 +00:00
|
|
|
if(tl->needs_redraw || draw_all){
|
|
|
|
if(tl->draw){
|
|
|
|
tl->draw(tl->tapdata);
|
|
|
|
}
|
|
|
|
}
|
2009-06-05 22:42:47 +00:00
|
|
|
tl->needs_redraw=FALSE;
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* **********************************************************************
|
2002-10-17 02:11:20 +00:00
|
|
|
* Functions used by tap to
|
2011-03-31 14:30:38 +00:00
|
|
|
* 1. register that a really simple extension is available for use by
|
|
|
|
* Wireshark.
|
|
|
|
* 2. start tapping from a subdissector
|
|
|
|
* 3. close an already open tap
|
2002-09-04 09:40:29 +00:00
|
|
|
* ********************************************************************** */
|
|
|
|
/* this function will return the tap_id for the specific protocol tap
|
|
|
|
or 0 if no such tap was found.
|
|
|
|
*/
|
2011-03-31 14:30:38 +00:00
|
|
|
int
|
2005-07-23 11:41:25 +00:00
|
|
|
find_tap_id(const char *name)
|
2002-09-04 09:40:29 +00:00
|
|
|
{
|
|
|
|
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 :
|
2003-04-23 08:20:06 +00:00
|
|
|
* NULL: ok.
|
|
|
|
* non-NULL: error, return value points to GString containing error
|
|
|
|
* message.
|
|
|
|
*/
|
|
|
|
GString *
|
2009-06-05 22:42:47 +00:00
|
|
|
register_tap_listener(const char *tapname, void *tapdata, const char *fstring,
|
|
|
|
guint flags, tap_reset_cb reset, tap_packet_cb packet, tap_draw_cb draw)
|
2002-09-04 09:40:29 +00:00
|
|
|
{
|
|
|
|
tap_listener_t *tl;
|
|
|
|
int tap_id;
|
2003-04-23 08:20:06 +00:00
|
|
|
GString *error_string;
|
2002-09-04 09:40:29 +00:00
|
|
|
|
|
|
|
tap_id=find_tap_id(tapname);
|
|
|
|
if(!tap_id){
|
2003-04-23 08:20:06 +00:00
|
|
|
error_string = g_string_new("");
|
2008-05-05 20:38:27 +00:00
|
|
|
g_string_printf(error_string, "Tap %s not found", tapname);
|
2003-04-23 08:20:06 +00:00
|
|
|
return error_string;
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tl=g_malloc(sizeof(tap_listener_t));
|
|
|
|
tl->code=NULL;
|
2009-06-05 22:42:47 +00:00
|
|
|
tl->needs_redraw=TRUE;
|
|
|
|
tl->flags=flags;
|
2002-09-04 09:40:29 +00:00
|
|
|
if(fstring){
|
2003-04-23 08:20:06 +00:00
|
|
|
if(!dfilter_compile(fstring, &tl->code)){
|
|
|
|
error_string = g_string_new("");
|
2008-05-05 20:38:27 +00:00
|
|
|
g_string_printf(error_string,
|
2003-04-23 08:20:06 +00:00
|
|
|
"Filter \"%s\" is invalid - %s",
|
|
|
|
fstring, dfilter_error_msg);
|
2002-09-04 09:40:29 +00:00
|
|
|
g_free(tl);
|
2003-04-23 08:20:06 +00:00
|
|
|
return error_string;
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tl->tap_id=tap_id;
|
|
|
|
tl->tapdata=tapdata;
|
|
|
|
tl->reset=reset;
|
|
|
|
tl->packet=packet;
|
|
|
|
tl->draw=draw;
|
2002-09-05 06:46:38 +00:00
|
|
|
tl->next=(tap_listener_t *)tap_listener_queue;
|
2002-09-04 09:40:29 +00:00
|
|
|
|
|
|
|
tap_listener_queue=tl;
|
|
|
|
|
2003-04-23 08:20:06 +00:00
|
|
|
return NULL;
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
|
|
|
|
2008-02-17 00:35:55 +00:00
|
|
|
/* this function sets a new dfilter to a tap listener
|
|
|
|
*/
|
|
|
|
GString *
|
|
|
|
set_tap_dfilter(void *tapdata, const char *fstring)
|
|
|
|
{
|
|
|
|
tap_listener_t *tl=NULL,*tl2;
|
|
|
|
GString *error_string;
|
|
|
|
|
|
|
|
if(!tap_listener_queue){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tap_listener_queue->tapdata==tapdata){
|
|
|
|
tl=(tap_listener_t *)tap_listener_queue;
|
|
|
|
} else {
|
|
|
|
for(tl2=(tap_listener_t *)tap_listener_queue;tl2->next;tl2=tl2->next){
|
|
|
|
if(tl2->next->tapdata==tapdata){
|
|
|
|
tl=tl2->next;
|
|
|
|
break;
|
|
|
|
}
|
2011-03-31 14:30:38 +00:00
|
|
|
|
2008-02-17 00:35:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tl){
|
|
|
|
if(tl->code){
|
|
|
|
dfilter_free(tl->code);
|
|
|
|
tl->code=NULL;
|
|
|
|
}
|
2009-06-05 22:42:47 +00:00
|
|
|
tl->needs_redraw=TRUE;
|
2008-02-17 00:35:55 +00:00
|
|
|
if(fstring){
|
|
|
|
if(!dfilter_compile(fstring, &tl->code)){
|
|
|
|
error_string = g_string_new("");
|
2008-05-05 20:38:27 +00:00
|
|
|
g_string_printf(error_string,
|
2008-02-17 00:35:55 +00:00
|
|
|
"Filter \"%s\" is invalid - %s",
|
|
|
|
fstring, dfilter_error_msg);
|
|
|
|
return error_string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-04 09:40:29 +00:00
|
|
|
/* this function removes a tap listener
|
2002-09-05 06:46:38 +00:00
|
|
|
*/
|
2002-09-04 09:40:29 +00:00
|
|
|
void
|
|
|
|
remove_tap_listener(void *tapdata)
|
|
|
|
{
|
|
|
|
tap_listener_t *tl=NULL,*tl2;
|
|
|
|
|
|
|
|
if(!tap_listener_queue){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tap_listener_queue->tapdata==tapdata){
|
2002-09-05 06:46:38 +00:00
|
|
|
tl=(tap_listener_t *)tap_listener_queue;
|
2002-09-04 09:40:29 +00:00
|
|
|
tap_listener_queue=tap_listener_queue->next;
|
|
|
|
} else {
|
2002-09-05 06:46:38 +00:00
|
|
|
for(tl2=(tap_listener_t *)tap_listener_queue;tl2->next;tl2=tl2->next){
|
2002-09-04 09:40:29 +00:00
|
|
|
if(tl2->next->tapdata==tapdata){
|
|
|
|
tl=tl2->next;
|
|
|
|
tl2->next=tl2->next->next;
|
|
|
|
break;
|
|
|
|
}
|
2011-03-31 14:30:38 +00:00
|
|
|
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-05 06:46:38 +00:00
|
|
|
if(tl){
|
|
|
|
if(tl->code){
|
|
|
|
dfilter_free(tl->code);
|
|
|
|
}
|
|
|
|
g_free(tl);
|
2002-09-04 09:40:29 +00:00
|
|
|
}
|
2002-09-05 06:46:38 +00:00
|
|
|
|
2002-09-04 09:40:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-31 09:53:21 +00:00
|
|
|
/*
|
|
|
|
* Return TRUE if we have tap listeners, FALSE otherwise.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
have_tap_listeners(void)
|
|
|
|
{
|
|
|
|
return tap_listener_queue != NULL;
|
|
|
|
}
|
2007-03-06 00:35:35 +00:00
|
|
|
|
|
|
|
/* Returns TRUE there is an active tap listener for the specified tap id. */
|
|
|
|
gboolean
|
|
|
|
have_tap_listener(int tap_id)
|
|
|
|
{
|
|
|
|
volatile tap_listener_t *tap_queue = tap_listener_queue;
|
|
|
|
|
|
|
|
while(tap_queue) {
|
|
|
|
if(tap_queue->tap_id == tap_id)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
tap_queue = tap_queue->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-06-05 22:42:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return TRUE if we have any tap listeners with filters, FALSE otherwise.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
have_filtering_tap_listeners(void)
|
|
|
|
{
|
|
|
|
tap_listener_t *tl;
|
|
|
|
|
|
|
|
for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){
|
|
|
|
if(tl->code)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the union of all the flags for all the tap listeners; that gives
|
|
|
|
* an indication of whether the protocol tree, or the columns, are
|
|
|
|
* required by any taps.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
union_of_tap_listener_flags(void)
|
|
|
|
{
|
|
|
|
tap_listener_t *tl;
|
|
|
|
guint flags = 0;
|
|
|
|
|
|
|
|
for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){
|
|
|
|
flags|=tl->flags;
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|