2015-06-20 16:22:22 +00:00
|
|
|
/* rtd_table.c
|
|
|
|
* Helper routines common to all RTD taps.
|
|
|
|
* Based on srt_table.c
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2015-06-20 16:22:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "proto.h"
|
2016-01-25 01:10:20 +00:00
|
|
|
#include "packet_info.h"
|
2015-06-20 16:22:22 +00:00
|
|
|
#include "rtd_table.h"
|
|
|
|
|
|
|
|
struct register_rtd {
|
|
|
|
int proto_id; /* protocol id (0-indexed) */
|
|
|
|
const char* tap_listen_str; /* string used in register_tap_listener (NULL to use protocol name) */
|
|
|
|
tap_packet_cb rtd_func; /* function to be called for new incoming packets for RTD */
|
|
|
|
guint num_tables;
|
|
|
|
guint num_timestats;
|
|
|
|
const value_string* vs_type;
|
|
|
|
rtd_filter_check_cb filter_check;
|
|
|
|
};
|
|
|
|
|
|
|
|
int get_rtd_proto_id(register_rtd_t* rtd)
|
|
|
|
{
|
|
|
|
if (!rtd) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return rtd->proto_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* get_rtd_tap_listener_name(register_rtd_t* rtd)
|
|
|
|
{
|
|
|
|
return rtd->tap_listen_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
tap_packet_cb get_rtd_packet_func(register_rtd_t* rtd)
|
|
|
|
{
|
|
|
|
return rtd->rtd_func;
|
|
|
|
}
|
|
|
|
|
2015-07-07 19:04:48 +00:00
|
|
|
guint get_rtd_num_tables(register_rtd_t* rtd) {
|
|
|
|
return rtd->num_tables;
|
|
|
|
}
|
|
|
|
|
2015-06-20 16:22:22 +00:00
|
|
|
const value_string* get_rtd_value_string(register_rtd_t* rtd)
|
|
|
|
{
|
|
|
|
return rtd->vs_type;
|
|
|
|
}
|
|
|
|
|
2017-02-08 01:18:33 +00:00
|
|
|
static wmem_tree_t *registered_rtd_tables = NULL;
|
2015-06-20 16:22:22 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
register_rtd_table(const int proto_id, const char* tap_listener, guint num_tables, guint num_timestats, const value_string* vs_type,
|
|
|
|
tap_packet_cb rtd_packet_func, rtd_filter_check_cb filter_check_cb)
|
|
|
|
{
|
|
|
|
register_rtd_t *table;
|
|
|
|
DISSECTOR_ASSERT(rtd_packet_func);
|
|
|
|
|
2017-02-08 01:18:33 +00:00
|
|
|
table = wmem_new(wmem_epan_scope(), register_rtd_t);
|
2015-06-20 16:22:22 +00:00
|
|
|
|
|
|
|
table->proto_id = proto_id;
|
|
|
|
if (tap_listener != NULL)
|
|
|
|
table->tap_listen_str = tap_listener;
|
|
|
|
else
|
|
|
|
table->tap_listen_str = proto_get_protocol_filter_name(proto_id);
|
|
|
|
table->rtd_func = rtd_packet_func;
|
|
|
|
table->num_tables = num_tables;
|
|
|
|
table->num_timestats = num_timestats;
|
|
|
|
table->vs_type = vs_type;
|
|
|
|
table->filter_check = filter_check_cb;
|
|
|
|
|
2017-02-08 01:18:33 +00:00
|
|
|
if (registered_rtd_tables == NULL)
|
|
|
|
registered_rtd_tables = wmem_tree_new(wmem_epan_scope());
|
|
|
|
|
2017-02-08 21:42:05 +00:00
|
|
|
wmem_tree_insert_string(registered_rtd_tables, proto_get_protocol_filter_name(proto_id), table, 0);
|
2015-06-20 16:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 23:00:36 +00:00
|
|
|
void free_rtd_table(rtd_stat_table* table)
|
2015-06-20 16:22:22 +00:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < table->num_rtds; i++)
|
|
|
|
{
|
|
|
|
g_free(table->time_stats[i].rtd);
|
|
|
|
}
|
|
|
|
g_free(table->time_stats);
|
2015-08-20 15:56:04 +00:00
|
|
|
table->time_stats = NULL;
|
|
|
|
table->num_rtds = 0;
|
2015-06-20 16:22:22 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 23:00:36 +00:00
|
|
|
void reset_rtd_table(rtd_stat_table* table)
|
2015-06-20 16:22:22 +00:00
|
|
|
{
|
|
|
|
guint i = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < table->num_rtds; i++)
|
|
|
|
memset(table->time_stats[i].rtd, 0, sizeof(timestat_t)*table->time_stats[i].num_timestat);
|
|
|
|
}
|
|
|
|
|
|
|
|
register_rtd_t* get_rtd_table_by_name(const char* name)
|
|
|
|
{
|
2017-02-08 01:18:33 +00:00
|
|
|
return (register_rtd_t*)wmem_tree_lookup_string(registered_rtd_tables, name, 0);
|
2015-06-20 16:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar* rtd_table_get_tap_string(register_rtd_t* rtd)
|
|
|
|
{
|
|
|
|
GString *cmd_str = g_string_new(proto_get_protocol_filter_name(rtd->proto_id));
|
|
|
|
g_string_append(cmd_str, ",rtd");
|
|
|
|
return g_string_free(cmd_str, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtd_table_get_filter(register_rtd_t* rtd, const char *opt_arg, const char **filter, char** err)
|
|
|
|
{
|
|
|
|
gchar* cmd_str = rtd_table_get_tap_string(rtd);
|
2015-06-22 15:53:34 +00:00
|
|
|
guint len = (guint) strlen(cmd_str);
|
2015-06-20 16:22:22 +00:00
|
|
|
*filter=NULL;
|
|
|
|
*err=NULL;
|
|
|
|
|
|
|
|
if (!strncmp(opt_arg, cmd_str, len))
|
|
|
|
{
|
|
|
|
if (opt_arg[len] == ',')
|
|
|
|
{
|
|
|
|
*filter = opt_arg + len+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtd->filter_check)
|
|
|
|
rtd->filter_check(opt_arg, filter, err);
|
|
|
|
|
|
|
|
g_free(cmd_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtd_table_dissector_init(register_rtd_t* rtd, rtd_stat_table* table, rtd_gui_init_cb gui_callback, void *callback_data)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
table->num_rtds = rtd->num_tables;
|
|
|
|
table->time_stats = g_new0(rtd_timestat, rtd->num_tables);
|
|
|
|
|
|
|
|
for (i = 0; i < table->num_rtds; i++)
|
|
|
|
{
|
|
|
|
table->time_stats[i].num_timestat = rtd->num_timestats;
|
|
|
|
table->time_stats[i].rtd = g_new0(timestat_t, rtd->num_timestats);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gui_callback)
|
|
|
|
gui_callback(table, callback_data);
|
|
|
|
}
|
|
|
|
|
2017-02-08 01:18:33 +00:00
|
|
|
void rtd_table_iterate_tables(wmem_foreach_func func, gpointer user_data)
|
2015-06-20 16:22:22 +00:00
|
|
|
{
|
2017-02-08 01:18:33 +00:00
|
|
|
wmem_tree_foreach(registered_rtd_tables, func, user_data);
|
2015-06-20 16:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|