From: Jason Ish Date: Mon, 3 Apr 2017 21:33:14 +0000 (-0600) Subject: rust: example of how an app-layer may be initialized X-Git-Tag: suricata-4.0.0-beta1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6f126d53df45be95412b342df68b16447a995b7;p=thirdparty%2Fsuricata.git rust: example of how an app-layer may be initialized Also shows basic usage of the configuration API from Rust. --- diff --git a/rust/src/dns/mod.rs b/rust/src/dns/mod.rs new file mode 100644 index 0000000000..68a02e53e1 --- /dev/null +++ b/rust/src/dns/mod.rs @@ -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."), + } +} diff --git a/rust/src/lib.rs b/rust/src/lib.rs index fb257128b2..ad4661df93 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -2,3 +2,4 @@ pub mod log; pub mod conf; +pub mod dns; diff --git a/src/app-layer-dns-udp.c b/src/app-layer-dns-udp.c index 82354ca76b..8d6ae4d2a6 100644 --- a/src/app-layer-dns-udp.c +++ b/src/app-layer-dns-udp.c @@ -50,6 +50,10 @@ #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); diff --git a/src/rust.h b/src/rust.h index 6f7c3b8d6d..f346cb2027 100644 --- a/src/rust.h +++ b/src/rust.h @@ -16,3 +16,4 @@ */ void rs_log_init(int32_t level); +void rs_dns_init(void);