From f2b8504740f3fd145a5504682c3788947e151606 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Sat, 19 Dec 2015 10:11:40 -0500 Subject: Don't limit capture packet counts to a fixed set of protocols. Kept backwards compatibility with GTK+ capture info dialog by keeping the protocols tracked hardcoded, but Qt should have more freedom. Change-Id: I497be71ec761d53f312e14858daa7152d01b8c72 Reviewed-on: https://code.wireshark.org/review/12724 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/capture_dissectors.c | 27 +++++++++++++++++++++++++++ epan/capture_dissectors.h | 4 ++++ epan/dissectors/packet-arcnet.c | 7 ++++++- epan/dissectors/packet-arp.c | 2 +- epan/dissectors/packet-gre.c | 2 +- epan/dissectors/packet-i2c.c | 11 +++++++++-- epan/dissectors/packet-icmp.c | 2 +- epan/dissectors/packet-icmpv6.c | 2 +- epan/dissectors/packet-ip.c | 1 + epan/dissectors/packet-ipv6.c | 2 ++ epan/dissectors/packet-ipx.c | 2 +- epan/dissectors/packet-netbios.c | 3 ++- epan/dissectors/packet-ospf.c | 2 +- epan/dissectors/packet-sctp.c | 2 +- epan/dissectors/packet-tcp.c | 2 +- epan/dissectors/packet-udp.c | 2 +- epan/dissectors/packet-vines.c | 5 ++++- epan/packet.h | 27 +-------------------------- 18 files changed, 65 insertions(+), 40 deletions(-) (limited to 'epan') diff --git a/epan/capture_dissectors.c b/epan/capture_dissectors.c index a68d76f4cb..1692533682 100644 --- a/epan/capture_dissectors.c +++ b/epan/capture_dissectors.c @@ -39,6 +39,11 @@ struct capture_dissector_handle protocol_t* protocol; }; +typedef struct capture_dissector_count +{ + guint32 count; +} capture_dissector_count_t; + static GHashTable *capture_dissector_tables = NULL; static void @@ -116,6 +121,28 @@ gboolean try_capture_dissector(const char* name, const guint32 pattern, const gu return handle->dissector(pd, offset, len, cpinfo, pseudo_header); } +guint32 capture_dissector_get_count(packet_counts* counts, const int proto) +{ + capture_dissector_count_t* hash_count = (capture_dissector_count_t*)g_hash_table_lookup(counts->counts_hash, GUINT_TO_POINTER(proto)); + if (hash_count == NULL) + return 0; + + return hash_count->count; +} + +void capture_dissector_increment_count(capture_packet_info_t *cpinfo, const int proto) +{ + /* See if we already have a counter for the protocol */ + capture_dissector_count_t* hash_count = (capture_dissector_count_t*)g_hash_table_lookup(cpinfo->counts, GUINT_TO_POINTER(proto)); + if (hash_count == NULL) + { + hash_count = g_new0(capture_dissector_count_t, 1); + g_hash_table_insert(cpinfo->counts, GUINT_TO_POINTER(proto), (gpointer)hash_count); + } + + hash_count->count++; +} + /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * diff --git a/epan/capture_dissectors.h b/epan/capture_dissectors.h index 8d353d88f6..dd0486efdf 100644 --- a/epan/capture_dissectors.h +++ b/epan/capture_dissectors.h @@ -25,6 +25,7 @@ #include "ws_symbol_export.h" #include +#include #ifdef __cplusplus extern "C" { @@ -46,6 +47,9 @@ WS_DLL_PUBLIC void register_capture_dissector(const char* name, const guint32 pa WS_DLL_PUBLIC gboolean try_capture_dissector(const char* name, const guint32 pattern, const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header); +WS_DLL_PUBLIC guint32 capture_dissector_get_count(packet_counts* counts, const int proto); +WS_DLL_PUBLIC void capture_dissector_increment_count(capture_packet_info_t *cpinfo, const int proto); + extern void capture_dissector_init(void); extern void capture_dissector_cleanup(void); diff --git a/epan/dissectors/packet-arcnet.c b/epan/dissectors/packet-arcnet.c index ab10565bc2..3c60c40b62 100644 --- a/epan/dissectors/packet-arcnet.c +++ b/epan/dissectors/packet-arcnet.c @@ -54,6 +54,9 @@ static int arcnet_address_type = -1; static dissector_table_t arcnet_dissector_table; static dissector_handle_t data_handle; +/* Cache protocol for packet counting */ +static int proto_ipx = -1; + static int arcnet_str_len(const address* addr _U_) { return 5; @@ -143,7 +146,7 @@ capture_arcnet_common(const guchar *pd, int offset, int len, capture_packet_info return capture_arp(pd, offset + 1, len, cpinfo, pseudo_header); case ARCNET_PROTO_IPX: - cpinfo->counts->ipx++; + capture_dissector_increment_count(cpinfo, proto_ipx); break; default: @@ -408,6 +411,8 @@ proto_reg_handoff_arcnet (void) arcnet_linux_handle = create_dissector_handle (dissect_arcnet_linux, proto_arcnet); dissector_add_uint ("wtap_encap", WTAP_ENCAP_ARCNET_LINUX, arcnet_linux_handle); + proto_ipx = proto_get_id_by_filter_name("ipx"); + register_capture_dissector("wtap_encap", WTAP_ENCAP_ARCNET_LINUX, capture_arcnet, proto_arcnet); register_capture_dissector("wtap_encap", WTAP_ENCAP_ARCNET, capture_arcnet_has_exception, proto_arcnet); data_handle = find_dissector ("data"); diff --git a/epan/dissectors/packet-arp.c b/epan/dissectors/packet-arp.c index beff539f2f..d171f00a7a 100644 --- a/epan/dissectors/packet-arp.c +++ b/epan/dissectors/packet-arp.c @@ -1362,7 +1362,7 @@ dissect_ax25arp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data gboolean capture_arp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_) { - cpinfo->counts->arp++; + capture_dissector_increment_count(cpinfo, proto_arp); return TRUE; } diff --git a/epan/dissectors/packet-gre.c b/epan/dissectors/packet-gre.c index 7e17ea2ce8..03de868d18 100644 --- a/epan/dissectors/packet-gre.c +++ b/epan/dissectors/packet-gre.c @@ -314,7 +314,7 @@ dissect_gre_wccp2_redirect_header(tvbuff_t *tvb, int offset, proto_tree *tree) static gboolean capture_gre(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_) { - cpinfo->counts->gre++; + capture_dissector_increment_count(cpinfo, proto_gre); return TRUE; } diff --git a/epan/dissectors/packet-i2c.c b/epan/dissectors/packet-i2c.c index 78a1525298..5b5cc4a5d5 100644 --- a/epan/dissectors/packet-i2c.c +++ b/epan/dissectors/packet-i2c.c @@ -34,6 +34,9 @@ void proto_register_i2c(void); void proto_reg_handoff_i2c(void); static int proto_i2c = -1; +static int proto_i2c_event = -1; +static int proto_i2c_data = -1; + static int hf_i2c_bus = -1; static int hf_i2c_event = -1; @@ -88,9 +91,9 @@ static gboolean capture_i2c(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header) { if (pseudo_header->i2c.is_event) { - cpinfo->counts->i2c_event++; + capture_dissector_increment_count(cpinfo, proto_i2c_event); } else { - cpinfo->counts->i2c_data++; + capture_dissector_increment_count(cpinfo, proto_i2c_data); } return TRUE; @@ -245,6 +248,10 @@ proto_register_i2c(void) static decode_as_t i2c_da = {"i2c", "I2C Message", "i2c.message", 1, 0, &i2c_da_values, NULL, NULL, decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL}; + /* Placeholders for capture statistics */ + proto_i2c_event = proto_register_protocol("I2C Events", "I2C Events", "i2c_event"); + proto_i2c_data = proto_register_protocol("I2C Data", "I2C Data", "i2c_data"); + proto_i2c = proto_register_protocol("Inter-Integrated Circuit", "I2C", "i2c"); proto_register_field_array(proto_i2c, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); diff --git a/epan/dissectors/packet-icmp.c b/epan/dissectors/packet-icmp.c index ae31bbdde3..a858201f90 100644 --- a/epan/dissectors/packet-icmp.c +++ b/epan/dissectors/packet-icmp.c @@ -1167,7 +1167,7 @@ get_best_guess_mstimeofday(tvbuff_t * tvb, gint offset, guint32 comp_ts) static gboolean capture_icmp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_) { - cpinfo->counts->icmp++; + capture_dissector_increment_count(cpinfo, proto_icmp); return TRUE; } diff --git a/epan/dissectors/packet-icmpv6.c b/epan/dissectors/packet-icmpv6.c index ded2043bac..69b4e6cac7 100644 --- a/epan/dissectors/packet-icmpv6.c +++ b/epan/dissectors/packet-icmpv6.c @@ -3454,7 +3454,7 @@ dissect_mldrv2( tvbuff_t *tvb, guint32 offset, packet_info *pinfo _U_, proto_tre static gboolean capture_icmpv6(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_) { - cpinfo->counts->icmp++; + capture_dissector_increment_count(cpinfo, proto_icmpv6); return TRUE; } diff --git a/epan/dissectors/packet-ip.c b/epan/dissectors/packet-ip.c index 7f6b7c3807..55b974361f 100644 --- a/epan/dissectors/packet-ip.c +++ b/epan/dissectors/packet-ip.c @@ -572,6 +572,7 @@ capture_ip(const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, if (!BYTES_ARE_IN_FRAME(offset, len, IPH_MIN_LEN)) return FALSE; + capture_dissector_increment_count(cpinfo, proto_ip); return try_capture_dissector("ip.proto", pd[offset + 9], pd, offset+IPH_MIN_LEN, len, cpinfo, pseudo_header); } diff --git a/epan/dissectors/packet-ipv6.c b/epan/dissectors/packet-ipv6.c index b6ce19979d..b6d0cb2539 100644 --- a/epan/dissectors/packet-ipv6.c +++ b/epan/dissectors/packet-ipv6.c @@ -530,6 +530,8 @@ capture_ipv6(const guchar *pd, int offset, int len, capture_packet_info_t *cpinf if (!BYTES_ARE_IN_FRAME(offset, len, 4+4+16+16)) return FALSE; + capture_dissector_increment_count(cpinfo, proto_ipv6); + nxt = pd[offset+6]; /* get the "next header" value */ offset += 4+4+16+16; /* skip past the IPv6 header */ diff --git a/epan/dissectors/packet-ipx.c b/epan/dissectors/packet-ipx.c index dff60bc75a..4cdf987fcb 100644 --- a/epan/dissectors/packet-ipx.c +++ b/epan/dissectors/packet-ipx.c @@ -276,7 +276,7 @@ static const value_string ipxmsg_sigchar_vals[] = { gboolean capture_ipx(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_) { - cpinfo->counts->ipx++; + capture_dissector_increment_count(cpinfo, proto_ipx); return TRUE; } diff --git a/epan/dissectors/packet-netbios.c b/epan/dissectors/packet-netbios.c index 6a3811bf3a..62b06b4d24 100644 --- a/epan/dissectors/packet-netbios.c +++ b/epan/dissectors/packet-netbios.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "packet-netbios.h" void proto_register_netbios(void); @@ -288,7 +289,7 @@ static const value_string max_frame_size_vals[] = { static gboolean capture_netbios(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_) { - cpinfo->counts->netbios++; + capture_dissector_increment_count(cpinfo, proto_netbios); return TRUE; } diff --git a/epan/dissectors/packet-ospf.c b/epan/dissectors/packet-ospf.c index 4f904466be..167bb9d83d 100644 --- a/epan/dissectors/packet-ospf.c +++ b/epan/dissectors/packet-ospf.c @@ -1043,7 +1043,7 @@ ospf_has_at_block(tvbuff_t *tvb, int offset, guint8 packet_type, guint8 version) static gboolean capture_ospf(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_) { - cpinfo->counts->ospf++; + capture_dissector_increment_count(cpinfo, proto_ospf); return TRUE; } diff --git a/epan/dissectors/packet-sctp.c b/epan/dissectors/packet-sctp.c index 42948149ea..e7519d3401 100644 --- a/epan/dissectors/packet-sctp.c +++ b/epan/dissectors/packet-sctp.c @@ -4688,7 +4688,7 @@ dissect_sctp_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolea static gboolean capture_sctp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_) { - cpinfo->counts->sctp++; + capture_dissector_increment_count(cpinfo, proto_sctp); return TRUE; } diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c index 9771f8d5c0..6f4dca0882 100644 --- a/epan/dissectors/packet-tcp.c +++ b/epan/dissectors/packet-tcp.c @@ -4807,7 +4807,7 @@ capture_tcp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_in if (!BYTES_ARE_IN_FRAME(offset, len, 4)) return FALSE; - cpinfo->counts->tcp++; + capture_dissector_increment_count(cpinfo, proto_tcp); src_port = pntoh16(&pd[offset]); dst_port = pntoh16(&pd[offset+2]); diff --git a/epan/dissectors/packet-udp.c b/epan/dissectors/packet-udp.c index 1e784a4a3a..4a1a6dbabe 100644 --- a/epan/dissectors/packet-udp.c +++ b/epan/dissectors/packet-udp.c @@ -699,7 +699,7 @@ capture_udp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_in if (!BYTES_ARE_IN_FRAME(offset, len, 4)) return FALSE; - cpinfo->counts->udp++; + capture_dissector_increment_count(cpinfo, hfi_udp->id); src_port = pntoh16(&pd[offset]); dst_port = pntoh16(&pd[offset+2]); diff --git a/epan/dissectors/packet-vines.c b/epan/dissectors/packet-vines.c index 7cafb52b2c..b7f523fb73 100644 --- a/epan/dissectors/packet-vines.c +++ b/epan/dissectors/packet-vines.c @@ -256,6 +256,7 @@ static gint ett_vines_rtp_control_flags = -1; static gint ett_vines_rtp_mtype = -1; static gint ett_vines_rtp_flags = -1; +static int proto_vines = -1; static int proto_vines_icp = -1; static int hf_vines_icp_exception_code = -1; static int hf_vines_icp_metric = -1; @@ -311,7 +312,7 @@ typedef struct _e_vipc { gboolean capture_vines(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_) { - cpinfo->counts->vines++; + capture_dissector_increment_count(cpinfo, proto_vines); return TRUE; } @@ -2004,6 +2005,8 @@ proto_register_vines_icp(void) proto_vines_icp = proto_register_protocol( "Banyan Vines ICP", "Vines ICP", "vines_icp"); + /* Placeholder for capture statistics */ + proto_vines = proto_register_protocol("VINES", "VINES", "vines"); proto_register_field_array(proto_vines_icp, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); } diff --git a/epan/packet.h b/epan/packet.h index 9690238949..cc13140bf6 100644 --- a/epan/packet.h +++ b/epan/packet.h @@ -56,33 +56,8 @@ struct epan_range; ((guint)(offset) + (guint)(len) > (guint)(offset) && \ (guint)(offset) + (guint)(len) <= (guint)(captured_len)) -/* - * GTK+ only. - * If we add this to the Qt UI we should modernize the statistics we show. - * At the very least we should remove or hide IPX and VINES. - */ -typedef struct _packet_counts { - gint sctp; - gint tcp; - gint udp; - gint icmp; - gint ospf; - gint gre; - gint netbios; - gint ipx; - gint vines; - gint other; - gint total; - gint arp; - gint i2c_event; - gint i2c_data; -} packet_counts; - -/** Number of packet counts. */ -#define PACKET_COUNTS_SIZE sizeof(packet_counts) / sizeof (gint) - typedef struct _capture_packet_info { - packet_counts *counts; + GHashTable *counts; } capture_packet_info_t; extern void packet_init(void); -- cgit v1.2.1