From b5a123adb18d6fb7433c3b818dbcd4d4990c795c Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Thu, 12 Aug 2021 22:11:38 +0530 Subject: [PATCH] ssh: use Direction enum --- rust/src/ssh/detect.rs | 30 +++++++++++++----------------- rust/src/ssh/ssh.rs | 7 +++---- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/rust/src/ssh/detect.rs b/rust/src/ssh/detect.rs index c7ea3c0305..d806bb1878 100644 --- a/rust/src/ssh/detect.rs +++ b/rust/src/ssh/detect.rs @@ -16,7 +16,7 @@ */ use super::ssh::SSHTransaction; -use crate::core::{STREAM_TOCLIENT, STREAM_TOSERVER}; +use crate::core::Direction; use std::ptr; #[no_mangle] @@ -24,8 +24,8 @@ pub unsafe extern "C" fn rs_ssh_tx_get_protocol( tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8, ) -> u8 { let tx = cast_pointer!(tx, SSHTransaction); - match direction { - STREAM_TOSERVER => { + match direction.into() { + Direction::ToServer => { let m = &tx.cli_hdr.protover; if m.len() > 0 { *buffer = m.as_ptr(); @@ -33,7 +33,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_protocol( return 1; } } - STREAM_TOCLIENT => { + Direction::ToClient => { let m = &tx.srv_hdr.protover; if m.len() > 0 { *buffer = m.as_ptr(); @@ -41,7 +41,6 @@ pub unsafe extern "C" fn rs_ssh_tx_get_protocol( return 1; } } - _ => {} } *buffer = ptr::null(); *buffer_len = 0; @@ -54,8 +53,8 @@ pub unsafe extern "C" fn rs_ssh_tx_get_software( tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8, ) -> u8 { let tx = cast_pointer!(tx, SSHTransaction); - match direction { - STREAM_TOSERVER => { + match direction.into() { + Direction::ToServer => { let m = &tx.cli_hdr.swver; if m.len() > 0 { *buffer = m.as_ptr(); @@ -63,7 +62,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_software( return 1; } } - STREAM_TOCLIENT => { + Direction::ToClient => { let m = &tx.srv_hdr.swver; if m.len() > 0 { *buffer = m.as_ptr(); @@ -71,7 +70,6 @@ pub unsafe extern "C" fn rs_ssh_tx_get_software( return 1; } } - _ => {} } *buffer = ptr::null(); *buffer_len = 0; @@ -87,8 +85,8 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh( direction: u8, ) -> u8 { let tx = cast_pointer!(tx, SSHTransaction); - match direction { - STREAM_TOSERVER => { + match direction.into() { + Direction::ToServer => { let m = &tx.cli_hdr.hassh; if m.len() > 0 { *buffer = m.as_ptr(); @@ -96,7 +94,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh( return 1; } } - STREAM_TOCLIENT => { + Direction::ToClient => { let m = &tx.srv_hdr.hassh; if m.len() > 0 { *buffer = m.as_ptr(); @@ -104,7 +102,6 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh( return 1; } } - _ => {} } *buffer = ptr::null(); *buffer_len = 0; @@ -120,8 +117,8 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh_string( direction: u8, ) -> u8 { let tx = cast_pointer!(tx, SSHTransaction); - match direction { - STREAM_TOSERVER => { + match direction.into() { + Direction::ToServer => { let m = &tx.cli_hdr.hassh_string; if m.len() > 0 { *buffer = m.as_ptr(); @@ -129,7 +126,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh_string( return 1; } } - STREAM_TOCLIENT => { + Direction::ToClient => { let m = &tx.srv_hdr.hassh_string; if m.len() > 0 { *buffer = m.as_ptr(); @@ -137,7 +134,6 @@ pub unsafe extern "C" fn rs_ssh_tx_get_hassh_string( return 1; } } - _ => {} } *buffer = ptr::null(); *buffer_len = 0; diff --git a/rust/src/ssh/ssh.rs b/rust/src/ssh/ssh.rs index 85c09d9967..507795673d 100644 --- a/rust/src/ssh/ssh.rs +++ b/rust/src/ssh/ssh.rs @@ -17,8 +17,7 @@ use super::parser; use crate::applayer::*; -use crate::core::STREAM_TOSERVER; -use crate::core::{self, AppProto, Flow, ALPROTO_UNKNOWN, IPPROTO_TCP}; +use crate::core::{self, *}; use nom7::Err; use std::ffi::CString; use std::sync::atomic::{AtomicBool, Ordering}; @@ -430,7 +429,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_flags( tx: *mut std::os::raw::c_void, direction: u8, ) -> SSHConnectionState { let tx = cast_pointer!(tx, SSHTransaction); - if direction == STREAM_TOSERVER { + if direction == Direction::ToServer.into() { return tx.cli_hdr.flags; } else { return tx.srv_hdr.flags; @@ -449,7 +448,7 @@ pub unsafe extern "C" fn rs_ssh_tx_get_alstate_progress( return SSHConnectionState::SshStateFinished as i32; } - if direction == STREAM_TOSERVER { + if direction == Direction::ToServer.into() { if tx.cli_hdr.flags >= SSHConnectionState::SshStateBannerDone { return SSHConnectionState::SshStateBannerDone as i32; }