From: Jason Ish Date: Tue, 1 Apr 2025 16:42:52 +0000 (-0600) Subject: rust/conf: use generated bindings to SCConf API X-Git-Tag: suricata-8.0.0-beta1~117 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=813eb27b952f817b9e856540470d6a8742797da9;p=thirdparty%2Fsuricata.git rust/conf: use generated bindings to SCConf API --- diff --git a/plugins/pfring/runmode-pfring.c b/plugins/pfring/runmode-pfring.c index 40a546e4d4..6a37ca2ea2 100644 --- a/plugins/pfring/runmode-pfring.c +++ b/plugins/pfring/runmode-pfring.c @@ -292,8 +292,8 @@ static void *ParsePfringConfig(const char *iface) } else if ((pfconf->threads == 1) && (strncmp(pfconf->iface, "dna", 3) == 0)) { SCLogInfo("%s: DNA interface detected, not setting cluster-id for PF_RING", pfconf->iface); - } else if (SCConfGetChildValueWithDefault(if_root, if_default, "cluster-id", &tmpclusterid) != - 1) { + } else if (SCConfGetChildValueWithDefault( + if_root, if_default, "cluster-id", &tmpclusterid) != 1) { SCLogError("Could not get cluster-id from config"); } else { if (StringParseInt32(&pfconf->cluster_id, 10, 0, (const char *)tmpclusterid) < 0) { diff --git a/rust/Makefile.am b/rust/Makefile.am index cb9158fc63..dce105165d 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -131,6 +131,7 @@ if HAVE_BINDGEN --allowlist-type 'SC.*' \ --allowlist-function 'SC.*' \ --allowlist-var 'SC.*' \ + --opaque-type 'SCConfNode' \ $(abs_top_srcdir)/src/bindgen.h \ -- \ -DHAVE_CONFIG_H -I../src -I../rust/gen $(CPPFLAGS) diff --git a/rust/src/conf.rs b/rust/src/conf.rs index 9355f5ee98..912252ecb6 100644 --- a/rust/src/conf.rs +++ b/rust/src/conf.rs @@ -18,7 +18,6 @@ //! Module for retrieving configuration details. use std::os::raw::c_char; -use std::os::raw::c_void; use std::os::raw::c_int; use std::ffi::{CString, CStr}; use std::ptr; @@ -30,16 +29,11 @@ use nom7::{ combinator::verify, IResult, }; - -/// cbindgen:ignore -extern { - fn SCConfGet(key: *const c_char, res: *mut *const c_char) -> i8; - fn SCConfGetChildValue(conf: *const c_void, key: *const c_char, - vptr: *mut *const c_char) -> i8; - fn SCConfGetChildValueBool(conf: *const c_void, key: *const c_char, - vptr: *mut c_int) -> i8; - fn SCConfGetNode(key: *const c_char) -> *const c_void; -} +use suricata_sys::sys::SCConfGet; +use suricata_sys::sys::SCConfGetChildValue; +use suricata_sys::sys::SCConfGetChildValueBool; +use suricata_sys::sys::SCConfGetNode; +use suricata_sys::sys::SCConfNode; pub fn conf_get_node(key: &str) -> Option { let key = if let Ok(key) = CString::new(key) { @@ -92,12 +86,12 @@ pub fn conf_get_bool(key: &str) -> bool { /// Wrap a Suricata ConfNode and expose some of its methods with a /// Rust friendly interface. pub struct ConfNode { - pub conf: *const c_void, + pub conf: *const SCConfNode, } impl ConfNode { - pub fn wrap(conf: *const c_void) -> Self { + pub fn wrap(conf: *const SCConfNode) -> Self { return Self { conf } } diff --git a/rust/src/dhcp/logger.rs b/rust/src/dhcp/logger.rs index 37b66d0b1d..d2751bf427 100644 --- a/rust/src/dhcp/logger.rs +++ b/rust/src/dhcp/logger.rs @@ -16,7 +16,8 @@ */ use std; -use std::os::raw::c_void; + +use suricata_sys::sys::SCConfNode; use crate::conf::ConfNode; use crate::dhcp::dhcp::*; @@ -244,7 +245,7 @@ fn format_addr_hex(input: &[u8]) -> String { } #[no_mangle] -pub extern "C" fn SCDhcpLoggerNew(conf: *const c_void) -> *mut std::os::raw::c_void { +pub extern "C" fn SCDhcpLoggerNew(conf: *const SCConfNode) -> *mut std::os::raw::c_void { let conf = ConfNode::wrap(conf); let boxed = Box::new(DHCPLogger::new(conf)); return Box::into_raw(boxed) as *mut _; diff --git a/rust/sys/src/sys.rs b/rust/sys/src/sys.rs index cadf3de725..87ea366bba 100644 --- a/rust/sys/src/sys.rs +++ b/rust/sys/src/sys.rs @@ -1,6 +1,8 @@ // This file is automatically generated. Do not edit. pub const SC_PACKAGE_VERSION: &[u8; 10] = b"8.0.0-dev\0"; +pub type __intmax_t = ::std::os::raw::c_long; +pub type intmax_t = __intmax_t; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum AppProtoEnum { @@ -129,3 +131,200 @@ pub type SCAppLayerPlugin = SCAppLayerPlugin_; extern "C" { pub fn SCPluginRegisterAppLayer(arg1: *mut SCAppLayerPlugin) -> ::std::os::raw::c_int; } +#[doc = " Structure of a configuration parameter."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct SCConfNode_ { + pub name: *mut ::std::os::raw::c_char, + pub val: *mut ::std::os::raw::c_char, + pub is_seq: ::std::os::raw::c_int, + pub final_: ::std::os::raw::c_int, + pub parent: *mut SCConfNode_, + pub head: SCConfNode___bindgen_ty_1, + pub next: SCConfNode___bindgen_ty_2, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct SCConfNode___bindgen_ty_1 { + pub tqh_first: *mut SCConfNode_, + pub tqh_last: *mut *mut SCConfNode_, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct SCConfNode___bindgen_ty_2 { + pub tqe_next: *mut SCConfNode_, + pub tqe_prev: *mut *mut SCConfNode_, +} +#[doc = " Structure of a configuration parameter."] +pub type SCConfNode = [u64; 8usize]; +extern "C" { + pub fn SCConfInit(); +} +extern "C" { + pub fn SCConfDeInit(); +} +extern "C" { + pub fn SCConfGetRootNode() -> *mut SCConfNode; +} +extern "C" { + pub fn SCConfGet( + name: *const ::std::os::raw::c_char, vptr: *mut *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfGetInt( + name: *const ::std::os::raw::c_char, val: *mut intmax_t, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfGetBool( + name: *const ::std::os::raw::c_char, val: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfGetDouble( + name: *const ::std::os::raw::c_char, val: *mut f64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfGetFloat( + name: *const ::std::os::raw::c_char, val: *mut f32, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfSet( + name: *const ::std::os::raw::c_char, val: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfSetFromString( + input: *const ::std::os::raw::c_char, final_: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfSetFinal( + name: *const ::std::os::raw::c_char, val: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfDump(); +} +extern "C" { + pub fn SCConfNodeDump(node: *const SCConfNode, prefix: *const ::std::os::raw::c_char); +} +extern "C" { + pub fn SCConfNodeNew() -> *mut SCConfNode; +} +extern "C" { + pub fn SCConfNodeFree(arg1: *mut SCConfNode); +} +extern "C" { + pub fn SCConfGetNode(key: *const ::std::os::raw::c_char) -> *mut SCConfNode; +} +extern "C" { + pub fn SCConfCreateContextBackup(); +} +extern "C" { + pub fn SCConfRestoreContextBackup(); +} +extern "C" { + pub fn SCConfNodeLookupChild( + node: *const SCConfNode, key: *const ::std::os::raw::c_char, + ) -> *mut SCConfNode; +} +extern "C" { + pub fn SCConfNodeLookupChildValue( + node: *const SCConfNode, key: *const ::std::os::raw::c_char, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn SCConfNodeRemove(arg1: *mut SCConfNode); +} +extern "C" { + pub fn SCConfRegisterTests(); +} +extern "C" { + pub fn SCConfNodeChildValueIsTrue( + node: *const SCConfNode, key: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfValIsTrue(val: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfValIsFalse(val: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfNodePrune(node: *mut SCConfNode); +} +extern "C" { + pub fn SCConfRemove(name: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfNodeHasChildren(node: *const SCConfNode) -> bool; +} +extern "C" { + pub fn SCConfGetChildWithDefault( + base: *const SCConfNode, dflt: *const SCConfNode, name: *const ::std::os::raw::c_char, + ) -> *mut SCConfNode; +} +extern "C" { + pub fn SCConfNodeLookupKeyValue( + base: *const SCConfNode, key: *const ::std::os::raw::c_char, + value: *const ::std::os::raw::c_char, + ) -> *mut SCConfNode; +} +extern "C" { + pub fn SCConfGetChildValue( + base: *const SCConfNode, name: *const ::std::os::raw::c_char, + vptr: *mut *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfGetChildValueInt( + base: *const SCConfNode, name: *const ::std::os::raw::c_char, val: *mut intmax_t, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfGetChildValueBool( + base: *const SCConfNode, name: *const ::std::os::raw::c_char, + val: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfGetChildValueWithDefault( + base: *const SCConfNode, dflt: *const SCConfNode, name: *const ::std::os::raw::c_char, + vptr: *mut *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfGetChildValueIntWithDefault( + base: *const SCConfNode, dflt: *const SCConfNode, name: *const ::std::os::raw::c_char, + val: *mut intmax_t, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfGetChildValueBoolWithDefault( + base: *const SCConfNode, dflt: *const SCConfNode, name: *const ::std::os::raw::c_char, + val: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfNodeIsSequence(node: *const SCConfNode) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfSetIfaceNode( + ifaces_node_name: *const ::std::os::raw::c_char, iface: *const ::std::os::raw::c_char, + ) -> *mut SCConfNode; +} +extern "C" { + pub fn SCConfSetRootAndDefaultNodes( + ifaces_node_name: *const ::std::os::raw::c_char, iface: *const ::std::os::raw::c_char, + if_root: *mut *mut SCConfNode, if_default: *mut *mut SCConfNode, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn SCConfNodeGetNodeOrCreate( + parent: *mut SCConfNode, name: *const ::std::os::raw::c_char, final_: ::std::os::raw::c_int, + ) -> *mut SCConfNode; +} diff --git a/src/bindgen.h b/src/bindgen.h index 6f491b2a2a..9dccc75d96 100644 --- a/src/bindgen.h +++ b/src/bindgen.h @@ -32,4 +32,6 @@ #include "app-layer-protos.h" #include "suricata-plugin.h" +#include "conf.h" + #endif diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index 37b333937a..9175bf9b2c 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -877,7 +877,8 @@ static int ConfigLoad(DPDKIfaceConfig *iconf, const char *iface) SCReturnInt(retval); bool irq_enable; - retval = SCConfGetChildValueBoolWithDefault(if_root, if_default, dpdk_yaml.irq_mode, &entry_bool); + retval = SCConfGetChildValueBoolWithDefault( + if_root, if_default, dpdk_yaml.irq_mode, &entry_bool); if (retval != 1) { irq_enable = DPDK_CONFIG_DEFAULT_INTERRUPT_MODE; } else { @@ -887,7 +888,8 @@ static int ConfigLoad(DPDKIfaceConfig *iconf, const char *iface) if (retval != true) SCReturnInt(-EINVAL); - retval = SCConfGetChildValueWithDefault(if_root, if_default, dpdk_yaml.copy_mode, ©_mode_str); + retval = SCConfGetChildValueWithDefault( + if_root, if_default, dpdk_yaml.copy_mode, ©_mode_str); if (retval != 1) { copy_mode_str = DPDK_CONFIG_DEFAULT_COPY_MODE; } diff --git a/src/runmode-netmap.c b/src/runmode-netmap.c index 4c1e913e81..6b9d503b70 100644 --- a/src/runmode-netmap.c +++ b/src/runmode-netmap.c @@ -224,9 +224,7 @@ static int ParseNetmapSettings( } const char *tmpctype; - if (SCConfGetChildValueWithDefault(if_root, if_default, - "checksum-checks", &tmpctype) == 1) - { + if (SCConfGetChildValueWithDefault(if_root, if_default, "checksum-checks", &tmpctype) == 1) { if (strcmp(tmpctype, "auto") == 0) { ns->checksum_mode = CHECKSUM_VALIDATION_AUTO; } else if (SCConfValIsTrue(tmpctype)) { @@ -239,9 +237,7 @@ static int ParseNetmapSettings( } const char *copymodestr; - if (SCConfGetChildValueWithDefault(if_root, if_default, - "copy-mode", ©modestr) == 1) - { + if (SCConfGetChildValueWithDefault(if_root, if_default, "copy-mode", ©modestr) == 1) { if (strcmp(copymodestr, "ips") == 0) { ns->copy_mode = NETMAP_COPY_MODE_IPS; } else if (strcmp(copymodestr, "tap") == 0) { @@ -315,8 +311,7 @@ static void *ParseNetmapConfig(const char *iface_name) /* if we have a copy iface, parse that as well */ if (netmap_node != NULL && - SCConfGetChildValueWithDefault(if_root, if_default, "copy-iface", &out_iface) == 1) - { + SCConfGetChildValueWithDefault(if_root, if_default, "copy-iface", &out_iface) == 1) { if (strlen(out_iface) > 0) { if_root = ConfFindDeviceConfig(netmap_node, out_iface); ParseNetmapSettings(&aconf->out, out_iface, if_root, if_default);