From: Jason Ish Date: Wed, 31 Aug 2016 14:24:08 +0000 (-0600) Subject: app-layer templates: cleanups X-Git-Tag: suricata-3.1.2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e878dd2231f4d29f7e3792dc496eed0cf9209051;p=thirdparty%2Fsuricata.git app-layer templates: cleanups - cleanup file headers - add todo section - convert unit tests to new macros - add markers to remove disabled by default behaviour --- diff --git a/src/app-layer-template.c b/src/app-layer-template.c index 1a2cce0ec1..a454b119bf 100644 --- a/src/app-layer-template.c +++ b/src/app-layer-template.c @@ -15,8 +15,18 @@ * 02110-1301, USA. */ +/* + * TODO: Update \author in this file and app-layer-template.h. + * TODO: Implement your app-layer logic with unit tests. + * TODO: Remove SCLogNotice statements or convert to debug. + */ + /** - * \file Template application layer detector and parser for learning and + * \file + * + * \author FirstName LastName + * + * Template application layer detector and parser for learning and * template pruposes. * * This template implements a simple application layer for something @@ -449,7 +459,6 @@ void RegisterTemplateParsers(void) return; } /* TEMPLATE_END_REMOVE */ - /* Check if Template TCP detection is enabled. If it does not exist in * the configuration file then it will be enabled by default. */ if (AppLayerProtoDetectConfProtoDetectionEnabled("tcp", proto_name)) { diff --git a/src/app-layer-template.h b/src/app-layer-template.h index 191e0933b5..2dd944a01a 100644 --- a/src/app-layer-template.h +++ b/src/app-layer-template.h @@ -15,6 +15,12 @@ * 02110-1301, USA. */ +/** + * \file + * + * \author FirstName LastName + */ + #ifndef __APP_LAYER_TEMPLATE_H__ #define __APP_LAYER_TEMPLATE_H__ diff --git a/src/detect-engine-template.c b/src/detect-engine-template.c index 49c29c6a6a..1d70d11fed 100644 --- a/src/detect-engine-template.c +++ b/src/detect-engine-template.c @@ -15,6 +15,21 @@ * 02110-1301, USA. */ +/* + * TODO: Update your name below and in detect-engine-template.h. + * TODO: Update description in the \file section below. + * TODO: Remove SCLogNotice statements or convert to debug. + */ + +/** + * \file + * + * \author FirstName LastName + * + * Implement buffer inspection on the decoded application layer + * content buffers. + */ + #include "suricata-common.h" #include "stream.h" #include "detect-engine-content-inspection.h" diff --git a/src/detect-engine-template.h b/src/detect-engine-template.h index 61eb8d0103..98a17bf63d 100644 --- a/src/detect-engine-template.h +++ b/src/detect-engine-template.h @@ -15,6 +15,12 @@ * 02110-1301, USA. */ +/** + * \file + * + * \author FirstName LastName + */ + #ifndef __DETECT_TEMPLATE_ENGINE_H__ #define __DETECT_TEMPLATE_ENGINE_H__ diff --git a/src/detect-template-buffer.c b/src/detect-template-buffer.c index 50521f937f..01f676a410 100644 --- a/src/detect-template-buffer.c +++ b/src/detect-template-buffer.c @@ -15,9 +15,19 @@ * 02110-1301, USA. */ +/* + * TODO: Update the \author in this file and detect-template-buffer.h. + * TODO: Update description in the \file section below. + * TODO: Remove SCLogNotice statements or convert to debug. + */ + /** - * \file Set up of the "template_buffer" keyword to allow content inspections - * on the decoded template application layer buffers. + * \file + * + * \author FirstName LastName + * + * Set up of the "template_buffer" keyword to allow content + * inspections on the decoded template application layer buffers. */ #include "suricata-common.h" @@ -30,10 +40,11 @@ static void DetectTemplateBufferRegisterTests(void); void DetectTemplateBufferRegister(void) { + /* TEMPLATE_START_REMOVE */ if (ConfGetNode("app-layer.protocols.template") == NULL) { return; } - + /* TEMPLATE_END_REMOVE */ sigmatch_table[DETECT_AL_TEMPLATE_BUFFER].name = "template_buffer"; sigmatch_table[DETECT_AL_TEMPLATE_BUFFER].desc = "Template content modififier to match on the template buffers"; @@ -77,8 +88,6 @@ static int DetectTemplateBufferTest(void) ThreadVars tv; Signature *s; - int result = 0; - uint8_t request[] = "Hello World!"; /* Setup flow. */ @@ -97,9 +106,7 @@ static int DetectTemplateBufferTest(void) StreamTcpInitConfig(TRUE); de_ctx = DetectEngineCtxInit(); - if (de_ctx == NULL) { - goto end; - } + FAIL_IF_NULL(de_ctx); /* This rule should match. */ s = DetectEngineAppendSig(de_ctx, @@ -107,9 +114,7 @@ static int DetectTemplateBufferTest(void) "msg:\"TEMPLATE Test Rule\"; " "template_buffer; content:\"World!\"; " "sid:1; rev:1;)"); - if (s == NULL) { - goto end; - } + FAIL_IF_NULL(s); /* This rule should not match. */ s = DetectEngineAppendSig(de_ctx, @@ -117,9 +122,7 @@ static int DetectTemplateBufferTest(void) "msg:\"TEMPLATE Test Rule\"; " "template_buffer; content:\"W0rld!\"; " "sid:2; rev:1;)"); - if (s == NULL) { - goto end; - } + FAIL_IF_NULL(s); SigGroupBuild(de_ctx); DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx); @@ -130,20 +133,12 @@ static int DetectTemplateBufferTest(void) SCMutexUnlock(&f.m); /* Check that we have app-layer state. */ - if (f.alstate == NULL) { - goto end; - } + FAIL_IF_NULL(f.alstate); SigMatchSignatures(&tv, de_ctx, det_ctx, p); - if (!PacketAlertCheck(p, 1)) { - goto end; - } - if (PacketAlertCheck(p, 2)) { - goto end; - } + FAIL_IF(!PacketAlertCheck(p, 1)); + FAIL_IF(PacketAlertCheck(p, 2)); - result = 1; -end: /* Cleanup. */ if (alp_tctx != NULL) AppLayerParserThreadCtxFree(alp_tctx); @@ -157,7 +152,7 @@ end: FLOW_DESTROY(&f); UTHFreePacket(p); - return result; + PASS; } #endif diff --git a/src/detect-template-buffer.h b/src/detect-template-buffer.h index 8a2ab8bad1..4385e44308 100644 --- a/src/detect-template-buffer.h +++ b/src/detect-template-buffer.h @@ -15,6 +15,12 @@ * 02110-1301, USA. */ +/** + * \file + * + * \author FirstName LastName + */ + #ifndef __DETECT_TEMPLATE_BUFFER_H__ #define __DETECT_TEMPLATE_BUFFER_H__ diff --git a/src/output-json-template.c b/src/output-json-template.c index eba2cebd68..d096d73004 100644 --- a/src/output-json-template.c +++ b/src/output-json-template.c @@ -15,6 +15,20 @@ * 02110-1301, USA. */ +/* + * TODO: Update \author in this file and in output-json-template.h. + * TODO: Remove SCLogNotice statements, or convert to debug. + * TODO: Implement your app-layers logging. + */ + +/** + * \file + * + * \author FirstName LastName + * + * Implement JSON/eve logging app-layer Template. + */ + #include "suricata-common.h" #include "debug.h" #include "detect.h" @@ -178,10 +192,11 @@ static TmEcode JsonTemplateLogThreadDeinit(ThreadVars *t, void *data) void TmModuleJsonTemplateLogRegister(void) { + /* TEMPLATE_START_REMOVE */ if (ConfGetNode("app-layer.protocols.template") == NULL) { return; } - + /* TEMPLATE_END_REMOVE */ tmm_modules[TMM_JSONTEMPLATELOG].name = "JsonTemplateLog"; tmm_modules[TMM_JSONTEMPLATELOG].ThreadInit = JsonTemplateLogThreadInit; tmm_modules[TMM_JSONTEMPLATELOG].ThreadDeinit = JsonTemplateLogThreadDeinit; diff --git a/src/output-json-template.h b/src/output-json-template.h index d071e1828b..4f1ac6b7af 100644 --- a/src/output-json-template.h +++ b/src/output-json-template.h @@ -15,6 +15,12 @@ * 02110-1301, USA. */ +/** + * \file + * + * \author FirstName LastName + */ + #ifndef __OUTPUT_JSON_TEMPLATE_H__ #define __OUTPUT_JSON_TEMPLATE_H__