]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mqtt: Move conf code to rust 10100/head
authorJeff Lucovsky <jlucovsky@oisf.net>
Thu, 21 Dec 2023 14:41:29 +0000 (09:41 -0500)
committerVictor Julien <victor@inliniac.net>
Thu, 28 Dec 2023 11:20:50 +0000 (12:20 +0100)
Issue: 6387

This commit moves the configuration logic to Rust.

rust/src/mqtt/mqtt.rs
rust/src/mqtt/parser.rs
src/Makefile.am
src/app-layer-mqtt.c [deleted file]
src/app-layer-mqtt.h [deleted file]
src/app-layer-parser.c
src/output-json-mqtt.c

index f1c37d83c8810254c92efea3d4926955d23cd2d9..7f60e2a757cd3ba4f7594d05527094edf6b22f7e 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2020-2022 Open Information Security Foundation
+/* Copyright (C) 2020-2023 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
@@ -21,7 +21,7 @@ use super::mqtt_message::*;
 use super::parser::*;
 use crate::applayer::*;
 use crate::applayer::{self, LoggerFlags};
-use crate::conf::conf_get;
+use crate::conf::{conf_get, get_memval};
 use crate::core::*;
 use crate::frames::*;
 use nom7::Err;
@@ -112,7 +112,7 @@ pub struct MQTTState {
     connected: bool,
     skip_request: usize,
     skip_response: usize,
-    max_msg_len: usize,
+    max_msg_len: u32,
     tx_index_completed: usize,
 }
 
@@ -142,7 +142,7 @@ impl MQTTState {
             connected: false,
             skip_request: 0,
             skip_response: 0,
-            max_msg_len: unsafe { MAX_MSG_LEN as usize },
+            max_msg_len: unsafe { MAX_MSG_LEN},
             tx_index_completed: 0,
         }
     }
@@ -778,10 +778,8 @@ export_tx_data_get!(rs_mqtt_get_tx_data, MQTTTransaction);
 export_state_data_get!(rs_mqtt_get_state_data, MQTTState);
 
 #[no_mangle]
-pub unsafe extern "C" fn rs_mqtt_register_parser(cfg_max_msg_len: u32) {
+pub unsafe extern "C" fn SCMqttRegisterParser() {
     let default_port = CString::new("[1883]").unwrap();
-    let max_msg_len = &mut MAX_MSG_LEN;
-    *max_msg_len = cfg_max_msg_len;
     let parser = RustParser {
         name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char,
         default_port: default_port.as_ptr(),
@@ -830,6 +828,13 @@ pub unsafe extern "C" fn rs_mqtt_register_parser(cfg_max_msg_len: u32) {
                 SCLogError!("Invalid value for mqtt.max-tx");
             }
         }
+        if let Some(val) = conf_get("app-layer.protocols.mqtt.max-msg-length") {
+            if let Ok(v) = get_memval(val) {
+                MAX_MSG_LEN = v as u32;
+            } else {
+                SCLogError!("Invalid value for mqtt.max-msg-length: {}", val);
+            }
+        }
     } else {
         SCLogDebug!("Protocol detector and parser disabled for MQTT.");
     }
index 8b1c8c542aba7f2e3fe22c9aed4ad2bfe8efc280..9b576e54a5c070842d384956dedf1ef1751e5f0c 100644 (file)
@@ -634,7 +634,7 @@ fn parse_remaining_message<'a>(
 pub fn parse_message(
     input: &[u8],
     protocol_version: u8,
-    max_msg_size: usize,
+    max_msg_size: u32,
 ) -> IResult<&[u8], MQTTMessage> {
     // Parse the fixed header first. This is identical across versions and can
     // be between 2 and 5 bytes long.
@@ -652,7 +652,7 @@ pub fn parse_message(
             // limit, we return a special truncation message type, containing
             // no parsed metadata but just the skipped length and the message
             // type.
-            if len > max_msg_size {
+            if len > max_msg_size as usize {
                 let msg = MQTTMessage {
                     header,
                     op: MQTTOperation::TRUNCATED(MQTTTruncatedData {
index 9cb4f815531c6e2f1e5551b2ccbddc2338c67d3e..133ed47cd1e884504a61480cbc0e3d032946d63b 100755 (executable)
@@ -36,7 +36,6 @@ noinst_HEADERS = \
        app-layer-krb5.h \
        app-layer-modbus.h \
        app-layer-quic.h \
-       app-layer-mqtt.h \
        app-layer-nfs-tcp.h \
        app-layer-nfs-udp.h \
        app-layer-ntp.h \
@@ -655,7 +654,6 @@ libsuricata_c_a_SOURCES = \
        app-layer-krb5.c \
        app-layer-modbus.c \
        app-layer-quic.c \
-       app-layer-mqtt.c \
        app-layer-nfs-tcp.c \
        app-layer-nfs-udp.c \
        app-layer-ntp.c \
diff --git a/src/app-layer-mqtt.c b/src/app-layer-mqtt.c
deleted file mode 100644 (file)
index 96b4cc2..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Copyright (C) 2020 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 Sascha Steinbiss <sascha@steinbiss.name>
- */
-
-#include "suricata-common.h"
-#include "stream.h"
-#include "conf.h"
-
-#include "util-misc.h"
-#include "util-unittest.h"
-
-#include "app-layer-detect-proto.h"
-#include "app-layer-parser.h"
-
-#include "app-layer-mqtt.h"
-#include "rust.h"
-
-void RegisterMQTTParsers(void)
-{
-    SCLogDebug("Registering Rust mqtt parser.");
-    uint32_t max_msg_len = 1048576; /* default: 1MB */
-
-    if (AppLayerParserConfParserEnabled("tcp", "mqtt")) {
-        ConfNode *p = ConfGetNode("app-layer.protocols.mqtt.max-msg-length");
-        if (p != NULL) {
-            uint32_t value;
-            if (ParseSizeStringU32(p->val, &value) < 0) {
-                SCLogError("invalid value for max-msg-length: %s", p->val);
-            } else {
-                max_msg_len = value;
-            }
-        }
-        rs_mqtt_register_parser(max_msg_len);
-    }
-#ifdef UNITTESTS
-    AppLayerParserRegisterProtocolUnittests(IPPROTO_TCP, ALPROTO_MQTT,
-        MQTTParserRegisterTests);
-#endif
-}
-
-void MQTTParserRegisterTests(void)
-{
-#ifdef UNITTESTS
-#endif
-}
diff --git a/src/app-layer-mqtt.h b/src/app-layer-mqtt.h
deleted file mode 100644 (file)
index b55720e..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Copyright (C) 2020 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 Sascha Steinbiss <sascha@steinbiss.name>
- */
-
-#ifndef __APP_LAYER_MQTT_H__
-#define __APP_LAYER_MQTT_H__
-
-void RegisterMQTTParsers(void);
-void MQTTParserRegisterTests(void);
-
-#endif /* __APP_LAYER_MQTT_H__ */
index 1f60664717571aff4410524bfd51f26301338ab0..96fc607fd2572f97505e84b2f70ea54b9db0f934 100644 (file)
@@ -57,7 +57,6 @@
 #include "app-layer-krb5.h"
 #include "app-layer-sip.h"
 #include "app-layer-rfb.h"
-#include "app-layer-mqtt.h"
 #include "app-layer-snmp.h"
 #include "app-layer-quic.h"
 #include "app-layer-rdp.h"
@@ -1766,7 +1765,7 @@ void AppLayerParserRegisterProtocolParsers(void)
     RegisterQuicParsers();
     rs_template_register_parser();
     RegisterRFBParsers();
-    RegisterMQTTParsers();
+    SCMqttRegisterParser();
     rs_pgsql_register_parser();
     RegisterRdpParsers();
     RegisterHTTP2Parsers();
index 2f600343e20d7d98a1c143713834a15bb23abf8c..b743229f36e38511ffc77c2ab8aa624c17be8cd9 100644 (file)
@@ -41,7 +41,6 @@
 #include "app-layer.h"
 #include "app-layer-parser.h"
 
-#include "app-layer-mqtt.h"
 #include "output-json-mqtt.h"
 #include "rust.h"