-
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
bindgen: use bindgen to provide Rust bindings to C - v8 #12466
base: master
Are you sure you want to change the base?
Conversation
Follow Rust convention of using a "sys" crate for bindings to C functions. The bindings don't exist yet, but will be generated by bindgen and put into this crate.
Bindgen works by processing a header file which includes all other header files it should generate bindings for. For this I've created bindgen.h which just includes app-layer-protos.h for now as an example. These bindings are then generated and saved in the "suricata-sys" crate and become availale as "suricata_sys::sys".
Have bindgen generate bindings for app-layer-protos.h, then use the generated definitions of AppProto/AppProtoEnum instead if defining them ourselves. This header was chosen as its used by Rust, and its a simple header with no circular dependencies.
#[repr(u32)] | ||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] | ||
pub enum AppProtoEnum { | ||
ALPROTO_UNKNOWN = 0, | ||
ALPROTO_FAILED = 1, | ||
ALPROTO_HTTP1 = 2, | ||
ALPROTO_FTP = 3, |
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.
Could also do:
pub const AppProtoEnum_ALPROTO_UNKNOWN: AppProtoEnum = 0;
pub const AppProtoEnum_ALPROTO_FAILED: AppProtoEnum = 1;
pub const AppProtoEnum_ALPROTO_HTTP1: AppProtoEnum = 2;
pub const AppProtoEnum_ALPROTO_FTP: AppProtoEnum = 3;
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.
Is it right to have a rust AppProtoEnum
? when we want dynamic AppProto cf #12420 and rejected https://redmine.openinfosecfoundation.org/issues/3524 ?
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #12466 +/- ##
=======================================
Coverage 80.63% 80.64%
=======================================
Files 920 920
Lines 258739 258739
=======================================
+ Hits 208643 208648 +5
+ Misses 50096 50091 -5
Flags with carried forward coverage won't be shown. Click here to find out more. |
Information: QA ran without warnings. Pipeline 24340 |
} | ||
pub type AppProto = u16; | ||
extern "C" { | ||
#[doc = " \\brief Maps the ALPROTO_*, to its string equivalent.\n\n \\param alproto App layer protocol id.\n\n \\retval String equivalent for the alproto."] |
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.
nit: We do not need to export the comment I guess
@@ -79,14 +79,49 @@ clean-local: | |||
distclean-local: | |||
rm -rf vendor dist | |||
|
|||
check-bindgen-bindings: |
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.
There should be a CI test with bindgen
pub const ALPROTO_UNKNOWN : AppProto = 0; | ||
pub const ALPROTO_FAILED : AppProto = 1; | ||
pub const ALPROTO_UNKNOWN : AppProto = AppProtoEnum::ALPROTO_UNKNOWN as AppProto; | ||
pub const ALPROTO_FAILED : AppProto = AppProtoEnum::ALPROTO_FAILED as AppProto; |
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.
Oh AppProtoEnum. as AppProto
...
This looks nice overall. What is the remaining work to do ?
|
A simpler, more focused version of #12461.
app-layer-protos.h
and update Rust code to use the generated bindings.AppProto
could have been more more minimal by re-exporting fromcore
, but I don't like the idea of add re-exports.