Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Parser registration functions and common interface module.

use std;
use crate::core::{self,DetectEngineState,AppLayerEventType,AppProto};
use crate::core::{self,DetectEngineState,AppLayerEventType};
use crate::direction::Direction;
use crate::filecontainer::FileContainer;
use crate::flow::Flow;
Expand All @@ -30,6 +30,7 @@ use crate::core::StreamingBufferConfig;
// Make the AppLayerEvent derive macro available to users importing
// AppLayerEvent from this module.
pub use suricata_derive::AppLayerEvent;
use suricata_sys::sys::AppProto;

#[repr(C)]
pub struct StreamSlice {
Expand Down
3 changes: 2 additions & 1 deletion rust/src/applayertemplate/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
use super::parser;
use crate::applayer::{self, *};
use crate::conf::conf_get;
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::core::{ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::flow::Flow;
use nom7 as nom;
use suricata_sys::sys::AppProto;
use std;
use std::collections::VecDeque;
use std::ffi::CString;
Expand Down
4 changes: 3 additions & 1 deletion rust/src/bittorrent_dht/bittorrent_dht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* 02110-1301, USA.
*/

use suricata_sys::sys::AppProto;

use crate::applayer::{self, *};
use crate::bittorrent_dht::parser::{
parse_bittorrent_dht_packet, BitTorrentDHTError, BitTorrentDHTRequest, BitTorrentDHTResponse,
};
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_UDP};
use crate::core::{ALPROTO_UNKNOWN, IPPROTO_UDP};
use crate::direction::Direction;
use crate::flow::Flow;
use std::ffi::CString;
Expand Down
9 changes: 4 additions & 5 deletions rust/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
//! This module exposes items from the core "C" code to Rust.

use std;
use suricata_sys::sys::{AppProto, AppProtoEnum};

use crate::filecontainer::*;
use crate::flow::Flow;

Expand All @@ -41,11 +43,8 @@ pub const STREAM_GAP: u8 = 0x10;
pub const STREAM_DEPTH: u8 = 0x20;
pub const STREAM_MIDSTREAM:u8 = 0x40;

// Application layer protocol identifiers (app-layer-protos.h)
pub type AppProto = u16;

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh AppProtoEnum. as AppProto...


pub const IPPROTO_TCP : u8 = 6;
pub const IPPROTO_UDP : u8 = 17;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/dcerpc/dcerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::flow::Flow;
use nom7::error::{Error, ErrorKind};
use nom7::number::Endianness;
use nom7::{Err, IResult, Needed};
use suricata_sys::sys::AppProto;
use std;
use std::cmp;
use std::ffi::CString;
Expand Down Expand Up @@ -1178,7 +1179,7 @@ pub unsafe extern "C" fn rs_dcerpc_parse_response(
}

#[no_mangle]
pub extern "C" fn rs_dcerpc_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: core::AppProto) -> *mut std::os::raw::c_void {
pub extern "C" fn rs_dcerpc_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
let state = DCERPCState::new();
let boxed = Box::new(state);
return Box::into_raw(boxed) as *mut _;
Expand Down
5 changes: 3 additions & 2 deletions rust/src/dcerpc/dcerpc_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::dcerpc::dcerpc::{
use crate::direction::{Direction, DIR_BOTH};
use crate::flow::Flow;
use nom7::Err;
use suricata_sys::sys::AppProto;
use std;
use std::ffi::CString;
use std::collections::VecDeque;
Expand Down Expand Up @@ -252,7 +253,7 @@ pub extern "C" fn rs_dcerpc_udp_state_free(state: *mut std::os::raw::c_void) {
}

#[no_mangle]
pub extern "C" fn rs_dcerpc_udp_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: core::AppProto) -> *mut std::os::raw::c_void {
pub extern "C" fn rs_dcerpc_udp_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
let state = DCERPCUDPState::new();
let boxed = Box::new(state);
return Box::into_raw(boxed) as *mut _;
Expand Down Expand Up @@ -313,7 +314,7 @@ fn probe(input: &[u8]) -> (bool, bool) {
}

pub unsafe extern "C" fn rs_dcerpc_probe_udp(_f: *const Flow, direction: u8, input: *const u8,
len: u32, rdir: *mut u8) -> core::AppProto
len: u32, rdir: *mut u8) -> AppProto
{
SCLogDebug!("Probing the packet for DCERPC/UDP");
if len == 0 || input.is_null() {
Expand Down
3 changes: 2 additions & 1 deletion rust/src/detect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ pub mod uri;
pub mod tojson;
pub mod vlan;

use crate::core::AppProto;
use std::os::raw::{c_int, c_void};

use suricata_sys::sys::AppProto;

/// EnumString trait that will be implemented on enums that
/// derive StringEnum.
pub trait EnumString<T> {
Expand Down
4 changes: 3 additions & 1 deletion rust/src/dhcp/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
* 02110-1301, USA.
*/

use suricata_sys::sys::AppProto;

use crate::applayer::{self, *};
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_UDP};
use crate::core::{ALPROTO_UNKNOWN, IPPROTO_UDP};
use crate::dhcp::parser::*;
use crate::flow::Flow;
use std;
Expand Down
1 change: 1 addition & 0 deletions rust/src/dns/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::frames::Frame;

use nom7::number::streaming::be_u16;
use nom7::{Err, IResult};
use suricata_sys::sys::AppProto;

/// DNS record types.
pub const DNS_RECORD_TYPE_A: u16 = 1;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/enip/enip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ use super::parser;
use crate::applayer::{self, *};
use crate::conf::conf_get;
use crate::core::{
AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP,
ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP,
STREAM_TOCLIENT, STREAM_TOSERVER,
};
use crate::detect::EnumString;
use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::Frame;
use nom7 as nom;
use suricata_sys::sys::AppProto;
use std;
use std::collections::VecDeque;
use std::ffi::CString;
Expand Down
1 change: 1 addition & 0 deletions rust/src/http2/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::frames::Frame;
use crate::dns::dns::{dns_parse_request, dns_parse_response, DNSTransaction};

use nom7::Err;
use suricata_sys::sys::AppProto;
use std;
use std::collections::VecDeque;
use std::ffi::CString;
Expand Down
1 change: 1 addition & 0 deletions rust/src/ike/ike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::ike::ikev1::{handle_ikev1, IkeV1Header, Ikev1Container};
use crate::ike::ikev2::{handle_ikev2, Ikev2Container};
use crate::ike::parser::*;
use nom7::Err;
use suricata_sys::sys::AppProto;
use std;
use std::collections::HashSet;
use std::ffi::CString;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/krb/krb5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ use der_parser::ber::Class;
use kerberos_parser::krb5_parser;
use kerberos_parser::krb5::{EncryptionType,ErrorCode,MessageType,PrincipalName,Realm,KrbError};
use asn1_rs::FromDer;
use suricata_sys::sys::AppProto;
use crate::applayer::{self, *};
use crate::core;
use crate::core::{AppProto,ALPROTO_FAILED,ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP};
use crate::core::{ALPROTO_FAILED,ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP};
use crate::direction::Direction;
use crate::flow::Flow;

Expand Down
1 change: 1 addition & 0 deletions rust/src/ldap/ldap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::*;
use nom7 as nom;
use suricata_sys::sys::AppProto;
use std;
use std::collections::VecDeque;
use std::ffi::CString;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/modbus/modbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 02110-1301, USA.
*/
use crate::applayer::{self, *};
use crate::core::{AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::core::{ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::flow::Flow;

use std::ffi::CString;
Expand All @@ -25,6 +25,7 @@ use sawp::error::ErrorKind as SawpErrorKind;
use sawp::parser::{Direction, Parse};
use sawp::probe::{Probe, Status};
use sawp_modbus::{self, AccessType, ErrorFlags, Flags, Message};
use suricata_sys::sys::AppProto;

pub const REQUEST_FLOOD: usize = 500; // Default unreplied Modbus requests are considered a flood
pub const MODBUS_PARSER: sawp_modbus::Modbus = sawp_modbus::Modbus { probe_strict: true };
Expand Down
1 change: 1 addition & 0 deletions rust/src/mqtt/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::*;
use nom7::Err;
use suricata_sys::sys::AppProto;
use std;
use std::collections::VecDeque;
use std::ffi::CString;
Expand Down
1 change: 1 addition & 0 deletions rust/src/nfs/nfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::collections::HashMap;
use std::ffi::CString;

use nom7::{Err, Needed};
use suricata_sys::sys::AppProto;

use crate::applayer;
use crate::applayer::*;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/ntp/ntp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ extern crate ntp_parser;
use self::ntp_parser::*;
use crate::applayer::{self, *};
use crate::core;
use crate::core::{AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN};
use crate::core::{ALPROTO_FAILED, ALPROTO_UNKNOWN};
use crate::direction::Direction;
use crate::flow::Flow;
use std;
use std::ffi::CString;

use nom7::Err;
use suricata_sys::sys::AppProto;

#[derive(AppLayerEvent)]
pub enum NTPEvent {
Expand Down
3 changes: 2 additions & 1 deletion rust/src/pgsql/pgsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
use super::parser::{self, ConsolidatedDataRowPacket, PgsqlBEMessage, PgsqlFEMessage};
use crate::applayer::*;
use crate::conf::*;
use crate::core::{AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, *};
use crate::core::{ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, *};
use crate::direction::Direction;
use crate::flow::Flow;
use nom7::{Err, IResult};
use suricata_sys::sys::AppProto;
use std;
use std::collections::VecDeque;
use std::ffi::CString;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/quic/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ use super::{
parser::{quic_pkt_num, QuicData, QuicHeader, QuicType},
};
use crate::{applayer::{self, *}, direction::Direction, flow::Flow};
use crate::core::{AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_UDP};
use crate::core::{ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_UDP};
use std::collections::VecDeque;
use std::ffi::CString;
use suricata_sys::sys::AppProto;
use tls_parser::TlsExtensionType;

static mut ALPROTO_QUIC: AppProto = ALPROTO_UNKNOWN;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/rdp/rdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
//! RDP application layer

use crate::applayer::{self, *};
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::core::{ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::flow::Flow;
use crate::rdp::parser::*;
use nom7::Err;
use suricata_sys::sys::AppProto;
use std;
use std::collections::VecDeque;
use tls_parser::{parse_tls_plaintext, TlsMessage, TlsMessageHandshake, TlsRecordType};
Expand Down
3 changes: 2 additions & 1 deletion rust/src/rfb/rfb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
use super::parser;
use crate::applayer;
use crate::applayer::*;
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::core::{ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::*;
use nom7::Err;
use suricata_sys::sys::AppProto;
use std;
use std::ffi::CString;
use std::os::raw::c_char;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/sip/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

use crate::applayer::{self, *};
use crate::core;
use crate::core::{AppProto, ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP};
use crate::core::{ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP};
use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::*;
use crate::sip::parser::*;
use nom7::Err;
use suricata_sys::sys::AppProto;
use std;
use std::collections::VecDeque;
use std::ffi::CString;
Expand Down
1 change: 1 addition & 0 deletions rust/src/smb/smb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use nom7::{Err, Needed};
use nom7::error::{make_error, ErrorKind};

use lru::LruCache;
use suricata_sys::sys::AppProto;
use std::num::NonZeroUsize;

use crate::core::*;
Expand Down
1 change: 1 addition & 0 deletions rust/src/snmp/snmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use der_parser::ber::BerObjectContent;
use der_parser::der::parse_der_sequence;
use nom7::{Err, IResult};
use nom7::error::{ErrorKind, make_error};
use suricata_sys::sys::AppProto;

#[derive(AppLayerEvent)]
pub enum SNMPEvent {
Expand Down
1 change: 1 addition & 0 deletions rust/src/ssh/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::Frame;
use nom7::Err;
use suricata_sys::sys::AppProto;
use std::ffi::CString;
use std::sync::atomic::{AtomicBool, Ordering};

Expand Down
3 changes: 2 additions & 1 deletion rust/src/telnet/telnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
*/

use std;
use crate::core::{ALPROTO_UNKNOWN, AppProto, IPPROTO_TCP};
use crate::core::{ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::applayer::{self, *};
use crate::flow::Flow;
use crate::frames::*;
use std::ffi::CString;
use nom7::IResult;
use suricata_sys::sys::AppProto;
use super::parser;

static mut ALPROTO_TELNET: AppProto = ALPROTO_UNKNOWN;
Expand Down
3 changes: 2 additions & 1 deletion rust/src/websocket/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use super::parser;
use crate::applayer::{self, *};
use crate::conf::conf_get;
use crate::core::{AppProto, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::core::{ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP};
use crate::direction::Direction;
use crate::flow::Flow;
use crate::frames::Frame;
Expand All @@ -27,6 +27,7 @@ use nom7 as nom;
use nom7::Needed;

use flate2::read::DeflateDecoder;
use suricata_sys::sys::AppProto;

use std;
use std::collections::VecDeque;
Expand Down
Loading