Skip to content

Commit

Permalink
template: rename template-rust to template
Browse files Browse the repository at this point in the history
Remove the distinction between the C template protocol "template" and
the Rust template protocol "template-rust" and make the Rust parser
simply template now that we no longer have support to generate a C
protocol template.
  • Loading branch information
jasonish authored and victorjulien committed Dec 6, 2022
1 parent 8683154 commit 4a7567b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 39 deletions.
4 changes: 2 additions & 2 deletions rust/src/applayertemplate/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,12 @@ export_tx_data_get!(rs_template_get_tx_data, TemplateTransaction);
export_state_data_get!(rs_template_get_state_data, TemplateState);

// Parser name as a C style string.
const PARSER_NAME: &[u8] = b"template-rust\0";
const PARSER_NAME: &[u8] = b"template\0";

#[no_mangle]
pub unsafe extern "C" fn rs_template_register_parser() {
/* TEMPLATE_START_REMOVE */
if crate::conf::conf_get_node("app-layer.protocols.template-rust").is_none() {
if crate::conf::conf_get_node("app-layer.protocols.template").is_none() {
return;
}
/* TEMPLATE_END_REMOVE */
Expand Down
10 changes: 5 additions & 5 deletions src/app-layer-detect-proto.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2007-2021 Open Information Security Foundation
/* Copyright (C) 2007-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
Expand Down Expand Up @@ -905,8 +905,8 @@ static void AppLayerProtoDetectPrintProbingParsers(AppLayerProtoDetectProbingPar
printf(" alproto: ALPROTO_SNMP\n");
else if (pp_pe->alproto == ALPROTO_SIP)
printf(" alproto: ALPROTO_SIP\n");
else if (pp_pe->alproto == ALPROTO_TEMPLATE_RUST)
printf(" alproto: ALPROTO_TEMPLATE_RUST\n");
else if (pp_pe->alproto == ALPROTO_TEMPLATE)
printf(" alproto: ALPROTO_TEMPLATE\n");
else if (pp_pe->alproto == ALPROTO_RFB)
printf(" alproto: ALPROTO_RFB\n");
else if (pp_pe->alproto == ALPROTO_MQTT)
Expand Down Expand Up @@ -988,8 +988,8 @@ static void AppLayerProtoDetectPrintProbingParsers(AppLayerProtoDetectProbingPar
printf(" alproto: ALPROTO_SNMP\n");
else if (pp_pe->alproto == ALPROTO_SIP)
printf(" alproto: ALPROTO_SIP\n");
else if (pp_pe->alproto == ALPROTO_TEMPLATE_RUST)
printf(" alproto: ALPROTO_TEMPLATE_RUST\n");
else if (pp_pe->alproto == ALPROTO_TEMPLATE)
printf(" alproto: ALPROTO_TEMPLATE\n");
else if (pp_pe->alproto == ALPROTO_RFB)
printf(" alproto: ALPROTO_RFB\n");
else if (pp_pe->alproto == ALPROTO_MQTT)
Expand Down
10 changes: 5 additions & 5 deletions src/app-layer-protos.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2007-2021 Open Information Security Foundation
/* Copyright (C) 2007-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
Expand Down Expand Up @@ -117,8 +117,8 @@ const char *AppProtoToString(AppProto alproto)
case ALPROTO_TELNET:
proto_name = "telnet";
break;
case ALPROTO_TEMPLATE_RUST:
proto_name = "template-rust";
case ALPROTO_TEMPLATE:
proto_name = "template";
break;
case ALPROTO_RDP:
proto_name = "rdp";
Expand Down Expand Up @@ -187,8 +187,8 @@ AppProto StringToAppProto(const char *proto_name)
return ALPROTO_PGSQL;
if (strcmp(proto_name, "telnet") == 0)
return ALPROTO_TELNET;
if (strcmp(proto_name, "template-rust") == 0)
return ALPROTO_TEMPLATE_RUST;
if (strcmp(proto_name, "template") == 0)
return ALPROTO_TEMPLATE;
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)
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ enum AppProtoEnum {
ALPROTO_MQTT,
ALPROTO_PGSQL,
ALPROTO_TELNET,
ALPROTO_TEMPLATE_RUST,
ALPROTO_TEMPLATE,
ALPROTO_RDP,
ALPROTO_HTTP2,
ALPROTO_BITTORRENT_DHT,
Expand Down
2 changes: 1 addition & 1 deletion src/detect-engine-register.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ enum DetectKeywordId {
DETECT_TCPMSS,
DETECT_FTPDATA,
DETECT_TARGET,
DETECT_AL_TEMPLATE_RUST_BUFFER,
DETECT_AL_TEMPLATE_BUFFER,
DETECT_AL_DHCP_LEASETIME,
DETECT_AL_DHCP_REBINDING_TIME,
DETECT_AL_DHCP_RENEWAL_TIME,
Expand Down
31 changes: 14 additions & 17 deletions src/detect-template-rust-buffer.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2015-2017 Open Information Security Foundation
/* Copyright (C) 2015-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
Expand Down Expand Up @@ -57,25 +57,22 @@ void DetectTemplateRustBufferRegister(void)
return;
}
/* TEMPLATE_END_REMOVE */
sigmatch_table[DETECT_AL_TEMPLATE_RUST_BUFFER].name =
"template_rust_buffer";
sigmatch_table[DETECT_AL_TEMPLATE_RUST_BUFFER].desc =
sigmatch_table[DETECT_AL_TEMPLATE_BUFFER].name = "template_rust_buffer";
sigmatch_table[DETECT_AL_TEMPLATE_BUFFER].desc =
"Template content modifier to match on the template buffers";
sigmatch_table[DETECT_AL_TEMPLATE_RUST_BUFFER].Setup =
DetectTemplateRustBufferSetup;
sigmatch_table[DETECT_AL_TEMPLATE_BUFFER].Setup = DetectTemplateRustBufferSetup;
#ifdef UNITTESTS
sigmatch_table[DETECT_AL_TEMPLATE_RUST_BUFFER].RegisterTests =
DetectTemplateRustBufferRegisterTests;
sigmatch_table[DETECT_AL_TEMPLATE_BUFFER].RegisterTests = DetectTemplateRustBufferRegisterTests;
#endif
sigmatch_table[DETECT_AL_TEMPLATE_RUST_BUFFER].flags |= SIGMATCH_NOOPT;
sigmatch_table[DETECT_AL_TEMPLATE_BUFFER].flags |= SIGMATCH_NOOPT;

/* register inspect engines */
DetectAppLayerInspectEngineRegister2("template_rust_buffer", ALPROTO_TEMPLATE_RUST,
SIG_FLAG_TOSERVER, 0, DetectEngineInspectTemplateRustBuffer, NULL);
DetectAppLayerInspectEngineRegister2("template_rust_buffer", ALPROTO_TEMPLATE_RUST,
SIG_FLAG_TOCLIENT, 0, DetectEngineInspectTemplateRustBuffer, NULL);
DetectAppLayerInspectEngineRegister2("template_buffer", ALPROTO_TEMPLATE, SIG_FLAG_TOSERVER, 0,
DetectEngineInspectTemplateRustBuffer, NULL);
DetectAppLayerInspectEngineRegister2("template_buffer", ALPROTO_TEMPLATE, SIG_FLAG_TOCLIENT, 0,
DetectEngineInspectTemplateRustBuffer, NULL);

g_template_rust_id = DetectBufferTypeGetByName("template_rust_buffer");
g_template_rust_id = DetectBufferTypeGetByName("template_buffer");

SCLogNotice("Template application layer detect registered.");
}
Expand All @@ -84,7 +81,7 @@ static int DetectTemplateRustBufferSetup(DetectEngineCtx *de_ctx, Signature *s,
{
s->init_data->list = g_template_rust_id;

if (DetectSignatureSetAppProto(s, ALPROTO_TEMPLATE_RUST) != 0)
if (DetectSignatureSetAppProto(s, ALPROTO_TEMPLATE) != 0)
return -1;

return 0;
Expand Down Expand Up @@ -141,7 +138,7 @@ static int DetectTemplateRustBufferTest(void)
memset(&tv, 0, sizeof(ThreadVars));
p = UTHBuildPacket(request, sizeof(request), IPPROTO_TCP);
FLOW_INITIALIZE(&f);
f.alproto = ALPROTO_TEMPLATE_RUST;
f.alproto = ALPROTO_TEMPLATE;
f.protoctx = (void *)&tcp;
f.proto = IPPROTO_TCP;
f.flags |= FLOW_IPV4;
Expand Down Expand Up @@ -171,7 +168,7 @@ static int DetectTemplateRustBufferTest(void)
DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx);

AppLayerParserParse(
NULL, alp_tctx, &f, ALPROTO_TEMPLATE_RUST, STREAM_TOSERVER, request, sizeof(request));
NULL, alp_tctx, &f, ALPROTO_TEMPLATE, STREAM_TOSERVER, request, sizeof(request));

/* Check that we have app-layer state. */
FAIL_IF_NULL(f.alstate);
Expand Down
16 changes: 8 additions & 8 deletions src/output-json-template-rust.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2018-2021 Open Information Security Foundation
/* Copyright (C) 2018-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
Expand Down Expand Up @@ -68,8 +68,8 @@ static int JsonTemplateLogger(ThreadVars *tv, void *thread_data, const Packet *p
SCLogNotice("JsonTemplateLogger");
LogTemplateLogThread *thread = thread_data;

JsonBuilder *js = CreateEveHeader(
p, LOG_DIR_PACKET, "template-rust", NULL, thread->templatelog_ctx->eve_ctx);
JsonBuilder *js =
CreateEveHeader(p, LOG_DIR_PACKET, "template", NULL, thread->templatelog_ctx->eve_ctx);
if (unlikely(js == NULL)) {
return TM_ECODE_FAILED;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf, OutputCtx *pare

SCLogNotice("Template log sub-module initialized.");

AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TEMPLATE_RUST);
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TEMPLATE);

result.ctx = output_ctx;
result.ok = true;
Expand Down Expand Up @@ -165,14 +165,14 @@ static TmEcode JsonTemplateLogThreadDeinit(ThreadVars *t, void *data)
void JsonTemplateRustLogRegister(void)
{
/* TEMPLATE_START_REMOVE */
if (ConfGetNode("app-layer.protocols.template-rust") == NULL) {
if (ConfGetNode("app-layer.protocols.template") == NULL) {
return;
}
/* TEMPLATE_END_REMOVE */
/* Register as an eve sub-module. */
OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonTemplateRustLog",
"eve-log.template-rust", OutputTemplateLogInitSub, ALPROTO_TEMPLATE_RUST,
JsonTemplateLogger, JsonTemplateLogThreadInit, JsonTemplateLogThreadDeinit, NULL);
OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonTemplateLog", "eve-log.template",
OutputTemplateLogInitSub, ALPROTO_TEMPLATE, JsonTemplateLogger,
JsonTemplateLogThreadInit, JsonTemplateLogThreadDeinit, NULL);

SCLogNotice("Template JSON logger registered.");
}

0 comments on commit 4a7567b

Please sign in to comment.