From: Jason Ish Date: Thu, 17 Nov 2022 04:50:59 +0000 (-0600) Subject: app-layer-template-rust: remove C app-layer stub X-Git-Tag: suricata-7.0.0-rc1~309 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50a787a9a3398e265c678db9030ecdd7def59e38;p=thirdparty%2Fsuricata.git app-layer-template-rust: remove C app-layer stub Remove the app-layer-PROTO stub for Rust based parsers. It is no longer needed as Rust parsers now contain the registration function in Rust. Ticket: 4939 --- diff --git a/rust/src/applayertemplate/template.rs b/rust/src/applayertemplate/template.rs index a7a962b567..317f2e7ade 100644 --- a/rust/src/applayertemplate/template.rs +++ b/rust/src/applayertemplate/template.rs @@ -424,6 +424,12 @@ const PARSER_NAME: &[u8] = b"template-rust\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() { + return; + } + /* TEMPLATE_END_REMOVE */ + let default_port = CString::new("[7000]").unwrap(); let parser = RustParser { name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char, diff --git a/scripts/setup-app-layer.py b/scripts/setup-app-layer.py index d43d5869a1..dd32d54bdc 100755 --- a/scripts/setup-app-layer.py +++ b/scripts/setup-app-layer.py @@ -64,10 +64,6 @@ def copy_app_layer_templates(proto, rust): if rust: pairs = ( - ("src/app-layer-template-rust.c", - "src/app-layer-%s.c" % (lower)), - ("src/app-layer-template-rust.h", - "src/app-layer-%s.h" % (lower)), ("rust/src/applayertemplate/mod.rs", "rust/src/applayer%s/mod.rs" % (lower)), ("rust/src/applayertemplate/template.rs", @@ -170,16 +166,20 @@ def patch_app_layer_detect_proto_c(proto): output.write(line) open(filename, "w").write(output.getvalue()) -def patch_app_layer_parser_c(proto): +def patch_app_layer_parser_c(proto, rust): filename = "src/app-layer-parser.c" print("Patching %s." % (filename)) output = io.StringIO() inlines = open(filename).readlines() for line in inlines: - if line.find("app-layer-template.h") > -1: - output.write(line.replace("template", proto.lower())) - if line.find("RegisterTemplateParsers()") > -1: - output.write(line.replace("Template", proto)) + if rust: + if line.find("rs_template_register_parser") > -1: + output.write(line.replace("template", proto.lower())) + else: + if line.find("app-layer-template.h") > -1: + output.write(line.replace("template", proto.lower())) + if line.find("RegisterTemplateParsers()") > -1: + output.write(line.replace("Template", proto)) output.write(line) open(filename, "w").write(output.getvalue()) @@ -462,11 +462,12 @@ def main(): copy_app_layer_templates(proto, args.rust) if args.rust: patch_rust_lib_rs(proto) - patch_makefile_am(proto) + if not args.rust: + patch_makefile_am(proto) patch_app_layer_protos_h(proto) patch_app_layer_protos_c(proto) patch_app_layer_detect_proto_c(proto) - patch_app_layer_parser_c(proto) + patch_app_layer_parser_c(proto, args.rust) patch_suricata_yaml_in(proto) if logger: diff --git a/src/Makefile.am b/src/Makefile.am index ff2ed0c3f2..633d2be9bc 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -52,7 +52,6 @@ noinst_HEADERS = \ app-layer-ssh.h \ app-layer-ssl.h \ app-layer-template.h \ - app-layer-template-rust.h \ app-layer-tftp.h \ autoconf.h \ build-info.h \ @@ -667,7 +666,6 @@ libsuricata_c_a_SOURCES = \ app-layer-ssh.c \ app-layer-ssl.c \ app-layer-template.c \ - app-layer-template-rust.c \ app-layer-tftp.c \ conf.c \ conf-yaml-loader.c \ diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index c65a1c2af2..6f03cb6eef 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -61,7 +61,6 @@ #include "app-layer-snmp.h" #include "app-layer-quic.h" #include "app-layer-template.h" -#include "app-layer-template-rust.h" #include "app-layer-rdp.h" #include "app-layer-http2.h" @@ -1738,7 +1737,7 @@ void AppLayerParserRegisterProtocolParsers(void) RegisterSNMPParsers(); RegisterSIPParsers(); RegisterQuicParsers(); - RegisterTemplateRustParsers(); + rs_template_register_parser(); RegisterRFBParsers(); RegisterMQTTParsers(); rs_pgsql_register_parser(); diff --git a/src/app-layer-template-rust.c b/src/app-layer-template-rust.c deleted file mode 100644 index 3ba9349f30..0000000000 --- a/src/app-layer-template-rust.c +++ /dev/null @@ -1,71 +0,0 @@ -/* Copyright (C) 2018 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 - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -/* - * TODO: Update \author in this file and app-layer-templaterust.h. - * TODO: Implement your app-layer logic with unit tests. - * TODO: Remove SCLogNotice statements or convert to debug. - */ - -/** - * \file - * - * \author FirstName LastName - * - * TemplateRust application layer detector and parser for learning and - * templaterust purposes. - * - * This templaterust implements a simple application layer for something - * like the echo protocol running on port 7. - */ - -#include "suricata-common.h" -#include "stream.h" -#include "conf.h" - -#include "util-unittest.h" - -#include "app-layer-detect-proto.h" -#include "app-layer-parser.h" - -#include "app-layer-template-rust.h" -#include "rust.h" - -void RegisterTemplateRustParsers(void) -{ - /* TEMPLATE_START_REMOVE */ - /* Only register if enabled in config. */ - if (ConfGetNode("app-layer.protocols.template-rust") == NULL) { - return; - } - /* TEMPLATE_END_REMOVE */ - SCLogNotice("Registering Rust template parser."); - rs_template_register_parser(); -#ifdef UNITTESTS - AppLayerParserRegisterProtocolUnittests(IPPROTO_TCP, ALPROTO_TEMPLATE_RUST, - TemplateRustParserRegisterTests); -#endif -} - -#ifdef UNITTESTS -#endif - -void TemplateRustParserRegisterTests(void) -{ -#ifdef UNITTESTS -#endif -} diff --git a/src/app-layer-template-rust.h b/src/app-layer-template-rust.h deleted file mode 100644 index dcdc3e431a..0000000000 --- a/src/app-layer-template-rust.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2018 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 - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -/** - * \file - * - * \author FirstName LastName - */ - -#ifndef __APP_LAYER_TEMPLATE_RUST_H__ -#define __APP_LAYER_TEMPLATE_RUST_H__ - -void RegisterTemplateRustParsers(void); -void TemplateRustParserRegisterTests(void); - -#endif /* __APP_LAYER_TEMPLATE_RUST_H__ */ diff --git a/src/output-json-template-rust.c b/src/output-json-template-rust.c index d71f040979..83aed08a84 100644 --- a/src/output-json-template-rust.c +++ b/src/output-json-template-rust.c @@ -49,7 +49,6 @@ #include "app-layer.h" #include "app-layer-parser.h" -#include "app-layer-template-rust.h" #include "output-json-template-rust.h" #include "rust.h"