Skip to content

Commit a67e7f5

Browse files
committed
examples/plugins/rust: add thread init callback
1 parent b408b98 commit a67e7f5

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

examples/plugins/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ Most code copied from rust/src/applayertemplate
1818
## rust
1919

2020
A pure Rust plugin example intended to grow into an omnibus plugin example.
21-
Currently demonstrates plugin initialization and EVE callback registration.
21+
Currently demonstrates plugin initialization, EVE callback registration,
22+
and thread init callback registration.

examples/plugins/rust/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
This is a pure Rust Suricata plugin example.
44

55
It is intended to grow into an omnibus Rust plugin example over time.
6+
Currently it demonstrates plugin initialization, EVE callback registration,
7+
and thread init callback registration.

examples/plugins/rust/src/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod eve;
2+
mod thread;
23

34
use suricata_ffi::{SCLogError, SCLogNotice};
45
use suricata_sys::sys::SCPlugin;
@@ -10,6 +11,12 @@ unsafe extern "C" fn init() {
1011
if let Err(err) = eve::register() {
1112
SCLogError!("Failed to register rust example EVE callback: {}", err);
1213
}
14+
if let Err(err) = thread::register() {
15+
SCLogError!(
16+
"Failed to register rust example thread init callback: {}",
17+
err
18+
);
19+
}
1320
}
1421

1522
#[no_mangle]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use suricata_ffi::{thread, SCLogNotice};
2+
use suricata_sys::sys::ThreadVars;
3+
4+
pub(crate) fn register() -> Result<(), &'static str> {
5+
thread::register_init_callback(|tv: *mut ThreadVars| {
6+
SCLogNotice!("Thread initialization callback (tv={:p})", tv);
7+
})?;
8+
9+
Ok(())
10+
}

0 commit comments

Comments
 (0)