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

app-layer/template: use a max number of txs #10367

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
20 changes: 19 additions & 1 deletion rust/src/applayertemplate/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@

use super::parser;
use crate::applayer::{self, *};
use crate::conf::conf_get;
use crate::core::{AppProto, Flow, ALPROTO_UNKNOWN, IPPROTO_TCP};
use nom7 as nom;
use std;
use std::collections::VecDeque;
use std::ffi::CString;
use std::os::raw::{c_char, c_int, c_void};

static mut TEMPLATE_MAX_TX: usize = 256;

static mut ALPROTO_TEMPLATE: AppProto = ALPROTO_UNKNOWN;

#[derive(AppLayerEvent)]
enum TemplateEvent {}
enum TemplateEvent {
TooManyTransactions,
}

pub struct TemplateTransaction {
tx_id: u64,
Expand Down Expand Up @@ -145,7 +150,13 @@ impl TemplateState {
SCLogNotice!("Request: {}", request);
let mut tx = self.new_tx();
tx.request = Some(request);
if self.transactions.len() >= unsafe {TEMPLATE_MAX_TX} {
tx.tx_data.set_event(TemplateEvent::TooManyTransactions as u8);
}
self.transactions.push_back(tx);
if self.transactions.len() >= unsafe {TEMPLATE_MAX_TX} {
return AppLayerResult::err();
}
}
Err(nom::Err::Incomplete(_)) => {
// Not enough data. This parser doesn't give us a good indication
Expand Down Expand Up @@ -429,6 +440,13 @@ pub unsafe extern "C" fn rs_template_register_parser() {
if AppLayerParserConfParserEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
let _ = AppLayerRegisterParser(&parser, alproto);
}
if let Some(val) = conf_get("app-layer.protocols.template.max-tx") {
if let Ok(v) = val.parse::<usize>() {
TEMPLATE_MAX_TX = v;
} else {
SCLogError!("Invalid value for template.max-tx");
}
}
SCLogNotice!("Rust template parser registered.");
} else {
SCLogNotice!("Protocol detector and parser disabled for TEMPLATE.");
Expand Down
Loading