aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/suricata/src/util-mpm-ac-tile.h
blob: 63d5bc95eff90568d03eaa2b53589b027bad3924 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* Copyright (C) 2013-2014 Open Information Security Foundation
 *
 * You can copy, redistribute or modify this Program under the terms of
 * the GNU General Public License version 2 as published by the Free
 * Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

/**
 * \file
 *
 * \author Anoop Saldanha <anoopsaldanha@gmail.com>
 * \author Ken Steele <suricata@tilera.com>
 *
 */

#ifndef __UTIL_MPM_AC_TILE__H__
#define __UTIL_MPM_AC_TILE__H__

typedef struct SCACTilePattern_ {
    /* length of the pattern */
    uint16_t len;
    /* flags decribing the pattern */
    uint8_t flags;
    /* holds the original pattern that was added */
    uint8_t *original_pat;
    /* case sensitive */
    uint8_t *cs;
    /* case INsensitive */
    uint8_t *ci;
    /* pattern id */
    uint32_t id;

    /* sid(s) for this pattern */
    uint32_t sids_size;
    SigIntId *sids;

    struct SCACTilePattern_ *next;
} SCACTilePattern;

typedef struct SCACTilePatternList_ {
    uint8_t *cs;
    uint16_t patlen;

    /* Pattern Id */
    uint32_t pid;

    /* sid(s) for this pattern */
    uint32_t sids_size;
    SigIntId *sids;
} SCACTilePatternList;

typedef struct SCACTileOutputTable_ {
    /* list of pattern indexes */
    MpmPatternIndex *patterns;
    /* number of entries in pattern list */
    uint32_t no_of_entries;
} SCACTileOutputTable;

struct SCACTileSearchCtx_;

/* Reordered for Tilera cache */
typedef struct SCACTileCtx_ {

    /* Convert input character to matching alphabet */
    uint8_t translate_table[256];

    /* The all important memory hungry state_table.
     * The size of each next-state is determined by bytes_per_state.
     */
    void *state_table;

    /* Specialized search function based on size of data in delta
     * tables.  The alphabet size determines address shifting and the
     * number of states could make the next state could be 16 bits or
     * 32 bits.
     */
    uint32_t (*search)(struct SCACTileSearchCtx_ *ctx, struct MpmThreadCtx_ *,
                       PatternMatcherQueue *, uint8_t *, uint16_t);

    /* Function to set the next state based on size of next state
     * (bytes_per_state).
     */
    void (*set_next_state)(struct SCACTileCtx_ *ctx, int state, int aa,
                           int new_state, int outputs);

    /* List of patterns that match for this state. Indexed by State Number */
    SCACTileOutputTable *output_table;
    /* Indexed by MpmPatternIndex */
    SCACTilePatternList *pattern_list;

    /* hash used during ctx initialization */
    SCACTilePattern **init_hash;

    /* pattern arrays.  We need this only during the goto table
       creation phase */
    SCACTilePattern **parray;

    /* goto_table, failure table and output table.  Needed to create
     * state_table.  Will be freed, once we have created the
     * state_table */
    int32_t (*goto_table)[256];
    int32_t *failure_table;

    /* Number of states used by ac-tile */
    uint32_t state_count;
    /* Number of states allocated for ac-tile. */
    uint32_t allocated_state_count;

    uint32_t alpha_hist[256];
    /* Number of characters in the compressed alphabet. */
    uint16_t alphabet_size;
    /* Space used to store compressed alphabet is the next
     * larger or equal power-of-2.
     */
    uint16_t alphabet_storage;

    /* How many bytes are used to store the next state. */
    uint8_t bytes_per_state;

} SCACTileCtx;


/* Only the stuff used at search time. This
 * structure is created after all the patterns are added.
 */
typedef struct SCACTileSearchCtx_ {

    /* Specialized search function based on size of data in delta
     * tables.  The alphabet size determines address shifting and the
     * number of states could make the next state could be 16 bits or
     * 32 bits.
     */
    uint32_t (*search)(struct SCACTileSearchCtx_ *ctx, struct MpmThreadCtx_ *,
                       PatternMatcherQueue *, uint8_t *, uint16_t);

    /* Convert input character to matching alphabet */
    uint8_t translate_table[256];

    /* the all important memory hungry state_table */
    void *state_table;

    /* List of patterns that match for this state. Indexed by State Number */
    SCACTileOutputTable *output_table;
    SCACTilePatternList *pattern_list;

    /* Number of bytes in the array of bits. One bit per pattern in this MPM. */
    uint32_t mpm_bitarray_size;

    /* MPM Creation data, only used at initialization. */
    SCACTileCtx *init_ctx;

} SCACTileSearchCtx;


typedef struct SCACTileThreadCtx_ {
    /* the total calls we make to the search function */
    uint32_t total_calls;
    /* the total patterns that we ended up matching against */
    uint64_t total_matches;
} SCACTileThreadCtx;

void MpmACTileRegister(void);

#endif /* __UTIL_MPM_AC_TILE__H__ */