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