From: Jason Ish Date: Thu, 17 Nov 2022 16:00:19 +0000 (-0600) Subject: templates: clang format cleanups X-Git-Tag: suricata-7.0.0-rc1~306 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05e16820de;p=thirdparty%2Fsuricata.git templates: clang format cleanups Cleanup the trivial clang-formatting issues in templates. Length of protocol names may require clang-format after new protocol generation. --- diff --git a/scripts/setup-app-layer.py b/scripts/setup-app-layer.py index 92abb9da45..920ddf7960 100755 --- a/scripts/setup-app-layer.py +++ b/scripts/setup-app-layer.py @@ -120,7 +120,7 @@ def patch_app_layer_protos_c(protoname): for i, line in enumerate(inlines): if line.find("case ALPROTO_TEMPLATE:") > -1: - # Duplicate the section starting an this line and + # Duplicate the section starting at this line and # including the following 2 lines. for j in range(i, i + 3): temp = inlines[j] @@ -129,9 +129,13 @@ def patch_app_layer_protos_c(protoname): output.write(temp) if line.find("return ALPROTO_TEMPLATE;") > -1: - output.write( - line.replace("TEMPLATE", protoname.upper()).replace( - "template", protoname.lower())) + # Duplicate the section starting at this line and + # including the following line. + for j in range(i, i + 2): + temp = inlines[j] + temp = temp.replace("TEMPLATE", protoname.upper()) + temp = temp.replace("template", protoname.lower()) + output.write(temp) output.write(line) open(filename, "w").write(output.getvalue()) diff --git a/src/app-layer-protos.c b/src/app-layer-protos.c index d18d2f6990..39e9e7f437 100644 --- a/src/app-layer-protos.c +++ b/src/app-layer-protos.c @@ -190,8 +190,10 @@ AppProto StringToAppProto(const char *proto_name) return ALPROTO_PGSQL; if (strcmp(proto_name, "telnet") == 0) return ALPROTO_TELNET; - if (strcmp(proto_name,"template")==0) return ALPROTO_TEMPLATE; - if (strcmp(proto_name,"template-rust")==0) return ALPROTO_TEMPLATE_RUST; + if (strcmp(proto_name, "template") == 0) + return ALPROTO_TEMPLATE; + if (strcmp(proto_name, "template-rust") == 0) + return ALPROTO_TEMPLATE_RUST; if (strcmp(proto_name,"rdp")==0) return ALPROTO_RDP; if (strcmp(proto_name,"http2")==0) return ALPROTO_HTTP2; if (strcmp(proto_name, "bittorrent-dht") == 0) diff --git a/src/detect-template-rust-buffer.c b/src/detect-template-rust-buffer.c index a3185ddda4..917f8a1ce2 100644 --- a/src/detect-template-rust-buffer.c +++ b/src/detect-template-rust-buffer.c @@ -41,9 +41,7 @@ #include "detect-engine-build.h" #include "rust.h" - -static int DetectTemplateRustBufferSetup(DetectEngineCtx *, Signature *, - const char *); +static int DetectTemplateRustBufferSetup(DetectEngineCtx *, Signature *, const char *); static uint8_t DetectEngineInspectTemplateRustBuffer(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id); @@ -82,8 +80,7 @@ void DetectTemplateRustBufferRegister(void) SCLogNotice("Template application layer detect registered."); } -static int DetectTemplateRustBufferSetup(DetectEngineCtx *de_ctx, Signature *s, - const char *str) +static int DetectTemplateRustBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str) { s->init_data->list = g_template_rust_id; @@ -157,26 +154,24 @@ static int DetectTemplateRustBufferTest(void) FAIL_IF_NULL(de_ctx); /* This rule should match. */ - s = DetectEngineAppendSig(de_ctx, - "alert tcp any any -> any any (" - "msg:\"TEMPLATE Test Rule\"; " - "template_rust_buffer; content:\"World!\"; " - "sid:1; rev:1;)"); + s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (" + "msg:\"TEMPLATE Test Rule\"; " + "template_rust_buffer; content:\"World!\"; " + "sid:1; rev:1;)"); FAIL_IF_NULL(s); /* This rule should not match. */ - s = DetectEngineAppendSig(de_ctx, - "alert tcp any any -> any any (" - "msg:\"TEMPLATE Test Rule\"; " - "template_rust_buffer; content:\"W0rld!\"; " - "sid:2; rev:1;)"); + s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (" + "msg:\"TEMPLATE Test Rule\"; " + "template_rust_buffer; content:\"W0rld!\"; " + "sid:2; rev:1;)"); FAIL_IF_NULL(s); SigGroupBuild(de_ctx); DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx); - AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_TEMPLATE_RUST, - STREAM_TOSERVER, request, sizeof(request)); + AppLayerParserParse( + NULL, alp_tctx, &f, ALPROTO_TEMPLATE_RUST, STREAM_TOSERVER, request, sizeof(request)); /* Check that we have app-layer state. */ FAIL_IF_NULL(f.alstate); diff --git a/src/detect-template-rust-buffer.h b/src/detect-template-rust-buffer.h index 8778a6efe6..5e24a97f19 100644 --- a/src/detect-template-rust-buffer.h +++ b/src/detect-template-rust-buffer.h @@ -24,7 +24,6 @@ #ifndef __DETECT_TEMPLATE_RUST_BUFFER_H__ #define __DETECT_TEMPLATE_RUST_BUFFER_H__ - void DetectTemplateRustBufferRegister(void); #endif /* __DETECT_TEMPLATE_RUST_BUFFER_H__ */ diff --git a/src/output-json-template-rust.c b/src/output-json-template-rust.c index 83aed08a84..1d7f5da241 100644 --- a/src/output-json-template-rust.c +++ b/src/output-json-template-rust.c @@ -53,7 +53,7 @@ #include "rust.h" typedef struct LogTemplateFileCtx_ { - uint32_t flags; + uint32_t flags; OutputJsonCtx *eve_ctx; } LogTemplateFileCtx; @@ -62,8 +62,8 @@ typedef struct LogTemplateLogThread_ { OutputJsonThreadCtx *ctx; } LogTemplateLogThread; -static int JsonTemplateLogger(ThreadVars *tv, void *thread_data, - const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id) +static int JsonTemplateLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f, + void *state, void *tx, uint64_t tx_id) { SCLogNotice("JsonTemplateLogger"); LogTemplateLogThread *thread = thread_data; @@ -97,8 +97,7 @@ static void OutputTemplateLogDeInitCtxSub(OutputCtx *output_ctx) SCFree(output_ctx); } -static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf, - OutputCtx *parent_ctx) +static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf, OutputCtx *parent_ctx) { OutputInitResult result = { NULL, false }; OutputJsonCtx *ajt = parent_ctx->data;