2 * Helper routines common to all RTD taps.
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "packet_info.h"
18 #include "rtd_table.h"
21 int proto_id
; /* protocol id (0-indexed) */
22 const char* tap_listen_str
; /* string used in register_tap_listener (NULL to use protocol name) */
23 tap_packet_cb rtd_func
; /* function to be called for new incoming packets for RTD */
25 unsigned num_timestats
;
26 const value_string
* vs_type
;
27 rtd_filter_check_cb filter_check
;
30 int get_rtd_proto_id(register_rtd_t
* rtd
)
38 const char* get_rtd_tap_listener_name(register_rtd_t
* rtd
)
40 return rtd
->tap_listen_str
;
43 tap_packet_cb
get_rtd_packet_func(register_rtd_t
* rtd
)
48 unsigned get_rtd_num_tables(register_rtd_t
* rtd
) {
49 return rtd
->num_tables
;
52 const value_string
* get_rtd_value_string(register_rtd_t
* rtd
)
57 static wmem_tree_t
*registered_rtd_tables
;
60 register_rtd_table(const int proto_id
, const char* tap_listener
, unsigned num_tables
, unsigned num_timestats
, const value_string
* vs_type
,
61 tap_packet_cb rtd_packet_func
, rtd_filter_check_cb filter_check_cb
)
63 register_rtd_t
*table
;
64 DISSECTOR_ASSERT(rtd_packet_func
);
66 table
= wmem_new(wmem_epan_scope(), register_rtd_t
);
68 table
->proto_id
= proto_id
;
69 if (tap_listener
!= NULL
)
70 table
->tap_listen_str
= tap_listener
;
72 table
->tap_listen_str
= proto_get_protocol_filter_name(proto_id
);
73 table
->rtd_func
= rtd_packet_func
;
74 table
->num_tables
= num_tables
;
75 table
->num_timestats
= num_timestats
;
76 table
->vs_type
= vs_type
;
77 table
->filter_check
= filter_check_cb
;
79 if (registered_rtd_tables
== NULL
)
80 registered_rtd_tables
= wmem_tree_new(wmem_epan_scope());
82 wmem_tree_insert_string(registered_rtd_tables
, proto_get_protocol_filter_name(proto_id
), table
, 0);
85 void free_rtd_table(rtd_stat_table
* table
)
89 for (i
= 0; i
< table
->num_rtds
; i
++)
91 g_free(table
->time_stats
[i
].rtd
);
93 g_free(table
->time_stats
);
94 table
->time_stats
= NULL
;
98 void reset_rtd_table(rtd_stat_table
* table
)
102 for (i
= 0; i
< table
->num_rtds
; i
++)
103 memset(table
->time_stats
[i
].rtd
, 0, sizeof(timestat_t
)*table
->time_stats
[i
].num_timestat
);
106 register_rtd_t
* get_rtd_table_by_name(const char* name
)
108 return (register_rtd_t
*)wmem_tree_lookup_string(registered_rtd_tables
, name
, 0);
111 char* rtd_table_get_tap_string(register_rtd_t
* rtd
)
113 GString
*cmd_str
= g_string_new(proto_get_protocol_filter_name(rtd
->proto_id
));
114 g_string_append(cmd_str
, ",rtd");
115 return g_string_free(cmd_str
, FALSE
);
118 void rtd_table_get_filter(register_rtd_t
* rtd
, const char *opt_arg
, const char **filter
, char** err
)
120 char* cmd_str
= rtd_table_get_tap_string(rtd
);
121 unsigned len
= (unsigned) strlen(cmd_str
);
125 if (!strncmp(opt_arg
, cmd_str
, len
))
127 if (opt_arg
[len
] == ',')
129 *filter
= opt_arg
+ len
+1;
133 if (rtd
->filter_check
)
134 rtd
->filter_check(opt_arg
, filter
, err
);
139 void rtd_table_dissector_init(register_rtd_t
* rtd
, rtd_stat_table
* table
, rtd_gui_init_cb gui_callback
, void *callback_data
)
143 table
->num_rtds
= rtd
->num_tables
;
144 table
->time_stats
= g_new0(rtd_timestat
, rtd
->num_tables
);
146 for (i
= 0; i
< table
->num_rtds
; i
++)
148 table
->time_stats
[i
].num_timestat
= rtd
->num_timestats
;
149 table
->time_stats
[i
].rtd
= g_new0(timestat_t
, rtd
->num_timestats
);
153 gui_callback(table
, callback_data
);
156 void rtd_table_iterate_tables(wmem_foreach_func func
, void *user_data
)
158 wmem_tree_foreach(registered_rtd_tables
, func
, user_data
);
167 * indent-tabs-mode: nil
170 * ex: set shiftwidth=4 tabstop=8 expandtab:
171 * :indentSize=4:tabSize=8:noTabs=true: