Wireshark 2.9.0-477-g68ec514b The Wireshark network protocol analyzer

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

stats_tree.h
1 /* stats_tree.h
2 * A counter tree API for Wireshark dissectors
3 * 2005, Luis E. G. Ontanon
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11 #ifndef __STATS_TREE_H
12 #define __STATS_TREE_H
13
14 #include <glib.h>
15 #include <epan/epan.h>
16 #include <epan/packet_info.h>
17 #include <epan/tap.h>
18 #include <epan/stat_groups.h>
19 #include "register.h"
20 #include "ws_symbol_export.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif /* __cplusplus */
25
26 #define STAT_TREE_ROOT "root"
27
28 #define ST_FLG_AVERAGE 0x10000000 /* Calculate averages for nodes, rather than totals */
29 #define ST_FLG_ROOTCHILD 0x20000000 /* This node is a direct child of the root node */
30 #define ST_FLG_DEF_NOEXPAND 0x01000000 /* This node should not be expanded by default */
31 #define ST_FLG_SORT_DESC 0x00800000 /* When sorting, sort ascending instead of decending */
32 #define ST_FLG_SORT_TOP 0x00400000 /* When sorting always keep these lines on of list */
33 #define ST_FLG_SRTCOL_MASK 0x000F0000 /* Mask for sort column ID */
34 #define ST_FLG_SRTCOL_SHIFT 16 /* Number of bits to shift masked result */
35
36 #define ST_FLG_MASK (ST_FLG_AVERAGE|ST_FLG_ROOTCHILD|ST_FLG_DEF_NOEXPAND| \
37 ST_FLG_SORT_TOP|ST_FLG_SORT_DESC|ST_FLG_SRTCOL_MASK)
38
39 #define ST_SORT_COL_NAME 1 /* Sort nodes by node names */
40 #define ST_SORT_COL_COUNT 2 /* Sort nodes by node count */
41 #define ST_SORT_COL_AVG 3 /* Sort nodes by node average */
42 #define ST_SORT_COL_MIN 4 /* Sort nodes by minimum node value */
43 #define ST_SORT_COL_MAX 5 /* Sort nodes by maximum node value */
44 #define ST_SORT_COL_BURSTRATE 6 /* Sort nodes by burst rate */
45
46 /* obscure information regarding the stats_tree */
47 typedef struct _stats_tree stats_tree;
48
49 /* tap packet callback for stats_tree */
50 typedef int (*stat_tree_packet_cb)(stats_tree*,
51 packet_info *,
52 epan_dissect_t *,
53 const void *);
54
55 /* stats_tree initialization callback */
56 typedef void (*stat_tree_init_cb)(stats_tree *);
57
58 /* stats_tree cleanup callback */
59 typedef void (*stat_tree_cleanup_cb)(stats_tree *);
60
61 /* registers a new stats tree with default group REGISTER_STAT_GROUP_UNSORTED
62 * abbr: protocol abbr
63 * name: protocol display name
64 * flags: tap listener flags for per-packet callback
65 * packet: per packet callback
66 * init: tree initialization callback
67 * cleanup: cleanup callback
68 */
69 WS_DLL_PUBLIC void stats_tree_register(const gchar *tapname,
70 const gchar *abbr,
71 const gchar *name,
72 guint flags,
73 stat_tree_packet_cb packet,
74 stat_tree_init_cb init,
75 stat_tree_cleanup_cb cleanup);
76
77 /* registers a new stats tree with default group REGISTER_STAT_GROUP_UNSORTED from a plugin
78 * abbr: protocol abbr
79 * name: protocol display name
80 * flags: tap listener flags for per-packet callback
81 * packet: per packet callback
82 * init: tree initialization callback
83 * cleanup: cleanup callback
84 */
85 WS_DLL_PUBLIC void stats_tree_register_plugin(const gchar *tapname,
86 const gchar *abbr,
87 const gchar *name,
88 guint flags,
89 stat_tree_packet_cb packet,
90 stat_tree_init_cb init,
91 stat_tree_cleanup_cb cleanup);
92
93 /* registers a new stats tree
94 * abbr: protocol abbr
95 * name: protocol display name
96 * flags: tap listener flags for per-packet callback
97 * packet: per packet callback
98 * init: tree initialization callback
99 * cleanup: cleanup callback
100 * stat_group: the group this stat belongs to
101 */
102 WS_DLL_PUBLIC void stats_tree_register_with_group(const gchar *tapname,
103 const gchar *abbr,
104 const gchar *name,
105 guint flags,
106 stat_tree_packet_cb packet,
107 stat_tree_init_cb init,
108 stat_tree_cleanup_cb cleanup,
109 register_stat_group_t stat_group);
110
111 WS_DLL_PUBLIC int stats_tree_parent_id_by_name(stats_tree *st, const gchar *parent_name);
112
113 /* Creates a node in the tree (to be used in the in init_cb)
114 * st: the stats_tree in which to create it
115 * name: the name of the new node
116 * parent_name: the name of the parent_node (NULL for root)
117 * with_children: TRUE if this node will have "dynamically created" children
118 */
119 WS_DLL_PUBLIC int stats_tree_create_node(stats_tree *st,
120 const gchar *name,
121 int parent_id,
122 gboolean with_children);
123
124 /* creates a node using its parent's tree name */
125 WS_DLL_PUBLIC int stats_tree_create_node_by_pname(stats_tree *st,
126 const gchar *name,
127 const gchar *parent_name,
128 gboolean with_children);
129
130 /* creates a node in the tree, that will contain a ranges list.
131 example:
132 stats_tree_create_range_node(st,name,parent,
133 "-99","100-199","200-299","300-399","400-", NULL);
134 */
135 WS_DLL_PUBLIC int stats_tree_create_range_node(stats_tree *st,
136 const gchar *name,
137 int parent_id,
138 ...);
139
140 WS_DLL_PUBLIC int stats_tree_create_range_node_string(stats_tree *st,
141 const gchar *name,
142 int parent_id,
143 int num_str_ranges,
144 gchar** str_ranges);
145
146 WS_DLL_PUBLIC int stats_tree_range_node_with_pname(stats_tree *st,
147 const gchar *name,
148 const gchar *parent_name,
149 ...);
150
151 /* increases by one the ranged node and the sub node to whose range the value belongs */
152 WS_DLL_PUBLIC int stats_tree_tick_range(stats_tree *st,
153 const gchar *name,
154 int parent_id,
155 int value_in_range);
156
157 #define stats_tree_tick_range_by_pname(st,name,parent_name,value_in_range) \
158 stats_tree_tick_range((st),(name),stats_tree_parent_id_by_name((st),(parent_name),(value_in_range)))
159
160 /* */
161 WS_DLL_PUBLIC int stats_tree_create_pivot(stats_tree *st,
162 const gchar *name,
163 int parent_id);
164
165 WS_DLL_PUBLIC int stats_tree_create_pivot_by_pname(stats_tree *st,
166 const gchar *name,
167 const gchar *parent_name);
168
169 WS_DLL_PUBLIC int stats_tree_tick_pivot(stats_tree *st,
170 int pivot_id,
171 const gchar *pivot_value);
172
173 extern void stats_tree_cleanup(void);
174
175
176 /*
177 * manipulates the value of the node whose name is given
178 * if the node does not exist yet it's created (with counter=1)
179 * using parent_name as parent node (NULL for root).
180 * with_children=TRUE to indicate that the created node will be a parent
181 */
182 typedef enum _manip_node_mode {
183 MN_INCREASE,
184 MN_SET,
185 MN_AVERAGE,
186 MN_AVERAGE_NOTICK,
187 MN_SET_FLAGS,
188 MN_CLEAR_FLAGS
189 } manip_node_mode;
190 WS_DLL_PUBLIC int stats_tree_manip_node(manip_node_mode mode,
191 stats_tree *st,
192 const gchar *name,
193 int parent_id,
194 gboolean with_children,
195 gint value);
196
197 #define increase_stat_node(st,name,parent_id,with_children,value) \
198 (stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),(value)))
199
200 #define tick_stat_node(st,name,parent_id,with_children) \
201 (stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),1))
202
203 #define set_stat_node(st,name,parent_id,with_children,value) \
204 (stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),value))
205
206 #define zero_stat_node(st,name,parent_id,with_children) \
207 (stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),0))
208
209 /*
210 * Add value to average calculation WITHOUT ticking node. Node MUST be ticked separately!
211 *
212 * Intention is to allow code to separately tick node (backward compatibility for plugin)
213 * and set value to use for averages. Older versions without average support will then at
214 * least show a count instead of 0.
215 */
216 #define avg_stat_node_add_value_notick(st,name,parent_id,with_children,value) \
217 (stats_tree_manip_node(MN_AVERAGE_NOTICK,(st),(name),(parent_id),(with_children),value))
218
219 /* Tick node and add a new value to the average calculation for this stats node. */
220 #define avg_stat_node_add_value(st,name,parent_id,with_children,value) \
221 (stats_tree_manip_node(MN_AVERAGE,(st),(name),(parent_id),(with_children),value))
222
223 /* Set flags for this node. Node created if it does not yet exist. */
224 #define stat_node_set_flags(st,name,parent_id,with_children,flags) \
225 (stats_tree_manip_node(MN_SET_FLAGS,(st),(name),(parent_id),(with_children),flags))
226
227 /* Clear flags for this node. Node created if it does not yet exist. */
228 #define stat_node_clear_flags(st,name,parent_id,with_children,flags) \
229 (stats_tree_manip_node(MN_CLEAR_FLAGS,(st),(name),(parent_id),(with_children),flags))
230
231 #ifdef __cplusplus
232 }
233 #endif /* __cplusplus */
234
235 #endif /* __STATS_TREE_H */
236
237 /*
238 * Editor modelines - http://www.wireshark.org/tools/modelines.html
239 *
240 * Local variables:
241 * c-basic-offset: 4
242 * tab-width: 8
243 * indent-tabs-mode: nil
244 * End:
245 *
246 * vi: set shiftwidth=4 tabstop=8 expandtab:
247 * :indentSize=4:tabSize=8:noTabs=true:
248 */
_packet_info
Definition: packet_info.h:44
stat_groups.h
register_stat_group_t
register_stat_group_t
Definition: stat_groups.h:45
epan_dissect
Definition: epan_dissect.h:28
packet_info.h
_stats_tree
Definition: stats_tree_priv.h:91