]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer templates: cleanups
authorJason Ish <ish@unx.ca>
Wed, 31 Aug 2016 14:24:08 +0000 (08:24 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 5 Sep 2016 16:16:35 +0000 (18:16 +0200)
- cleanup file headers
- add todo section
- convert unit tests to new macros
- add markers to remove disabled by default behaviour

src/app-layer-template.c
src/app-layer-template.h
src/detect-engine-template.c
src/detect-engine-template.h
src/detect-template-buffer.c
src/detect-template-buffer.h
src/output-json-template.c
src/output-json-template.h

index 1a2cce0ec186ac2ba3fa996a448b44906718d8c8..a454b119bf8929e5641f976afaa9cc881055a528 100644 (file)
  * 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 <yourname@domain>
+ *
+ * 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)) {
index 191e0933b541d0f6d8ab091dab1803a0ebdcca0d..2dd944a01a8c5aec4c63f9fc89eaf2b3b49e4d4f 100644 (file)
  * 02110-1301, USA.
  */
 
+/**
+ * \file
+ *
+ * \author FirstName LastName <yourname@domain>
+ */
+
 #ifndef __APP_LAYER_TEMPLATE_H__
 #define __APP_LAYER_TEMPLATE_H__
 
index 49c29c6a6ae0bcc46435cdbd8fa484277abfc052..1d70d11fedd5edac5c9ae9bc57ffe53cefd34395 100644 (file)
  * 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 <yourname@domain>
+ *
+ * Implement buffer inspection on the decoded application layer
+ * content buffers.
+ */
+
 #include "suricata-common.h"
 #include "stream.h"
 #include "detect-engine-content-inspection.h"
index 61eb8d01035b141bf1a92b5421575ed7eaa90eea..98a17bf63d3fe77b8c1bc8bf51e6acd80e6a155a 100644 (file)
  * 02110-1301, USA.
  */
 
+/**
+ * \file
+ *
+ * \author FirstName LastName <yourname@domain>
+ */
+
 #ifndef __DETECT_TEMPLATE_ENGINE_H__
 #define __DETECT_TEMPLATE_ENGINE_H__
 
index 50521f937f94accd207cc87949812b2624877259..01f676a410117fe552c8a090395e8f092fa607a9 100644 (file)
  * 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 <yourname@domain>
+ *
+ * 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
index 8a2ab8bad1768eb0f27f9e674dfa4f86e4c94f3c..4385e443082ce034432fac0dda24a47d9dd8a639 100644 (file)
  * 02110-1301, USA.
  */
 
+/**
+ * \file
+ *
+ * \author FirstName LastName <yourname@domain>
+ */
+
 #ifndef __DETECT_TEMPLATE_BUFFER_H__
 #define __DETECT_TEMPLATE_BUFFER_H__
 
index eba2cebd68e448764d5cc837eea20eb501ca1f48..d096d730041bafc9528b618af48b1f9f3c4b2fbd 100644 (file)
  * 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 <yourname@domain>
+ *
+ * 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;
index d071e1828b597a7e610faa58b68f3438ffb6b970..4f1ac6b7afdd31edb31cdf9682500b3568da8f03 100644 (file)
  * 02110-1301, USA.
  */
 
+/**
+ * \file
+ *
+ * \author FirstName LastName <name@domain>
+ */
+
 #ifndef __OUTPUT_JSON_TEMPLATE_H__
 #define __OUTPUT_JSON_TEMPLATE_H__