diff --git a/rust/Cargo.toml.in b/rust/Cargo.toml.in index c69db937708e..d932b3f6ec81 100644 --- a/rust/Cargo.toml.in +++ b/rust/Cargo.toml.in @@ -5,6 +5,7 @@ license = "GPL-2.0-only" description = "Suricata Rust components" edition = "2021" rust-version = "1.67.1" +build = "src/build.rs" [workspace] members = [".", "./derive"] @@ -72,3 +73,11 @@ suricata-lua-sys = { version = "0.1.0-alpha.1" } [dev-dependencies] test-case = "~3.3.1" hex = "~0.4.3" + +[build-dependencies] +# Pin as bindgen 0.70.1 requires Rust 1.70.0+ +bindgen = "=0.69.4" + +# Most recent version to support Rust 1.67. 0.5.9 requires 1.70.0. +# - Not used directly but Suricata, but by bindgen. +home = "=0.5.5" diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 652775a66799..fe7b393c98b6 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -369,7 +369,7 @@ pub struct RustParser { pub tx_comp_st_ts: c_int, pub tx_comp_st_tc: c_int, /// Function returning the current transaction progress - pub tx_get_progress: StateGetProgressFn, + pub tx_get_progress: crate::sys::SCAppLayerStateGetProgressFn, /// Function to get an event id from a description pub get_eventinfo: Option, @@ -443,7 +443,6 @@ pub type StateFreeFn = unsafe extern "C" fn (*mut c_void); pub type StateTxFreeFn = unsafe extern "C" fn (*mut c_void, u64); pub type StateGetTxFn = unsafe extern "C" fn (*mut c_void, u64) -> *mut c_void; pub type StateGetTxCntFn = unsafe extern "C" fn (*mut c_void) -> u64; -pub type StateGetProgressFn = unsafe extern "C" fn (*mut c_void, u8) -> c_int; pub type GetEventInfoFn = unsafe extern "C" fn (*const c_char, *mut c_int, *mut AppLayerEventType) -> c_int; pub type GetEventInfoByIdFn = unsafe extern "C" fn (c_int, *mut *const c_char, *mut AppLayerEventType) -> c_int; pub type LocalStorageNewFn = extern "C" fn () -> *mut c_void; diff --git a/rust/src/applayertemplate/template.rs b/rust/src/applayertemplate/template.rs index 1580c4fdf3dd..4287fd4286ed 100644 --- a/rust/src/applayertemplate/template.rs +++ b/rust/src/applayertemplate/template.rs @@ -379,7 +379,7 @@ pub unsafe extern "C" fn rs_template_register_parser() { get_tx: rs_template_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_template_tx_get_alstate_progress, + tx_get_progress: Some(rs_template_tx_get_alstate_progress), get_eventinfo: Some(TemplateEvent::get_event_info), get_eventinfo_byid: Some(TemplateEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/bittorrent_dht/bittorrent_dht.rs b/rust/src/bittorrent_dht/bittorrent_dht.rs index f48cb3d2bf28..76509e631323 100644 --- a/rust/src/bittorrent_dht/bittorrent_dht.rs +++ b/rust/src/bittorrent_dht/bittorrent_dht.rs @@ -271,7 +271,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() { get_tx: rs_bittorrent_dht_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_bittorrent_dht_tx_get_alstate_progress, + tx_get_progress: Some(rs_bittorrent_dht_tx_get_alstate_progress), get_eventinfo: Some(BitTorrentDHTEvent::get_event_info), get_eventinfo_byid: Some(BitTorrentDHTEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/build.rs b/rust/src/build.rs new file mode 100644 index 000000000000..e0b4ddc81535 --- /dev/null +++ b/rust/src/build.rs @@ -0,0 +1,12 @@ +fn main() { + let bindings = bindgen::Builder::default() + .header("../src/app-layer-ext.h") + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .allowlist_item("SC.*") + .generate() + .unwrap(); + let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .unwrap(); +} diff --git a/rust/src/dcerpc/dcerpc.rs b/rust/src/dcerpc/dcerpc.rs index 32ebf6990134..babe19ca6026 100644 --- a/rust/src/dcerpc/dcerpc.rs +++ b/rust/src/dcerpc/dcerpc.rs @@ -1332,7 +1332,7 @@ pub unsafe extern "C" fn rs_dcerpc_register_parser() { get_tx: rs_dcerpc_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_dcerpc_get_alstate_progress, + tx_get_progress: Some(rs_dcerpc_get_alstate_progress), get_eventinfo: None, get_eventinfo_byid : None, localstorage_new: None, diff --git a/rust/src/dcerpc/dcerpc_udp.rs b/rust/src/dcerpc/dcerpc_udp.rs index ab7f65cafbad..9974319f4df1 100644 --- a/rust/src/dcerpc/dcerpc_udp.rs +++ b/rust/src/dcerpc/dcerpc_udp.rs @@ -363,7 +363,7 @@ pub unsafe extern "C" fn rs_dcerpc_udp_register_parser() { get_tx: rs_dcerpc_udp_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_dcerpc_get_alstate_progress, + tx_get_progress: Some(rs_dcerpc_get_alstate_progress), get_eventinfo: None, get_eventinfo_byid: None, localstorage_new: None, diff --git a/rust/src/dhcp/dhcp.rs b/rust/src/dhcp/dhcp.rs index 5b6f4b4a085a..18d3b7796da9 100644 --- a/rust/src/dhcp/dhcp.rs +++ b/rust/src/dhcp/dhcp.rs @@ -287,7 +287,7 @@ pub unsafe extern "C" fn rs_dhcp_register_parser() { get_tx : rs_dhcp_state_get_tx, tx_comp_st_ts : 1, tx_comp_st_tc : 1, - tx_get_progress : rs_dhcp_tx_get_alstate_progress, + tx_get_progress : Some(rs_dhcp_tx_get_alstate_progress), get_eventinfo : Some(DHCPEvent::get_event_info), get_eventinfo_byid : Some(DHCPEvent::get_event_info_by_id), localstorage_new : None, diff --git a/rust/src/dns/dns.rs b/rust/src/dns/dns.rs index 906f2a028859..19f8a78ab767 100644 --- a/rust/src/dns/dns.rs +++ b/rust/src/dns/dns.rs @@ -1031,7 +1031,7 @@ pub unsafe extern "C" fn SCRegisterDnsUdpParser() { get_tx: state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: tx_get_alstate_progress, + tx_get_progress: Some(tx_get_alstate_progress), get_eventinfo: Some(DNSEvent::get_event_info), get_eventinfo_byid: Some(DNSEvent::get_event_info_by_id), localstorage_new: None, @@ -1076,7 +1076,7 @@ pub unsafe extern "C" fn SCRegisterDnsTcpParser() { get_tx: state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: tx_get_alstate_progress, + tx_get_progress: Some(tx_get_alstate_progress), get_eventinfo: Some(DNSEvent::get_event_info), get_eventinfo_byid: Some(DNSEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/enip/enip.rs b/rust/src/enip/enip.rs index 31c9152e5cab..79ffdff3ad7d 100644 --- a/rust/src/enip/enip.rs +++ b/rust/src/enip/enip.rs @@ -600,7 +600,7 @@ pub unsafe extern "C" fn SCEnipRegisterParsers() { get_tx: rs_enip_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_enip_tx_get_alstate_progress, + tx_get_progress: Some(rs_enip_tx_get_alstate_progress), get_eventinfo: Some(EnipEvent::get_event_info), get_eventinfo_byid: Some(EnipEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/http2/http2.rs b/rust/src/http2/http2.rs index 9281c011ff29..2bf681f38204 100644 --- a/rust/src/http2/http2.rs +++ b/rust/src/http2/http2.rs @@ -1539,7 +1539,7 @@ pub unsafe extern "C" fn rs_http2_register_parser() { get_tx: rs_http2_state_get_tx, tx_comp_st_ts: HTTP2TransactionState::HTTP2StateClosed as i32, tx_comp_st_tc: HTTP2TransactionState::HTTP2StateClosed as i32, - tx_get_progress: rs_http2_tx_get_alstate_progress, + tx_get_progress: Some(rs_http2_tx_get_alstate_progress), get_eventinfo: Some(HTTP2Event::get_event_info), get_eventinfo_byid: Some(HTTP2Event::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/ike/ike.rs b/rust/src/ike/ike.rs index df62c19cb4ff..dca29d4dc71e 100644 --- a/rust/src/ike/ike.rs +++ b/rust/src/ike/ike.rs @@ -413,7 +413,7 @@ pub unsafe extern "C" fn rs_ike_register_parser() { get_tx: rs_ike_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_ike_tx_get_alstate_progress, + tx_get_progress: Some(rs_ike_tx_get_alstate_progress), get_eventinfo: Some(IkeEvent::get_event_info), get_eventinfo_byid: Some(IkeEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/krb/krb5.rs b/rust/src/krb/krb5.rs index 51b215ca30d1..e6d9657565c1 100644 --- a/rust/src/krb/krb5.rs +++ b/rust/src/krb/krb5.rs @@ -598,7 +598,7 @@ pub unsafe extern "C" fn rs_register_krb5_parser() { get_tx : rs_krb5_state_get_tx, tx_comp_st_ts : 1, tx_comp_st_tc : 1, - tx_get_progress : rs_krb5_tx_get_alstate_progress, + tx_get_progress : Some(rs_krb5_tx_get_alstate_progress), get_eventinfo : Some(KRB5Event::get_event_info), get_eventinfo_byid : Some(KRB5Event::get_event_info_by_id), localstorage_new : None, diff --git a/rust/src/ldap/ldap.rs b/rust/src/ldap/ldap.rs index 4c9c3947d7a8..0cf9129a81b7 100644 --- a/rust/src/ldap/ldap.rs +++ b/rust/src/ldap/ldap.rs @@ -635,7 +635,7 @@ pub unsafe extern "C" fn SCRegisterLdapTcpParser() { get_tx: SCLdapStateGetTx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: SCLdapTxGetAlstateProgress, + tx_get_progress: Some(SCLdapTxGetAlstateProgress), get_eventinfo: Some(LdapEvent::get_event_info), get_eventinfo_byid: Some(LdapEvent::get_event_info_by_id), localstorage_new: None, @@ -692,7 +692,7 @@ pub unsafe extern "C" fn SCRegisterLdapUdpParser() { get_tx: SCLdapStateGetTx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: SCLdapTxGetAlstateProgress, + tx_get_progress: Some(SCLdapTxGetAlstateProgress), get_eventinfo: Some(LdapEvent::get_event_info), get_eventinfo_byid: Some(LdapEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 7a99cd2532e5..053f157e9252 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -134,3 +134,6 @@ pub mod ldap; #[allow(unused_imports)] pub use suricata_lua_sys; + +// Generating Rust bindings from C. +pub mod sys; diff --git a/rust/src/modbus/modbus.rs b/rust/src/modbus/modbus.rs index 0d0c73371ef0..fa313cef9d38 100644 --- a/rust/src/modbus/modbus.rs +++ b/rust/src/modbus/modbus.rs @@ -396,7 +396,7 @@ pub unsafe extern "C" fn rs_modbus_register_parser() { get_tx: rs_modbus_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_modbus_tx_get_alstate_progress, + tx_get_progress: Some(rs_modbus_tx_get_alstate_progress), get_eventinfo: Some(ModbusEvent::get_event_info), get_eventinfo_byid: Some(ModbusEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/mqtt/mqtt.rs b/rust/src/mqtt/mqtt.rs index 4079daa6de05..1ad19b1d9fa3 100644 --- a/rust/src/mqtt/mqtt.rs +++ b/rust/src/mqtt/mqtt.rs @@ -778,7 +778,7 @@ pub unsafe extern "C" fn SCMqttRegisterParser() { get_tx: rs_mqtt_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_mqtt_tx_get_alstate_progress, + tx_get_progress: Some(rs_mqtt_tx_get_alstate_progress), get_eventinfo: Some(MQTTEvent::get_event_info), get_eventinfo_byid: Some(MQTTEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/nfs/nfs.rs b/rust/src/nfs/nfs.rs index d4b472e1f69c..528c63caa329 100644 --- a/rust/src/nfs/nfs.rs +++ b/rust/src/nfs/nfs.rs @@ -1978,7 +1978,7 @@ pub unsafe extern "C" fn rs_nfs_register_parser() { get_tx: rs_nfs_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_nfs_tx_get_alstate_progress, + tx_get_progress: Some(rs_nfs_tx_get_alstate_progress), get_eventinfo: Some(NFSEvent::get_event_info), get_eventinfo_byid : Some(NFSEvent::get_event_info_by_id), localstorage_new: None, @@ -2055,7 +2055,7 @@ pub unsafe extern "C" fn rs_nfs_udp_register_parser() { get_tx: rs_nfs_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_nfs_tx_get_alstate_progress, + tx_get_progress: Some(rs_nfs_tx_get_alstate_progress), get_eventinfo: Some(NFSEvent::get_event_info), get_eventinfo_byid : Some(NFSEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/ntp/ntp.rs b/rust/src/ntp/ntp.rs index ae723bbb21cd..1c7674cc19a6 100644 --- a/rust/src/ntp/ntp.rs +++ b/rust/src/ntp/ntp.rs @@ -289,7 +289,7 @@ pub unsafe extern "C" fn rs_register_ntp_parser() { get_tx : rs_ntp_state_get_tx, tx_comp_st_ts : 1, tx_comp_st_tc : 1, - tx_get_progress : rs_ntp_tx_get_alstate_progress, + tx_get_progress : Some(rs_ntp_tx_get_alstate_progress), get_eventinfo : Some(NTPEvent::get_event_info), get_eventinfo_byid : Some(NTPEvent::get_event_info_by_id), localstorage_new : None, diff --git a/rust/src/pgsql/pgsql.rs b/rust/src/pgsql/pgsql.rs index 658c2326ffd5..75fe5d305a45 100644 --- a/rust/src/pgsql/pgsql.rs +++ b/rust/src/pgsql/pgsql.rs @@ -806,7 +806,7 @@ pub unsafe extern "C" fn SCRegisterPgsqlParser() { get_tx: SCPgsqlStateGetTx, tx_comp_st_ts: PgsqlTxProgress::TxDone as i32, tx_comp_st_tc: PgsqlTxProgress::TxDone as i32, - tx_get_progress: SCPgsqlTxGetALStateProgress, + tx_get_progress: Some(SCPgsqlTxGetALStateProgress), get_eventinfo: None, get_eventinfo_byid: None, localstorage_new: None, diff --git a/rust/src/quic/quic.rs b/rust/src/quic/quic.rs index bc58afe21974..f2c3e4dccdbf 100644 --- a/rust/src/quic/quic.rs +++ b/rust/src/quic/quic.rs @@ -497,7 +497,7 @@ pub unsafe extern "C" fn rs_quic_register_parser() { get_tx: rs_quic_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_quic_tx_get_alstate_progress, + tx_get_progress: Some(rs_quic_tx_get_alstate_progress), get_eventinfo: Some(QuicEvent::get_event_info), get_eventinfo_byid: Some(QuicEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/rdp/rdp.rs b/rust/src/rdp/rdp.rs index 25b5ee381a63..e14cd0522c01 100644 --- a/rust/src/rdp/rdp.rs +++ b/rust/src/rdp/rdp.rs @@ -482,7 +482,7 @@ pub unsafe extern "C" fn rs_rdp_register_parser() { get_tx: rs_rdp_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_rdp_tx_get_progress, + tx_get_progress: Some(rs_rdp_tx_get_progress), get_eventinfo: None, get_eventinfo_byid: None, localstorage_new: None, diff --git a/rust/src/rfb/rfb.rs b/rust/src/rfb/rfb.rs index 810ed1d85d9a..b03e54f26fea 100644 --- a/rust/src/rfb/rfb.rs +++ b/rust/src/rfb/rfb.rs @@ -850,7 +850,7 @@ pub unsafe extern "C" fn SCRfbRegisterParser() { get_tx: rs_rfb_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_rfb_tx_get_alstate_progress, + tx_get_progress: Some(rs_rfb_tx_get_alstate_progress), get_eventinfo: Some(RFBEvent::get_event_info), get_eventinfo_byid: Some(RFBEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/sip/sip.rs b/rust/src/sip/sip.rs index 1a73d4e46a66..bbcd333120e1 100755 --- a/rust/src/sip/sip.rs +++ b/rust/src/sip/sip.rs @@ -559,7 +559,7 @@ pub unsafe extern "C" fn rs_sip_register_parser() { get_tx: rs_sip_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_sip_tx_get_alstate_progress, + tx_get_progress: Some(rs_sip_tx_get_alstate_progress), get_eventinfo: Some(SIPEvent::get_event_info), get_eventinfo_byid: Some(SIPEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/smb/smb.rs b/rust/src/smb/smb.rs index c5d2f6916509..37d504d97931 100644 --- a/rust/src/smb/smb.rs +++ b/rust/src/smb/smb.rs @@ -2299,7 +2299,7 @@ pub unsafe extern "C" fn rs_smb_register_parser() { get_tx: rs_smb_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_smb_tx_get_alstate_progress, + tx_get_progress: Some(rs_smb_tx_get_alstate_progress), get_eventinfo: Some(rs_smb_state_get_event_info), get_eventinfo_byid : Some(rs_smb_state_get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/snmp/snmp.rs b/rust/src/snmp/snmp.rs index 4e1afd0566e3..4b37905f5e8a 100644 --- a/rust/src/snmp/snmp.rs +++ b/rust/src/snmp/snmp.rs @@ -395,7 +395,7 @@ pub unsafe extern "C" fn rs_register_snmp_parser() { get_tx : rs_snmp_state_get_tx, tx_comp_st_ts : 1, tx_comp_st_tc : 1, - tx_get_progress : rs_snmp_tx_get_alstate_progress, + tx_get_progress : Some(rs_snmp_tx_get_alstate_progress), get_eventinfo : Some(SNMPEvent::get_event_info), get_eventinfo_byid : Some(SNMPEvent::get_event_info_by_id), localstorage_new : None, diff --git a/rust/src/ssh/ssh.rs b/rust/src/ssh/ssh.rs index a6a3871a8e60..185bec44d60c 100644 --- a/rust/src/ssh/ssh.rs +++ b/rust/src/ssh/ssh.rs @@ -509,7 +509,7 @@ pub unsafe extern "C" fn rs_ssh_register_parser() { get_tx: rs_ssh_state_get_tx, tx_comp_st_ts: SSHConnectionState::SshStateFinished as i32, tx_comp_st_tc: SSHConnectionState::SshStateFinished as i32, - tx_get_progress: rs_ssh_tx_get_alstate_progress, + tx_get_progress: Some(rs_ssh_tx_get_alstate_progress), get_eventinfo: Some(SSHEvent::get_event_info), get_eventinfo_byid: Some(SSHEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/sys.rs b/rust/src/sys.rs new file mode 100644 index 000000000000..cb933dae54fe --- /dev/null +++ b/rust/src/sys.rs @@ -0,0 +1,18 @@ +/* Copyright (C) 2024 Open Information Security Foundation + * + * You can copy, redistribute or modify this Program under the terms of + * the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/rust/src/telnet/telnet.rs b/rust/src/telnet/telnet.rs index 29b02a9b7f41..e72de000b1c0 100644 --- a/rust/src/telnet/telnet.rs +++ b/rust/src/telnet/telnet.rs @@ -526,7 +526,7 @@ pub unsafe extern "C" fn rs_telnet_register_parser() { get_tx: rs_telnet_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_telnet_tx_get_alstate_progress, + tx_get_progress: Some(rs_telnet_tx_get_alstate_progress), get_eventinfo: Some(TelnetEvent::get_event_info), get_eventinfo_byid : Some(TelnetEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/websocket/websocket.rs b/rust/src/websocket/websocket.rs index f686ad471b42..2f96df430815 100644 --- a/rust/src/websocket/websocket.rs +++ b/rust/src/websocket/websocket.rs @@ -352,7 +352,7 @@ pub unsafe extern "C" fn rs_websocket_register_parser() { get_tx: rs_websocket_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_websocket_tx_get_alstate_progress, + tx_get_progress: Some(rs_websocket_tx_get_alstate_progress), get_eventinfo: Some(WebSocketEvent::get_event_info), get_eventinfo_byid: Some(WebSocketEvent::get_event_info_by_id), localstorage_new: None,