Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust plugins: provide bindings to register eve filetype plugins - v1 #12446

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jasonish
Copy link
Member

First, fix some breaking changes done in the visibility cleanups with respect to Rust plugins and using our log macros.

But primarily, add Rust bindings to our C EVE filetype registration. For 7.0 my Redis example plugin provided its own bindings, (see https://github.com/jasonish/suricata-redis-output/blob/main/src/ffi.rs), but ideally those should be provided by Suricata.

This patch brings enough bindings over to register EVE filetypes such as a Redis output without having to provide any custom C bindings itself.

With the recent refactor, the log level as seen by plugins was not
being updated when being set through the C interface, so just set it
directly upon plugin initialization.
This allow for an EVE file type plugin written in Rust to register
itself without needing to provide its own Rust bindings.
Comment on lines +146 to +161
// Get a child node of this node by name.
//
// Wrapper around ConfNodeLookupChild.
//
// Returns None if the child is not found.
pub fn get_child(&self, name: &str) -> Option<ConfNode> {
unsafe {
let name = CString::new(name).unwrap();
let child = ConfNodeLookupChild(self.conf, name.as_ptr());
if child.is_null() {
None
} else {
Some(ConfNode { conf: child })
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used by our Rust, but still an existing conf function that was never exposed to Rust. But useful to have.

Comment on lines +50 to +59
#[repr(C)]
pub struct EveFileType {
name: *const c_char,
open: EveFileInitFn,
thread_init: EveFileThreadInitFn,
write: EveFileWriteFn,
thread_deinit: EveFileThreadDeinitFn,
close: EveFileDeinitFn,
pad: [usize; 2],
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its kind of painful to have to duplicate this, yet I don't want to cbindgen it from Rust to C, because this is functionality owned by C. The other alternative is bindgen to generate Rust from C, but has some extra developer overhead like requiring clang.

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 0% with 40 lines in your changes missing coverage. Please review.

Project coverage is 80.62%. Comparing base (95e8427) to head (c6126b1).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12446      +/-   ##
==========================================
- Coverage   80.63%   80.62%   -0.01%     
==========================================
  Files         920      921       +1     
  Lines      258704   258740      +36     
==========================================
+ Hits       208595   208606      +11     
- Misses      50109    50134      +25     
Flag Coverage Δ
fuzzcorpus 56.80% <0.00%> (-0.02%) ⬇️
livemode 19.39% <0.00%> (-0.01%) ⬇️
pcap 44.27% <0.00%> (-0.07%) ⬇️
suricata-verify 63.25% <0.00%> (-0.02%) ⬇️
unittests 58.51% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 24312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants