]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: example of how an app-layer may be initialized
authorJason Ish <ish@unx.ca>
Mon, 3 Apr 2017 21:33:14 +0000 (15:33 -0600)
committerJason Ish <ish@unx.ca>
Mon, 5 Jun 2017 20:57:20 +0000 (14:57 -0600)
Also shows basic usage of the configuration API from Rust.

rust/src/dns/mod.rs [new file with mode: 0644]
rust/src/lib.rs
src/app-layer-dns-udp.c
src/rust.h

diff --git a/rust/src/dns/mod.rs b/rust/src/dns/mod.rs
new file mode 100644 (file)
index 0000000..68a02e5
--- /dev/null
@@ -0,0 +1,34 @@
+/* Copyright (C) 2017 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.
+ */
+
+use log::*;
+use conf;
+
+#[no_mangle]
+pub extern "C" fn rs_dns_init() {
+    SCLogNotice!("Initializing DNS analyzer");
+
+    match conf::conf_get("app-layer.protocols.dns.tcp.enabled") {
+        Some(val) => SCLogNotice!("- TCP is enabled: {}", val),
+        None => SCLogNotice!("- TCP is not enabled."),
+    }
+
+    match conf::conf_get("app-layer.protocols.dns.udp.enabled") {
+        Some(val) => SCLogNotice!("- UDP is enabled: {}", val),
+        None => SCLogNotice!("- UDP is not enabled."),
+    }
+}
index fb257128b2ac6edecbb03d1198f04111c19fcb1c..ad4661df93edcf3cc78aaf087976becb6e9d2c2e 100644 (file)
@@ -2,3 +2,4 @@
 pub mod log;
 
 pub mod conf;
+pub mod dns;
index 82354ca76ba400b8b7404576aa4ff81087048a85..8d6ae4d2a6cbb44cb964af8651c2750090360bc7 100644 (file)
 
 #include "app-layer-dns-udp.h"
 
+#ifdef HAVE_RUST
+#include "rust.h"
+#endif
+
 /** \internal
  *  \brief Parse DNS request packet
  */
@@ -385,6 +389,12 @@ void RegisterDNSUDPParsers(void)
 {
     const char *proto_name = "dns";
 
+#ifdef HAVE_RUST
+    /* If DNS was implemented in Rust, we could call into the rust
+     * init function here. */
+    rs_dns_init();
+#endif
+
     /** DNS */
     if (AppLayerProtoDetectConfProtoDetectionEnabled("udp", proto_name)) {
         AppLayerProtoDetectRegisterProtocol(ALPROTO_DNS, proto_name);
index 6f7c3b8d6d2283039f2f39ab44867c431f0c3717..f346cb2027bc652f9865d8afec131a92f6e36677 100644 (file)
@@ -16,3 +16,4 @@
  */
 
 void rs_log_init(int32_t level);
+void rs_dns_init(void);