Move the implementation of Direction to its own file, direction.rs.
//! Parser registration functions and common interface module.
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::flow::Flow;
use std::os::raw::{c_void,c_char,c_int};
/* TEMPLATE_START_REMOVE */
use crate::conf::conf_get_node;
/* TEMPLATE_END_REMOVE */
-use crate::core::Direction;
+use crate::direction::Direction;
use crate::detect::{
DetectBufferSetActiveList, DetectHelperBufferMpmRegister, DetectHelperGetData,
DetectHelperKeywordRegister, DetectSignatureSetAppProto, SCSigTableElmt,
use crate::bittorrent_dht::parser::{
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 std::ffi::CString;
use std::os::raw::c_char;
}
}
- 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) {
return true;
}
) -> AppLayerResult {
return rs_bittorrent_dht_parse(
_flow, state, _pstate, stream_slice,
- _data, crate::core::Direction::ToServer);
+ _data, Direction::ToServer);
}
#[no_mangle]
) -> AppLayerResult {
return rs_bittorrent_dht_parse(
_flow, state, _pstate, stream_slice,
- _data, crate::core::Direction::ToClient);
+ _data, Direction::ToClient);
}
#[no_mangle]
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,
stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
- direction: crate::core::Direction,
+ direction: Direction,
) -> AppLayerResult {
let state = cast_pointer!(state, BitTorrentDHTState);
let buf = stream_slice.as_slice();
BITTORRENT_DHT_PAYLOAD_PREFIX.as_ptr() as *const c_char,
BITTORRENT_DHT_PAYLOAD_PREFIX.len() as u16 - 1,
0,
- crate::core::Direction::ToServer.into(),
+ Direction::ToServer.into(),
) < 0
{
SCLogDebug!("Failed to register protocol detection pattern for direction TOSERVER");
BITTORRENT_DHT_PAYLOAD_PREFIX.as_ptr() as *const c_char,
BITTORRENT_DHT_PAYLOAD_PREFIX.len() as u16 - 1,
0,
- crate::core::Direction::ToClient.into(),
+ Direction::ToClient.into(),
) < 0
{
SCLogDebug!("Failed to register protocol detection pattern for direction TOCLIENT");
#[cfg(test)]
mod tests {
use super::*;
- use crate::core::Direction;
+ use crate::direction::Direction;
use test_case::test_case;
#[test_case(
use std;
use crate::filecontainer::*;
-use crate::debug_validate_fail;
use crate::flow::Flow;
/// Opaque C types.
pub const STREAM_GAP: u8 = 0x10;
pub const STREAM_DEPTH: u8 = 0x20;
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)
pub type AppProto = u16;
}
}
}
-
-#[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());
- }
-}
use crate::applayer::{self, *};
use crate::core::{self, *};
use crate::dcerpc::parser;
+use crate::direction::{Direction, DIR_BOTH};
use crate::flow::Flow;
use nom7::error::{Error, ErrorKind};
use nom7::number::Endianness;
use crate::applayer::AppLayerResult;
use crate::core::*;
use crate::dcerpc::dcerpc::DCERPCState;
+ use crate::direction::Direction;
use std::cmp;
#[test]
* 02110-1301, USA.
*/
+use crate::core;
use crate::applayer::{self, *};
-use crate::core::{self, Direction, DIR_BOTH};
use crate::dcerpc::dcerpc::{
DCERPCTransaction, DCERPC_MAX_TX, DCERPC_TYPE_REQUEST, DCERPC_TYPE_RESPONSE, PFCL1_FRAG, PFCL1_LASTFRAG,
rs_dcerpc_get_alstate_progress, ALPROTO_DCERPC, PARSER_NAME,
};
+use crate::direction::{Direction, DIR_BOTH};
use crate::flow::Flow;
use nom7::Err;
use std;
--- /dev/null
+/* 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());
+ }
+}
*/
use super::dns::DNSTransaction;
-use crate::core::Direction;
+use crate::direction::Direction;
use crate::detect::uint::{detect_match_uint, DetectUintData};
/// Perform the DNS opcode match.
use crate::applayer::*;
use crate::core::{self, *};
+use crate::direction::Direction;
+use crate::direction::DIR_BOTH;
use crate::dns::parser;
use crate::flow::Flow;
use crate::frames::Frame;
SigMatchAppendSMToList, SIGMATCH_INFO_STICKY_BUFFER, SIGMATCH_NOOPT,
};
-use crate::core::Direction;
+use crate::direction::Direction;
use std::ffi::CStr;
use crate::applayer::{self, *};
use crate::conf::conf_get;
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,
};
use crate::detect::EnumString;
+use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::Frame;
use nom7 as nom;
use crate::flow::Flow;
#[cfg(not(test))]
use crate::core::STREAM_TOSERVER;
-use crate::core::Direction;
+use crate::direction::Direction;
#[cfg(not(test))]
#[repr(C)]
* 02110-1301, USA.
*/
-use crate::core::Direction;
+use crate::direction::Direction;
use brotli;
use flate2::read::{DeflateDecoder, GzDecoder};
use std;
HTTP2Event, HTTP2Frame, HTTP2FrameTypeData, HTTP2State, HTTP2Transaction, HTTP2TransactionState,
};
use super::parser;
-use crate::core::Direction;
+use crate::direction::Direction;
use crate::detect::uint::{detect_match_uint, DetectUintData};
use std::ffi::CStr;
use std::str::FromStr;
use crate::applayer::{self, *};
use crate::conf::conf_get;
use crate::core::*;
+use crate::direction::Direction;
use crate::filecontainer::*;
use crate::filetracker::*;
use crate::flow::Flow;
use super::detect;
use crate::core::{
- Direction, HttpRangeContainerBlock, StreamingBufferConfig, SuricataFileContext, SC,
+ HttpRangeContainerBlock, StreamingBufferConfig, SuricataFileContext, SC,
};
+use crate::direction::Direction;
use crate::flow::Flow;
use crate::http2::http2::HTTP2Transaction;
use crate::http2::http2::SURICATA_HTTP2_FILE_CONFIG;
use crate::applayer;
use crate::applayer::*;
use crate::core::{self, *};
+use crate::direction::Direction;
use crate::flow::Flow;
use crate::ike::ikev1::{handle_ikev1, IkeV1Header, Ikev1Container};
use crate::ike::ikev2::{handle_ikev2, Ikev2Container};
use crate::applayer::*;
use crate::common::to_hex;
-use crate::core::Direction;
+use crate::direction::Direction;
use crate::ike::ike::{IKEState, IkeEvent};
use crate::ike::parser::*;
use nom7::Err;
// written by Pierre Chifflier <chifflier@wzdftpd.net>
use crate::applayer::*;
-use crate::core::Direction;
+use crate::direction::Direction;
use crate::ike::ipsec_parser::*;
use super::ipsec_parser::IkeV2Transform;
use super::ike::{IKEState, IKETransaction};
use super::ipsec_parser::IKEV2_FLAG_INITIATOR;
-use crate::core::Direction;
+use crate::direction::Direction;
use crate::ike::parser::{ExchangeType, IsakmpPayloadType, SaAttribute};
use crate::jsonbuilder::{JsonBuilder, JsonError};
use num_traits::FromPrimitive;
use asn1_rs::FromDer;
use crate::applayer::{self, *};
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;
#[derive(AppLayerEvent)]
use crate::applayer::{self, *};
use crate::conf::conf_get;
use crate::core::*;
+use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::*;
use nom7 as nom;
pub mod sdp;
pub mod ldap;
pub mod flow;
+pub mod direction;
#[allow(unused_imports)]
pub use suricata_lua_sys;
#[cfg(test)]
mod test {
use super::*;
- use crate::core::Direction;
+ use crate::direction::Direction;
use crate::detect::uint::DetectUintMode;
use crate::mqtt::mqtt::MQTTTransaction;
use crate::mqtt::mqtt_message::*;
use crate::applayer::{self, LoggerFlags};
use crate::conf::{conf_get, get_memval};
use crate::core::*;
+use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::*;
use nom7::Err;
use crate::applayer;
use crate::applayer::*;
+use crate::direction::Direction;
+use crate::direction::DIR_BOTH;
use crate::flow::Flow;
use crate::frames::*;
use crate::core::*;
// written by Victor Julien
-use crate::core::*;
-
+use crate::direction::Direction;
use crate::nfs::nfs::*;
use crate::nfs::types::*;
use crate::nfs::rpc_records::*;
use nom7::number::streaming::be_u32;
use nom7::{Err, IResult};
-use crate::core::*;
+use crate::direction::Direction;
use crate::nfs::nfs::*;
use crate::nfs::nfs4_records::*;
use crate::nfs::nfs_records::*;
extern crate ntp_parser;
use self::ntp_parser::*;
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::direction::Direction;
use crate::flow::Flow;
use std;
use std::ffi::CString;
use super::parser::{self, ConsolidatedDataRowPacket, PgsqlBEMessage, PgsqlFEMessage};
use crate::applayer::*;
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 nom7::{Err, IResult};
use std;
frames::{Frame, QuicTlsExtension, StreamTag},
parser::{quic_pkt_num, QuicData, QuicHeader, QuicType},
};
-use crate::{applayer::{self, *}, flow::Flow};
-use crate::core::{AppProto, Direction, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_UDP};
+use crate::{applayer::{self, *}, direction::Direction, flow::Flow};
+use crate::core::{AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_UDP};
use std::collections::VecDeque;
use std::ffi::CString;
use tls_parser::TlsExtensionType;
use crate::applayer;
use crate::applayer::*;
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP};
+use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::*;
use nom7::Err;
b"RFB \0".as_ptr() as *const c_char,
b"RFB ".len() as u16,
0,
- crate::core::Direction::ToServer.into(),
+ Direction::ToServer.into(),
) < 0
{
SCLogDebug!("Failed to register protocol detection pattern for direction TOSERVER");
b"RFB \0".as_ptr() as *const c_char,
b"RFB ".len() as u16,
0,
- crate::core::Direction::ToClient.into(),
+ Direction::ToClient.into(),
) < 0
{
SCLogDebug!("Failed to register protocol detection pattern for direction TOCLIENT");
// written by Giuseppe Longo <giuseppe@glongo.it>
-use crate::core::Direction;
+use crate::direction::Direction;
use crate::detect::{
DetectBufferSetActiveList, DetectHelperBufferMpmRegister, DetectHelperGetData,
DetectHelperGetMultiData, DetectHelperKeywordRegister, DetectHelperMultiBufferMpmRegister,
use crate::applayer::{self, *};
use crate::core;
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP};
+use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::*;
use crate::sip::parser::*;
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;
SIPTransaction::new(self.tx_id, direction)
}
match sip_parse_request(input) {
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);
tx.request = Some(request);
if let Ok((_, req_line)) = sip_take_line(input) {
}
match sip_parse_request(start) {
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;
sip_frames_ts(flow, &stream_slice, &request, tx_id);
tx.request = Some(request);
match sip_parse_response(input) {
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);
tx.response = Some(response);
if let Ok((_, resp_line)) = sip_take_line(input) {
}
match sip_parse_response(start) {
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;
sip_frames_tc(flow, &stream_slice, &response, tx_id);
tx.response = Some(response);
}
impl SIPTransaction {
- pub fn new(id: u64, direction: crate::core::Direction) -> SIPTransaction {
+ pub fn new(id: u64, direction: Direction) -> SIPTransaction {
SIPTransaction {
id,
request: None,
method.as_ptr() as *const std::os::raw::c_char,
depth,
0,
- core::Direction::ToServer as u8,
+ Direction::ToServer as u8,
);
}
r |= AppLayerProtoDetectPMRegisterPatternCS(
b"SIP/2.0\0".as_ptr() as *const std::os::raw::c_char,
8,
0,
- core::Direction::ToClient as u8,
+ Direction::ToClient as u8,
);
if proto == core::IPPROTO_UDP {
r |= AppLayerProtoDetectPMRegisterPatternCS(
"UPDATE\0".as_ptr() as *const std::os::raw::c_char,
"UPDATE".len() as u16,
0,
- core::Direction::ToServer as u8,
+ Direction::ToServer as u8,
);
}
}
* 02110-1301, USA.
*/
-use crate::core::*;
use crate::dcerpc::dcerpc::DCERPC_TYPE_REQUEST;
use crate::dcerpc::detect::{DCEIfaceData, DCEOpnumData, DETECT_DCE_OPNUM_RANGE_UNINITIALIZED};
use crate::detect::uint::detect_match_uint;
+use crate::direction::Direction;
use crate::smb::smb::*;
use std::ffi::CStr;
use std::os::raw::{c_char, c_void};
use std;
use crate::core::*;
+use crate::direction::Direction;
use crate::filetracker::*;
use crate::filecontainer::*;
use crate::core::*;
use crate::applayer;
use crate::applayer::*;
+use crate::direction::Direction;
use crate::flow::{Flow, FLOW_DIR_REVERSED};
use crate::frames::*;
use crate::conf::*;
* - check all parsers for calls on non-SUCCESS status
*/
-use crate::core::*;
-
+use crate::direction::Direction;
use crate::smb::smb::*;
use crate::smb::dcerpc::*;
use crate::smb::events::*;
use nom7::Err;
-use crate::core::*;
-
+use crate::direction::Direction;
use crate::smb::smb::*;
use crate::smb::smb2_records::*;
use crate::smb::smb2_session::*;
// written by Pierre Chifflier <chifflier@wzdftpd.net>
+use crate::direction::Direction;
use crate::flow::Flow;
use crate::snmp::snmp_parser::*;
use crate::core::{self, *};
*/
use super::ssh::SSHTransaction;
-use crate::core::Direction;
+use crate::direction::Direction;
use std::ptr;
#[no_mangle]
use super::parser;
use crate::applayer::*;
use crate::core::*;
+use crate::direction::Direction;
use crate::flow::Flow;
use nom7::Err;
use std::ffi::CString;
use super::parser;
use crate::applayer::{self, *};
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::frames::Frame;