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