Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mqtt: improve rule support for detection #11995

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions rust/src/mqtt/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,29 @@ fn mqtt_tx_get_reason_code(tx: &MQTTTransaction) -> Option<u8> {
return None;
}

fn mqtt_tx_unsuback_has_reason_code(tx: &MQTTTransaction, code: &DetectUintData<u8>) -> c_int {
fn mqtt_tx_suback_unsuback_has_reason_code(
tx: &MQTTTransaction, code: &DetectUintData<u8>,
) -> c_int {
for msg in tx.msg.iter() {
if let MQTTOperation::UNSUBACK(ref unsuback) = msg.op {
if let Some(ref reason_codes) = unsuback.reason_codes {
for rc in reason_codes.iter() {
match msg.op {
MQTTOperation::UNSUBACK(ref unsuback) => {
if let Some(ref reason_codes) = unsuback.reason_codes {
for rc in reason_codes.iter() {
if detect_match_uint(code, *rc) {
return 1;
}
}
}
}
MQTTOperation::SUBACK(ref suback) => {
// in SUBACK these are stored as "QOS granted" historically
for rc in suback.qoss.iter() {
if detect_match_uint(code, *rc) {
return 1;
}
}
}
_ => {}
}
}
return 0;
Expand Down Expand Up @@ -476,7 +489,7 @@ unsafe extern "C" fn mqtt_reason_code_match(
return 1;
}
}
return mqtt_tx_unsuback_has_reason_code(tx, ctx);
return mqtt_tx_suback_unsuback_has_reason_code(tx, ctx);
}

unsafe extern "C" fn mqtt_reason_code_free(_de: *mut c_void, ctx: *mut c_void) {
Expand Down
Loading