Skip to content

Commit

Permalink
rust: compatibility with cbindgen 0.27
Browse files Browse the repository at this point in the history
Ticket: 7206

Cbindgen 0.27 now handles extern blocks as extern "C" blocks.
The way to differentiate them is to use a special comment
before the block.
  • Loading branch information
catenacyber committed Aug 12, 2024
1 parent 564a6c9 commit 304271e
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ pub type GetFrameNameById = unsafe extern "C" fn(u8) -> *const c_char;


// Defined in app-layer-register.h
/// cbindgen:ignore
extern {
pub fn AppLayerRegisterProtocolDetection(parser: *const RustParser, enable_default: c_int) -> AppProto;
pub fn AppLayerRegisterParserAlias(parser_name: *const c_char, alias_name: *const c_char);
Expand All @@ -470,6 +471,7 @@ pub unsafe fn AppLayerRegisterParser(parser: *const RustParser, alproto: AppProt
}

// Defined in app-layer-detect-proto.h
/// cbindgen:ignore
extern {
pub fn AppLayerForceProtocolChange(f: *const Flow, new_proto: AppProto);
pub fn AppLayerProtoDetectPPRegister(ipproto: u8, portstr: *const c_char, alproto: AppProto,
Expand Down Expand Up @@ -506,6 +508,7 @@ pub const APP_LAYER_PARSER_OPT_ACCEPT_GAPS: u32 = BIT_U32!(0);

pub const APP_LAYER_TX_SKIP_INSPECT_FLAG: u64 = BIT_U64!(62);

/// cbindgen:ignore
extern {
pub fn AppLayerParserStateSetFlag(state: *mut c_void, flag: u16);
pub fn AppLayerParserStateIssetFlag(state: *mut c_void, flag: u16) -> u16;
Expand Down
1 change: 1 addition & 0 deletions rust/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use nom7::{
IResult,
};

/// cbindgen:ignore
extern {
fn ConfGet(key: *const c_char, res: *mut *const c_char) -> i8;
fn ConfGetChildValue(conf: *const c_void, key: *const c_char,
Expand Down
3 changes: 3 additions & 0 deletions rust/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ macro_rules!BIT_U64 {
pub const FLOW_DIR_REVERSED: u32 = BIT_U32!(26);

// Defined in app-layer-protos.h
/// cbindgen:ignore
extern {
pub fn StringToAppProto(proto_name: *const u8) -> AppProto;
}
Expand Down Expand Up @@ -239,6 +240,7 @@ pub struct SuricataFileContext {
pub files_sbcfg: &'static StreamingBufferConfig,
}

/// cbindgen:ignore
extern {
pub fn SCGetContext() -> &'static mut SuricataContext;
pub fn SCLogGetLogLevel() -> i32;
Expand Down Expand Up @@ -305,6 +307,7 @@ pub fn sc_app_layer_decoder_events_free_events(
pub enum Flow {}

// Extern functions operating on Flow.
/// cbindgen:ignore
extern {
pub fn FlowGetLastTimeAsParts(flow: &Flow, secs: *mut u64, usecs: *mut u64);
pub fn FlowGetFlags(flow: &Flow) -> u32;
Expand Down
1 change: 1 addition & 0 deletions rust/src/detect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct SCSigTableElmt {
pub(crate) const SIGMATCH_NOOPT: u16 = 1; // BIT_U16(0) in detect.h
pub(crate) const SIGMATCH_INFO_STICKY_BUFFER: u16 = 0x200; // BIT_U16(9)

/// cbindgen:ignore
extern {
pub fn DetectBufferSetActiveList(de: *mut c_void, s: *mut c_void, bufid: c_int) -> c_int;
pub fn DetectHelperGetData(
Expand Down
1 change: 1 addition & 0 deletions rust/src/filecontainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::os::raw::{c_void};
use crate::core::*;

// Defined in util-file.h
/// cbindgen:ignore
extern {
pub fn FileFlowFlagsToFlags(flow_file_flags: u16, flags: u8) -> u16;
}
Expand Down
1 change: 1 addition & 0 deletions rust/src/frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct CFrame {
}

// Defined in app-layer-register.h
/// cbindgen:ignore
extern {
#[cfg(not(test))]
fn AppLayerFrameNewByRelativeOffset(
Expand Down
4 changes: 4 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
// just due to FFI.
#![allow(clippy::missing_safety_doc)]

// Allow /// cbindgen:ignore comments on extern blocks
// cf https://github.com/mozilla/cbindgen/issues/709
#![allow(unused_doc_comments)]

#[macro_use]
extern crate bitflags;
extern crate byteorder;
Expand Down
1 change: 1 addition & 0 deletions rust/src/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::os::raw::c_long;
/// The Rust place holder for lua_State.
pub enum CLuaState {}

/// cbindgen:ignore
extern {
fn lua_createtable(lua: *mut CLuaState, narr: c_int, nrec: c_int);
fn lua_settable(lua: *mut CLuaState, idx: c_long);
Expand Down

0 comments on commit 304271e

Please sign in to comment.