]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
ssh: use Direction enum
authorShivani Bhardwaj <shivanib134@gmail.com>
Thu, 12 Aug 2021 16:41:38 +0000 (22:11 +0530)
committerVictor Julien <vjulien@oisf.net>
Fri, 19 Nov 2021 16:20:01 +0000 (17:20 +0100)
rust/src/ssh/detect.rs
rust/src/ssh/ssh.rs

index c7ea3c03054c34243009582577aa35c6aea17bf0..d806bb1878a3fc7188c777ce3aa412d8b840294f 100644 (file)
@@ -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;
index 85c09d996749ba0745ff752721e71191e04ef5f1..507795673dc5e080cd8c217bb16fca2cd1fb7f7e 100644 (file)
@@ -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;
         }