2005-02-20 05:39:24 +00:00
|
|
|
/* pinfo_stats_tree.c
|
2005-02-16 14:26:27 +00:00
|
|
|
* Stats tree for ethernet frames
|
|
|
|
*
|
2008-08-05 21:03:46 +00:00
|
|
|
* (c) 2005, Luis E. G. Ontanon <luis@ontanon.org>
|
2005-02-16 14:26:27 +00:00
|
|
|
*
|
2005-02-20 05:39:24 +00:00
|
|
|
* $Id$
|
2005-02-16 14:26:27 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2005-02-16 14:26:27 +00:00
|
|
|
* 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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-02-16 14:26:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <epan/stats_tree.h>
|
2012-07-07 08:15:41 +00:00
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <epan/uat.h>
|
|
|
|
#include <epan/uat-int.h>
|
2013-06-17 21:54:21 +00:00
|
|
|
#include <epan/to_str.h>
|
2005-02-16 14:26:27 +00:00
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
#include "pinfo_stats_tree.h"
|
|
|
|
|
2012-07-07 08:15:41 +00:00
|
|
|
/*-------------------------------------
|
|
|
|
* UAT for Packet Lengths
|
|
|
|
*-------------------------------------
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
range_t *packet_range;
|
|
|
|
} uat_plen_record_t;
|
|
|
|
|
|
|
|
static range_t default_range[10] = {
|
|
|
|
{1, {{0, 19}}},
|
|
|
|
{1, {{20, 39}}},
|
|
|
|
{1, {{40, 79}}},
|
|
|
|
{1, {{80, 159}}},
|
|
|
|
{1, {{160, 319}}},
|
|
|
|
{1, {{320, 639}}},
|
|
|
|
{1, {{640, 1279}}},
|
|
|
|
{1, {{1280, 2559}}},
|
|
|
|
{1, {{2560, 5119}}},
|
|
|
|
{1, {{5120, 0xFFFFFFFF}}}
|
|
|
|
};
|
|
|
|
static uat_plen_record_t *uat_plen_records = NULL;
|
|
|
|
static uat_t * plen_uat = NULL;
|
|
|
|
static guint num_plen_uat = 0;
|
|
|
|
|
|
|
|
static void* uat_plen_record_copy_cb(void* n, const void* o, size_t siz _U_) {
|
2013-03-20 01:18:10 +00:00
|
|
|
const uat_plen_record_t *r = (const uat_plen_record_t *)o;
|
|
|
|
uat_plen_record_t *rn = (uat_plen_record_t *)n;
|
2012-07-07 08:15:41 +00:00
|
|
|
|
|
|
|
if (r->packet_range)
|
|
|
|
rn->packet_range = range_copy(r->packet_range);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-10-18 21:17:01 +00:00
|
|
|
static void
|
|
|
|
uat_plen_record_update_cb(void *r, const char **err)
|
|
|
|
{
|
|
|
|
uat_plen_record_t *rec = (uat_plen_record_t*)r;
|
|
|
|
if (rec->packet_range->nranges < 1) {
|
2013-10-25 22:14:25 +00:00
|
|
|
*err = g_strdup("Invalid range string");
|
2013-10-18 21:17:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*err = NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-07 08:15:41 +00:00
|
|
|
static void uat_plen_record_free_cb(void*r) {
|
2013-11-29 22:47:59 +00:00
|
|
|
uat_plen_record_t* record = (uat_plen_record_t*)r;
|
2012-07-07 08:15:41 +00:00
|
|
|
|
|
|
|
if (record->packet_range)
|
|
|
|
g_free(record->packet_range);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uat_plen_record_post_update_cb(void) {
|
|
|
|
guint i, num_default;
|
|
|
|
uat_plen_record_t rec;
|
|
|
|
|
|
|
|
/* If there are no records, create default list */
|
|
|
|
if (num_plen_uat == 0) {
|
|
|
|
num_default = sizeof(default_range)/sizeof(range_t);
|
|
|
|
|
|
|
|
/* default values for packet lengths */
|
|
|
|
for (i = 0; i < num_default; i++)
|
|
|
|
{
|
|
|
|
rec.packet_range = &default_range[i];
|
2013-04-22 02:10:49 +00:00
|
|
|
uat_add_record(plen_uat, &rec, TRUE);
|
2012-07-07 08:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UAT_RANGE_CB_DEF(uat_plen_records, packet_range, uat_plen_record_t)
|
|
|
|
|
2005-02-24 22:04:34 +00:00
|
|
|
/* ip host stats_tree -- basic test */
|
|
|
|
static int st_node_ip = -1;
|
2013-11-29 22:47:59 +00:00
|
|
|
static const gchar* st_str_ip = "IP Statistics/IP Addresses";
|
2005-02-24 22:04:34 +00:00
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static void ip_hosts_stats_tree_init(stats_tree* st) {
|
2009-09-06 14:25:47 +00:00
|
|
|
st_node_ip = stats_tree_create_node(st, st_str_ip, 0, TRUE);
|
2005-02-16 14:26:27 +00:00
|
|
|
}
|
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static int ip_hosts_stats_tree_packet(stats_tree *st , packet_info *pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
|
2007-03-28 21:55:11 +00:00
|
|
|
tick_stat_node(st, st_str_ip, 0, FALSE);
|
2009-09-06 14:25:47 +00:00
|
|
|
tick_stat_node(st, ep_address_to_str(&pinfo->net_src), st_node_ip, FALSE);
|
|
|
|
tick_stat_node(st, ep_address_to_str(&pinfo->net_dst), st_node_ip, FALSE);
|
|
|
|
|
2005-02-25 05:15:18 +00:00
|
|
|
return 1;
|
2005-02-24 22:04:34 +00:00
|
|
|
}
|
|
|
|
|
2013-11-29 22:47:59 +00:00
|
|
|
/* ip host stats_tree -- separate source and dest, test stats_tree flags */
|
|
|
|
static int st_node_ip_src = -1;
|
|
|
|
static int st_node_ip_dst = -1;
|
|
|
|
static const gchar* st_str_ip_srcdst = "IP Statistics/Source and Dest IP Addresses";
|
|
|
|
static const gchar* st_str_ip_src = "Source IP Addresses";
|
|
|
|
static const gchar* st_str_ip_dst = "Destination IP Addresses";
|
|
|
|
|
|
|
|
static void ip_srcdst_stats_tree_init(stats_tree* st) {
|
|
|
|
/* create one tree branch for source */
|
|
|
|
st_node_ip_src = stats_tree_create_node(st, st_str_ip_src, 0, TRUE);
|
|
|
|
/* set flag so this branch will always be sorted to top of tree */
|
|
|
|
stat_node_set_flags(st, st_str_ip_src, 0, FALSE, ST_FLG_SORT_TOP);
|
|
|
|
/* creat another top level node for destination branch */
|
|
|
|
st_node_ip_dst = stats_tree_create_node(st, st_str_ip_dst, 0, TRUE);
|
|
|
|
/* set flag so this branch will not be expanded by default */
|
|
|
|
stat_node_set_flags(st, st_str_ip_dst, 0, FALSE, ST_FLG_DEF_NOEXPAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_srcdst_stats_tree_packet(stats_tree *st , packet_info *pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
|
|
|
|
/* update source branch */
|
|
|
|
tick_stat_node(st, st_str_ip_src, 0, FALSE);
|
|
|
|
tick_stat_node(st, ep_address_to_str(&pinfo->net_src), st_node_ip_src, FALSE);
|
|
|
|
/* update destination branch */
|
|
|
|
tick_stat_node(st, st_str_ip_dst, 0, FALSE);
|
|
|
|
tick_stat_node(st, ep_address_to_str(&pinfo->net_dst), st_node_ip_dst, FALSE);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-02-24 22:04:34 +00:00
|
|
|
/* packet type stats_tree -- test pivot node */
|
|
|
|
static int st_node_ptype = -1;
|
2013-11-29 22:47:59 +00:00
|
|
|
static const gchar* st_str_ptype = "IP Statistics/IP Protocol Types";
|
2005-02-24 22:04:34 +00:00
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static void ptype_stats_tree_init(stats_tree* st) {
|
2005-03-21 01:32:26 +00:00
|
|
|
st_node_ptype = stats_tree_create_pivot(st, st_str_ptype, 0);
|
2005-02-24 22:04:34 +00:00
|
|
|
}
|
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static int ptype_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
|
2005-02-24 22:04:34 +00:00
|
|
|
const gchar* ptype;
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2005-02-24 22:04:34 +00:00
|
|
|
ptype = port_type_to_str(pinfo->ptype);
|
|
|
|
|
2005-03-21 01:32:26 +00:00
|
|
|
stats_tree_tick_pivot(st,st_node_ptype,ptype);
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2005-02-25 05:15:18 +00:00
|
|
|
return 1;
|
2005-02-24 22:04:34 +00:00
|
|
|
}
|
|
|
|
|
2009-09-06 14:25:47 +00:00
|
|
|
/* packet length stats_tree -- test range node */
|
2005-02-24 22:04:34 +00:00
|
|
|
static int st_node_plen = -1;
|
2008-04-14 01:11:07 +00:00
|
|
|
static const gchar* st_str_plen = "Packet Lengths";
|
2005-02-24 22:04:34 +00:00
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static void plen_stats_tree_init(stats_tree* st) {
|
2012-07-07 08:15:41 +00:00
|
|
|
guint i;
|
2013-03-20 01:18:10 +00:00
|
|
|
char **str_range_array = (char **)ep_alloc(num_plen_uat*sizeof(char*));
|
2012-07-07 08:15:41 +00:00
|
|
|
|
|
|
|
/* Convert the ranges to strings for the stats tree API */
|
|
|
|
for (i = 0; i < num_plen_uat; i++) {
|
|
|
|
str_range_array[i] = range_convert_range(uat_plen_records[i].packet_range);
|
|
|
|
}
|
|
|
|
|
|
|
|
st_node_plen = stats_tree_create_range_node_string(st, st_str_plen, 0, num_plen_uat, str_range_array);
|
2005-02-16 14:26:27 +00:00
|
|
|
}
|
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static int plen_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
|
2007-03-28 21:55:11 +00:00
|
|
|
tick_stat_node(st, st_str_plen, 0, FALSE);
|
2013-11-29 22:47:59 +00:00
|
|
|
/* also add value for averages calculation. we call the notick version of */
|
|
|
|
/* avg_stat_node_add_value and call tick_stat_node separately. this allows */
|
|
|
|
/* compatiblity with older wireshark versions with no average support. */
|
|
|
|
avg_stat_node_add_value_notick(st, st_str_plen, 0, FALSE, pinfo->fd->pkt_len);
|
|
|
|
|
2005-03-21 01:32:26 +00:00
|
|
|
stats_tree_tick_range(st, st_str_plen, 0, pinfo->fd->pkt_len);
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2005-02-25 05:15:18 +00:00
|
|
|
return 1;
|
2005-02-24 22:04:34 +00:00
|
|
|
}
|
2005-02-16 14:26:27 +00:00
|
|
|
|
2006-04-27 22:13:29 +00:00
|
|
|
/* a tree example
|
2005-02-25 05:15:18 +00:00
|
|
|
- IP
|
|
|
|
- PROTO
|
|
|
|
- PORT
|
|
|
|
|
|
|
|
*/
|
|
|
|
static int st_node_dsts = -1;
|
2013-11-29 22:47:59 +00:00
|
|
|
static const gchar* st_str_dsts = "IP Statistics/IP Destinations";
|
2005-02-25 05:15:18 +00:00
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static void dsts_stats_tree_init(stats_tree* st) {
|
2009-09-06 14:25:47 +00:00
|
|
|
st_node_dsts = stats_tree_create_node(st, st_str_dsts, 0, TRUE);
|
2005-02-25 05:15:18 +00:00
|
|
|
}
|
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static int dsts_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
|
2008-07-11 21:13:39 +00:00
|
|
|
static gchar str[128];
|
2005-02-25 05:15:18 +00:00
|
|
|
int ip_dst_node;
|
2010-01-28 23:53:27 +00:00
|
|
|
int protocol_node;
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2007-03-28 21:55:11 +00:00
|
|
|
tick_stat_node(st, st_str_dsts, 0, FALSE);
|
2009-09-06 14:25:47 +00:00
|
|
|
|
|
|
|
ip_dst_node = tick_stat_node(st, ep_address_to_str(&pinfo->net_src), st_node_dsts, TRUE);
|
|
|
|
|
2010-01-28 23:53:27 +00:00
|
|
|
protocol_node = tick_stat_node(st,port_type_to_str(pinfo->ptype),ip_dst_node,TRUE);
|
2005-02-25 05:15:18 +00:00
|
|
|
|
2007-03-28 21:55:11 +00:00
|
|
|
g_snprintf(str, sizeof(str),"%u",pinfo->destport);
|
2010-01-28 23:53:27 +00:00
|
|
|
tick_stat_node(st,str,protocol_node,TRUE);
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2005-02-25 05:15:18 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-02-24 22:04:34 +00:00
|
|
|
/* register all pinfo trees */
|
2005-07-24 21:23:10 +00:00
|
|
|
void register_pinfo_stat_trees(void) {
|
2012-07-07 08:15:41 +00:00
|
|
|
module_t *stat_module;
|
|
|
|
|
|
|
|
static uat_field_t plen_uat_flds[] = {
|
|
|
|
UAT_FLD_RANGE(uat_plen_records, packet_range, "Packet Range", 0xFFFFFFFF, "Range of packet sizes to count"),
|
|
|
|
UAT_END_FIELDS
|
|
|
|
};
|
|
|
|
|
2012-07-15 16:24:35 +00:00
|
|
|
stats_tree_register_plugin("ip","ip_hosts",st_str_ip, 0, ip_hosts_stats_tree_packet, ip_hosts_stats_tree_init, NULL );
|
2013-11-29 22:47:59 +00:00
|
|
|
stats_tree_register_plugin("ip","ip_srcdst",st_str_ip_srcdst, 0, ip_srcdst_stats_tree_packet, ip_srcdst_stats_tree_init, NULL );
|
2012-07-15 16:24:35 +00:00
|
|
|
stats_tree_register_plugin("ip","ptype",st_str_ptype, 0, ptype_stats_tree_packet, ptype_stats_tree_init, NULL );
|
2009-06-05 22:42:47 +00:00
|
|
|
stats_tree_register_with_group("frame","plen",st_str_plen, 0, plen_stats_tree_packet, plen_stats_tree_init, NULL, REGISTER_STAT_GROUP_GENERIC );
|
2012-07-15 16:24:35 +00:00
|
|
|
stats_tree_register_plugin("ip","dests",st_str_dsts, 0, dsts_stats_tree_packet, dsts_stats_tree_init, NULL );
|
2012-07-07 08:15:41 +00:00
|
|
|
|
|
|
|
stat_module = prefs_register_stat("stat_tree", "Stats Tree", "Stats Tree", NULL);
|
|
|
|
|
|
|
|
plen_uat = uat_new("Packet Lengths",
|
|
|
|
sizeof(uat_plen_record_t), /* record size */
|
|
|
|
"packet_lengths", /* filename */
|
|
|
|
TRUE, /* from_profile */
|
2013-03-20 01:18:10 +00:00
|
|
|
(void**) &uat_plen_records, /* data_ptr */
|
2012-07-07 08:15:41 +00:00
|
|
|
&num_plen_uat, /* numitems_ptr */
|
UATs could be put into "categories". The categories were defined only
implicitly by the #define name and string they were defined to; not all
UATs neatly fit into any of the categories, so some of them were put
into categories that weren't obviously correct for them, and one - the
display filter macro UAT - wasn't put into any category at all (which
caused crashes when editing them, as the GUI code that handled UAT
changes from a dialog assumed the category field was non-null).
The category was, in practice, used only to decide, in the
aforementioned GUI code, whether the packet summary pane needed to be
updated or not. It also offered no option of "don't update the packet
summary pane *and* don't redissect anything", which is what would be
appropriate for the display filter macro UAT.
Replace the category with a set of fields indicating what the UAT
affects; we currently offer "dissection", which applies to most UATs
(any UAT in libwireshark presumably affects dissection at a minimum) and
"the set of named fields that exist". Changing any UAT that affects
dissection requires a redissection; changing any UAT that affects the
set of named fields that exist requires a redissection *and* rebuilding
the packet summary pane.
Perhaps we also need "filtering", so that if you change a display filter
macro, we re-filter, in case the display is currently filtered with a
display filter that uses a macro that changed.
svn path=/trunk/; revision=43603
2012-07-08 01:00:46 +00:00
|
|
|
0, /* not a dissector, so affects neither dissection nor fields */
|
2012-07-07 08:15:41 +00:00
|
|
|
NULL, /* help */
|
|
|
|
uat_plen_record_copy_cb, /* copy callback */
|
2013-10-18 21:17:01 +00:00
|
|
|
uat_plen_record_update_cb, /* update callback */
|
2012-07-07 08:15:41 +00:00
|
|
|
uat_plen_record_free_cb, /* free callback */
|
|
|
|
uat_plen_record_post_update_cb, /* post update callback */
|
|
|
|
plen_uat_flds); /* UAT field definitions */
|
|
|
|
|
|
|
|
prefs_register_uat_preference(stat_module, "packet_lengths",
|
|
|
|
"Packet Lengths", "Delineated packet sizes to count", plen_uat);
|
2012-07-16 18:07:08 +00:00
|
|
|
}
|