rust/direction: move direction to own file (cleanup)

Move the implementation of Direction to its own file, direction.rs.
pull/12424/head
Jason Ish 2 years ago committed by Victor Julien
parent 7ef4caf90e
commit f62be374ea

@ -18,7 +18,8 @@
//! Parser registration functions and common interface module. //! Parser registration functions and common interface module.
use std; use std;
use crate::core::{self,DetectEngineState,AppLayerEventType,AppProto,Direction}; use crate::core::{self,DetectEngineState,AppLayerEventType,AppProto};
use crate::direction::Direction;
use crate::filecontainer::FileContainer; use crate::filecontainer::FileContainer;
use crate::flow::Flow; use crate::flow::Flow;
use std::os::raw::{c_void,c_char,c_int}; use std::os::raw::{c_void,c_char,c_int};

@ -19,7 +19,7 @@ use super::template::{TemplateTransaction, ALPROTO_TEMPLATE};
/* TEMPLATE_START_REMOVE */ /* TEMPLATE_START_REMOVE */
use crate::conf::conf_get_node; use crate::conf::conf_get_node;
/* TEMPLATE_END_REMOVE */ /* TEMPLATE_END_REMOVE */
use crate::core::Direction; use crate::direction::Direction;
use crate::detect::{ use crate::detect::{
DetectBufferSetActiveList, DetectHelperBufferMpmRegister, DetectHelperGetData, DetectBufferSetActiveList, DetectHelperBufferMpmRegister, DetectHelperGetData,
DetectHelperKeywordRegister, DetectSignatureSetAppProto, SCSigTableElmt, DetectHelperKeywordRegister, DetectSignatureSetAppProto, SCSigTableElmt,

@ -19,7 +19,8 @@ use crate::applayer::{self, *};
use crate::bittorrent_dht::parser::{ use crate::bittorrent_dht::parser::{
parse_bittorrent_dht_packet, BitTorrentDHTError, BitTorrentDHTRequest, BitTorrentDHTResponse, parse_bittorrent_dht_packet, BitTorrentDHTError, BitTorrentDHTRequest, BitTorrentDHTResponse,
}; };
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_UDP, Direction}; use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_UDP};
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use std::ffi::CString; use std::ffi::CString;
use std::os::raw::c_char; use std::os::raw::c_char;
@ -99,7 +100,7 @@ impl BitTorrentDHTState {
} }
} }
pub fn parse(&mut self, input: &[u8], _direction: crate::core::Direction) -> bool { pub fn parse(&mut self, input: &[u8], _direction: Direction) -> bool {
if !Self::is_dht(input) { if !Self::is_dht(input) {
return true; return true;
} }
@ -171,7 +172,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_parse_ts(
) -> AppLayerResult { ) -> AppLayerResult {
return rs_bittorrent_dht_parse( return rs_bittorrent_dht_parse(
_flow, state, _pstate, stream_slice, _flow, state, _pstate, stream_slice,
_data, crate::core::Direction::ToServer); _data, Direction::ToServer);
} }
#[no_mangle] #[no_mangle]
@ -181,14 +182,14 @@ pub unsafe extern "C" fn rs_bittorrent_dht_parse_tc(
) -> AppLayerResult { ) -> AppLayerResult {
return rs_bittorrent_dht_parse( return rs_bittorrent_dht_parse(
_flow, state, _pstate, stream_slice, _flow, state, _pstate, stream_slice,
_data, crate::core::Direction::ToClient); _data, Direction::ToClient);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn rs_bittorrent_dht_parse( pub unsafe extern "C" fn rs_bittorrent_dht_parse(
_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void, _flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice, _data: *const std::os::raw::c_void, stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
direction: crate::core::Direction, direction: Direction,
) -> AppLayerResult { ) -> AppLayerResult {
let state = cast_pointer!(state, BitTorrentDHTState); let state = cast_pointer!(state, BitTorrentDHTState);
let buf = stream_slice.as_slice(); let buf = stream_slice.as_slice();
@ -302,7 +303,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() {
BITTORRENT_DHT_PAYLOAD_PREFIX.as_ptr() as *const c_char, BITTORRENT_DHT_PAYLOAD_PREFIX.as_ptr() as *const c_char,
BITTORRENT_DHT_PAYLOAD_PREFIX.len() as u16 - 1, BITTORRENT_DHT_PAYLOAD_PREFIX.len() as u16 - 1,
0, 0,
crate::core::Direction::ToServer.into(), Direction::ToServer.into(),
) < 0 ) < 0
{ {
SCLogDebug!("Failed to register protocol detection pattern for direction TOSERVER"); SCLogDebug!("Failed to register protocol detection pattern for direction TOSERVER");
@ -313,7 +314,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() {
BITTORRENT_DHT_PAYLOAD_PREFIX.as_ptr() as *const c_char, BITTORRENT_DHT_PAYLOAD_PREFIX.as_ptr() as *const c_char,
BITTORRENT_DHT_PAYLOAD_PREFIX.len() as u16 - 1, BITTORRENT_DHT_PAYLOAD_PREFIX.len() as u16 - 1,
0, 0,
crate::core::Direction::ToClient.into(), Direction::ToClient.into(),
) < 0 ) < 0
{ {
SCLogDebug!("Failed to register protocol detection pattern for direction TOCLIENT"); SCLogDebug!("Failed to register protocol detection pattern for direction TOCLIENT");

@ -446,7 +446,7 @@ pub fn parse_bittorrent_dht_packet(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::core::Direction; use crate::direction::Direction;
use test_case::test_case; use test_case::test_case;
#[test_case( #[test_case(

@ -19,7 +19,6 @@
use std; use std;
use crate::filecontainer::*; use crate::filecontainer::*;
use crate::debug_validate_fail;
use crate::flow::Flow; use crate::flow::Flow;
/// Opaque C types. /// Opaque C types.
@ -41,70 +40,6 @@ pub const STREAM_TOCLIENT: u8 = 0x08;
pub const STREAM_GAP: u8 = 0x10; pub const STREAM_GAP: u8 = 0x10;
pub const STREAM_DEPTH: u8 = 0x20; pub const STREAM_DEPTH: u8 = 0x20;
pub const STREAM_MIDSTREAM:u8 = 0x40; pub const STREAM_MIDSTREAM:u8 = 0x40;
pub const DIR_BOTH: u8 = 0b0000_1100;
const DIR_TOSERVER: u8 = 0b0000_0100;
const DIR_TOCLIENT: u8 = 0b0000_1000;
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Direction {
ToServer = 0x04,
ToClient = 0x08,
}
impl Direction {
/// Return true if the direction is to server.
pub fn is_to_server(&self) -> bool {
matches!(self, Self::ToServer)
}
/// Return true if the direction is to client.
pub fn is_to_client(&self) -> bool {
matches!(self, Self::ToClient)
}
pub fn index(&self) -> usize {
match self {
Self::ToClient => 0,
_ => 1,
}
}
}
impl Default for Direction {
fn default() -> Self { Direction::ToServer }
}
impl std::fmt::Display for Direction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ToServer => write!(f, "toserver"),
Self::ToClient => write!(f, "toclient"),
}
}
}
impl From<u8> for Direction {
fn from(d: u8) -> Self {
if d & (DIR_TOSERVER | DIR_TOCLIENT) == (DIR_TOSERVER | DIR_TOCLIENT) {
debug_validate_fail!("Both directions are set");
Direction::ToServer
} else if d & DIR_TOSERVER != 0 {
Direction::ToServer
} else if d & DIR_TOCLIENT != 0 {
Direction::ToClient
} else {
debug_validate_fail!("Unknown direction!!");
Direction::ToServer
}
}
}
impl From<Direction> for u8 {
fn from(d: Direction) -> u8 {
d as u8
}
}
// Application layer protocol identifiers (app-layer-protos.h) // Application layer protocol identifiers (app-layer-protos.h)
pub type AppProto = u16; pub type AppProto = u16;
@ -299,17 +234,3 @@ pub fn sc_app_layer_decoder_events_free_events(
} }
} }
} }
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_direction() {
assert!(Direction::ToServer.is_to_server());
assert!(!Direction::ToServer.is_to_client());
assert!(Direction::ToClient.is_to_client());
assert!(!Direction::ToClient.is_to_server());
}
}

@ -18,6 +18,7 @@
use crate::applayer::{self, *}; use crate::applayer::{self, *};
use crate::core::{self, *}; use crate::core::{self, *};
use crate::dcerpc::parser; use crate::dcerpc::parser;
use crate::direction::{Direction, DIR_BOTH};
use crate::flow::Flow; use crate::flow::Flow;
use nom7::error::{Error, ErrorKind}; use nom7::error::{Error, ErrorKind};
use nom7::number::Endianness; use nom7::number::Endianness;
@ -1389,6 +1390,7 @@ mod tests {
use crate::applayer::AppLayerResult; use crate::applayer::AppLayerResult;
use crate::core::*; use crate::core::*;
use crate::dcerpc::dcerpc::DCERPCState; use crate::dcerpc::dcerpc::DCERPCState;
use crate::direction::Direction;
use std::cmp; use std::cmp;
#[test] #[test]

@ -15,12 +15,13 @@
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use crate::core;
use crate::applayer::{self, *}; use crate::applayer::{self, *};
use crate::core::{self, Direction, DIR_BOTH};
use crate::dcerpc::dcerpc::{ use crate::dcerpc::dcerpc::{
DCERPCTransaction, DCERPC_MAX_TX, DCERPC_TYPE_REQUEST, DCERPC_TYPE_RESPONSE, PFCL1_FRAG, PFCL1_LASTFRAG, DCERPCTransaction, DCERPC_MAX_TX, DCERPC_TYPE_REQUEST, DCERPC_TYPE_RESPONSE, PFCL1_FRAG, PFCL1_LASTFRAG,
rs_dcerpc_get_alstate_progress, ALPROTO_DCERPC, PARSER_NAME, rs_dcerpc_get_alstate_progress, ALPROTO_DCERPC, PARSER_NAME,
}; };
use crate::direction::{Direction, DIR_BOTH};
use crate::flow::Flow; use crate::flow::Flow;
use nom7::Err; use nom7::Err;
use std; use std;

@ -0,0 +1,97 @@
/* Copyright (C) 2017-2025 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.
*/
pub const DIR_BOTH: u8 = 0b0000_1100;
const DIR_TOSERVER: u8 = 0b0000_0100;
const DIR_TOCLIENT: u8 = 0b0000_1000;
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Direction {
ToServer = 0x04,
ToClient = 0x08,
}
impl Direction {
/// Return true if the direction is to server.
pub fn is_to_server(&self) -> bool {
matches!(self, Self::ToServer)
}
/// Return true if the direction is to client.
pub fn is_to_client(&self) -> bool {
matches!(self, Self::ToClient)
}
pub fn index(&self) -> usize {
match self {
Self::ToClient => 0,
_ => 1,
}
}
}
impl Default for Direction {
fn default() -> Self {
Direction::ToServer
}
}
impl std::fmt::Display for Direction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ToServer => write!(f, "toserver"),
Self::ToClient => write!(f, "toclient"),
}
}
}
impl From<u8> for Direction {
fn from(d: u8) -> Self {
if d & (DIR_TOSERVER | DIR_TOCLIENT) == (DIR_TOSERVER | DIR_TOCLIENT) {
debug_validate_fail!("Both directions are set");
Direction::ToServer
} else if d & DIR_TOSERVER != 0 {
Direction::ToServer
} else if d & DIR_TOCLIENT != 0 {
Direction::ToClient
} else {
debug_validate_fail!("Unknown direction!!");
Direction::ToServer
}
}
}
impl From<Direction> for u8 {
fn from(d: Direction) -> u8 {
d as u8
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_direction() {
assert!(Direction::ToServer.is_to_server());
assert!(!Direction::ToServer.is_to_client());
assert!(Direction::ToClient.is_to_client());
assert!(!Direction::ToClient.is_to_server());
}
}

@ -16,7 +16,7 @@
*/ */
use super::dns::DNSTransaction; use super::dns::DNSTransaction;
use crate::core::Direction; use crate::direction::Direction;
use crate::detect::uint::{detect_match_uint, DetectUintData}; use crate::detect::uint::{detect_match_uint, DetectUintData};
/// Perform the DNS opcode match. /// Perform the DNS opcode match.

@ -22,6 +22,8 @@ use std::ffi::CString;
use crate::applayer::*; use crate::applayer::*;
use crate::core::{self, *}; use crate::core::{self, *};
use crate::direction::Direction;
use crate::direction::DIR_BOTH;
use crate::dns::parser; use crate::dns::parser;
use crate::flow::Flow; use crate::flow::Flow;
use crate::frames::Frame; use crate::frames::Frame;

@ -40,7 +40,7 @@ use crate::detect::{
SigMatchAppendSMToList, SIGMATCH_INFO_STICKY_BUFFER, SIGMATCH_NOOPT, SigMatchAppendSMToList, SIGMATCH_INFO_STICKY_BUFFER, SIGMATCH_NOOPT,
}; };
use crate::core::Direction; use crate::direction::Direction;
use std::ffi::CStr; use std::ffi::CStr;

