-
Notifications
You must be signed in to change notification settings - Fork 98
FW-1087: provide wirefilter.h C header file and add ffi-ctests crate #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,127 @@ | ||
#ifndef _WIREFILTER_H_ | ||
#define _WIREFILTER_H_ | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct wirefilter_scheme wirefilter_scheme_t; | ||
typedef struct wirefilter_execution_context wirefilter_execution_context_t; | ||
typedef struct wirefilter_filter_ast wirefilter_filter_ast_t; | ||
typedef struct wirefilter_filter wirefilter_filter_t; | ||
|
||
typedef struct { | ||
const char *data; | ||
size_t length; | ||
} wirefilter_rust_allocated_str_t; | ||
|
||
typedef struct { | ||
const char *data; | ||
size_t length; | ||
} wirefilter_static_rust_allocated_str_t; | ||
|
||
typedef struct { | ||
const char *data; | ||
size_t length; | ||
} wirefilter_externally_allocated_str_t; | ||
|
||
typedef struct { | ||
const unsigned char *data; | ||
size_t length; | ||
} wirefilter_externally_allocated_byte_arr_t; | ||
|
||
typedef union { | ||
uint8_t success; | ||
struct { | ||
uint8_t _res1; | ||
wirefilter_rust_allocated_str_t msg; | ||
} err; | ||
struct { | ||
uint8_t _res2; | ||
wirefilter_filter_ast_t *ast; | ||
} ok; | ||
} wirefilter_parsing_result_t; | ||
|
||
typedef enum { | ||
WIREFILTER_TYPE_IP, | ||
WIREFILTER_TYPE_BYTES, | ||
WIREFILTER_TYPE_INT, | ||
WIREFILTER_TYPE_BOOL, | ||
} wirefilter_type_t; | ||
|
||
wirefilter_scheme_t *wirefilter_create_scheme(); | ||
void wirefilter_free_scheme(wirefilter_scheme_t *scheme); | ||
|
||
void wirefilter_add_type_field_to_scheme( | ||
wirefilter_scheme_t *scheme, | ||
wirefilter_externally_allocated_str_t name, | ||
wirefilter_type_t type | ||
); | ||
|
||
wirefilter_parsing_result_t wirefilter_parse_filter( | ||
wirefilter_scheme_t *scheme, | ||
wirefilter_externally_allocated_str_t input | ||
); | ||
|
||
void wirefilter_free_parsing_result(wirefilter_parsing_result_t result); | ||
|
||
wirefilter_filter_t *wirefilter_compile_filter(wirefilter_filter_ast_t *ast); | ||
void wirefilter_free_compiled_filter(wirefilter_filter_t *filter); | ||
|
||
wirefilter_execution_context_t *wirefilter_create_execution_context( | ||
wirefilter_scheme_t *scheme | ||
); | ||
void wirefilter_free_execution_context( | ||
wirefilter_execution_context_t *exec_ctx | ||
); | ||
|
||
void wirefilter_add_int_value_to_execution_context( | ||
wirefilter_execution_context_t *exec_ctx, | ||
wirefilter_externally_allocated_str_t name, | ||
int32_t value | ||
); | ||
|
||
void wirefilter_add_bytes_value_to_execution_context( | ||
wirefilter_execution_context_t *exec_ctx, | ||
wirefilter_externally_allocated_str_t name, | ||
wirefilter_externally_allocated_byte_arr_t value | ||
); | ||
|
||
void wirefilter_add_ipv6_value_to_execution_context( | ||
wirefilter_execution_context_t *exec_ctx, | ||
wirefilter_externally_allocated_str_t name, | ||
uint8_t value[16] | ||
); | ||
|
||
void wirefilter_add_ipv4_value_to_execution_context( | ||
wirefilter_execution_context_t *exec_ctx, | ||
wirefilter_externally_allocated_str_t name, | ||
uint8_t value[4] | ||
); | ||
|
||
void wirefilter_add_bool_value_to_execution_context( | ||
wirefilter_execution_context_t *exec_ctx, | ||
wirefilter_externally_allocated_str_t name, | ||
bool value | ||
); | ||
|
||
bool wirefilter_match( | ||
wirefilter_filter_t *filter, | ||
wirefilter_execution_context_t *exec_ctx | ||
); | ||
|
||
bool wirefilter_filter_uses( | ||
wirefilter_filter_t *filter, | ||
wirefilter_externally_allocated_str_t field_name | ||
); | ||
|
||
wirefilter_static_rust_allocated_str_t wirefilter_get_version(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // _WIREFILTER_H_ |
This file contains hidden or 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 hidden or 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,12 @@ | ||
[package] | ||
authors = ["Elie ROUDNINSKI <[email protected]>"] | ||
name = "wirefilter-ffi-ctests" | ||
version = "0.1.0" | ||
description = "C based tests for FFI bindings of the Wirefilter engine" | ||
publish = false | ||
|
||
[dependencies] | ||
wirefilter-ffi = {path = "../.."} | ||
|
||
[build-dependencies] | ||
cc = "1.0" |
This file contains hidden or 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,11 @@ | ||
extern crate cc; | ||
|
||
fn main() { | ||
cc::Build::new() | ||
.include("../../include") | ||
.file("src/tests.c") | ||
.warnings(true) | ||
.extra_warnings(true) | ||
.warnings_into_errors(true) | ||
.compile("wirefilter_ffi_ctests"); | ||
} |
This file contains hidden or 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,41 @@ | ||
extern crate wirefilter_ffi as _; | ||
|
||
#[no_mangle] | ||
unsafe extern "C" fn rust_assert(check: bool, msg: *const std::os::raw::c_char) { | ||
assert!(check, "{}", std::ffi::CStr::from_ptr(msg).to_str().unwrap()); | ||
} | ||
|
||
macro_rules! ffi_ctest { | ||
(@inner $($name:ident => $link_name:expr,)*) => { | ||
$( | ||
#[test] | ||
pub fn $name() { | ||
extern "C" { | ||
#[link_name = $link_name] | ||
fn ctest(); | ||
} | ||
|
||
unsafe { ctest() } | ||
} | ||
)* | ||
}; | ||
|
||
($($name:ident,)*) => { | ||
ffi_ctest! { @inner | ||
$($name => concat!("wirefilter_ffi_ctest_", stringify!($name)),)* | ||
} | ||
}; | ||
} | ||
|
||
mod ffi_ctest { | ||
ffi_ctest!( | ||
create_scheme, | ||
add_fields_to_scheme, | ||
parse_good_filter, | ||
parse_bad_filter, | ||
compile_filter, | ||
create_execution_context, | ||
add_values_to_execution_context, | ||
match_filter, | ||
); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.