Wireshark  4.3.0
The Wireshark network protocol analyzer
dfvm.h
Go to the documentation of this file.
1 
10 #ifndef DFVM_H
11 #define DFVM_H
12 
13 #include <wsutil/regex.h>
14 #include <epan/proto.h>
15 #include "dfilter-int.h"
16 #include "syntax-tree.h"
17 #include "drange.h"
18 #include "dfunctions.h"
19 
20 #define ASSERT_DFVM_OP_NOT_REACHED(op) \
21  ws_error("Invalid dfvm opcode '%s'.", dfvm_opcode_tostr(op))
22 
23 typedef enum {
24  EMPTY,
25  FVALUE,
26  HFINFO,
27  RAW_HFINFO,
28  INSN_NUMBER,
29  REGISTER,
30  INTEGER,
31  DRANGE,
32  FUNCTION_DEF,
33  PCRE,
34 } dfvm_value_type_t;
35 
36 typedef struct {
37  dfvm_value_type_t type;
38 
39  union {
40  GPtrArray *fvalue_p; /* Always has length == 1 */
41  uint32_t numeric;
42  drange_t *drange;
43  header_field_info *hfinfo;
44  df_func_def_t *funcdef;
45  ws_regex_t *pcre;
46  } value;
47 
48  int ref_count;
49 } dfvm_value_t;
50 
51 #define dfvm_value_get_fvalue(val) ((val)->value.fvalue_p->pdata[0])
52 
53 typedef enum {
54  DFVM_NULL, /* Null/invalid opcode */
55  DFVM_IF_TRUE_GOTO,
56  DFVM_IF_FALSE_GOTO,
57  DFVM_CHECK_EXISTS,
58  DFVM_CHECK_EXISTS_R,
59  DFVM_NOT,
60  DFVM_RETURN,
61  DFVM_READ_TREE,
62  DFVM_READ_TREE_R,
63  DFVM_READ_REFERENCE,
64  DFVM_READ_REFERENCE_R,
65  DFVM_PUT_FVALUE,
66  DFVM_ALL_EQ,
67  DFVM_ANY_EQ,
68  DFVM_ALL_NE,
69  DFVM_ANY_NE,
70  DFVM_ALL_GT,
71  DFVM_ANY_GT,
72  DFVM_ALL_GE,
73  DFVM_ANY_GE,
74  DFVM_ALL_LT,
75  DFVM_ANY_LT,
76  DFVM_ALL_LE,
77  DFVM_ANY_LE,
78  DFVM_ALL_CONTAINS,
79  DFVM_ANY_CONTAINS,
80  DFVM_ALL_MATCHES,
81  DFVM_ANY_MATCHES,
82  DFVM_SET_ALL_IN,
83  DFVM_SET_ANY_IN,
84  DFVM_SET_ALL_NOT_IN,
85  DFVM_SET_ANY_NOT_IN,
86  DFVM_SET_ADD,
87  DFVM_SET_ADD_RANGE,
88  DFVM_SET_CLEAR,
89  DFVM_SLICE,
90  DFVM_LENGTH,
91  DFVM_VALUE_STRING,
92  DFVM_BITWISE_AND,
93  DFVM_UNARY_MINUS,
94  DFVM_ADD,
95  DFVM_SUBTRACT,
96  DFVM_MULTIPLY,
97  DFVM_DIVIDE,
98  DFVM_MODULO,
99  DFVM_CALL_FUNCTION,
100  DFVM_STACK_PUSH,
101  DFVM_STACK_POP,
102  DFVM_NOT_ALL_ZERO,
103  DFVM_NO_OP,
104 } dfvm_opcode_t;
105 
106 const char *
107 dfvm_opcode_tostr(dfvm_opcode_t code);
108 
109 typedef struct {
110  int id;
111  dfvm_opcode_t op;
112  dfvm_value_t *arg1;
113  dfvm_value_t *arg2;
114  dfvm_value_t *arg3;
115 } dfvm_insn_t;
116 
118 dfvm_insn_new(dfvm_opcode_t op);
119 
120 void
121 dfvm_insn_replace_no_op(dfvm_insn_t *insn);
122 
123 void
124 dfvm_insn_free(dfvm_insn_t *insn);
125 
127 dfvm_value_new(dfvm_value_type_t type);
128 
130 dfvm_value_ref(dfvm_value_t *v);
131 
132 void
133 dfvm_value_unref(dfvm_value_t *v);
134 
136 dfvm_value_new_fvalue(fvalue_t *fv);
137 
139 dfvm_value_new_hfinfo(header_field_info *hfinfo, bool raw);
140 
142 dfvm_value_new_register(int reg);
143 
145 dfvm_value_new_drange(drange_t *dr);
146 
148 dfvm_value_new_funcdef(df_func_def_t *funcdef);
149 
151 dfvm_value_new_pcre(ws_regex_t *re);
152 
154 dfvm_value_new_guint(unsigned num);
155 
156 void
157 dfvm_dump(FILE *f, dfilter_t *df, uint16_t flags);
158 
159 char *
160 dfvm_dump_str(wmem_allocator_t *alloc, dfilter_t *df, uint16_t flags);
161 
162 bool
163 dfvm_apply(dfilter_t *df, proto_tree *tree);
164 
165 bool
166 dfvm_apply_full(dfilter_t *df, proto_tree *tree, GPtrArray **fvals);
167 
168 fvalue_t *
169 dfvm_get_raw_fvalue(const field_info *fi);
170 
171 #endif
Definition: drange.h:40
Definition: ftypes-int.h:17
Definition: proto.h:769
Definition: proto.h:904
Definition: wmem_allocator.h:27
Definition: regex.c:17
Definition: dfunctions.h:39
Definition: dfvm.h:109
Definition: dfvm.h:36
Definition: dfilter-int.h:35
Definition: proto.h:816