@ -20,10 +20,11 @@ use super::parser;
use crate::applayer::{self, *}; use crate::applayer::{self, *};
use crate::conf::conf_get; use crate::conf::conf_get;
use crate::core::{ use crate::core::{
AppProto, Direction, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP, AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP,
STREAM_TOCLIENT, STREAM_TOSERVER, STREAM_TOCLIENT, STREAM_TOSERVER,
}; };
use crate::detect::EnumString; use crate::detect::EnumString;
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use crate::frames::Frame; use crate::frames::Frame;
use nom7 as nom; use nom7 as nom;

@ -21,7 +21,7 @@ use crate::applayer::StreamSlice;
use crate::flow::Flow; use crate::flow::Flow;
#[cfg(not(test))] #[cfg(not(test))]
use crate::core::STREAM_TOSERVER; use crate::core::STREAM_TOSERVER;
use crate::core::Direction; use crate::direction::Direction;
#[cfg(not(test))] #[cfg(not(test))]
#[repr(C)] #[repr(C)]

@ -15,7 +15,7 @@
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use crate::core::Direction; use crate::direction::Direction;
use brotli; use brotli;
use flate2::read::{DeflateDecoder, GzDecoder}; use flate2::read::{DeflateDecoder, GzDecoder};
use std; use std;

