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
pull/8251/head
Jason Ish 3 years ago committed by Victor Julien
parent baa7021ee6
commit 50a787a9a3

@ -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,

@ -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:

@ -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 \

@ -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();

@ -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
}

@ -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__ */

@ -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"

Loading…
Cancel
Save