]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/conf: use generated bindings to SCConf API
authorJason Ish <jason.ish@oisf.net>
Tue, 1 Apr 2025 16:42:52 +0000 (10:42 -0600)
committerVictor Julien <victor@inliniac.net>
Tue, 1 Apr 2025 19:11:14 +0000 (21:11 +0200)
plugins/pfring/runmode-pfring.c
rust/Makefile.am
rust/src/conf.rs
rust/src/dhcp/logger.rs
rust/sys/src/sys.rs
src/bindgen.h
src/runmode-dpdk.c
src/runmode-netmap.c

index 40a546e4d48512b0659cdabaa1bfb009f0e07d0d..6a37ca2ea2145d36f408102695c7c1731433207f 100644 (file)
@@ -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) {
index cb9158fc63c421293c0ab08895a43a3263e60955..dce105165d85f7fc359530784647c379758519e7 100644 (file)
@@ -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)
index 9355f5ee986d5484f0696107ea15097b39563b42..912252ecb6d604458ee0cf775b8941f3b5e989be 100644 (file)
@@ -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<ConfNode> {
     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 }
     }
 
index 37b66d0b1d133e8b2397fb7ca01191976b0cdc76..d2751bf427db1f0bd9dcb3f8c3d88fffb0faaa76 100644 (file)
@@ -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 _;
index cadf3de72591e6633440988fb7443e4463adadc4..87ea366bba421036ba6116136f12cf07cf5b11a3 100644 (file)
@@ -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;
+}
index 6f491b2a2a96f9ae98fc8c54081fa1de68eb5cb9..9dccc75d96e2a8bb0e6487f89db8ec7fe35a7899 100644 (file)
@@ -32,4 +32,6 @@
 #include "app-layer-protos.h"
 #include "suricata-plugin.h"
 
+#include "conf.h"
+
 #endif
index 37b333937a293cd130fc9bd111f6412d465e4e0d..9175bf9b2c05eb1d987b14339f921cee21da8b77 100644 (file)
@@ -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, &copy_mode_str);
+    retval = SCConfGetChildValueWithDefault(
+            if_root, if_default, dpdk_yaml.copy_mode, &copy_mode_str);
     if (retval != 1) {
         copy_mode_str = DPDK_CONFIG_DEFAULT_COPY_MODE;
     }
index 4c1e913e8173e49579f46b5c3fd4943227bd5e5c..6b9d503b70338e183d423ee9028be55afbcb6e77 100644 (file)
@@ -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", &copymodestr) == 1)
-    {
+    if (SCConfGetChildValueWithDefault(if_root, if_default, "copy-mode", &copymodestr) == 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);