]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer-template-rust: remove C app-layer stub
authorJason Ish <jason.ish@oisf.net>
Thu, 17 Nov 2022 04:50:59 +0000 (22:50 -0600)
committerVictor Julien <vjulien@oisf.net>
Tue, 6 Dec 2022 13:09:10 +0000 (14:09 +0100)
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

rust/src/applayertemplate/template.rs
scripts/setup-app-layer.py
src/Makefile.am
src/app-layer-parser.c
src/app-layer-template-rust.c [deleted file]
src/app-layer-template-rust.h [deleted file]
src/output-json-template-rust.c

index a7a962b567807fcd8228e00f96158e74ebf59735..317f2e7ade80722065983abfe327e737df4db541 100644 (file)
@@ -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,
index d43d5869a179a512fa7021e314a02ef67ef4230c..dd32d54bdc869138311a65c40b9c467c1d7c23c1 100755 (executable)
@@ -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:
index ff2ed0c3f26562b1199377d598228427e50e5982..633d2be9bc079b3599c533127bc3d73a671862db 100755 (executable)
@@ -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 \
index c65a1c2af291412faea3f83568ab6cb6fd6eb71a..6f03cb6eef9ff1768f5c3f00dd5c3179c2084394 100644 (file)
@@ -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 (file)
index 3ba9349..0000000
+++ /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 <yourname@domain>
- *
- * 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 (file)
index dcdc3e4..0000000
+++ /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 <yourname@domain>
- */
-
-#ifndef __APP_LAYER_TEMPLATE_RUST_H__
-#define __APP_LAYER_TEMPLATE_RUST_H__
-
-void RegisterTemplateRustParsers(void);
-void TemplateRustParserRegisterTests(void);
-
-#endif /* __APP_LAYER_TEMPLATE_RUST_H__ */
index d71f0409799942c5dc8c135222e6a8f3775bd8df..83aed08a84d79df05b8b30cdaf76c96e44710d7f 100644 (file)
@@ -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"