#endif
}
-void FTPAtExitPrintStats(void)
-{
-#ifdef DEBUG
- SCMutexLock(&ftp_state_mem_lock);
- SCLogDebug("ftp_state_memcnt %"PRIu64", ftp_state_memuse %"PRIu64"",
- ftp_state_memcnt, ftp_state_memuse);
- SCMutexUnlock(&ftp_state_mem_lock);
-#endif
-}
-
-
/*
* \brief Returns the ending offset of the next line from a multi-line buffer.
*
void RegisterFTPParsers(void);
void FTPParserRegisterTests(void);
-void FTPAtExitPrintStats(void);
void FTPParserCleanup(void);
uint64_t FTPMemuseGlobalCounter(void);
uint64_t FTPMemcapGlobalCounter(void);
* \param body pointer to the HtpBody holding the list
* \retval none
*/
-void HtpBodyPrint(HtpBody *body)
-{
- if (SCLogDebugEnabled()||1) {
- SCEnter();
-
- if (body->first == NULL)
- return;
-
- HtpBodyChunk *cur = NULL;
- SCLogDebug("--- Start body chunks at %p ---", body);
- printf("--- Start body chunks at %p ---\n", body);
- for (cur = body->first; cur != NULL; cur = cur->next) {
- const uint8_t *data = NULL;
- uint32_t data_len = 0;
- StreamingBufferSegmentGetData(body->sb, &cur->sbseg, &data, &data_len);
- SCLogDebug("Body %p; data %p, len %"PRIu32, body, data, data_len);
- printf("Body %p; data %p, len %"PRIu32"\n", body, data, data_len);
- PrintRawDataFp(stdout, data, data_len);
- }
- SCLogDebug("--- End body chunks at %p ---", body);
- }
-}
/**
* \brief Free the information held in the request body
#define SURICATA_APP_LAYER_HTP_BODY_H
int HtpBodyAppendChunk(const HTPCfgDir *, HtpBody *, const uint8_t *, uint32_t);
-void HtpBodyPrint(HtpBody *);
void HtpBodyFree(const HTPCfgDir *, HtpBody *);
void HtpBodyPrune(HtpState *, HtpBody *, int);
SCReturn;
}
-uint32_t AppLayerParserGetOptionFlags(uint8_t protomap, AppProto alproto)
-{
- SCEnter();
- SCReturnUInt(alp_ctx.ctxs[protomap][alproto].option_flags);
-}
-
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto,
void *(*StateAlloc)(void *, AppProto), void (*StateFree)(void *))
{
"AppLayerDecoderEvents *");
}
-void AppLayerParserSetDecoderEvents(AppLayerParserState *pstate, AppLayerDecoderEvents *devents)
-{
- pstate->decoder_events = devents;
-}
-
AppLayerDecoderEvents *AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto,
void *tx)
{
SCReturn;
}
-#ifdef DEBUG
-void AppLayerParserStatePrintDetails(AppLayerParserState *pstate)
-{
- SCEnter();
-
- if (pstate == NULL)
- SCReturn;
-
- AppLayerParserState *p = pstate;
- SCLogDebug("AppLayerParser parser state information for parser state p(%p). "
- "p->inspect_id[0](%"PRIu64"), "
- "p->inspect_id[1](%"PRIu64"), "
- "p->log_id(%"PRIu64"), "
- "p->decoder_events(%p).",
- pstate, p->inspect_id[0], p->inspect_id[1], p->log_id,
- p->decoder_events);
-
- SCReturn;
-}
-#endif
-
/***** Unittests *****/
#ifdef UNITTESTS
/***** Get and transaction functions *****/
-uint32_t AppLayerParserGetOptionFlags(uint8_t protomap, AppProto alproto);
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto,
const AppProto alproto);
void *alstate, const uint8_t flags, bool tag_txs_as_inspected);
AppLayerDecoderEvents *AppLayerParserGetDecoderEvents(AppLayerParserState *pstate);
-void AppLayerParserSetDecoderEvents(AppLayerParserState *pstate, AppLayerDecoderEvents *devents);
AppLayerDecoderEvents *AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *tx);
AppLayerGetFileState AppLayerParserGetTxFiles(
const Flow *f, void *state, void *tx, const uint8_t direction);
void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir);
-#ifdef DEBUG
-void AppLayerParserStatePrintDetails(AppLayerParserState *pstate);
-#endif
-
-
/***** Unittests *****/
#ifdef UNITTESTS
* \param file The name of the file
* \retval str Pointer to the string path + sig_file
*/
-char *ConfLoadCompleteIncludePath(const char *file)
-{
- const char *defaultpath = NULL;
- char *path = NULL;
-
- /* Path not specified */
- if (PathIsRelative(file)) {
- if (ConfGet("include-path", &defaultpath) == 1) {
- SCLogDebug("Default path: %s", defaultpath);
- size_t path_len = sizeof(char) * (strlen(defaultpath) +
- strlen(file) + 2);
- path = SCMalloc(path_len);
- if (unlikely(path == NULL))
- return NULL;
- strlcpy(path, defaultpath, path_len);
- if (path[strlen(path) - 1] != '/')
- strlcat(path, "/", path_len);
- strlcat(path, file, path_len);
- } else {
- path = SCStrdup(file);
- if (unlikely(path == NULL))
- return NULL;
- }
- } else {
- path = SCStrdup(file);
- if (unlikely(path == NULL))
- return NULL;
- }
- return path;
-}
/**
* \brief Prune a configuration node.
int ConfGetChildValueBool(const ConfNode *base, const char *name, int *val);
int ConfGetChildValueWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, const char **vptr);
int ConfGetChildValueIntWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, intmax_t *val);
-int ConfGetChildValueBoolWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, int *val);
-char *ConfLoadCompleteIncludePath(const char *);
+int ConfGetChildValueBoolWithDefault(
+ const ConfNode *base, const ConfNode *dflt, const char *name, int *val);
int ConfNodeIsSequence(const ConfNode *node);
ConfNode *ConfSetIfaceNode(const char *ifaces_node_name, const char *iface);
int ConfSetRootAndDefaultNodes(
return defrag_config.memcap_policy;
}
-uint32_t DefragTrackerSpareQueueGetSize(void)
-{
- return DefragTrackerQueueLen(&defragtracker_spare_q);
-}
-
void DefragTrackerMoveToSpare(DefragTracker *h)
{
DefragTrackerEnqueue(&defragtracker_spare_q, h);
void DefragTrackerRelease(DefragTracker *);
void DefragTrackerClearMemory(DefragTracker *);
void DefragTrackerMoveToSpare(DefragTracker *);
-uint32_t DefragTrackerSpareQueueGetSize(void);
int DefragTrackerSetMemcap(uint64_t);
uint64_t DefragTrackerGetMemcap(void);
DQLOCK_UNLOCK(q);
return dt;
}
-
-uint32_t DefragTrackerQueueLen(DefragTrackerQueue *q)
-{
- uint32_t len;
- DQLOCK_LOCK(q);
- len = q->len;
- DQLOCK_UNLOCK(q);
- return len;
-}
-
void DefragTrackerQueueDestroy (DefragTrackerQueue *);
void DefragTrackerEnqueue (DefragTrackerQueue *, DefragTracker *);
-DefragTracker *DefragTrackerDequeue (DefragTrackerQueue *);
-uint32_t DefragTrackerQueueLen(DefragTrackerQueue *);
+DefragTracker *DefragTrackerDequeue(DefragTrackerQueue *);
#endif /* SURICATA_DEFRAG_QUEUE_H */
return ag;
}
-#ifdef DEBUG
-/**
- * \brief Prints the address data information for all the DetectAddress
- * instances in the DetectAddress list sent as the argument.
- *
- * \param head Pointer to a list of DetectAddress instances.
- */
-void DetectAddressPrintList(DetectAddress *head)
-{
- SCLogInfo("list:");
- for (DetectAddress *cur = head; cur != NULL; cur = cur->next) {
- DetectAddressPrint(cur);
- }
- SCLogInfo("endlist");
-}
-#endif
-
/**
* \internal
* \brief Frees a list of DetectAddress instances.
const DetectAddressHead *DetectParseAddress(DetectEngineCtx *de_ctx,
const char *string, bool *contains_negation);
-#ifdef DEBUG
-void DetectAddressPrintList(DetectAddress *);
-#endif
-
#endif /* SURICATA_DETECT_ADDRESS_H */
mpm_table[mpm_matcher].DestroyCtx(mpm_ctx);
}
-void PatternMatchThreadPrint(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher)
-{
- SCLogDebug("mpm_thread_ctx %p, mpm_matcher %"PRIu16" defunct", mpm_thread_ctx, mpm_matcher);
- //mpm_table[mpm_matcher].PrintThreadCtx(mpm_thread_ctx);
-}
void PatternMatchThreadDestroy(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher)
{
SCLogDebug("mpm_thread_ctx %p, mpm_matcher %"PRIu16"", mpm_thread_ctx, mpm_matcher);
void PatternMatchDestroy(MpmCtx *, uint16_t);
void PatternMatchThreadDestroy(MpmThreadCtx *mpm_thread_ctx, uint16_t);
-void PatternMatchThreadPrint(MpmThreadCtx *, uint16_t);
int PatternMatchPrepareGroup(DetectEngineCtx *, SigGroupHead *);
-void DetectEngineThreadCtxInfo(ThreadVars *, DetectEngineThreadCtx *);
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **);
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *);
return ret;
}
-int SigGroupHeadHashRemove(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
-{
- return HashListTableRemove(de_ctx->sgh_hash_table, (void *)sgh, 0);
-}
-
/**
* \brief Used to lookup a SigGroupHead hash from the detection engine context
* SigGroupHead hash table.
int SigGroupHeadHashInit(DetectEngineCtx *);
-int SigGroupHeadHashRemove(DetectEngineCtx *, SigGroupHead *);
-
void SigGroupHeadInitDataFree(SigGroupHeadInitData *sghid);
void SigGroupHeadSetSigCnt(SigGroupHead *sgh, uint32_t max_idx);
bool SigGroupHeadEqual(const SigGroupHead *, const SigGroupHead *);
#endif
}
-/** \brief Reset the tagging engine context
- */
-void TagRestartCtx(void)
-{
- TagDestroyCtx();
- TagInitCtx();
-}
-
int TagHostHasTag(Host *host)
{
return HostGetStorageById(host, host_tag_id) ? 1 : 0;
void TagInitCtx(void);
void TagDestroyCtx(void);
-void TagRestartCtx(void);
int TagTimeoutCheck(Host *, SCTime_t);
}
}
-/** \brief register inspect engine at start up time
- *
- * \note errors are fatal */
-void DetectFrameInspectEngineRegister(const char *name, int dir,
- InspectionBufferFrameInspectFunc Callback, AppProto alproto, uint8_t type)
-{
- DetectBufferTypeRegister(name);
- const int sm_list = DetectBufferTypeGetByName(name);
- if (sm_list == -1) {
- FatalError("failed to register inspect engine %s", name);
- }
-
- if ((sm_list < DETECT_SM_LIST_MATCH) || (sm_list >= SHRT_MAX) || (Callback == NULL)) {
- SCLogError("Invalid arguments");
- BUG_ON(1);
- }
-
- uint8_t direction;
- if (dir == SIG_FLAG_TOSERVER) {
- direction = 0;
- } else {
- direction = 1;
- }
-
- DetectEngineFrameInspectionEngine *new_engine = SCCalloc(1, sizeof(*new_engine));
- if (unlikely(new_engine == NULL)) {
- FatalError("failed to register inspect engine %s: %s", name, strerror(errno));
- }
- new_engine->sm_list = (uint16_t)sm_list;
- new_engine->sm_list_base = (uint16_t)sm_list;
- new_engine->dir = direction;
- new_engine->v1.Callback = Callback;
- new_engine->alproto = alproto;
- new_engine->type = type;
-
- if (g_frame_inspect_engines == NULL) {
- g_frame_inspect_engines = new_engine;
- } else {
- DetectEngineFrameInspectionEngine *t = g_frame_inspect_engines;
- while (t->next != NULL) {
- t = t->next;
- }
-
- t->next = new_engine;
- }
-}
-
/** \brief register inspect engine at start up time
*
* \note errors are fatal */
return TM_ECODE_OK;
}
-void DetectEngineThreadCtxInfo(ThreadVars *t, DetectEngineThreadCtx *det_ctx)
-{
- /* XXX */
- PatternMatchThreadPrint(&det_ctx->mtc, det_ctx->de_ctx->mpm_matcher);
-}
-
static uint32_t DetectKeywordCtxHashFunc(HashListTable *ht, void *data, uint16_t datalen)
{
DetectEngineThreadKeywordCtxItem *ctx = data;
det_ctx->events++;
}
-AppLayerDecoderEvents *DetectEngineGetEvents(DetectEngineThreadCtx *det_ctx)
-{
- return det_ctx->decoder_events;
-}
-
/*************************************Unittest*********************************/
#ifdef UNITTESTS
InspectionBufferGetPktDataPtr GetPktData,
InspectionBufferPktInspectFunc Callback);
-void DetectFrameInspectEngineRegister(const char *name, int dir,
- InspectionBufferFrameInspectFunc Callback, AppProto alproto, uint8_t type);
void DetectEngineFrameInspectEngineRegister(DetectEngineCtx *de_ctx, const char *name, int dir,
InspectionBufferFrameInspectFunc Callback, AppProto alproto, uint8_t type);
/* events */
void DetectEngineSetEvent(DetectEngineThreadCtx *det_ctx, uint8_t e);
-AppLayerDecoderEvents *DetectEngineGetEvents(DetectEngineThreadCtx *det_ctx);
void DumpPatterns(DetectEngineCtx *de_ctx);
/* Start of "private" function */
-void *LiveDevAllocStorageById(LiveDevice *d, LiveDevStorageId id)
-{
- return StorageAllocByIdPrealloc(d->storage, STORAGE_DEVICE, id.id);
-}
-
-void LiveDevFreeStorageById(LiveDevice *d, LiveDevStorageId id)
-{
- StorageFreeById(d->storage, STORAGE_DEVICE, id.id);
-}
-
void LiveDevFreeStorage(LiveDevice *d)
{
if (LiveDevStorageSize() > 0)
void *LiveDevGetStorageById(LiveDevice *d, LiveDevStorageId id);
int LiveDevSetStorageById(LiveDevice *d, LiveDevStorageId id, void *ptr);
-void *LiveDevAllocStorageById(LiveDevice *d, LiveDevStorageId id);
-void LiveDevFreeStorageById(LiveDevice *d, LiveDevStorageId id);
void LiveDevFreeStorage(LiveDevice *d);
LiveDevStorageId LiveDevStorageRegister(const char *name, const unsigned int size,
return 0;
}
-bool FlowHasGaps(const Flow *f, uint8_t way)
-{
- if (f->proto == IPPROTO_TCP) {
- TcpSession *ssn = (TcpSession *)f->protoctx;
- if (ssn != NULL) {
- if (way == STREAM_TOCLIENT) {
- if (ssn->server.flags & STREAMTCP_STREAM_FLAG_HAS_GAP)
- return 1;
- } else {
- if (ssn->client.flags & STREAMTCP_STREAM_FLAG_HAS_GAP)
- return 1;
- }
- }
- }
- return 0;
-}
-
/** \brief Set flag to indicate to change proto for the flow
*
* \param f flow
void FlowSetIPOnlyFlag(Flow *, int);
void FlowSetHasAlertsFlag(Flow *);
int FlowHasAlerts(const Flow *);
-bool FlowHasGaps(const Flow *, uint8_t way);
void FlowSetChangeProtoFlag(Flow *);
void FlowUnsetChangeProtoFlag(Flow *);
int FlowChangeProto(Flow *);
HQLOCK_UNLOCK(q);
return h;
}
-
-uint32_t HostQueueLen(HostQueue *q)
-{
- uint32_t len;
- HQLOCK_LOCK(q);
- len = q->len;
- HQLOCK_UNLOCK(q);
- return len;
-}
-
void HostQueueDestroy (HostQueue *);
void HostEnqueue (HostQueue *, Host *);
-Host *HostDequeue (HostQueue *);
-uint32_t HostQueueLen(HostQueue *);
+Host *HostDequeue(HostQueue *);
#endif /* SURICATA_HOST_QUEUE_H */
return StorageAllocByIdPrealloc(h->storage, STORAGE_HOST, id.id);
}
-void HostFreeStorageById(Host *h, HostStorageId id)
-{
- StorageFreeById(h->storage, STORAGE_HOST, id.id);
-}
-
void HostFreeStorage(Host *h)
{
if (HostStorageSize() > 0)
int HostSetStorageById(Host *h, HostStorageId id, void *ptr);
void *HostAllocStorageById(Host *h, HostStorageId id);
-void HostFreeStorageById(Host *h, HostStorageId id);
void HostFreeStorage(Host *h);
void RegisterHostStorageTests(void);
#include "reputation.h"
-uint32_t HostGetSpareCount(void)
-{
- return HostSpareQueueGetSize();
-}
-
-uint32_t HostGetActiveCount(void)
-{
- return SC_ATOMIC_GET(host_counter);
-}
-
/** \internal
* \brief See if we can really discard this host. Check use_cnt reference.
*
uint32_t HostTimeoutHash(SCTime_t ts);
-uint32_t HostGetSpareCount(void);
-uint32_t HostGetActiveCount(void);
-
#endif
return memuse;
}
-uint32_t HostSpareQueueGetSize(void)
-{
- return HostQueueLen(&host_spare_q);
-}
-
void HostMoveToSpare(Host *h)
{
HostEnqueue(&host_spare_q, h);
void HostLock(Host *);
void HostClearMemory(Host *);
void HostMoveToSpare(Host *);
-uint32_t HostSpareQueueGetSize(void);
void HostPrintStats (void);
void HostRegisterUnittests(void);
HQLOCK_UNLOCK(q);
return h;
}
-
-uint32_t IPPairQueueLen(IPPairQueue *q)
-{
- uint32_t len;
- HQLOCK_LOCK(q);
- len = q->len;
- HQLOCK_UNLOCK(q);
- return len;
-}
void IPPairQueueDestroy (IPPairQueue *);
void IPPairEnqueue (IPPairQueue *, IPPair *);
-IPPair *IPPairDequeue (IPPairQueue *);
-uint32_t IPPairQueueLen(IPPairQueue *);
+IPPair *IPPairDequeue(IPPairQueue *);
#endif /* SURICATA_IPPAIR_QUEUE_H */
return StorageAllocByIdPrealloc(h->storage, STORAGE_IPPAIR, id.id);
}
-void IPPairFreeStorageById(IPPair *h, IPPairStorageId id)
-{
- StorageFreeById(h->storage, STORAGE_IPPAIR, id.id);
-}
-
void IPPairFreeStorage(IPPair *h)
{
if (IPPairStorageSize() > 0)
int IPPairSetStorageById(IPPair *h, IPPairStorageId id, void *ptr);
void *IPPairAllocStorageById(IPPair *h, IPPairStorageId id);
-void IPPairFreeStorageById(IPPair *h, IPPairStorageId id);
void IPPairFreeStorage(IPPair *h);
void RegisterIPPairStorageTests(void);
#include "ippair-timeout.h"
#include "detect-engine-threshold.h"
-uint32_t IPPairGetSpareCount(void)
-{
- return IPPairSpareQueueGetSize();
-}
-
-uint32_t IPPairGetActiveCount(void)
-{
- return SC_ATOMIC_GET(ippair_counter);
-}
-
/** \internal
* \brief See if we can really discard this ippair. Check use_cnt reference.
*
uint32_t IPPairTimeoutHash(SCTime_t ts);
-uint32_t IPPairGetSpareCount(void);
-uint32_t IPPairGetActiveCount(void);
-
#endif
return memusecopy;
}
-uint32_t IPPairSpareQueueGetSize(void)
-{
- return IPPairQueueLen(&ippair_spare_q);
-}
-
void IPPairMoveToSpare(IPPair *h)
{
IPPairEnqueue(&ippair_spare_q, h);
SCMutexUnlock(&h->m);
}
-void IPPairLock(IPPair *h)
-{
- SCMutexLock(&h->m);
-}
-
void IPPairUnlock(IPPair *h)
{
SCMutexUnlock(&h->m);
IPPair *IPPairLookupIPPairFromHash (Address *, Address *);
IPPair *IPPairGetIPPairFromHash (Address *, Address *);
void IPPairRelease(IPPair *);
-void IPPairLock(IPPair *);
void IPPairClearMemory(IPPair *);
void IPPairMoveToSpare(IPPair *);
-uint32_t IPPairSpareQueueGetSize(void);
void IPPairPrintStats (void);
void IPPairRegisterUnittests(void);
IPPair *IPPairAlloc(void);
void IPPairFree(IPPair *);
-void IPPairLock(IPPair *);
void IPPairUnlock(IPPair *);
int IPPairSetMemcap(uint64_t size);
return TM_ECODE_OK;
}
-void OutputFlowLogExitPrintStats(ThreadVars *tv, void *thread_data)
-{
- OutputFlowLoggerThreadData *op_thread_data = (OutputFlowLoggerThreadData *)thread_data;
- OutputLoggerThreadStore *store = op_thread_data->store;
- OutputFlowLogger *logger = list;
-
- while (logger && store) {
- if (logger->ThreadExitPrintStats) {
- logger->ThreadExitPrintStats(tv, store->thread_data);
- }
-
- logger = logger->next;
- store = store->next;
- }
-}
-
void OutputFlowShutdown(void)
{
OutputFlowLogger *logger = list;
TmEcode OutputFlowLog(ThreadVars *tv, void *thread_data, Flow *f);
TmEcode OutputFlowLogThreadInit(ThreadVars *tv, void *initdata, void **data);
TmEcode OutputFlowLogThreadDeinit(ThreadVars *tv, void *thread_data);
-void OutputFlowLogExitPrintStats(ThreadVars *tv, void *thread_data);
#endif /* SURICATA_OUTPUT_FLOW_H */
ThreadExitPrintStats);
}
-/**
- * \brief Register a file output module.
- *
- * This function will register an output module so it can be
- * configured with the configuration file.
- *
- * \retval Returns 0 on success, -1 on failure.
- */
-void OutputRegisterFileModule(LoggerId id, const char *name,
- const char *conf_name, OutputInitFunc InitFunc, FileLogger FileLogFunc,
- ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
- ThreadExitPrintStatsFunc ThreadExitPrintStats)
-{
- if (unlikely(FileLogFunc == NULL)) {
- goto error;
- }
-
- OutputModule *module = SCCalloc(1, sizeof(*module));
- if (unlikely(module == NULL)) {
- goto error;
- }
-
- module->logger_id = id;
- module->name = name;
- module->conf_name = conf_name;
- module->InitFunc = InitFunc;
- module->FileLogFunc = FileLogFunc;
- module->ThreadInit = ThreadInit;
- module->ThreadDeinit = ThreadDeinit;
- module->ThreadExitPrintStats = ThreadExitPrintStats;
- TAILQ_INSERT_TAIL(&output_modules, module, entries);
-
- SCLogDebug("File logger \"%s\" registered.", name);
- return;
-error:
- FatalError("Fatal error encountered. Exiting...");
-}
-
/**
* \brief Register a file output sub-module.
*
FatalError("Fatal error encountered. Exiting...");
}
-/**
- * \brief Register a file data output sub-module.
- *
- * This function will register an output module so it can be
- * configured with the configuration file.
- *
- * \retval Returns 0 on success, -1 on failure.
- */
-void OutputRegisterFiledataSubModule(LoggerId id, const char *parent_name,
- const char *name, const char *conf_name, OutputInitSubFunc InitFunc,
- FiledataLogger FiledataLogFunc, ThreadInitFunc ThreadInit,
- ThreadDeinitFunc ThreadDeinit,
- ThreadExitPrintStatsFunc ThreadExitPrintStats)
-{
- if (unlikely(FiledataLogFunc == NULL)) {
- goto error;
- }
-
- OutputModule *module = SCCalloc(1, sizeof(*module));
- if (unlikely(module == NULL)) {
- goto error;
- }
-
- module->logger_id = id;
- module->name = name;
- module->conf_name = conf_name;
- module->parent_name = parent_name;
- module->InitSubFunc = InitFunc;
- module->FiledataLogFunc = FiledataLogFunc;
- module->ThreadInit = ThreadInit;
- module->ThreadDeinit = ThreadDeinit;
- module->ThreadExitPrintStats = ThreadExitPrintStats;
- TAILQ_INSERT_TAIL(&output_modules, module, entries);
-
- SCLogDebug("Filedata logger \"%s\" registered.", name);
- return;
-error:
- FatalError("Fatal error encountered. Exiting...");
-}
-
/**
* \brief Register a flow output sub-module.
*
FatalError("Fatal error encountered. Exiting...");
}
-/**
- * \brief Register a streaming data output sub-module.
- *
- * This function will register an output module so it can be
- * configured with the configuration file.
- *
- * \retval Returns 0 on success, -1 on failure.
- */
-void OutputRegisterStreamingSubModule(LoggerId id, const char *parent_name,
- const char *name, const char *conf_name, OutputInitSubFunc InitFunc,
- StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type,
- ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
- ThreadExitPrintStatsFunc ThreadExitPrintStats)
-{
- if (unlikely(StreamingLogFunc == NULL)) {
- goto error;
- }
-
- OutputModule *module = SCCalloc(1, sizeof(*module));
- if (unlikely(module == NULL)) {
- goto error;
- }
-
- module->logger_id = id;
- module->name = name;
- module->conf_name = conf_name;
- module->parent_name = parent_name;
- module->InitSubFunc = InitFunc;
- module->StreamingLogFunc = StreamingLogFunc;
- module->stream_type = stream_type;
- module->ThreadInit = ThreadInit;
- module->ThreadDeinit = ThreadDeinit;
- module->ThreadExitPrintStats = ThreadExitPrintStats;
- TAILQ_INSERT_TAIL(&output_modules, module, entries);
-
- SCLogDebug("Streaming logger \"%s\" registered.", name);
- return;
-error:
- FatalError("Fatal error encountered. Exiting...");
-}
-
/**
* \brief Register a stats data output module.
*
ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats);
-void OutputRegisterFileModule(LoggerId id, const char *name,
- const char *conf_name, OutputInitFunc InitFunc,
- FileLogger FileLogFunc, ThreadInitFunc ThreadInit,
- ThreadDeinitFunc ThreadDeinit,
- ThreadExitPrintStatsFunc ThreadExitPrintStats);
void OutputRegisterFileSubModule(LoggerId id, const char *parent_name,
const char *name, const char *conf_name,
OutputInitSubFunc InitFunc, FileLogger FileLogFunc,
ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats);
-void OutputRegisterFiledataModule(LoggerId id, const char *name,
- const char *conf_name, OutputInitFunc InitFunc,
- FiledataLogger FiledataLogFunc, ThreadInitFunc ThreadInit,
- ThreadDeinitFunc ThreadDeinit,
- ThreadExitPrintStatsFunc ThreadExitPrintStats);
-void OutputRegisterFiledataSubModule(LoggerId, const char *parent_name,
- const char *name, const char *conf_name, OutputInitSubFunc InitFunc,
- FiledataLogger FiledataLogFunc, ThreadInitFunc ThreadInit,
- ThreadDeinitFunc ThreadDeinit,
- ThreadExitPrintStatsFunc ThreadExitPrintStats);
+void OutputRegisterFiledataModule(LoggerId id, const char *name, const char *conf_name,
+ OutputInitFunc InitFunc, FiledataLogger FiledataLogFunc, ThreadInitFunc ThreadInit,
+ ThreadDeinitFunc ThreadDeinit, ThreadExitPrintStatsFunc ThreadExitPrintStats);
void OutputRegisterFlowSubModule(LoggerId id, const char *parent_name,
const char *name, const char *conf_name, OutputInitSubFunc InitFunc,
ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats);
-void OutputRegisterStreamingModule(LoggerId id, const char *name,
- const char *conf_name, OutputInitFunc InitFunc,
- StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type,
- ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
- ThreadExitPrintStatsFunc ThreadExitPrintStats);
-void OutputRegisterStreamingSubModule(LoggerId id, const char *parent_name,
- const char *name, const char *conf_name,
- OutputInitSubFunc InitFunc, StreamingLogger StreamingLogFunc,
- enum OutputStreamingType stream_type,
- ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
- ThreadExitPrintStatsFunc ThreadExitPrintStats);
+void OutputRegisterStreamingModule(LoggerId id, const char *name, const char *conf_name,
+ OutputInitFunc InitFunc, StreamingLogger StreamingLogFunc,
+ enum OutputStreamingType stream_type, ThreadInitFunc ThreadInit,
+ ThreadDeinitFunc ThreadDeinit, ThreadExitPrintStatsFunc ThreadExitPrintStats);
void OutputRegisterStatsModule(LoggerId id, const char *name,
const char *conf_name, OutputInitFunc InitFunc,
return 0;
}
-int RunModeNapatechAutoFp(void)
-{
- return NapatechInit(NT_RUNMODE_AUTOFP);
-}
-
int RunModeNapatechWorkers(void)
{
return NapatechInit(NT_RUNMODE_WORKERS);
#include <nt.h>
#endif /* HAVE_NAPATECH */
-int RunModeNapatechAutoFp(void);
int RunModeNapatechWorkers(void);
void RunModeNapatechRegister(void);
const char *RunModeNapatechGetDefaultMode(void);
static int filedata_logger_count = 0;
static LoggerId logger_bits[ALPROTO_MAX];
-int RunModeOutputFileEnabled(void)
-{
- return file_logger_count > 0;
-}
-
int RunModeOutputFiledataEnabled(void)
{
return filedata_logger_count > 0;
void RunModeInitializeOutputs(void);
void RunModeShutDown(void);
-/* bool indicating if file logger is enabled */
-int RunModeOutputFileEnabled(void);
/* bool indicating if filedata logger is enabled */
int RunModeOutputFiledataEnabled(void);
/** bool indicating if run mode is offline */
SCReturnInt(TM_ECODE_OK);
}
-void AFXDPMutexClean(void)
-{
- SCMutexDestroy(&xsk_protect.queue_protect);
-}
-
static TmEcode AFXDPAssignQueueID(AFXDPThreadVars *ptv)
{
if (ptv->xsk.queue.assigned == false) {
void TmModuleDecodeAFXDPRegister(void);
TmEcode AFXDPQueueProtectionInit(void);
-void AFXDPMutexClean(void);
#endif /* SURICATA_SOURCE_AFXDP_H */
}
}
-uint64_t StreamTcpGetAcked(const TcpStream *stream)
-{
- return GetAbsLastAck(stream);
-}
-
// may contain gaps
uint64_t StreamDataRightEdge(const TcpStream *stream, const bool eof)
{
* \param stream Reassembled stream returned from the reassembly functions
*/
-int StreamTcpCheckStreamContents(uint8_t *stream_policy, uint16_t sp_size, TcpStream *stream)
-{
- if (StreamingBufferCompareRawData(&stream->sb, stream_policy,(uint32_t)sp_size) == 0)
- {
- //PrintRawDataFp(stdout, stream_policy, sp_size);
- return 0;
- }
- return 1;
-}
-
static int VALIDATE(TcpStream *stream, uint8_t *data, uint32_t data_len)
{
if (StreamingBufferCompareRawData(&stream->sb,
void StreamTcpDisableAppLayer(Flow *f);
int StreamTcpAppLayerIsDisabled(Flow *f);
-#ifdef UNITTESTS
-int StreamTcpCheckStreamContents(uint8_t *, uint16_t , TcpStream *);
-#endif
-
bool StreamReassembleRawHasDataReady(TcpSession *ssn, Packet *p);
void StreamTcpReassemblySetMinInspectDepth(TcpSession *ssn, int direction, uint32_t depth);
void StreamTcpUpdateAppLayerProgress(TcpSession *ssn, char direction,
const uint32_t progress);
-uint64_t StreamTcpGetAcked(const TcpStream *stream);
uint64_t StreamTcpGetUsable(const TcpStream *stream, const bool eof);
uint64_t StreamDataRightEdge(const TcpStream *stream, const bool eof);
return NULL;
}
-/** \brief get the id of a module from it's name
- * \param name registered name of the module
- * \retval id the id or -1 in case of error */
-int TmModuleGetIdByName(const char *name)
-{
- TmModule *tm = TmModuleGetByName(name);
- if (tm == NULL)
- return -1;
- return TmModuleGetIDForTM(tm);
-}
-
/**
* \brief Returns a TM Module by its id.
*
TmModule *TmModuleGetByName(const char *name);
TmModule *TmModuleGetById(int id);
-int TmModuleGetIdByName(const char *name);
int TmModuleGetIDForTM(TmModule *tm);
TmEcode TmModuleRegister(char *name, int (*module_func)(ThreadVars *, Packet *, void *));
void TmModuleDebugList(void);
}
}
-void PacketPoolInitEmpty(void)
-{
- PktPool *my_pool = GetThreadPacketPool();
-
-#ifdef DEBUG_VALIDATION
- BUG_ON(my_pool->initialized);
- my_pool->initialized = 1;
- my_pool->destroyed = 0;
-#endif /* DEBUG_VALIDATION */
-
- SCMutexInit(&my_pool->return_stack.mutex, NULL);
- SCCondInit(&my_pool->return_stack.cond, NULL);
- SC_ATOMIC_INIT(my_pool->return_stack.return_threshold);
- SC_ATOMIC_SET(my_pool->return_stack.return_threshold, 32);
-}
-
void PacketPoolInit(void)
{
PktPool *my_pool = GetThreadPacketPool();
void PacketPoolWait(void);
void PacketPoolReturnPacket(Packet *p);
void PacketPoolInit(void);
-void PacketPoolInitEmpty(void);
void PacketPoolDestroy(void);
void PacketPoolPostRunmodes(void);
}
}
-void BloomFilterCountingPrint(BloomFilterCounting *bf)
-{
- printf("\n------ Counting Bloom Filter Stats ------\n");
- printf("Buckets: %" PRIu32 "\n", bf->array_size);
- printf("Counter size: %" PRIu32 "\n", bf->type);
- printf("Memory size: %" PRIu32 " bytes\n", bf->array_size * bf->type);
- printf("Hash function pointer: %p\n", bf->Hash);
- printf("Hash functions: %" PRIu32 "\n", bf->hash_iterations);
- printf("-----------------------------------------\n");
-}
-
int BloomFilterCountingAdd(BloomFilterCounting *bf, const void *data, uint16_t datalen)
{
uint8_t iter = 0;
/* prototypes */
BloomFilterCounting *BloomFilterCountingInit(uint32_t, uint8_t, uint8_t, uint32_t (*Hash)(const void *, uint16_t, uint8_t, uint32_t));
void BloomFilterCountingFree(BloomFilterCounting *);
-void BloomFilterCountingPrint(BloomFilterCounting *);
int BloomFilterCountingAdd(BloomFilterCounting *, const void *, uint16_t);
int BloomFilterCountingRemove(BloomFilterCounting *, const void *, uint16_t);
int BloomFilterCountingTest(BloomFilterCounting *, const void *, uint16_t);
}
}
-void BloomFilterPrint(BloomFilter *bf)
-{
- printf("\n---------- Bloom Filter Stats -----------\n");
- printf("Buckets: %" PRIu32 "\n", bf->bitarray_size);
- printf("Memory size: %" PRIu32 " bytes\n", bf->bitarray_size/8 + 1);
- printf("Hash function pointer: %p\n", bf->Hash);
- printf("Hash functions: %" PRIu32 "\n", bf->hash_iterations);
- printf("-----------------------------------------\n");
-}
-
int BloomFilterAdd(BloomFilter *bf, const void *data, uint16_t datalen)
{
uint8_t iter = 0;
return 0;
}
-uint32_t BloomFilterMemoryCnt(BloomFilter *bf)
-{
- if (bf == NULL)
- return 0;
-
- return 2;
-}
-
-uint32_t BloomFilterMemorySize(BloomFilter *bf)
-{
- if (bf == NULL)
- return 0;
-
- return (sizeof(BloomFilter) + (bf->bitarray_size/8) + 1);
-}
-
/*
* ONLY TESTS BELOW THIS COMMENT
*/
/* prototypes */
BloomFilter *BloomFilterInit(uint32_t, uint8_t, uint32_t (*Hash)(const void *, uint16_t, uint8_t, uint32_t));
void BloomFilterFree(BloomFilter *);
-void BloomFilterPrint(BloomFilter *);
int BloomFilterAdd(BloomFilter *, const void *, uint16_t);
-uint32_t BloomFilterMemoryCnt(BloomFilter *);
-uint32_t BloomFilterMemorySize(BloomFilter *);
void BloomFilterRegisterTests(void);
#endif
}
-/**
- * \brief Get the maximum number of cpus allowed in the system
- * This syscall is present on Solaris, but it's not on linux
- * or macosx. Maybe you should look at UtilCpuGetNumProcessorsConfigured()
- * \retval 0 if the syscall is not available or we have an error;
- * otherwise it will return the number of cpus allowed
- */
-uint16_t UtilCpuGetNumProcessorsMax(void)
-{
-#ifdef SYSCONF_NPROCESSORS_MAX_COMPAT
- long nprocs = -1;
- nprocs = sysconf(_SC_NPROCESSORS_MAX);
- if (nprocs < 1) {
- SCLogError("Couldn't retrieve the maximum number of cpus "
- "allowed by the system (%s)",
- strerror(errno));
- return 0;
- }
-
- if (nprocs > UINT16_MAX) {
- SCLogDebug("It seems that the system support more that %"PRIu16" CPUs. You "
- "can modify util-cpu.{c,h} to use uint32_t to support it", UINT16_MAX);
- return UINT16_MAX;
- }
-
- return (uint16_t)nprocs;
-#else
- SCLogError("Couldn't retrieve the maximum number of cpus allowed by "
- "the system, synconf macro unavailable");
- return 0;
-#endif
-}
-
/**
* \brief Print a summary of CPUs detected (configured and online)
*/
/* Processors online: */
uint16_t UtilCpuGetNumProcessorsOnline(void);
-/* Only on Solaris */
-uint16_t UtilCpuGetNumProcessorsMax(void);
-
void UtilCpuPrintSummary(void);
uint64_t UtilCpuGetTicks(void);
return SCLogMatchFGFilter(file, function, line, SC_LOG_FILTER_BL);
}
-/**
- * \brief Adds a Whitelist(WL) fine-grained(FG) filter. A FG filter WL filter
- * allows messages that match this filter, to be logged, while the filter
- * is defined using a file_name, function_name and line_number.
- *
- * If a particular parameter in the fg-filter(file, function and line),
- * shouldn't be considered while logging the message, one can supply
- * NULL for the file_name or function_name and a negative line_no.
- *
- * \param file File_name of the filter
- * \param function Function_name of the filter
- * \param line Line number of the filter
- *
- * \retval 0 on successfully adding the filter;
- * \retval -1 on failure
- */
-int SCLogAddFGFilterWL(const char *file, const char *function, int line)
-{
- return SCLogAddFGFilter(file, function, line, SC_LOG_FILTER_WL);
-}
-
/**
* \brief Adds a Blacklist(BL) fine-grained(FG) filter. A FG filter BL filter
* allows messages that don't match this filter, to be logged, while the
extern int sc_log_fd_filters_present;
-
-int SCLogAddFGFilterWL(const char *, const char *, int);
-
int SCLogAddFGFilterBL(const char *, const char *, int);
int SCLogMatchFGFilterBL(const char *, const char *, int);
return 0;
}
-/**
- * Set number of currently bypassed flows for a protocol family
- *
- * \param dev pointer to LiveDevice to set stats for
- * \param cnt number of currently bypassed flows
- * \param family AF_INET to set IPv4 count or AF_INET6 to set IPv6 count
- */
-void LiveDevSetBypassStats(LiveDevice *dev, uint64_t cnt, int family)
-{
- BypassInfo *bpfdata = LiveDevGetStorageById(dev, g_bypass_storage_id);
- if (bpfdata) {
- if (family == AF_INET) {
- SC_ATOMIC_SET(bpfdata->ipv4_hash_count, cnt);
- } else if (family == AF_INET6) {
- SC_ATOMIC_SET(bpfdata->ipv6_hash_count, cnt);
- }
- }
-}
-
/**
* Increase number of currently bypassed flows for a protocol family
*
int LiveRegisterDeviceName(const char *dev);
int LiveRegisterDevice(const char *dev);
int LiveDevUseBypass(LiveDevice *dev);
-void LiveDevSetBypassStats(LiveDevice *dev, uint64_t cnt, int family);
void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family);
void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family);
void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family);
SCFree(ht);
}
-void HashTablePrint(HashTable *ht)
-{
- printf("\n----------- Hash Table Stats ------------\n");
- printf("Buckets: %" PRIu32 "\n", ht->array_size);
- printf("Hash function pointer: %p\n", ht->Hash);
- printf("-----------------------------------------\n");
-}
-
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
{
if (ht == NULL || data == NULL)
/* prototypes */
HashTable* HashTableInit(uint32_t, uint32_t (*Hash)(struct HashTable_ *, void *, uint16_t), char (*Compare)(void *, uint16_t, void *, uint16_t), void (*Free)(void *));
void HashTableFree(HashTable *);
-void HashTablePrint(HashTable *);
int HashTableAdd(HashTable *, void *, uint16_t);
int HashTableRemove(HashTable *, void *, uint16_t);
void *HashTableLookup(HashTable *, void *, uint16_t);
SCFree(ht);
}
-void HashListTablePrint(HashListTable *ht)
-{
- printf("\n----------- Hash Table Stats ------------\n");
- printf("Buckets: %" PRIu32 "\n", ht->array_size);
- printf("Hash function pointer: %p\n", ht->Hash);
- printf("-----------------------------------------\n");
-}
-
int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen)
{
if (ht == NULL || data == NULL)
/* prototypes */
HashListTable* HashListTableInit(uint32_t, uint32_t (*Hash)(struct HashListTable_ *, void *, uint16_t), char (*Compare)(void *, uint16_t, void *, uint16_t), void (*Free)(void *));
void HashListTableFree(HashListTable *);
-void HashListTablePrint(HashListTable *);
int HashListTableAdd(HashListTable *, void *, uint16_t);
int HashListTableRemove(HashListTable *, void *, uint16_t);
void *HashListTableLookup(HashListTable *, void *, uint16_t);
SCFree(p);
}
-void PoolPrint(Pool *p)
-{
- printf("\n----------- Hash Table Stats ------------\n");
- printf("Buckets: %" PRIu32 "\n", p->empty_stack_size + p->alloc_stack_size);
- printf("-----------------------------------------\n");
-}
-
void *PoolGet(Pool *p)
{
SCEnter();
SCReturn;
}
-void PoolPrintSaturation(Pool *p)
-{
- if (p->max_buckets > 0) {
- SCLogDebug("pool %p is using %" PRIu32 " out of %" PRIu32 " items (%02.1f%%), max %" PRIu32
- " (%02.1f%%): pool struct memory %" PRIu64 ".",
- p, p->outstanding, p->max_buckets,
- (float)(p->outstanding) / (float)(p->max_buckets) * 100, p->max_outstanding,
- (float)(p->max_outstanding) / (float)(p->max_buckets) * 100,
- (uint64_t)(p->max_buckets * sizeof(PoolBucket)));
- }
-}
-
/*
* ONLY TESTS BELOW THIS COMMENT
*/
/* prototypes */
Pool* PoolInit(uint32_t, uint32_t, uint32_t, void *(*Alloc)(void), int (*Init)(void *, void *), void *, void (*Cleanup)(void *), void (*Free)(void *));
void PoolFree(Pool *);
-void PoolPrint(Pool *);
-void PoolPrintSaturation(Pool *p);
void *PoolGet(Pool *);
void PoolReturn(Pool *, void *);
}
}
-void PrintRawJsonFp(FILE *fp, uint8_t *buf, uint32_t buflen)
-{
-#define BUFFER_LENGTH 2048
- char nbuf[BUFFER_LENGTH] = "";
- uint32_t offset = 0;
-
- for (uint32_t u = 0; u < buflen; u++) {
- if (buf[u] == '\\' || buf[u] == '/' || buf[u] == '\"') {
- PrintBufferData(nbuf, &offset, BUFFER_LENGTH,
- "\\%c", buf[u]);
- } else if (isprint(buf[u])) {
- PrintBufferData(nbuf, &offset, BUFFER_LENGTH,
- "%c", buf[u]);
- } else {
- PrintBufferData(nbuf, &offset, BUFFER_LENGTH,
- "\\\\x%02X", buf[u]);
- }
- }
- fprintf(fp, "%s", nbuf);
-}
-
void PrintRawUriFp(FILE *fp, uint8_t *buf, uint32_t buflen)
{
#define BUFFER_LENGTH 2048
void PrintBufferRawLineHex(char *, int *,int, const uint8_t *, uint32_t);
void PrintRawUriFp(FILE *, uint8_t *, uint32_t);
-void PrintRawUriBuf(char *, uint32_t *, uint32_t,
- uint8_t *, uint32_t);
-void PrintRawJsonFp(FILE *, uint8_t *, uint32_t);
+void PrintRawUriBuf(char *, uint32_t *, uint32_t, uint8_t *, uint32_t);
void PrintRawDataFp(FILE *, const uint8_t *, uint32_t);
void PrintRawDataToBuffer(uint8_t *dst_buf, uint32_t *dst_buf_offset_ptr, uint32_t dst_buf_size,
const uint8_t *src_buf, uint32_t src_buf_len);
return;
}
-/**
- * \brief Removes a key from the Radix tree
- *
- * \param key_stream Data that has to be removed from the Radix tree
- * \param key_bitlen The bitlen of the above stream.
- * \param tree Pointer to the Radix tree from which the key has to be
- * removed
- */
-void SCRadixRemoveKeyGeneric(uint8_t *key_stream, uint16_t key_bitlen,
- SCRadixTree *tree)
-{
- SCRadixRemoveKey(key_stream, key_bitlen, tree, 255);
- return;
-}
-
/**
* \brief Removes an IPV4 address netblock key from the Radix tree.
*
bool SCRadixAddKeyIPV4String(const char *, SCRadixTree *, void *);
bool SCRadixAddKeyIPV6String(const char *, SCRadixTree *, void *);
-void SCRadixRemoveKeyGeneric(uint8_t *, uint16_t, SCRadixTree *);
void SCRadixRemoveKeyIPV4Netblock(uint8_t *, SCRadixTree *, uint8_t);
void SCRadixRemoveKeyIPV4(uint8_t *, SCRadixTree *);
void SCRadixRemoveKeyIPV6Netblock(uint8_t *, SCRadixTree *, uint8_t);
return;
}
-
-#if 0
-int UtilSignalIsHandler(int sig, void (*handler)(int))
-{
- struct sigaction action;
- memset(&action, 0x00, sizeof(struct sigaction));
-
- sigaction(sig, NULL, &action);
-
- return (action.sa_handler == handler);
-}
-#endif
int UtilSignalBlock(int);
int UtilSignalUnblock(int);
void UtilSignalHandlerSetup(int, void (*handler)(int));
-#if 0
-int UtilSignalIsHandler(int sig, void (*handler)(int));
-#endif
#endif /* SURICATA_UTIL_SIGNAL_H */
return NULL;
}
-
-void BasicSearchInit (void)
-{
- /* nothing no more */
-}
-
uint8_t *BasicSearch(const uint8_t *, uint32_t, const uint8_t *, uint16_t);
uint8_t *BasicSearchNocase(const uint8_t *, uint32_t, const uint8_t *, uint16_t);
-void BasicSearchInit (void);
#endif /* SURICATA_UTIL_SPM_BS */
badchars[needle[i]] = 0;
}
-/**
- * \brief Array setup function for Bs2BmNocase of bad characters index (not found at the needle)
- *
- * \param needle pointer to the pattern we ar searching for
- * \param needle_len length limit of the needle
- * \param badchars pointer to an empty array of bachars. The array prepared contains
- * characters that can't be inside the needle_len. So the skips can be
- * faster
- */
-void Bs2BmBadcharsNocase(const uint8_t *needle, uint16_t needle_len, uint8_t *badchars)
-{
- uint32_t i;
- for (i = 0; i < ALPHABET_SIZE; i++)
- badchars[i] = 1;
-
- /* set to 0 the values where index as ascii is present
- * because they are not badchars
- */
- for (i = 0; i < needle_len; i++) {
- badchars[u8_tolower(needle[i])] = 0;
- }
-}
-
/**
* \brief Basic search with a bad characters array. The array badchars contains
* flags at character's ascii index that can't be inside the needle. So the skips can be
#define ALPHABET_SIZE 256
void Bs2BmBadchars(const uint8_t *, uint16_t, uint8_t *);
-void Bs2BmBadcharsNocase(const uint8_t *, uint16_t, uint8_t *);
uint8_t *Bs2Bm(const uint8_t *, uint32_t, const uint8_t *, uint16_t, const uint8_t[]);
uint8_t *Bs2BmNocase(const uint8_t *, uint32_t, const uint8_t *, uint16_t, const uint8_t[]);
return Bs2Bm(text, textlen, needle, needlelen, badchars);
}
-/**
- * \brief Search a pattern in the text using the Bs2Bm nocase algorithm (build a bad characters array)
- *
- * \param text Text to search in
- * \param textlen length of the text
- * \param needle pattern to search for
- * \param needlelen length of the pattern
- */
-uint8_t *Bs2bmNocaseSearch(const uint8_t *text, uint32_t textlen,
- const uint8_t *needle, uint16_t needlelen)
-{
- uint8_t badchars[ALPHABET_SIZE];
- Bs2BmBadchars(needle, needlelen, badchars);
-
- return Bs2BmNocase(text, textlen, needle, needlelen, badchars);
-}
-
/**
* \brief Search a pattern in the text using Boyer Moore algorithm
* (build a bad character shifts array and good prefixes shift array)
const uint8_t *haystack, uint32_t haystack_len);
/** Default algorithm to use: Boyer Moore */
-uint8_t *Bs2bmSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
-uint8_t *Bs2bmNocaseSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
+uint8_t *Bs2bmSearch(
+ const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
uint8_t *BoyerMooreSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
uint8_t *BoyerMooreNocaseSearch(const uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
}
}
}
-
-#ifdef UNITTESTS
-
-static void *StorageTestAlloc(unsigned int size)
-{
- void *x = SCMalloc(size);
- return x;
-}
-static void StorageTestFree(void *x)
-{
- if (x)
- SCFree(x);
-}
-
-static int StorageTest01(void)
-{
- StorageInit();
-
- int id = StorageRegister(STORAGE_HOST, "test", 8, StorageTestAlloc, StorageTestFree);
- if (id < 0)
- goto error;
- id = StorageRegister(STORAGE_HOST, "variable", 24, StorageTestAlloc, StorageTestFree);
- if (id < 0)
- goto error;
- id = StorageRegister(STORAGE_FLOW, "store", sizeof(void *), StorageTestAlloc, StorageTestFree);
- if (id < 0)
- goto error;
-
- if (StorageFinalize() < 0)
- goto error;
-
- StorageCleanup();
- return 1;
-error:
- StorageCleanup();
- return 0;
-}
-
-static int StorageTest03(void)
-{
- StorageInit();
-
- int id = StorageRegister(STORAGE_HOST, "test", 8, StorageTestAlloc, StorageTestFree);
- if (id < 0)
- goto error;
- id = StorageRegister(STORAGE_HOST, "test", 8, StorageTestAlloc, StorageTestFree);
- if (id != -1) {
- printf("duplicate registration should have failed: ");
- goto error;
- }
-
- id = StorageRegister(STORAGE_HOST, "test1", 6, NULL, StorageTestFree);
- if (id != -1) {
- printf("duplicate registration should have failed (2): ");
- goto error;
- }
-
- id = StorageRegister(STORAGE_HOST, "test2", 8, StorageTestAlloc, NULL);
- if (id != -1) {
- printf("duplicate registration should have failed (3): ");
- goto error;
- }
-
- id = StorageRegister(STORAGE_HOST, "test3", 0, StorageTestAlloc, StorageTestFree);
- if (id != -1) {
- printf("duplicate registration should have failed (4): ");
- goto error;
- }
-
- id = StorageRegister(STORAGE_HOST, "", 8, StorageTestAlloc, StorageTestFree);
- if (id != -1) {
- printf("duplicate registration should have failed (5): ");
- goto error;
- }
-
- id = StorageRegister(STORAGE_HOST, NULL, 8, StorageTestAlloc, StorageTestFree);
- if (id != -1) {
- printf("duplicate registration should have failed (6): ");
- goto error;
- }
-
- id = StorageRegister(STORAGE_MAX, "test4", 8, StorageTestAlloc, StorageTestFree);
- if (id != -1) {
- printf("duplicate registration should have failed (7): ");
- goto error;
- }
-
- id = StorageRegister(38, "test5", 8, StorageTestAlloc, StorageTestFree);
- if (id != -1) {
- printf("duplicate registration should have failed (8): ");
- goto error;
- }
-
- id = StorageRegister(-1, "test6", 8, StorageTestAlloc, StorageTestFree);
- if (id != -1) {
- printf("duplicate registration should have failed (9): ");
- goto error;
- }
-
- StorageCleanup();
- return 1;
-error:
- StorageCleanup();
- return 0;
-}
-
-void StorageRegisterTests(void)
-{
- UtRegisterTest("StorageTest01", StorageTest01);
- UtRegisterTest("StorageTest03", StorageTest03);
-}
-#endif
void StorageFreeById(Storage *storage, const StorageEnum type, const int id);
void StorageFreeAll(Storage *storage, const StorageEnum type);
-void StorageRegisterTests(void);
#endif
41424, 80);
}
-/**
- * \brief UTHBuildPacketArrayFromEth is a wrapper that build a packets from an array of
- * packets in ethernet rawbytes. Hint: It also share the flows.
- *
- * \param raw_eth pointer to the array of ethernet packets in rawbytes
- * \param pktsize pointer to the array of sizes corresponding to each buffer pointed
- * from pktsize.
- * \param numpkts number of packets in the array
- *
- * \retval Packet pointer to the array of built in packets; NULL if something fail
- */
-Packet **UTHBuildPacketArrayFromEth(uint8_t *raw_eth[], int *pktsize, int numpkts)
-{
- DecodeThreadVars dtv;
- ThreadVars th_v;
- if (raw_eth == NULL || pktsize == NULL || numpkts <= 0) {
- SCLogError("The arrays cant be null, and the number"
- " of packets should be grater thatn zero");
- return NULL;
- }
- Packet **p = NULL;
- p = SCMalloc(sizeof(Packet *) * numpkts);
- if (unlikely(p == NULL))
- return NULL;
-
- memset(&dtv, 0, sizeof(DecodeThreadVars));
- memset(&th_v, 0, sizeof(th_v));
-
- int i = 0;
- for (; i < numpkts; i++) {
- p[i] = PacketGetFromAlloc();
- if (p[i] == NULL) {
- SCFree(p);
- return NULL;
- }
- DecodeEthernet(&th_v, &dtv, p[i], raw_eth[i], pktsize[i]);
- }
- return p;
-}
-
/**
* \brief UTHBuildPacketFromEth is a wrapper that build a packet for the rawbytes
*
Packet *UTHBuildPacketIPV6SrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
int UTHPacketMatchSigMpm(Packet *, char *, uint16_t);
-Packet **UTHBuildPacketArrayFromEth(uint8_t **, int *, int);
Packet *UTHBuildPacketFromEth(uint8_t *, uint16_t);
void UTHFreePacket(Packet *);