suricata
util-mpm-hs-core.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2024 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Jim Xu <jim.xu@windriver.com>
22  * \author Justin Viiret <justin.viiret@intel.com>
23  * \author Lukas Sismis <lsismis@oisf.net>
24  *
25  * MPM pattern matcher core function for the Hyperscan regex matcher.
26  */
27 
28 #ifndef SURICATA_UTIL_MPM_HS_CORE__H
29 #define SURICATA_UTIL_MPM_HS_CORE__H
30 
31 #include "suricata-common.h"
32 #include "suricata.h"
33 
34 #ifdef BUILD_HYPERSCAN
35 #include <hs.h>
36 
37 typedef struct SCHSPattern_ {
38  /** length of the pattern */
39  uint16_t len;
40  /** flags describing the pattern */
41  uint8_t flags;
42  /** holds the original pattern that was added */
43  uint8_t *original_pat;
44  /** pattern id */
45  uint32_t id;
46 
47  uint16_t offset;
48  uint16_t depth;
49 
50  /** sid(s) for this pattern */
51  uint32_t sids_size;
52  SigIntId *sids;
53 
54  /** only used at ctx init time, when this structure is part of a hash
55  * table. */
56  struct SCHSPattern_ *next;
57 } SCHSPattern;
58 
59 typedef struct SCHSCtx_ {
60  /** hash used during ctx initialization */
61  SCHSPattern **init_hash;
62 
63  /** pattern database and pattern arrays. */
64  void *pattern_db;
65 
66  /** size of database, for accounting. */
67  size_t hs_db_size;
68 } SCHSCtx;
69 
70 typedef struct SCHSThreadCtx_ {
71  /** Hyperscan scratch space region for this thread, capable of handling any
72  * database that has been compiled. */
73  void *scratch;
74 
75  /** size of scratch space, for accounting. */
76  size_t scratch_size;
77 } SCHSThreadCtx;
78 
79 typedef struct PatternDatabase_ {
80  SCHSPattern **parray;
81  hs_database_t *hs_db;
82  uint32_t pattern_cnt;
83 
84  /** Reference count: number of MPM contexts using this pattern database. */
85  uint32_t ref_cnt;
86  /** Signals if the matcher has loaded/saved the pattern database to disk */
87  bool cached;
88  /** Matcher will not cache this pattern DB */
89  bool no_cache;
90 } PatternDatabase;
91 
92 typedef struct PatternDatabaseCache_ {
93  uint32_t hs_cacheable_dbs_cnt;
94  uint32_t hs_dbs_cache_loaded_cnt;
95  uint32_t hs_dbs_cache_saved_cnt;
96 } PatternDatabaseCache;
97 
98 const char *HSErrorToStr(hs_error_t error_code);
99 
100 #endif /* BUILD_HYPERSCAN */
101 #endif /* SURICATA_UTIL_MPM_HS_CORE__H */
len
uint8_t len
Definition: app-layer-dnp3.h:2
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
suricata.h
SigIntId
#define SigIntId
Definition: suricata-common.h:324