]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: bindgen part of util-debug.h
authorPhilippe Antoine <pantoine@oisf.net>
Thu, 22 May 2025 08:04:20 +0000 (10:04 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 27 May 2025 19:43:50 +0000 (21:43 +0200)
Ticket: 7667

Especially SCLogLevel whose enum redef is removed in rust

rust/src/core.rs
rust/src/debug.rs
rust/src/plugin.rs
rust/sys/src/sys.rs
src/bindgen.h
src/util-debug.h

index 8c6ecc7ab0c227f72ebba986ced21822337c5f22..4f6ce602a88d88d5b44c569c1bf86513ce5a5ecc 100644 (file)
@@ -19,7 +19,7 @@
 
 use std;
 use std::os::raw::{c_int, c_void};
-use suricata_sys::sys::{AppProto, AppProtoEnum};
+use suricata_sys::sys::{AppProto, AppProtoEnum, SCLogLevel};
 
 use crate::filecontainer::*;
 use crate::flow::Flow;
@@ -89,7 +89,7 @@ extern "C" {
 
 #[allow(non_snake_case)]
 pub type SCLogMessageFunc =
-    extern "C" fn(level: std::os::raw::c_int,
+    extern "C" fn(level: SCLogLevel,
                   filename: *const std::os::raw::c_char,
                   line: std::os::raw::c_uint,
                   function: *const std::os::raw::c_char,
index 72f7b737c310159fb0a9b48e9825171ed2f108f5..d31508bde3643ef4aa68af3cfe69c67818af6411 100644 (file)
 use std::{ffi::CString, path::Path};
 
 use crate::core::SC;
-use std::os::raw::c_char;
 
-/// cbindgen:ignore
-extern "C" {
-    pub fn SCLogGetLogLevel() -> i32;
-}
-
-// Defined in util-debug.c
-/// cbindgen:ignore
-extern "C" {
-    pub fn SCFatalErrorOnInitStatic(arg: *const c_char);
-}
-
-#[derive(Debug)]
-#[repr(C)]
-pub enum Level {
-    NotSet = -1,
-    _None = 0,
-    Error,
-    Warning,
-    Notice,
-    Info,
-    _Perf,
-    Config,
-    #[cfg(feature = "debug")]
-    Debug,
-}
+use suricata_sys::sys::{SCFatalErrorOnInitStatic, SCLogLevel};
 
-pub static mut LEVEL: i32 = Level::NotSet as i32;
+pub static mut LEVEL: SCLogLevel = SCLogLevel::SC_LOG_NOTSET;
 
 /// Set the Rust context's idea of the log level.
 ///
 /// This will be called during Suricata initialization with the
 /// runtime log level.
 #[no_mangle]
-pub unsafe extern "C" fn SCSetRustLogLevel(level: i32) {
+pub unsafe extern "C" fn SCSetRustLogLevel(level: SCLogLevel) {
     LEVEL = level;
 }
 
@@ -75,7 +50,7 @@ pub fn fatalerror(message: &str) {
     }
 }
 
-pub fn sclog(level: Level, file: &str, line: u32, function: &str, message: &str) {
+pub fn sclog(level: SCLogLevel, file: &str, line: u32, function: &str, message: &str) {
     let filename = basename(file);
     let noext = &filename[0..filename.len() - 3];
     sc_log_message(level, filename, line, function, noext, message);
@@ -85,13 +60,13 @@ pub fn sclog(level: Level, file: &str, line: u32, function: &str, message: &str)
 /// a more basic log format will be used (for example, when running
 /// Rust unit tests).
 pub fn sc_log_message(
-    level: Level, filename: &str, line: std::os::raw::c_uint, function: &str, module: &str,
+    level: SCLogLevel, filename: &str, line: std::os::raw::c_uint, function: &str, module: &str,
     message: &str,
 ) -> std::os::raw::c_int {
     unsafe {
         if let Some(c) = SC {
             return (c.SCLogMessage)(
-                level as i32,
+                level,
                 to_safe_cstring(filename).as_ptr(),
                 line,
                 to_safe_cstring(function).as_ptr(),
@@ -148,7 +123,7 @@ macro_rules! function {
 macro_rules!do_log {
     ($level:expr, $($arg:tt)*) => {
         #[allow(unused_unsafe)]
-        if unsafe { $crate::debug::LEVEL } >= $level as i32 {
+        if unsafe { $crate::debug::LEVEL as i32 } >= $level as i32 {
             $crate::debug::sclog($level, file!(), line!(), $crate::function!(),
                   &(format!($($arg)*)));
         }
@@ -158,42 +133,42 @@ macro_rules!do_log {
 #[macro_export]
 macro_rules!SCLogError {
     ($($arg:tt)*) => {
-        $crate::do_log!($crate::debug::Level::Error, $($arg)*);
+        $crate::do_log!(suricata_sys::sys::SCLogLevel::SC_LOG_ERROR, $($arg)*);
     };
 }
 
 #[macro_export]
 macro_rules!SCLogWarning {
     ($($arg:tt)*) => {
-        $crate::do_log!($crate::debug::Level::Warning, $($arg)*);
+        $crate::do_log!(suricata_sys::sys::SCLogLevel::SC_LOG_WARNING, $($arg)*);
     };
 }
 
 #[macro_export]
 macro_rules!SCLogNotice {
     ($($arg:tt)*) => {
-        $crate::do_log!($crate::debug::Level::Notice, $($arg)*);
+        $crate::do_log!(suricata_sys::sys::SCLogLevel::SC_LOG_NOTICE, $($arg)*);
     }
 }
 
 #[macro_export]
 macro_rules!SCLogInfo {
     ($($arg:tt)*) => {
-        $crate::do_log!($crate::debug::Level::Info, $($arg)*);
+        $crate::do_log!(suricata_sys::sys::SCLogLevel::SC_LOG_INFO, $($arg)*);
     }
 }
 
 #[macro_export]
 macro_rules!SCLogPerf {
     ($($arg:tt)*) => {
-        $crate::do_log!($crate::debug::Level::Perf, $($arg)*);
+        $crate::do_log!(suricata_sys::sys::SCLogLevel::SC_LOG_PERF, $($arg)*);
     }
 }
 
 #[macro_export]
 macro_rules!SCLogConfig {
     ($($arg:tt)*) => {
-        $crate::do_log!($crate::debug::Level::Config, $($arg)*);
+        $crate::do_log!(suricata_sys::sys::SCLogLevel::SC_LOG_CONFIG, $($arg)*);
     }
 }
 
@@ -202,7 +177,7 @@ macro_rules!SCLogConfig {
 #[macro_export]
 macro_rules!SCLogDebug {
     ($($arg:tt)*) => {
-        do_log!($crate::debug::Level::Debug, $($arg)*);
+        do_log!(suricata_sys::sys::SCLogLevel::SC_LOG_DEBUG, $($arg)*);
     }
 }
 
index db47131848e58534ebaf211b1df61c58624e0d3e..925f30c95dee63db06dc811b94ac0002440afb66 100644 (file)
 
 //! Plugin utility module.
 
+use suricata_sys::sys::SCLogGetLogLevel;
+
 pub fn init() {
     unsafe {
         let context = crate::core::SCGetContext();
         crate::core::init_ffi(context);
 
-        crate::debug::LEVEL = crate::debug::SCLogGetLogLevel();
+        crate::debug::LEVEL = SCLogGetLogLevel();
     }
 }
index 74a29339e86fd291656c24ea7029c09e9ba992ac..75e75f80811a9ce30d9fd2a928fac776d4ba89fa 100644 (file)
@@ -396,6 +396,27 @@ extern "C" {
         s: *mut Signature, alproto: AppProto,
     ) -> ::std::os::raw::c_int;
 }
+#[repr(i32)]
+#[doc = " \\brief The various log levels\n NOTE: when adding new level, don't forget to update SCLogMapLogLevelToSyslogLevel()\n      or it may result in logging to syslog with LOG_EMERG priority."]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub enum SCLogLevel {
+    SC_LOG_NOTSET = -1,
+    SC_LOG_NONE = 0,
+    SC_LOG_ERROR = 1,
+    SC_LOG_WARNING = 2,
+    SC_LOG_NOTICE = 3,
+    SC_LOG_INFO = 4,
+    SC_LOG_PERF = 5,
+    SC_LOG_CONFIG = 6,
+    SC_LOG_DEBUG = 7,
+    SC_LOG_LEVEL_MAX = 8,
+}
+extern "C" {
+    pub fn SCFatalErrorOnInitStatic(arg1: *const ::std::os::raw::c_char);
+}
+extern "C" {
+    pub fn SCLogGetLogLevel() -> SCLogLevel;
+}
 #[doc = " Structure of a configuration parameter."]
 #[repr(C)]
 #[derive(Debug, Copy, Clone)]
index e2016639edcea43949a3b7fe72d1960c97196083..9ba5501b2de5002fa726e4c2821fb3aef36bd8dd 100644 (file)
@@ -42,6 +42,8 @@
 #include "detect-engine-helper.h"
 #include "detect-parse.h"
 
+#include "util-debug.h"
+
 #include "conf.h"
 
 #endif
index 78586de6cda273c49dc3bd0e2f0d812cfca14298..9a5f077954fde566eeddb4a4c7b4d9df01dd7d2e 100644 (file)
 #ifndef SURICATA_UTIL_DEBUG_H
 #define SURICATA_UTIL_DEBUG_H
 
-#include "suricata-common.h"
-
-#include "threads.h"
-#include "util-error.h"
-#include "util-debug-filters.h"
-
-/**
- * \brief ENV vars that can be used to set the properties for the logging module
- */
-#define SC_LOG_ENV_LOG_LEVEL        "SC_LOG_LEVEL"
-#define SC_LOG_ENV_LOG_OP_IFACE     "SC_LOG_OP_IFACE"
-#define SC_LOG_ENV_LOG_FILE         "SC_LOG_FILE"
-#define SC_LOG_ENV_LOG_FACILITY     "SC_LOG_FACILITY"
-#define SC_LOG_ENV_LOG_FORMAT       "SC_LOG_FORMAT"
-#define SC_LOG_ENV_LOG_OP_FILTER    "SC_LOG_OP_FILTER"
-
 /**
  * \brief The various log levels
  * NOTE: when adding new level, don't forget to update SCLogMapLogLevelToSyslogLevel()
@@ -58,6 +42,23 @@ typedef enum {
     SC_LOG_LEVEL_MAX,
 } SCLogLevel;
 
+#ifndef SURICATA_BINDGEN_H
+#include "suricata-common.h"
+
+#include "threads.h"
+#include "util-error.h"
+#include "util-debug-filters.h"
+
+/**
+ * \brief ENV vars that can be used to set the properties for the logging module
+ */
+#define SC_LOG_ENV_LOG_LEVEL     "SC_LOG_LEVEL"
+#define SC_LOG_ENV_LOG_OP_IFACE  "SC_LOG_OP_IFACE"
+#define SC_LOG_ENV_LOG_FILE      "SC_LOG_FILE"
+#define SC_LOG_ENV_LOG_FACILITY  "SC_LOG_FACILITY"
+#define SC_LOG_ENV_LOG_FORMAT    "SC_LOG_FORMAT"
+#define SC_LOG_ENV_LOG_OP_FILTER "SC_LOG_OP_FILTER"
+
 /**
  * \brief The various output interfaces supported
  */
@@ -530,8 +531,6 @@ SCLogInitData *SCLogAllocLogInitData(void);
 
 void SCLogAppendOPIfaceCtx(SCLogOPIfaceCtx *, SCLogInitData *);
 
-void SCFatalErrorOnInitStatic(const char *);
-
 void SCLogInitLogModule(SCLogInitData *);
 
 void SCLogDeInitLogModule(void);
@@ -546,6 +545,9 @@ int SCLogDebugEnabled(void);
 void SCLogRegisterTests(void);
 
 void SCLogLoadConfig(int daemon, int verbose, uint32_t userid, uint32_t groupid);
+#endif // #ifndef SURICATA_BINDGEN_H
+
+void SCFatalErrorOnInitStatic(const char *);
 
 SCLogLevel SCLogGetLogLevel(void);