]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
templates: C stub template for Rust parser
authorJason Ish <ish@unx.ca>
Tue, 28 Aug 2018 13:12:45 +0000 (07:12 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 19 Sep 2018 19:00:51 +0000 (21:00 +0200)
src/Makefile.am
src/app-layer-detect-proto.c
src/app-layer-parser.c
src/app-layer-protos.c
src/app-layer-protos.h
src/app-layer-template-rust.c [new file with mode: 0644]
src/app-layer-template-rust.h [new file with mode: 0644]

index 69ad4d810b537eef3237a6c6c6101148b5860517..e9f3b815978736f871b181ac3af47715b2d64a1d 100644 (file)
@@ -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 \
index a473a37dd7b0f2a50502fe6a46cc122c5e4d0105..326d76de19981bc54b0c03b94a11760ae7ca5805 100644 (file)
@@ -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)
index 718c18d10a7001d7ed1714b8d8cbfea261c8ba11..bce0d721d41191cfb51714e7aa84ac523343c08c 100644 (file)
@@ -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 */
index 7d083bcda71079e8faff8f2a9c7f2c378674313e..eb3d22684ecd1ce4d2b0d8156d11fe81689e9faf 100644 (file)
@@ -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;
index 7602167c65c13ef6385a03e8fefdb08a5abc27b8..855a1b339751297c50d16df9d47ceb20fc921935 100644 (file)
@@ -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 (file)
index 0000000..a7d99f4
--- /dev/null
@@ -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 <yourname@domain>
+ *
+ * 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 (file)
index 0000000..dcdc3e4
--- /dev/null
@@ -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 <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__ */