From: Jason Ish Date: Tue, 28 Aug 2018 13:12:45 +0000 (-0600) Subject: templates: C stub template for Rust parser X-Git-Tag: suricata-4.1.0-rc2~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96dc20abb15969b5c61e3b93d02b80c1462edf56;p=thirdparty%2Fsuricata.git templates: C stub template for Rust parser --- diff --git a/src/Makefile.am b/src/Makefile.am index 69ad4d810b..e9f3b81597 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -51,6 +51,7 @@ app-layer-ikev2.c app-layer-ikev2.h \ app-layer-krb5.c app-layer-krb5.h \ app-layer-dhcp.c app-layer-dhcp.h \ app-layer-template.c app-layer-template.h \ +app-layer-template-rust.c app-layer-template-rust.h \ app-layer-ssh.c app-layer-ssh.h \ app-layer-ssl.c app-layer-ssl.h \ conf.c conf.h \ diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index a473a37dd7..326d76de19 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -731,6 +731,8 @@ static void AppLayerProtoDetectPrintProbingParsers(AppLayerProtoDetectProbingPar printf(" alproto: ALPROTO_KRB5\n"); else if (pp_pe->alproto == ALPROTO_DHCP) printf(" alproto: ALPROTO_DHCP\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_DNP3) @@ -802,6 +804,8 @@ static void AppLayerProtoDetectPrintProbingParsers(AppLayerProtoDetectProbingPar printf(" alproto: ALPROTO_KRB5\n"); else if (pp_pe->alproto == ALPROTO_DHCP) printf(" alproto: ALPROTO_DHCP\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_DNP3) diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 718c18d10a..bce0d721d4 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -68,6 +68,7 @@ #include "app-layer-krb5.h" #include "app-layer-dhcp.h" #include "app-layer-template.h" +#include "app-layer-template-rust.h" #include "conf.h" #include "util-spm.h" @@ -1466,6 +1467,7 @@ void AppLayerParserRegisterProtocolParsers(void) RegisterIKEV2Parsers(); RegisterKRB5Parsers(); RegisterDHCPParsers(); + RegisterTemplateRustParsers(); RegisterTemplateParsers(); /** IMAP */ diff --git a/src/app-layer-protos.c b/src/app-layer-protos.c index 7d083bcda7..eb3d22684e 100644 --- a/src/app-layer-protos.c +++ b/src/app-layer-protos.c @@ -105,6 +105,9 @@ const char *AppProtoToString(AppProto alproto) case ALPROTO_TEMPLATE: proto_name = "template"; break; + case ALPROTO_TEMPLATE_RUST: + proto_name = "template-rust"; + break; case ALPROTO_FAILED: proto_name = "failed"; break; @@ -145,6 +148,7 @@ AppProto StringToAppProto(const char *proto_name) if (strcmp(proto_name,"krb5")==0) return ALPROTO_KRB5; if (strcmp(proto_name,"dhcp")==0) return ALPROTO_DHCP; if (strcmp(proto_name,"template")==0) return ALPROTO_TEMPLATE; + if (strcmp(proto_name,"template-rust")==0) return ALPROTO_TEMPLATE_RUST; if (strcmp(proto_name,"failed")==0) return ALPROTO_FAILED; return ALPROTO_UNKNOWN; diff --git a/src/app-layer-protos.h b/src/app-layer-protos.h index 7602167c65..855a1b3397 100644 --- a/src/app-layer-protos.h +++ b/src/app-layer-protos.h @@ -52,6 +52,7 @@ enum AppProtoEnum { ALPROTO_KRB5, ALPROTO_DHCP, ALPROTO_TEMPLATE, + ALPROTO_TEMPLATE_RUST, /* used by the probing parser when alproto detection fails * permanently for that particular stream */ diff --git a/src/app-layer-template-rust.c b/src/app-layer-template-rust.c new file mode 100644 index 0000000000..a7d99f4d52 --- /dev/null +++ b/src/app-layer-template-rust.c @@ -0,0 +1,74 @@ +/* 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 pruposes. + * + * 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" + +#ifdef HAVE_RUST +#include "rust-applayertemplate-template-gen.h" +#endif + +void RegisterTemplateRustParsers(void) +{ +#ifdef HAVE_RUST + /* Only register if enabled in config. */ + if (ConfGetNode("app-layer.protocols.template-rust") == NULL) { + return; + } + SCLogNotice("Registring Rust template parser."); + rs_template_register_parser(); +#endif +#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 new file mode 100644 index 0000000000..dcdc3e431a --- /dev/null +++ b/src/app-layer-template-rust.h @@ -0,0 +1,30 @@ +/* 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__ */