rust: format all files

except the ones with #[rustfmt::skip]

Ticket: 3836
pull/15699/head
Philippe Antoine 3 weeks ago committed by Victor Julien
parent 3adb975032
commit e6ee69c7da

@ -17,18 +17,16 @@
//! Parser registration functions and common interface module.
use std;
use crate::core::STREAM_TOSERVER;
use crate::direction::Direction;
use crate::flow::Flow;
use std::os::raw::{c_void,c_char,c_int};
use std;
use std::os::raw::{c_char, c_int, c_void};
// Make the AppLayerEvent derive macro available to users importing
// AppLayerEvent from this module.
pub use suricata_derive::AppLayerEvent;
use suricata_sys::sys::{
AppLayerGetTxIterState, AppLayerParserState, AppProto,
};
use suricata_sys::sys::{AppLayerGetTxIterState, AppLayerParserState, AppProto};
pub use suricata_sys::sys::{
AppLayerGetFileState, AppLayerGetTxIterTuple, AppLayerResult, AppLayerStateData,
@ -37,68 +35,70 @@ pub use suricata_sys::sys::{
pub use suricata_ffi::cast_pointer;
pub use suricata_ffi::{export_tx_data_get, export_state_data_get};
pub use suricata_ffi::{export_state_data_get, export_tx_data_get};
pub use suricata_ffi::applayer::{AppLayerEvent, AppLayerEventType, AppLayerResultRust, AppLayerTxData, StreamSliceRust};
pub use suricata_ffi::applayer::{
AppLayerEvent, AppLayerEventType, AppLayerResultRust, AppLayerTxData, StreamSliceRust,
};
/// Rust parser declaration
#[repr(C)]
pub struct RustParser {
/// Parser name.
pub name: *const c_char,
pub name: *const c_char,
/// Default port
pub default_port: *const c_char,
pub default_port: *const c_char,
/// IP Protocol (core::IPPROTO_UDP, core::IPPROTO_TCP, etc.)
pub ipproto: u8,
pub ipproto: u8,
/// Probing function, for packets going to server
pub probe_ts: Option<ProbeFn>,
pub probe_ts: Option<ProbeFn>,
/// Probing function, for packets going to client
pub probe_tc: Option<ProbeFn>,
pub probe_tc: Option<ProbeFn>,
/// Minimum frame depth for probing
pub min_depth: u16,
pub min_depth: u16,
/// Maximum frame depth for probing
pub max_depth: u16,
pub max_depth: u16,
/// Allocation function for a new state
pub state_new: StateAllocFn,
pub state_new: StateAllocFn,
/// Function called to free a state
pub state_free: StateFreeFn,
pub state_free: StateFreeFn,
/// Parsing function, for packets going to server
pub parse_ts: ParseFn,
pub parse_ts: ParseFn,
/// Parsing function, for packets going to client
pub parse_tc: ParseFn,
pub parse_tc: ParseFn,
/// Get the current transaction count
pub get_tx_count: StateGetTxCntFn,
pub get_tx_count: StateGetTxCntFn,
/// Get a transaction
pub get_tx: StateGetTxFn,
pub get_tx: StateGetTxFn,
/// Function called to free a transaction
pub tx_free: StateTxFreeFn,
pub tx_free: StateTxFreeFn,
/// Progress values at which the tx is considered complete in a direction
pub tx_comp_st_ts: c_int,
pub tx_comp_st_tc: c_int,
pub tx_comp_st_ts: c_int,
pub tx_comp_st_tc: c_int,
/// Function returning the current transaction progress
pub tx_get_progress: StateGetProgressFn,
pub tx_get_progress: StateGetProgressFn,
/// Function to get an event id from a description
pub get_eventinfo: Option<GetEventInfoFn>,
pub get_eventinfo: Option<GetEventInfoFn>,
/// Function to get an event description from an event id
pub get_eventinfo_byid: Option<GetEventInfoByIdFn>,
/// Function to allocate local storage
pub localstorage_new: Option<LocalStorageNewFn>,
pub localstorage_new: Option<LocalStorageNewFn>,
/// Function to free local storage
pub localstorage_free: Option<LocalStorageFreeFn>,
pub localstorage_free: Option<LocalStorageFreeFn>,
/// Function to get files
pub get_tx_files: Option<GetTxFilesFn>,
pub get_tx_files: Option<GetTxFilesFn>,
/// Function to get the TX iterator
pub get_tx_iterator: Option<GetTxIteratorFn>,
pub get_tx_iterator: Option<GetTxIteratorFn>,
pub get_state_data: GetStateDataFn,
pub get_tx_data: GetTxDataFn,
@ -124,36 +124,51 @@ pub trait AppLayerGetFileStateRust {
impl AppLayerGetFileStateRust for AppLayerGetFileState {
fn err() -> AppLayerGetFileState {
AppLayerGetFileState { fc: std::ptr::null_mut(), cfg: std::ptr::null() }
AppLayerGetFileState {
fc: std::ptr::null_mut(),
cfg: std::ptr::null(),
}
}
}
pub type ParseFn = unsafe extern "C" fn (flow: *mut Flow,
state: *mut c_void,
pstate: *mut AppLayerParserState,
stream_slice: StreamSlice,
data: *mut c_void) -> AppLayerResult;
pub type ProbeFn = unsafe extern "C" fn (flow: *const Flow, flags: u8, input:*const u8, input_len: u32, rdir: *mut u8) -> AppProto;
pub type StateAllocFn = unsafe extern "C" fn (*mut c_void, AppProto) -> *mut c_void;
pub type StateFreeFn = unsafe extern "C" fn (*mut c_void);
pub type StateTxFreeFn = unsafe extern "C" fn (*mut c_void, u64);
pub type StateGetTxFn = unsafe extern "C" fn (*mut c_void, u64) -> *mut c_void;
pub type StateGetTxCntFn = unsafe extern "C" fn (*mut c_void) -> u64;
pub type StateGetProgressFn = unsafe extern "C" fn (*mut c_void, u8) -> c_int;
pub type GetEventInfoFn = unsafe extern "C" fn (*const c_char, event_id: *mut u8, *mut AppLayerEventType) -> c_int;
pub type GetEventInfoByIdFn = unsafe extern "C" fn (event_id: u8, *mut *const c_char, *mut AppLayerEventType) -> c_int;
pub type LocalStorageNewFn = unsafe extern "C" fn () -> *mut c_void;
pub type LocalStorageFreeFn = unsafe extern "C" fn (*mut c_void);
pub type GetTxFilesFn = unsafe extern "C" fn (*mut c_void, u8) -> AppLayerGetFileState;
pub type GetTxIteratorFn = unsafe extern "C" fn (ipproto: u8, alproto: AppProto,
state: *mut c_void,
min_tx_id: u64,
max_tx_id: u64,
istate: *mut AppLayerGetTxIterState)
-> AppLayerGetTxIterTuple;
pub type ParseFn = unsafe extern "C" fn(
flow: *mut Flow,
state: *mut c_void,
pstate: *mut AppLayerParserState,
stream_slice: StreamSlice,
data: *mut c_void,
) -> AppLayerResult;
pub type ProbeFn = unsafe extern "C" fn(
flow: *const Flow,
flags: u8,
input: *const u8,
input_len: u32,
rdir: *mut u8,
) -> AppProto;
pub type StateAllocFn = unsafe extern "C" fn(*mut c_void, AppProto) -> *mut c_void;
pub type StateFreeFn = unsafe extern "C" fn(*mut c_void);
pub type StateTxFreeFn = unsafe extern "C" fn(*mut c_void, u64);
pub type StateGetTxFn = unsafe extern "C" fn(*mut c_void, u64) -> *mut c_void;
pub type StateGetTxCntFn = unsafe extern "C" fn(*mut c_void) -> u64;
pub type StateGetProgressFn = unsafe extern "C" fn(*mut c_void, u8) -> c_int;
pub type GetEventInfoFn =
unsafe extern "C" fn(*const c_char, event_id: *mut u8, *mut AppLayerEventType) -> c_int;
pub type GetEventInfoByIdFn =
unsafe extern "C" fn(event_id: u8, *mut *const c_char, *mut AppLayerEventType) -> c_int;
pub type LocalStorageNewFn = unsafe extern "C" fn() -> *mut c_void;
pub type LocalStorageFreeFn = unsafe extern "C" fn(*mut c_void);
pub type GetTxFilesFn = unsafe extern "C" fn(*mut c_void, u8) -> AppLayerGetFileState;
pub type GetTxIteratorFn = unsafe extern "C" fn(
ipproto: u8,
alproto: AppProto,
state: *mut c_void,
min_tx_id: u64,
max_tx_id: u64,
istate: *mut AppLayerGetTxIterState,
) -> AppLayerGetTxIterTuple;
pub type GetTxDataFn = unsafe extern "C" fn(*mut c_void) -> *mut suricata_sys::sys::AppLayerTxData;
pub type GetStateDataFn = unsafe extern "C" fn(*mut c_void) -> *mut AppLayerStateData;
pub type ApplyTxConfigFn = unsafe extern "C" fn (*mut c_void, *mut c_void, c_int, AppLayerTxConfig);
pub type ApplyTxConfigFn = unsafe extern "C" fn(*mut c_void, *mut c_void, c_int, AppLayerTxConfig);
pub type GetFrameIdByName = unsafe extern "C" fn(*const c_char) -> c_int;
pub type GetFrameNameById = unsafe extern "C" fn(u8) -> *const c_char;
pub type GetStateIdByName = unsafe extern "C" fn(*const c_char, u8) -> c_int;
@ -163,7 +178,7 @@ use suricata_sys::sys::{AppLayerParser, SCAppLayerRegisterParser};
#[allow(non_snake_case)]
pub fn AppLayerRegisterParser(parser: &RustParser, alproto: AppProto) -> c_int {
let det = AppLayerParser{
let det = AppLayerParser {
name: parser.name,
default_port: parser.default_port,
ip_proto: parser.ipproto,
@ -204,13 +219,15 @@ pub fn AppLayerRegisterParser(parser: &RustParser, alproto: AppProto) -> c_int {
GetStateIdByName: parser.get_state_id_by_name,
GetStateNameById: parser.get_state_name_by_id,
};
unsafe {SCAppLayerRegisterParser(&det, alproto) }
unsafe { SCAppLayerRegisterParser(&det, alproto) }
}
use suricata_sys::sys::{AppLayerProtocolDetect, SCAppLayerRegisterProtocolDetection};
pub fn applayer_register_protocol_detection(parser: &RustParser, enable_default: c_int) -> AppProto {
let det = AppLayerProtocolDetect{
pub fn applayer_register_protocol_detection(
parser: &RustParser, enable_default: c_int,
) -> AppProto {
let det = AppLayerProtocolDetect {
name: parser.name,
default_port: parser.default_port,
ip_proto: parser.ipproto,
@ -219,14 +236,14 @@ pub fn applayer_register_protocol_detection(parser: &RustParser, enable_default:
min_depth: parser.min_depth,
max_depth: parser.max_depth,
};
unsafe {SCAppLayerRegisterProtocolDetection(&det, enable_default) }
unsafe { SCAppLayerRegisterProtocolDetection(&det, enable_default) }
}
pub use suricata_ffi::applayer::{
APP_LAYER_PARSER_BYPASS_READY, APP_LAYER_PARSER_EOF_TC, APP_LAYER_PARSER_EOF_TS,
APP_LAYER_PARSER_NO_INSPECTION, APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD,
APP_LAYER_PARSER_NO_REASSEMBLY, APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
APP_LAYER_TX_SKIP_INSPECT_TS, APP_LAYER_TX_SKIP_INSPECT_TC,
APP_LAYER_PARSER_NO_REASSEMBLY, APP_LAYER_PARSER_OPT_ACCEPT_GAPS, APP_LAYER_TX_SKIP_INSPECT_TC,
APP_LAYER_TX_SKIP_INSPECT_TS,
};
pub const _APP_LAYER_TX_INSPECTED_TS: u8 = BIT_U8!(2);
@ -251,7 +268,9 @@ pub trait AppLayerFrameType {
/// Create a frame type variant from a u8.
///
/// None will be returned if there is no matching enum variant.
fn from_u8(value: u8) -> Option<Self> where Self: std::marker::Sized;
fn from_u8(value: u8) -> Option<Self>
where
Self: std::marker::Sized;
/// Return the u8 value of the enum where the first entry has the value of 0.
fn as_u8(&self) -> u8;
@ -259,14 +278,19 @@ pub trait AppLayerFrameType {
/// Create a frame type variant from a &str.
///
/// None will be returned if there is no matching enum variant.
fn from_str(s: &str) -> Option<Self> where Self: std::marker::Sized;
fn from_str(s: &str) -> Option<Self>
where
Self: std::marker::Sized;
/// Return a pointer to a C string of the enum variant suitable as-is for
/// FFI.
fn to_cstring(&self) -> *const std::os::raw::c_char;
/// Converts a C string formatted name to a frame type ID.
unsafe extern "C" fn ffi_id_from_name(name: *const std::os::raw::c_char) -> i32 where Self: Sized {
unsafe extern "C" fn ffi_id_from_name(name: *const std::os::raw::c_char) -> i32
where
Self: Sized,
{
if name.is_null() {
return -1;
}
@ -279,8 +303,13 @@ pub trait AppLayerFrameType {
}
/// Converts a variant ID to an FFI safe name.
extern "C" fn ffi_name_from_id(id: u8) -> *const std::os::raw::c_char where Self: Sized {
Self::from_u8(id).map(|s| s.to_cstring()).unwrap_or_else(std::ptr::null)
extern "C" fn ffi_name_from_id(id: u8) -> *const std::os::raw::c_char
where
Self: Sized,
{
Self::from_u8(id)
.map(|s| s.to_cstring())
.unwrap_or_else(std::ptr::null)
}
}

@ -113,9 +113,7 @@ pub fn to_hex(input: &[u8]) -> String {
}
#[no_mangle]
pub unsafe extern "C" fn SCToHex(
output: *mut u8, out_len: usize, input: *const u8, in_len: usize,
) {
pub unsafe extern "C" fn SCToHex(output: *mut u8, out_len: usize, input: *const u8, in_len: usize) {
if out_len < 2 * in_len + 1 {
return;
}

@ -31,12 +31,12 @@ use std::ptr;
use std::str;
use suricata_sys::sys::SCConfGetChildValue;
use suricata_sys::sys::SCConfGetChildValueBool;
use suricata_sys::sys::SCConfGetNode;
use suricata_sys::sys::SCConfNode;
use suricata_sys::sys::SCConfNodeLookupChild;
use suricata_sys::sys::SCConfGetFirstNode;
use suricata_sys::sys::SCConfGetNextNode;
use suricata_sys::sys::SCConfGetNode;
use suricata_sys::sys::SCConfGetValueNode;
use suricata_sys::sys::SCConfNode;
use suricata_sys::sys::SCConfNodeLookupChild;
pub fn conf_get_node(key: &str) -> Option<ConfNode> {
let key = if let Ok(key) = CString::new(key) {
@ -179,7 +179,8 @@ pub fn get_memval(arg: &str) -> Result<u64, &'static str> {
let r: IResult<&str, (f64, &str)> = (
preceded(multispace0, double),
preceded(multispace0, verify(not_line_ending, |c: &str| c.len() < 4)),
).parse(arg);
)
.parse(arg);
if let Ok(r) = r {
val = (r.1).0;
unit = (r.1).1;

@ -17,46 +17,50 @@
//! This module exposes items from the core "C" code to Rust.
use suricata_sys::sys::{AppProto, AppProtoEnum};
#[cfg(not(test))]
use suricata_sys::sys::SCAppLayerParserTriggerRawStreamInspection;
use suricata_sys::sys::{AppProto, AppProtoEnum};
use crate::flow::Flow;
pub use suricata_sys::sys::AppLayerEventType;
pub use suricata_ffi::STREAM_START;
pub use suricata_ffi::STREAM_DEPTH;
pub use suricata_ffi::STREAM_EOF;
pub use suricata_ffi::STREAM_TOSERVER;
pub use suricata_ffi::STREAM_TOCLIENT;
pub use suricata_ffi::STREAM_GAP;
pub use suricata_ffi::STREAM_DEPTH;
pub use suricata_ffi::STREAM_MIDSTREAM;
pub use suricata_ffi::STREAM_START;
pub use suricata_ffi::STREAM_TOCLIENT;
pub use suricata_ffi::STREAM_TOSERVER;
pub const ALPROTO_UNKNOWN : AppProto = AppProtoEnum::ALPROTO_UNKNOWN as AppProto;
pub const ALPROTO_FAILED : AppProto = AppProtoEnum::ALPROTO_FAILED as AppProto;
pub const ALPROTO_UNKNOWN: AppProto = AppProtoEnum::ALPROTO_UNKNOWN as AppProto;
pub const ALPROTO_FAILED: AppProto = AppProtoEnum::ALPROTO_FAILED as AppProto;
pub use suricata_ffi::IPPROTO_TCP;
pub use suricata_ffi::IPPROTO_UDP;
macro_rules!BIT_U8 {
($x:expr) => (1 << $x);
macro_rules! BIT_U8 {
($x:expr) => {
1 << $x
};
}
/*unused macro_rules!BIT_U16 {
($x:expr) => (1 << $x);
}*/
macro_rules!BIT_U32 {
($x:expr) => (1 << $x);
macro_rules! BIT_U32 {
($x:expr) => {
1 << $x
};
}
macro_rules!BIT_U64 {
($x:expr) => (1 << $x);
macro_rules! BIT_U64 {
($x:expr) => {
1 << $x
};
}
//
// Function types for calls into C.
//
@ -77,4 +81,7 @@ pub(crate) fn sc_app_layer_parser_trigger_raw_stream_inspection(flow: *mut Flow,
}
#[cfg(test)]
pub(crate) fn sc_app_layer_parser_trigger_raw_stream_inspection(_flow: *const Flow, _direction: i32) {}
pub(crate) fn sc_app_layer_parser_trigger_raw_stream_inspection(
_flow: *const Flow, _direction: i32,
) {
}

@ -19,9 +19,9 @@
use std::path::Path;
use suricata_sys::sys::SCLogLevel;
#[cfg(not(test))]
use suricata_sys::sys::SCError;
use suricata_sys::sys::SCLogLevel;
pub static mut LEVEL: SCLogLevel = SCLogLevel::SC_LOG_NOTSET;

@ -35,4 +35,4 @@ impl std::str::FromStr for EncryptionHandling {
_ => Err(()),
}
}
}
}

@ -48,7 +48,6 @@ mod real {
use std::ffi::CString;
use suricata_sys::sys::{SCRequiresFeature, SCSigTableHasKeyword};
/// Check for a feature returning true if found.
pub fn requires(feature: &str) -> bool {
if let Ok(feature) = CString::new(feature) {

@ -28,9 +28,9 @@
//! Author: Victor Julien <victor@inliniac.net>
use crate::core::*;
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use crate::filecontainer::*;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::HashMap;
#[derive(Debug)]
struct FileChunk {
@ -47,11 +47,10 @@ impl FileChunk {
}
}
#[derive(Debug)]
#[derive(Default)]
#[derive(Debug, Default)]
pub struct FileTransferTracker {
pub tracked: u64,
cur_ooo: u64, // how many bytes do we have queued from ooo chunks
cur_ooo: u64, // how many bytes do we have queued from ooo chunks
track_id: u32,
chunk_left: u32,
@ -76,7 +75,7 @@ pub struct FileTransferTracker {
impl FileTransferTracker {
pub fn new() -> FileTransferTracker {
FileTransferTracker {
chunks:HashMap::new(),
chunks: HashMap::new(),
..Default::default()
}
}
@ -89,28 +88,28 @@ impl FileTransferTracker {
return self.file_open || self.file_is_truncated || self.file_closed;
}
fn open(&mut self, config: &'static SuricataFileContext, name: &[u8]) -> i32
{
let r = self.file.file_open(config, self.track_id, name, self.file_flags);
fn open(&mut self, config: &'static SuricataFileContext, name: &[u8]) -> i32 {
let r = self
.file
.file_open(config, self.track_id, name, self.file_flags);
if r == 0 {
self.file_open = true;
}
r
}
pub fn close(&mut self, config: &'static SuricataFileContext)
{
pub fn close(&mut self, config: &'static SuricataFileContext) {
if !self.file_is_truncated {
SCLogDebug!("closing file with id {}", self.track_id);
self.file.file_close(config, &self.track_id, self.file_flags);
self.file
.file_close(config, &self.track_id, self.file_flags);
}
self.file_open = false;
self.file_closed = true;
self.tracked = 0;
}
pub fn trunc (&mut self, config: &'static SuricataFileContext)
{
pub fn trunc(&mut self, config: &'static SuricataFileContext) {
if self.file_is_truncated || !self.file_open {
return;
}
@ -123,22 +122,30 @@ impl FileTransferTracker {
self.cur_ooo = 0;
}
pub fn new_chunk(&mut self, config: &'static SuricataFileContext,
name: &[u8], data: &[u8], chunk_offset: u64, chunk_size: u32,
fill_bytes: u8, is_last: bool, xid: &u32) -> u32
{
pub fn new_chunk(
&mut self, config: &'static SuricataFileContext, name: &[u8], data: &[u8],
chunk_offset: u64, chunk_size: u32, fill_bytes: u8, is_last: bool, xid: &u32,
) -> u32 {
if self.chunk_left != 0 || self.fill_bytes != 0 {
SCLogDebug!("current chunk incomplete: truncating");
self.trunc(config);
}
SCLogDebug!("NEW CHUNK: chunk_size {} fill_bytes {}", chunk_size, fill_bytes);
SCLogDebug!(
"NEW CHUNK: chunk_size {} fill_bytes {}",
chunk_size,
fill_bytes
);
// for now assume that is_last means its really the last chunk
// so no out of order chunks coming after. This means that if
// the last chunk is out or order, we've missed chunks before.
if chunk_offset != self.tracked {
SCLogDebug!("NEW CHUNK IS OOO: expected {}, got {}", self.tracked, chunk_offset);
SCLogDebug!(
"NEW CHUNK IS OOO: expected {}, got {}",
self.tracked,
chunk_offset
);
if is_last {
SCLogDebug!("last chunk is out of order, this means we missed data before");
self.trunc(config);
@ -172,8 +179,9 @@ impl FileTransferTracker {
/// update the file tracker
/// If gap_size > 0 'data' should not be used.
/// return how much we consumed of data
pub fn update(&mut self, config: &'static SuricataFileContext, data: &[u8], gap_size: u32) -> u32
{
pub fn update(
&mut self, config: &'static SuricataFileContext, data: &[u8], gap_size: u32,
) -> u32 {
if self.file_is_truncated {
let consumed = std::cmp::min(data.len() as u32, self.chunk_left);
self.chunk_left = self.chunk_left.saturating_sub(data.len() as u32);
@ -182,7 +190,12 @@ impl FileTransferTracker {
let mut consumed = 0_usize;
let is_gap = gap_size > 0;
if is_gap || gap_size > 0 {
SCLogDebug!("is_gap {} size {} ooo? {}", is_gap, gap_size, self.chunk_is_ooo);
SCLogDebug!(
"is_gap {} size {} ooo? {}",
is_gap,
gap_size,
self.chunk_is_ooo
);
}
if self.chunk_left == 0 && self.fill_bytes == 0 {
@ -192,7 +205,7 @@ impl FileTransferTracker {
self.close(config);
self.chunk_is_last = false;
}
return 0
return 0;
} else if self.chunk_left == 0 {
SCLogDebug!("FILL BYTES {} from prev run", self.fill_bytes);
if data.len() >= self.fill_bytes as usize {
@ -205,7 +218,7 @@ impl FileTransferTracker {
SCLogDebug!("CHUNK(pre) fill bytes now still {}", self.fill_bytes);
}
SCLogDebug!("FILL BYTES: returning {}", consumed);
return consumed as u32
return consumed as u32;
}
SCLogDebug!("UPDATE: data {} chunk_left {}", data.len(), self.chunk_left);
@ -216,24 +229,26 @@ impl FileTransferTracker {
if !self.chunk_is_ooo {
let res = self.file.file_append(config, &self.track_id, d, is_gap);
match res {
0 => { },
-2 => {
0 => {}
-2 => {
self.file_is_truncated = true;
},
}
_ => {
SCLogDebug!("got error so truncating file");
self.file_is_truncated = true;
},
}
}
self.tracked += self.chunk_left as u64;
} else {
SCLogDebug!("UPDATE: appending data {} to ooo chunk at offset {}/{}",
d.len(), self.cur_ooo_chunk_offset, self.tracked);
SCLogDebug!(
"UPDATE: appending data {} to ooo chunk at offset {}/{}",
d.len(),
self.cur_ooo_chunk_offset,
self.tracked
);
let c = match self.chunks.entry(self.cur_ooo_chunk_offset) {
Vacant(entry) => {
entry.insert(FileChunk::new(self.chunk_left))
},
Vacant(entry) => entry.insert(FileChunk::new(self.chunk_left)),
Occupied(entry) => entry.into_mut(),
};
self.cur_ooo += d.len() as u64;
@ -267,31 +282,42 @@ impl FileTransferTracker {
Some(c) => {
self.in_flight -= c.chunk.len() as u64;
let res = self.file.file_append(config, &self.track_id, &c.chunk, c.contains_gap);
let res = self.file.file_append(
config,
&self.track_id,
&c.chunk,
c.contains_gap,
);
match res {
0 => { },
-2 => {
0 => {}
-2 => {
self.file_is_truncated = true;
},
}
_ => {
SCLogDebug!("got error so truncating file");
self.file_is_truncated = true;
},
}
}
self.tracked += c.chunk.len() as u64;
self.cur_ooo -= c.chunk.len() as u64;
SCLogDebug!("STORED OOO CHUNK at offset {}, tracked now {}, stored len {}", _offset, self.tracked, c.chunk.len());
},
}
_ => {
SCLogDebug!("NO STORED CHUNK found at _offset {}", self.tracked);
SCLogDebug!(
"NO STORED CHUNK found at _offset {}",
self.tracked
);
break;
},
}
};
}
} else {
SCLogDebug!("UPDATE: complete ooo chunk. Offset {}", self.cur_ooo_chunk_offset);
SCLogDebug!(
"UPDATE: complete ooo chunk. Offset {}",
self.cur_ooo_chunk_offset
);
self.chunk_is_ooo = false;
self.cur_ooo_chunk_offset = 0;
@ -304,19 +330,18 @@ impl FileTransferTracker {
} else {
SCLogDebug!("NOT last chunk, keep going");
}
} else {
if !self.chunk_is_ooo {
let res = self.file.file_append(config, &self.track_id, data, is_gap);
match res {
0 => { },
-2 => {
0 => {}
-2 => {
self.file_is_truncated = true;
},
}
_ => {
SCLogDebug!("got error so truncating file");
self.file_is_truncated = true;
},
}
}
self.tracked += data.len() as u64;
} else {

@ -27,9 +27,9 @@ use crate::flow::Flow;
#[cfg(not(test))]
use std::os::raw::c_void;
use suricata_sys::sys::{SCAppLayerFrameAddEventById, SCAppLayerFrameSetLengthById};
#[cfg(not(test))]
use suricata_sys::sys::{SCAppLayerFrameNewByRelativeOffset, SCAppLayerFrameSetTxIdById};
use suricata_sys::sys::{SCAppLayerFrameAddEventById, SCAppLayerFrameSetLengthById};
pub struct Frame {
pub id: i64,

@ -194,7 +194,7 @@ pub extern "C" fn SCTLSHandshakeNew() -> *mut HandshakeParams {
}
#[no_mangle]
pub unsafe extern "C" fn SCTLSHandshakeIsEmpty(hs: & HandshakeParams) -> bool {
pub unsafe extern "C" fn SCTLSHandshakeIsEmpty(hs: &HandshakeParams) -> bool {
*hs == HandshakeParams::default()
}
@ -233,48 +233,58 @@ pub unsafe extern "C" fn SCTLSHandshakeFree(hs: &mut HandshakeParams) {
}
#[no_mangle]
pub unsafe extern "C" fn SCTLSHandshakeLogVersion(hs: &HandshakeParams, js: *mut JsonBuilder) -> bool {
pub unsafe extern "C" fn SCTLSHandshakeLogVersion(
hs: &HandshakeParams, js: *mut JsonBuilder,
) -> bool {
if js.is_null() {
return false;
}
return hs.log_version(js.as_mut().unwrap()).is_ok()
return hs.log_version(js.as_mut().unwrap()).is_ok();
}
#[no_mangle]
pub unsafe extern "C" fn SCTLSHandshakeLogCiphers(hs: &HandshakeParams, js: *mut JsonBuilder) -> bool {
pub unsafe extern "C" fn SCTLSHandshakeLogCiphers(
hs: &HandshakeParams, js: *mut JsonBuilder,
) -> bool {
if js.is_null() {
return false;
}
return hs.log_ciphers(js.as_mut().unwrap()).is_ok()
return hs.log_ciphers(js.as_mut().unwrap()).is_ok();
}
#[no_mangle]
pub unsafe extern "C" fn SCTLSHandshakeLogFirstCipher(hs: &HandshakeParams, js: *mut JsonBuilder) -> bool {
pub unsafe extern "C" fn SCTLSHandshakeLogFirstCipher(
hs: &HandshakeParams, js: *mut JsonBuilder,
) -> bool {
if js.is_null() {
return false;
}
return hs.log_first_cipher(js.as_mut().unwrap()).is_ok()
return hs.log_first_cipher(js.as_mut().unwrap()).is_ok();
}
#[no_mangle]
pub unsafe extern "C" fn SCTLSHandshakeLogExtensions(hs: &HandshakeParams, js: *mut JsonBuilder) -> bool {
pub unsafe extern "C" fn SCTLSHandshakeLogExtensions(
hs: &HandshakeParams, js: *mut JsonBuilder,
) -> bool {
if js.is_null() {
return false;
}
return hs.log_exts(js.as_mut().unwrap()).is_ok()
return hs.log_exts(js.as_mut().unwrap()).is_ok();
}
#[no_mangle]
pub unsafe extern "C" fn SCTLSHandshakeLogSigAlgs(hs: &HandshakeParams, js: *mut JsonBuilder) -> bool {
pub unsafe extern "C" fn SCTLSHandshakeLogSigAlgs(
hs: &HandshakeParams, js: *mut JsonBuilder,
) -> bool {
if js.is_null() {
return false;
}
return hs.log_sig_algs(js.as_mut().unwrap()).is_ok()
return hs.log_sig_algs(js.as_mut().unwrap()).is_ok();
}
#[no_mangle]
pub unsafe extern "C" fn SCTLSHandshakeLogALPNs(
hs: &HandshakeParams, js: *mut JsonBuilder, ptr: *const c_char
hs: &HandshakeParams, js: *mut JsonBuilder, ptr: *const c_char,
) -> bool {
if js.is_null() {
return false;

@ -587,17 +587,17 @@ impl JsonBuilder {
b'\r' => {
self.push_str("\\r")?;
}
b'\n'=> {
b'\n' => {
self.push_str("\\n")?;
}
b'"'=> {
b'"' => {
self.push_str("\\\"")?;
}
b'\\'=> {
b'\\' => {
self.push_str("\\\\")?;
}
_ => {
if !x.is_ascii() || x.is_ascii_control() {
if !x.is_ascii() || x.is_ascii_control() {
self.push('.')?;
} else {
self.push(x as char)?;

@ -17,14 +17,14 @@
//! Kerberos parser wrapper module.
use nom7::IResult;
use nom7::error::{ErrorKind, ParseError};
use nom7::number::streaming::le_u16;
use asn1_rs::FromDer;
use der_parser;
use der_parser::der::parse_der_oid;
use der_parser::error::BerError;
use kerberos_parser::krb5::{ApReq, PrincipalName, Realm};
use asn1_rs::FromDer;
use nom7::error::{ErrorKind, ParseError};
use nom7::number::streaming::le_u16;
use nom7::IResult;
#[derive(Debug)]
pub enum SecBlobError {
@ -55,12 +55,11 @@ pub struct Kerberos5Ticket {
pub sname: PrincipalName,
}
fn parse_kerberos5_request_do(blob: &[u8]) -> IResult<&[u8], ApReq<'_>, SecBlobError>
{
let (_,b) = der_parser::parse_der(blob).map_err(nom7::Err::convert)?;
let blob = b.as_slice().or(
Err(nom7::Err::Error(SecBlobError::KrbFmtError))
)?;
fn parse_kerberos5_request_do(blob: &[u8]) -> IResult<&[u8], ApReq<'_>, SecBlobError> {
let (_, b) = der_parser::parse_der(blob).map_err(nom7::Err::convert)?;
let blob = b
.as_slice()
.or(Err(nom7::Err::Error(SecBlobError::KrbFmtError)))?;
let parser = |i| {
let (i, _base_o) = parse_der_oid(i)?;
let (i, _tok_id) = le_u16(i)?;

@ -21,34 +21,26 @@
//! the components written in Rust.
#![cfg_attr(feature = "strict", deny(warnings))]
// Allow these patterns as its a style we like.
#![allow(clippy::needless_return)]
#![allow(clippy::let_and_return)]
#![allow(clippy::uninlined_format_args)]
// We find this is beyond what the linter should flag.
#![allow(clippy::items_after_test_module)]
// We find this makes sense at time.
#![allow(clippy::module_inception)]
// The match macro is not always more clear. But its use is
// recommended where it makes sense.
#![allow(clippy::match_like_matches_macro)]
// Something we should be conscious of, but due to interfacing with C
// is unavoidable at this time.
#![allow(clippy::too_many_arguments)]
// This would be nice, but having this lint enables causes
// clippy --fix to make changes that don't meet our MSRV.
#![allow(clippy::derivable_impls)]
// TODO: All unsafe functions should have a safety doc, even if its
// just due to FFI.
#![allow(clippy::missing_safety_doc)]
// Allow unknown lints, our MSRV doesn't know them all, for
// example static_mut_refs.
#![allow(unknown_lints)]
@ -59,17 +51,17 @@ extern crate suricata_ffi;
extern crate bitflags;
extern crate byteorder;
extern crate crc;
extern crate memchr;
extern crate lru;
extern crate memchr;
#[macro_use]
extern crate num_derive;
extern crate widestring;
extern crate der_parser;
extern crate kerberos_parser;
extern crate ldap_parser;
extern crate tls_parser;
extern crate x509_parser;
extern crate ldap_parser;
#[macro_use]
extern crate suricata_derive;
@ -85,61 +77,61 @@ pub mod conf;
pub mod jsonbuilder;
#[macro_use]
pub mod applayer;
pub mod frames;
pub mod detect;
pub mod filecontainer;
pub mod filetracker;
pub mod frames;
pub mod kerberos;
pub mod detect;
pub mod utils;
pub mod encryption;
pub mod handshake;
pub mod ja4;
pub mod tls_version;
pub mod handshake;
pub mod encryption;
pub mod lua;
pub mod dcerpc;
pub mod dnp3;
pub mod dns;
pub mod mdns;
pub mod nfs;
pub mod ftp;
pub mod smb;
pub mod krb;
pub mod dcerpc;
pub mod mdns;
pub mod modbus;
pub mod nfs;
pub mod smb;
pub mod ike;
pub mod snmp;
pub mod ntp;
pub mod tftp;
pub mod applayertemplate;
pub mod asn1;
pub mod bittorrent_dht;
pub mod dhcp;
pub mod sip;
pub mod rfb;
pub mod enip;
pub mod feature;
pub mod ffi;
pub mod flow;
pub mod http2;
pub mod ldap;
pub mod lzma;
pub mod mime;
pub mod mqtt;
pub mod ntp;
pub mod pgsql;
pub mod telnet;
pub mod websocket;
pub mod enip;
pub mod pop3;
pub mod applayertemplate;
pub mod rdp;
pub mod x509;
pub mod asn1;
pub mod mime;
pub mod ssh;
pub mod http2;
pub mod quic;
pub mod bittorrent_dht;
pub mod lzma;
pub mod util;
pub mod ffi;
pub mod feature;
pub mod rdp;
pub mod rfb;
pub mod sctp;
pub mod sdp;
pub mod ldap;
pub mod flow;
pub mod sip;
pub mod ssh;
pub mod telnet;
pub mod tftp;
pub mod util;
pub mod websocket;
pub mod x509;
pub use suricata_ffi::direction;
pub mod llmnr;

@ -38,7 +38,6 @@ pub struct LuaState {
}
impl LuaState {
pub fn newtable(&self) {
unsafe {
lua_createtable(self.lua, 0, 0);

@ -41,7 +41,8 @@ fn is_alphanumeric_or_hyphen(chr: u8) -> bool {
fn parse_domain_label(i: &[u8]) -> IResult<&[u8], ()> {
let (i, _) = verify(take_while1(is_alphanumeric_or_hyphen), |x: &[u8]| {
x[0].is_alpha() && x[x.len() - 1] != b'-'
}).parse(i)?;
})
.parse(i)?;
return Ok((i, ()));
}

Loading…
Cancel
Save