2003-09-02 22:47:59 +00:00
|
|
|
/* tap-rpcstat.c
|
|
|
|
* wspstat 2003 Jean-Michel FAYARD
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2003-09-02 22:47:59 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2003-09-02 22:47:59 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2010-09-23 06:08:19 +00:00
|
|
|
*
|
2003-09-02 22:47:59 +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.
|
2010-09-23 06:08:19 +00:00
|
|
|
*
|
2003-09-02 22:47:59 +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.
|
2010-09-23 06:08:19 +00:00
|
|
|
*
|
2003-09-02 22:47:59 +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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-09-02 22:47:59 +00:00
|
|
|
*/
|
|
|
|
|
2006-05-31 17:38:42 +00:00
|
|
|
/* This module provides WSP statistics to tshark.
|
|
|
|
* It is only used by tshark and not wireshark
|
2003-09-02 22:47:59 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-09-20 01:29:52 +00:00
|
|
|
#include "config.h"
|
2003-09-02 22:47:59 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "epan/packet_info.h"
|
2004-09-29 00:06:36 +00:00
|
|
|
#include <epan/tap.h>
|
2005-08-20 20:06:05 +00:00
|
|
|
#include <epan/stat_cmd_args.h>
|
2003-09-02 22:47:59 +00:00
|
|
|
#include "epan/value_string.h"
|
2004-07-18 18:06:47 +00:00
|
|
|
#include <epan/dissectors/packet-wsp.h>
|
2003-09-02 22:47:59 +00:00
|
|
|
|
|
|
|
/* used to keep track of the stats for a specific PDU type*/
|
|
|
|
typedef struct _wsp_pdu_t {
|
2005-06-26 19:56:52 +00:00
|
|
|
const gchar *type;
|
2003-09-02 22:47:59 +00:00
|
|
|
guint32 packets;
|
|
|
|
} wsp_pdu_t;
|
2011-03-23 20:00:13 +00:00
|
|
|
/* used to keep track of SRT statistics */
|
2003-09-02 22:47:59 +00:00
|
|
|
typedef struct _wsp_status_code_t {
|
2005-06-24 01:32:42 +00:00
|
|
|
const gchar *name;
|
2003-09-02 22:47:59 +00:00
|
|
|
guint32 packets;
|
|
|
|
} wsp_status_code_t;
|
|
|
|
/* used to keep track of the statictics for an entire program interface */
|
|
|
|
typedef struct _wsp_stats_t {
|
|
|
|
char *filter;
|
|
|
|
wsp_pdu_t *pdu_stats;
|
|
|
|
guint32 num_pdus;
|
|
|
|
GHashTable *hash;
|
|
|
|
} wspstat_t;
|
2010-09-23 06:08:19 +00:00
|
|
|
|
2003-09-02 22:47:59 +00:00
|
|
|
static void
|
2010-09-23 06:08:19 +00:00
|
|
|
wsp_reset_hash(gchar *key _U_ , wsp_status_code_t *data, gpointer ptr _U_ )
|
|
|
|
{
|
2003-09-02 22:47:59 +00:00
|
|
|
data->packets = 0;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
wsp_print_statuscode(gint *key, wsp_status_code_t *data, char* format)
|
|
|
|
{
|
|
|
|
if (data && (data->packets!=0))
|
|
|
|
printf(format, *key, data->packets ,data->name);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
wsp_free_hash_table( gpointer key, gpointer value, gpointer user_data _U_ )
|
|
|
|
{
|
|
|
|
g_free(key);
|
|
|
|
g_free(value);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
wspstat_reset(void *psp)
|
|
|
|
{
|
2013-03-07 19:52:33 +00:00
|
|
|
wspstat_t *sp=(wspstat_t *)psp;
|
2003-09-02 22:47:59 +00:00
|
|
|
guint32 i;
|
|
|
|
|
|
|
|
for(i=1;i<=sp->num_pdus;i++)
|
|
|
|
{
|
|
|
|
sp->pdu_stats[i].packets=0;
|
|
|
|
}
|
|
|
|
g_hash_table_foreach( sp->hash, (GHFunc)wsp_reset_hash, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This callback is invoked whenever the tap system has seen a packet
|
|
|
|
* we might be interested in.
|
|
|
|
* The function is to be used to only update internal state information
|
|
|
|
* in the *tapdata structure, and if there were state changes which requires
|
|
|
|
* the window to be redrawn, return 1 and (*draw) will be called sometime
|
|
|
|
* later.
|
|
|
|
*
|
|
|
|
* We didnt apply a filter when we registered so we will be called for
|
|
|
|
* ALL packets and not just the ones we are collecting stats for.
|
|
|
|
*
|
|
|
|
*/
|
2010-09-23 06:08:19 +00:00
|
|
|
static gint
|
2003-09-02 22:47:59 +00:00
|
|
|
pdut2index(gint pdut)
|
|
|
|
{
|
|
|
|
if (pdut<=0x09) return pdut;
|
|
|
|
if (pdut>=0x40){
|
|
|
|
if (pdut <= 0x44){
|
|
|
|
return pdut-54;
|
|
|
|
} else if (pdut==0x60||pdut==0x61){
|
|
|
|
return pdut-81;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static gint
|
|
|
|
index2pdut(gint pdut)
|
|
|
|
{
|
|
|
|
if (pdut<=0x09)
|
|
|
|
return pdut;
|
|
|
|
if (pdut<=14)
|
|
|
|
return pdut+54;
|
|
|
|
if (pdut<=16)
|
|
|
|
return pdut+81;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static int
|
2005-01-01 02:57:02 +00:00
|
|
|
wspstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
|
2003-09-02 22:47:59 +00:00
|
|
|
{
|
2013-03-07 19:52:33 +00:00
|
|
|
wspstat_t *sp=(wspstat_t *)psp;
|
|
|
|
const wsp_info_value_t *value=(const wsp_info_value_t *)pri;
|
2010-01-29 16:09:25 +00:00
|
|
|
gint idx = pdut2index(value->pdut);
|
2003-09-02 22:47:59 +00:00
|
|
|
int retour=0;
|
|
|
|
|
|
|
|
if (value->status_code != 0) {
|
2013-03-07 19:52:33 +00:00
|
|
|
gint *key=g_new(gint,1);
|
2003-09-02 22:47:59 +00:00
|
|
|
wsp_status_code_t *sc;
|
|
|
|
*key=value->status_code ;
|
2013-03-20 01:18:10 +00:00
|
|
|
sc = (wsp_status_code_t *)g_hash_table_lookup(
|
2010-09-23 06:08:19 +00:00
|
|
|
sp->hash,
|
2003-09-02 22:47:59 +00:00
|
|
|
key);
|
|
|
|
if (!sc) {
|
2013-03-07 19:52:33 +00:00
|
|
|
sc = g_new(wsp_status_code_t,1);
|
2003-09-02 22:47:59 +00:00
|
|
|
sc -> packets = 1;
|
|
|
|
sc -> name = NULL;
|
|
|
|
g_hash_table_insert(
|
|
|
|
sp->hash,
|
|
|
|
key,
|
|
|
|
sc);
|
|
|
|
} else {
|
|
|
|
sc->packets++;
|
|
|
|
}
|
|
|
|
retour=1;
|
|
|
|
}
|
|
|
|
|
2010-09-23 06:08:19 +00:00
|
|
|
|
2003-09-02 22:47:59 +00:00
|
|
|
|
2010-01-29 16:09:25 +00:00
|
|
|
if (idx!=0) {
|
|
|
|
sp->pdu_stats[ idx ].packets++;
|
2003-09-02 22:47:59 +00:00
|
|
|
retour = 1;
|
|
|
|
}
|
|
|
|
return retour;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-31 17:38:42 +00:00
|
|
|
/* This callback is used when tshark wants us to draw/update our
|
|
|
|
* data to the output device. Since this is tshark only output is
|
2003-09-02 22:47:59 +00:00
|
|
|
* stdout.
|
2006-05-31 17:38:42 +00:00
|
|
|
* TShark will only call this callback once, which is when tshark has
|
2003-09-02 22:47:59 +00:00
|
|
|
* finished reading all packets and exists.
|
2010-09-23 06:08:19 +00:00
|
|
|
* If used with wireshark this may be called any time, perhaps once every 3
|
2003-09-02 22:47:59 +00:00
|
|
|
* seconds or so.
|
|
|
|
* This function may even be called in parallell with (*reset) or (*draw)
|
|
|
|
* so make sure there are no races. The data in the rpcstat_t can thus change
|
|
|
|
* beneath us. Beware.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
wspstat_draw(void *psp)
|
|
|
|
{
|
2013-03-07 19:52:33 +00:00
|
|
|
wspstat_t *sp=(wspstat_t *)psp;
|
2003-09-02 22:47:59 +00:00
|
|
|
guint32 i;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
printf("===================================================================\n");
|
|
|
|
printf("WSP Statistics:\n");
|
|
|
|
printf("%-23s %9s || %-23s %9s\n","PDU Type", "Packets", "PDU Type", "Packets");
|
|
|
|
for(i=1; i<= ((sp->num_pdus+1)/2) ; i++)
|
|
|
|
{
|
|
|
|
guint32 ii=i+sp->num_pdus/2;
|
|
|
|
printf("%-23s %9d", sp->pdu_stats[i ].type, sp->pdu_stats[i ].packets);
|
|
|
|
printf(" || ");
|
|
|
|
if (ii< (sp->num_pdus) )
|
|
|
|
printf("%-23s %9d\n", sp->pdu_stats[ii].type, sp->pdu_stats[ii].packets);
|
2010-09-23 06:08:19 +00:00
|
|
|
else
|
2003-09-02 22:47:59 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
printf("\nStatus code in reply packets\n");
|
|
|
|
printf( "Status Code Packets Description\n");
|
2010-09-23 06:08:19 +00:00
|
|
|
g_hash_table_foreach( sp->hash, (GHFunc) wsp_print_statuscode,
|
2012-12-26 05:57:06 +00:00
|
|
|
(gpointer)" 0x%02X %9d %s\n" ) ;
|
2003-09-02 22:47:59 +00:00
|
|
|
printf("===================================================================\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* When called, this function will create a new instance of wspstat.
|
|
|
|
* program and version are whick onc-rpc program/version we want to
|
|
|
|
* collect statistics for.
|
2006-05-31 17:38:42 +00:00
|
|
|
* This function is called from tshark when it parses the -z wsp, arguments
|
2003-09-02 22:47:59 +00:00
|
|
|
* and it creates a new instance to store statistics in and registers this
|
|
|
|
* new instance for the wsp tap.
|
|
|
|
*/
|
|
|
|
static void
|
2013-08-14 01:18:58 +00:00
|
|
|
wspstat_init(const char *opt_arg, void* userdata _U_)
|
2003-09-02 22:47:59 +00:00
|
|
|
{
|
2010-11-03 18:28:35 +00:00
|
|
|
wspstat_t *sp;
|
|
|
|
const char *filter=NULL;
|
|
|
|
guint32 i;
|
|
|
|
GString *error_string;
|
|
|
|
wsp_status_code_t *sc;
|
|
|
|
const value_string *wsp_vals_status_p;
|
2010-09-23 06:08:19 +00:00
|
|
|
|
2013-08-14 01:18:58 +00:00
|
|
|
if (!strncmp (opt_arg, "wsp,stat," , 9)){
|
|
|
|
filter=opt_arg+9;
|
2003-09-02 22:47:59 +00:00
|
|
|
} else {
|
|
|
|
filter=NULL;
|
|
|
|
}
|
2010-09-23 06:08:19 +00:00
|
|
|
|
|
|
|
|
2013-03-07 19:52:33 +00:00
|
|
|
sp = g_new(wspstat_t,1);
|
2003-09-02 22:47:59 +00:00
|
|
|
sp->hash = g_hash_table_new( g_int_hash, g_int_equal);
|
2010-11-03 18:28:35 +00:00
|
|
|
wsp_vals_status_p = VALUE_STRING_EXT_VS_P(&wsp_vals_status_ext);
|
|
|
|
for (i=0 ; wsp_vals_status_p[i].strptr ; i++ )
|
2003-09-02 22:47:59 +00:00
|
|
|
{
|
|
|
|
gint *key;
|
2013-03-07 19:52:33 +00:00
|
|
|
sc=g_new(wsp_status_code_t,1);
|
|
|
|
key=g_new(gint,1);
|
2003-09-02 22:47:59 +00:00
|
|
|
sc->packets=0;
|
2010-11-03 18:28:35 +00:00
|
|
|
sc->name=wsp_vals_status_p[i].strptr;
|
|
|
|
*key=wsp_vals_status_p[i].value;
|
2003-09-02 22:47:59 +00:00
|
|
|
g_hash_table_insert(
|
|
|
|
sp->hash,
|
|
|
|
key,
|
|
|
|
sc);
|
|
|
|
}
|
|
|
|
sp->num_pdus = 16;
|
2013-03-07 19:52:33 +00:00
|
|
|
sp->pdu_stats=g_new(wsp_pdu_t,(sp->num_pdus+1));
|
2003-09-02 22:47:59 +00:00
|
|
|
if(filter){
|
2008-02-03 15:38:20 +00:00
|
|
|
sp->filter=g_strdup(filter);
|
2003-09-02 22:47:59 +00:00
|
|
|
} else {
|
|
|
|
sp->filter=NULL;
|
|
|
|
}
|
|
|
|
for (i=0;i<sp->num_pdus; i++)
|
|
|
|
{
|
|
|
|
sp->pdu_stats[i].packets=0;
|
2013-03-29 00:26:23 +00:00
|
|
|
sp->pdu_stats[i].type = try_val_to_str_ext( index2pdut( i ), &wsp_vals_pdu_type_ext) ;
|
2003-09-02 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
2010-09-23 06:08:19 +00:00
|
|
|
error_string = register_tap_listener(
|
2003-09-02 22:47:59 +00:00
|
|
|
"wsp",
|
|
|
|
sp,
|
|
|
|
filter,
|
2009-06-05 22:42:47 +00:00
|
|
|
0,
|
2003-09-02 22:47:59 +00:00
|
|
|
wspstat_reset,
|
|
|
|
wspstat_packet,
|
|
|
|
wspstat_draw);
|
|
|
|
if (error_string){
|
|
|
|
/* error, we failed to attach to the tap. clean up */
|
|
|
|
g_free(sp->pdu_stats);
|
|
|
|
g_free(sp->filter);
|
|
|
|
g_free(sp);
|
|
|
|
g_hash_table_foreach( sp->hash, (GHFunc) wsp_free_hash_table, NULL ) ;
|
|
|
|
g_hash_table_destroy( sp->hash );
|
2006-05-31 17:38:42 +00:00
|
|
|
fprintf(stderr, "tshark: Couldn't register wsp,stat tap: %s\n",
|
2003-09-02 22:47:59 +00:00
|
|
|
error_string->str);
|
|
|
|
g_string_free(error_string, TRUE);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2010-09-23 06:08:19 +00:00
|
|
|
void
|
2003-09-02 22:47:59 +00:00
|
|
|
register_tap_listener_wspstat(void)
|
|
|
|
{
|
2006-02-11 13:05:24 +00:00
|
|
|
register_stat_cmd_arg("wsp,stat,", wspstat_init,NULL);
|
2003-09-02 22:47:59 +00:00
|
|
|
}
|