suricata
|
#include "suricata-common.h"
#include "detect.h"
#include "detect-engine.h"
#include "util-hash.h"
#include "conf.h"
#include "util-classification-config.h"
#include "util-unittest.h"
#include "util-error.h"
#include "util-debug.h"
#include "util-fmemopen.h"
#include "util-byte.h"
Go to the source code of this file.
Macros | |
#define | DETECT_CLASSCONFIG_REGEX "^\\s*config\\s*classification\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s*,\\s*(.+)\\s*,\\s*(\\d+)\\s*$" |
#define | SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/classification.config" |
Functions | |
uint32_t | SCClassConfClasstypeHashFunc (HashTable *ht, void *data, uint16_t datalen) |
Hashing function to be used to hash the Classtype name. Would be supplied as an argument to the HashTableInit function for DetectEngineCtx->class_conf_ht. More... | |
char | SCClassConfClasstypeHashCompareFunc (void *data1, uint16_t datalen1, void *data2, uint16_t datalen2) |
Used to compare two Classtypes that have been stored in the HashTable. This function is supplied as an argument to the HashTableInit function for DetectionEngineCtx->class_conf_ct. More... | |
void | SCClassConfClasstypeHashFree (void *ch) |
Used to free the Classification Config Hash Data that was stored in DetectEngineCtx->class_conf_ht Hashtable. More... | |
void | SCClassConfInit (DetectEngineCtx *de_ctx) |
void | SCClassConfDeinit (DetectEngineCtx *de_ctx) |
void | SCClassConfDeInitContext (DetectEngineCtx *de_ctx) |
Releases resources used by the Classification Config API. More... | |
int | SCClassConfAddClasstype (DetectEngineCtx *de_ctx, char *rawstr, uint16_t index) |
Parses a line from the classification file and adds it to Classtype hash table in DetectEngineCtx, i.e. DetectEngineCtx->class_conf_ht. More... | |
bool | SCClassConfLoadClassificationConfigFile (DetectEngineCtx *de_ctx, FILE *fd) |
Loads the Classtype info from the classification.config file. More... | |
SCClassConfClasstype * | SCClassConfGetClasstype (const char *ct_name, DetectEngineCtx *de_ctx) |
Gets the classtype from the corresponding hash table stored in the Detection Engine Context's class conf ht, given the classtype name. More... | |
FILE * | SCClassConfGenerateValidDummyClassConfigFD01 (void) |
Creates a dummy classification file, with all valid Classtypes, for testing purposes. More... | |
FILE * | SCClassConfGenerateInvalidDummyClassConfigFD02 (void) |
Creates a dummy classification file, with some valid Classtypes and a couple of invalid Classtypes, for testing purposes. More... | |
FILE * | SCClassConfGenerateInvalidDummyClassConfigFD03 (void) |
Creates a dummy classification file, with all invalid Classtypes, for testing purposes. More... | |
void | SCClassConfRegisterTests (void) |
This function registers unit tests for Classification Config API. More... | |
Used for parsing a classification.config file
Definition in file util-classification-config.c.
#define DETECT_CLASSCONFIG_REGEX "^\\s*config\\s*classification\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s*,\\s*(.+)\\s*,\\s*(\\d+)\\s*$" |
Definition at line 43 of file util-classification-config.c.
#define SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/classification.config" |
Definition at line 49 of file util-classification-config.c.
int SCClassConfAddClasstype | ( | DetectEngineCtx * | de_ctx, |
char * | rawstr, | ||
uint16_t | index | ||
) |
Parses a line from the classification file and adds it to Classtype hash table in DetectEngineCtx, i.e. DetectEngineCtx->class_conf_ht.
rawstr | Pointer to the string to be parsed. |
index | Relative index of the string to be parsed. |
de_ctx | Pointer to the Detection Engine Context. |
0 | On success. |
-1 | On failure. |
Definition at line 233 of file util-classification-config.c.
References DetectEngineCtx_::class_conf_regex, DetectEngineCtx_::class_conf_regex_match, CLASSTYPE_DESC_MAX_LEN, CLASSTYPE_NAME_MAX_LEN, de_ctx, and SCLogError.
char SCClassConfClasstypeHashCompareFunc | ( | void * | data1, |
uint16_t | datalen1, | ||
void * | data2, | ||
uint16_t | datalen2 | ||
) |
Used to compare two Classtypes that have been stored in the HashTable. This function is supplied as an argument to the HashTableInit function for DetectionEngineCtx->class_conf_ct.
data1 | Pointer to the first SCClassConfClasstype to be compared. |
len1 | Not used by this function. |
data2 | Pointer to the second SCClassConfClasstype to be compared. |
len2 | Not used by this function. |
1 | On data1 and data2 being equal. |
0 | On data1 and data2 not being equal. |
Definition at line 476 of file util-classification-config.c.
References SCClassConfClasstype_::classtype, and SCLogDebug.
void SCClassConfClasstypeHashFree | ( | void * | ch | ) |
Used to free the Classification Config Hash Data that was stored in DetectEngineCtx->class_conf_ht Hashtable.
ch | Pointer to the data that has to be freed. |
Definition at line 507 of file util-classification-config.c.
uint32_t SCClassConfClasstypeHashFunc | ( | HashTable * | ht, |
void * | data, | ||
uint16_t | datalen | ||
) |
Hashing function to be used to hash the Classtype name. Would be supplied as an argument to the HashTableInit function for DetectEngineCtx->class_conf_ht.
ht | Pointer to the HashTable. |
data | Pointer to the data to be hashed. In this case, the data would be a pointer to a SCClassConfClasstype instance. |
datalen | Not used by this function. |
Definition at line 447 of file util-classification-config.c.
References HashTable_::array_size, SCClassConfClasstype_::classtype, len, and u8_tolower.
void SCClassConfDeinit | ( | DetectEngineCtx * | de_ctx | ) |
Definition at line 81 of file util-classification-config.c.
References DetectEngineCtx_::class_conf_regex, DetectEngineCtx_::class_conf_regex_match, and de_ctx.
void SCClassConfDeInitContext | ( | DetectEngineCtx * | de_ctx | ) |
Releases resources used by the Classification Config API.
Definition at line 190 of file util-classification-config.c.
References DetectEngineCtx_::class_conf_ht, de_ctx, and HashTableFree().
Referenced by DetectEngineCtxFree().
FILE* SCClassConfGenerateInvalidDummyClassConfigFD02 | ( | void | ) |
Creates a dummy classification file, with some valid Classtypes and a couple of invalid Classtypes, for testing purposes.
\file_path Pointer to the file_path for the dummy classification file.
Definition at line 607 of file util-classification-config.c.
References SCFmemopen, and SCLogDebug.
FILE* SCClassConfGenerateInvalidDummyClassConfigFD03 | ( | void | ) |
Creates a dummy classification file, with all invalid Classtypes, for testing purposes.
\file_path Pointer to the file_path for the dummy classification file.
Definition at line 631 of file util-classification-config.c.
References SCFmemopen, and SCLogDebug.
FILE* SCClassConfGenerateValidDummyClassConfigFD01 | ( | void | ) |
Creates a dummy classification file, with all valid Classtypes, for testing purposes.
\file_path Pointer to the file_path for the dummy classification file.
Definition at line 587 of file util-classification-config.c.
References SCFmemopen, and SCLogDebug.
SCClassConfClasstype* SCClassConfGetClasstype | ( | const char * | ct_name, |
DetectEngineCtx * | de_ctx | ||
) |
Gets the classtype from the corresponding hash table stored in the Detection Engine Context's class conf ht, given the classtype name.
ct_name | Pointer to the classtype name that has to be looked up. |
de_ctx | Pointer to the Detection Engine Context. |
lookup_ct_info | Pointer to the SCClassConfClasstype instance from the hash table on success; NULL on failure. |
Definition at line 561 of file util-classification-config.c.
References DetectEngineCtx_::class_conf_ht, de_ctx, HashTableLookup(), and u8_tolower.
void SCClassConfInit | ( | DetectEngineCtx * | de_ctx | ) |
Definition at line 61 of file util-classification-config.c.
References DetectEngineCtx_::class_conf_regex, DetectEngineCtx_::class_conf_regex_match, de_ctx, DETECT_CLASSCONFIG_REGEX, and SCLogWarning.
bool SCClassConfLoadClassificationConfigFile | ( | DetectEngineCtx * | de_ctx, |
FILE * | fd | ||
) |
Loads the Classtype info from the classification.config file.
The classification.config file contains the different classtypes, that can be used to label Signatures. Each line of the file should have the following format - classtype_name, classtype_description, priority None of the above parameters should hold a quote inside the file.
de_ctx | Pointer to the Detection Engine Context that should be updated with Classtype information. |
Definition at line 524 of file util-classification-config.c.
void SCClassConfRegisterTests | ( | void | ) |
This function registers unit tests for Classification Config API.
Definition at line 783 of file util-classification-config.c.
References UtRegisterTest().