rust/ffi: move STREAM_ constants to ffi crate

Ticket: 7666

reexport them in suricata crate
cbindgen them to C
pull/15112/head
Philippe Antoine 6 months ago committed by Victor Julien
parent 61c667400b
commit 267c3baff7

@ -22,10 +22,9 @@
use super::template::{TemplateTransaction, ALPROTO_TEMPLATE};
use std::os::raw::{c_int, c_void};
use suricata::core::{STREAM_TOCLIENT, STREAM_TOSERVER};
use suricata::detect::{helper_keyword_register_sticky_buffer, SigTableElmtStickyBuffer};
use suricata::direction::Direction;
use suricata_ffi::cast_pointer;
use suricata_ffi::{cast_pointer, STREAM_TOCLIENT, STREAM_TOSERVER};
use suricata_sys::sys::{
DetectEngineCtx, SCDetectBufferSetActiveList, SCDetectHelperBufferMpmRegister,
SCDetectSignatureSetAppProto, Signature,

@ -12,6 +12,7 @@ EXTRA_DIST = .cargo/config.toml.in \
derive/Cargo.toml \
dist/htp/htp_rs.h \
dist/rust-bindings.h \
dist/rust-ffi.h \
ffi \
htp \
src \
@ -84,6 +85,7 @@ all-local: Cargo.toml
$(RUST_SURICATA_LIBDIR)/${RUST_SURICATA_LIBNAME}; \
fi
$(MAKE) gen/rust-bindings.h
$(MAKE) gen/rust-ffi.h
$(MAKE) gen/htp/htp_rs.h
if test -e Cargo.lock.in; then \
cp Cargo.lock Cargo.lock.in; \
@ -186,6 +188,15 @@ else
gen/htp/htp_rs.h:
endif
if HAVE_CBINDGEN
gen/rust-ffi.h: $(RUST_SURICATA_LIB) ffi/cbindgen.toml
cd $(abs_top_srcdir)/rust/ffi && \
CARGO=$(CARGO) $(CBINDGEN) --config $(abs_top_srcdir)/rust/ffi/cbindgen.toml \
--quiet --verify --output $(abs_top_builddir)/rust/gen/rust-ffi.h || true
else
gen/rust-ffi.h:
endif
doc:
$(CARGO_ENV) $(CARGO) doc --all-features --no-deps
@ -206,6 +217,15 @@ else
dist/htp/htp_rs.h:
endif
if HAVE_CBINDGEN
dist/rust-ffi.h:
cd $(abs_top_srcdir)/rust/ffi && \
CARGO=$(CARGO) $(CBINDGEN) --config cbindgen.toml \
--quiet --output $(abs_top_builddir)/rust/dist/rust-ffi.h
else
dist/rust-ffi.h:
endif
Cargo.toml: Cargo.toml.in
update-lock: Cargo.toml

@ -0,0 +1,20 @@
language = "C"
include_guard = "__RUST_FFI_GEN_H_"
autogen_warning = "/* DO NOT EDIT This file is autogenerated by cbindgen. Don't modify this manually. */"
include_version = true
no_includes = true
includes = ["stdint.h", "stdbool.h"]
line_length = 80
tab_width = 4
documentation_style = "doxy"
[export]
exclude = [
"IPPROTO_TCP",
"IPPROTO_UDP",
]
item_types = ["constants"]

@ -23,6 +23,14 @@ pub mod plugin;
pub const IPPROTO_TCP: u8 = 6;
pub const IPPROTO_UDP: u8 = 17;
pub const STREAM_START: u8 = 0x01;
pub const STREAM_EOF: u8 = 0x02;
pub const STREAM_TOSERVER: u8 = 0x04;
pub const STREAM_TOCLIENT: u8 = 0x08;
pub const STREAM_GAP: u8 = 0x10;
pub const STREAM_DEPTH: u8 = 0x20;
pub const STREAM_MIDSTREAM: u8 = 0x40;
/// Cast pointer to a variable, as a mutable reference to an object
///
/// UNSAFE !

@ -25,13 +25,13 @@ use crate::flow::Flow;
pub use suricata_sys::sys::AppLayerEventType;
pub const STREAM_START: u8 = 0x01;
pub const STREAM_EOF: u8 = 0x02;
pub const STREAM_TOSERVER: u8 = 0x04;
pub const STREAM_TOCLIENT: u8 = 0x08;
pub const STREAM_GAP: u8 = 0x10;
pub const STREAM_DEPTH: u8 = 0x20;
pub const STREAM_MIDSTREAM:u8 = 0x40;
pub use suricata_ffi::STREAM_START;
pub use suricata_ffi::STREAM_EOF;
pub use suricata_ffi::STREAM_TOSERVER;
pub use suricata_ffi::STREAM_TOCLIENT;
pub use suricata_ffi::STREAM_GAP;
pub use suricata_ffi::STREAM_DEPTH;
pub use suricata_ffi::STREAM_MIDSTREAM;
pub const ALPROTO_UNKNOWN : AppProto = AppProtoEnum::ALPROTO_UNKNOWN as AppProto;
pub const ALPROTO_FAILED : AppProto = AppProtoEnum::ALPROTO_FAILED as AppProto;

@ -1228,6 +1228,12 @@ install-headers:
if test -e ../rust/gen/rust-bindings.h; then \
$(INSTALL_DATA) ../rust/gen/rust-bindings.h "$(DESTDIR)${includedir}/suricata"; \
fi
if test -e ../rust/dist/rust-ffi.h; then \
$(INSTALL_DATA) ../rust/dist/rust-ffi.h "$(DESTDIR)${includedir}/suricata"; \
fi
if test -e ../rust/gen/rust-ffi.h; then \
$(INSTALL_DATA) ../rust/gen/rust-ffi.h "$(DESTDIR)${includedir}/suricata"; \
fi
# Until we can remove autoconf.h from our headers, we need to to
# provide this for library/plugin users.

@ -30,6 +30,7 @@ typedef struct StreamSlice StreamSlice;
// may be improved by smaller include
#include "detect.h"
#include "rust-ffi.h"
#include "rust-bindings.h"
#define JB_SET_STRING(jb, key, val) SCJbSetFormatted((jb), "\"" key "\":\"" val "\"")

Loading…
Cancel
Save