suricata
datasets.h
Go to the documentation of this file.
1/* Copyright (C) 2017 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#ifndef SURICATA_DATASETS_H
19#define SURICATA_DATASETS_H
20
21#include "util-thash.h"
22#include "rust.h"
23#include "datasets-reputation.h"
24
25int DatasetsInit(void);
26void DatasetsDestroy(void);
27void DatasetsSave(void);
28void DatasetReload(void);
30
31typedef enum {
33 DATASET_FORMAT_JSON, /* File contains one single JSON object */
34 DATASET_FORMAT_NDJSON, /* Newline Delimited JSON */
36
45
46#define DATASET_NAME_MAX_LEN 63
47typedef struct Dataset {
50 uint32_t id;
51 bool from_yaml; /* Mark whether the set was retrieved from YAML */
52 bool hidden; /* Mark the old sets hidden in case of reload */
53 bool remove_key; /* Mark that value key should be removed from extra data */
55
56 char load[PATH_MAX];
57 char save[PATH_MAX];
58
59 struct Dataset *next;
61
62enum DatasetTypes DatasetGetTypeFromString(const char *s);
64Dataset *DatasetAlloc(const char *name);
65void DatasetLock(void);
66void DatasetUnlock(void);
67Dataset *DatasetSearchByName(const char *name);
68Dataset *DatasetFind(const char *name, enum DatasetTypes type);
69Dataset *DatasetGet(const char *name, enum DatasetTypes type, const char *save, const char *load,
70 uint64_t memcap, uint32_t hashsize);
71int DatasetGetOrCreate(const char *name, enum DatasetTypes type, const char *save, const char *load,
72 uint64_t *memcap, uint32_t *hashsize, Dataset **ret_set);
73int DatasetAdd(Dataset *set, const uint8_t *data, const uint32_t data_len);
74int DatasetRemove(Dataset *set, const uint8_t *data, const uint32_t data_len);
75int DatasetLookup(Dataset *set, const uint8_t *data, const uint32_t data_len);
76DataRepResultType DatasetLookupwRep(Dataset *set, const uint8_t *data, const uint32_t data_len,
77 const DataRepType *rep);
78
79void DatasetGetDefaultMemcap(uint64_t *memcap, uint32_t *hashsize);
80int DatasetParseIpv6String(Dataset *set, const char *line, struct in6_addr *in6);
81
82int DatasetAddSerialized(Dataset *set, const char *string);
83int DatasetRemoveSerialized(Dataset *set, const char *string);
84int DatasetLookupSerialized(Dataset *set, const char *string);
85
86#endif /* SURICATA_DATASETS_H */
void DatasetUnlock(void)
Definition datasets.c:107
Dataset * DatasetSearchByName(const char *name)
Definition datasets.c:121
int DatasetLookupSerialized(Dataset *set, const char *string)
add serialized data to set
Definition datasets.c:1458
int DatasetAddSerialized(Dataset *set, const char *string)
add serialized data to set
Definition datasets.c:1446
int DatasetLookup(Dataset *set, const uint8_t *data, const uint32_t data_len)
see if data is part of the set
Definition datasets.c:1104
int DatasetRemoveSerialized(Dataset *set, const char *string)
remove serialized data from set
Definition datasets.c:1536
void DatasetPostReloadCleanup(void)
Definition datasets.c:569
void DatasetsSave(void)
Definition datasets.c:852
DataRepResultType DatasetLookupwRep(Dataset *set, const uint8_t *data, const uint32_t data_len, const DataRepType *rep)
Definition datasets.c:1124
Dataset * DatasetAlloc(const char *name)
Definition datasets.c:112
DatasetTypes
Definition datasets.h:37
@ DATASET_TYPE_STRING
Definition datasets.h:39
@ DATASET_TYPE_IPV6
Definition datasets.h:43
@ DATASET_TYPE_IPV4
Definition datasets.h:42
@ DATASET_TYPE_SHA256
Definition datasets.h:41
@ DATASET_TYPE_MD5
Definition datasets.h:40
Dataset * DatasetFind(const char *name, enum DatasetTypes type)
look for set by name without creating it
Definition datasets.c:320
#define DATASET_NAME_MAX_LEN
Definition datasets.h:46
int DatasetsInit(void)
Definition datasets.c:622
void DatasetLock(void)
Definition datasets.c:102
void DatasetReload(void)
Definition datasets.c:543
int DatasetAppendSet(Dataset *set)
Definition datasets.c:79
DatasetFormats
Definition datasets.h:31
@ DATASET_FORMAT_CSV
Definition datasets.h:32
@ DATASET_FORMAT_JSON
Definition datasets.h:33
@ DATASET_FORMAT_NDJSON
Definition datasets.h:34
void DatasetGetDefaultMemcap(uint64_t *memcap, uint32_t *hashsize)
Definition datasets.c:599
int DatasetAdd(Dataset *set, const uint8_t *data, const uint32_t data_len)
Definition datasets.c:1339
void DatasetsDestroy(void)
Definition datasets.c:774
enum DatasetTypes DatasetGetTypeFromString(const char *s)
Definition datasets.c:64
int DatasetGetOrCreate(const char *name, enum DatasetTypes type, const char *save, const char *load, uint64_t *memcap, uint32_t *hashsize, Dataset **ret_set)
Definition datasets.c:369
int DatasetRemove(Dataset *set, const uint8_t *data, const uint32_t data_len)
Definition datasets.c:1542
int DatasetParseIpv6String(Dataset *set, const char *line, struct in6_addr *in6)
Definition datasets.c:156
Dataset * DatasetGet(const char *name, enum DatasetTypes type, const char *save, const char *load, uint64_t memcap, uint32_t hashsize)
Definition datasets.c:451
uint16_t type
bool remove_key
Definition datasets.h:53
struct Dataset * next
Definition datasets.h:59
bool from_yaml
Definition datasets.h:51
char name[DATASET_NAME_MAX_LEN+1]
Definition datasets.h:48
bool hidden
Definition datasets.h:52
THashTableContext * hash
Definition datasets.h:54
uint32_t id
Definition datasets.h:50
enum DatasetTypes type
Definition datasets.h:49
char load[PATH_MAX]
Definition datasets.h:56
char save[PATH_MAX]
Definition datasets.h:57
const char * name
#define hashsize(n)