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 - v7 #12461

Closed
wants to merge 12 commits into from
Closed
3 changes: 3 additions & 0 deletions rust/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ if HAVE_BINDGEN
--allowlist-type 'SCAppLayerEventType' \
--rustified-enum 'SCAppLayerEventType' \
--allowlist-type 'SCAppLayerStateGetEventInfoByIdFn' \
--allowlist-type 'AppProto' \
--allowlist-type 'AppProtoEnum' \
--rustified-enum 'AppProtoEnum' \
$(abs_top_srcdir)/src/bindgen.h \
-- \
-DHAVE_CONFIG_H -I../src $(CPPFLAGS)
Expand Down
45 changes: 45 additions & 0 deletions rust/src/_sys.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
#[repr(u32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum AppProtoEnum {
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember doing such a PR once, and then rejected the ticket as we want dynamic app-layer protocols, and this is not what is done in a rust enum...

ALPROTO_UNKNOWN = 0,
ALPROTO_FAILED = 1,
ALPROTO_HTTP1 = 2,
ALPROTO_FTP = 3,
ALPROTO_SMTP = 4,
ALPROTO_TLS = 5,
ALPROTO_SSH = 6,
ALPROTO_IMAP = 7,
ALPROTO_JABBER = 8,
ALPROTO_SMB = 9,
ALPROTO_DCERPC = 10,
ALPROTO_IRC = 11,
ALPROTO_DNS = 12,
ALPROTO_MODBUS = 13,
ALPROTO_ENIP = 14,
ALPROTO_DNP3 = 15,
ALPROTO_NFS = 16,
ALPROTO_NTP = 17,
ALPROTO_FTPDATA = 18,
ALPROTO_TFTP = 19,
ALPROTO_IKE = 20,
ALPROTO_KRB5 = 21,
ALPROTO_QUIC = 22,
ALPROTO_DHCP = 23,
ALPROTO_SNMP = 24,
ALPROTO_SIP = 25,
ALPROTO_RFB = 26,
ALPROTO_MQTT = 27,
ALPROTO_PGSQL = 28,
ALPROTO_TELNET = 29,
ALPROTO_WEBSOCKET = 30,
ALPROTO_LDAP = 31,
ALPROTO_DOH2 = 32,
ALPROTO_TEMPLATE = 33,
ALPROTO_RDP = 34,
ALPROTO_HTTP2 = 35,
ALPROTO_BITTORRENT_DHT = 36,
ALPROTO_POP3 = 37,
ALPROTO_HTTP = 38,
ALPROTO_MAX_STATIC = 39,
}
pub type AppProto = u16;
#[repr(u32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum SCAppLayerEventType {
APP_LAYER_EVENT_TYPE_TRANSACTION = 1,
APP_LAYER_EVENT_TYPE_PACKET = 2,
Expand Down
9 changes: 4 additions & 5 deletions rust/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use std;
use crate::filecontainer::*;
use crate::flow::Flow;

pub use crate::sys::{AppProto, AppProtoEnum};

/// Opaque C types.
pub enum DetectEngineState {}
pub enum AppLayerDecoderEvents {}
Expand All @@ -33,11 +35,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 u16;
pub const ALPROTO_FAILED : AppProto = AppProtoEnum::ALPROTO_FAILED as u16;

pub const IPPROTO_TCP : u8 = 6;
pub const IPPROTO_UDP : u8 = 17;
Expand Down
2 changes: 2 additions & 0 deletions src/app-layer-protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef SURICATA_APP_LAYER_PROTOS_H
#define SURICATA_APP_LAYER_PROTOS_H

#include "suricata-common.h"

enum AppProtoEnum {
ALPROTO_UNKNOWN = 0,
/* used by the probing parser when alproto detection fails
Expand Down