-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1a5aa30
rust/conf: export ConfNodeLookupChild to rust
jasonish 8e8a1eb
rust/debug: make pub, so plugins can use logging
jasonish 8b12670
rust/plugins: fix logging initialization
jasonish c6126b1
rust/plugins: expose eve plugin registration to Rust
jasonish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* Copyright (C) 2025 Open Information Security Foundation | ||
* | ||
* You can copy, redistribute or modify this Program under the terms of | ||
* the GNU General Public License version 2 as published by the Free | ||
* Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
//! Bindings to Suricata C EVE related functions such as creating a | ||
//! filetype. | ||
|
||
use std::ffi::{c_char, c_int, c_void, CString}; | ||
|
||
/// cbindgen:ignore | ||
extern "C" { | ||
pub fn SCRegisterEveFileType(filetype: *const EveFileType) -> bool; | ||
} | ||
|
||
pub type EveFileInitFn = | ||
unsafe extern "C" fn(conf: *const c_void, threaded: bool, init_data: *mut *mut c_void) -> c_int; | ||
pub type EveFileDeinitFn = unsafe extern "C" fn(init_data: *const c_void); | ||
pub type EveFileWriteFn = unsafe extern "C" fn( | ||
buffer: *const c_char, | ||
buffer_len: c_int, | ||
init_data: *const c_void, | ||
thread_data: *const c_void, | ||
) -> c_int; | ||
pub type EveFileThreadInitFn = unsafe extern "C" fn( | ||
init_data: *const c_void, | ||
thread_id: std::os::raw::c_int, | ||
thread_data: *mut *mut c_void, | ||
) -> c_int; | ||
pub type EveFileThreadDeinitFn = | ||
unsafe extern "C" fn(init_data: *const c_void, thread_data: *mut c_void); | ||
|
||
/// Rust equivalent to C SCEveFileType. | ||
/// | ||
/// NOTE: Needs to be kept in sync with SCEveFileType. | ||
/// | ||
/// cbindgen:ignore | ||
#[repr(C)] | ||
pub struct EveFileType { | ||
name: *const c_char, | ||
open: EveFileInitFn, | ||
thread_init: EveFileThreadInitFn, | ||
write: EveFileWriteFn, | ||
thread_deinit: EveFileThreadDeinitFn, | ||
close: EveFileDeinitFn, | ||
pad: [usize; 2], | ||
} | ||
Comment on lines
+50
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
impl EveFileType { | ||
pub fn new( | ||
name: &str, open: EveFileInitFn, close: EveFileDeinitFn, write: EveFileWriteFn, | ||
thread_init: EveFileThreadInitFn, thread_deinit: EveFileThreadDeinitFn, | ||
) -> *const Self { | ||
// Convert the name to C and forget. | ||
let name = CString::new(name).unwrap().into_raw(); | ||
let file_type = Self { | ||
name, | ||
open, | ||
close, | ||
write, | ||
thread_init, | ||
thread_deinit, | ||
pad: [0, 0], | ||
}; | ||
Box::into_raw(Box::new(file_type)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ | |
pub mod hashing; | ||
pub mod base64; | ||
pub mod strings; | ||
pub mod eve; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.