@ -19,7 +19,7 @@ use super::http2::{
HTTP2Event, HTTP2Frame, HTTP2FrameTypeData, HTTP2State, HTTP2Transaction, HTTP2TransactionState, HTTP2Event, HTTP2Frame, HTTP2FrameTypeData, HTTP2State, HTTP2Transaction, HTTP2TransactionState,
}; };
use super::parser; use super::parser;
use crate::core::Direction; use crate::direction::Direction;
use crate::detect::uint::{detect_match_uint, DetectUintData}; use crate::detect::uint::{detect_match_uint, DetectUintData};
use std::ffi::CStr; use std::ffi::CStr;
use std::str::FromStr; use std::str::FromStr;

@ -23,6 +23,7 @@ use super::range;
use crate::applayer::{self, *}; use crate::applayer::{self, *};
use crate::conf::conf_get; use crate::conf::conf_get;
use crate::core::*; use crate::core::*;
use crate::direction::Direction;
use crate::filecontainer::*; use crate::filecontainer::*;
use crate::filetracker::*; use crate::filetracker::*;
use crate::flow::Flow; use crate::flow::Flow;

@ -17,8 +17,9 @@
use super::detect; use super::detect;
use crate::core::{ use crate::core::{
Direction, HttpRangeContainerBlock, StreamingBufferConfig, SuricataFileContext, SC, HttpRangeContainerBlock, StreamingBufferConfig, SuricataFileContext, SC,
}; };
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use crate::http2::http2::HTTP2Transaction; use crate::http2::http2::HTTP2Transaction;
use crate::http2::http2::SURICATA_HTTP2_FILE_CONFIG; use crate::http2::http2::SURICATA_HTTP2_FILE_CONFIG;

@ -23,6 +23,7 @@ use self::ipsec_parser::*;
use crate::applayer; use crate::applayer;
use crate::applayer::*; use crate::applayer::*;
use crate::core::{self, *}; use crate::core::{self, *};
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use crate::ike::ikev1::{handle_ikev1, IkeV1Header, Ikev1Container}; use crate::ike::ikev1::{handle_ikev1, IkeV1Header, Ikev1Container};
use crate::ike::ikev2::{handle_ikev2, Ikev2Container}; use crate::ike::ikev2::{handle_ikev2, Ikev2Container};

@ -19,7 +19,7 @@
use crate::applayer::*; use crate::applayer::*;
use crate::common::to_hex; use crate::common::to_hex;
use crate::core::Direction; use crate::direction::Direction;
use crate::ike::ike::{IKEState, IkeEvent}; use crate::ike::ike::{IKEState, IkeEvent};
use crate::ike::parser::*; use crate::ike::parser::*;
use nom7::Err; use nom7::Err;

@ -18,7 +18,7 @@
// written by Pierre Chifflier <chifflier@wzdftpd.net> // written by Pierre Chifflier <chifflier@wzdftpd.net>
use crate::applayer::*; use crate::applayer::*;
use crate::core::Direction; use crate::direction::Direction;
use crate::ike::ipsec_parser::*; use crate::ike::ipsec_parser::*;
use super::ipsec_parser::IkeV2Transform; use super::ipsec_parser::IkeV2Transform;

@ -17,7 +17,7 @@
use super::ike::{IKEState, IKETransaction}; use super::ike::{IKEState, IKETransaction};
use super::ipsec_parser::IKEV2_FLAG_INITIATOR; use super::ipsec_parser::IKEV2_FLAG_INITIATOR;
use crate::core::Direction; use crate::direction::Direction;
use crate::ike::parser::{ExchangeType, IsakmpPayloadType, SaAttribute}; use crate::ike::parser::{ExchangeType, IsakmpPayloadType, SaAttribute};
use crate::jsonbuilder::{JsonBuilder, JsonError}; use crate::jsonbuilder::{JsonBuilder, JsonError};
use num_traits::FromPrimitive; use num_traits::FromPrimitive;

@ -28,7 +28,8 @@ use kerberos_parser::krb5::{EncryptionType,ErrorCode,MessageType,PrincipalName,R
use asn1_rs::FromDer; use asn1_rs::FromDer;
use crate::applayer::{self, *}; use crate::applayer::{self, *};
use crate::core; use crate::core;
use crate::core::{AppProto,ALPROTO_FAILED,ALPROTO_UNKNOWN,Direction, IPPROTO_TCP, IPPROTO_UDP}; use crate::core::{AppProto,ALPROTO_FAILED,ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP};
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
#[derive(AppLayerEvent)] #[derive(AppLayerEvent)]

@ -20,6 +20,7 @@
use crate::applayer::{self, *}; use crate::applayer::{self, *};
use crate::conf::conf_get; use crate::conf::conf_get;
use crate::core::*; use crate::core::*;
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use crate::frames::*; use crate::frames::*;
use nom7 as nom; use nom7 as nom;

@ -140,6 +140,7 @@ pub mod feature;
pub mod sdp; pub mod sdp;
pub mod ldap; pub mod ldap;
pub mod flow; pub mod flow;
pub mod direction;
#[allow(unused_imports)] #[allow(unused_imports)]
pub use suricata_lua_sys; pub use suricata_lua_sys;

@ -1426,7 +1426,7 @@ pub unsafe extern "C" fn ScDetectMqttRegister() {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::core::Direction; use crate::direction::Direction;
use crate::detect::uint::DetectUintMode; use crate::detect::uint::DetectUintMode;
use crate::mqtt::mqtt::MQTTTransaction; use crate::mqtt::mqtt::MQTTTransaction;
use crate::mqtt::mqtt_message::*; use crate::mqtt::mqtt_message::*;

@ -23,6 +23,7 @@ use crate::applayer::*;
use crate::applayer::{self, LoggerFlags}; use crate::applayer::{self, LoggerFlags};
use crate::conf::{conf_get, get_memval}; use crate::conf::{conf_get, get_memval};
use crate::core::*; use crate::core::*;
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use crate::frames::*; use crate::frames::*;
use nom7::Err; use nom7::Err;

@ -26,6 +26,8 @@ use nom7::{Err, Needed};
use crate::applayer; use crate::applayer;
use crate::applayer::*; use crate::applayer::*;
use crate::direction::Direction;
use crate::direction::DIR_BOTH;
use crate::flow::Flow; use crate::flow::Flow;
use crate::frames::*; use crate::frames::*;
use crate::core::*; use crate::core::*;

@ -17,8 +17,7 @@
// written by Victor Julien // written by Victor Julien
use crate::core::*; use crate::direction::Direction;
use crate::nfs::nfs::*; use crate::nfs::nfs::*;
use crate::nfs::types::*; use crate::nfs::types::*;
use crate::nfs::rpc_records::*; use crate::nfs::rpc_records::*;

@ -21,7 +21,7 @@ use nom7::bytes::streaming::take;
use nom7::number::streaming::be_u32; use nom7::number::streaming::be_u32;
use nom7::{Err, IResult}; use nom7::{Err, IResult};
use crate::core::*; use crate::direction::Direction;
use crate::nfs::nfs::*; use crate::nfs::nfs::*;
use crate::nfs::nfs4_records::*; use crate::nfs::nfs4_records::*;
use crate::nfs::nfs_records::*; use crate::nfs::nfs_records::*;

@ -20,8 +20,9 @@
extern crate ntp_parser; extern crate ntp_parser;
use self::ntp_parser::*; use self::ntp_parser::*;
use crate::core; use crate::core;
use crate::core::{AppProto,ALPROTO_UNKNOWN,ALPROTO_FAILED,Direction}; use crate::core::{AppProto,ALPROTO_UNKNOWN,ALPROTO_FAILED};
use crate::applayer::{self, *}; use crate::applayer::{self, *};
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use std; use std;
use std::ffi::CString; use std::ffi::CString;

@ -22,7 +22,8 @@
use super::parser::{self, ConsolidatedDataRowPacket, PgsqlBEMessage, PgsqlFEMessage}; use super::parser::{self, ConsolidatedDataRowPacket, PgsqlBEMessage, PgsqlFEMessage};
use crate::applayer::*; use crate::applayer::*;
use crate::conf::*; use crate::conf::*;
use crate::core::{AppProto, Direction, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, *}; use crate::core::{AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, *};
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use nom7::{Err, IResult}; use nom7::{Err, IResult};
use std; use std;

@ -21,8 +21,8 @@ use super::{
frames::{Frame, QuicTlsExtension, StreamTag}, frames::{Frame, QuicTlsExtension, StreamTag},
parser::{quic_pkt_num, QuicData, QuicHeader, QuicType}, parser::{quic_pkt_num, QuicData, QuicHeader, QuicType},
}; };
use crate::{applayer::{self, *}, flow::Flow}; use crate::{applayer::{self, *}, direction::Direction, flow::Flow};
use crate::core::{AppProto, Direction, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_UDP}; use crate::core::{AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_UDP};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::ffi::CString; use std::ffi::CString;
use tls_parser::TlsExtensionType; use tls_parser::TlsExtensionType;

@ -22,6 +22,7 @@ use super::parser;
use crate::applayer; use crate::applayer;
use crate::applayer::*; use crate::applayer::*;
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP}; use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use crate::frames::*; use crate::frames::*;
use nom7::Err; use nom7::Err;
@ -888,7 +889,7 @@ pub unsafe extern "C" fn SCRfbRegisterParser() {
b"RFB \0".as_ptr() as *const c_char, b"RFB \0".as_ptr() as *const c_char,
b"RFB ".len() as u16, b"RFB ".len() as u16,
0, 0,
crate::core::Direction::ToServer.into(), Direction::ToServer.into(),
) < 0 ) < 0
{ {
SCLogDebug!("Failed to register protocol detection pattern for direction TOSERVER"); SCLogDebug!("Failed to register protocol detection pattern for direction TOSERVER");
@ -899,7 +900,7 @@ pub unsafe extern "C" fn SCRfbRegisterParser() {
b"RFB \0".as_ptr() as *const c_char, b"RFB \0".as_ptr() as *const c_char,
b"RFB ".len() as u16, b"RFB ".len() as u16,
0, 0,
crate::core::Direction::ToClient.into(), Direction::ToClient.into(),
) < 0 ) < 0
{ {
SCLogDebug!("Failed to register protocol detection pattern for direction TOCLIENT"); SCLogDebug!("Failed to register protocol detection pattern for direction TOCLIENT");

@ -17,7 +17,7 @@
// written by Giuseppe Longo <giuseppe@glongo.it> // written by Giuseppe Longo <giuseppe@glongo.it>
use crate::core::Direction; use crate::direction::Direction;
use crate::detect::{ use crate::detect::{
DetectBufferSetActiveList, DetectHelperBufferMpmRegister, DetectHelperGetData, DetectBufferSetActiveList, DetectHelperBufferMpmRegister, DetectHelperGetData,
DetectHelperGetMultiData, DetectHelperKeywordRegister, DetectHelperMultiBufferMpmRegister, DetectHelperGetMultiData, DetectHelperKeywordRegister, DetectHelperMultiBufferMpmRegister,

@ -20,6 +20,7 @@
use crate::applayer::{self, *}; use crate::applayer::{self, *};
use crate::core; use crate::core;
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP}; use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP};
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use crate::frames::*; use crate::frames::*;
use crate::sip::parser::*; use crate::sip::parser::*;
@ -90,7 +91,7 @@ impl SIPState {
self.transactions.clear(); self.transactions.clear();
} }
fn new_tx(&mut self, direction: crate::core::Direction) -> SIPTransaction { fn new_tx(&mut self, direction: Direction) -> SIPTransaction {
self.tx_id += 1; self.tx_id += 1;
SIPTransaction::new(self.tx_id, direction) SIPTransaction::new(self.tx_id, direction)
} }
@ -128,7 +129,7 @@ impl SIPState {
match sip_parse_request(input) { match sip_parse_request(input) {
Ok((_, request)) => { Ok((_, request)) => {
let mut tx = self.new_tx(crate::core::Direction::ToServer); let mut tx = self.new_tx(Direction::ToServer);
sip_frames_ts(flow, &stream_slice, &request, tx.id); sip_frames_ts(flow, &stream_slice, &request, tx.id);
tx.request = Some(request); tx.request = Some(request);
if let Ok((_, req_line)) = sip_take_line(input) { if let Ok((_, req_line)) = sip_take_line(input) {
@ -172,7 +173,7 @@ impl SIPState {
} }
match sip_parse_request(start) { match sip_parse_request(start) {
Ok((rem, request)) => { Ok((rem, request)) => {
let mut tx = self.new_tx(crate::core::Direction::ToServer); let mut tx = self.new_tx(Direction::ToServer);
let tx_id = tx.id; let tx_id = tx.id;
sip_frames_ts(flow, &stream_slice, &request, tx_id); sip_frames_ts(flow, &stream_slice, &request, tx_id);
tx.request = Some(request); tx.request = Some(request);
@ -224,7 +225,7 @@ impl SIPState {
match sip_parse_response(input) { match sip_parse_response(input) {
Ok((_, response)) => { Ok((_, response)) => {
let mut tx = self.new_tx(crate::core::Direction::ToClient); let mut tx = self.new_tx(Direction::ToClient);
sip_frames_tc(flow, &stream_slice, &response, tx.id); sip_frames_tc(flow, &stream_slice, &response, tx.id);
tx.response = Some(response); tx.response = Some(response);
if let Ok((_, resp_line)) = sip_take_line(input) { if let Ok((_, resp_line)) = sip_take_line(input) {
@ -267,7 +268,7 @@ impl SIPState {
} }
match sip_parse_response(start) { match sip_parse_response(start) {
Ok((rem, response)) => { Ok((rem, response)) => {
let mut tx = self.new_tx(crate::core::Direction::ToClient); let mut tx = self.new_tx(Direction::ToClient);
let tx_id = tx.id; let tx_id = tx.id;
sip_frames_tc(flow, &stream_slice, &response, tx_id); sip_frames_tc(flow, &stream_slice, &response, tx_id);
tx.response = Some(response); tx.response = Some(response);
@ -307,7 +308,7 @@ impl SIPState {
} }
impl SIPTransaction { impl SIPTransaction {
pub fn new(id: u64, direction: crate::core::Direction) -> SIPTransaction { pub fn new(id: u64, direction: Direction) -> SIPTransaction {
SIPTransaction { SIPTransaction {
id, id,
request: None, request: None,
@ -515,7 +516,7 @@ fn register_pattern_probe(proto: u8) -> i8 {
method.as_ptr() as *const std::os::raw::c_char, method.as_ptr() as *const std::os::raw::c_char,
depth, depth,
0, 0,
core::Direction::ToServer as u8, Direction::ToServer as u8,
); );
} }
r |= AppLayerProtoDetectPMRegisterPatternCS( r |= AppLayerProtoDetectPMRegisterPatternCS(
@ -524,7 +525,7 @@ fn register_pattern_probe(proto: u8) -> i8 {
b"SIP/2.0\0".as_ptr() as *const std::os::raw::c_char, b"SIP/2.0\0".as_ptr() as *const std::os::raw::c_char,
8, 8,
0, 0,
core::Direction::ToClient as u8, Direction::ToClient as u8,
); );
if proto == core::IPPROTO_UDP { if proto == core::IPPROTO_UDP {
r |= AppLayerProtoDetectPMRegisterPatternCS( r |= AppLayerProtoDetectPMRegisterPatternCS(
@ -533,7 +534,7 @@ fn register_pattern_probe(proto: u8) -> i8 {
"UPDATE\0".as_ptr() as *const std::os::raw::c_char, "UPDATE\0".as_ptr() as *const std::os::raw::c_char,
"UPDATE".len() as u16, "UPDATE".len() as u16,
0, 0,
core::Direction::ToServer as u8, Direction::ToServer as u8,
); );
} }
} }

@ -15,10 +15,10 @@
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use crate::core::*;
use crate::dcerpc::dcerpc::DCERPC_TYPE_REQUEST; use crate::dcerpc::dcerpc::DCERPC_TYPE_REQUEST;
use crate::dcerpc::detect::{DCEIfaceData, DCEOpnumData, DETECT_DCE_OPNUM_RANGE_UNINITIALIZED}; use crate::dcerpc::detect::{DCEIfaceData, DCEOpnumData, DETECT_DCE_OPNUM_RANGE_UNINITIALIZED};
use crate::detect::uint::detect_match_uint; use crate::detect::uint::detect_match_uint;
use crate::direction::Direction;
use crate::smb::smb::*; use crate::smb::smb::*;
use std::ffi::CStr; use std::ffi::CStr;
use std::os::raw::{c_char, c_void}; use std::os::raw::{c_char, c_void};

@ -17,6 +17,7 @@
use std; use std;
use crate::core::*; use crate::core::*;
use crate::direction::Direction;
use crate::filetracker::*; use crate::filetracker::*;
use crate::filecontainer::*; use crate::filecontainer::*;

@ -39,6 +39,7 @@ use std::num::NonZeroUsize;
use crate::core::*; use crate::core::*;
use crate::applayer; use crate::applayer;
use crate::applayer::*; use crate::applayer::*;
use crate::direction::Direction;
use crate::flow::{Flow, FLOW_DIR_REVERSED}; use crate::flow::{Flow, FLOW_DIR_REVERSED};
use crate::frames::*; use crate::frames::*;
use crate::conf::*; use crate::conf::*;

@ -19,8 +19,7 @@
* - check all parsers for calls on non-SUCCESS status * - check all parsers for calls on non-SUCCESS status
*/ */
use crate::core::*; use crate::direction::Direction;
use crate::smb::smb::*; use crate::smb::smb::*;
use crate::smb::dcerpc::*; use crate::smb::dcerpc::*;
use crate::smb::events::*; use crate::smb::events::*;

@ -17,8 +17,7 @@
use nom7::Err; use nom7::Err;
use crate::core::*; use crate::direction::Direction;
use crate::smb::smb::*; use crate::smb::smb::*;
use crate::smb::smb2_records::*; use crate::smb::smb2_records::*;
use crate::smb::smb2_session::*; use crate::smb::smb2_session::*;

@ -17,6 +17,7 @@
// written by Pierre Chifflier <chifflier@wzdftpd.net> // written by Pierre Chifflier <chifflier@wzdftpd.net>
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use crate::snmp::snmp_parser::*; use crate::snmp::snmp_parser::*;
use crate::core::{self, *}; use crate::core::{self, *};

@ -16,7 +16,7 @@
*/ */
use super::ssh::SSHTransaction; use super::ssh::SSHTransaction;
use crate::core::Direction; use crate::direction::Direction;
use std::ptr; use std::ptr;
#[no_mangle] #[no_mangle]

@ -18,6 +18,7 @@
use super::parser; use super::parser;
use crate::applayer::*; use crate::applayer::*;
use crate::core::*; use crate::core::*;
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use nom7::Err; use nom7::Err;
use std::ffi::CString; use std::ffi::CString;

@ -18,7 +18,8 @@
use super::parser; use super::parser;
use crate::applayer::{self, *}; use crate::applayer::{self, *};
use crate::conf::conf_get; use crate::conf::conf_get;
use crate::core::{AppProto, Direction, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP}; use crate::core::{AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::direction::Direction;
use crate::flow::Flow; use crate::flow::Flow;
use crate::frames::Frame; use crate::frames::Frame;

Loading…
Cancel
Save