-/* 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
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;
connected: bool,
skip_request: usize,
skip_response: usize,
- max_msg_len: usize,
+ max_msg_len: u32,
tx_index_completed: usize,
}
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,
}
}
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(),
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.");
}
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.
// 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 {
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 \
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 \
+++ /dev/null
-/* 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
-}
+++ /dev/null
-/* 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__ */
#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"
RegisterQuicParsers();
rs_template_register_parser();
RegisterRFBParsers();
- RegisterMQTTParsers();
+ SCMqttRegisterParser();
rs_pgsql_register_parser();
RegisterRdpParsers();
RegisterHTTP2Parsers();
#include "app-layer.h"
#include "app-layer-parser.h"
-#include "app-layer-mqtt.h"
#include "output-json-mqtt.h"
#include "rust.h"