Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
dfilter.h
Go to the documentation of this file.
1
10#ifndef DFILTER_H
11#define DFILTER_H
12
13#include <wireshark.h>
14
15#include "dfilter-loc.h"
16#include <epan/proto.h>
17
18/* Passed back to user */
19typedef struct epan_dfilter dfilter_t;
20
21#ifdef __cplusplus
22extern "C" {
23#endif /* __cplusplus */
24
25struct epan_dissect;
26
27#define DF_ERROR_GENERIC -1
28#define DF_ERROR_UNEXPECTED_END -2
29
30typedef struct {
31 int code;
32 char *msg;
33 df_loc_t loc;
35
45df_error_new(int code, char *msg, df_loc_t *loc);
46
56df_error_new_printf(int code, df_loc_t *loc, const char *fmt, ...)
57G_GNUC_PRINTF(3, 4);
58
59#define df_error_new_msg(msg) \
60 df_error_new_printf(DF_ERROR_GENERIC, NULL, "%s", msg)
61
72df_error_new_vprintf(int code, df_loc_t *loc, const char *fmt, va_list ap);
73
81WS_DLL_PUBLIC
82void
84
85/* Module-level initialization */
86
95void
96dfilter_init(const char* app_env_var_prefix);
97
98/* Module-level cleanup */
105void
106 dfilter_cleanup(void);
107
108/* Perform macro expansion. */
118WS_DLL_PUBLIC
119char *
120dfilter_expand(const char *expr, df_error_t **err_ret);
121
122/* Save textual representation of syntax tree (for debugging purposes). */
123#define DF_SAVE_TREE (1U << 0)
124/* Perform macro substitution on filter text. */
125#define DF_EXPAND_MACROS (1U << 1)
126/* Do an optimization pass on the compiled filter. */
127#define DF_OPTIMIZE (1U << 2)
128/* Enable debug trace for flex. */
129#define DF_DEBUG_FLEX (1U << 3)
130/* Enable debug trace for lemon. */
131#define DF_DEBUG_LEMON (1U << 4)
132/* If the root of the syntax tree is a field, load and return the field values.
133 * By default the field is only checked for existence. */
134#define DF_RETURN_VALUES (1U << 5)
135
152WS_DLL_PUBLIC
153bool
154dfilter_compile_full(const char *text, dfilter_t **dfp,
155 df_error_t **errpp, unsigned flags,
156 const char *caller);
157
158#define dfilter_compile(text, dfp, errp) \
159 dfilter_compile_full(text, dfp, errp, \
160 DF_EXPAND_MACROS|DF_OPTIMIZE, \
161 __func__)
162
163struct stnode;
164
170WS_DLL_PUBLIC
171struct stnode *dfilter_get_syntax_tree(const char *text);
172
181WS_DLL_PUBLIC
182void
184
192WS_DLL_PUBLIC
193bool
195
202bool
204
215bool
216dfilter_apply_full(dfilter_t *df, proto_tree *tree, GPtrArray **fvals);
217
224void
226
233void
235
242WS_DLL_PUBLIC
243void
245
252WS_DLL_PUBLIC
253void
255
262bool
264
272bool
273dfilter_interested_in_field(const dfilter_t *df, int hfid);
274
283bool
284dfilter_interested_in_proto(const dfilter_t *df, int proto_id);
285
292WS_DLL_PUBLIC
293bool
295
302WS_DLL_PUBLIC
303GPtrArray *
305
312WS_DLL_PUBLIC
313GSList *
315
316#define DF_DUMP_REFERENCES (1U << 0)
317#define DF_DUMP_SHOW_FTYPE (1U << 1)
318
319/* Print bytecode of dfilter to fp */
327WS_DLL_PUBLIC
328void
329dfilter_dump(FILE *fp, dfilter_t *df, uint16_t flags);
330
331/* Text after macro expansion. */
338WS_DLL_PUBLIC
339const char *
341
350WS_DLL_PUBLIC
351const char *
353
360WS_DLL_PUBLIC
361ftenum_t
363
364/* Print bytecode of dfilter to log */
378WS_DLL_PUBLIC
379void
380dfilter_log_full(const char *domain, enum ws_log_level level,
381 const char *file, long line, const char *func,
382 dfilter_t *dfcode, const char *msg);
383
384#ifdef WS_DEBUG
385#define dfilter_log(dfcode, msg) \
386 dfilter_log_full(LOG_DOMAIN_DFILTER, LOG_LEVEL_NOISY, \
387 __FILE__, __LINE__, __func__, \
388 dfcode, msg)
389#else
390#define dfilter_log(dfcode, msg) (void)0
391#endif
392
393#define DFILTER_DEBUG_HERE(dfcode) \
394 dfilter_log_full(LOG_DOMAIN_DFILTER, LOG_LEVEL_ECHO, \
395 __FILE__, __LINE__, __func__, \
396 dfcode, #dfcode);
397
398#ifdef __cplusplus
399}
400#endif /* __cplusplus */
401
402#endif /* DFILTER_H */
bool dfilter_has_interesting_fields(const dfilter_t *df)
Check if a display filter has any interesting fields.
Definition dfilter.c:729
df_error_t * df_error_new_printf(int code, df_loc_t *loc, const char *fmt,...)
Create a new error with formatted message.
Definition dfilter.c:963
WS_DLL_PUBLIC bool dfilter_requires_columns(const dfilter_t *df)
Check if a display filter requires specific columns.
Definition dfilter.c:772
WS_DLL_PUBLIC GPtrArray * dfilter_deprecated_tokens(dfilter_t *df)
Get deprecated tokens from a dfilter.
Definition dfilter.c:789
bool dfilter_interested_in_proto(const dfilter_t *df, int proto_id)
Check if dfilter is interested in a given protocol.
Definition dfilter.c:748
void dfilter_init(const char *app_env_var_prefix)
Initialize the display filter module.
Definition dfilter.c:105
bool dfilter_apply(dfilter_t *df, proto_tree *tree)
Apply a compiled dfilter to a protocol tree.
Definition dfilter.c:693
bool dfilter_apply_full(dfilter_t *df, proto_tree *tree, GPtrArray **fvals)
Apply a dfilter to a proto_tree and populate fvals.
Definition dfilter.c:705
WS_DLL_PUBLIC void dfilter_free(dfilter_t *df)
Free a compiled dfilter.
Definition dfilter.c:171
WS_DLL_PUBLIC void dfilter_load_field_references_edt(const dfilter_t *df, struct epan_dissect *edt)
Load field references for a display filter into an epan_dissect_t structure.
Definition dfilter.c:901
WS_DLL_PUBLIC const char * dfilter_text(dfilter_t *df)
Get the text representation of a syntax tree.
Definition dfilter.c:809
df_error_t * df_error_new_vprintf(int code, df_loc_t *loc, const char *fmt, va_list ap)
Create a new error with formatted message and location information.
Definition dfilter.c:946
void dfilter_prime_proto_tree_print(const dfilter_t *df, proto_tree *tree)
Prime a proto_tree using the fields/protocols used in a dfilter, marked for print.
Definition dfilter.c:721
WS_DLL_PUBLIC void dfilter_load_field_references(const dfilter_t *df, proto_tree *tree)
Refresh references in a compiled display filter.
Definition dfilter.c:894
WS_DLL_PUBLIC GSList * dfilter_get_warnings(dfilter_t *df)
Get warnings associated with a display filter.
Definition dfilter.c:797
void dfilter_cleanup(void)
Perform module-level cleanup for the dfilter subsystem.
Definition dfilter.c:125
WS_DLL_PUBLIC bool dfilter_apply_edt(dfilter_t *df, struct epan_dissect *edt)
Apply a compiled display filter to an epan_dissect structure.
Definition dfilter.c:699
WS_DLL_PUBLIC void df_error_free(df_error_t **ep)
Frees a df_error_t structure.
Definition dfilter.c:973
df_error_t * df_error_new(int code, char *msg, df_loc_t *loc)
Create a new error object with a specific code and message.
Definition dfilter.c:929
WS_DLL_PUBLIC struct stnode * dfilter_get_syntax_tree(const char *text)
Build a syntax tree for a filter.
Definition dfilter.c:654
WS_DLL_PUBLIC const char * dfilter_syntax_tree(dfilter_t *df)
Get the syntax tree of a dfilter.
Definition dfilter.c:815
bool dfilter_interested_in_field(const dfilter_t *df, int hfid)
Check if dfilter is interested in a given field.
Definition dfilter.c:735
void dfilter_prime_proto_tree(const dfilter_t *df, proto_tree *tree)
Prime a proto_tree using the fields/protocols used in a dfilter.
Definition dfilter.c:711
WS_DLL_PUBLIC void dfilter_log_full(const char *domain, enum ws_log_level level, const char *file, long line, const char *func, dfilter_t *dfcode, const char *msg)
Log a display filter with full details.
Definition dfilter.c:827
WS_DLL_PUBLIC void dfilter_dump(FILE *fp, dfilter_t *df, uint16_t flags)
Dump a dfilter to a file.
Definition dfilter.c:803
WS_DLL_PUBLIC bool dfilter_compile_full(const char *text, dfilter_t **dfp, df_error_t **errpp, unsigned flags, const char *caller)
Compiles a string to a dfilter_t.
Definition dfilter.c:605
WS_DLL_PUBLIC ftenum_t dfilter_get_return_type(dfilter_t *df)
Get the return type of a display filter.
Definition dfilter.c:821
Definition dfilter-loc.h:16
Definition proto.h:905
Definition dfilter.h:30
Definition dfilter-int.h:35
Definition epan_dissect.h:28
Definition syntax-tree.h:78